Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(646)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/nodes.dart

Issue 12334070: Support runtime check of function types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fix Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 assert(type.isRaw 1118 assert(type.isRaw
1119 || type.isMalformed 1119 || type.isMalformed
1120 || type.kind == TypeKind.TYPEDEF
1121 || type.kind == TypeKind.FUNCTION); 1120 || type.kind == TypeKind.FUNCTION);
1122 if (identical(type.element, compiler.dynamicClass)) return this; 1121 if (identical(type.element, compiler.dynamicClass)) return this;
1123 if (identical(type.element, compiler.objectClass)) return this; 1122 if (identical(type.element, compiler.objectClass)) return this;
1124 if (type.isMalformed || type.kind != TypeKind.INTERFACE) { 1123 if (type.isMalformed || type.kind != TypeKind.INTERFACE) {
1125 return new HTypeConversion(type, kind, HType.UNKNOWN, this); 1124 return new HTypeConversion(type, kind, HType.UNKNOWN, this);
1126 } else if (kind == HTypeConversion.BOOLEAN_CONVERSION_CHECK) { 1125 } else if (kind == HTypeConversion.BOOLEAN_CONVERSION_CHECK) {
1127 // Boolean conversion checks work on non-nullable booleans. 1126 // Boolean conversion checks work on non-nullable booleans.
1128 return new HTypeConversion(type, kind, HType.BOOLEAN, this); 1127 return new HTypeConversion(type, kind, HType.BOOLEAN, this);
1129 } else if (kind == HTypeConversion.CHECKED_MODE_CHECK && !type.isRaw) { 1128 } else if (kind == HTypeConversion.CHECKED_MODE_CHECK && !type.isRaw) {
1130 throw 'creating compound check to $type (this = ${this})'; 1129 throw 'creating compound check to $type (this = ${this})';
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2244 return typeExpression == other.typeExpression 2243 return typeExpression == other.typeExpression
2245 && nullOk == other.nullOk 2244 && nullOk == other.nullOk
2246 && kind == other.kind; 2245 && kind == other.kind;
2247 } 2246 }
2248 } 2247 }
2249 2248
2250 class HTypeConversion extends HCheck { 2249 class HTypeConversion extends HCheck {
2251 final DartType typeExpression; 2250 final DartType typeExpression;
2252 final int kind; 2251 final int kind;
2253 final Selector receiverTypeCheckSelector; 2252 final Selector receiverTypeCheckSelector;
2253 final bool contextIsTypeArguments;
2254 2254
2255 static const int NO_CHECK = 0; 2255 static const int NO_CHECK = 0;
2256 static const int CHECKED_MODE_CHECK = 1; 2256 static const int CHECKED_MODE_CHECK = 1;
2257 static const int ARGUMENT_TYPE_CHECK = 2; 2257 static const int ARGUMENT_TYPE_CHECK = 2;
2258 static const int CAST_TYPE_CHECK = 3; 2258 static const int CAST_TYPE_CHECK = 3;
2259 static const int BOOLEAN_CONVERSION_CHECK = 4; 2259 static const int BOOLEAN_CONVERSION_CHECK = 4;
2260 static const int RECEIVER_TYPE_CHECK = 5; 2260 static const int RECEIVER_TYPE_CHECK = 5;
2261 2261
2262 HTypeConversion(this.typeExpression, this.kind, 2262 HTypeConversion(this.typeExpression, this.kind,
2263 HType type, HInstruction input, 2263 HType type, HInstruction input,
2264 [this.receiverTypeCheckSelector]) 2264 [this.receiverTypeCheckSelector])
2265 : super(<HInstruction>[input]) { 2265 : contextIsTypeArguments = false,
2266 super(<HInstruction>[input]) {
2266 assert(!isReceiverTypeCheck || receiverTypeCheckSelector != null); 2267 assert(!isReceiverTypeCheck || receiverTypeCheckSelector != null);
2268 assert(typeExpression == null ||
2269 typeExpression.kind != TypeKind.TYPEDEF);
2267 sourceElement = input.sourceElement; 2270 sourceElement = input.sourceElement;
2268 instructionType = type; 2271 instructionType = type;
2269 } 2272 }
2270 2273
2271 HTypeConversion.withTypeRepresentation(this.typeExpression, this.kind, 2274 HTypeConversion.withTypeRepresentation(this.typeExpression, this.kind,
2272 HType type, HInstruction input, 2275 HType type, HInstruction input,
2273 HInstruction typeRepresentation) 2276 HInstruction typeRepresentation)
2274 : super(<HInstruction>[input, typeRepresentation]), 2277 : contextIsTypeArguments = false,
2278 super(<HInstruction>[input, typeRepresentation]),
2275 receiverTypeCheckSelector = null { 2279 receiverTypeCheckSelector = null {
2280 assert(typeExpression.kind != TypeKind.TYPEDEF);
2276 sourceElement = input.sourceElement; 2281 sourceElement = input.sourceElement;
2277 instructionType = type; 2282 instructionType = type;
2278 } 2283 }
2279 2284
2280 bool get hasTypeRepresentation => inputs.length > 1; 2285 HTypeConversion.withContext(this.typeExpression, this.kind,
2286 HType type, HInstruction input,
2287 HInstruction context,
2288 {bool this.contextIsTypeArguments})
2289 : super(<HInstruction>[input, context]),
2290 receiverTypeCheckSelector = null {
2291 assert(typeExpression.kind != TypeKind.TYPEDEF);
2292 sourceElement = input.sourceElement;
2293 instructionType = type;
2294 }
2295
2296 bool get hasTypeRepresentation {
2297 return typeExpression.kind == TypeKind.INTERFACE && inputs.length > 1;
2298 }
2281 HInstruction get typeRepresentation => inputs[1]; 2299 HInstruction get typeRepresentation => inputs[1];
2282 2300
2301 bool get hasContext {
2302 return typeExpression.kind == TypeKind.FUNCTION && inputs.length > 1;
2303 }
2304 HInstruction get context => inputs[1];
2305
2283 HInstruction convertType(Compiler compiler, DartType type, int kind) { 2306 HInstruction convertType(Compiler compiler, DartType type, int kind) {
2284 if (typeExpression == type) return this; 2307 if (typeExpression == type) return this;
2285 return super.convertType(compiler, type, kind); 2308 return super.convertType(compiler, type, kind);
2286 } 2309 }
2287 2310
2288 bool get isChecked => kind != NO_CHECK; 2311 bool get isChecked => kind != NO_CHECK;
2289 bool get isCheckedModeCheck { 2312 bool get isCheckedModeCheck {
2290 return kind == CHECKED_MODE_CHECK 2313 return kind == CHECKED_MODE_CHECK
2291 || kind == BOOLEAN_CONVERSION_CHECK; 2314 || kind == BOOLEAN_CONVERSION_CHECK;
2292 } 2315 }
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
2689 HBasicBlock get start => expression.start; 2712 HBasicBlock get start => expression.start;
2690 HBasicBlock get end { 2713 HBasicBlock get end {
2691 // We don't create a switch block if there are no cases. 2714 // We don't create a switch block if there are no cases.
2692 assert(!statements.isEmpty); 2715 assert(!statements.isEmpty);
2693 return statements.last.end; 2716 return statements.last.end;
2694 } 2717 }
2695 2718
2696 bool accept(HStatementInformationVisitor visitor) => 2719 bool accept(HStatementInformationVisitor visitor) =>
2697 visitor.visitSwitchInfo(this); 2720 visitor.visitSwitchInfo(this);
2698 } 2721 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698