Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart

Issue 174533005: Reapply "Avoid use of empty string as a property name." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Another fix. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 js('var constructorsList = []')]), 324 js('var constructorsList = []')]),
325 js.forIn('cls', 'collectedClasses', [ 325 js.forIn('cls', 'collectedClasses', [
326 js.if_('hasOwnProperty.call(collectedClasses, cls)', [ 326 js.if_('hasOwnProperty.call(collectedClasses, cls)', [
327 js('var desc = collectedClasses[cls]'), 327 js('var desc = collectedClasses[cls]'),
328 js.if_('desc instanceof Array', js('desc = desc[1]')), 328 js.if_('desc instanceof Array', js('desc = desc[1]')),
329 329
330 /* The 'fields' are either a constructor function or a 330 /* The 'fields' are either a constructor function or a
331 * string encoding fields, constructor and superclass. Get 331 * string encoding fields, constructor and superclass. Get
332 * the superclass and the fields in the format 332 * the superclass and the fields in the format
333 * '[name/]Super;field1,field2' 333 * '[name/]Super;field1,field2'
334 * from the null-string property on the descriptor. 334 * from the CLASS_DESCRIPTOR_PROPERTY property on the descriptor.
335 * The 'name/' is optional and contains the name that should be used 335 * The 'name/' is optional and contains the name that should be used
336 * when printing the runtime type string. It is used, for example, to 336 * when printing the runtime type string. It is used, for example, to
337 * print the runtime type JSInt as 'int'. 337 * print the runtime type JSInt as 'int'.
338 */ 338 */
339 js('var classData = desc[""], supr, name = cls, fields = classData'), 339 js('var classData = desc["${namer.classDescriptorProperty}"], '
340 'supr, name = cls, fields = classData'),
340 optional( 341 optional(
341 backend.hasRetainedMetadata, 342 backend.hasRetainedMetadata,
342 js.if_('typeof classData == "object" && ' 343 js.if_('typeof classData == "object" && '
343 'classData instanceof Array', 344 'classData instanceof Array',
344 [js('classData = fields = classData[0]')])), 345 [js('classData = fields = classData[0]')])),
345 346
346 js.if_('typeof classData == "string"', [ 347 js.if_('typeof classData == "string"', [
347 js('var split = classData.split("/")'), 348 js('var split = classData.split("/")'),
348 js.if_('split.length == 2', [ 349 js.if_('split.length == 2', [
349 js('name = split[0]'), 350 js('name = split[0]'),
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 } 822 }
822 823
823 void emitStaticFunctions() { 824 void emitStaticFunctions() {
824 bool isStaticFunction(Element element) => 825 bool isStaticFunction(Element element) =>
825 !element.isInstanceMember() && !element.isField(); 826 !element.isInstanceMember() && !element.isField();
826 827
827 Iterable<Element> elements = 828 Iterable<Element> elements =
828 backend.generatedCode.keys.where(isStaticFunction); 829 backend.generatedCode.keys.where(isStaticFunction);
829 830
830 for (Element element in Elements.sortedByPosition(elements)) { 831 for (Element element in Elements.sortedByPosition(elements)) {
831 ClassBuilder builder = new ClassBuilder(); 832 ClassBuilder builder = new ClassBuilder(namer);
832 containerBuilder.addMember(element, builder); 833 containerBuilder.addMember(element, builder);
833 getElementDecriptor(element).properties.addAll(builder.properties); 834 getElementDecriptor(element).properties.addAll(builder.properties);
834 } 835 }
835 } 836 }
836 837
837 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer) { 838 void emitStaticNonFinalFieldInitializations(CodeBuffer buffer) {
838 ConstantHandler handler = compiler.constantHandler; 839 ConstantHandler handler = compiler.constantHandler;
839 Iterable<VariableElement> staticNonFinalFields = 840 Iterable<VariableElement> staticNonFinalFields =
840 handler.getStaticNonFinalFieldsForEmission(); 841 handler.getStaticNonFinalFieldsForEmission();
841 for (Element element in Elements.sortedByPosition(staticNonFinalFields)) { 842 for (Element element in Elements.sortedByPosition(staticNonFinalFields)) {
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 // here. It should be relative to the main JavaScript 1225 // here. It should be relative to the main JavaScript
1225 // output file. 1226 // output file.
1226 uri = relativize( 1227 uri = relativize(
1227 compiler.sourceMapUri, library.canonicalUri, false); 1228 compiler.sourceMapUri, library.canonicalUri, false);
1228 } 1229 }
1229 Map<OutputUnit, ClassBuilder> descriptors = 1230 Map<OutputUnit, ClassBuilder> descriptors =
1230 elementDescriptors[library]; 1231 elementDescriptors[library];
1231 1232
1232 for (OutputUnit outputUnit in compiler.deferredLoadTask.allOutputUnits) { 1233 for (OutputUnit outputUnit in compiler.deferredLoadTask.allOutputUnits) {
1233 ClassBuilder descriptor = 1234 ClassBuilder descriptor =
1234 descriptors.putIfAbsent(outputUnit, () 1235 descriptors.putIfAbsent(outputUnit, () => new ClassBuilder(namer));
1235 => new ClassBuilder());
1236 if (descriptor.properties.isEmpty) continue; 1236 if (descriptor.properties.isEmpty) continue;
1237 bool isDeferred = 1237 bool isDeferred =
1238 outputUnit != compiler.deferredLoadTask.mainOutputUnit; 1238 outputUnit != compiler.deferredLoadTask.mainOutputUnit;
1239 jsAst.Fun metadata = metadataEmitter.buildMetadataFunction(library); 1239 jsAst.Fun metadata = metadataEmitter.buildMetadataFunction(library);
1240 1240
1241 jsAst.ObjectInitializer initializers = 1241 jsAst.ObjectInitializer initializers =
1242 descriptor.toObjectInitializer(); 1242 descriptor.toObjectInitializer();
1243 CodeBuffer outputBuffer = 1243 CodeBuffer outputBuffer =
1244 outputBuffers.putIfAbsent(outputUnit, () => new CodeBuffer()); 1244 outputBuffers.putIfAbsent(outputUnit, () => new CodeBuffer());
1245 int sizeBefore = outputBuffer.length; 1245 int sizeBefore = outputBuffer.length;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 classesCollector = r"$$"; 1343 classesCollector = r"$$";
1344 if (compiler.enableMinification) { 1344 if (compiler.enableMinification) {
1345 mainBuffer.write(';'); 1345 mainBuffer.write(';');
1346 } 1346 }
1347 1347
1348 for (Element element in elementDescriptors.keys) { 1348 for (Element element in elementDescriptors.keys) {
1349 // TODO(ahe): Should iterate over all libraries. Otherwise, we will 1349 // TODO(ahe): Should iterate over all libraries. Otherwise, we will
1350 // not see libraries that only have fields. 1350 // not see libraries that only have fields.
1351 if (element.isLibrary()) { 1351 if (element.isLibrary()) {
1352 LibraryElement library = element; 1352 LibraryElement library = element;
1353 ClassBuilder builder = new ClassBuilder(); 1353 ClassBuilder builder = new ClassBuilder(namer);
1354 if (classEmitter.emitFields( 1354 if (classEmitter.emitFields(
1355 library, builder, null, emitStatics: true)) { 1355 library, builder, null, emitStatics: true)) {
1356 OutputUnit mainUnit = compiler.deferredLoadTask.mainOutputUnit; 1356 OutputUnit mainUnit = compiler.deferredLoadTask.mainOutputUnit;
1357 getElementDescriptorForOutputUnit(library, mainUnit) 1357 getElementDescriptorForOutputUnit(library, mainUnit)
1358 .properties.addAll(builder.toObjectInitializer().properties); 1358 .properties.addAll(builder.toObjectInitializer().properties);
1359 } 1359 }
1360 } 1360 }
1361 } 1361 }
1362 1362
1363 if (!mangledFieldNames.isEmpty) { 1363 if (!mangledFieldNames.isEmpty) {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 }); 1541 });
1542 return compiler.assembledCode; 1542 return compiler.assembledCode;
1543 } 1543 }
1544 1544
1545 ClassBuilder getElementDescriptorForOutputUnit(Element element, 1545 ClassBuilder getElementDescriptorForOutputUnit(Element element,
1546 OutputUnit outputUnit) { 1546 OutputUnit outputUnit) {
1547 Map<OutputUnit, ClassBuilder> descriptors = 1547 Map<OutputUnit, ClassBuilder> descriptors =
1548 elementDescriptors.putIfAbsent( 1548 elementDescriptors.putIfAbsent(
1549 element, () => new Map<OutputUnit, ClassBuilder>()); 1549 element, () => new Map<OutputUnit, ClassBuilder>());
1550 return descriptors.putIfAbsent(outputUnit, 1550 return descriptors.putIfAbsent(outputUnit,
1551 () => new ClassBuilder()); 1551 () => new ClassBuilder(namer));
1552 } 1552 }
1553 1553
1554 ClassBuilder getElementDecriptor(Element element) { 1554 ClassBuilder getElementDecriptor(Element element) {
1555 Element owner = element.getLibrary(); 1555 Element owner = element.getLibrary();
1556 if (!element.isTopLevel() && !element.isNative()) { 1556 if (!element.isTopLevel() && !element.isNative()) {
1557 // For static (not top level) elements, record their code in a buffer 1557 // For static (not top level) elements, record their code in a buffer
1558 // specific to the class. For now, not supported for native classes and 1558 // specific to the class. For now, not supported for native classes and
1559 // native elements. 1559 // native elements.
1560 ClassElement cls = 1560 ClassElement cls =
1561 element.getEnclosingClassOrCompilationUnit().declaration; 1561 element.getEnclosingClassOrCompilationUnit().declaration;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 String sourceMap = buildSourceMap(mainBuffer, compiledFile); 1644 String sourceMap = buildSourceMap(mainBuffer, compiledFile);
1645 compiler.outputProvider(name, 'js.map') 1645 compiler.outputProvider(name, 'js.map')
1646 ..add(sourceMap) 1646 ..add(sourceMap)
1647 ..close(); 1647 ..close();
1648 } 1648 }
1649 1649
1650 void registerReadTypeVariable(TypeVariableElement element) { 1650 void registerReadTypeVariable(TypeVariableElement element) {
1651 readTypeVariables.add(element); 1651 readTypeVariables.add(element);
1652 } 1652 }
1653 } 1653 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698