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

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

Issue 10310060: Generate getters and setters dynamically. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Simplify by using a bool. 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
7 Compiler compiler; 6 Compiler compiler;
8 StringBuffer nativeBuffer; 7 StringBuffer nativeBuffer;
9 8
10 // Classes that participate in dynamic dispatch. These are the 9 // Classes that participate in dynamic dispatch. These are the
11 // classes that contain used members. 10 // classes that contain used members.
12 Set<ClassElement> classesWithDynamicDispatch; 11 Set<ClassElement> classesWithDynamicDispatch;
13 12
14 // Native classes found in the application. 13 // Native classes found in the application.
15 Set<ClassElement> nativeClasses; 14 Set<ClassElement> nativeClasses;
16 15
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 nativeBuffer.add(' = '); 76 nativeBuffer.add(' = ');
78 nativeBuffer.add(nativeCode); 77 nativeBuffer.add(nativeCode);
79 nativeBuffer.add(';\n'); 78 nativeBuffer.add(';\n');
80 79
81 void defineInstanceMember(String name, String value) { 80 void defineInstanceMember(String name, String value) {
82 nativeBuffer.add("$className.$name = $value;\n"); 81 nativeBuffer.add("$className.$name = $value;\n");
83 } 82 }
84 83
85 for (Element member in classElement.members) { 84 for (Element member in classElement.members) {
86 if (member.isInstanceMember()) { 85 if (member.isInstanceMember()) {
87 compiler.emitter.addInstanceMember(member, defineInstanceMember); 86 bool needGettersAndSetters = true;
87 compiler.emitter.addInstanceMember(
88 member, needGettersAndSetters, defineInstanceMember);
88 } 89 }
89 } 90 }
90 } 91 }
91 92
92 bool isNativeLiteral(String quotedName) { 93 bool isNativeLiteral(String quotedName) {
93 return quotedName[1] === '='; 94 return quotedName[1] === '=';
94 } 95 }
95 96
96 bool isNativeGlobal(String quotedName) { 97 bool isNativeGlobal(String quotedName) {
97 return quotedName[1] === '@'; 98 return quotedName[1] === '@';
(...skipping 24 matching lines...) Expand all
122 String nativeName = toNativeName(classElement); 123 String nativeName = toNativeName(classElement);
123 bool hasUsedSelectors = false; 124 bool hasUsedSelectors = false;
124 125
125 void defineInstanceMember(String name, String value) { 126 void defineInstanceMember(String name, String value) {
126 hasUsedSelectors = true; 127 hasUsedSelectors = true;
127 nativeBuffer.add("$dynamicName('$name').$nativeName = $value;\n"); 128 nativeBuffer.add("$dynamicName('$name').$nativeName = $value;\n");
128 } 129 }
129 130
130 for (Element member in classElement.members) { 131 for (Element member in classElement.members) {
131 if (member.isInstanceMember()) { 132 if (member.isInstanceMember()) {
132 compiler.emitter.addInstanceMember(member, defineInstanceMember); 133 bool needGettersAndSetters = true;
134 compiler.emitter.addInstanceMember(
135 member, needGettersAndSetters, defineInstanceMember);
133 } 136 }
134 } 137 }
135 138
136 compiler.emitter.generateTypeTests(classElement, (Element other) { 139 compiler.emitter.generateTypeTests(classElement, (Element other) {
137 assert(requiresNativeIsCheck(other)); 140 assert(requiresNativeIsCheck(other));
138 defineInstanceMember(compiler.namer.operatorIs(other), 141 defineInstanceMember(compiler.namer.operatorIs(other),
139 "function() { return true; }"); 142 "function() { return true; }");
140 }); 143 });
141 144
142 if (hasUsedSelectors) classesWithDynamicDispatch.add(classElement); 145 if (hasUsedSelectors) classesWithDynamicDispatch.add(classElement);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 String toStringName = compiler.namer.instanceMethodName( 374 String toStringName = compiler.namer.instanceMethodName(
372 null, const SourceString('toString'), 0); 375 null, const SourceString('toString'), 0);
373 objectProperties.add("$defPropName(Object.prototype, '$toStringName', "); 376 objectProperties.add("$defPropName(Object.prototype, '$toStringName', ");
374 objectProperties.add( 377 objectProperties.add(
375 'function() { return $toStringHelperName(this); });\n'); 378 'function() { return $toStringHelperName(this); });\n');
376 379
377 // Finally, emit the code in the main buffer. 380 // Finally, emit the code in the main buffer.
378 targetBuffer.add('(function() {\n$objectProperties$nativeBuffer\n})();\n'); 381 targetBuffer.add('(function() {\n$objectProperties$nativeBuffer\n})();\n');
379 } 382 }
380 } 383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698