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

Side by Side Diff: lib/compiler/implementation/native_emitter.dart

Issue 10386086: RFC: Start refactoring to provide more than a single backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Next iteration Created 8 years, 7 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 class NativeEmitter { 5 class NativeEmitter {
6 6
7 Compiler compiler; 7 Emitter emitter;
8 StringBuffer nativeBuffer; 8 StringBuffer nativeBuffer;
9 9
10 // Classes that participate in dynamic dispatch. These are the 10 // Classes that participate in dynamic dispatch. These are the
11 // classes that contain used members. 11 // classes that contain used members.
12 Set<ClassElement> classesWithDynamicDispatch; 12 Set<ClassElement> classesWithDynamicDispatch;
13 13
14 // Native classes found in the application. 14 // Native classes found in the application.
15 Set<ClassElement> nativeClasses; 15 Set<ClassElement> nativeClasses;
16 16
17 // Caches the native subtypes of a native class. 17 // Caches the native subtypes of a native class.
18 Map<ClassElement, List<ClassElement>> subtypes; 18 Map<ClassElement, List<ClassElement>> subtypes;
19 19
20 // Caches the direct native subtypes of a native class. 20 // Caches the direct native subtypes of a native class.
21 Map<ClassElement, List<ClassElement>> directSubtypes; 21 Map<ClassElement, List<ClassElement>> directSubtypes;
22 22
23 // Caches the native methods that are overridden by a native class. 23 // Caches the native methods that are overridden by a native class.
24 // Note that the method that overrides does not have to be native: 24 // Note that the method that overrides does not have to be native:
25 // it's the overridden method that must make sure it will dispatch 25 // it's the overridden method that must make sure it will dispatch
26 // to its subclass if it sees an instance whose class is a subclass. 26 // to its subclass if it sees an instance whose class is a subclass.
27 Set<FunctionElement> overriddenMethods; 27 Set<FunctionElement> overriddenMethods;
28 28
29 // Caches the methods that should just call a native JS 29 // Caches the methods that should just call a native JS
30 // implementation. 30 // implementation.
31 Set<FunctionElement> nativeMethods; 31 Set<FunctionElement> nativeMethods;
32 32
33 NativeEmitter(this.compiler) 33 NativeEmitter(this.emitter)
34 : classesWithDynamicDispatch = new Set<ClassElement>(), 34 : classesWithDynamicDispatch = new Set<ClassElement>(),
35 nativeClasses = new Set<ClassElement>(), 35 nativeClasses = new Set<ClassElement>(),
36 subtypes = new Map<ClassElement, List<ClassElement>>(), 36 subtypes = new Map<ClassElement, List<ClassElement>>(),
37 directSubtypes = new Map<ClassElement, List<ClassElement>>(), 37 directSubtypes = new Map<ClassElement, List<ClassElement>>(),
38 overriddenMethods = new Set<FunctionElement>(), 38 overriddenMethods = new Set<FunctionElement>(),
39 nativeMethods = new Set<FunctionElement>(), 39 nativeMethods = new Set<FunctionElement>(),
40 nativeBuffer = new StringBuffer(); 40 nativeBuffer = new StringBuffer();
41 41
42 Compiler get compiler() => emitter.compiler;
43
42 String get dynamicName() { 44 String get dynamicName() {
43 Element element = compiler.findHelper( 45 Element element = compiler.findHelper(
44 const SourceString('dynamicFunction')); 46 const SourceString('dynamicFunction'));
45 return compiler.namer.isolateAccess(element); 47 return compiler.namer.isolateAccess(element);
46 } 48 }
47 49
48 String get dynamicSetMetadataName() { 50 String get dynamicSetMetadataName() {
49 Element element = compiler.findHelper( 51 Element element = compiler.findHelper(
50 const SourceString('dynamicSetMetadata')); 52 const SourceString('dynamicSetMetadata'));
51 return compiler.namer.isolateAccess(element); 53 return compiler.namer.isolateAccess(element);
(...skipping 26 matching lines...) Expand all
78 nativeBuffer.add(nativeCode); 80 nativeBuffer.add(nativeCode);
79 nativeBuffer.add(';\n'); 81 nativeBuffer.add(';\n');
80 82
81 void defineInstanceMember(String name, String value) { 83 void defineInstanceMember(String name, String value) {
82 nativeBuffer.add("$className.$name = $value;\n"); 84 nativeBuffer.add("$className.$name = $value;\n");
83 } 85 }
84 86
85 for (Element member in classElement.members) { 87 for (Element member in classElement.members) {
86 if (member.isInstanceMember()) { 88 if (member.isInstanceMember()) {
87 bool needGettersAndSetters = true; 89 bool needGettersAndSetters = true;
88 compiler.emitter.addInstanceMember( 90 emitter.addInstanceMember(
89 member, needGettersAndSetters, defineInstanceMember); 91 member, needGettersAndSetters, defineInstanceMember);
90 } 92 }
91 } 93 }
92 } 94 }
93 95
94 bool isNativeLiteral(String quotedName) { 96 bool isNativeLiteral(String quotedName) {
95 return quotedName[1] === '='; 97 return quotedName[1] === '=';
96 } 98 }
97 99
98 bool isNativeGlobal(String quotedName) { 100 bool isNativeGlobal(String quotedName) {
(...skipping 26 matching lines...) Expand all
125 bool hasUsedSelectors = false; 127 bool hasUsedSelectors = false;
126 128
127 void defineInstanceMember(String name, String value) { 129 void defineInstanceMember(String name, String value) {
128 hasUsedSelectors = true; 130 hasUsedSelectors = true;
129 nativeBuffer.add("$dynamicName('$name').$nativeName = $value;\n"); 131 nativeBuffer.add("$dynamicName('$name').$nativeName = $value;\n");
130 } 132 }
131 133
132 for (Element member in classElement.members) { 134 for (Element member in classElement.members) {
133 if (member.isInstanceMember()) { 135 if (member.isInstanceMember()) {
134 bool needGettersAndSetters = true; 136 bool needGettersAndSetters = true;
135 compiler.emitter.addInstanceMember( 137 emitter.addInstanceMember(
136 member, needGettersAndSetters, defineInstanceMember); 138 member, needGettersAndSetters, defineInstanceMember);
137 } 139 }
138 } 140 }
139 141
140 compiler.emitter.generateTypeTests(classElement, (Element other) { 142 emitter.generateTypeTests(classElement, (Element other) {
141 assert(requiresNativeIsCheck(other)); 143 assert(requiresNativeIsCheck(other));
142 defineInstanceMember(compiler.namer.operatorIs(other), 144 defineInstanceMember(compiler.namer.operatorIs(other),
143 "function() { return true; }"); 145 "function() { return true; }");
144 }); 146 });
145 147
146 if (hasUsedSelectors) classesWithDynamicDispatch.add(classElement); 148 if (hasUsedSelectors) classesWithDynamicDispatch.add(classElement);
147 } 149 }
148 150
149 List<ClassElement> getDirectSubclasses(ClassElement cls) { 151 List<ClassElement> getDirectSubclasses(ClassElement cls) {
150 List<ClassElement> result = directSubtypes[cls]; 152 List<ClassElement> result = directSubtypes[cls];
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 String toStringName = compiler.namer.instanceMethodName( 377 String toStringName = compiler.namer.instanceMethodName(
376 null, const SourceString('toString'), 0); 378 null, const SourceString('toString'), 0);
377 objectProperties.add("$defPropName(Object.prototype, '$toStringName', "); 379 objectProperties.add("$defPropName(Object.prototype, '$toStringName', ");
378 objectProperties.add( 380 objectProperties.add(
379 'function() { return $toStringHelperName(this); });\n'); 381 'function() { return $toStringHelperName(this); });\n');
380 382
381 // Finally, emit the code in the main buffer. 383 // Finally, emit the code in the main buffer.
382 targetBuffer.add('(function() {\n$objectProperties$nativeBuffer\n})();\n'); 384 targetBuffer.add('(function() {\n$objectProperties$nativeBuffer\n})();\n');
383 } 385 }
384 } 386 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698