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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 15934017: Implement InstanceMirror.getField/setField (minified). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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 js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 final CodeBuffer deferredBuffer = new CodeBuffer(); 66 final CodeBuffer deferredBuffer = new CodeBuffer();
67 /** Shorter access to [isolatePropertiesName]. Both here in the code, as 67 /** Shorter access to [isolatePropertiesName]. Both here in the code, as
68 well as in the generated code. */ 68 well as in the generated code. */
69 String isolateProperties; 69 String isolateProperties;
70 String classesCollector; 70 String classesCollector;
71 final Set<ClassElement> neededClasses = new Set<ClassElement>(); 71 final Set<ClassElement> neededClasses = new Set<ClassElement>();
72 final List<ClassElement> regularClasses = <ClassElement>[]; 72 final List<ClassElement> regularClasses = <ClassElement>[];
73 final List<ClassElement> deferredClasses = <ClassElement>[]; 73 final List<ClassElement> deferredClasses = <ClassElement>[];
74 final List<ClassElement> nativeClasses = <ClassElement>[]; 74 final List<ClassElement> nativeClasses = <ClassElement>[];
75 final List<Selector> trivialNsmHandlers = <Selector>[]; 75 final List<Selector> trivialNsmHandlers = <Selector>[];
76 final Map<String, String> mangledFieldNames = <String, String>{};
76 77
77 // TODO(ngeoffray): remove this field. 78 // TODO(ngeoffray): remove this field.
78 Set<ClassElement> instantiatedClasses; 79 Set<ClassElement> instantiatedClasses;
79 80
80 final List<jsAst.Expression> boundClosures = <jsAst.Expression>[]; 81 final List<jsAst.Expression> boundClosures = <jsAst.Expression>[];
81 82
82 JavaScriptBackend get backend => compiler.backend; 83 JavaScriptBackend get backend => compiler.backend;
83 84
84 String get _ => compiler.enableMinification ? "" : " "; 85 String get _ => compiler.enableMinification ? "" : " ";
85 String get n => compiler.enableMinification ? "" : "\n"; 86 String get n => compiler.enableMinification ? "" : "\n";
(...skipping 1367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 } 1454 }
1454 1455
1455 void emitSuper(String superName, ClassBuilder builder) { 1456 void emitSuper(String superName, ClassBuilder builder) {
1456 /* Do nothing. */ 1457 /* Do nothing. */
1457 } 1458 }
1458 1459
1459 void emitRuntimeName(String runtimeName, ClassBuilder builder) { 1460 void emitRuntimeName(String runtimeName, ClassBuilder builder) {
1460 /* Do nothing. */ 1461 /* Do nothing. */
1461 } 1462 }
1462 1463
1464 void recordMangledField(Element member,
1465 String accessorName,
1466 String memberName) {
1467 String previousName = mangledFieldNames.putIfAbsent(
1468 '${namer.getterPrefix}$accessorName',
1469 () => memberName);
1470 assert(invariant(member, previousName == memberName,
1471 message: '$previousName != ${memberName}'));
1472 previousName = mangledFieldNames.putIfAbsent(
1473 '${namer.setterPrefix}$accessorName',
1474 () => '${memberName}=');
1475 assert(invariant(member, previousName == '${memberName}=',
1476 message: '$previousName != ${memberName}='));
1477 }
1478
1463 /// Returns `true` if fields added. 1479 /// Returns `true` if fields added.
1464 bool emitClassFields(ClassElement classElement, 1480 bool emitClassFields(ClassElement classElement,
1465 ClassBuilder builder, 1481 ClassBuilder builder,
1466 String superName, 1482 String superName,
1467 { bool classIsNative: false }) { 1483 { bool classIsNative: false }) {
1468 assert(superName != null); 1484 assert(superName != null);
1469 String separator = ''; 1485 String separator = '';
1470 String nativeName = namer.getPrimitiveInterceptorRuntimeName(classElement); 1486 String nativeName = namer.getPrimitiveInterceptorRuntimeName(classElement);
1471 StringBuffer buffer = new StringBuffer(); 1487 StringBuffer buffer = new StringBuffer();
1472 if (nativeName != null) { 1488 if (nativeName != null) {
(...skipping 20 matching lines...) Expand all
1493 if (!classIsNative || needsAccessor) { 1509 if (!classIsNative || needsAccessor) {
1494 buffer.write(separator); 1510 buffer.write(separator);
1495 separator = ','; 1511 separator = ',';
1496 if (compiler.mirrorsEnabled) { 1512 if (compiler.mirrorsEnabled) {
1497 var metadata = buildMetadataFunction(member); 1513 var metadata = buildMetadataFunction(member);
1498 fieldMetadata.add(metadata); 1514 fieldMetadata.add(metadata);
1499 if (metadata != null) { 1515 if (metadata != null) {
1500 hasMetadata = true; 1516 hasMetadata = true;
1501 } 1517 }
1502 } 1518 }
1519 if (compiler.mirrorsEnabled) {
1520 recordMangledField(member, accessorName, member.name.slowToString());
1521 }
1503 if (!needsAccessor) { 1522 if (!needsAccessor) {
1504 // Emit field for constructor generation. 1523 // Emit field for constructor generation.
1505 assert(!classIsNative); 1524 assert(!classIsNative);
1506 buffer.write(name); 1525 buffer.write(name);
1507 } else { 1526 } else {
1508 // Emit (possibly renaming) field name so we can add accessors at 1527 // Emit (possibly renaming) field name so we can add accessors at
1509 // runtime. 1528 // runtime.
1510 buffer.write(accessorName); 1529 buffer.write(accessorName);
1511 if (name != accessorName) { 1530 if (name != accessorName) {
1512 buffer.write(':$name'); 1531 buffer.write(':$name');
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after
3080 classesCollector = 'classesCollector should not be used from now on'; 3099 classesCollector = 'classesCollector should not be used from now on';
3081 3100
3082 emitStaticFunctions(mainBuffer); 3101 emitStaticFunctions(mainBuffer);
3083 3102
3084 if (!libraryBuffers.isEmpty) { 3103 if (!libraryBuffers.isEmpty) {
3085 var oldClassesCollector = classesCollector; 3104 var oldClassesCollector = classesCollector;
3086 classesCollector = r"$$"; 3105 classesCollector = r"$$";
3087 if (compiler.enableMinification) { 3106 if (compiler.enableMinification) {
3088 mainBuffer.write(';'); 3107 mainBuffer.write(';');
3089 } 3108 }
3109 if (!mangledFieldNames.isEmpty) {
3110 var keys = mangledFieldNames.keys.toList();
3111 keys.sort();
3112 var properties = [];
3113 for (String key in keys) {
3114 var value = js.string('${mangledFieldNames[key]}');
3115 properties.add(new jsAst.Property(js.string(key), value));
3116 }
3117 var map = new jsAst.ObjectInitializer(properties);
3118 mainBuffer.write(
3119 jsAst.prettyPrint(
3120 js('init.mangledNames = #', map).toStatement(), compiler));
3121 if (compiler.enableMinification) {
3122 mainBuffer.write(';');
3123 }
3124 }
3090 mainBuffer 3125 mainBuffer
3091 ..write(getReflectionDataParser()) 3126 ..write(getReflectionDataParser())
3092 ..write('([$n'); 3127 ..write('([$n');
3093 emitDeferredPreambleWhenEmpty(deferredBuffer); 3128 emitDeferredPreambleWhenEmpty(deferredBuffer);
3094 deferredBuffer.add('\$\$$_=$_{};$n'); 3129 deferredBuffer.add('\$\$$_=$_{};$n');
3095 3130
3096 deferredBuffer 3131 deferredBuffer
3097 ..write(getReflectionDataParser()) 3132 ..write(getReflectionDataParser())
3098 ..write('([$n'); 3133 ..write('([$n');
3099 var sortedLibraries = Elements.sortedByPosition(libraryBuffers.keys); 3134 var sortedLibraries = Elements.sortedByPosition(libraryBuffers.keys);
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
3349 3384
3350 const String HOOKS_API_USAGE = """ 3385 const String HOOKS_API_USAGE = """
3351 // The code supports the following hooks: 3386 // The code supports the following hooks:
3352 // dartPrint(message) - if this function is defined it is called 3387 // dartPrint(message) - if this function is defined it is called
3353 // instead of the Dart [print] method. 3388 // instead of the Dart [print] method.
3354 // dartMainRunner(main) - if this function is defined, the Dart [main] 3389 // dartMainRunner(main) - if this function is defined, the Dart [main]
3355 // method will not be invoked directly. 3390 // method will not be invoked directly.
3356 // Instead, a closure that will invoke [main] is 3391 // Instead, a closure that will invoke [main] is
3357 // passed to [dartMainRunner]. 3392 // passed to [dartMainRunner].
3358 """; 3393 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698