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 5613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5624 } | 5624 } |
5625 List<HInstruction> listInputs = <HInstruction>[]; | 5625 List<HInstruction> listInputs = <HInstruction>[]; |
5626 for (Link<ast.Node> link = node.entries.nodes; | 5626 for (Link<ast.Node> link = node.entries.nodes; |
5627 !link.isEmpty; | 5627 !link.isEmpty; |
5628 link = link.tail) { | 5628 link = link.tail) { |
5629 visit(link.head); | 5629 visit(link.head); |
5630 listInputs.add(pop()); | 5630 listInputs.add(pop()); |
5631 listInputs.add(pop()); | 5631 listInputs.add(pop()); |
5632 } | 5632 } |
5633 | 5633 |
5634 ConstructorElement constructor; | 5634 Element constructor; |
5635 List<HInstruction> inputs = <HInstruction>[]; | 5635 List<HInstruction> inputs = <HInstruction>[]; |
5636 | 5636 |
5637 if (listInputs.isEmpty) { | 5637 if (listInputs.isEmpty) { |
5638 constructor = backend.mapLiteralConstructorEmpty; | 5638 constructor = backend.mapLiteralConstructorEmpty; |
5639 } else { | 5639 } else { |
5640 constructor = backend.mapLiteralConstructor; | 5640 constructor = backend.mapLiteralConstructor; |
5641 HLiteralList keyValuePairs = buildLiteralList(listInputs); | 5641 HLiteralList keyValuePairs = buildLiteralList(listInputs); |
5642 add(keyValuePairs); | 5642 add(keyValuePairs); |
5643 inputs.add(keyValuePairs); | 5643 inputs.add(keyValuePairs); |
5644 } | 5644 } |
5645 | 5645 |
5646 assert(constructor.isFactoryConstructor); | 5646 assert(constructor.isFactoryConstructor); |
5647 | 5647 |
5648 ConstructorElement functionElement = constructor; | 5648 ConstructorElement functionElement = constructor; |
5649 constructor = functionElement.effectiveTarget; | 5649 constructor = functionElement.effectiveTarget; |
5650 | 5650 |
5651 InterfaceType type = elements.getType(node); | 5651 InterfaceType type = elements.getType(node); |
5652 InterfaceType expectedType = | 5652 InterfaceType expectedType = |
5653 functionElement.computeEffectiveTargetType(type); | 5653 functionElement.computeEffectiveTargetType(type); |
5654 expectedType = localsHandler.substInContext(expectedType); | 5654 expectedType = localsHandler.substInContext(expectedType); |
5655 | 5655 |
5656 ClassElement cls = constructor.enclosingClass; | 5656 ClassElement cls = constructor.enclosingClass; |
5657 | 5657 |
5658 if (backend.classNeedsRti(cls)) { | 5658 if (backend.classNeedsRti(cls)) { |
5659 List<HInstruction> typeInputs = <HInstruction>[]; | |
5659 List<DartType> typeVariable = cls.typeVariables; | 5660 List<DartType> typeVariable = cls.typeVariables; |
5660 expectedType.typeArguments.forEach((DartType argument) { | 5661 expectedType.typeArguments.forEach((DartType argument) { |
5661 inputs.add(analyzeTypeArgument(argument)); | 5662 typeInputs.add(analyzeTypeArgument(argument)); |
5662 }); | 5663 }); |
5664 if (typeInputs.every((HInstruction input) => input.isNull())) { | |
herhut
2015/04/14 11:00:14
Can you add a comment about what this is doing, i.
zarah
2015/04/14 11:27:56
Done.
| |
5665 if (listInputs.isEmpty) { | |
5666 constructor = backend.mapLiteralUntypedEmptyMaker; | |
5667 } else { | |
5668 constructor = backend.mapLiteralUntypedMaker; | |
5669 } | |
5670 } else { | |
5671 inputs.addAll(typeInputs); | |
5672 } | |
5663 } | 5673 } |
5664 | 5674 |
5675 // If rti is needed and the map literal has no type parameters, | |
5676 // 'constructor' is a static function that forwards the call to the factory | |
5677 // constructor without type parameters. | |
5678 assert(constructor is ConstructorElement || constructor is FunctionElement); | |
5679 | |
5665 // The instruction type will always be a subtype of the mapLiteralClass, but | 5680 // The instruction type will always be a subtype of the mapLiteralClass, but |
5666 // type inference might discover a more specific type, or find nothing (in | 5681 // type inference might discover a more specific type, or find nothing (in |
5667 // dart2js unit tests). | 5682 // dart2js unit tests). |
5668 TypeMask mapType = | 5683 TypeMask mapType = |
5669 new TypeMask.nonNullSubtype(backend.mapLiteralClass, compiler.world); | 5684 new TypeMask.nonNullSubtype(backend.mapLiteralClass, compiler.world); |
5670 TypeMask returnTypeMask = TypeMaskFactory.inferredReturnTypeForElement( | 5685 TypeMask returnTypeMask = TypeMaskFactory.inferredReturnTypeForElement( |
5671 constructor, compiler); | 5686 constructor, compiler); |
5672 TypeMask instructionType = | 5687 TypeMask instructionType = |
5673 mapType.intersection(returnTypeMask, compiler.world); | 5688 mapType.intersection(returnTypeMask, compiler.world); |
5674 | 5689 |
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6981 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 6996 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
6982 unaliased.accept(this, builder); | 6997 unaliased.accept(this, builder); |
6983 } | 6998 } |
6984 | 6999 |
6985 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 7000 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
6986 JavaScriptBackend backend = builder.compiler.backend; | 7001 JavaScriptBackend backend = builder.compiler.backend; |
6987 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 7002 ClassElement cls = backend.findHelper('DynamicRuntimeType'); |
6988 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 7003 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
6989 } | 7004 } |
6990 } | 7005 } |
OLD | NEW |