| OLD | NEW |
| 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 * A function element that represents a closure call. The signature is copied | 6 * A function element that represents a closure call. The signature is copied |
| 7 * from the given element. | 7 * from the given element. |
| 8 */ | 8 */ |
| 9 class ClosureInvocationElement extends FunctionElement { | 9 class ClosureInvocationElement extends FunctionElement { |
| 10 ClosureInvocationElement(SourceString name, | 10 ClosureInvocationElement(SourceString name, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 String attachTo(String invocationName), | 64 String attachTo(String invocationName), |
| 65 StringBuffer buffer, | 65 StringBuffer buffer, |
| 66 Selector selector, | 66 Selector selector, |
| 67 bool isNative) { | 67 bool isNative) { |
| 68 FunctionParameters parameters = member.computeParameters(compiler); | 68 FunctionParameters parameters = member.computeParameters(compiler); |
| 69 int positionalArgumentCount = selector.positionalArgumentCount; | 69 int positionalArgumentCount = selector.positionalArgumentCount; |
| 70 if (positionalArgumentCount == parameters.parameterCount) { | 70 if (positionalArgumentCount == parameters.parameterCount) { |
| 71 assert(selector.namedArgumentCount == 0); | 71 assert(selector.namedArgumentCount == 0); |
| 72 return; | 72 return; |
| 73 } | 73 } |
| 74 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; | 74 ConstantHandler handler = compiler.constantHandler; |
| 75 List<SourceString> names = selector.getOrderedNamedArguments(); | 75 List<SourceString> names = selector.getOrderedNamedArguments(); |
| 76 | 76 |
| 77 String invocationName = | 77 String invocationName = |
| 78 namer.instanceMethodInvocationName(member.name, selector); | 78 namer.instanceMethodInvocationName(member.name, selector); |
| 79 buffer.add('${attachTo(invocationName)} = function('); | 79 buffer.add('${attachTo(invocationName)} = function('); |
| 80 | 80 |
| 81 // The parameters that this stub takes. | 81 // The parameters that this stub takes. |
| 82 List<String> parametersBuffer = new List<String>(selector.argumentCount); | 82 List<String> parametersBuffer = new List<String>(selector.argumentCount); |
| 83 // The arguments that will be passed to the real method. | 83 // The arguments that will be passed to the real method. |
| 84 List<String> argumentsBuffer = new List<String>(parameters.parameterCount); | 84 List<String> argumentsBuffer = new List<String>(parameters.parameterCount); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 argumentsBuffer[count] = jsName; | 126 argumentsBuffer[count] = jsName; |
| 127 } else { | 127 } else { |
| 128 int index = names.indexOf(element.name); | 128 int index = names.indexOf(element.name); |
| 129 if (index != -1) { | 129 if (index != -1) { |
| 130 indexOfLastOptionalArgumentInParameters = count; | 130 indexOfLastOptionalArgumentInParameters = count; |
| 131 // The order of the named arguments is not the same as the | 131 // The order of the named arguments is not the same as the |
| 132 // one in the real method (which is in Dart source order). | 132 // one in the real method (which is in Dart source order). |
| 133 argumentsBuffer[count] = jsName; | 133 argumentsBuffer[count] = jsName; |
| 134 parametersBuffer[selector.positionalArgumentCount + index] = jsName; | 134 parametersBuffer[selector.positionalArgumentCount + index] = jsName; |
| 135 } else { | 135 } else { |
| 136 Constant value = constants.initialVariableValues[element]; | 136 Constant value = handler.initialVariableValues[element]; |
| 137 if (value == null) { | 137 if (value == null) { |
| 138 argumentsBuffer[count] = '(void 0)'; | 138 argumentsBuffer[count] = '(void 0)'; |
| 139 } else { | 139 } else { |
| 140 // If we have an optional value, we need to pass it to the | 140 // If we have an optional value, we need to pass it to the |
| 141 // JS function. | 141 // JS function. |
| 142 indexOfLastOptionalArgumentInParameters = count; | 142 indexOfLastOptionalArgumentInParameters = count; |
| 143 argumentsBuffer[count] = | 143 argumentsBuffer[count] = |
| 144 constants.writeJsCode(new StringBuffer(), value).toString(); | 144 handler.writeJsCode(new StringBuffer(), value).toString(); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 count++; | 148 count++; |
| 149 }); | 149 }); |
| 150 String parametersString = Strings.join(parametersBuffer, ","); | 150 String parametersString = Strings.join(parametersBuffer, ","); |
| 151 buffer.add('$parametersString) {\n'); | 151 buffer.add('$parametersString) {\n'); |
| 152 | 152 |
| 153 if (isNative) { | 153 if (isNative) { |
| 154 nativeEmitter.emitParameterStub( | 154 nativeEmitter.emitParameterStub( |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 } | 466 } |
| 467 } | 467 } |
| 468 | 468 |
| 469 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) { | 469 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) { |
| 470 // Adds initializations inside the Isolate constructor. | 470 // Adds initializations inside the Isolate constructor. |
| 471 // Example: | 471 // Example: |
| 472 // function Isolate() { | 472 // function Isolate() { |
| 473 // this.staticNonFinal = Isolate.prototype.someVal; | 473 // this.staticNonFinal = Isolate.prototype.someVal; |
| 474 // ... | 474 // ... |
| 475 // } | 475 // } |
| 476 CompileTimeConstantHandler handler = compiler.compileTimeConstantHandler; | 476 ConstantHandler handler = compiler.constantHandler; |
| 477 List<VariableElement> staticNonFinalFields = | 477 List<VariableElement> staticNonFinalFields = |
| 478 handler.getStaticNonFinalFieldsForEmission(); | 478 handler.getStaticNonFinalFieldsForEmission(); |
| 479 if (!staticNonFinalFields.isEmpty()) buffer.add('\n'); | 479 if (!staticNonFinalFields.isEmpty()) buffer.add('\n'); |
| 480 for (Element element in staticNonFinalFields) { | 480 for (Element element in staticNonFinalFields) { |
| 481 buffer.add(' this.${namer.getName(element)} = '); | 481 buffer.add(' this.${namer.getName(element)} = '); |
| 482 compiler.withCurrentElement(element, () { | 482 compiler.withCurrentElement(element, () { |
| 483 handler.writeJsCodeForVariable(buffer, element); | 483 handler.writeJsCodeForVariable(buffer, element); |
| 484 }); | 484 }); |
| 485 buffer.add(';\n'); | 485 buffer.add(';\n'); |
| 486 } | 486 } |
| 487 } | 487 } |
| 488 | 488 |
| 489 void emitCompileTimeConstants(StringBuffer buffer) { | 489 void emitCompileTimeConstants(StringBuffer buffer) { |
| 490 CompileTimeConstantHandler handler = compiler.compileTimeConstantHandler; | 490 ConstantHandler handler = compiler.constantHandler; |
| 491 List<Constant> constants = handler.getConstantsForEmission(); | 491 List<Constant> constants = handler.getConstantsForEmission(); |
| 492 String prototype = "${namer.ISOLATE}.prototype"; | 492 String prototype = "${namer.ISOLATE}.prototype"; |
| 493 emitMakeConstantList(prototype, buffer); | 493 emitMakeConstantList(prototype, buffer); |
| 494 for (Constant constant in constants) { | 494 for (Constant constant in constants) { |
| 495 String name = handler.getNameForConstant(constant); | 495 String name = handler.getNameForConstant(constant); |
| 496 buffer.add('$prototype.$name = '); | 496 buffer.add('$prototype.$name = '); |
| 497 handler.writeJsCode(buffer, constant); | 497 handler.writeJsCode(buffer, constant); |
| 498 buffer.add(';\n'); | 498 buffer.add(';\n'); |
| 499 } | 499 } |
| 500 } | 500 } |
| 501 | 501 |
| 502 void emitMakeConstantList(String prototype, StringBuffer buffer) { | 502 void emitMakeConstantList(String prototype, StringBuffer buffer) { |
| 503 buffer.add(prototype); | 503 buffer.add(prototype); |
| 504 buffer.add(@'''.makeConstantList = function(list) { | 504 buffer.add(@'''.makeConstantList = function(list) { |
| 505 list.immutable$list = true; | 505 list.immutable$list = true; |
| 506 list.fixed$length = true; | 506 list.fixed$length = true; |
| 507 return list; | 507 return list; |
| 508 }; | 508 }; |
| 509 '''); | 509 '''); |
| 510 } | 510 } |
| 511 | 511 |
| 512 void emitStaticFinalFieldInitializations(StringBuffer buffer) { | 512 void emitStaticFinalFieldInitializations(StringBuffer buffer) { |
| 513 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; | 513 ConstantHandler handler = compiler.constantHandler; |
| 514 List<VariableElement> staticFinalFields = | 514 List<VariableElement> staticFinalFields = |
| 515 constants.getStaticFinalFieldsForEmission(); | 515 handler.getStaticFinalFieldsForEmission(); |
| 516 for (VariableElement element in staticFinalFields) { | 516 for (VariableElement element in staticFinalFields) { |
| 517 buffer.add('${namer.isolatePropertyAccess(element)} = '); | 517 buffer.add('${namer.isolatePropertyAccess(element)} = '); |
| 518 compiler.withCurrentElement(element, () { | 518 compiler.withCurrentElement(element, () { |
| 519 constants.writeJsCodeForVariable(buffer, element); | 519 handler.writeJsCodeForVariable(buffer, element); |
| 520 }); | 520 }); |
| 521 buffer.add(';\n'); | 521 buffer.add(';\n'); |
| 522 } | 522 } |
| 523 } | 523 } |
| 524 | 524 |
| 525 void emitExtraAccessors(Element member, | 525 void emitExtraAccessors(Element member, |
| 526 String attachTo(String name), | 526 String attachTo(String name), |
| 527 StringBuffer buffer) { | 527 StringBuffer buffer) { |
| 528 if (member.kind == ElementKind.GETTER || member.kind == ElementKind.FIELD) { | 528 if (member.kind == ElementKind.GETTER || member.kind == ElementKind.FIELD) { |
| 529 Set<Selector> selectors = compiler.universe.invokedNames[member.name]; | 529 Set<Selector> selectors = compiler.universe.invokedNames[member.name]; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 emitStaticFinalFieldInitializations(buffer); | 610 emitStaticFinalFieldInitializations(buffer); |
| 611 nativeEmitter.emitDynamicDispatchMetadata(buffer); | 611 nativeEmitter.emitDynamicDispatchMetadata(buffer); |
| 612 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); | 612 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); |
| 613 Element main = compiler.mainApp.find(Compiler.MAIN); | 613 Element main = compiler.mainApp.find(Compiler.MAIN); |
| 614 buffer.add('${namer.isolateAccess(main)}();\n'); | 614 buffer.add('${namer.isolateAccess(main)}();\n'); |
| 615 compiler.assembledCode = buffer.toString(); | 615 compiler.assembledCode = buffer.toString(); |
| 616 }); | 616 }); |
| 617 return compiler.assembledCode; | 617 return compiler.assembledCode; |
| 618 } | 618 } |
| 619 } | 619 } |
| OLD | NEW |