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

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

Issue 9315028: Support default values for optional parameters. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' 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
« no previous file with comments | « dart/frog/leg/compiler.dart ('k') | dart/frog/leg/resolver.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 29 matching lines...) Expand all
40 void addParameterStub(FunctionElement member, 40 void addParameterStub(FunctionElement member,
41 String prototype, 41 String prototype,
42 StringBuffer buffer, 42 StringBuffer buffer,
43 Selector selector) { 43 Selector selector) {
44 FunctionParameters parameters = member.computeParameters(compiler); 44 FunctionParameters parameters = member.computeParameters(compiler);
45 int positionalArgumentCount = selector.positionalArgumentCount; 45 int positionalArgumentCount = selector.positionalArgumentCount;
46 if (positionalArgumentCount == parameters.parameterCount) { 46 if (positionalArgumentCount == parameters.parameterCount) {
47 assert(selector.namedArgumentCount == 0); 47 assert(selector.namedArgumentCount == 0);
48 return; 48 return;
49 } 49 }
50 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler;
50 List<SourceString> names = selector.getOrderedNamedArguments(); 51 List<SourceString> names = selector.getOrderedNamedArguments();
51 52
52 String invocationName = 53 String invocationName =
53 namer.instanceMethodInvocationName(member.name, selector); 54 namer.instanceMethodInvocationName(member.name, selector);
54 buffer.add('$prototype.$invocationName = function('); 55 buffer.add('$prototype.$invocationName = function(');
55 56
56 // The parameters that this stub takes. 57 // The parameters that this stub takes.
57 List<String> parametersBuffer = new List<String>(selector.argumentCount); 58 List<String> parametersBuffer = new List<String>(selector.argumentCount);
58 // The arguments that will be passed to the real method. 59 // The arguments that will be passed to the real method.
59 List<String> argumentsBuffer = new List<String>(parameters.parameterCount); 60 List<String> argumentsBuffer = new List<String>(parameters.parameterCount);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 parametersBuffer[count] = jsName; 100 parametersBuffer[count] = jsName;
100 argumentsBuffer[count] = jsName; 101 argumentsBuffer[count] = jsName;
101 } else { 102 } else {
102 int index = names.indexOf(element.name); 103 int index = names.indexOf(element.name);
103 if (index != -1) { 104 if (index != -1) {
104 // 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
105 // one in the real method (which is in Dart source order). 106 // one in the real method (which is in Dart source order).
106 argumentsBuffer[count] = jsName; 107 argumentsBuffer[count] = jsName;
107 parametersBuffer[selector.positionalArgumentCount + index] = jsName; 108 parametersBuffer[selector.positionalArgumentCount + index] = jsName;
108 } else { 109 } else {
109 // TODO(ngeoffray): Get the default value. 110 argumentsBuffer[count] = constants.getJsCodeForVariable(element);
110 argumentsBuffer[count] = '(void 0)';
111 } 111 }
112 } 112 }
113 count++; 113 count++;
114 }); 114 });
115 115
116 buffer.add('${Strings.join(parametersBuffer, ",")}) {\n'); 116 buffer.add('${Strings.join(parametersBuffer, ",")}) {\n');
117 buffer.add(' return this.${namer.getName(member)}'); 117 buffer.add(' return this.${namer.getName(member)}');
118 buffer.add('(${Strings.join(argumentsBuffer, ",")})\n}\n'); 118 buffer.add('(${Strings.join(argumentsBuffer, ",")})\n}\n');
119 } 119 }
120 120
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // function Isolate() { 260 // function Isolate() {
261 // this.staticNonFinal = Isolate.prototype.someVal; 261 // this.staticNonFinal = Isolate.prototype.someVal;
262 // ... 262 // ...
263 // } 263 // }
264 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; 264 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler;
265 List<VariableElement> staticNonFinalFields = 265 List<VariableElement> staticNonFinalFields =
266 constants.getStaticNonFinalFieldsForEmission(); 266 constants.getStaticNonFinalFieldsForEmission();
267 if (!staticNonFinalFields.isEmpty()) buffer.add('\n'); 267 if (!staticNonFinalFields.isEmpty()) buffer.add('\n');
268 for (Element element in staticNonFinalFields) { 268 for (Element element in staticNonFinalFields) {
269 buffer.add(' this.${namer.getName(element)} = '); 269 buffer.add(' this.${namer.getName(element)} = ');
270 constants.emitJsCodeForField(element, buffer); 270 buffer.add(constants.getJsCodeForVariable(element));
271 buffer.add(';\n'); 271 buffer.add(';\n');
272 } 272 }
273 } 273 }
274 274
275 void emitStaticFinalFieldInitializations(StringBuffer buffer) { 275 void emitStaticFinalFieldInitializations(StringBuffer buffer) {
276 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; 276 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler;
277 List<VariableElement> staticFinalFields = 277 List<VariableElement> staticFinalFields =
278 constants.getStaticFinalFieldsForEmission(); 278 constants.getStaticFinalFieldsForEmission();
279 for (VariableElement element in staticFinalFields) { 279 for (VariableElement element in staticFinalFields) {
280 buffer.add('${namer.isolatePropertyAccess(element)} = '); 280 buffer.add('${namer.isolatePropertyAccess(element)} = ');
281 constants.emitJsCodeForField(element, buffer); 281 buffer.add(constants.getJsCodeForVariable(element));
282 buffer.add(';\n'); 282 buffer.add(';\n');
283 } 283 }
284 } 284 }
285 285
286 void emitNoSuchMethodCalls(StringBuffer buffer) { 286 void emitNoSuchMethodCalls(StringBuffer buffer) {
287 // Do not generate no such method calls if there is no class. 287 // Do not generate no such method calls if there is no class.
288 if (compiler.universe.instantiatedClasses.isEmpty()) return; 288 if (compiler.universe.instantiatedClasses.isEmpty()) return;
289 289
290 // TODO(ngeoffray): We don't need to generate these methods if 290 // TODO(ngeoffray): We don't need to generate these methods if
291 // nobody overwrites noSuchMethod. 291 // nobody overwrites noSuchMethod.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 emitStaticFunctions(buffer); 343 emitStaticFunctions(buffer);
344 emitStaticFinalFieldInitializations(buffer); 344 emitStaticFinalFieldInitializations(buffer);
345 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); 345 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n');
346 Element main = compiler.universe.find(Compiler.MAIN); 346 Element main = compiler.universe.find(Compiler.MAIN);
347 buffer.add('${namer.isolateAccess(main)}();\n'); 347 buffer.add('${namer.isolateAccess(main)}();\n');
348 compiler.assembledCode = buffer.toString(); 348 compiler.assembledCode = buffer.toString();
349 }); 349 });
350 return compiler.assembledCode; 350 return compiler.assembledCode;
351 } 351 }
352 } 352 }
OLDNEW
« no previous file with comments | « dart/frog/leg/compiler.dart ('k') | dart/frog/leg/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698