| 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 ConstantHandler handler = compiler.constantHandler; | 74 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; |
| 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 = handler.initialVariableValues[element]; | 136 Constant value = constants.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 (!value.isNull()) { | 140 if (!value.isNull()) { |
| 141 // If the value is the null constant, we should not pass it | 141 // If the value is the null constant, we should not pass it |
| 142 // down to the native method. | 142 // down to the native method. |
| 143 indexOfLastOptionalArgumentInParameters = count; | 143 indexOfLastOptionalArgumentInParameters = count; |
| 144 } | 144 } |
| 145 argumentsBuffer[count] = | 145 argumentsBuffer[count] = |
| 146 handler.writeJsCode(new StringBuffer(), value).toString(); | 146 constants.writeJsCode(new StringBuffer(), value).toString(); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 count++; | 150 count++; |
| 151 }); | 151 }); |
| 152 String parametersString = Strings.join(parametersBuffer, ","); | 152 String parametersString = Strings.join(parametersBuffer, ","); |
| 153 buffer.add('$parametersString) {\n'); | 153 buffer.add('$parametersString) {\n'); |
| 154 | 154 |
| 155 if (isNative) { | 155 if (isNative) { |
| 156 nativeEmitter.emitParameterStub( | 156 nativeEmitter.emitParameterStub( |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 468 } |
| 469 } | 469 } |
| 470 | 470 |
| 471 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) { | 471 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) { |
| 472 // Adds initializations inside the Isolate constructor. | 472 // Adds initializations inside the Isolate constructor. |
| 473 // Example: | 473 // Example: |
| 474 // function Isolate() { | 474 // function Isolate() { |
| 475 // this.staticNonFinal = Isolate.prototype.someVal; | 475 // this.staticNonFinal = Isolate.prototype.someVal; |
| 476 // ... | 476 // ... |
| 477 // } | 477 // } |
| 478 ConstantHandler handler = compiler.constantHandler; | 478 CompileTimeConstantHandler handler = compiler.compileTimeConstantHandler; |
| 479 List<VariableElement> staticNonFinalFields = | 479 List<VariableElement> staticNonFinalFields = |
| 480 handler.getStaticNonFinalFieldsForEmission(); | 480 handler.getStaticNonFinalFieldsForEmission(); |
| 481 if (!staticNonFinalFields.isEmpty()) buffer.add('\n'); | 481 if (!staticNonFinalFields.isEmpty()) buffer.add('\n'); |
| 482 for (Element element in staticNonFinalFields) { | 482 for (Element element in staticNonFinalFields) { |
| 483 buffer.add(' this.${namer.getName(element)} = '); | 483 buffer.add(' this.${namer.getName(element)} = '); |
| 484 compiler.withCurrentElement(element, () { | 484 compiler.withCurrentElement(element, () { |
| 485 handler.writeJsCodeForVariable(buffer, element); | 485 handler.writeJsCodeForVariable(buffer, element); |
| 486 }); | 486 }); |
| 487 buffer.add(';\n'); | 487 buffer.add(';\n'); |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 | 490 |
| 491 void emitCompileTimeConstants(StringBuffer buffer) { | 491 void emitCompileTimeConstants(StringBuffer buffer) { |
| 492 ConstantHandler handler = compiler.constantHandler; | 492 CompileTimeConstantHandler handler = compiler.compileTimeConstantHandler; |
| 493 List<Constant> constants = handler.getConstantsForEmission(); | 493 List<Constant> constants = handler.getConstantsForEmission(); |
| 494 String prototype = "${namer.ISOLATE}.prototype"; | 494 String prototype = "${namer.ISOLATE}.prototype"; |
| 495 emitMakeConstantList(prototype, buffer); | 495 emitMakeConstantList(prototype, buffer); |
| 496 for (Constant constant in constants) { | 496 for (Constant constant in constants) { |
| 497 String name = handler.getNameForConstant(constant); | 497 String name = handler.getNameForConstant(constant); |
| 498 buffer.add('$prototype.$name = '); | 498 buffer.add('$prototype.$name = '); |
| 499 handler.writeJsCode(buffer, constant); | 499 handler.writeJsCode(buffer, constant); |
| 500 buffer.add(';\n'); | 500 buffer.add(';\n'); |
| 501 } | 501 } |
| 502 } | 502 } |
| 503 | 503 |
| 504 void emitMakeConstantList(String prototype, StringBuffer buffer) { | 504 void emitMakeConstantList(String prototype, StringBuffer buffer) { |
| 505 buffer.add(prototype); | 505 buffer.add(prototype); |
| 506 buffer.add(@'''.makeConstantList = function(list) { | 506 buffer.add(@'''.makeConstantList = function(list) { |
| 507 list.immutable$list = true; | 507 list.immutable$list = true; |
| 508 list.fixed$length = true; | 508 list.fixed$length = true; |
| 509 return list; | 509 return list; |
| 510 }; | 510 }; |
| 511 '''); | 511 '''); |
| 512 } | 512 } |
| 513 | 513 |
| 514 void emitStaticFinalFieldInitializations(StringBuffer buffer) { | 514 void emitStaticFinalFieldInitializations(StringBuffer buffer) { |
| 515 ConstantHandler handler = compiler.constantHandler; | 515 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; |
| 516 List<VariableElement> staticFinalFields = | 516 List<VariableElement> staticFinalFields = |
| 517 handler.getStaticFinalFieldsForEmission(); | 517 constants.getStaticFinalFieldsForEmission(); |
| 518 for (VariableElement element in staticFinalFields) { | 518 for (VariableElement element in staticFinalFields) { |
| 519 buffer.add('${namer.isolatePropertyAccess(element)} = '); | 519 buffer.add('${namer.isolatePropertyAccess(element)} = '); |
| 520 compiler.withCurrentElement(element, () { | 520 compiler.withCurrentElement(element, () { |
| 521 handler.writeJsCodeForVariable(buffer, element); | 521 constants.writeJsCodeForVariable(buffer, element); |
| 522 }); | 522 }); |
| 523 buffer.add(';\n'); | 523 buffer.add(';\n'); |
| 524 } | 524 } |
| 525 } | 525 } |
| 526 | 526 |
| 527 void emitExtraAccessors(Element member, | 527 void emitExtraAccessors(Element member, |
| 528 String attachTo(String name), | 528 String attachTo(String name), |
| 529 StringBuffer buffer) { | 529 StringBuffer buffer) { |
| 530 if (member.kind == ElementKind.GETTER || member.kind == ElementKind.FIELD) { | 530 if (member.kind == ElementKind.GETTER || member.kind == ElementKind.FIELD) { |
| 531 Set<Selector> selectors = compiler.universe.invokedNames[member.name]; | 531 Set<Selector> selectors = compiler.universe.invokedNames[member.name]; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 emitStaticFinalFieldInitializations(buffer); | 612 emitStaticFinalFieldInitializations(buffer); |
| 613 nativeEmitter.emitDynamicDispatchMetadata(buffer); | 613 nativeEmitter.emitDynamicDispatchMetadata(buffer); |
| 614 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); | 614 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); |
| 615 Element main = compiler.mainApp.find(Compiler.MAIN); | 615 Element main = compiler.mainApp.find(Compiler.MAIN); |
| 616 buffer.add('${namer.isolateAccess(main)}();\n'); | 616 buffer.add('${namer.isolateAccess(main)}();\n'); |
| 617 compiler.assembledCode = buffer.toString(); | 617 compiler.assembledCode = buffer.toString(); |
| 618 }); | 618 }); |
| 619 return compiler.assembledCode; | 619 return compiler.assembledCode; |
| 620 } | 620 } |
| 621 } | 621 } |
| OLD | NEW |