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 abstract class HVisitor<R> { | 7 abstract class HVisitor<R> { |
8 R visitAdd(HAdd node); | 8 R visitAdd(HAdd node); |
9 R visitBailoutTarget(HBailoutTarget node); | 9 R visitBailoutTarget(HBailoutTarget node); |
10 R visitBitAnd(HBitAnd node); | 10 R visitBitAnd(HBitAnd node); |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1103 HInstruction current = this.next; | 1103 HInstruction current = this.next; |
1104 while (current != null) { | 1104 while (current != null) { |
1105 if (current == other) return true; | 1105 if (current == other) return true; |
1106 current = current.next; | 1106 current = current.next; |
1107 } | 1107 } |
1108 return false; | 1108 return false; |
1109 } | 1109 } |
1110 | 1110 |
1111 HInstruction convertType(Compiler compiler, DartType type, int kind) { | 1111 HInstruction convertType(Compiler compiler, DartType type, int kind) { |
1112 if (type == null) return this; | 1112 if (type == null) return this; |
1113 type = type.unalias(compiler); | |
1113 // Only the builder knows how to create [HTypeConversion] | 1114 // Only the builder knows how to create [HTypeConversion] |
1114 // instructions with generics. It has the generic type context | 1115 // instructions with generics. It has the generic type context |
1115 // available. | 1116 // available. |
1116 assert(type.kind != TypeKind.TYPE_VARIABLE); | 1117 assert(type.kind != TypeKind.TYPE_VARIABLE); |
1117 // TODO(5022): Generic typedefs should not be handled here. | 1118 // TODO(5022): Generic typedefs should not be handled here. |
karlklose
2013/06/20 07:32:55
This TODO is obsolete now.
Johnni Winther
2013/06/21 12:19:15
Removed.
| |
1118 assert(type.isRaw | 1119 assert(type.isRaw |
1119 || type.isMalformed | 1120 || type.isMalformed |
1120 || type.kind == TypeKind.TYPEDEF | |
1121 || type.kind == TypeKind.FUNCTION); | 1121 || type.kind == TypeKind.FUNCTION); |
1122 if (identical(type.element, compiler.dynamicClass)) return this; | 1122 if (identical(type.element, compiler.dynamicClass)) return this; |
1123 if (identical(type.element, compiler.objectClass)) return this; | 1123 if (identical(type.element, compiler.objectClass)) return this; |
1124 if (type.isMalformed || type.kind != TypeKind.INTERFACE) { | 1124 if (type.isMalformed || type.kind != TypeKind.INTERFACE) { |
1125 return new HTypeConversion(type, kind, HType.UNKNOWN, this); | 1125 return new HTypeConversion(type, kind, HType.UNKNOWN, this); |
1126 } else if (kind == HTypeConversion.BOOLEAN_CONVERSION_CHECK) { | 1126 } else if (kind == HTypeConversion.BOOLEAN_CONVERSION_CHECK) { |
1127 // Boolean conversion checks work on non-nullable booleans. | 1127 // Boolean conversion checks work on non-nullable booleans. |
1128 return new HTypeConversion(type, kind, HType.BOOLEAN, this); | 1128 return new HTypeConversion(type, kind, HType.BOOLEAN, this); |
1129 } else if (kind == HTypeConversion.CHECKED_MODE_CHECK && !type.isRaw) { | 1129 } else if (kind == HTypeConversion.CHECKED_MODE_CHECK && !type.isRaw) { |
1130 throw 'creating compound check to $type (this = ${this})'; | 1130 throw 'creating compound check to $type (this = ${this})'; |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2244 return typeExpression == other.typeExpression | 2244 return typeExpression == other.typeExpression |
2245 && nullOk == other.nullOk | 2245 && nullOk == other.nullOk |
2246 && kind == other.kind; | 2246 && kind == other.kind; |
2247 } | 2247 } |
2248 } | 2248 } |
2249 | 2249 |
2250 class HTypeConversion extends HCheck { | 2250 class HTypeConversion extends HCheck { |
2251 final DartType typeExpression; | 2251 final DartType typeExpression; |
2252 final int kind; | 2252 final int kind; |
2253 final Selector receiverTypeCheckSelector; | 2253 final Selector receiverTypeCheckSelector; |
2254 final bool contextIsTypeArguments; | |
2254 | 2255 |
2255 static const int NO_CHECK = 0; | 2256 static const int NO_CHECK = 0; |
2256 static const int CHECKED_MODE_CHECK = 1; | 2257 static const int CHECKED_MODE_CHECK = 1; |
2257 static const int ARGUMENT_TYPE_CHECK = 2; | 2258 static const int ARGUMENT_TYPE_CHECK = 2; |
2258 static const int CAST_TYPE_CHECK = 3; | 2259 static const int CAST_TYPE_CHECK = 3; |
2259 static const int BOOLEAN_CONVERSION_CHECK = 4; | 2260 static const int BOOLEAN_CONVERSION_CHECK = 4; |
2260 static const int RECEIVER_TYPE_CHECK = 5; | 2261 static const int RECEIVER_TYPE_CHECK = 5; |
2261 | 2262 |
2262 HTypeConversion(this.typeExpression, this.kind, | 2263 HTypeConversion(this.typeExpression, this.kind, |
2263 HType type, HInstruction input, | 2264 HType type, HInstruction input, |
2264 [this.receiverTypeCheckSelector]) | 2265 [this.receiverTypeCheckSelector]) |
2265 : super(<HInstruction>[input]) { | 2266 : contextIsTypeArguments = false, |
2267 super(<HInstruction>[input]) { | |
2266 assert(!isReceiverTypeCheck || receiverTypeCheckSelector != null); | 2268 assert(!isReceiverTypeCheck || receiverTypeCheckSelector != null); |
2269 assert(typeExpression == null || | |
2270 typeExpression.kind != TypeKind.TYPEDEF); | |
2267 sourceElement = input.sourceElement; | 2271 sourceElement = input.sourceElement; |
2268 instructionType = type; | 2272 instructionType = type; |
2269 } | 2273 } |
2270 | 2274 |
2271 HTypeConversion.withTypeRepresentation(this.typeExpression, this.kind, | 2275 HTypeConversion.withTypeRepresentation(this.typeExpression, this.kind, |
2272 HType type, HInstruction input, | 2276 HType type, HInstruction input, |
2273 HInstruction typeRepresentation) | 2277 HInstruction typeRepresentation) |
2274 : super(<HInstruction>[input, typeRepresentation]), | 2278 : contextIsTypeArguments = false, |
2279 super(<HInstruction>[input, typeRepresentation]), | |
2275 receiverTypeCheckSelector = null { | 2280 receiverTypeCheckSelector = null { |
2281 assert(typeExpression.kind != TypeKind.TYPEDEF); | |
2276 sourceElement = input.sourceElement; | 2282 sourceElement = input.sourceElement; |
2277 instructionType = type; | 2283 instructionType = type; |
2278 } | 2284 } |
2285 | |
2286 HTypeConversion.withContext(this.typeExpression, this.kind, | |
2287 HType type, HInstruction input, | |
2288 HInstruction context, | |
2289 {bool this.contextIsTypeArguments}) | |
2290 : super(<HInstruction>[input, context]), | |
2291 receiverTypeCheckSelector = null { | |
2292 assert(typeExpression.kind != TypeKind.TYPEDEF); | |
2293 sourceElement = input.sourceElement; | |
2294 instructionType = type; | |
2295 } | |
2279 | 2296 |
2280 bool get hasTypeRepresentation => inputs.length > 1; | 2297 bool get hasTypeRepresentation => inputs.length > 1; |
2281 HInstruction get typeRepresentation => inputs[1]; | 2298 HInstruction get typeRepresentation => inputs[1]; |
2282 | 2299 |
2300 bool get hasContext => inputs.length > 1; | |
karlklose
2013/06/20 07:32:55
So we distinguish an HIs withTypeRepresentation fr
Johnni Winther
2013/06/21 12:19:15
Done.
| |
2301 HInstruction get context => inputs[1]; | |
2302 | |
2283 HInstruction convertType(Compiler compiler, DartType type, int kind) { | 2303 HInstruction convertType(Compiler compiler, DartType type, int kind) { |
2284 if (typeExpression == type) return this; | 2304 if (typeExpression == type) return this; |
2285 return super.convertType(compiler, type, kind); | 2305 return super.convertType(compiler, type, kind); |
2286 } | 2306 } |
2287 | 2307 |
2288 bool get isChecked => kind != NO_CHECK; | 2308 bool get isChecked => kind != NO_CHECK; |
2289 bool get isCheckedModeCheck { | 2309 bool get isCheckedModeCheck { |
2290 return kind == CHECKED_MODE_CHECK | 2310 return kind == CHECKED_MODE_CHECK |
2291 || kind == BOOLEAN_CONVERSION_CHECK; | 2311 || kind == BOOLEAN_CONVERSION_CHECK; |
2292 } | 2312 } |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2689 HBasicBlock get start => expression.start; | 2709 HBasicBlock get start => expression.start; |
2690 HBasicBlock get end { | 2710 HBasicBlock get end { |
2691 // We don't create a switch block if there are no cases. | 2711 // We don't create a switch block if there are no cases. |
2692 assert(!statements.isEmpty); | 2712 assert(!statements.isEmpty); |
2693 return statements.last.end; | 2713 return statements.last.end; |
2694 } | 2714 } |
2695 | 2715 |
2696 bool accept(HStatementInformationVisitor visitor) => | 2716 bool accept(HStatementInformationVisitor visitor) => |
2697 visitor.visitSwitchInfo(this); | 2717 visitor.visitSwitchInfo(this); |
2698 } | 2718 } |
OLD | NEW |