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 2098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2109 if (!node.isConstantString()) return false; | 2109 if (!node.isConstantString()) return false; |
2110 HConstant constant = node; | 2110 HConstant constant = node; |
2111 StringConstant string = constant.constant; | 2111 StringConstant string = constant.constant; |
2112 return string.value.length == 0; | 2112 return string.value.length == 0; |
2113 } | 2113 } |
2114 | 2114 |
2115 void useStringified(HInstruction node) { | 2115 void useStringified(HInstruction node) { |
2116 if (node.isString(types)) { | 2116 if (node.isString(types)) { |
2117 use(node); | 2117 use(node); |
2118 } else { | 2118 } else { |
2119 Element convertToString = compiler.findHelper(const SourceString("S")); | 2119 Element convertToString = backend.getStringInterpolationHelper(); |
2120 world.registerStaticUse(convertToString); | 2120 world.registerStaticUse(convertToString); |
2121 js.VariableUse variableUse = | 2121 js.VariableUse variableUse = |
2122 new js.VariableUse(backend.namer.isolateAccess(convertToString)); | 2122 new js.VariableUse(backend.namer.isolateAccess(convertToString)); |
2123 use(node); | 2123 use(node); |
2124 push(new js.Call(variableUse, <js.Expression>[pop()]), node); | 2124 push(new js.Call(variableUse, <js.Expression>[pop()]), node); |
2125 } | 2125 } |
2126 } | 2126 } |
2127 | 2127 |
2128 void visitLiteralList(HLiteralList node) { | 2128 void visitLiteralList(HLiteralList node) { |
2129 world.registerInstantiatedClass(compiler.listClass); | 2129 world.registerInstantiatedClass(compiler.listClass); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2386 attachLocationToLast(node); | 2386 attachLocationToLast(node); |
2387 } | 2387 } |
2388 if (node.nullOk) { | 2388 if (node.nullOk) { |
2389 checkNull(input); | 2389 checkNull(input); |
2390 push(new js.Binary('||', pop(), pop()), node); | 2390 push(new js.Binary('||', pop(), pop()), node); |
2391 } | 2391 } |
2392 } | 2392 } |
2393 | 2393 |
2394 // TODO(johnniwinther): Refactor this method. | 2394 // TODO(johnniwinther): Refactor this method. |
2395 void visitTypeConversion(HTypeConversion node) { | 2395 void visitTypeConversion(HTypeConversion node) { |
2396 Map<String, SourceString> castNames = const <String, SourceString> { | |
2397 "stringTypeCheck": | |
2398 const SourceString("stringTypeCast"), | |
2399 "doubleTypeCheck": | |
2400 const SourceString("doubleTypeCast"), | |
2401 "numTypeCheck": | |
2402 const SourceString("numTypeCast"), | |
2403 "boolTypeCheck": | |
2404 const SourceString("boolTypeCast"), | |
2405 "functionTypeCheck": | |
2406 const SourceString("functionTypeCast"), | |
2407 "intTypeCheck": | |
2408 const SourceString("intTypeCast"), | |
2409 "numberOrStringSuperNativeTypeCheck": | |
2410 const SourceString("numberOrStringSuperNativeTypeCast"), | |
2411 "numberOrStringSuperTypeCheck": | |
2412 const SourceString("numberOrStringSuperTypeCast"), | |
2413 "stringSuperNativeTypeCheck": | |
2414 const SourceString("stringSuperNativeTypeCast"), | |
2415 "stringSuperTypeCheck": | |
2416 const SourceString("stringSuperTypeCast"), | |
2417 "listTypeCheck": | |
2418 const SourceString("listTypeCast"), | |
2419 "listSuperNativeTypeCheck": | |
2420 const SourceString("listSuperNativeTypeCast"), | |
2421 "listSuperTypeCheck": | |
2422 const SourceString("listSuperTypeCast"), | |
2423 "callTypeCheck": | |
2424 const SourceString("callTypeCast"), | |
2425 "propertyTypeCheck": | |
2426 const SourceString("propertyTypeCast"), | |
2427 // TODO(johnniwinther): Add a malformedTypeCast which produces a TypeError | |
2428 // with another message. | |
2429 "malformedTypeCheck": | |
2430 const SourceString("malformedTypeCheck") | |
2431 }; | |
2432 | |
2433 if (node.isChecked) { | 2396 if (node.isChecked) { |
2434 DartType type = node.type.computeType(compiler); | 2397 DartType type = node.type.computeType(compiler); |
2435 Element element = type.element; | 2398 Element element = type.element; |
2436 world.registerIsCheck(type); | 2399 world.registerIsCheck(type); |
2437 | 2400 |
2438 if (node.isArgumentTypeCheck) { | 2401 if (node.isArgumentTypeCheck) { |
2439 if (element == backend.jsIntClass) { | 2402 if (element == backend.jsIntClass) { |
2440 checkInt(node.checkedInput, '!=='); | 2403 checkInt(node.checkedInput, '!=='); |
2441 } else { | 2404 } else { |
2442 assert(element == backend.jsNumberClass); | 2405 assert(element == backend.jsNumberClass); |
(...skipping 10 matching lines...) Expand all Loading... |
2453 return; | 2416 return; |
2454 } | 2417 } |
2455 assert(node.isCheckedModeCheck || node.isCastTypeCheck); | 2418 assert(node.isCheckedModeCheck || node.isCastTypeCheck); |
2456 | 2419 |
2457 SourceString helper; | 2420 SourceString helper; |
2458 if (node.isBooleanConversionCheck) { | 2421 if (node.isBooleanConversionCheck) { |
2459 helper = const SourceString('boolConversionCheck'); | 2422 helper = const SourceString('boolConversionCheck'); |
2460 } else { | 2423 } else { |
2461 helper = backend.getCheckedModeHelper(type); | 2424 helper = backend.getCheckedModeHelper(type); |
2462 if (node.isCastTypeCheck) { | 2425 if (node.isCastTypeCheck) { |
2463 helper = castNames[helper.stringValue]; | 2426 helper = backend.castNames[helper.stringValue]; |
2464 } | 2427 } |
2465 } | 2428 } |
2466 FunctionElement helperElement = compiler.findHelper(helper); | 2429 FunctionElement helperElement = compiler.findHelper(helper); |
2467 world.registerStaticUse(helperElement); | 2430 world.registerStaticUse(helperElement); |
2468 List<js.Expression> arguments = <js.Expression>[]; | 2431 List<js.Expression> arguments = <js.Expression>[]; |
2469 use(node.checkedInput); | 2432 use(node.checkedInput); |
2470 arguments.add(pop()); | 2433 arguments.add(pop()); |
2471 int parameterCount = | 2434 int parameterCount = |
2472 helperElement.computeSignature(compiler).parameterCount; | 2435 helperElement.computeSignature(compiler).parameterCount; |
2473 if (parameterCount == 2) { | 2436 if (parameterCount == 2) { |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3013 if (leftType.canBeNull() && rightType.canBeNull()) { | 2976 if (leftType.canBeNull() && rightType.canBeNull()) { |
3014 if (left.isConstantNull() || right.isConstantNull() || | 2977 if (left.isConstantNull() || right.isConstantNull() || |
3015 (leftType.isPrimitive() && leftType == rightType)) { | 2978 (leftType.isPrimitive() && leftType == rightType)) { |
3016 return '=='; | 2979 return '=='; |
3017 } | 2980 } |
3018 return null; | 2981 return null; |
3019 } else { | 2982 } else { |
3020 return '==='; | 2983 return '==='; |
3021 } | 2984 } |
3022 } | 2985 } |
OLD | NEW |