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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 functionsCalledInLoop = new Set<FunctionElement>(), | 152 functionsCalledInLoop = new Set<FunctionElement>(), |
| 153 selectorsCalledInLoop = new Map<SourceString, Selector>(), | 153 selectorsCalledInLoop = new Map<SourceString, Selector>(), |
| 154 super(backend.compiler); | 154 super(backend.compiler); |
| 155 | 155 |
| 156 HGraph build(WorkItem work) { | 156 HGraph build(WorkItem work) { |
| 157 return measure(() { | 157 return measure(() { |
| 158 FunctionElement element = work.element; | 158 FunctionElement element = work.element; |
| 159 HInstruction.idCounter = 0; | 159 HInstruction.idCounter = 0; |
| 160 SsaBuilder builder = new SsaBuilder(this, work); | 160 SsaBuilder builder = new SsaBuilder(this, work); |
| 161 HGraph graph; | 161 HGraph graph; |
| 162 switch (element.kind) { | 162 ElementKind kind = element.kind; |
| 163 case ElementKind.GENERATIVE_CONSTRUCTOR: | 163 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR) { |
| 164 graph = compileConstructor(builder, work); | 164 graph = compileConstructor(builder, work); |
| 165 break; | 165 } else if (kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY || |
|
karlklose
2012/06/15 12:43:46
break before ||?
| |
| 166 case ElementKind.GENERATIVE_CONSTRUCTOR_BODY: | 166 kind === ElementKind.FUNCTION || |
| 167 case ElementKind.FUNCTION: | 167 kind === ElementKind.GETTER || |
| 168 case ElementKind.GETTER: | 168 kind === ElementKind.SETTER) { |
| 169 case ElementKind.SETTER: | 169 graph = builder.buildMethod(work.element); |
| 170 graph = builder.buildMethod(work.element); | |
| 171 break; | |
| 172 } | 170 } |
| 173 assert(graph.isValid()); | 171 assert(graph.isValid()); |
| 174 bool inLoop = functionsCalledInLoop.contains(element); | 172 bool inLoop = functionsCalledInLoop.contains(element); |
| 175 if (!inLoop) { | 173 if (!inLoop) { |
| 176 Selector selector = selectorsCalledInLoop[element.name]; | 174 Selector selector = selectorsCalledInLoop[element.name]; |
| 177 inLoop = selector !== null && selector.applies(element, compiler); | 175 inLoop = selector !== null && selector.applies(element, compiler); |
| 178 } | 176 } |
| 179 graph.calledInLoop = inLoop; | 177 graph.calledInLoop = inLoop; |
| 180 if (compiler.tracer.enabled) { | 178 if (compiler.tracer.enabled) { |
| 181 String name; | 179 String name; |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 compiledArguments); | 904 compiledArguments); |
| 907 if (!succeeded) { | 905 if (!succeeded) { |
| 908 // Non-matching super and redirects are compile-time errors and thus | 906 // Non-matching super and redirects are compile-time errors and thus |
| 909 // checked by the resolver. | 907 // checked by the resolver. |
| 910 compiler.internalError( | 908 compiler.internalError( |
| 911 "Parameters and arguments didn't match for super/redirect call", | 909 "Parameters and arguments didn't match for super/redirect call", |
| 912 element: constructor); | 910 element: constructor); |
| 913 } | 911 } |
| 914 | 912 |
| 915 int index = 0; | 913 int index = 0; |
| 916 FunctionSignature parameters = constructor.computeSignature(compiler); | 914 FunctionSignature params = constructor.computeSignature(compiler); |
|
karlklose
2012/06/15 12:43:46
I would prefer the name parameters.
floitsch
2012/06/15 13:05:17
Renamed to "signature".
| |
| 917 parameters.forEachParameter((Element parameter) { | 915 params.forEachParameter((Element parameter) { |
| 918 HInstruction argument = compiledArguments[index++]; | 916 HInstruction argument = compiledArguments[index++]; |
| 919 localsHandler.updateLocal(parameter, argument); | 917 localsHandler.updateLocal(parameter, argument); |
| 920 // Don't forget to update the field, if the parameter is of the | 918 // Don't forget to update the field, if the parameter is of the |
| 921 // form [:this.x:]. | 919 // form [:this.x:]. |
| 922 if (parameter.kind == ElementKind.FIELD_PARAMETER) { | 920 if (parameter.kind == ElementKind.FIELD_PARAMETER) { |
| 923 FieldParameterElement fieldParameterElement = parameter; | 921 FieldParameterElement fieldParameterElement = parameter; |
| 924 fieldValues[fieldParameterElement.fieldElement] = argument; | 922 fieldValues[fieldParameterElement.fieldElement] = argument; |
| 925 } | 923 } |
| 926 }); | 924 }); |
| 927 | 925 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1005 FunctionElement functionElement) { | 1003 FunctionElement functionElement) { |
| 1006 FunctionExpression function = functionElement.parseNode(compiler); | 1004 FunctionExpression function = functionElement.parseNode(compiler); |
| 1007 // Note that constructors (like any other static function) do not need | 1005 // Note that constructors (like any other static function) do not need |
| 1008 // to deal with optional arguments. It is the callers job to provide all | 1006 // to deal with optional arguments. It is the callers job to provide all |
| 1009 // arguments as if they were positional. | 1007 // arguments as if they were positional. |
| 1010 | 1008 |
| 1011 // The initializer list could contain closures. | 1009 // The initializer list could contain closures. |
| 1012 openFunction(functionElement, function); | 1010 openFunction(functionElement, function); |
| 1013 | 1011 |
| 1014 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>(); | 1012 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>(); |
| 1015 FunctionSignature parameters = functionElement.computeSignature(compiler); | 1013 FunctionSignature params = functionElement.computeSignature(compiler); |
| 1016 parameters.forEachParameter((Element element) { | 1014 params.forEachParameter((Element element) { |
| 1017 if (element.kind == ElementKind.FIELD_PARAMETER) { | 1015 if (element.kind == ElementKind.FIELD_PARAMETER) { |
| 1018 // If the [element] is a field-parameter (such as [:this.x:] then | 1016 // If the [element] is a field-parameter (such as [:this.x:] then |
| 1019 // initialize the field element with its value. | 1017 // initialize the field element with its value. |
| 1020 FieldParameterElement fieldParameterElement = element; | 1018 FieldParameterElement fieldParameterElement = element; |
| 1021 HInstruction parameterValue = localsHandler.readLocal(element); | 1019 HInstruction parameterValue = localsHandler.readLocal(element); |
| 1022 fieldValues[fieldParameterElement.fieldElement] = parameterValue; | 1020 fieldValues[fieldParameterElement.fieldElement] = parameterValue; |
| 1023 } | 1021 } |
| 1024 }); | 1022 }); |
| 1025 | 1023 |
| 1026 final Map<FunctionElement, TreeElements> constructorElements = | 1024 final Map<FunctionElement, TreeElements> constructorElements = |
| (...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2240 node: node.argumentsNode); | 2238 node: node.argumentsNode); |
| 2241 } | 2239 } |
| 2242 Node closure = node.arguments.head; | 2240 Node closure = node.arguments.head; |
| 2243 Element element = elements[closure]; | 2241 Element element = elements[closure]; |
| 2244 if (!Elements.isStaticOrTopLevelFunction(element)) { | 2242 if (!Elements.isStaticOrTopLevelFunction(element)) { |
| 2245 compiler.cancel( | 2243 compiler.cancel( |
| 2246 'JS_TO_CLOSURE requires a static or top-level method', | 2244 'JS_TO_CLOSURE requires a static or top-level method', |
| 2247 node: closure); | 2245 node: closure); |
| 2248 } | 2246 } |
| 2249 FunctionElement function = element; | 2247 FunctionElement function = element; |
| 2250 FunctionSignature parameters = function.computeSignature(compiler); | 2248 FunctionSignature params = function.computeSignature(compiler); |
| 2251 if (parameters.optionalParameterCount !== 0) { | 2249 if (params.optionalParameterCount !== 0) { |
| 2252 compiler.cancel( | 2250 compiler.cancel( |
| 2253 'JS_TO_CLOSURE does not handle closure with optional parameters', | 2251 'JS_TO_CLOSURE does not handle closure with optional parameters', |
| 2254 node: closure); | 2252 node: closure); |
| 2255 } | 2253 } |
| 2256 visit(closure); | 2254 visit(closure); |
| 2257 List<HInstruction> inputs = <HInstruction>[pop()]; | 2255 List<HInstruction> inputs = <HInstruction>[pop()]; |
| 2258 String invocationName = compiler.namer.closureInvocationName( | 2256 String invocationName = compiler.namer.closureInvocationName( |
| 2259 new Selector(SelectorKind.INVOCATION, | 2257 new Selector(SelectorKind.INVOCATION, params.requiredParameterCount)); |
| 2260 parameters.requiredParameterCount)); | |
| 2261 push(new HForeign(new DartString.literal('#.$invocationName'), | 2258 push(new HForeign(new DartString.literal('#.$invocationName'), |
| 2262 const LiteralDartString('var'), | 2259 const LiteralDartString('var'), |
| 2263 inputs)); | 2260 inputs)); |
| 2264 } | 2261 } |
| 2265 | 2262 |
| 2266 visitForeignSend(Send node) { | 2263 visitForeignSend(Send node) { |
| 2267 Element element = elements[node]; | 2264 Element element = elements[node]; |
| 2268 if (element.name == const SourceString('JS')) { | 2265 if (element.name == const SourceString('JS')) { |
| 2269 handleForeignJs(node); | 2266 handleForeignJs(node); |
| 2270 } else if (element.name == const SourceString('UNINTERCEPTED')) { | 2267 } else if (element.name == const SourceString('UNINTERCEPTED')) { |
| (...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3417 | 3414 |
| 3418 /** | 3415 /** |
| 3419 * Visitor that handles generation of string literals (LiteralString, | 3416 * Visitor that handles generation of string literals (LiteralString, |
| 3420 * StringInterpolation), and otherwise delegates to the given visitor for | 3417 * StringInterpolation), and otherwise delegates to the given visitor for |
| 3421 * non-literal subexpressions. | 3418 * non-literal subexpressions. |
| 3422 * TODO(lrn): Consider whether to handle compile time constant int/boolean | 3419 * TODO(lrn): Consider whether to handle compile time constant int/boolean |
| 3423 * expressions as well. | 3420 * expressions as well. |
| 3424 */ | 3421 */ |
| 3425 class StringBuilderVisitor extends AbstractVisitor { | 3422 class StringBuilderVisitor extends AbstractVisitor { |
| 3426 final SsaBuilder builder; | 3423 final SsaBuilder builder; |
| 3427 final Node node; | 3424 final Node diagnosticNode; |
| 3428 | 3425 |
| 3429 /** | 3426 /** |
| 3430 * The string value generated so far. | 3427 * The string value generated so far. |
| 3431 */ | 3428 */ |
| 3432 HInstruction result = null; | 3429 HInstruction result = null; |
| 3433 | 3430 |
| 3434 StringBuilderVisitor(this.builder, this.node); | 3431 StringBuilderVisitor(this.builder, this.diagnosticNode); |
| 3435 | 3432 |
| 3436 void visit(Node node) { | 3433 void visit(Node node) { |
| 3437 node.accept(this); | 3434 node.accept(this); |
| 3438 } | 3435 } |
| 3439 | 3436 |
| 3440 visitNode(Node node) { | 3437 visitNode(Node node) { |
| 3441 builder.compiler.internalError('unexpected node', node: node); | 3438 builder.compiler.internalError('unexpected node', node: node); |
| 3442 } | 3439 } |
| 3443 | 3440 |
| 3444 void visitExpression(Node node) { | 3441 void visitExpression(Node node) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 3458 | 3455 |
| 3459 void visitStringJuxtaposition(StringJuxtaposition node) { | 3456 void visitStringJuxtaposition(StringJuxtaposition node) { |
| 3460 node.visitChildren(this); | 3457 node.visitChildren(this); |
| 3461 } | 3458 } |
| 3462 | 3459 |
| 3463 void visitNodeList(NodeList node) { | 3460 void visitNodeList(NodeList node) { |
| 3464 node.visitChildren(this); | 3461 node.visitChildren(this); |
| 3465 } | 3462 } |
| 3466 | 3463 |
| 3467 HInstruction concat(HInstruction left, HInstruction right) { | 3464 HInstruction concat(HInstruction left, HInstruction right) { |
| 3468 HInstruction instruction = new HStringConcat(left, right, node); | 3465 HInstruction instruction = new HStringConcat(left, right, diagnosticNode); |
| 3469 builder.add(instruction); | 3466 builder.add(instruction); |
| 3470 return instruction; | 3467 return instruction; |
| 3471 } | 3468 } |
| 3472 } | 3469 } |
| OLD | NEW |