| 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 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 | 1083 |
| 1084 HInstruction convertType(Compiler compiler, DartType type, int kind) { | 1084 HInstruction convertType(Compiler compiler, DartType type, int kind) { |
| 1085 if (type == null) return this; | 1085 if (type == null) return this; |
| 1086 if (identical(type.element, compiler.dynamicClass)) return this; | 1086 if (identical(type.element, compiler.dynamicClass)) return this; |
| 1087 if (identical(type.element, compiler.objectClass)) return this; | 1087 if (identical(type.element, compiler.objectClass)) return this; |
| 1088 if (type.isMalformed || type.kind != TypeKind.INTERFACE) { | 1088 if (type.isMalformed || type.kind != TypeKind.INTERFACE) { |
| 1089 return new HTypeConversion(type, kind, HType.UNKNOWN, this); | 1089 return new HTypeConversion(type, kind, HType.UNKNOWN, this); |
| 1090 } else if (kind == HTypeConversion.BOOLEAN_CONVERSION_CHECK) { | 1090 } else if (kind == HTypeConversion.BOOLEAN_CONVERSION_CHECK) { |
| 1091 // Boolean conversion checks work on non-nullable booleans. | 1091 // Boolean conversion checks work on non-nullable booleans. |
| 1092 return new HTypeConversion(type, kind, HType.BOOLEAN, this); | 1092 return new HTypeConversion(type, kind, HType.BOOLEAN, this); |
| 1093 } else if (kind == HTypeConversion.CHECKED_MODE_CHECK && !type.isRaw) { | |
| 1094 throw 'creating compound check to $type (this = ${this})'; | |
| 1095 } else { | 1093 } else { |
| 1096 HType subtype = new HType.subtype(type, compiler); | 1094 HType subtype = new HType.subtype(type, compiler); |
| 1097 return new HTypeConversion(type, kind, subtype, this); | 1095 return new HTypeConversion(type, kind, subtype, this); |
| 1098 } | 1096 } |
| 1099 } | 1097 } |
| 1100 | 1098 |
| 1101 /** | 1099 /** |
| 1102 * Return whether the instructions do not belong to a loop or | 1100 * Return whether the instructions do not belong to a loop or |
| 1103 * belong to the same loop. | 1101 * belong to the same loop. |
| 1104 */ | 1102 */ |
| (...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2150 sideEffects.setChangesIndex(); | 2148 sideEffects.setChangesIndex(); |
| 2151 } | 2149 } |
| 2152 String toString() => 'index assign operator'; | 2150 String toString() => 'index assign operator'; |
| 2153 accept(HVisitor visitor) => visitor.visitIndexAssign(this); | 2151 accept(HVisitor visitor) => visitor.visitIndexAssign(this); |
| 2154 | 2152 |
| 2155 HInstruction get receiver => inputs[0]; | 2153 HInstruction get receiver => inputs[0]; |
| 2156 HInstruction get index => inputs[1]; | 2154 HInstruction get index => inputs[1]; |
| 2157 HInstruction get value => inputs[2]; | 2155 HInstruction get value => inputs[2]; |
| 2158 } | 2156 } |
| 2159 | 2157 |
| 2158 // TODO(karlklose): use this class to represent type conversions as well. |
| 2160 class HIs extends HInstruction { | 2159 class HIs extends HInstruction { |
| 2161 /// A check against a raw type: 'o is int', 'o is A'. | 2160 /// A check against a raw type: 'o is int', 'o is A'. |
| 2162 static const int RAW_CHECK = 0; | 2161 static const int RAW_CHECK = 0; |
| 2163 /// A check against a type with type arguments: 'o is List<int>', 'o is C<T>'. | 2162 /// A check against a type with type arguments: 'o is List<int>', 'o is C<T>'. |
| 2164 static const int COMPOUND_CHECK = 1; | 2163 static const int COMPOUND_CHECK = 1; |
| 2165 /// A check against a single type variable: 'o is T'. | 2164 /// A check against a single type variable: 'o is T'. |
| 2166 static const int VARIABLE_CHECK = 2; | 2165 static const int VARIABLE_CHECK = 2; |
| 2167 | 2166 |
| 2168 final DartType typeExpression; | 2167 final DartType typeExpression; |
| 2169 final bool nullOk; | 2168 final bool nullOk; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2216 | 2215 |
| 2217 HTypeConversion(this.typeExpression, this.kind, | 2216 HTypeConversion(this.typeExpression, this.kind, |
| 2218 HType type, HInstruction input, | 2217 HType type, HInstruction input, |
| 2219 [this.receiverTypeCheckSelector]) | 2218 [this.receiverTypeCheckSelector]) |
| 2220 : super(<HInstruction>[input]) { | 2219 : super(<HInstruction>[input]) { |
| 2221 assert(!isReceiverTypeCheck || receiverTypeCheckSelector != null); | 2220 assert(!isReceiverTypeCheck || receiverTypeCheckSelector != null); |
| 2222 sourceElement = input.sourceElement; | 2221 sourceElement = input.sourceElement; |
| 2223 instructionType = type; | 2222 instructionType = type; |
| 2224 } | 2223 } |
| 2225 | 2224 |
| 2226 HTypeConversion.withTypeRepresentation(this.typeExpression, this.kind, | |
| 2227 HType type, HInstruction input, | |
| 2228 HInstruction typeRepresentation) | |
| 2229 : super(<HInstruction>[input, typeRepresentation]), | |
| 2230 receiverTypeCheckSelector = null { | |
| 2231 sourceElement = input.sourceElement; | |
| 2232 instructionType = type; | |
| 2233 } | |
| 2234 | |
| 2235 bool get hasTypeRepresentation => inputs.length > 1; | |
| 2236 HInstruction get typeRepresentation => inputs[1]; | |
| 2237 | |
| 2238 HInstruction convertType(Compiler compiler, DartType type, int kind) { | |
| 2239 if (typeExpression == type) return this; | |
| 2240 return super.convertType(compiler, type, kind); | |
| 2241 } | |
| 2242 | |
| 2243 bool get isChecked => kind != NO_CHECK; | 2225 bool get isChecked => kind != NO_CHECK; |
| 2244 bool get isCheckedModeCheck { | 2226 bool get isCheckedModeCheck { |
| 2245 return kind == CHECKED_MODE_CHECK | 2227 return kind == CHECKED_MODE_CHECK |
| 2246 || kind == BOOLEAN_CONVERSION_CHECK; | 2228 || kind == BOOLEAN_CONVERSION_CHECK; |
| 2247 } | 2229 } |
| 2248 bool get isArgumentTypeCheck => kind == ARGUMENT_TYPE_CHECK; | 2230 bool get isArgumentTypeCheck => kind == ARGUMENT_TYPE_CHECK; |
| 2249 bool get isReceiverTypeCheck => kind == RECEIVER_TYPE_CHECK; | 2231 bool get isReceiverTypeCheck => kind == RECEIVER_TYPE_CHECK; |
| 2250 bool get isCastTypeCheck => kind == CAST_TYPE_CHECK; | 2232 bool get isCastTypeCheck => kind == CAST_TYPE_CHECK; |
| 2251 bool get isBooleanConversionCheck => kind == BOOLEAN_CONVERSION_CHECK; | 2233 bool get isBooleanConversionCheck => kind == BOOLEAN_CONVERSION_CHECK; |
| 2252 | 2234 |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2642 HBasicBlock get start => expression.start; | 2624 HBasicBlock get start => expression.start; |
| 2643 HBasicBlock get end { | 2625 HBasicBlock get end { |
| 2644 // We don't create a switch block if there are no cases. | 2626 // We don't create a switch block if there are no cases. |
| 2645 assert(!statements.isEmpty); | 2627 assert(!statements.isEmpty); |
| 2646 return statements.last.end; | 2628 return statements.last.end; |
| 2647 } | 2629 } |
| 2648 | 2630 |
| 2649 bool accept(HStatementInformationVisitor visitor) => | 2631 bool accept(HStatementInformationVisitor visitor) => |
| 2650 visitor.visitSwitchInfo(this); | 2632 visitor.visitSwitchInfo(this); |
| 2651 } | 2633 } |
| OLD | NEW |