| 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 final SsaCodeGeneratorTask generator; | 8 final SsaCodeGeneratorTask generator; |
| 9 final SsaBuilderTask builder; | 9 final SsaBuilderTask builder; |
| 10 final SsaOptimizerTask optimizer; | 10 final SsaOptimizerTask optimizer; |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 this.rti = backend.rti, | 1098 this.rti = backend.rti, |
| 1099 this.elements = work.resolutionTree { | 1099 this.elements = work.resolutionTree { |
| 1100 graph.element = work.element; | 1100 graph.element = work.element; |
| 1101 localsHandler = new LocalsHandler(this, work.element, null); | 1101 localsHandler = new LocalsHandler(this, work.element, null); |
| 1102 sourceElementStack.add(work.element); | 1102 sourceElementStack.add(work.element); |
| 1103 sourceInformationBuilder = | 1103 sourceInformationBuilder = |
| 1104 sourceInformationFactory.createBuilderForContext( | 1104 sourceInformationFactory.createBuilderForContext( |
| 1105 work.element.implementation); | 1105 work.element.implementation); |
| 1106 } | 1106 } |
| 1107 | 1107 |
| 1108 // TODO(johnniwinther): Avoid the need for this. |
| 1109 Resolution get resolution => compiler.resolution; |
| 1110 |
| 1108 @override | 1111 @override |
| 1109 SemanticSendVisitor get sendVisitor => this; | 1112 SemanticSendVisitor get sendVisitor => this; |
| 1110 | 1113 |
| 1111 @override | 1114 @override |
| 1112 void visitNode(ast.Node node) { | 1115 void visitNode(ast.Node node) { |
| 1113 internalError(node, "Unhandled node: $node"); | 1116 internalError(node, "Unhandled node: $node"); |
| 1114 } | 1117 } |
| 1115 | 1118 |
| 1116 @override | 1119 @override |
| 1117 void apply(ast.Node node, [_]) { | 1120 void apply(ast.Node node, [_]) { |
| (...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2472 } | 2475 } |
| 2473 | 2476 |
| 2474 /// Build a [HTypeConversion] for convertion [original] to type [type]. | 2477 /// Build a [HTypeConversion] for convertion [original] to type [type]. |
| 2475 /// | 2478 /// |
| 2476 /// Invariant: [type] must be valid in the context. | 2479 /// Invariant: [type] must be valid in the context. |
| 2477 /// See [LocalsHandler.substInContext]. | 2480 /// See [LocalsHandler.substInContext]. |
| 2478 HInstruction buildTypeConversion(HInstruction original, | 2481 HInstruction buildTypeConversion(HInstruction original, |
| 2479 DartType type, | 2482 DartType type, |
| 2480 int kind) { | 2483 int kind) { |
| 2481 if (type == null) return original; | 2484 if (type == null) return original; |
| 2482 type = type.unalias(compiler); | 2485 type = type.unalias(resolution); |
| 2483 assert(assertTypeInContext(type, original)); | 2486 assert(assertTypeInContext(type, original)); |
| 2484 if (type.isInterfaceType && !type.treatAsRaw) { | 2487 if (type.isInterfaceType && !type.treatAsRaw) { |
| 2485 TypeMask subtype = new TypeMask.subtype(type.element, compiler.world); | 2488 TypeMask subtype = new TypeMask.subtype(type.element, compiler.world); |
| 2486 HInstruction representations = buildTypeArgumentRepresentations(type); | 2489 HInstruction representations = buildTypeArgumentRepresentations(type); |
| 2487 add(representations); | 2490 add(representations); |
| 2488 return new HTypeConversion.withTypeRepresentation(type, kind, subtype, | 2491 return new HTypeConversion.withTypeRepresentation(type, kind, subtype, |
| 2489 original, representations); | 2492 original, representations); |
| 2490 } else if (type.isTypeVariable) { | 2493 } else if (type.isTypeVariable) { |
| 2491 TypeMask subtype = original.instructionType; | 2494 TypeMask subtype = original.instructionType; |
| 2492 HInstruction typeVariable = addTypeVariableReference(type); | 2495 HInstruction typeVariable = addTypeVariableReference(type); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2508 return new HTypeConversion(type, kind, original.instructionType, pop()); | 2511 return new HTypeConversion(type, kind, original.instructionType, pop()); |
| 2509 } else { | 2512 } else { |
| 2510 return original.convertType(compiler, type, kind); | 2513 return original.convertType(compiler, type, kind); |
| 2511 } | 2514 } |
| 2512 } | 2515 } |
| 2513 | 2516 |
| 2514 HInstruction _trustType(HInstruction original, DartType type) { | 2517 HInstruction _trustType(HInstruction original, DartType type) { |
| 2515 assert(compiler.trustTypeAnnotations); | 2518 assert(compiler.trustTypeAnnotations); |
| 2516 assert(type != null); | 2519 assert(type != null); |
| 2517 type = localsHandler.substInContext(type); | 2520 type = localsHandler.substInContext(type); |
| 2518 type = type.unalias(compiler); | 2521 type = type.unalias(resolution); |
| 2519 if (type.isDynamic) return original; | 2522 if (type.isDynamic) return original; |
| 2520 if (!type.isInterfaceType) return original; | 2523 if (!type.isInterfaceType) return original; |
| 2521 // The type element is either a class or the void element. | 2524 // The type element is either a class or the void element. |
| 2522 Element element = type.element; | 2525 Element element = type.element; |
| 2523 if (element == compiler.objectClass) return original; | 2526 if (element == compiler.objectClass) return original; |
| 2524 TypeMask mask = new TypeMask.subtype(element, compiler.world); | 2527 TypeMask mask = new TypeMask.subtype(element, compiler.world); |
| 2525 return new HTypeKnown.pinned(mask, original); | 2528 return new HTypeKnown.pinned(mask, original); |
| 2526 } | 2529 } |
| 2527 | 2530 |
| 2528 HInstruction _checkType(HInstruction original, DartType type, int kind) { | 2531 HInstruction _checkType(HInstruction original, DartType type, int kind) { |
| (...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3803 void visitIsNot(ast.Send node, ast.Node expression, DartType type, _) { | 3806 void visitIsNot(ast.Send node, ast.Node expression, DartType type, _) { |
| 3804 HInstruction expressionInstruction = visitAndPop(expression); | 3807 HInstruction expressionInstruction = visitAndPop(expression); |
| 3805 HInstruction instruction = buildIsNode(node, type, expressionInstruction); | 3808 HInstruction instruction = buildIsNode(node, type, expressionInstruction); |
| 3806 add(instruction); | 3809 add(instruction); |
| 3807 push(new HNot(instruction, backend.boolType)); | 3810 push(new HNot(instruction, backend.boolType)); |
| 3808 } | 3811 } |
| 3809 | 3812 |
| 3810 HInstruction buildIsNode(ast.Node node, | 3813 HInstruction buildIsNode(ast.Node node, |
| 3811 DartType type, | 3814 DartType type, |
| 3812 HInstruction expression) { | 3815 HInstruction expression) { |
| 3813 type = localsHandler.substInContext(type).unalias(compiler); | 3816 type = localsHandler.substInContext(type).unalias(resolution); |
| 3814 if (type.isFunctionType) { | 3817 if (type.isFunctionType) { |
| 3815 List arguments = [buildFunctionType(type), expression]; | 3818 List arguments = [buildFunctionType(type), expression]; |
| 3816 pushInvokeDynamic( | 3819 pushInvokeDynamic( |
| 3817 node, | 3820 node, |
| 3818 new Selector.call( | 3821 new Selector.call( |
| 3819 new PrivateName('_isTest', backend.jsHelperLibrary), | 3822 new PrivateName('_isTest', backend.jsHelperLibrary), |
| 3820 CallStructure.ONE_ARG), | 3823 CallStructure.ONE_ARG), |
| 3821 null, | 3824 null, |
| 3822 arguments); | 3825 arguments); |
| 3823 return new HIs.compound(type, expression, pop(), backend.boolType); | 3826 return new HIs.compound(type, expression, pop(), backend.boolType); |
| (...skipping 5153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8977 if (type.typeArguments.isEmpty) { | 8980 if (type.typeArguments.isEmpty) { |
| 8978 cls = builder.backend.findHelper('RuntimeTypePlain'); | 8981 cls = builder.backend.findHelper('RuntimeTypePlain'); |
| 8979 } else { | 8982 } else { |
| 8980 cls = builder.backend.findHelper('RuntimeTypeGeneric'); | 8983 cls = builder.backend.findHelper('RuntimeTypeGeneric'); |
| 8981 } | 8984 } |
| 8982 builder.push(new HInterfaceType(inputs, type, | 8985 builder.push(new HInterfaceType(inputs, type, |
| 8983 new TypeMask.exact(cls, classWorld))); | 8986 new TypeMask.exact(cls, classWorld))); |
| 8984 } | 8987 } |
| 8985 | 8988 |
| 8986 void visitTypedefType(TypedefType type, SsaBuilder builder) { | 8989 void visitTypedefType(TypedefType type, SsaBuilder builder) { |
| 8987 DartType unaliased = type.unalias(builder.compiler); | 8990 DartType unaliased = type.unalias(builder.compiler.resolution); |
| 8988 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 8991 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
| 8989 unaliased.accept(this, builder); | 8992 unaliased.accept(this, builder); |
| 8990 } | 8993 } |
| 8991 | 8994 |
| 8992 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 8995 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
| 8993 JavaScriptBackend backend = builder.compiler.backend; | 8996 JavaScriptBackend backend = builder.compiler.backend; |
| 8994 ClassElement cls = backend.findHelper('DynamicRuntimeType'); | 8997 ClassElement cls = backend.findHelper('DynamicRuntimeType'); |
| 8995 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); | 8998 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); |
| 8996 } | 8999 } |
| 8997 } | 9000 } |
| OLD | NEW |