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

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

Issue 12334070: Support runtime check of function types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: New check encoding Created 7 years, 9 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 class SsaCodeGeneratorTask extends CompilerTask { 7 class SsaCodeGeneratorTask extends CompilerTask {
8 8
9 final JavaScriptBackend backend; 9 final JavaScriptBackend backend;
10 10
(...skipping 2226 matching lines...) Expand 10 before | Expand all | Expand 10 after
2237 push(new js.Binary('||', 2237 push(new js.Binary('||',
2238 functionTest, 2238 functionTest,
2239 new js.Binary('&&', objectTest, pop()))); 2239 new js.Binary('&&', objectTest, pop())));
2240 } 2240 }
2241 2241
2242 void checkType(HInstruction input, DartType type, {bool negative: false}) { 2242 void checkType(HInstruction input, DartType type, {bool negative: false}) {
2243 assert(invariant(input, !type.isMalformed, 2243 assert(invariant(input, !type.isMalformed,
2244 message: 'Attempt to check malformed type $type')); 2244 message: 'Attempt to check malformed type $type'));
2245 world.registerIsCheck(type, work.resolutionTree); 2245 world.registerIsCheck(type, work.resolutionTree);
2246 Element element = type.element; 2246 Element element = type.element;
2247 String operatorIs = backend.namer.operatorIsType(type);
2247 use(input); 2248 use(input);
2248 js.PropertyAccess field = 2249 js.PropertyAccess field =
2249 new js.PropertyAccess.field(pop(), backend.namer.operatorIs(element)); 2250 new js.PropertyAccess.field(pop(), operatorIs);
2250 if (backend.emitter.nativeEmitter.requiresNativeIsCheck(element)) { 2251 if (backend.emitter.nativeEmitter.requiresNativeIsCheck(element)) {
2251 push(new js.Call(field, <js.Expression>[])); 2252 push(new js.Call(field, <js.Expression>[]));
2252 if (negative) push(new js.Prefix('!', pop())); 2253 if (negative) push(new js.Prefix('!', pop()));
2253 } else { 2254 } else {
2254 // We always negate at least once so that the result is boolified. 2255 // We always negate at least once so that the result is boolified.
2255 push(new js.Prefix('!', field)); 2256 push(new js.Prefix('!', field));
2256 // If the result is not negated, put another '!' in front. 2257 // If the result is not negated, put another '!' in front.
2257 if (!negative) push(new js.Prefix('!', pop())); 2258 if (!negative) push(new js.Prefix('!', pop()));
2258 } 2259 }
2259 } 2260 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
2419 use(node.checkedInput); 2420 use(node.checkedInput);
2420 arguments.add(pop()); 2421 arguments.add(pop());
2421 int parameterCount = 2422 int parameterCount =
2422 helperElement.computeSignature(compiler).parameterCount; 2423 helperElement.computeSignature(compiler).parameterCount;
2423 // TODO(johnniwinther): Refactor this to avoid using the parameter count 2424 // TODO(johnniwinther): Refactor this to avoid using the parameter count
2424 // to determine how the helper should be called. 2425 // to determine how the helper should be called.
2425 if (parameterCount == 2) { 2426 if (parameterCount == 2) {
2426 // 2 arguments implies that the method is either [propertyTypeCheck] 2427 // 2 arguments implies that the method is either [propertyTypeCheck]
2427 // or [propertyTypeCast]. 2428 // or [propertyTypeCast].
2428 assert(!type.isMalformed); 2429 assert(!type.isMalformed);
2429 String additionalArgument = backend.namer.operatorIs(type.element); 2430 String additionalArgument = backend.namer.operatorIsType(type);
2430 arguments.add(js.string(additionalArgument)); 2431 arguments.add(js.string(additionalArgument));
2431 } else if (parameterCount == 3) { 2432 } else if (parameterCount == 3) {
2432 // 3 arguments implies that the method is [malformedTypeCheck]. 2433 // 3 arguments implies that the method is [malformedTypeCheck].
2433 assert(type.isMalformed); 2434 assert(type.isMalformed);
2434 String reasons = Types.fetchReasonsFromMalformedType(type); 2435 String reasons = Types.fetchReasonsFromMalformedType(type);
2435 arguments.add(js.string('$type')); 2436 arguments.add(js.string('$type'));
2436 // TODO(johnniwinther): Handle escaping correctly. 2437 // TODO(johnniwinther): Handle escaping correctly.
2437 arguments.add(js.string(reasons)); 2438 arguments.add(js.string(reasons));
2438 } else { 2439 } else {
2439 assert(!type.isMalformed); 2440 assert(!type.isMalformed);
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
2963 if (leftType.canBeNull() && rightType.canBeNull()) { 2964 if (leftType.canBeNull() && rightType.canBeNull()) {
2964 if (left.isConstantNull() || right.isConstantNull() || 2965 if (left.isConstantNull() || right.isConstantNull() ||
2965 (leftType.isPrimitive() && leftType == rightType)) { 2966 (leftType.isPrimitive() && leftType == rightType)) {
2966 return '=='; 2967 return '==';
2967 } 2968 }
2968 return null; 2969 return null;
2969 } else { 2970 } else {
2970 return '==='; 2971 return '===';
2971 } 2972 }
2972 } 2973 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698