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

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

Issue 25675002: Generative constructor factories for native objects (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 } 1486 }
1487 1487
1488 /** 1488 /**
1489 * Emit initializer for [mapTypeToInterceptor] data structure used by 1489 * Emit initializer for [mapTypeToInterceptor] data structure used by
1490 * [findInterceptorForType]. See declaration of [mapTypeToInterceptor] in 1490 * [findInterceptorForType]. See declaration of [mapTypeToInterceptor] in
1491 * `interceptors.dart`. 1491 * `interceptors.dart`.
1492 */ 1492 */
1493 void emitMapTypeToInterceptor(CodeBuffer buffer) { 1493 void emitMapTypeToInterceptor(CodeBuffer buffer) {
1494 // TODO(sra): Perhaps inject a constant instead? 1494 // TODO(sra): Perhaps inject a constant instead?
1495 // TODO(sra): Filter by subclasses of native types. 1495 // TODO(sra): Filter by subclasses of native types.
1496 // TODO(13835): Don't generate this unless we generated the functions that
1497 // use the data structure.
1496 List<jsAst.Expression> elements = <jsAst.Expression>[]; 1498 List<jsAst.Expression> elements = <jsAst.Expression>[];
1497 ConstantHandler handler = compiler.constantHandler; 1499 ConstantHandler handler = compiler.constantHandler;
1498 List<Constant> constants = handler.getConstantsForEmission(); 1500 List<Constant> constants = handler.getConstantsForEmission();
1499 for (Constant constant in constants) { 1501 for (Constant constant in constants) {
1500 if (constant is TypeConstant) { 1502 if (constant is TypeConstant) {
1501 TypeConstant typeConstant = constant; 1503 TypeConstant typeConstant = constant;
1502 Element element = typeConstant.representedType.element; 1504 Element element = typeConstant.representedType.element;
1503 if (element is ClassElement) { 1505 if (element is ClassElement) {
1504 ClassElement classElement = element; 1506 ClassElement classElement = element;
1505 elements.add(backend.emitter.constantReference(constant)); 1507 elements.add(backend.emitter.constantReference(constant));
1506 elements.add(js(namer.isolateAccess(classElement))); 1508 elements.add(js(namer.isolateAccess(classElement)));
1509
1510 // Create JavaScript Object map for by-name lookup of generative
1511 // constructors. For example, the class A has three generative
1512 // constructors
1513 //
1514 // class A {
1515 // A() {}
1516 // A.foo() {}
1517 // A.bar() {}
1518 // }
1519 //
1520 // Which are described by the map
1521 //
1522 // {"": A.A$, "foo": A.A$foo, "bar": A.A$bar}
1523 //
1524 // We expect most of the time the map will be a singleton.
1525 var properties = [];
1526 classElement.forEachMember(
1527 (ClassElement enclosingClass, Element member) {
1528 if (member.isGenerativeConstructor()) {
1529 properties.add(
1530 new jsAst.Property(
1531 js.string(member.name.slowToString()),
1532 new jsAst.VariableUse(
1533 backend.namer.isolateAccess(member))));
1534 }
1535 },
1536 includeBackendMembers: false,
1537 includeSuperAndInjectedMembers: false);
1538
1539 var map = new jsAst.ObjectInitializer(properties);
1540 elements.add(map);
1507 } 1541 }
1508 } 1542 }
1509 } 1543 }
1510 1544
1511 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer.from(elements); 1545 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer.from(elements);
1512 String name = 1546 String name =
1513 backend.namer.getNameOfGlobalField(backend.mapTypeToInterceptor); 1547 backend.namer.getNameOfGlobalField(backend.mapTypeToInterceptor);
1514 jsAst.Expression assignment = js('$isolateProperties.$name = #', array); 1548 jsAst.Expression assignment = js('$isolateProperties.$name = #', array);
1515 1549
1516 buffer.write(jsAst.prettyPrint(assignment, compiler)); 1550 buffer.write(jsAst.prettyPrint(assignment, compiler));
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 return compiler.deferredLoadTask.isDeferred(element); 2146 return compiler.deferredLoadTask.isDeferred(element);
2113 } 2147 }
2114 2148
2115 bool get areAnyElementsDeferred { 2149 bool get areAnyElementsDeferred {
2116 return compiler.deferredLoadTask.areAnyElementsDeferred; 2150 return compiler.deferredLoadTask.areAnyElementsDeferred;
2117 } 2151 }
2118 } 2152 }
2119 2153
2120 // TODO(ahe): Move code for interceptors to own file. 2154 // TODO(ahe): Move code for interceptors to own file.
2121 // TODO(ahe): Move code for reifying metadata/types to own file. 2155 // TODO(ahe): Move code for reifying metadata/types to own file.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698