Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * A function element that represents a closure call. The signature is copied | 6 * A function element that represents a closure call. The signature is copied |
| 7 * from the given element. | 7 * from the given element. |
| 8 */ | 8 */ |
| 9 class ClosureInvocationElement extends FunctionElement { | 9 class ClosureInvocationElement extends FunctionElement { |
| 10 ClosureInvocationElement(SourceString name, | 10 ClosureInvocationElement(SourceString name, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 /** Shorter access to [isolatePropertiesName]. Both here in the code, as | 31 /** Shorter access to [isolatePropertiesName]. Both here in the code, as |
| 32 well as in the generated code. */ | 32 well as in the generated code. */ |
| 33 String isolateProperties; | 33 String isolateProperties; |
| 34 final Map<int, String> boundClosureCache; | 34 final Map<int, String> boundClosureCache; |
| 35 | 35 |
| 36 CodeEmitterTask(Compiler compiler) | 36 CodeEmitterTask(Compiler compiler) |
| 37 : namer = compiler.namer, | 37 : namer = compiler.namer, |
| 38 boundClosureBuffer = new StringBuffer(), | 38 boundClosureBuffer = new StringBuffer(), |
| 39 mainBuffer = new StringBuffer(), | 39 mainBuffer = new StringBuffer(), |
| 40 boundClosureCache = new Map<int, String>(), | 40 boundClosureCache = new Map<int, String>(), |
| 41 sourceMappings = new List<SourceMappingEntry>(), | |
| 41 super(compiler) { | 42 super(compiler) { |
| 42 nativeEmitter = new NativeEmitter(this); | 43 nativeEmitter = new NativeEmitter(this); |
| 43 } | 44 } |
| 44 | 45 |
| 45 String get name() => 'CodeEmitter'; | 46 String get name() => 'CodeEmitter'; |
| 46 | 47 |
| 47 String get defineClassName() | 48 String get defineClassName() |
| 48 => '${namer.ISOLATE}.\$defineClass'; | 49 => '${namer.ISOLATE}.\$defineClass'; |
| 49 String get finishClassesName() | 50 String get finishClassesName() |
| 50 => '${namer.ISOLATE}.\$finishClasses'; | 51 => '${namer.ISOLATE}.\$finishClasses'; |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 void emitFinishClassesInvocationIfNecessary(StringBuffer buffer) { | 591 void emitFinishClassesInvocationIfNecessary(StringBuffer buffer) { |
| 591 if (needsDefineClass) buffer.add("$finishClassesName();\n"); | 592 if (needsDefineClass) buffer.add("$finishClassesName();\n"); |
| 592 } | 593 } |
| 593 | 594 |
| 594 void emitStaticFunctionsWithNamer(StringBuffer buffer, | 595 void emitStaticFunctionsWithNamer(StringBuffer buffer, |
| 595 Map<Element, String> generatedCode, | 596 Map<Element, String> generatedCode, |
| 596 String functionNamer(Element element)) { | 597 String functionNamer(Element element)) { |
| 597 generatedCode.forEach((Element element, String codeBlock) { | 598 generatedCode.forEach((Element element, String codeBlock) { |
| 598 if (!element.isInstanceMember()) { | 599 if (!element.isInstanceMember()) { |
| 599 String functionName = functionNamer(element); | 600 String functionName = functionNamer(element); |
| 600 buffer.add('$isolateProperties.$functionName = $codeBlock;\n\n'); | 601 buffer.add('$isolateProperties.$functionName = '); |
| 602 int beginPosition = buffer.length; | |
| 603 buffer.add(codeBlock); | |
| 604 int endPosition = buffer.length; | |
| 605 buffer.add(';\n\n'); | |
| 606 addSourceMapping(element, beginPosition, endPosition); | |
| 601 } | 607 } |
| 602 }); | 608 }); |
| 603 } | 609 } |
| 604 | 610 |
| 605 void emitStaticFunctions(StringBuffer buffer) { | 611 void emitStaticFunctions(StringBuffer buffer) { |
| 606 emitStaticFunctionsWithNamer(buffer, | 612 emitStaticFunctionsWithNamer(buffer, |
| 607 compiler.codegenWorld.generatedCode, | 613 compiler.codegenWorld.generatedCode, |
| 608 namer.getName); | 614 namer.getName); |
| 609 emitStaticFunctionsWithNamer(buffer, | 615 emitStaticFunctionsWithNamer(buffer, |
| 610 compiler.codegenWorld.generatedBailoutCode, | 616 compiler.codegenWorld.generatedBailoutCode, |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 999 emitMain(mainBuffer); | 1005 emitMain(mainBuffer); |
| 1000 mainBuffer.add('function init() {\n'); | 1006 mainBuffer.add('function init() {\n'); |
| 1001 mainBuffer.add(' $isolateProperties = {};\n'); | 1007 mainBuffer.add(' $isolateProperties = {};\n'); |
| 1002 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); | 1008 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); |
| 1003 emitFinishIsolateConstructor(mainBuffer); | 1009 emitFinishIsolateConstructor(mainBuffer); |
| 1004 mainBuffer.add('}\n'); | 1010 mainBuffer.add('}\n'); |
| 1005 compiler.assembledCode = mainBuffer.toString(); | 1011 compiler.assembledCode = mainBuffer.toString(); |
| 1006 }); | 1012 }); |
| 1007 return compiler.assembledCode; | 1013 return compiler.assembledCode; |
| 1008 } | 1014 } |
| 1015 | |
| 1016 void addSourceMapping(FunctionElement element, int emittedBeginPosition, int e mittedEndPosition) { | |
|
podivilov
2012/06/19 16:37:54
This should probably be a method of SourceMapListe
ahe
2012/06/19 17:00:41
Long lines.
podivilov
2012/06/20 09:37:14
Done.
| |
| 1017 SourceFile sourceFile = element.getCompilationUnit().script.file; | |
| 1018 FunctionExpression expression = element.cachedNode; | |
| 1019 sourceMappings.add(new SourceMappingEntry(sourceFile, expression.getBeginTok en().charOffset, emittedBeginPosition)); | |
| 1020 sourceMappings.add(new SourceMappingEntry(sourceFile, expression.getEndToken ().charOffset, emittedEndPosition)); | |
| 1021 } | |
| 1022 | |
| 1023 final List<SourceMappingEntry> sourceMappings; | |
| 1009 } | 1024 } |
| OLD | NEW |