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 class SsaCodeGeneratorTask extends CompilerTask { | 7 class SsaCodeGeneratorTask extends CompilerTask { |
8 | 8 |
9 final JavaScriptBackend backend; | 9 final JavaScriptBackend backend; |
10 | 10 |
(...skipping 2380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2391 attachLocationToLast(node); | 2391 attachLocationToLast(node); |
2392 } else if (types[input].canBePrimitive() || types[input].canBeNull()) { | 2392 } else if (types[input].canBePrimitive() || types[input].canBeNull()) { |
2393 checkObject(input, '==='); | 2393 checkObject(input, '==='); |
2394 js.Expression objectTest = pop(); | 2394 js.Expression objectTest = pop(); |
2395 checkType(input, type); | 2395 checkType(input, type); |
2396 push(new js.Binary('&&', objectTest, pop()), node); | 2396 push(new js.Binary('&&', objectTest, pop()), node); |
2397 } else { | 2397 } else { |
2398 checkType(input, type); | 2398 checkType(input, type); |
2399 attachLocationToLast(node); | 2399 attachLocationToLast(node); |
2400 } | 2400 } |
2401 if (node.hasTypeInfo()) { | 2401 if (node.hasArgumentChecks()) { |
2402 InterfaceType interfaceType = type; | 2402 InterfaceType interfaceType = type; |
2403 ClassElement cls = type.element; | 2403 ClassElement cls = type.element; |
2404 Link<DartType> arguments = interfaceType.typeArguments; | 2404 Link<DartType> arguments = interfaceType.typeArguments; |
2405 js.Expression result = pop(); | 2405 js.Expression result = pop(); |
2406 for (TypeVariableType typeVariable in cls.typeVariables) { | 2406 for (int i = 0; i < node.checkCount; i++) { |
2407 use(node.typeInfoCall); | 2407 use(node.getCheck(i)); |
2408 int index = RuntimeTypeInformation.getTypeVariableIndex(typeVariable); | 2408 result = new js.Binary('&&', result, pop()); |
2409 js.PropertyAccess field = new js.PropertyAccess.indexed(pop(), index); | |
2410 // Also test for 'undefined' in case the object does not have | |
2411 // any type variable. | |
2412 js.Prefix undefinedTest = new js.Prefix('!', field); | |
2413 if (arguments.head == compiler.types.dynamicType) { | |
2414 result = new js.Binary('&&', result, undefinedTest); | |
2415 } else { | |
2416 RuntimeTypeInformation rti = backend.rti; | |
2417 String typeName = rti.getStringRepresentation(arguments.head); | |
2418 js.Expression genericName = new js.LiteralString("'$typeName'"); | |
2419 js.Binary eqTest = new js.Binary('===', field, genericName); | |
2420 result = new js.Binary( | |
2421 '&&', result, new js.Binary('||', undefinedTest, eqTest)); | |
2422 } | |
2423 arguments = arguments.tail; | |
2424 } | 2409 } |
2425 push(result, node); | 2410 push(result, node); |
2426 } | 2411 } |
2427 if (node.nullOk) { | 2412 if (node.nullOk) { |
2428 checkNull(input); | 2413 checkNull(input); |
2429 push(new js.Binary('||', pop(), pop()), node); | 2414 push(new js.Binary('||', pop(), pop()), node); |
2430 } | 2415 } |
2431 } | 2416 } |
2432 | 2417 |
2433 // TODO(johnniwinther): Refactor this method. | 2418 // TODO(johnniwinther): Refactor this method. |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3056 if (leftType.canBeNull() && rightType.canBeNull()) { | 3041 if (leftType.canBeNull() && rightType.canBeNull()) { |
3057 if (left.isConstantNull() || right.isConstantNull() || | 3042 if (left.isConstantNull() || right.isConstantNull() || |
3058 (leftType.isPrimitive() && leftType == rightType)) { | 3043 (leftType.isPrimitive() && leftType == rightType)) { |
3059 return '=='; | 3044 return '=='; |
3060 } | 3045 } |
3061 return null; | 3046 return null; |
3062 } else { | 3047 } else { |
3063 return '==='; | 3048 return '==='; |
3064 } | 3049 } |
3065 } | 3050 } |
OLD | NEW |