| 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 class SsaFunctionCompiler implements FunctionCompiler { | 7 class SsaFunctionCompiler implements FunctionCompiler { |
| 8 SsaCodeGeneratorTask generator; | 8 SsaCodeGeneratorTask generator; |
| 9 SsaBuilderTask builder; | 9 SsaBuilderTask builder; |
| 10 SsaOptimizerTask optimizer; | 10 SsaOptimizerTask optimizer; |
| (...skipping 4612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4623 pushInvokeStatic(node, element, inputs); | 4623 pushInvokeStatic(node, element, inputs); |
| 4624 } | 4624 } |
| 4625 } | 4625 } |
| 4626 | 4626 |
| 4627 HConstant addConstantString(String string) { | 4627 HConstant addConstantString(String string) { |
| 4628 ast.DartString dartString = new ast.DartString.literal(string); | 4628 ast.DartString dartString = new ast.DartString.literal(string); |
| 4629 ConstantValue constant = constantSystem.createString(dartString); | 4629 ConstantValue constant = constantSystem.createString(dartString); |
| 4630 return graph.addConstant(constant, compiler); | 4630 return graph.addConstant(constant, compiler); |
| 4631 } | 4631 } |
| 4632 | 4632 |
| 4633 visitTypeLiteralSend(ast.Send node) { | 4633 visitClassTypeLiteralGet( |
| 4634 DartType type = elements.getTypeLiteralType(node); | 4634 ast.Send node, |
| 4635 if (type.isInterfaceType || type.isTypedef || type.isDynamic) { | 4635 ConstantExpression constant, |
| 4636 // TODO(karlklose): add type representation | 4636 _) { |
| 4637 if (node.isCall) { | 4637 generateConstantTypeLiteral(node); |
| 4638 // The node itself is not a constant but we register the selector (the | 4638 } |
| 4639 // identifier that refers to the class/typedef) as a constant. | 4639 |
| 4640 stack.add(addConstant(node.selector)); | 4640 visitClassTypeLiteralInvoke( |
| 4641 } else { | 4641 ast.Send node, |
| 4642 stack.add(addConstant(node)); | 4642 ConstantExpression constant, |
| 4643 } | 4643 ast.NodeList arguments, |
| 4644 } else if (type.isTypeVariable) { | 4644 CallStructure callStructure, |
| 4645 type = localsHandler.substInContext(type); | 4645 _) { |
| 4646 HInstruction value = analyzeTypeArgument(type); | 4646 generateConstantTypeLiteral(node); |
| 4647 pushInvokeStatic(node, | 4647 generateTypeLiteralCall(node); |
| 4648 backend.getRuntimeTypeToString(), | 4648 } |
| 4649 [value], | 4649 |
| 4650 backend.stringType); | 4650 visitTypedefTypeLiteralGet( |
| 4651 pushInvokeStatic(node, | 4651 ast.Send node, |
| 4652 backend.getCreateRuntimeType(), | 4652 ConstantExpression constant, |
| 4653 [pop()]); | 4653 _) { |
| 4654 generateConstantTypeLiteral(node); |
| 4655 } |
| 4656 |
| 4657 visitTypedefTypeLiteralInvoke( |
| 4658 ast.Send node, |
| 4659 ConstantExpression constant, |
| 4660 ast.NodeList arguments, |
| 4661 CallStructure callStructure, |
| 4662 _) { |
| 4663 generateConstantTypeLiteral(node); |
| 4664 generateTypeLiteralCall(node); |
| 4665 } |
| 4666 |
| 4667 visitTypeVariableTypeLiteralGet( |
| 4668 ast.Send node, |
| 4669 TypeVariableElement element, |
| 4670 _) { |
| 4671 generateTypeVariableLiteral(node, element.type); |
| 4672 } |
| 4673 |
| 4674 visitTypeVariableTypeLiteralInvoke( |
| 4675 ast.Send node, |
| 4676 TypeVariableElement element, |
| 4677 ast.NodeList arguments, |
| 4678 CallStructure callStructure, |
| 4679 _) { |
| 4680 generateTypeVariableLiteral(node, element.type); |
| 4681 generateTypeLiteralCall(node); |
| 4682 } |
| 4683 |
| 4684 visitDynamicTypeLiteralGet( |
| 4685 ast.Send node, |
| 4686 ConstantExpression constant, |
| 4687 _) { |
| 4688 generateConstantTypeLiteral(node); |
| 4689 } |
| 4690 |
| 4691 visitDynamicTypeLiteralInvoke( |
| 4692 ast.Send node, |
| 4693 ConstantExpression constant, |
| 4694 ast.NodeList arguments, |
| 4695 CallStructure callStructure, |
| 4696 _) { |
| 4697 generateConstantTypeLiteral(node); |
| 4698 generateTypeLiteralCall(node); |
| 4699 } |
| 4700 |
| 4701 /// Generate the constant value for a constant type literal. |
| 4702 void generateConstantTypeLiteral(ast.Send node) { |
| 4703 // TODO(karlklose): add type representation |
| 4704 if (node.isCall) { |
| 4705 // The node itself is not a constant but we register the selector (the |
| 4706 // identifier that refers to the class/typedef) as a constant. |
| 4707 stack.add(addConstant(node.selector)); |
| 4654 } else { | 4708 } else { |
| 4655 internalError(node, 'unexpected type kind ${type.kind}'); | 4709 stack.add(addConstant(node)); |
| 4656 } | 4710 } |
| 4657 if (node.isCall) { | 4711 } |
| 4658 // This send is of the form 'e(...)', where e is resolved to a type | 4712 |
| 4659 // reference. We create a regular closure call on the result of the type | 4713 /// Generate the literal for [typeVariable] in the current context. |
| 4660 // reference instead of creating a NoSuchMethodError to avoid pulling it | 4714 void generateTypeVariableLiteral(ast.Send node, |
| 4661 // in if it is not used (e.g., in a try/catch). | 4715 TypeVariableType typeVariable) { |
| 4662 HInstruction target = pop(); | 4716 DartType type = localsHandler.substInContext(typeVariable); |
| 4663 Selector selector = elements.getSelector(node); | 4717 HInstruction value = analyzeTypeArgument(type); |
| 4664 List<HInstruction> inputs = <HInstruction>[target]; | 4718 pushInvokeStatic(node, |
| 4665 addDynamicSendArgumentsToList(node, inputs); | 4719 backend.getRuntimeTypeToString(), |
| 4666 Selector closureSelector = new Selector.callClosureFrom(selector); | 4720 [value], |
| 4667 push(new HInvokeClosure(closureSelector, inputs, backend.dynamicType)); | 4721 backend.stringType); |
| 4668 } | 4722 pushInvokeStatic(node, |
| 4723 backend.getCreateRuntimeType(), |
| 4724 [pop()]); |
| 4725 } |
| 4726 |
| 4727 /// Generate a call to a type literal. |
| 4728 void generateTypeLiteralCall(ast.Send node) { |
| 4729 // This send is of the form 'e(...)', where e is resolved to a type |
| 4730 // reference. We create a regular closure call on the result of the type |
| 4731 // reference instead of creating a NoSuchMethodError to avoid pulling it |
| 4732 // in if it is not used (e.g., in a try/catch). |
| 4733 HInstruction target = pop(); |
| 4734 Selector selector = elements.getSelector(node); |
| 4735 List<HInstruction> inputs = <HInstruction>[target]; |
| 4736 addDynamicSendArgumentsToList(node, inputs); |
| 4737 Selector closureSelector = new Selector.callClosureFrom(selector); |
| 4738 push(new HInvokeClosure(closureSelector, inputs, backend.dynamicType)); |
| 4669 } | 4739 } |
| 4670 | 4740 |
| 4671 visitGetterSend(ast.Send node) { | 4741 visitGetterSend(ast.Send node) { |
| 4672 generateIsDeferredLoadedCheckIfNeeded(node); | 4742 generateIsDeferredLoadedCheckIfNeeded(node); |
| 4673 generateGetter(node, elements[node]); | 4743 generateGetter(node, elements[node]); |
| 4674 } | 4744 } |
| 4675 | 4745 |
| 4676 // TODO(antonm): migrate rest of SsaFromAstMixin to internalError. | 4746 // TODO(antonm): migrate rest of SsaFromAstMixin to internalError. |
| 4677 internalError(Spannable node, String reason) { | 4747 internalError(Spannable node, String reason) { |
| 4678 compiler.internalError(node, reason); | 4748 compiler.internalError(node, reason); |
| (...skipping 2423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7102 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 7172 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
| 7103 unaliased.accept(this, builder); | 7173 unaliased.accept(this, builder); |
| 7104 } | 7174 } |
| 7105 | 7175 |
| 7106 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 7176 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
| 7107 JavaScriptBackend backend = builder.compiler.backend; | 7177 JavaScriptBackend backend = builder.compiler.backend; |
| 7108 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 7178 ClassElement cls = backend.findHelper('DynamicRuntimeType'); |
| 7109 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 7179 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
| 7110 } | 7180 } |
| 7111 } | 7181 } |
| OLD | NEW |