| 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 2180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2191 } else if (Elements.isStaticOrTopLevelFunction(element)) { | 2191 } else if (Elements.isStaticOrTopLevelFunction(element)) { |
| 2192 // TODO(5346): Try to avoid the need for calling [declaration] before | 2192 // TODO(5346): Try to avoid the need for calling [declaration] before |
| 2193 // creating an [HStatic]. | 2193 // creating an [HStatic]. |
| 2194 push(new HStatic(element.declaration)); | 2194 push(new HStatic(element.declaration)); |
| 2195 // TODO(ahe): This should be registered in codegen. | 2195 // TODO(ahe): This should be registered in codegen. |
| 2196 compiler.enqueuer.codegen.registerGetOfStaticFunction(element); | 2196 compiler.enqueuer.codegen.registerGetOfStaticFunction(element); |
| 2197 } else if (Elements.isErroneousElement(element)) { | 2197 } else if (Elements.isErroneousElement(element)) { |
| 2198 // An erroneous element indicates an unresolved static getter. | 2198 // An erroneous element indicates an unresolved static getter. |
| 2199 generateThrowNoSuchMethod(send, | 2199 generateThrowNoSuchMethod(send, |
| 2200 getTargetName(element, 'get'), | 2200 getTargetName(element, 'get'), |
| 2201 const Link<Node>()); | 2201 argumentNodes: const Link<Node>()); |
| 2202 } else { | 2202 } else { |
| 2203 stack.add(localsHandler.readLocal(element)); | 2203 stack.add(localsHandler.readLocal(element)); |
| 2204 } | 2204 } |
| 2205 } | 2205 } |
| 2206 | 2206 |
| 2207 void generateInstanceSetterWithCompiledReceiver(Send send, | 2207 void generateInstanceSetterWithCompiledReceiver(Send send, |
| 2208 HInstruction receiver, | 2208 HInstruction receiver, |
| 2209 HInstruction value) { | 2209 HInstruction value) { |
| 2210 assert(Elements.isInstanceSend(send, elements)); | 2210 assert(Elements.isInstanceSend(send, elements)); |
| 2211 Selector selector = elements.getSelector(send); | 2211 Selector selector = elements.getSelector(send); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2240 addWithPosition(new HStaticStore(element, value), send); | 2240 addWithPosition(new HStaticStore(element, value), send); |
| 2241 } | 2241 } |
| 2242 stack.add(value); | 2242 stack.add(value); |
| 2243 } else if (element == null || Elements.isInstanceField(element)) { | 2243 } else if (element == null || Elements.isInstanceField(element)) { |
| 2244 HInstruction receiver = generateInstanceSendReceiver(send); | 2244 HInstruction receiver = generateInstanceSendReceiver(send); |
| 2245 generateInstanceSetterWithCompiledReceiver(send, receiver, value); | 2245 generateInstanceSetterWithCompiledReceiver(send, receiver, value); |
| 2246 } else if (Elements.isErroneousElement(element)) { | 2246 } else if (Elements.isErroneousElement(element)) { |
| 2247 // An erroneous element indicates an unresolved static setter. | 2247 // An erroneous element indicates an unresolved static setter. |
| 2248 generateThrowNoSuchMethod(send, | 2248 generateThrowNoSuchMethod(send, |
| 2249 getTargetName(element, 'set'), | 2249 getTargetName(element, 'set'), |
| 2250 send.arguments); | 2250 argumentNodes: send.arguments); |
| 2251 } else { | 2251 } else { |
| 2252 stack.add(value); | 2252 stack.add(value); |
| 2253 // If the value does not already have a name, give it here. | 2253 // If the value does not already have a name, give it here. |
| 2254 if (value.sourceElement == null) { | 2254 if (value.sourceElement == null) { |
| 2255 value.sourceElement = element; | 2255 value.sourceElement = element; |
| 2256 } | 2256 } |
| 2257 HInstruction checked = potentiallyCheckType(value, element); | 2257 HInstruction checked = potentiallyCheckType(value, element); |
| 2258 if (!identical(checked, value)) { | 2258 if (!identical(checked, value)) { |
| 2259 pop(); | 2259 pop(); |
| 2260 stack.add(checked); | 2260 stack.add(checked); |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2967 // the 'new' is done. | 2967 // the 'new' is done. |
| 2968 if (isListConstructor && compiler.world.needsRti(compiler.listClass)) { | 2968 if (isListConstructor && compiler.world.needsRti(compiler.listClass)) { |
| 2969 handleListConstructor(type, node, newInstance); | 2969 handleListConstructor(type, node, newInstance); |
| 2970 } | 2970 } |
| 2971 } | 2971 } |
| 2972 | 2972 |
| 2973 visitStaticSend(Send node) { | 2973 visitStaticSend(Send node) { |
| 2974 Selector selector = elements.getSelector(node); | 2974 Selector selector = elements.getSelector(node); |
| 2975 Element element = elements[node]; | 2975 Element element = elements[node]; |
| 2976 if (element.isErroneous()) { | 2976 if (element.isErroneous()) { |
| 2977 generateThrowNoSuchMethod(node, getTargetName(element), node.arguments); | 2977 generateThrowNoSuchMethod(node, |
| 2978 getTargetName(element), |
| 2979 argumentNodes: node.arguments); |
| 2978 return; | 2980 return; |
| 2979 } | 2981 } |
| 2980 if (identical(element, compiler.assertMethod) && !compiler.enableUserAsserti
ons) { | 2982 if (identical(element, compiler.assertMethod) && !compiler.enableUserAsserti
ons) { |
| 2981 stack.add(graph.addConstantNull(constantSystem)); | 2983 stack.add(graph.addConstantNull(constantSystem)); |
| 2982 return; | 2984 return; |
| 2983 } | 2985 } |
| 2984 compiler.ensure(!element.isGenerativeConstructor()); | 2986 compiler.ensure(!element.isGenerativeConstructor()); |
| 2985 if (element.isFunction()) { | 2987 if (element.isFunction()) { |
| 2986 if (tryInlineMethod(element, selector, node.arguments)) { | 2988 if (tryInlineMethod(element, selector, node.arguments)) { |
| 2987 return; | 2989 return; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3046 } | 3048 } |
| 3047 | 3049 |
| 3048 void generateAbstractClassInstantiationError(Node node, String message) { | 3050 void generateAbstractClassInstantiationError(Node node, String message) { |
| 3049 generateError(node, | 3051 generateError(node, |
| 3050 message, | 3052 message, |
| 3051 interceptors.getThrowAbstractClassInstantiationError()); | 3053 interceptors.getThrowAbstractClassInstantiationError()); |
| 3052 } | 3054 } |
| 3053 | 3055 |
| 3054 void generateThrowNoSuchMethod(Node diagnosticNode, | 3056 void generateThrowNoSuchMethod(Node diagnosticNode, |
| 3055 String methodName, | 3057 String methodName, |
| 3056 [Link<Node> argumentNodes, | 3058 {Link<Node> argumentNodes, |
| 3057 List<HInstruction> argumentValues]) { | 3059 List<HInstruction> argumentValues}) { |
| 3058 Element helper = | 3060 Element helper = |
| 3059 compiler.findHelper(const SourceString('throwNoSuchMethod')); | 3061 compiler.findHelper(const SourceString('throwNoSuchMethod')); |
| 3060 Constant receiverConstant = | 3062 Constant receiverConstant = |
| 3061 constantSystem.createString(new DartString.empty(), diagnosticNode); | 3063 constantSystem.createString(new DartString.empty(), diagnosticNode); |
| 3062 HInstruction receiver = graph.addConstant(receiverConstant); | 3064 HInstruction receiver = graph.addConstant(receiverConstant); |
| 3063 DartString dartString = new DartString.literal(methodName); | 3065 DartString dartString = new DartString.literal(methodName); |
| 3064 Constant nameConstant = | 3066 Constant nameConstant = |
| 3065 constantSystem.createString(dartString, diagnosticNode); | 3067 constantSystem.createString(dartString, diagnosticNode); |
| 3066 HInstruction name = graph.addConstant(nameConstant); | 3068 HInstruction name = graph.addConstant(nameConstant); |
| 3067 if (argumentValues == null) { | 3069 if (argumentValues == null) { |
| 3068 argumentValues = <HInstruction>[]; | 3070 argumentValues = <HInstruction>[]; |
| 3069 argumentNodes.forEach((argumentNode) { | 3071 argumentNodes.forEach((argumentNode) { |
| 3070 visit(argumentNode); | 3072 visit(argumentNode); |
| 3071 HInstruction value = pop(); | 3073 HInstruction value = pop(); |
| 3072 argumentValues.add(value); | 3074 argumentValues.add(value); |
| 3073 }); | 3075 }); |
| 3074 } | 3076 } |
| 3075 HInstruction arguments = new HLiteralList(argumentValues); | 3077 HInstruction arguments = new HLiteralList(argumentValues); |
| 3076 add(arguments); | 3078 add(arguments); |
| 3077 pushInvokeHelper3(helper, receiver, name, arguments); | 3079 pushInvokeHelper3(helper, receiver, name, arguments); |
| 3078 } | 3080 } |
| 3079 | 3081 |
| 3080 visitNewExpression(NewExpression node) { | 3082 visitNewExpression(NewExpression node) { |
| 3081 Element element = elements[node.send]; | 3083 Element element = elements[node.send]; |
| 3082 if (Elements.isErroneousElement(element)) { | 3084 if (Elements.isErroneousElement(element)) { |
| 3083 ErroneousElement error = element; | 3085 ErroneousElement error = element; |
| 3084 if (error.messageKind == MessageKind.CANNOT_FIND_CONSTRUCTOR) { | 3086 if (error.messageKind == MessageKind.CANNOT_FIND_CONSTRUCTOR) { |
| 3085 generateThrowNoSuchMethod(node.send, | 3087 generateThrowNoSuchMethod(node.send, |
| 3086 getTargetName(error, 'constructor'), | 3088 getTargetName(error, 'constructor'), |
| 3087 node.send.arguments); | 3089 argumentNodes: node.send.arguments); |
| 3088 } else if (error.messageKind == MessageKind.CANNOT_RESOLVE) { | 3090 } else if (error.messageKind == MessageKind.CANNOT_RESOLVE) { |
| 3089 Message message = error.messageKind.message(error.messageArguments); | 3091 Message message = error.messageKind.message(error.messageArguments); |
| 3090 generateRuntimeError(node.send, message.toString()); | 3092 generateRuntimeError(node.send, message.toString()); |
| 3091 } else { | 3093 } else { |
| 3092 compiler.internalError('unexpected unresolved constructor call', | 3094 compiler.internalError('unexpected unresolved constructor call', |
| 3093 node: node); | 3095 node: node); |
| 3094 } | 3096 } |
| 3095 } else if (node.isConst()) { | 3097 } else if (node.isConst()) { |
| 3096 // TODO(karlklose): add type representation | 3098 // TODO(karlklose): add type representation |
| 3097 ConstantHandler handler = compiler.constantHandler; | 3099 ConstantHandler handler = compiler.constantHandler; |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3455 variable = elements[node.declaredIdentifier]; | 3457 variable = elements[node.declaredIdentifier]; |
| 3456 } else { | 3458 } else { |
| 3457 assert(node.declaredIdentifier.asVariableDefinitions() != null); | 3459 assert(node.declaredIdentifier.asVariableDefinitions() != null); |
| 3458 VariableDefinitions variableDefinitions = node.declaredIdentifier; | 3460 VariableDefinitions variableDefinitions = node.declaredIdentifier; |
| 3459 variable = elements[variableDefinitions.definitions.nodes.head]; | 3461 variable = elements[variableDefinitions.definitions.nodes.head]; |
| 3460 } | 3462 } |
| 3461 HInstruction oldVariable = pop(); | 3463 HInstruction oldVariable = pop(); |
| 3462 if (variable.isErroneous()) { | 3464 if (variable.isErroneous()) { |
| 3463 generateThrowNoSuchMethod(node, | 3465 generateThrowNoSuchMethod(node, |
| 3464 getTargetName(variable, 'set'), | 3466 getTargetName(variable, 'set'), |
| 3465 <HInstruction>[oldVariable]); | 3467 argumentValues: <HInstruction>[oldVariable]); |
| 3466 pop(); | 3468 pop(); |
| 3467 } else { | 3469 } else { |
| 3468 localsHandler.updateLocal(variable, oldVariable); | 3470 localsHandler.updateLocal(variable, oldVariable); |
| 3469 } | 3471 } |
| 3470 | 3472 |
| 3471 visit(node.body); | 3473 visit(node.body); |
| 3472 } | 3474 } |
| 3473 handleLoop(node, buildInitializer, buildCondition, () {}, buildBody); | 3475 handleLoop(node, buildInitializer, buildCondition, () {}, buildBody); |
| 3474 } | 3476 } |
| 3475 | 3477 |
| (...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4498 new HSubGraphBlockInformation(elseBranch.graph)); | 4500 new HSubGraphBlockInformation(elseBranch.graph)); |
| 4499 | 4501 |
| 4500 HBasicBlock conditionStartBlock = conditionBranch.block; | 4502 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 4501 conditionStartBlock.setBlockFlow(info, joinBlock); | 4503 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 4502 SubGraph conditionGraph = conditionBranch.graph; | 4504 SubGraph conditionGraph = conditionBranch.graph; |
| 4503 HIf branch = conditionGraph.end.last; | 4505 HIf branch = conditionGraph.end.last; |
| 4504 assert(branch is HIf); | 4506 assert(branch is HIf); |
| 4505 branch.blockInformation = conditionStartBlock.blockFlow; | 4507 branch.blockInformation = conditionStartBlock.blockFlow; |
| 4506 } | 4508 } |
| 4507 } | 4509 } |
| OLD | NEW |