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 class NativeEmitter { | 5 class NativeEmitter { |
| 6 final emptyElementSet; | |
|
kasperl
2012/05/09 07:53:15
Add a comment here that explains what this is used
ngeoffray
2012/05/09 08:50:28
final Set<Element>
floitsch
2012/05/09 13:58:36
Done.
floitsch
2012/05/09 13:58:36
removed.
| |
| 6 | 7 |
| 7 Compiler compiler; | 8 Compiler compiler; |
| 8 StringBuffer nativeBuffer; | 9 StringBuffer nativeBuffer; |
| 9 | 10 |
| 10 // Classes that participate in dynamic dispatch. These are the | 11 // Classes that participate in dynamic dispatch. These are the |
| 11 // classes that contain used members. | 12 // classes that contain used members. |
| 12 Set<ClassElement> classesWithDynamicDispatch; | 13 Set<ClassElement> classesWithDynamicDispatch; |
| 13 | 14 |
| 14 // Native classes found in the application. | 15 // Native classes found in the application. |
| 15 Set<ClassElement> nativeClasses; | 16 Set<ClassElement> nativeClasses; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 30 // implementation. | 31 // implementation. |
| 31 Set<FunctionElement> nativeMethods; | 32 Set<FunctionElement> nativeMethods; |
| 32 | 33 |
| 33 NativeEmitter(this.compiler) | 34 NativeEmitter(this.compiler) |
| 34 : classesWithDynamicDispatch = new Set<ClassElement>(), | 35 : classesWithDynamicDispatch = new Set<ClassElement>(), |
| 35 nativeClasses = new Set<ClassElement>(), | 36 nativeClasses = new Set<ClassElement>(), |
| 36 subtypes = new Map<ClassElement, List<ClassElement>>(), | 37 subtypes = new Map<ClassElement, List<ClassElement>>(), |
| 37 directSubtypes = new Map<ClassElement, List<ClassElement>>(), | 38 directSubtypes = new Map<ClassElement, List<ClassElement>>(), |
| 38 overriddenMethods = new Set<FunctionElement>(), | 39 overriddenMethods = new Set<FunctionElement>(), |
| 39 nativeMethods = new Set<FunctionElement>(), | 40 nativeMethods = new Set<FunctionElement>(), |
| 40 nativeBuffer = new StringBuffer(); | 41 nativeBuffer = new StringBuffer(), |
| 42 emptyElementSet = new Set<Element>(); | |
| 41 | 43 |
| 42 String get dynamicName() { | 44 String get dynamicName() { |
| 43 Element element = compiler.findHelper( | 45 Element element = compiler.findHelper( |
| 44 const SourceString('dynamicFunction')); | 46 const SourceString('dynamicFunction')); |
| 45 return compiler.namer.isolateAccess(element); | 47 return compiler.namer.isolateAccess(element); |
| 46 } | 48 } |
| 47 | 49 |
| 48 String get dynamicSetMetadataName() { | 50 String get dynamicSetMetadataName() { |
| 49 Element element = compiler.findHelper( | 51 Element element = compiler.findHelper( |
| 50 const SourceString('dynamicSetMetadata')); | 52 const SourceString('dynamicSetMetadata')); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 77 nativeBuffer.add(' = '); | 79 nativeBuffer.add(' = '); |
| 78 nativeBuffer.add(nativeCode); | 80 nativeBuffer.add(nativeCode); |
| 79 nativeBuffer.add(';\n'); | 81 nativeBuffer.add(';\n'); |
| 80 | 82 |
| 81 void defineInstanceMember(String name, String value) { | 83 void defineInstanceMember(String name, String value) { |
| 82 nativeBuffer.add("$className.$name = $value;\n"); | 84 nativeBuffer.add("$className.$name = $value;\n"); |
| 83 } | 85 } |
| 84 | 86 |
| 85 for (Element member in classElement.members) { | 87 for (Element member in classElement.members) { |
| 86 if (member.isInstanceMember()) { | 88 if (member.isInstanceMember()) { |
| 87 compiler.emitter.addInstanceMember(member, defineInstanceMember); | 89 compiler.emitter.addInstanceMember( |
| 90 member, emptyElementSet, defineInstanceMember); | |
| 88 } | 91 } |
| 89 } | 92 } |
| 90 } | 93 } |
| 91 | 94 |
| 92 bool isNativeLiteral(String quotedName) { | 95 bool isNativeLiteral(String quotedName) { |
| 93 return quotedName[1] === '='; | 96 return quotedName[1] === '='; |
| 94 } | 97 } |
| 95 | 98 |
| 96 bool isNativeGlobal(String quotedName) { | 99 bool isNativeGlobal(String quotedName) { |
| 97 return quotedName[1] === '@'; | 100 return quotedName[1] === '@'; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 122 String nativeName = toNativeName(classElement); | 125 String nativeName = toNativeName(classElement); |
| 123 bool hasUsedSelectors = false; | 126 bool hasUsedSelectors = false; |
| 124 | 127 |
| 125 void defineInstanceMember(String name, String value) { | 128 void defineInstanceMember(String name, String value) { |
| 126 hasUsedSelectors = true; | 129 hasUsedSelectors = true; |
| 127 nativeBuffer.add("$dynamicName('$name').$nativeName = $value;\n"); | 130 nativeBuffer.add("$dynamicName('$name').$nativeName = $value;\n"); |
| 128 } | 131 } |
| 129 | 132 |
| 130 for (Element member in classElement.members) { | 133 for (Element member in classElement.members) { |
| 131 if (member.isInstanceMember()) { | 134 if (member.isInstanceMember()) { |
| 132 compiler.emitter.addInstanceMember(member, defineInstanceMember); | 135 compiler.emitter.addInstanceMember( |
| 136 member, emptyElementSet, defineInstanceMember); | |
| 133 } | 137 } |
| 134 } | 138 } |
| 135 | 139 |
| 136 compiler.emitter.generateTypeTests(classElement, (Element other) { | 140 compiler.emitter.generateTypeTests(classElement, (Element other) { |
| 137 assert(requiresNativeIsCheck(other)); | 141 assert(requiresNativeIsCheck(other)); |
| 138 defineInstanceMember(compiler.namer.operatorIs(other), | 142 defineInstanceMember(compiler.namer.operatorIs(other), |
| 139 "function() { return true; }"); | 143 "function() { return true; }"); |
| 140 }); | 144 }); |
| 141 | 145 |
| 142 if (hasUsedSelectors) classesWithDynamicDispatch.add(classElement); | 146 if (hasUsedSelectors) classesWithDynamicDispatch.add(classElement); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 String toStringName = compiler.namer.instanceMethodName( | 375 String toStringName = compiler.namer.instanceMethodName( |
| 372 null, const SourceString('toString'), 0); | 376 null, const SourceString('toString'), 0); |
| 373 objectProperties.add("$defPropName(Object.prototype, '$toStringName', "); | 377 objectProperties.add("$defPropName(Object.prototype, '$toStringName', "); |
| 374 objectProperties.add( | 378 objectProperties.add( |
| 375 'function() { return $toStringHelperName(this); });\n'); | 379 'function() { return $toStringHelperName(this); });\n'); |
| 376 | 380 |
| 377 // Finally, emit the code in the main buffer. | 381 // Finally, emit the code in the main buffer. |
| 378 targetBuffer.add('(function() {\n$objectProperties$nativeBuffer\n})();\n'); | 382 targetBuffer.add('(function() {\n$objectProperties$nativeBuffer\n})();\n'); |
| 379 } | 383 } |
| 380 } | 384 } |
| OLD | NEW |