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

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: Address comments and cosmetic changes. 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
« no previous file with comments | « lib/compiler/implementation/namer.dart ('k') | tests/language/naming3_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 nativeBuffer.add(' = '); 77 nativeBuffer.add(' = ');
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 compiler.emitter.addInstanceMember(member, defineInstanceMember); 87 bool needGettersAndSetters = true;
88 compiler.emitter.addInstanceMember(
89 member, needGettersAndSetters, defineInstanceMember);
88 } 90 }
89 } 91 }
90 } 92 }
91 93
92 bool isNativeLiteral(String quotedName) { 94 bool isNativeLiteral(String quotedName) {
93 return quotedName[1] === '='; 95 return quotedName[1] === '=';
94 } 96 }
95 97
96 bool isNativeGlobal(String quotedName) { 98 bool isNativeGlobal(String quotedName) {
97 return quotedName[1] === '@'; 99 return quotedName[1] === '@';
(...skipping 24 matching lines...) Expand all
122 String nativeName = toNativeName(classElement); 124 String nativeName = toNativeName(classElement);
123 bool hasUsedSelectors = false; 125 bool hasUsedSelectors = false;
124 126
125 void defineInstanceMember(String name, String value) { 127 void defineInstanceMember(String name, String value) {
126 hasUsedSelectors = true; 128 hasUsedSelectors = true;
127 nativeBuffer.add("$dynamicName('$name').$nativeName = $value;\n"); 129 nativeBuffer.add("$dynamicName('$name').$nativeName = $value;\n");
128 } 130 }
129 131
130 for (Element member in classElement.members) { 132 for (Element member in classElement.members) {
131 if (member.isInstanceMember()) { 133 if (member.isInstanceMember()) {
132 compiler.emitter.addInstanceMember(member, defineInstanceMember); 134 bool needGettersAndSetters = true;
135 compiler.emitter.addInstanceMember(
136 member, needGettersAndSetters, defineInstanceMember);
133 } 137 }
134 } 138 }
135 139
136 compiler.emitter.generateTypeTests(classElement, (Element other) { 140 compiler.emitter.generateTypeTests(classElement, (Element other) {
137 assert(requiresNativeIsCheck(other)); 141 assert(requiresNativeIsCheck(other));
138 defineInstanceMember(compiler.namer.operatorIs(other), 142 defineInstanceMember(compiler.namer.operatorIs(other),
139 "function() { return true; }"); 143 "function() { return true; }");
140 }); 144 });
141 145
142 if (hasUsedSelectors) classesWithDynamicDispatch.add(classElement); 146 if (hasUsedSelectors) classesWithDynamicDispatch.add(classElement);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 String toStringName = compiler.namer.instanceMethodName( 375 String toStringName = compiler.namer.instanceMethodName(
372 null, const SourceString('toString'), 0); 376 null, const SourceString('toString'), 0);
373 objectProperties.add("$defPropName(Object.prototype, '$toStringName', "); 377 objectProperties.add("$defPropName(Object.prototype, '$toStringName', ");
374 objectProperties.add( 378 objectProperties.add(
375 'function() { return $toStringHelperName(this); });\n'); 379 'function() { return $toStringHelperName(this); });\n');
376 380
377 // Finally, emit the code in the main buffer. 381 // Finally, emit the code in the main buffer.
378 targetBuffer.add('(function() {\n$objectProperties$nativeBuffer\n})();\n'); 382 targetBuffer.add('(function() {\n$objectProperties$nativeBuffer\n})();\n');
379 } 383 }
380 } 384 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/namer.dart ('k') | tests/language/naming3_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698