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, |
| 11 FunctionElement other) | 11 FunctionElement other) |
| 12 : super.from(name, other, other.enclosingElement); | 12 : super.from(name, other, other.enclosingElement); |
| 13 | 13 |
| 14 isInstanceMember() => true; | 14 isInstanceMember() => true; |
| 15 } | 15 } |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Generates the code for all used classes in the program. Static fields (even | 18 * Generates the code for all used classes in the program. Static fields (even |
| 19 * in classes) are ignored, since they can be treated as non-class elements. | 19 * in classes) are ignored, since they can be treated as non-class elements. |
| 20 * | 20 * |
| 21 * The code for the containing (used) methods must exist in the [:universe:]. | 21 * The code for the containing (used) methods must exist in the [:universe:]. |
| 22 */ | 22 */ |
| 23 class CodeEmitterTask extends CompilerTask { | 23 class CodeEmitterTask extends CompilerTask { |
| 24 bool needsInheritFunction = false; | 24 bool needsInheritFunction = false; |
| 25 bool needsDefineClass = false; | 25 bool needsDefineClass = false; |
| 26 bool needsClosureClass = false; | 26 bool needsClosureClass = false; |
| 27 final Namer namer; | 27 final Namer namer; |
| 28 final NativeEmitter nativeEmitter; | 28 NativeEmitter nativeEmitter; |
| 29 StringBuffer boundClosureBuffer; | 29 StringBuffer boundClosureBuffer; |
| 30 StringBuffer mainBuffer; | 30 StringBuffer mainBuffer; |
| 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 | 34 |
| 35 CodeEmitterTask(Compiler compiler) | 35 CodeEmitterTask(Compiler compiler) |
| 36 : namer = compiler.namer, | 36 : namer = compiler.namer, |
| 37 nativeEmitter = new NativeEmitter(compiler), | |
| 38 boundClosureBuffer = new StringBuffer(), | 37 boundClosureBuffer = new StringBuffer(), |
| 39 mainBuffer = new StringBuffer(), | 38 mainBuffer = new StringBuffer(), |
| 40 super(compiler); | 39 super(compiler) { |
| 40 nativeEmitter = new NativeEmitter(this); | |
| 41 } | |
| 41 | 42 |
| 42 String get name() => 'CodeEmitter'; | 43 String get name() => 'CodeEmitter'; |
| 43 | 44 |
| 44 String get defineClassName() | 45 String get defineClassName() |
| 45 => '${namer.ISOLATE}.\$defineClass'; | 46 => '${namer.ISOLATE}.\$defineClass'; |
| 46 String get finishClassesName() | 47 String get finishClassesName() |
| 47 => '${namer.ISOLATE}.\$finishClasses'; | 48 => '${namer.ISOLATE}.\$finishClasses'; |
| 48 String get finishIsolateConstructorName() | 49 String get finishIsolateConstructorName() |
| 49 => '${namer.ISOLATE}.\$finishIsolateConstructor'; | 50 => '${namer.ISOLATE}.\$finishIsolateConstructor'; |
| 50 String get pendingClassesName() | 51 String get pendingClassesName() |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 770 }; | 771 }; |
| 771 '''); | 772 '''); |
| 772 } | 773 } |
| 773 | 774 |
| 774 void emitExtraAccessors(Element member, | 775 void emitExtraAccessors(Element member, |
| 775 void defineInstanceMember(String invocationName, | 776 void defineInstanceMember(String invocationName, |
| 776 String definition)) { | 777 String definition)) { |
| 777 if (member.kind == ElementKind.GETTER || member.kind == ElementKind.FIELD) { | 778 if (member.kind == ElementKind.GETTER || member.kind == ElementKind.FIELD) { |
| 778 Set<Selector> selectors = compiler.universe.invokedNames[member.name]; | 779 Set<Selector> selectors = compiler.universe.invokedNames[member.name]; |
| 779 if (selectors !== null && !selectors.isEmpty()) { | 780 if (selectors !== null && !selectors.isEmpty()) { |
| 780 compiler.emitter.emitCallStubForGetter(member, selectors, | 781 emitCallStubForGetter(member, selectors, defineInstanceMember); |
|
Anton Muhin
2012/05/14 14:36:45
might have been an oversight while moving code aro
floitsch
2012/05/14 15:10:29
LGTM.
| |
| 781 defineInstanceMember); | |
| 782 } | 782 } |
| 783 } else if (member.kind == ElementKind.FUNCTION) { | 783 } else if (member.kind == ElementKind.FUNCTION) { |
| 784 if (compiler.universe.hasGetter(member, compiler)) { | 784 if (compiler.universe.hasGetter(member, compiler)) { |
| 785 compiler.emitter.emitDynamicFunctionGetter(member, | 785 emitDynamicFunctionGetter(member, defineInstanceMember); |
| 786 defineInstanceMember); | |
| 787 } | 786 } |
| 788 } | 787 } |
| 789 } | 788 } |
| 790 | 789 |
| 791 void emitNoSuchMethodCalls(void defineInstanceMember(String invocationName, | 790 void emitNoSuchMethodCalls(void defineInstanceMember(String invocationName, |
| 792 String definition)) { | 791 String definition)) { |
| 793 // Do not generate no such method calls if there is no class. | 792 // Do not generate no such method calls if there is no class. |
| 794 if (compiler.universe.instantiatedClasses.isEmpty()) return; | 793 if (compiler.universe.instantiatedClasses.isEmpty()) return; |
| 795 | 794 |
| 796 ClassElement objectClass = | 795 ClassElement objectClass = |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 980 mainBuffer.add('function init() {\n'); | 979 mainBuffer.add('function init() {\n'); |
| 981 mainBuffer.add(' $isolateProperties = {};\n'); | 980 mainBuffer.add(' $isolateProperties = {};\n'); |
| 982 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); | 981 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); |
| 983 emitFinishIsolateConstructor(mainBuffer); | 982 emitFinishIsolateConstructor(mainBuffer); |
| 984 mainBuffer.add('}\n'); | 983 mainBuffer.add('}\n'); |
| 985 compiler.assembledCode = mainBuffer.toString(); | 984 compiler.assembledCode = mainBuffer.toString(); |
| 986 }); | 985 }); |
| 987 return compiler.assembledCode; | 986 return compiler.assembledCode; |
| 988 } | 987 } |
| 989 } | 988 } |
| OLD | NEW |