| 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 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 | 1079 |
| 1080 HInstruction convertType(Compiler compiler, DartType type, int kind) { | 1080 HInstruction convertType(Compiler compiler, DartType type, int kind) { |
| 1081 if (type == null) return this; | 1081 if (type == null) return this; |
| 1082 if (identical(type.element, compiler.dynamicClass)) return this; | 1082 if (identical(type.element, compiler.dynamicClass)) return this; |
| 1083 if (identical(type.element, compiler.objectClass)) return this; | 1083 if (identical(type.element, compiler.objectClass)) return this; |
| 1084 if (type.isMalformed || type.kind != TypeKind.INTERFACE) { | 1084 if (type.isMalformed || type.kind != TypeKind.INTERFACE) { |
| 1085 return new HTypeConversion(type, kind, HType.UNKNOWN, this); | 1085 return new HTypeConversion(type, kind, HType.UNKNOWN, this); |
| 1086 } else if (kind == HTypeConversion.BOOLEAN_CONVERSION_CHECK) { | 1086 } else if (kind == HTypeConversion.BOOLEAN_CONVERSION_CHECK) { |
| 1087 // Boolean conversion checks work on non-nullable booleans. | 1087 // Boolean conversion checks work on non-nullable booleans. |
| 1088 return new HTypeConversion(type, kind, HType.BOOLEAN, this); | 1088 return new HTypeConversion(type, kind, HType.BOOLEAN, this); |
| 1089 } else if (kind == HTypeConversion.CHECKED_MODE_CHECK && !type.isRaw) { |
| 1090 throw 'creating compound check to $type (this = ${this})'; |
| 1089 } else { | 1091 } else { |
| 1090 HType subtype = new HType.subtype(type, compiler); | 1092 HType subtype = new HType.subtype(type, compiler); |
| 1091 return new HTypeConversion(type, kind, subtype, this); | 1093 return new HTypeConversion(type, kind, subtype, this); |
| 1092 } | 1094 } |
| 1093 } | 1095 } |
| 1094 | 1096 |
| 1095 /** | 1097 /** |
| 1096 * Return whether the instructions do not belong to a loop or | 1098 * Return whether the instructions do not belong to a loop or |
| 1097 * belong to the same loop. | 1099 * belong to the same loop. |
| 1098 */ | 1100 */ |
| (...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2131 sideEffects.setChangesIndex(); | 2133 sideEffects.setChangesIndex(); |
| 2132 } | 2134 } |
| 2133 String toString() => 'index assign operator'; | 2135 String toString() => 'index assign operator'; |
| 2134 accept(HVisitor visitor) => visitor.visitIndexAssign(this); | 2136 accept(HVisitor visitor) => visitor.visitIndexAssign(this); |
| 2135 | 2137 |
| 2136 HInstruction get receiver => inputs[0]; | 2138 HInstruction get receiver => inputs[0]; |
| 2137 HInstruction get index => inputs[1]; | 2139 HInstruction get index => inputs[1]; |
| 2138 HInstruction get value => inputs[2]; | 2140 HInstruction get value => inputs[2]; |
| 2139 } | 2141 } |
| 2140 | 2142 |
| 2141 // TODO(karlklose): use this class to represent type conversions as well. | |
| 2142 class HIs extends HInstruction { | 2143 class HIs extends HInstruction { |
| 2143 /// A check against a raw type: 'o is int', 'o is A'. | 2144 /// A check against a raw type: 'o is int', 'o is A'. |
| 2144 static const int RAW_CHECK = 0; | 2145 static const int RAW_CHECK = 0; |
| 2145 /// A check against a type with type arguments: 'o is List<int>', 'o is C<T>'. | 2146 /// A check against a type with type arguments: 'o is List<int>', 'o is C<T>'. |
| 2146 static const int COMPOUND_CHECK = 1; | 2147 static const int COMPOUND_CHECK = 1; |
| 2147 /// A check against a single type variable: 'o is T'. | 2148 /// A check against a single type variable: 'o is T'. |
| 2148 static const int VARIABLE_CHECK = 2; | 2149 static const int VARIABLE_CHECK = 2; |
| 2149 | 2150 |
| 2150 final DartType typeExpression; | 2151 final DartType typeExpression; |
| 2151 final bool nullOk; | 2152 final bool nullOk; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2198 | 2199 |
| 2199 HTypeConversion(this.typeExpression, this.kind, | 2200 HTypeConversion(this.typeExpression, this.kind, |
| 2200 HType type, HInstruction input, | 2201 HType type, HInstruction input, |
| 2201 [this.receiverTypeCheckSelector]) | 2202 [this.receiverTypeCheckSelector]) |
| 2202 : super(<HInstruction>[input]) { | 2203 : super(<HInstruction>[input]) { |
| 2203 assert(!isReceiverTypeCheck || receiverTypeCheckSelector != null); | 2204 assert(!isReceiverTypeCheck || receiverTypeCheckSelector != null); |
| 2204 sourceElement = input.sourceElement; | 2205 sourceElement = input.sourceElement; |
| 2205 instructionType = type; | 2206 instructionType = type; |
| 2206 } | 2207 } |
| 2207 | 2208 |
| 2209 HTypeConversion.withTypeRepresentation(this.typeExpression, this.kind, |
| 2210 HType type, HInstruction input, |
| 2211 HInstruction typeRepresentation) |
| 2212 : super(<HInstruction>[input, typeRepresentation]), |
| 2213 receiverTypeCheckSelector = null { |
| 2214 sourceElement = input.sourceElement; |
| 2215 instructionType = type; |
| 2216 } |
| 2217 |
| 2218 bool get hasTypeRepresentation => inputs.length > 1; |
| 2219 HInstruction get typeRepresentation => inputs[1]; |
| 2220 |
| 2221 HInstruction convertType(Compiler compiler, DartType type, int kind) { |
| 2222 if (typeExpression == type) return this; |
| 2223 return super.convertType(compiler, type, kind); |
| 2224 } |
| 2225 |
| 2208 bool get isChecked => kind != NO_CHECK; | 2226 bool get isChecked => kind != NO_CHECK; |
| 2209 bool get isCheckedModeCheck { | 2227 bool get isCheckedModeCheck { |
| 2210 return kind == CHECKED_MODE_CHECK | 2228 return kind == CHECKED_MODE_CHECK |
| 2211 || kind == BOOLEAN_CONVERSION_CHECK; | 2229 || kind == BOOLEAN_CONVERSION_CHECK; |
| 2212 } | 2230 } |
| 2213 bool get isArgumentTypeCheck => kind == ARGUMENT_TYPE_CHECK; | 2231 bool get isArgumentTypeCheck => kind == ARGUMENT_TYPE_CHECK; |
| 2214 bool get isReceiverTypeCheck => kind == RECEIVER_TYPE_CHECK; | 2232 bool get isReceiverTypeCheck => kind == RECEIVER_TYPE_CHECK; |
| 2215 bool get isCastTypeCheck => kind == CAST_TYPE_CHECK; | 2233 bool get isCastTypeCheck => kind == CAST_TYPE_CHECK; |
| 2216 bool get isBooleanConversionCheck => kind == BOOLEAN_CONVERSION_CHECK; | 2234 bool get isBooleanConversionCheck => kind == BOOLEAN_CONVERSION_CHECK; |
| 2217 | 2235 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2604 HBasicBlock get start => expression.start; | 2622 HBasicBlock get start => expression.start; |
| 2605 HBasicBlock get end { | 2623 HBasicBlock get end { |
| 2606 // We don't create a switch block if there are no cases. | 2624 // We don't create a switch block if there are no cases. |
| 2607 assert(!statements.isEmpty); | 2625 assert(!statements.isEmpty); |
| 2608 return statements.last.end; | 2626 return statements.last.end; |
| 2609 } | 2627 } |
| 2610 | 2628 |
| 2611 bool accept(HStatementInformationVisitor visitor) => | 2629 bool accept(HStatementInformationVisitor visitor) => |
| 2612 visitor.visitSwitchInfo(this); | 2630 visitor.visitSwitchInfo(this); |
| 2613 } | 2631 } |
| OLD | NEW |