| 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A special element for the extra parameter taken by intercepted | 8 * A special element for the extra parameter taken by intercepted |
| 9 * methods. We need to override [Element.computeType] because our | 9 * methods. We need to override [Element.computeType] because our |
| 10 * optimizers may look at its declared type. | 10 * optimizers may look at its declared type. |
| (...skipping 2752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2763 visitBinary(left, op, right, elements.getSelector(node), node); | 2763 visitBinary(left, op, right, elements.getSelector(node), node); |
| 2764 } | 2764 } |
| 2765 } | 2765 } |
| 2766 | 2766 |
| 2767 void visitIsSend(Send node) { | 2767 void visitIsSend(Send node) { |
| 2768 visit(node.receiver); | 2768 visit(node.receiver); |
| 2769 HInstruction expression = pop(); | 2769 HInstruction expression = pop(); |
| 2770 bool isNot = node.isIsNotCheck; | 2770 bool isNot = node.isIsNotCheck; |
| 2771 DartType type = elements.getType(node.typeAnnotationFromIsCheckOrCast); | 2771 DartType type = elements.getType(node.typeAnnotationFromIsCheckOrCast); |
| 2772 type = type.unalias(compiler); | 2772 type = type.unalias(compiler); |
| 2773 if (type.containsAmbiguousTypes) { | 2773 HInstruction instruction = buildIsNode(node, type, expression); |
| 2774 String reasons = Types.fetchReasonsFromAmbiguousType(type); | 2774 if (isNot) { |
| 2775 if (compiler.enableTypeAssertions) { | 2775 add(instruction); |
| 2776 generateMalformedSubtypeError(node, expression, type, reasons); | 2776 instruction = new HNot(instruction); |
| 2777 } else { | |
| 2778 generateRuntimeError(node, '$type is ambiguous: $reasons'); | |
| 2779 } | |
| 2780 } else { | |
| 2781 HInstruction instruction = buildIsNode(node, type, expression); | |
| 2782 if (isNot) { | |
| 2783 add(instruction); | |
| 2784 instruction = new HNot(instruction); | |
| 2785 } | |
| 2786 push(instruction); | |
| 2787 } | 2777 } |
| 2778 push(instruction); |
| 2788 } | 2779 } |
| 2789 | 2780 |
| 2790 HLiteralList buildTypeVariableList(ClassElement contextClass) { | 2781 HLiteralList buildTypeVariableList(ClassElement contextClass) { |
| 2791 List<HInstruction> inputs = <HInstruction>[]; | 2782 List<HInstruction> inputs = <HInstruction>[]; |
| 2792 for (Link<DartType> link = contextClass.typeVariables; | 2783 for (Link<DartType> link = contextClass.typeVariables; |
| 2793 !link.isEmpty; | 2784 !link.isEmpty; |
| 2794 link = link.tail) { | 2785 link = link.tail) { |
| 2795 inputs.add(addTypeVariableReference(link.head)); | 2786 inputs.add(addTypeVariableReference(link.head)); |
| 2796 } | 2787 } |
| 2797 return buildLiteralList(inputs); | 2788 return buildLiteralList(inputs); |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3402 return readTypeVariable(member.getEnclosingClass(), | 3393 return readTypeVariable(member.getEnclosingClass(), |
| 3403 type.element); | 3394 type.element); |
| 3404 } else { | 3395 } else { |
| 3405 // TODO(ngeoffray): Match the VM behavior and throw an | 3396 // TODO(ngeoffray): Match the VM behavior and throw an |
| 3406 // exception at runtime. | 3397 // exception at runtime. |
| 3407 compiler.cancel('Unimplemented unresolved type variable', | 3398 compiler.cancel('Unimplemented unresolved type variable', |
| 3408 element: type.element); | 3399 element: type.element); |
| 3409 } | 3400 } |
| 3410 } | 3401 } |
| 3411 | 3402 |
| 3412 /** | |
| 3413 * Documentation wanted -- johnniwinther | |
| 3414 * | |
| 3415 * Invariant: [argument] must not be malformed in checked mode. | |
| 3416 */ | |
| 3417 HInstruction analyzeTypeArgument(DartType argument) { | 3403 HInstruction analyzeTypeArgument(DartType argument) { |
| 3418 if (argument.treatAsDynamic) { | 3404 if (argument.treatAsDynamic) { |
| 3419 // Represent [dynamic] as [null]. | 3405 // Represent [dynamic] as [null]. |
| 3420 return graph.addConstantNull(compiler); | 3406 return graph.addConstantNull(compiler); |
| 3421 } | 3407 } |
| 3422 | 3408 |
| 3423 List<HInstruction> inputs = <HInstruction>[]; | 3409 List<HInstruction> inputs = <HInstruction>[]; |
| 3424 | 3410 |
| 3425 String template = rti.getTypeRepresentation(argument, (variable) { | 3411 String template = rti.getTypeRepresentation(argument, (variable) { |
| 3426 inputs.add(addTypeVariableReference(variable)); | 3412 inputs.add(addTypeVariableReference(variable)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3457 // Set the runtime type information on the object. | 3443 // Set the runtime type information on the object. |
| 3458 Element typeInfoSetterElement = backend.getSetRuntimeTypeInfo(); | 3444 Element typeInfoSetterElement = backend.getSetRuntimeTypeInfo(); |
| 3459 pushInvokeStatic( | 3445 pushInvokeStatic( |
| 3460 null, | 3446 null, |
| 3461 typeInfoSetterElement, | 3447 typeInfoSetterElement, |
| 3462 <HInstruction>[newObject, typeInfo], | 3448 <HInstruction>[newObject, typeInfo], |
| 3463 HType.UNKNOWN); | 3449 HType.UNKNOWN); |
| 3464 pop(); | 3450 pop(); |
| 3465 } | 3451 } |
| 3466 | 3452 |
| 3467 /** | |
| 3468 * Documentation wanted -- johnniwinther | |
| 3469 * | |
| 3470 * Invariant: [type] must not be malformed in checked mode. | |
| 3471 */ | |
| 3472 handleNewSend(NewExpression node, InterfaceType type) { | 3453 handleNewSend(NewExpression node, InterfaceType type) { |
| 3473 Send send = node.send; | 3454 Send send = node.send; |
| 3474 bool isListConstructor = false; | 3455 bool isListConstructor = false; |
| 3475 computeType(element) { | 3456 computeType(element) { |
| 3476 Element originalElement = elements[send]; | 3457 Element originalElement = elements[send]; |
| 3477 if (Elements.isFixedListConstructorCall(originalElement, send, compiler) | 3458 if (Elements.isFixedListConstructorCall(originalElement, send, compiler) |
| 3478 || Elements.isFilledListConstructorCall( | 3459 || Elements.isFilledListConstructorCall( |
| 3479 originalElement, send, compiler)) { | 3460 originalElement, send, compiler)) { |
| 3480 isListConstructor = true; | 3461 isListConstructor = true; |
| 3481 HType inferred = | 3462 HType inferred = |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3738 FunctionSignature signature = function.computeSignature(compiler); | 3719 FunctionSignature signature = function.computeSignature(compiler); |
| 3739 signature.forEachParameter((Element parameter) { | 3720 signature.forEachParameter((Element parameter) { |
| 3740 existingArguments.add(parameter.name.slowToString()); | 3721 existingArguments.add(parameter.name.slowToString()); |
| 3741 }); | 3722 }); |
| 3742 generateThrowNoSuchMethod(diagnosticNode, | 3723 generateThrowNoSuchMethod(diagnosticNode, |
| 3743 function.name.slowToString(), | 3724 function.name.slowToString(), |
| 3744 argumentNodes: argumentNodes, | 3725 argumentNodes: argumentNodes, |
| 3745 existingArguments: existingArguments); | 3726 existingArguments: existingArguments); |
| 3746 } | 3727 } |
| 3747 | 3728 |
| 3748 void generateMalformedSubtypeError(Node node, HInstruction value, | |
| 3749 DartType type, String reasons) { | |
| 3750 HInstruction typeString = addConstantString(node, type.toString()); | |
| 3751 HInstruction reasonsString = addConstantString(node, reasons); | |
| 3752 Element helper = backend.getThrowMalformedSubtypeError(); | |
| 3753 pushInvokeStatic(node, helper, [value, typeString, reasonsString]); | |
| 3754 } | |
| 3755 | |
| 3756 visitNewExpression(NewExpression node) { | 3729 visitNewExpression(NewExpression node) { |
| 3757 Element element = elements[node.send]; | 3730 Element element = elements[node.send]; |
| 3758 final bool isSymbolConstructor = element == compiler.symbolConstructor; | 3731 final bool isSymbolConstructor = element == compiler.symbolConstructor; |
| 3759 if (!Elements.isErroneousElement(element)) { | 3732 if (!Elements.isErroneousElement(element)) { |
| 3760 FunctionElement function = element; | 3733 FunctionElement function = element; |
| 3761 element = function.redirectionTarget; | 3734 element = function.redirectionTarget; |
| 3762 } | 3735 } |
| 3763 if (Elements.isErroneousElement(element)) { | 3736 if (Elements.isErroneousElement(element)) { |
| 3764 ErroneousElement error = element; | 3737 ErroneousElement error = element; |
| 3765 if (error.messageKind == MessageKind.CANNOT_FIND_CONSTRUCTOR.error) { | 3738 if (error.messageKind == MessageKind.CANNOT_FIND_CONSTRUCTOR.error) { |
| 3766 generateThrowNoSuchMethod(node.send, | 3739 generateThrowNoSuchMethod(node.send, |
| 3767 getTargetName(error, 'constructor'), | 3740 getTargetName(error, 'constructor'), |
| 3768 argumentNodes: node.send.arguments); | 3741 argumentNodes: node.send.arguments); |
| 3769 } else { | 3742 } else { |
| 3770 Message message = error.messageKind.message(error.messageArguments); | 3743 Message message = error.messageKind.message(error.messageArguments); |
| 3771 generateRuntimeError(node.send, message.toString()); | 3744 generateRuntimeError(node.send, message.toString()); |
| 3772 } | 3745 } |
| 3773 } else if (node.isConst()) { | 3746 } else if (node.isConst()) { |
| 3774 ConstantHandler handler = compiler.constantHandler; | 3747 ConstantHandler handler = compiler.constantHandler; |
| 3775 Constant constant = handler.compileNodeWithDefinitions(node, elements); | 3748 Constant constant = handler.compileNodeWithDefinitions(node, elements); |
| 3776 stack.add(graph.addConstant(constant, compiler)); | 3749 stack.add(graph.addConstant(constant, compiler)); |
| 3777 if (isSymbolConstructor) { | 3750 if (isSymbolConstructor) { |
| 3778 ConstructedConstant symbol = constant; | 3751 ConstructedConstant symbol = constant; |
| 3779 StringConstant stringConstant = symbol.fields.single; | 3752 StringConstant stringConstant = symbol.fields.single; |
| 3780 String nameString = stringConstant.toDartString().slowToString(); | 3753 String nameString = stringConstant.toDartString().slowToString(); |
| 3781 compiler.enqueuer.codegen.registerConstSymbol(nameString, elements); | 3754 compiler.enqueuer.codegen.registerConstSymbol(nameString, elements); |
| 3782 } | 3755 } |
| 3783 } else { | 3756 } else { |
| 3784 DartType type = elements.getType(node); | 3757 DartType type = elements.getType(node); |
| 3785 if (compiler.enableTypeAssertions && type.containsAmbiguousTypes) { | 3758 // TODO(karlklose): move this type registration to the codegen. |
| 3786 String reasons = Types.fetchReasonsFromAmbiguousType(type); | 3759 compiler.codegenWorld.instantiatedTypes.add(type); |
| 3787 // TODO(johnniwinther): Change to resemble type errors from bounds check | 3760 handleNewSend(node, type); |
| 3788 // on type arguments. | |
| 3789 generateRuntimeError(node, '$type is malformed: $reasons'); | |
| 3790 } else { | |
| 3791 // TODO(karlklose): move this type registration to the codegen. | |
| 3792 compiler.codegenWorld.instantiatedTypes.add(type); | |
| 3793 handleNewSend(node, type); | |
| 3794 } | |
| 3795 } | 3761 } |
| 3796 } | 3762 } |
| 3797 | 3763 |
| 3798 void pushInvokeDynamic(Node node, | 3764 void pushInvokeDynamic(Node node, |
| 3799 Selector selector, | 3765 Selector selector, |
| 3800 List<HInstruction> arguments, | 3766 List<HInstruction> arguments, |
| 3801 {Node location}) { | 3767 {Node location}) { |
| 3802 if (location == null) location = node; | 3768 if (location == null) location = node; |
| 3803 | 3769 |
| 3804 // We prefer to not inline certain operations on indexables, | 3770 // We prefer to not inline certain operations on indexables, |
| (...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4945 condition = new HIs(type, <HInstruction>[unwrappedException], | 4911 condition = new HIs(type, <HInstruction>[unwrappedException], |
| 4946 HIs.RAW_CHECK); | 4912 HIs.RAW_CHECK); |
| 4947 push(condition); | 4913 push(condition); |
| 4948 } | 4914 } |
| 4949 } | 4915 } |
| 4950 } | 4916 } |
| 4951 | 4917 |
| 4952 void visitThen() { | 4918 void visitThen() { |
| 4953 CatchBlock catchBlock = link.head; | 4919 CatchBlock catchBlock = link.head; |
| 4954 link = link.tail; | 4920 link = link.tail; |
| 4955 | |
| 4956 if (compiler.enableTypeAssertions) { | |
| 4957 // In checked mode: throw a type error if the on-catch type is | |
| 4958 // malformed. | |
| 4959 if (catchBlock.onKeyword != null) { | |
| 4960 DartType type = elements.getType(catchBlock.type); | |
| 4961 if (type != null && type.containsAmbiguousTypes) { | |
| 4962 String reasons = Types.fetchReasonsFromAmbiguousType(type); | |
| 4963 generateMalformedSubtypeError(node, | |
| 4964 unwrappedException, type, reasons); | |
| 4965 pop(); | |
| 4966 return; | |
| 4967 } | |
| 4968 } | |
| 4969 } | |
| 4970 if (catchBlock.exception != null) { | 4921 if (catchBlock.exception != null) { |
| 4971 localsHandler.updateLocal(elements[catchBlock.exception], | 4922 localsHandler.updateLocal(elements[catchBlock.exception], |
| 4972 unwrappedException); | 4923 unwrappedException); |
| 4973 } | 4924 } |
| 4974 Node trace = catchBlock.trace; | 4925 Node trace = catchBlock.trace; |
| 4975 if (trace != null) { | 4926 if (trace != null) { |
| 4976 pushInvokeStatic(trace, backend.getTraceFromException(), [exception]); | 4927 pushInvokeStatic(trace, backend.getTraceFromException(), [exception]); |
| 4977 HInstruction traceInstruction = pop(); | 4928 HInstruction traceInstruction = pop(); |
| 4978 localsHandler.updateLocal(elements[trace], traceInstruction); | 4929 localsHandler.updateLocal(elements[trace], traceInstruction); |
| 4979 } | 4930 } |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5505 new HSubGraphBlockInformation(elseBranch.graph)); | 5456 new HSubGraphBlockInformation(elseBranch.graph)); |
| 5506 | 5457 |
| 5507 HBasicBlock conditionStartBlock = conditionBranch.block; | 5458 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 5508 conditionStartBlock.setBlockFlow(info, joinBlock); | 5459 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 5509 SubGraph conditionGraph = conditionBranch.graph; | 5460 SubGraph conditionGraph = conditionBranch.graph; |
| 5510 HIf branch = conditionGraph.end.last; | 5461 HIf branch = conditionGraph.end.last; |
| 5511 assert(branch is HIf); | 5462 assert(branch is HIf); |
| 5512 branch.blockInformation = conditionStartBlock.blockFlow; | 5463 branch.blockInformation = conditionStartBlock.blockFlow; |
| 5513 } | 5464 } |
| 5514 } | 5465 } |
| OLD | NEW |