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