| 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 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 }; | 764 }; |
| 764 '''); | 765 '''); |
| 765 } | 766 } |
| 766 | 767 |
| 767 void emitExtraAccessors(Element member, | 768 void emitExtraAccessors(Element member, |
| 768 void defineInstanceMember(String invocationName, | 769 void defineInstanceMember(String invocationName, |
| 769 String definition)) { | 770 String definition)) { |
| 770 if (member.kind == ElementKind.GETTER || member.kind == ElementKind.FIELD) { | 771 if (member.kind == ElementKind.GETTER || member.kind == ElementKind.FIELD) { |
| 771 Set<Selector> selectors = compiler.universe.invokedNames[member.name]; | 772 Set<Selector> selectors = compiler.universe.invokedNames[member.name]; |
| 772 if (selectors !== null && !selectors.isEmpty()) { | 773 if (selectors !== null && !selectors.isEmpty()) { |
| 773 compiler.emitter.emitCallStubForGetter(member, selectors, | 774 emitCallStubForGetter(member, selectors, defineInstanceMember); |
| 774 defineInstanceMember); | |
| 775 } | 775 } |
| 776 } else if (member.kind == ElementKind.FUNCTION) { | 776 } else if (member.kind == ElementKind.FUNCTION) { |
| 777 if (compiler.universe.hasGetter(member, compiler)) { | 777 if (compiler.universe.hasGetter(member, compiler)) { |
| 778 compiler.emitter.emitDynamicFunctionGetter(member, | 778 emitDynamicFunctionGetter(member, defineInstanceMember); |
| 779 defineInstanceMember); | |
| 780 } | 779 } |
| 781 } | 780 } |
| 782 } | 781 } |
| 783 | 782 |
| 784 void emitNoSuchMethodCalls(void defineInstanceMember(String invocationName, | 783 void emitNoSuchMethodCalls(void defineInstanceMember(String invocationName, |
| 785 String definition)) { | 784 String definition)) { |
| 786 // Do not generate no such method calls if there is no class. | 785 // Do not generate no such method calls if there is no class. |
| 787 if (compiler.universe.instantiatedClasses.isEmpty()) return; | 786 if (compiler.universe.instantiatedClasses.isEmpty()) return; |
| 788 | 787 |
| 789 ClassElement objectClass = | 788 ClassElement objectClass = |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 mainBuffer.add('function init() {\n'); | 971 mainBuffer.add('function init() {\n'); |
| 973 mainBuffer.add(' $isolateProperties = {};\n'); | 972 mainBuffer.add(' $isolateProperties = {};\n'); |
| 974 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); | 973 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); |
| 975 emitFinishIsolateConstructor(mainBuffer); | 974 emitFinishIsolateConstructor(mainBuffer); |
| 976 mainBuffer.add('}\n'); | 975 mainBuffer.add('}\n'); |
| 977 compiler.assembledCode = mainBuffer.toString(); | 976 compiler.assembledCode = mainBuffer.toString(); |
| 978 }); | 977 }); |
| 979 return compiler.assembledCode; | 978 return compiler.assembledCode; |
| 980 } | 979 } |
| 981 } | 980 } |
| OLD | NEW |