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

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: Handle function types in checked mode. 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 2221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2232 return typeExpression == other.typeExpression 2232 return typeExpression == other.typeExpression
2233 && nullOk == other.nullOk 2233 && nullOk == other.nullOk
2234 && kind == other.kind; 2234 && kind == other.kind;
2235 } 2235 }
2236 } 2236 }
2237 2237
2238 class HTypeConversion extends HCheck { 2238 class HTypeConversion extends HCheck {
2239 final DartType typeExpression; 2239 final DartType typeExpression;
2240 final int kind; 2240 final int kind;
2241 final Selector receiverTypeCheckSelector; 2241 final Selector receiverTypeCheckSelector;
2242 final bool contextIsTypeArguments;
2242 2243
2243 static const int NO_CHECK = 0; 2244 static const int NO_CHECK = 0;
2244 static const int CHECKED_MODE_CHECK = 1; 2245 static const int CHECKED_MODE_CHECK = 1;
2245 static const int ARGUMENT_TYPE_CHECK = 2; 2246 static const int ARGUMENT_TYPE_CHECK = 2;
2246 static const int CAST_TYPE_CHECK = 3; 2247 static const int CAST_TYPE_CHECK = 3;
2247 static const int BOOLEAN_CONVERSION_CHECK = 4; 2248 static const int BOOLEAN_CONVERSION_CHECK = 4;
2248 static const int RECEIVER_TYPE_CHECK = 5; 2249 static const int RECEIVER_TYPE_CHECK = 5;
2249 2250
2250 HTypeConversion(this.typeExpression, this.kind, 2251 HTypeConversion(this.typeExpression, this.kind,
2251 HType type, HInstruction input, 2252 HType type, HInstruction input,
2252 [this.receiverTypeCheckSelector]) 2253 [this.receiverTypeCheckSelector])
2253 : super(<HInstruction>[input]) { 2254 : contextIsTypeArguments = false,
2255 super(<HInstruction>[input]) {
2254 assert(!isReceiverTypeCheck || receiverTypeCheckSelector != null); 2256 assert(!isReceiverTypeCheck || receiverTypeCheckSelector != null);
2255 sourceElement = input.sourceElement; 2257 sourceElement = input.sourceElement;
2256 instructionType = type; 2258 instructionType = type;
2257 } 2259 }
2258 2260
2259 HTypeConversion.withTypeRepresentation(this.typeExpression, this.kind, 2261 HTypeConversion.withTypeRepresentation(this.typeExpression, this.kind,
2260 HType type, HInstruction input, 2262 HType type, HInstruction input,
2261 HInstruction typeRepresentation) 2263 HInstruction typeRepresentation)
2262 : super(<HInstruction>[input, typeRepresentation]), 2264 : contextIsTypeArguments = false,
2265 super(<HInstruction>[input, typeRepresentation]),
2263 receiverTypeCheckSelector = null { 2266 receiverTypeCheckSelector = null {
2264 sourceElement = input.sourceElement; 2267 sourceElement = input.sourceElement;
2265 instructionType = type; 2268 instructionType = type;
2269 }
2270
2271 HTypeConversion.withContext(this.typeExpression, this.kind,
2272 HType type, HInstruction input,
2273 HInstruction context,
2274 {bool this.contextIsTypeArguments})
2275 : super(<HInstruction>[input, context]),
2276 receiverTypeCheckSelector = null {
2277 sourceElement = input.sourceElement;
2278 instructionType = type;
2266 } 2279 }
2267 2280
2268 bool get hasTypeRepresentation => inputs.length > 1; 2281 bool get hasTypeRepresentation => inputs.length > 1;
2269 HInstruction get typeRepresentation => inputs[1]; 2282 HInstruction get typeRepresentation => inputs[1];
2270 2283
2284 bool get hasContext => inputs.length > 1;
2285 HInstruction get context => inputs[1];
2286
2271 HInstruction convertType(Compiler compiler, DartType type, int kind) { 2287 HInstruction convertType(Compiler compiler, DartType type, int kind) {
2272 if (typeExpression == type) return this; 2288 if (typeExpression == type) return this;
2273 return super.convertType(compiler, type, kind); 2289 return super.convertType(compiler, type, kind);
2274 } 2290 }
2275 2291
2276 bool get isChecked => kind != NO_CHECK; 2292 bool get isChecked => kind != NO_CHECK;
2277 bool get isCheckedModeCheck { 2293 bool get isCheckedModeCheck {
2278 return kind == CHECKED_MODE_CHECK 2294 return kind == CHECKED_MODE_CHECK
2279 || kind == BOOLEAN_CONVERSION_CHECK; 2295 || kind == BOOLEAN_CONVERSION_CHECK;
2280 } 2296 }
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
2675 HBasicBlock get start => expression.start; 2691 HBasicBlock get start => expression.start;
2676 HBasicBlock get end { 2692 HBasicBlock get end {
2677 // We don't create a switch block if there are no cases. 2693 // We don't create a switch block if there are no cases.
2678 assert(!statements.isEmpty); 2694 assert(!statements.isEmpty);
2679 return statements.last.end; 2695 return statements.last.end;
2680 } 2696 }
2681 2697
2682 bool accept(HStatementInformationVisitor visitor) => 2698 bool accept(HStatementInformationVisitor visitor) =>
2683 visitor.visitSwitchInfo(this); 2699 visitor.visitSwitchInfo(this);
2684 } 2700 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698