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

Side by Side Diff: frog/leg/emitter.dart

Issue 9360039: Create values for literal Strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test. Created 8 years, 10 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 /** 5 /**
6 * Generates the code for all used classes in the program. Static fields (even 6 * Generates the code for all used classes in the program. Static fields (even
7 * in classes) are ignored, since they can be treated as non-class elements. 7 * in classes) are ignored, since they can be treated as non-class elements.
8 * 8 *
9 * The code for the containing (used) methods must exist in the [:universe:]. 9 * The code for the containing (used) methods must exist in the [:universe:].
10 */ 10 */
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 parametersBuffer[count] = jsName; 100 parametersBuffer[count] = jsName;
101 argumentsBuffer[count] = jsName; 101 argumentsBuffer[count] = jsName;
102 } else { 102 } else {
103 int index = names.indexOf(element.name); 103 int index = names.indexOf(element.name);
104 if (index != -1) { 104 if (index != -1) {
105 // The order of the named arguments is not the same as the 105 // The order of the named arguments is not the same as the
106 // one in the real method (which is in Dart source order). 106 // one in the real method (which is in Dart source order).
107 argumentsBuffer[count] = jsName; 107 argumentsBuffer[count] = jsName;
108 parametersBuffer[selector.positionalArgumentCount + index] = jsName; 108 parametersBuffer[selector.positionalArgumentCount + index] = jsName;
109 } else { 109 } else {
110 argumentsBuffer[count] = constants.getJsCodeForVariable(element); 110 var value = constants.writeJsCodeForVariable(new StringBuffer(), eleme nt);
floitsch 2012/02/14 16:08:02 80 chars.
karlklose 2012/02/15 10:37:30 Done.
111 argumentsBuffer[count] = value.toString();
111 } 112 }
112 } 113 }
113 count++; 114 count++;
114 }); 115 });
115 116
116 buffer.add('${Strings.join(parametersBuffer, ",")}) {\n'); 117 buffer.add('${Strings.join(parametersBuffer, ",")}) {\n');
117 buffer.add(' return this.${namer.getName(member)}'); 118 buffer.add(' return this.${namer.getName(member)}');
118 buffer.add('(${Strings.join(argumentsBuffer, ",")})\n}\n'); 119 buffer.add('(${Strings.join(argumentsBuffer, ",")})\n}\n');
119 } 120 }
120 121
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // this.staticNonFinal = Isolate.prototype.someVal; 296 // this.staticNonFinal = Isolate.prototype.someVal;
296 // ... 297 // ...
297 // } 298 // }
298 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; 299 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler;
299 List<VariableElement> staticNonFinalFields = 300 List<VariableElement> staticNonFinalFields =
300 constants.getStaticNonFinalFieldsForEmission(); 301 constants.getStaticNonFinalFieldsForEmission();
301 if (!staticNonFinalFields.isEmpty()) buffer.add('\n'); 302 if (!staticNonFinalFields.isEmpty()) buffer.add('\n');
302 for (Element element in staticNonFinalFields) { 303 for (Element element in staticNonFinalFields) {
303 buffer.add(' this.${namer.getName(element)} = '); 304 buffer.add(' this.${namer.getName(element)} = ');
304 compiler.withCurrentElement(element, () { 305 compiler.withCurrentElement(element, () {
305 buffer.add(constants.getJsCodeForVariable(element)); 306 constants.writeJsCodeForVariable(buffer, element);
306 }); 307 });
307 buffer.add(';\n'); 308 buffer.add(';\n');
308 } 309 }
309 } 310 }
310 311
311 void emitStaticFinalFieldInitializations(StringBuffer buffer) { 312 void emitStaticFinalFieldInitializations(StringBuffer buffer) {
312 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; 313 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler;
313 List<VariableElement> staticFinalFields = 314 List<VariableElement> staticFinalFields =
314 constants.getStaticFinalFieldsForEmission(); 315 constants.getStaticFinalFieldsForEmission();
315 for (VariableElement element in staticFinalFields) { 316 for (VariableElement element in staticFinalFields) {
316 buffer.add('${namer.isolatePropertyAccess(element)} = '); 317 buffer.add('${namer.isolatePropertyAccess(element)} = ');
317 compiler.withCurrentElement(element, () { 318 compiler.withCurrentElement(element, () {
318 buffer.add(constants.getJsCodeForVariable(element)); 319 constants.writeJsCodeForVariable(buffer, element);
319 }); 320 });
320 buffer.add(';\n'); 321 buffer.add(';\n');
321 } 322 }
322 } 323 }
323 324
324 void emitNoSuchMethodCalls(StringBuffer buffer) { 325 void emitNoSuchMethodCalls(StringBuffer buffer) {
325 // Do not generate no such method calls if there is no class. 326 // Do not generate no such method calls if there is no class.
326 if (compiler.universe.instantiatedClasses.isEmpty()) return; 327 if (compiler.universe.instantiatedClasses.isEmpty()) return;
327 328
328 // TODO(ngeoffray): We don't need to generate these methods if 329 // TODO(ngeoffray): We don't need to generate these methods if
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 emitStaticFunctionGetters(buffer); 383 emitStaticFunctionGetters(buffer);
383 emitStaticFinalFieldInitializations(buffer); 384 emitStaticFinalFieldInitializations(buffer);
384 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); 385 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n');
385 Element main = compiler.mainApp.find(Compiler.MAIN); 386 Element main = compiler.mainApp.find(Compiler.MAIN);
386 buffer.add('${namer.isolateAccess(main)}();\n'); 387 buffer.add('${namer.isolateAccess(main)}();\n');
387 compiler.assembledCode = buffer.toString(); 388 compiler.assembledCode = buffer.toString();
388 }); 389 });
389 return compiler.assembledCode; 390 return compiler.assembledCode;
390 } 391 }
391 } 392 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698