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

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: 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 Compiler compiler;
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
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 nativeBuffer.add(nativeCode); 78 nativeBuffer.add(nativeCode);
79 nativeBuffer.add(';\n'); 79 nativeBuffer.add(';\n');
80 80
81 void defineInstanceMember(String name, String value) { 81 void defineInstanceMember(String name, String value) {
82 nativeBuffer.add("$className.$name = $value;\n"); 82 nativeBuffer.add("$className.$name = $value;\n");
83 } 83 }
84 84
85 for (Element member in classElement.members) { 85 for (Element member in classElement.members) {
86 if (member.isInstanceMember()) { 86 if (member.isInstanceMember()) {
87 bool needGettersAndSetters = true; 87 bool needGettersAndSetters = true;
88 compiler.emitter.addInstanceMember( 88 compiler.backend.emitter.addInstanceMember(
89 member, needGettersAndSetters, defineInstanceMember); 89 member, needGettersAndSetters, defineInstanceMember);
90 } 90 }
91 } 91 }
92 } 92 }
93 93
94 bool isNativeLiteral(String quotedName) { 94 bool isNativeLiteral(String quotedName) {
95 return quotedName[1] === '='; 95 return quotedName[1] === '=';
96 } 96 }
97 97
98 bool isNativeGlobal(String quotedName) { 98 bool isNativeGlobal(String quotedName) {
(...skipping 26 matching lines...) Expand all
125 bool hasUsedSelectors = false; 125 bool hasUsedSelectors = false;
126 126
127 void defineInstanceMember(String name, String value) { 127 void defineInstanceMember(String name, String value) {
128 hasUsedSelectors = true; 128 hasUsedSelectors = true;
129 nativeBuffer.add("$dynamicName('$name').$nativeName = $value;\n"); 129 nativeBuffer.add("$dynamicName('$name').$nativeName = $value;\n");
130 } 130 }
131 131
132 for (Element member in classElement.members) { 132 for (Element member in classElement.members) {
133 if (member.isInstanceMember()) { 133 if (member.isInstanceMember()) {
134 bool needGettersAndSetters = true; 134 bool needGettersAndSetters = true;
135 compiler.emitter.addInstanceMember( 135 compiler.backend.emitter.addInstanceMember(
136 member, needGettersAndSetters, defineInstanceMember); 136 member, needGettersAndSetters, defineInstanceMember);
137 } 137 }
138 } 138 }
139 139
140 compiler.emitter.generateTypeTests(classElement, (Element other) { 140 compiler.backend.emitter.generateTypeTests(classElement, (Element other) {
141 assert(requiresNativeIsCheck(other)); 141 assert(requiresNativeIsCheck(other));
142 defineInstanceMember(compiler.namer.operatorIs(other), 142 defineInstanceMember(compiler.namer.operatorIs(other),
143 "function() { return true; }"); 143 "function() { return true; }");
144 }); 144 });
145 145
146 if (hasUsedSelectors) classesWithDynamicDispatch.add(classElement); 146 if (hasUsedSelectors) classesWithDynamicDispatch.add(classElement);
147 } 147 }
148 148
149 List<ClassElement> getDirectSubclasses(ClassElement cls) { 149 List<ClassElement> getDirectSubclasses(ClassElement cls) {
150 List<ClassElement> result = directSubtypes[cls]; 150 List<ClassElement> result = directSubtypes[cls];
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 String toStringName = compiler.namer.instanceMethodName( 375 String toStringName = compiler.namer.instanceMethodName(
376 null, const SourceString('toString'), 0); 376 null, const SourceString('toString'), 0);
377 objectProperties.add("$defPropName(Object.prototype, '$toStringName', "); 377 objectProperties.add("$defPropName(Object.prototype, '$toStringName', ");
378 objectProperties.add( 378 objectProperties.add(
379 'function() { return $toStringHelperName(this); });\n'); 379 'function() { return $toStringHelperName(this); });\n');
380 380
381 // Finally, emit the code in the main buffer. 381 // Finally, emit the code in the main buffer.
382 targetBuffer.add('(function() {\n$objectProperties$nativeBuffer\n})();\n'); 382 targetBuffer.add('(function() {\n$objectProperties$nativeBuffer\n})();\n');
383 } 383 }
384 } 384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698