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 2188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2199 List<js.Expression> arguments = <js.Expression>[object, record]; | 2199 List<js.Expression> arguments = <js.Expression>[object, record]; |
2200 FunctionElement helper = | 2200 FunctionElement helper = |
2201 compiler.findHelper(const SourceString('isJsIndexable')); | 2201 compiler.findHelper(const SourceString('isJsIndexable')); |
2202 world.registerStaticUse(helper); | 2202 world.registerStaticUse(helper); |
2203 String helperName = backend.namer.isolateAccess(helper); | 2203 String helperName = backend.namer.isolateAccess(helper); |
2204 push(new js.Call(new js.VariableUse(helperName), arguments)); | 2204 push(new js.Call(new js.VariableUse(helperName), arguments)); |
2205 if (negative) push(new js.Prefix('!', pop())); | 2205 if (negative) push(new js.Prefix('!', pop())); |
2206 } | 2206 } |
2207 | 2207 |
2208 void checkType(HInstruction input, DartType type, {bool negative: false}) { | 2208 void checkType(HInstruction input, DartType type, {bool negative: false}) { |
2209 assert(invariant(input, !type.isMalformed, | |
2210 message: 'Attempt to check malformed type $type')); | |
2211 Element element = type.element; | 2209 Element element = type.element; |
2212 if (element == backend.jsArrayClass) { | 2210 if (element == backend.jsArrayClass) { |
2213 checkArray(input, negative ? '!==': '==='); | 2211 checkArray(input, negative ? '!==': '==='); |
2214 return; | 2212 return; |
2215 } else if (element == backend.jsMutableArrayClass) { | 2213 } else if (element == backend.jsMutableArrayClass) { |
2216 if (negative) { | 2214 if (negative) { |
2217 checkImmutableArray(input); | 2215 checkImmutableArray(input); |
2218 } else { | 2216 } else { |
2219 checkMutableArray(input); | 2217 checkMutableArray(input); |
2220 } | 2218 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2331 | 2329 |
2332 if (node.isVariableCheck || node.isCompoundCheck) { | 2330 if (node.isVariableCheck || node.isCompoundCheck) { |
2333 use(node.checkCall); | 2331 use(node.checkCall); |
2334 if (negative) push(new js.Prefix('!', pop())); | 2332 if (negative) push(new js.Prefix('!', pop())); |
2335 } else { | 2333 } else { |
2336 assert(node.isRawCheck); | 2334 assert(node.isRawCheck); |
2337 LibraryElement coreLibrary = compiler.coreLibrary; | 2335 LibraryElement coreLibrary = compiler.coreLibrary; |
2338 ClassElement objectClass = compiler.objectClass; | 2336 ClassElement objectClass = compiler.objectClass; |
2339 Element element = type.element; | 2337 Element element = type.element; |
2340 | 2338 |
2341 if (identical(element, objectClass) || | 2339 if (identical(element, objectClass) || type.treatAsDynamic) { |
2342 identical(element, compiler.dynamicClass)) { | |
2343 // The constant folder also does this optimization, but we make | 2340 // The constant folder also does this optimization, but we make |
2344 // it safe by assuming it may have not run. | 2341 // it safe by assuming it may have not run. |
2345 push(newLiteralBool(!negative), node); | 2342 push(newLiteralBool(!negative), node); |
2346 } else if (element == compiler.stringClass) { | 2343 } else if (element == compiler.stringClass) { |
2347 checkString(input, relation); | 2344 checkString(input, relation); |
2348 attachLocationToLast(node); | 2345 attachLocationToLast(node); |
2349 } else if (element == compiler.doubleClass) { | 2346 } else if (element == compiler.doubleClass) { |
2350 checkDouble(input, relation); | 2347 checkDouble(input, relation); |
2351 attachLocationToLast(node); | 2348 attachLocationToLast(node); |
2352 } else if (element == compiler.numClass) { | 2349 } else if (element == compiler.numClass) { |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2976 if (leftType.canBeNull() && rightType.canBeNull()) { | 2973 if (leftType.canBeNull() && rightType.canBeNull()) { |
2977 if (left.isConstantNull() || right.isConstantNull() || | 2974 if (left.isConstantNull() || right.isConstantNull() || |
2978 (leftType.isPrimitive(compiler) && leftType == rightType)) { | 2975 (leftType.isPrimitive(compiler) && leftType == rightType)) { |
2979 return '=='; | 2976 return '=='; |
2980 } | 2977 } |
2981 return null; | 2978 return null; |
2982 } else { | 2979 } else { |
2983 return '==='; | 2980 return '==='; |
2984 } | 2981 } |
2985 } | 2982 } |
OLD | NEW |