| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 ElementKind kind = element.kind; | 177 ElementKind kind = element.kind; |
| 178 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR) { | 178 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR) { |
| 179 graph = compileConstructor(builder, work); | 179 graph = compileConstructor(builder, work); |
| 180 } else if (kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY || | 180 } else if (kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY || |
| 181 kind === ElementKind.FUNCTION || | 181 kind === ElementKind.FUNCTION || |
| 182 kind === ElementKind.GETTER || | 182 kind === ElementKind.GETTER || |
| 183 kind === ElementKind.SETTER) { | 183 kind === ElementKind.SETTER) { |
| 184 graph = builder.buildMethod(element); | 184 graph = builder.buildMethod(element); |
| 185 } else if (kind === ElementKind.FIELD) { | 185 } else if (kind === ElementKind.FIELD) { |
| 186 graph = builder.buildLazyInitializer(element); | 186 graph = builder.buildLazyInitializer(element); |
| 187 } else { |
| 188 compiler.internalErrorOnElement(element, |
| 189 'unexpected element kind $kind'); |
| 187 } | 190 } |
| 188 assert(graph.isValid()); | 191 assert(graph.isValid()); |
| 189 if (kind !== ElementKind.FIELD) { | 192 if (kind !== ElementKind.FIELD) { |
| 190 bool inLoop = functionsCalledInLoop.contains(element.declaration); | 193 bool inLoop = functionsCalledInLoop.contains(element.declaration); |
| 191 if (!inLoop) { | 194 if (!inLoop) { |
| 192 Selector selector = selectorsCalledInLoop[element.name]; | 195 Selector selector = selectorsCalledInLoop[element.name]; |
| 193 inLoop = selector !== null && selector.applies(element, compiler); | 196 inLoop = selector !== null && selector.applies(element, compiler); |
| 194 } | 197 } |
| 195 graph.calledInLoop = inLoop; | 198 graph.calledInLoop = inLoop; |
| 196 | 199 |
| 197 // If there is an estimate of the parameter types assume these types | 200 // If there is an estimate of the parameter types assume these types |
| 198 // when compiling. | 201 // when compiling. |
| 202 // TODO(karlklose,ngeoffray): add a check to make sure that element is |
| 203 // of type FunctionElement. |
| 204 FunctionElement function = element; |
| 199 OptionalParameterTypes defaultValueTypes = null; | 205 OptionalParameterTypes defaultValueTypes = null; |
| 200 FunctionSignature signature = element.computeSignature(compiler); | 206 FunctionSignature signature = function.computeSignature(compiler); |
| 201 if (signature.optionalParameterCount > 0) { | 207 if (signature.optionalParameterCount > 0) { |
| 202 defaultValueTypes = | 208 defaultValueTypes = |
| 203 new OptionalParameterTypes(signature.optionalParameterCount); | 209 new OptionalParameterTypes(signature.optionalParameterCount); |
| 204 int index = 0; | 210 int index = 0; |
| 205 signature.forEachOptionalParameter((Element parameter) { | 211 signature.forEachOptionalParameter((Element parameter) { |
| 206 Constant defaultValue = compiler.compileVariable(parameter); | 212 Constant defaultValue = compiler.compileVariable(parameter); |
| 207 HType type = HGraph.mapConstantTypeToSsaType(defaultValue); | 213 HType type = HGraph.mapConstantTypeToSsaType(defaultValue); |
| 208 defaultValueTypes.update(index, parameter.name, type); | 214 defaultValueTypes.update(index, parameter.name, type); |
| 209 index++; | 215 index++; |
| 210 }); | 216 }); |
| (...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 // TODO(ahe): The constructor name is statically resolved. See | 1344 // TODO(ahe): The constructor name is statically resolved. See |
| 1339 // SsaCodeGenerator.visitInvokeDynamicMethod. Is there a cleaner | 1345 // SsaCodeGenerator.visitInvokeDynamicMethod. Is there a cleaner |
| 1340 // way to do this? | 1346 // way to do this? |
| 1341 SourceString name = | 1347 SourceString name = |
| 1342 new SourceString(backend.namer.getName(body.declaration)); | 1348 new SourceString(backend.namer.getName(body.declaration)); |
| 1343 // TODO(kasperl): This seems fishy. We shouldn't be inventing all | 1349 // TODO(kasperl): This seems fishy. We shouldn't be inventing all |
| 1344 // these selectors. Maybe the resolver can do more of the work | 1350 // these selectors. Maybe the resolver can do more of the work |
| 1345 // for us here? | 1351 // for us here? |
| 1346 LibraryElement library = body.getLibrary(); | 1352 LibraryElement library = body.getLibrary(); |
| 1347 Selector selector = new Selector.call(name, library, arity); | 1353 Selector selector = new Selector.call(name, library, arity); |
| 1348 HInstruction invoke = new HInvokeDynamicMethod(selector, bodyCallInputs); | 1354 HInvokeDynamic invoke = |
| 1355 new HInvokeDynamicMethod(selector, bodyCallInputs); |
| 1349 invoke.element = body; | 1356 invoke.element = body; |
| 1350 add(invoke); | 1357 add(invoke); |
| 1351 } | 1358 } |
| 1352 close(new HReturn(newObject)).addSuccessor(graph.exit); | 1359 close(new HReturn(newObject)).addSuccessor(graph.exit); |
| 1353 return closeFunction(); | 1360 return closeFunction(); |
| 1354 } | 1361 } |
| 1355 | 1362 |
| 1356 void addParameterCheckInstruction(Element element) { | 1363 void addParameterCheckInstruction(Element element) { |
| 1357 // This is the code we emit for a parameter that is being checked | 1364 // This is the code we emit for a parameter that is being checked |
| 1358 // on whether it was given at value at the call site: | 1365 // on whether it was given at value at the call site: |
| (...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2618 Element element = elements[closure]; | 2625 Element element = elements[closure]; |
| 2619 if (!Elements.isStaticOrTopLevelFunction(element)) { | 2626 if (!Elements.isStaticOrTopLevelFunction(element)) { |
| 2620 compiler.cancel( | 2627 compiler.cancel( |
| 2621 'JS_TO_CLOSURE requires a static or top-level method', | 2628 'JS_TO_CLOSURE requires a static or top-level method', |
| 2622 node: closure); | 2629 node: closure); |
| 2623 } | 2630 } |
| 2624 FunctionElement function = element; | 2631 FunctionElement function = element; |
| 2625 // TODO(johnniwinther): Try to eliminate the need to distinguish declaration | 2632 // TODO(johnniwinther): Try to eliminate the need to distinguish declaration |
| 2626 // and implementation signatures. Currently it is need because the | 2633 // and implementation signatures. Currently it is need because the |
| 2627 // signatures have different elements for parameters. | 2634 // signatures have different elements for parameters. |
| 2628 FunctionSignature params | 2635 FunctionElement implementation = function.implementation; |
| 2629 = function.implementation.computeSignature(compiler); | 2636 FunctionSignature params = implementation.computeSignature(compiler); |
| 2630 if (params.optionalParameterCount !== 0) { | 2637 if (params.optionalParameterCount !== 0) { |
| 2631 compiler.cancel( | 2638 compiler.cancel( |
| 2632 'JS_TO_CLOSURE does not handle closure with optional parameters', | 2639 'JS_TO_CLOSURE does not handle closure with optional parameters', |
| 2633 node: closure); | 2640 node: closure); |
| 2634 } | 2641 } |
| 2635 visit(closure); | 2642 visit(closure); |
| 2636 List<HInstruction> inputs = <HInstruction>[pop()]; | 2643 List<HInstruction> inputs = <HInstruction>[pop()]; |
| 2637 String invocationName = backend.namer.closureInvocationName( | 2644 String invocationName = backend.namer.closureInvocationName( |
| 2638 new Selector.callClosure(params.requiredParameterCount)); | 2645 new Selector.callClosure(params.requiredParameterCount)); |
| 2639 push(new HForeign(new DartString.literal('#.$invocationName'), | 2646 push(new HForeign(new DartString.literal('#.$invocationName'), |
| (...skipping 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4389 new HSubGraphBlockInformation(elseBranch.graph)); | 4396 new HSubGraphBlockInformation(elseBranch.graph)); |
| 4390 | 4397 |
| 4391 HBasicBlock conditionStartBlock = conditionBranch.block; | 4398 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 4392 conditionStartBlock.setBlockFlow(info, joinBlock); | 4399 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 4393 SubGraph conditionGraph = conditionBranch.graph; | 4400 SubGraph conditionGraph = conditionBranch.graph; |
| 4394 HIf branch = conditionGraph.end.last; | 4401 HIf branch = conditionGraph.end.last; |
| 4395 assert(branch is HIf); | 4402 assert(branch is HIf); |
| 4396 branch.blockInformation = conditionStartBlock.blockFlow; | 4403 branch.blockInformation = conditionStartBlock.blockFlow; |
| 4397 } | 4404 } |
| 4398 } | 4405 } |
| OLD | NEW |