Chromium Code Reviews| 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 class Interceptors { | 5 class Interceptors { |
| 6 Compiler compiler; | 6 Compiler compiler; |
| 7 Interceptors(Compiler this.compiler); | 7 Interceptors(Compiler this.compiler); |
| 8 | 8 |
| 9 SourceString mapOperatorToMethodName(Operator op) { | 9 SourceString mapOperatorToMethodName(Operator op) { |
| 10 String name = op.source.stringValue; | 10 String name = op.source.stringValue; |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 FunctionExpression node) { | 269 FunctionExpression node) { |
| 270 | 270 |
| 271 ClosureTranslator translator = | 271 ClosureTranslator translator = |
| 272 new ClosureTranslator(builder.compiler, builder.elements); | 272 new ClosureTranslator(builder.compiler, builder.elements); |
| 273 closureData = translator.translate(node); | 273 closureData = translator.translate(node); |
| 274 | 274 |
| 275 FunctionParameters params = function.computeParameters(builder.compiler); | 275 FunctionParameters params = function.computeParameters(builder.compiler); |
| 276 params.forEachParameter((Element element) { | 276 params.forEachParameter((Element element) { |
| 277 HParameterValue parameter = new HParameterValue(element); | 277 HParameterValue parameter = new HParameterValue(element); |
| 278 builder.add(parameter); | 278 builder.add(parameter); |
| 279 // Note that for constructors [element] could be a field-element which we | |
| 280 // treat as if it was a local. | |
| 281 directLocals[element] = parameter; | 279 directLocals[element] = parameter; |
| 280 // If the [element] is a field-parameter (such as [:this.x:] then | |
| 281 // initialize the field element with its value. | |
| 282 // Note that in the constructor factory we treat fields as if they were | |
| 283 // locals. | |
|
ngeoffray
2012/03/15 10:06:01
It looks like you should have an if/else here:
if
floitsch
2012/03/15 14:11:04
Done.
| |
| 284 if (element.kind == ElementKind.FIELD_PARAMETER) { | |
| 285 FieldParameterElement fieldParameterElement = element; | |
| 286 directLocals[fieldParameterElement.fieldElement] = parameter; | |
| 287 } | |
| 282 }); | 288 }); |
| 283 if (closureData.thisElement !== null) { | 289 if (closureData.thisElement !== null) { |
| 284 // Once closures have been mapped to classes their instance members might | 290 // Once closures have been mapped to classes their instance members might |
| 285 // not have any thisElement if the closure was created inside a static | 291 // not have any thisElement if the closure was created inside a static |
| 286 // context. | 292 // context. |
| 287 assert(function.isInstanceMember() || function.isGenerativeConstructor()); | 293 assert(function.isInstanceMember() || function.isGenerativeConstructor()); |
| 288 // We have to introduce 'this' before we enter the scope, since it might | 294 // We have to introduce 'this' before we enter the scope, since it might |
| 289 // need to be copied into a box (if it is captured). This is similar | 295 // need to be copied into a box (if it is captured). This is similar |
| 290 // to all other parameters that are introduced. | 296 // to all other parameters that are introduced. |
| 291 HInstruction thisInstruction = new HThis(); | 297 HInstruction thisInstruction = new HThis(); |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 784 Initializers.isConstructorRedirect(call)); | 790 Initializers.isConstructorRedirect(call)); |
| 785 assert(nextConstructor === null); | 791 assert(nextConstructor === null); |
| 786 nextConstructor = elements[call]; | 792 nextConstructor = elements[call]; |
| 787 // Visit arguments and map the corresponding parameter value to | 793 // Visit arguments and map the corresponding parameter value to |
| 788 // the resulting HInstruction value. | 794 // the resulting HInstruction value. |
| 789 List<HInstruction> arguments = new List<HInstruction>(); | 795 List<HInstruction> arguments = new List<HInstruction>(); |
| 790 addStaticSendArgumentsToList(call, nextConstructor, arguments); | 796 addStaticSendArgumentsToList(call, nextConstructor, arguments); |
| 791 int index = 0; | 797 int index = 0; |
| 792 FunctionParameters parameters = | 798 FunctionParameters parameters = |
| 793 nextConstructor.computeParameters(compiler); | 799 nextConstructor.computeParameters(compiler); |
| 794 parameters.forEachParameter((parameter) { | 800 parameters.forEachParameter((Element parameter) { |
| 795 localsHandler.updateLocal(parameter, arguments[index++]); | 801 HInstruction argument = arguments[index++]; |
| 802 localsHandler.updateLocal(parameter, argument); | |
|
ngeoffray
2012/03/15 10:06:01
ditto for the if/else. The field parameter element
floitsch
2012/03/15 14:11:04
Done.
| |
| 803 if (parameter.kind == ElementKind.FIELD_PARAMETER) { | |
| 804 FieldParameterElement fieldParameterElement = parameter; | |
| 805 localsHandler.updateLocal(fieldParameterElement.fieldElement, | |
| 806 argument); | |
| 807 } | |
| 796 }); | 808 }); |
| 797 } else { | 809 } else { |
| 798 // A field initializer. | 810 // A field initializer. |
| 799 SendSet init = link.head; | 811 SendSet init = link.head; |
| 800 Link<Node> arguments = init.arguments; | 812 Link<Node> arguments = init.arguments; |
| 801 assert(!arguments.isEmpty() && arguments.tail.isEmpty()); | 813 assert(!arguments.isEmpty() && arguments.tail.isEmpty()); |
| 802 visit(arguments.head); | 814 visit(arguments.head); |
| 803 // We treat the init field-elements like locals. In the context of | 815 // We treat the init field-elements like locals. In the context of |
| 804 // the factory this is correct, and simplifies dealing with | 816 // the factory this is correct, and simplifies dealing with |
| 805 // parameter-initializers (like A(this.x)). | 817 // parameter-initializers (like A(this.x)). |
| 806 localsHandler.updateLocal(elements[init], pop()); | 818 localsHandler.updateLocal(elements[init], pop()); |
| 807 } | 819 } |
| 808 } | 820 } |
| 809 return nextConstructor; | 821 return nextConstructor; |
| 810 } | 822 } |
| 811 | 823 |
| 812 /** | 824 /** |
| 813 * Build the factory function corresponding to the constructor | 825 * Build the factory function corresponding to the constructor |
| 814 * [functionElement]: | 826 * [functionElement]: |
| 815 * - Initialize fields with the values of the field initializers of the | 827 * - Initialize fields with the values of the field initializers of the |
| 816 * current constructor and super constructors or constructors redirected | 828 * current constructor and super constructors or constructors redirected |
| 817 * to, starting from the current constructor. | 829 * to, starting from the current constructor. |
| 818 * - Call the the constructor bodies, starting from the constructor(s) in the | 830 * - Call the the constructor bodies, starting from the constructor(s) in the |
| 819 * super class(es). | 831 * super class(es). |
| 820 */ | 832 */ |
| 821 HGraph buildFactory(ClassElement classElement, | 833 HGraph buildFactory(ClassElement classElement, |
| 822 FunctionElement functionElement) { | 834 FunctionElement functionElement) { |
| 823 FunctionExpression function = functionElement.parseNode(compiler); | 835 FunctionExpression function = functionElement.parseNode(compiler); |
| 836 // Note that constructors (like any other static function) do not need | |
| 837 // to deal with optional arguments. It is the callers job to provide all | |
| 838 // arguments as if they were positional. | |
| 839 | |
| 824 // The initializer list could contain closures. | 840 // The initializer list could contain closures. |
| 825 openFunction(functionElement, function); | 841 openFunction(functionElement, function); |
| 826 | 842 |
| 827 final Map<FunctionElement, TreeElements> constructorElements = | 843 final Map<FunctionElement, TreeElements> constructorElements = |
| 828 compiler.resolver.constructorElements; | 844 compiler.resolver.constructorElements; |
| 829 List<FunctionElement> constructors = new List<FunctionElement>(); | 845 List<FunctionElement> constructors = new List<FunctionElement>(); |
| 830 | 846 |
| 831 // Analyze the constructor and all referenced constructors and collect | 847 // Analyze the constructor and all referenced constructors and collect |
| 832 // initializers and constructor bodies. | 848 // initializers and constructor bodies. |
| 833 FunctionElement nextConstructor = functionElement; | 849 FunctionElement nextConstructor = functionElement; |
| (...skipping 1686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2520 buildBody() { | 2536 buildBody() { |
| 2521 // TODO(lrn): Make sure to take continue into account. | 2537 // TODO(lrn): Make sure to take continue into account. |
| 2522 visit(body); | 2538 visit(body); |
| 2523 if (isAborted()) { | 2539 if (isAborted()) { |
| 2524 compiler.reportWarning(body, "aborting loop body"); | 2540 compiler.reportWarning(body, "aborting loop body"); |
| 2525 } | 2541 } |
| 2526 } | 2542 } |
| 2527 handleIf(buildBody, null); | 2543 handleIf(buildBody, null); |
| 2528 } | 2544 } |
| 2529 } | 2545 } |
| OLD | NEW |