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 2199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2210 List<js.Expression> arguments = <js.Expression>[object, record]; | 2210 List<js.Expression> arguments = <js.Expression>[object, record]; |
2211 FunctionElement helper = | 2211 FunctionElement helper = |
2212 compiler.findHelper(const SourceString('isJsIndexable')); | 2212 compiler.findHelper(const SourceString('isJsIndexable')); |
2213 world.registerStaticUse(helper); | 2213 world.registerStaticUse(helper); |
2214 String helperName = backend.namer.isolateAccess(helper); | 2214 String helperName = backend.namer.isolateAccess(helper); |
2215 push(new js.Call(new js.VariableUse(helperName), arguments)); | 2215 push(new js.Call(new js.VariableUse(helperName), arguments)); |
2216 if (negative) push(new js.Prefix('!', pop())); | 2216 if (negative) push(new js.Prefix('!', pop())); |
2217 } | 2217 } |
2218 | 2218 |
2219 void checkType(HInstruction input, DartType type, {bool negative: false}) { | 2219 void checkType(HInstruction input, DartType type, {bool negative: false}) { |
2220 assert(invariant(input, !type.isMalformed, | |
2221 message: 'Attempt to check malformed type $type')); | |
2222 Element element = type.element; | 2220 Element element = type.element; |
2223 if (element == backend.jsArrayClass) { | 2221 if (element == backend.jsArrayClass) { |
2224 checkArray(input, negative ? '!==': '==='); | 2222 checkArray(input, negative ? '!==': '==='); |
2225 return; | 2223 return; |
2226 } else if (element == backend.jsMutableArrayClass) { | 2224 } else if (element == backend.jsMutableArrayClass) { |
2227 if (negative) { | 2225 if (negative) { |
2228 checkImmutableArray(input); | 2226 checkImmutableArray(input); |
2229 } else { | 2227 } else { |
2230 checkMutableArray(input); | 2228 checkMutableArray(input); |
2231 } | 2229 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2342 | 2340 |
2343 if (node.isVariableCheck || node.isCompoundCheck) { | 2341 if (node.isVariableCheck || node.isCompoundCheck) { |
2344 use(node.checkCall); | 2342 use(node.checkCall); |
2345 if (negative) push(new js.Prefix('!', pop())); | 2343 if (negative) push(new js.Prefix('!', pop())); |
2346 } else { | 2344 } else { |
2347 assert(node.isRawCheck); | 2345 assert(node.isRawCheck); |
2348 LibraryElement coreLibrary = compiler.coreLibrary; | 2346 LibraryElement coreLibrary = compiler.coreLibrary; |
2349 ClassElement objectClass = compiler.objectClass; | 2347 ClassElement objectClass = compiler.objectClass; |
2350 Element element = type.element; | 2348 Element element = type.element; |
2351 | 2349 |
2352 if (identical(element, objectClass) || | 2350 if (identical(element, objectClass) || type.treatAsDynamic) { |
2353 identical(element, compiler.dynamicClass)) { | |
2354 // The constant folder also does this optimization, but we make | 2351 // The constant folder also does this optimization, but we make |
2355 // it safe by assuming it may have not run. | 2352 // it safe by assuming it may have not run. |
2356 push(newLiteralBool(!negative), node); | 2353 push(newLiteralBool(!negative), node); |
2357 } else if (element == compiler.stringClass) { | 2354 } else if (element == compiler.stringClass) { |
2358 checkString(input, relation); | 2355 checkString(input, relation); |
2359 attachLocationToLast(node); | 2356 attachLocationToLast(node); |
2360 } else if (element == compiler.doubleClass) { | 2357 } else if (element == compiler.doubleClass) { |
2361 checkDouble(input, relation); | 2358 checkDouble(input, relation); |
2362 attachLocationToLast(node); | 2359 attachLocationToLast(node); |
2363 } else if (element == compiler.numClass) { | 2360 } else if (element == compiler.numClass) { |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2987 if (leftType.canBeNull() && rightType.canBeNull()) { | 2984 if (leftType.canBeNull() && rightType.canBeNull()) { |
2988 if (left.isConstantNull() || right.isConstantNull() || | 2985 if (left.isConstantNull() || right.isConstantNull() || |
2989 (leftType.isPrimitive(compiler) && leftType == rightType)) { | 2986 (leftType.isPrimitive(compiler) && leftType == rightType)) { |
2990 return '=='; | 2987 return '=='; |
2991 } | 2988 } |
2992 return null; | 2989 return null; |
2993 } else { | 2990 } else { |
2994 return '==='; | 2991 return '==='; |
2995 } | 2992 } |
2996 } | 2993 } |
OLD | NEW |