| OLD | NEW |
| 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 26 matching lines...) Expand all Loading... |
| 37 buffer.add(';\n'); | 37 buffer.add(';\n'); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void addParameterStub(FunctionElement member, | 40 void addParameterStub(FunctionElement member, |
| 41 String prototype, | 41 String prototype, |
| 42 StringBuffer buffer, | 42 StringBuffer buffer, |
| 43 Invocation invocation) { | 43 Invocation invocation) { |
| 44 // TODO(ngeoffray): also support invocation with names. | 44 // TODO(ngeoffray): also support invocation with names. |
| 45 String invocationName = | 45 String invocationName = |
| 46 namer.instanceMethodName(member.name, invocation.argumentCount); | 46 namer.instanceMethodName(member.name, invocation.argumentCount); |
| 47 int allParameters = member.parameterCount(compiler) | 47 int allParameters = member.parameterCount(compiler); |
| 48 + member.optionalParameterCount(compiler); | |
| 49 int missingParameters = allParameters - invocation.argumentCount; | 48 int missingParameters = allParameters - invocation.argumentCount; |
| 50 if (missingParameters == 0) return; | 49 if (missingParameters == 0) return; |
| 51 assert(missingParameters > 0); | 50 assert(missingParameters > 0); |
| 52 buffer.add('$prototype.$invocationName = function('); | 51 buffer.add('$prototype.$invocationName = function('); |
| 53 StringBuffer parameters = new StringBuffer(); | 52 StringBuffer parameters = new StringBuffer(); |
| 54 for (int i = 0; i < invocation.argumentCount; i++) { | 53 for (int i = 0; i < invocation.argumentCount; i++) { |
| 55 if (i != 0) parameters.add(', '); | 54 if (i != 0) parameters.add(', '); |
| 56 parameters.add('param$i'); | 55 parameters.add('param$i'); |
| 57 } | 56 } |
| 58 buffer.add('$parameters) {\n'); | 57 buffer.add('$parameters) {\n'); |
| 59 buffer.add(' this.${namer.getName(member)}($parameters'); | 58 buffer.add(' this.${namer.getName(member)}($parameters'); |
| 60 for (int i = 0; i < missingParameters; i++) { | 59 for (int i = 0; i < missingParameters; i++) { |
| 61 if (i != 0 || invocation.argumentCount != 0) buffer.add(', '); | 60 if (i != 0 || invocation.argumentCount != 0) buffer.add(', '); |
| 62 buffer.add('(void 0)'); | 61 buffer.add('(void 0)'); |
| 63 } | 62 } |
| 64 buffer.add(')\n}\n'); | 63 buffer.add(')\n}\n'); |
| 65 } | 64 } |
| 66 | 65 |
| 67 void addParameterStubs(FunctionElement member, | 66 void addParameterStubs(FunctionElement member, |
| 68 String prototype, | 67 String prototype, |
| 69 StringBuffer buffer) { | 68 StringBuffer buffer) { |
| 70 Set<Invocation> invocations = compiler.universe.invokedNames[member.name]; | 69 Set<Invocation> invocations = compiler.universe.invokedNames[member.name]; |
| 70 if (invocations == null) return; |
| 71 for (Invocation invocation in invocations) { | 71 for (Invocation invocation in invocations) { |
| 72 if (!invocation.applies(compiler, member)) continue; | 72 if (!invocation.applies(compiler, member)) continue; |
| 73 addParameterStub(member, prototype, buffer, invocation); | 73 addParameterStub(member, prototype, buffer, invocation); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 void addInstanceMember(Element member, | 77 void addInstanceMember(Element member, |
| 78 String prototype, | 78 String prototype, |
| 79 StringBuffer buffer) { | 79 StringBuffer buffer) { |
| 80 assert(member.isInstanceMember()); | 80 assert(member.isInstanceMember()); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 emitStaticFunctions(buffer); | 288 emitStaticFunctions(buffer); |
| 289 emitStaticFinalFieldInitializations(buffer); | 289 emitStaticFinalFieldInitializations(buffer); |
| 290 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); | 290 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); |
| 291 Element main = compiler.universe.find(Compiler.MAIN); | 291 Element main = compiler.universe.find(Compiler.MAIN); |
| 292 buffer.add('${namer.isolateAccess(main)}();\n'); | 292 buffer.add('${namer.isolateAccess(main)}();\n'); |
| 293 compiler.assembledCode = buffer.toString(); | 293 compiler.assembledCode = buffer.toString(); |
| 294 }); | 294 }); |
| 295 return compiler.assembledCode; | 295 return compiler.assembledCode; |
| 296 } | 296 } |
| 297 } | 297 } |
| OLD | NEW |