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

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

Issue 11412245: MalformedType used for all invalid type annotations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Bug fixes Created 8 years 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 2062 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 backend.registerNonCallStaticUse(node); 2073 backend.registerNonCallStaticUse(node);
2074 if (node.element.isFunction()) { 2074 if (node.element.isFunction()) {
2075 world.registerInstantiatedClass(compiler.functionClass); 2075 world.registerInstantiatedClass(compiler.functionClass);
2076 } 2076 }
2077 } else if (instr.target != node) { 2077 } else if (instr.target != node) {
2078 backend.registerNonCallStaticUse(node); 2078 backend.registerNonCallStaticUse(node);
2079 } 2079 }
2080 }); 2080 });
2081 Element element = node.element; 2081 Element element = node.element;
2082 world.registerStaticUse(element); 2082 world.registerStaticUse(element);
2083 ClassElement cls = element.getEnclosingClass(); 2083 ClassElement cls = element.getEnclosingClass();
2084 if (element.isGenerativeConstructor() 2084 if (element.isGenerativeConstructor()
2085 || (element.isFactoryConstructor() && cls == compiler.listClass)) { 2085 || (element.isFactoryConstructor() && cls == compiler.listClass)) {
2086 world.registerInstantiatedClass(cls); 2086 world.registerInstantiatedClass(cls);
2087 } 2087 }
2088 push(new js.VariableUse(backend.namer.isolateAccess(node.element))); 2088 push(new js.VariableUse(backend.namer.isolateAccess(node.element)));
2089 } 2089 }
2090 2090
2091 void visitLazyStatic(HLazyStatic node) { 2091 void visitLazyStatic(HLazyStatic node) {
2092 Element element = node.element; 2092 Element element = node.element;
2093 world.registerStaticUse(element); 2093 world.registerStaticUse(element);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
2267 js.Expression functionTest = pop(); 2267 js.Expression functionTest = pop();
2268 checkObject(input, '==='); 2268 checkObject(input, '===');
2269 js.Expression objectTest = pop(); 2269 js.Expression objectTest = pop();
2270 checkType(input, type); 2270 checkType(input, type);
2271 push(new js.Binary('||', 2271 push(new js.Binary('||',
2272 functionTest, 2272 functionTest,
2273 new js.Binary('&&', objectTest, pop()))); 2273 new js.Binary('&&', objectTest, pop())));
2274 } 2274 }
2275 2275
2276 void checkType(HInstruction input, DartType type, {bool negative: false}) { 2276 void checkType(HInstruction input, DartType type, {bool negative: false}) {
2277 assert(invariant(input, !type.isMalformed,
2278 message: 'Attempt to check malformed type $type'));
2277 world.registerIsCheck(type); 2279 world.registerIsCheck(type);
2278 Element element = type.element; 2280 Element element = type.element;
2279 use(input); 2281 use(input);
2280 js.PropertyAccess field = 2282 js.PropertyAccess field =
2281 new js.PropertyAccess.field(pop(), backend.namer.operatorIs(element)); 2283 new js.PropertyAccess.field(pop(), backend.namer.operatorIs(element));
2282 if (backend.emitter.nativeEmitter.requiresNativeIsCheck(element)) { 2284 if (backend.emitter.nativeEmitter.requiresNativeIsCheck(element)) {
2283 push(new js.Call(field, <js.Expression>[])); 2285 push(new js.Call(field, <js.Expression>[]));
2284 if (negative) push(new js.Prefix('!', pop())); 2286 if (negative) push(new js.Prefix('!', pop()));
2285 } else { 2287 } else {
2286 // We always negate at least once so that the result is boolified. 2288 // We always negate at least once so that the result is boolified.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 const SourceString("stringSuperTypeCast"), 2453 const SourceString("stringSuperTypeCast"),
2452 "listTypeCheck": 2454 "listTypeCheck":
2453 const SourceString("listTypeCast"), 2455 const SourceString("listTypeCast"),
2454 "listSuperNativeTypeCheck": 2456 "listSuperNativeTypeCheck":
2455 const SourceString("listSuperNativeTypeCast"), 2457 const SourceString("listSuperNativeTypeCast"),
2456 "listSuperTypeCheck": 2458 "listSuperTypeCheck":
2457 const SourceString("listSuperTypeCast"), 2459 const SourceString("listSuperTypeCast"),
2458 "callTypeCheck": 2460 "callTypeCheck":
2459 const SourceString("callTypeCast"), 2461 const SourceString("callTypeCast"),
2460 "propertyTypeCheck": 2462 "propertyTypeCheck":
2461 const SourceString("propertyTypeCast") 2463 const SourceString("propertyTypeCast"),
2464 "malformedTypeCheck":
2465 const SourceString("malformedTypeCheck")
ahe 2012/11/30 15:44:07 How about adding malformedTypeCast which gives a s
Johnni Winther 2012/12/04 10:07:17 Added a TODO.
2462 }; 2466 };
2463 2467
2464 if (node.isChecked) { 2468 if (node.isChecked) {
2465 DartType type = node.type.computeType(compiler); 2469 DartType type = node.type.computeType(compiler);
2466 Element element = type.element; 2470 Element element = type.element;
2467 world.registerIsCheck(type); 2471 world.registerIsCheck(type);
2468 2472
2469 if (node.isArgumentTypeCheck) { 2473 if (node.isArgumentTypeCheck) {
2470 if (element == compiler.intClass) { 2474 if (element == compiler.intClass) {
2471 checkInt(node.checkedInput, '!=='); 2475 checkInt(node.checkedInput, '!==');
(...skipping 20 matching lines...) Expand all
2492 helper = backend.getCheckedModeHelper(type); 2496 helper = backend.getCheckedModeHelper(type);
2493 if (node.isCastTypeCheck) { 2497 if (node.isCastTypeCheck) {
2494 helper = castNames[helper.stringValue]; 2498 helper = castNames[helper.stringValue];
2495 } 2499 }
2496 } 2500 }
2497 FunctionElement helperElement = compiler.findHelper(helper); 2501 FunctionElement helperElement = compiler.findHelper(helper);
2498 world.registerStaticUse(helperElement); 2502 world.registerStaticUse(helperElement);
2499 List<js.Expression> arguments = <js.Expression>[]; 2503 List<js.Expression> arguments = <js.Expression>[];
2500 use(node.checkedInput); 2504 use(node.checkedInput);
2501 arguments.add(pop()); 2505 arguments.add(pop());
2502 if (helperElement.computeSignature(compiler).parameterCount != 1) { 2506 int parameterCount =
2507 helperElement.computeSignature(compiler).parameterCount;
2508 if (parameterCount == 2) {
ahe 2012/11/30 15:44:07 Could you document what is going on here?
Johnni Winther 2012/12/04 10:07:17 Done.
2509 assert(!type.isMalformed);
2503 String additionalArgument = backend.namer.operatorIs(element); 2510 String additionalArgument = backend.namer.operatorIs(element);
2504 arguments.add(new js.LiteralString("'$additionalArgument'")); 2511 arguments.add(new js.LiteralString("'$additionalArgument'"));
2512 } else if (parameterCount == 3) {
2513 assert(type.isMalformed);
2514 String reasons = fetchReasonsFromMalformedType(type);
2515 arguments.add(new js.LiteralString("'$type'"));
2516 arguments.add(new js.LiteralString("'$reasons)}'"));
ahe 2012/11/30 15:44:07 How about using writeJsonEscapedCharsOn from util.
Johnni Winther 2012/12/04 10:07:17 Added a TODO.
2517 } else {
2518 assert(!type.isMalformed);
2505 } 2519 }
2506 String helperName = backend.namer.isolateAccess(helperElement); 2520 String helperName = backend.namer.isolateAccess(helperElement);
2507 push(new js.Call(new js.VariableUse(helperName), arguments)); 2521 push(new js.Call(new js.VariableUse(helperName), arguments));
2508 } else { 2522 } else {
2509 use(node.checkedInput); 2523 use(node.checkedInput);
2510 } 2524 }
2511 } 2525 }
2512 } 2526 }
2513 2527
2514 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { 2528 class SsaOptimizedCodeGenerator extends SsaCodeGenerator {
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
3034 if (leftType.canBeNull() && rightType.canBeNull()) { 3048 if (leftType.canBeNull() && rightType.canBeNull()) {
3035 if (left.isConstantNull() || right.isConstantNull() || 3049 if (left.isConstantNull() || right.isConstantNull() ||
3036 (leftType.isPrimitive() && leftType == rightType)) { 3050 (leftType.isPrimitive() && leftType == rightType)) {
3037 return '=='; 3051 return '==';
3038 } 3052 }
3039 return null; 3053 return null;
3040 } else { 3054 } else {
3041 return '==='; 3055 return '===';
3042 } 3056 }
3043 } 3057 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698