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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
6 | 6 |
7 /** | 7 /** |
8 * Generates the code for all used classes in the program. Static fields (even | 8 * Generates the code for all used classes in the program. Static fields (even |
9 * in classes) are ignored, since they can be treated as non-class elements. | 9 * in classes) are ignored, since they can be treated as non-class elements. |
10 * | 10 * |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 final Map<ClassElement, Map<String, jsAst.Expression>> additionalProperties = | 48 final Map<ClassElement, Map<String, jsAst.Expression>> additionalProperties = |
49 new Map<ClassElement, Map<String, jsAst.Expression>>(); | 49 new Map<ClassElement, Map<String, jsAst.Expression>>(); |
50 | 50 |
51 /// Records if a type variable is read dynamically for type tests. | 51 /// Records if a type variable is read dynamically for type tests. |
52 final Set<TypeVariableElement> readTypeVariables = | 52 final Set<TypeVariableElement> readTypeVariables = |
53 new Set<TypeVariableElement>(); | 53 new Set<TypeVariableElement>(); |
54 | 54 |
55 // TODO(ngeoffray): remove this field. | 55 // TODO(ngeoffray): remove this field. |
56 Set<ClassElement> instantiatedClasses; | 56 Set<ClassElement> instantiatedClasses; |
57 | 57 |
| 58 List<TypedefElement> typedefsNeededForReflection; |
| 59 |
58 JavaScriptBackend get backend => compiler.backend; | 60 JavaScriptBackend get backend => compiler.backend; |
59 TypeVariableHandler get typeVariableHandler => backend.typeVariableHandler; | 61 TypeVariableHandler get typeVariableHandler => backend.typeVariableHandler; |
60 | 62 |
61 String get _ => space; | 63 String get _ => space; |
62 String get space => compiler.enableMinification ? "" : " "; | 64 String get space => compiler.enableMinification ? "" : " "; |
63 String get n => compiler.enableMinification ? "" : "\n"; | 65 String get n => compiler.enableMinification ? "" : "\n"; |
64 String get N => compiler.enableMinification ? "\n" : ";\n"; | 66 String get N => compiler.enableMinification ? "\n" : ";\n"; |
65 | 67 |
| 68 CodeBuffer getBuffer(OutputUnit outputUnit) { |
| 69 return outputBuffers.putIfAbsent(outputUnit, () => new CodeBuffer()); |
| 70 } |
| 71 |
66 CodeBuffer get mainBuffer { | 72 CodeBuffer get mainBuffer { |
67 return outputBuffers.putIfAbsent(compiler.deferredLoadTask.mainOutputUnit, | 73 return getBuffer(compiler.deferredLoadTask.mainOutputUnit); |
68 () => new CodeBuffer()); | |
69 } | 74 } |
70 | 75 |
71 /** | 76 /** |
72 * List of expressions and statements that will be included in the | 77 * List of expressions and statements that will be included in the |
73 * precompiled function. | 78 * precompiled function. |
74 * | 79 * |
75 * To save space, dart2js normally generates constructors and accessors | 80 * To save space, dart2js normally generates constructors and accessors |
76 * dynamically. This doesn't work in CSP mode, and may impact startup time | 81 * dynamically. This doesn't work in CSP mode, and may impact startup time |
77 * negatively. So dart2js will emit these functions to a separate file that | 82 * negatively. So dart2js will emit these functions to a separate file that |
78 * can be optionally included to support CSP mode or for faster startup. | 83 * can be optionally included to support CSP mode or for faster startup. |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 '$namedArguments'; | 748 '$namedArguments'; |
744 return (isConstructor) ? 'new $suffix' : suffix; | 749 return (isConstructor) ? 'new $suffix' : suffix; |
745 } | 750 } |
746 Element element = elementOrSelector; | 751 Element element = elementOrSelector; |
747 if (element.isGenerativeConstructorBody) { | 752 if (element.isGenerativeConstructorBody) { |
748 return null; | 753 return null; |
749 } else if (element.isClass) { | 754 } else if (element.isClass) { |
750 ClassElement cls = element; | 755 ClassElement cls = element; |
751 if (cls.isUnnamedMixinApplication) return null; | 756 if (cls.isUnnamedMixinApplication) return null; |
752 return cls.name; | 757 return cls.name; |
| 758 } else if (element.isTypedef) { |
| 759 return element.name; |
753 } | 760 } |
754 throw compiler.internalError(element, | 761 throw compiler.internalError(element, |
755 'Do not know how to reflect on this $element.'); | 762 'Do not know how to reflect on this $element.'); |
756 } | 763 } |
757 | 764 |
758 String namedParametersAsReflectionNames(Selector selector) { | 765 String namedParametersAsReflectionNames(Selector selector) { |
759 if (selector.getOrderedNamedArguments().isEmpty) return ''; | 766 if (selector.getOrderedNamedArguments().isEmpty) return ''; |
760 String names = selector.getOrderedNamedArguments().join(':'); | 767 String names = selector.getOrderedNamedArguments().join(':'); |
761 return ':$names'; | 768 return ':$names'; |
762 } | 769 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 void emitStaticFunctions() { | 859 void emitStaticFunctions() { |
853 bool isStaticFunction(Element element) => | 860 bool isStaticFunction(Element element) => |
854 !element.isInstanceMember && !element.isField; | 861 !element.isInstanceMember && !element.isField; |
855 | 862 |
856 Iterable<Element> elements = | 863 Iterable<Element> elements = |
857 backend.generatedCode.keys.where(isStaticFunction); | 864 backend.generatedCode.keys.where(isStaticFunction); |
858 | 865 |
859 for (Element element in Elements.sortedByPosition(elements)) { | 866 for (Element element in Elements.sortedByPosition(elements)) { |
860 ClassBuilder builder = new ClassBuilder(namer); | 867 ClassBuilder builder = new ClassBuilder(namer); |
861 containerBuilder.addMember(element, builder); | 868 containerBuilder.addMember(element, builder); |
862 getElementDecriptor(element).properties.addAll(builder.properties); | 869 getElementDescriptor(element).properties.addAll(builder.properties); |
863 } | 870 } |
864 } | 871 } |
865 | 872 |
866 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer) { | 873 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer) { |
867 JavaScriptConstantCompiler handler = backend.constants; | 874 JavaScriptConstantCompiler handler = backend.constants; |
868 Iterable<VariableElement> staticNonFinalFields = | 875 Iterable<VariableElement> staticNonFinalFields = |
869 handler.getStaticNonFinalFieldsForEmission(); | 876 handler.getStaticNonFinalFieldsForEmission(); |
870 for (Element element in Elements.sortedByPosition(staticNonFinalFields)) { | 877 for (Element element in Elements.sortedByPosition(staticNonFinalFields)) { |
871 // [:interceptedNames:] is handled in [emitInterceptedNames]. | 878 // [:interceptedNames:] is handled in [emitInterceptedNames]. |
872 if (element == backend.interceptedNames) continue; | 879 if (element == backend.interceptedNames) continue; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 // The back-end introduces some constants, like "InterceptorConstant" or | 1145 // The back-end introduces some constants, like "InterceptorConstant" or |
1139 // some list constants. They are emitted in the main output-unit. | 1146 // some list constants. They are emitted in the main output-unit. |
1140 // TODO(sigurdm): We should track those constants. | 1147 // TODO(sigurdm): We should track those constants. |
1141 constantUnit = compiler.deferredLoadTask.mainOutputUnit; | 1148 constantUnit = compiler.deferredLoadTask.mainOutputUnit; |
1142 } | 1149 } |
1143 outputConstantLists.putIfAbsent(constantUnit, () => new List<Constant>()) | 1150 outputConstantLists.putIfAbsent(constantUnit, () => new List<Constant>()) |
1144 .add(constant); | 1151 .add(constant); |
1145 } | 1152 } |
1146 } | 1153 } |
1147 | 1154 |
1148 /** | 1155 /// Compute all the classes and typedefs that must be emitted. |
1149 * Compute all the classes that must be emitted. | 1156 void computeNeededDeclarations() { |
1150 */ | 1157 // Compute needed typedefs. |
1151 void computeNeededClasses() { | 1158 typedefsNeededForReflection = Elements.sortedByPosition( |
| 1159 compiler.world.allTypedefs |
| 1160 .where(backend.isAccessibleByReflection) |
| 1161 .toList()); |
| 1162 |
| 1163 // Compute needed classes. |
1152 instantiatedClasses = | 1164 instantiatedClasses = |
1153 compiler.codegenWorld.instantiatedClasses.where(computeClassFilter()) | 1165 compiler.codegenWorld.instantiatedClasses.where(computeClassFilter()) |
1154 .toSet(); | 1166 .toSet(); |
1155 | 1167 |
1156 void addClassWithSuperclasses(ClassElement cls) { | 1168 void addClassWithSuperclasses(ClassElement cls) { |
1157 neededClasses.add(cls); | 1169 neededClasses.add(cls); |
1158 for (ClassElement superclass = cls.superclass; | 1170 for (ClassElement superclass = cls.superclass; |
1159 superclass != null; | 1171 superclass != null; |
1160 superclass = superclass.superclass) { | 1172 superclass = superclass.superclass) { |
1161 neededClasses.add(superclass); | 1173 neededClasses.add(superclass); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 | 1308 |
1297 mainBuffer.add(jsAst.prettyPrint(convertToFastObject, compiler)); | 1309 mainBuffer.add(jsAst.prettyPrint(convertToFastObject, compiler)); |
1298 mainBuffer.add(N); | 1310 mainBuffer.add(N); |
1299 } | 1311 } |
1300 | 1312 |
1301 void writeLibraryDescriptors(LibraryElement library) { | 1313 void writeLibraryDescriptors(LibraryElement library) { |
1302 var uri = library.canonicalUri; | 1314 var uri = library.canonicalUri; |
1303 if (uri.scheme == 'file' && compiler.outputUri != null) { | 1315 if (uri.scheme == 'file' && compiler.outputUri != null) { |
1304 uri = relativize(compiler.outputUri, library.canonicalUri, false); | 1316 uri = relativize(compiler.outputUri, library.canonicalUri, false); |
1305 } | 1317 } |
1306 Map<OutputUnit, ClassBuilder> descriptors = | 1318 Map<OutputUnit, ClassBuilder> descriptors = elementDescriptors[library]; |
1307 elementDescriptors[library]; | |
1308 | 1319 |
1309 for (OutputUnit outputUnit in compiler.deferredLoadTask.allOutputUnits) { | 1320 for (OutputUnit outputUnit in compiler.deferredLoadTask.allOutputUnits) { |
1310 ClassBuilder descriptor = | 1321 if (!descriptors.containsKey(outputUnit)) continue; |
1311 descriptors.putIfAbsent(outputUnit, () => new ClassBuilder(namer)); | 1322 |
1312 if (descriptor.properties.isEmpty) continue; | 1323 ClassBuilder descriptor = descriptors[outputUnit]; |
1313 bool isDeferred = | |
1314 outputUnit != compiler.deferredLoadTask.mainOutputUnit; | |
1315 jsAst.Fun metadata = metadataEmitter.buildMetadataFunction(library); | 1324 jsAst.Fun metadata = metadataEmitter.buildMetadataFunction(library); |
1316 | 1325 |
1317 jsAst.ObjectInitializer initializers = | 1326 jsAst.ObjectInitializer initializers = descriptor.toObjectInitializer(); |
1318 descriptor.toObjectInitializer(); | 1327 CodeBuffer outputBuffer = getBuffer(outputUnit); |
1319 CodeBuffer outputBuffer = | 1328 |
1320 outputBuffers.putIfAbsent(outputUnit, () => new CodeBuffer()); | |
1321 int sizeBefore = outputBuffer.length; | 1329 int sizeBefore = outputBuffer.length; |
1322 outputBuffers[outputUnit] | 1330 outputBuffers[outputUnit] |
1323 ..write('["${library.getLibraryName()}",$_') | 1331 ..write('["${library.getLibraryName()}",$_') |
1324 ..write('"${uri}",$_') | 1332 ..write('"${uri}",$_') |
1325 ..write(metadata == null ? "" : jsAst.prettyPrint(metadata, compiler)) | 1333 ..write(metadata == null ? "" : jsAst.prettyPrint(metadata, compiler)) |
1326 ..write(',$_') | 1334 ..write(',$_') |
1327 ..write(namer.globalObjectFor(library)) | 1335 ..write(namer.globalObjectFor(library)) |
1328 ..write(',$_') | 1336 ..write(',$_') |
1329 ..write(jsAst.prettyPrint(initializers, compiler)) | 1337 ..write(jsAst.prettyPrint(initializers, compiler)) |
1330 ..write(library == compiler.mainApp ? ',${n}1' : "") | 1338 ..write(library == compiler.mainApp ? ',${n}1' : "") |
1331 ..write('],$n'); | 1339 ..write('],$n'); |
1332 int sizeAfter = outputBuffer.length; | 1340 int sizeAfter = outputBuffer.length; |
1333 compiler.dumpInfoTask.codeSizeCounter | 1341 compiler.dumpInfoTask.codeSizeCounter |
1334 .countCode(library, sizeAfter - sizeBefore); | 1342 .countCode(library, sizeAfter - sizeBefore); |
1335 } | 1343 } |
1336 } | 1344 } |
1337 | 1345 |
1338 String assembleProgram() { | 1346 String assembleProgram() { |
1339 measure(() { | 1347 measure(() { |
1340 invalidateCaches(); | 1348 invalidateCaches(); |
1341 | 1349 |
1342 // Compute the required type checks to know which classes need a | 1350 // Compute the required type checks to know which classes need a |
1343 // 'is$' method. | 1351 // 'is$' method. |
1344 typeTestEmitter.computeRequiredTypeChecks(); | 1352 typeTestEmitter.computeRequiredTypeChecks(); |
1345 | 1353 |
1346 computeNeededClasses(); | 1354 computeNeededDeclarations(); |
1347 | 1355 |
1348 mainBuffer.add(buildGeneratedBy()); | 1356 mainBuffer.add(buildGeneratedBy()); |
1349 addComment(HOOKS_API_USAGE, mainBuffer); | 1357 addComment(HOOKS_API_USAGE, mainBuffer); |
1350 | 1358 |
1351 if (!compiler.deferredLoadTask.splitProgram) { | 1359 if (!compiler.deferredLoadTask.splitProgram) { |
1352 mainBuffer.add('(function(${namer.currentIsolate})$_{$n'); | 1360 mainBuffer.add('(function(${namer.currentIsolate})$_{$n'); |
1353 } | 1361 } |
1354 | 1362 |
1355 // Using a named function here produces easier to read stack traces in | 1363 // Using a named function here produces easier to read stack traces in |
1356 // Chrome/V8. | 1364 // Chrome/V8. |
(...skipping 14 matching lines...) Expand all Loading... |
1371 // Shorten the code by using [namer.currentIsolate] as temporary. | 1379 // Shorten the code by using [namer.currentIsolate] as temporary. |
1372 isolateProperties = namer.currentIsolate; | 1380 isolateProperties = namer.currentIsolate; |
1373 mainBuffer.add( | 1381 mainBuffer.add( |
1374 '$isolateProperties$_=$_$isolatePropertiesName$N'); | 1382 '$isolateProperties$_=$_$isolatePropertiesName$N'); |
1375 | 1383 |
1376 emitStaticFunctions(); | 1384 emitStaticFunctions(); |
1377 | 1385 |
1378 // Only output the classesCollector if we actually have any classes. | 1386 // Only output the classesCollector if we actually have any classes. |
1379 if (!(nativeClasses.isEmpty && | 1387 if (!(nativeClasses.isEmpty && |
1380 compiler.codegenWorld.staticFunctionsNeedingGetter.isEmpty && | 1388 compiler.codegenWorld.staticFunctionsNeedingGetter.isEmpty && |
1381 outputClassLists.values.every((classList) => classList.isEmpty))) { | 1389 outputClassLists.values.every((classList) => classList.isEmpty) && |
| 1390 typedefsNeededForReflection.isEmpty)) { |
1382 // Shorten the code by using "$$" as temporary. | 1391 // Shorten the code by using "$$" as temporary. |
1383 classesCollector = r"$$"; | 1392 classesCollector = r"$$"; |
1384 mainBuffer.add('var $classesCollector$_=$_{}$N$n'); | 1393 mainBuffer.add('var $classesCollector$_=$_{}$N$n'); |
1385 } | 1394 } |
1386 | 1395 |
1387 // Emit native classes on [nativeBuffer]. | 1396 // Emit native classes on [nativeBuffer]. |
1388 // Might create methodClosures. | 1397 // Might create methodClosures. |
1389 final CodeBuffer nativeBuffer = new CodeBuffer(); | 1398 final CodeBuffer nativeBuffer = new CodeBuffer(); |
1390 if (!nativeClasses.isEmpty) { | 1399 if (!nativeClasses.isEmpty) { |
1391 addComment('Native classes', nativeBuffer); | 1400 addComment('Native classes', nativeBuffer); |
1392 addComment('Native classes', mainBuffer); | 1401 addComment('Native classes', mainBuffer); |
1393 nativeEmitter.generateNativeClasses(nativeClasses, mainBuffer, | 1402 nativeEmitter.generateNativeClasses(nativeClasses, mainBuffer, |
1394 additionalProperties); | 1403 additionalProperties); |
1395 } | 1404 } |
1396 | 1405 |
1397 // As a side-effect, emitting classes will produce "bound closures" in | 1406 // As a side-effect, emitting classes will produce "bound closures" in |
1398 // [methodClosures]. The bound closures are JS AST nodes that add | 1407 // [methodClosures]. The bound closures are JS AST nodes that add |
1399 // properties to $$ [classesCollector]. The bound closures are not | 1408 // properties to $$ [classesCollector]. The bound closures are not |
1400 // emitted until we have emitted all other classes (native or not). | 1409 // emitted until we have emitted all other classes (native or not). |
1401 | 1410 |
1402 // Might create methodClosures. | 1411 // Might create methodClosures. |
1403 for (List<ClassElement> outputClassList in outputClassLists.values) { | 1412 for (List<ClassElement> outputClassList in outputClassLists.values) { |
1404 for (ClassElement element in outputClassList) { | 1413 for (ClassElement element in outputClassList) { |
1405 generateClass(element, getElementDecriptor(element)); | 1414 generateClass(element, getElementDescriptor(element)); |
1406 } | 1415 } |
1407 } | 1416 } |
1408 | 1417 |
1409 nativeEmitter.finishGenerateNativeClasses(); | 1418 nativeEmitter.finishGenerateNativeClasses(); |
1410 nativeEmitter.assembleCode(nativeBuffer); | 1419 nativeEmitter.assembleCode(nativeBuffer); |
1411 | 1420 |
1412 | 1421 |
1413 // After this assignment we will produce invalid JavaScript code if we use | 1422 // After this assignment we will produce invalid JavaScript code if we use |
1414 // the classesCollector variable. | 1423 // the classesCollector variable. |
1415 classesCollector = 'classesCollector should not be used from now on'; | 1424 classesCollector = 'classesCollector should not be used from now on'; |
1416 | 1425 |
1417 // TODO(sigurdm): Need to check this for each outputUnit. | 1426 // TODO(sigurdm): Need to check this for each outputUnit. |
1418 if (!elementDescriptors.isEmpty) { | 1427 if (!elementDescriptors.isEmpty) { |
1419 var oldClassesCollector = classesCollector; | 1428 var oldClassesCollector = classesCollector; |
1420 classesCollector = r"$$"; | 1429 classesCollector = r"$$"; |
1421 if (compiler.enableMinification) { | 1430 if (compiler.enableMinification) { |
1422 mainBuffer.write(';'); | 1431 mainBuffer.write(';'); |
1423 } | 1432 } |
1424 | 1433 |
| 1434 // TODO(karlklose): document what kinds of fields this loop adds to the |
| 1435 // library class builder. |
1425 for (Element element in elementDescriptors.keys) { | 1436 for (Element element in elementDescriptors.keys) { |
1426 // TODO(ahe): Should iterate over all libraries. Otherwise, we will | 1437 // TODO(ahe): Should iterate over all libraries. Otherwise, we will |
1427 // not see libraries that only have fields. | 1438 // not see libraries that only have fields. |
1428 if (element.isLibrary) { | 1439 if (element.isLibrary) { |
1429 LibraryElement library = element; | 1440 LibraryElement library = element; |
1430 ClassBuilder builder = new ClassBuilder(namer); | 1441 ClassBuilder builder = new ClassBuilder(namer); |
1431 if (classEmitter.emitFields( | 1442 if (classEmitter.emitFields( |
1432 library, builder, null, emitStatics: true)) { | 1443 library, builder, null, emitStatics: true)) { |
1433 OutputUnit mainUnit = compiler.deferredLoadTask.mainOutputUnit; | 1444 OutputUnit mainUnit = compiler.deferredLoadTask.mainOutputUnit; |
1434 getElementDescriptorForOutputUnit(library, mainUnit) | 1445 getElementDescriptorForOutputUnit(library, mainUnit) |
1435 .properties.addAll(builder.toObjectInitializer().properties); | 1446 .properties.addAll(builder.toObjectInitializer().properties); |
1436 } | 1447 } |
1437 } | 1448 } |
1438 } | 1449 } |
1439 | 1450 |
| 1451 // Emit all required typedef declarations into the main output unit. |
| 1452 // TODO(karlklose): unify required classes and typedefs to declarations |
| 1453 // and have builders for each kind. |
| 1454 for (TypedefElement typedef in typedefsNeededForReflection) { |
| 1455 OutputUnit mainUnit = compiler.deferredLoadTask.mainOutputUnit; |
| 1456 LibraryElement library = typedef.library; |
| 1457 // TODO(karlklose): add a TypedefBuilder and move this code there. |
| 1458 DartType type = typedef.alias; |
| 1459 int typeIndex = metadataEmitter.reifyType(type); |
| 1460 String typeReference = |
| 1461 encoding.encodeTypedefFieldDescriptor(typeIndex); |
| 1462 jsAst.Property descriptor = new jsAst.Property( |
| 1463 js.string(namer.classDescriptorProperty), |
| 1464 js.string(typeReference)); |
| 1465 jsAst.Node declaration = new jsAst.ObjectInitializer([descriptor]); |
| 1466 String mangledName = namer.getNameX(typedef); |
| 1467 String reflectionName = getReflectionName(typedef, mangledName); |
| 1468 getElementDescriptorForOutputUnit(library, mainUnit) |
| 1469 ..addProperty(mangledName, declaration) |
| 1470 ..addProperty("+$reflectionName", js.string('')); |
| 1471 } |
| 1472 |
1440 if (!mangledFieldNames.isEmpty) { | 1473 if (!mangledFieldNames.isEmpty) { |
1441 var keys = mangledFieldNames.keys.toList(); | 1474 var keys = mangledFieldNames.keys.toList(); |
1442 keys.sort(); | 1475 keys.sort(); |
1443 var properties = []; | 1476 var properties = []; |
1444 for (String key in keys) { | 1477 for (String key in keys) { |
1445 var value = js.string('${mangledFieldNames[key]}'); | 1478 var value = js.string('${mangledFieldNames[key]}'); |
1446 properties.add(new jsAst.Property(js.string(key), value)); | 1479 properties.add(new jsAst.Property(js.string(key), value)); |
1447 } | 1480 } |
1448 var map = new jsAst.ObjectInitializer(properties); | 1481 var map = new jsAst.ObjectInitializer(properties); |
1449 mainBuffer.write( | 1482 mainBuffer.write( |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 | 1715 |
1683 ClassBuilder getElementDescriptorForOutputUnit(Element element, | 1716 ClassBuilder getElementDescriptorForOutputUnit(Element element, |
1684 OutputUnit outputUnit) { | 1717 OutputUnit outputUnit) { |
1685 Map<OutputUnit, ClassBuilder> descriptors = | 1718 Map<OutputUnit, ClassBuilder> descriptors = |
1686 elementDescriptors.putIfAbsent( | 1719 elementDescriptors.putIfAbsent( |
1687 element, () => new Map<OutputUnit, ClassBuilder>()); | 1720 element, () => new Map<OutputUnit, ClassBuilder>()); |
1688 return descriptors.putIfAbsent(outputUnit, | 1721 return descriptors.putIfAbsent(outputUnit, |
1689 () => new ClassBuilder(namer)); | 1722 () => new ClassBuilder(namer)); |
1690 } | 1723 } |
1691 | 1724 |
1692 ClassBuilder getElementDecriptor(Element element) { | 1725 ClassBuilder getElementDescriptor(Element element) { |
1693 Element owner = element.library; | 1726 Element owner = element.library; |
1694 if (!element.isTopLevel && !element.isNative) { | 1727 if (!element.isTopLevel && !element.isNative) { |
1695 // For static (not top level) elements, record their code in a buffer | 1728 // For static (not top level) elements, record their code in a buffer |
1696 // specific to the class. For now, not supported for native classes and | 1729 // specific to the class. For now, not supported for native classes and |
1697 // native elements. | 1730 // native elements. |
1698 ClassElement cls = | 1731 ClassElement cls = |
1699 element.enclosingClassOrCompilationUnit.declaration; | 1732 element.enclosingClassOrCompilationUnit.declaration; |
1700 if (compiler.codegenWorld.instantiatedClasses.contains(cls) | 1733 if (compiler.codegenWorld.instantiatedClasses.contains(cls) |
1701 && !cls.isNative) { | 1734 && !cls.isNative) { |
1702 owner = cls; | 1735 owner = cls; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1797 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 1830 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
1798 if (element.isInstanceMember) { | 1831 if (element.isInstanceMember) { |
1799 cachedClassBuilders.remove(element.enclosingClass); | 1832 cachedClassBuilders.remove(element.enclosingClass); |
1800 | 1833 |
1801 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 1834 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
1802 | 1835 |
1803 } | 1836 } |
1804 } | 1837 } |
1805 } | 1838 } |
1806 } | 1839 } |
OLD | NEW |