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 2196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2207 world.registerStaticUse(helper); | 2207 world.registerStaticUse(helper); |
2208 String helperName = backend.namer.isolateAccess(helper); | 2208 String helperName = backend.namer.isolateAccess(helper); |
2209 push(new js.Call(new js.VariableUse(helperName), arguments)); | 2209 push(new js.Call(new js.VariableUse(helperName), arguments)); |
2210 if (negative) push(new js.Prefix('!', pop())); | 2210 if (negative) push(new js.Prefix('!', pop())); |
2211 } | 2211 } |
2212 | 2212 |
2213 void checkType(HInstruction input, DartType type, {bool negative: false}) { | 2213 void checkType(HInstruction input, DartType type, {bool negative: false}) { |
2214 assert(invariant(input, !type.isMalformed, | 2214 assert(invariant(input, !type.isMalformed, |
2215 message: 'Attempt to check malformed type $type')); | 2215 message: 'Attempt to check malformed type $type')); |
2216 Element element = type.element; | 2216 Element element = type.element; |
2217 | |
2218 if (element == backend.jsArrayClass) { | 2217 if (element == backend.jsArrayClass) { |
2219 checkArray(input, negative ? '!==': '==='); | 2218 checkArray(input, negative ? '!==': '==='); |
2220 return; | 2219 return; |
2221 } else if (element == backend.jsMutableArrayClass) { | 2220 } else if (element == backend.jsMutableArrayClass) { |
2222 if (negative) { | 2221 if (negative) { |
2223 checkImmutableArray(input); | 2222 checkImmutableArray(input); |
2224 } else { | 2223 } else { |
2225 checkMutableArray(input); | 2224 checkMutableArray(input); |
2226 } | 2225 } |
2227 return; | 2226 return; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2508 pushStatement(new js.Throw(call)); | 2507 pushStatement(new js.Throw(call)); |
2509 } | 2508 } |
2510 currentContainer = oldContainer; | 2509 currentContainer = oldContainer; |
2511 body = unwrapStatement(body); | 2510 body = unwrapStatement(body); |
2512 pushStatement(new js.If.noElse(test, body), node); | 2511 pushStatement(new js.If.noElse(test, body), node); |
2513 return; | 2512 return; |
2514 } | 2513 } |
2515 | 2514 |
2516 assert(node.isCheckedModeCheck || node.isCastTypeCheck); | 2515 assert(node.isCheckedModeCheck || node.isCastTypeCheck); |
2517 DartType type = node.typeExpression; | 2516 DartType type = node.typeExpression; |
| 2517 assert(type.kind != TypeKind.TYPEDEF); |
2518 if (type.kind == TypeKind.FUNCTION) { | 2518 if (type.kind == TypeKind.FUNCTION) { |
2519 // TODO(5022): We currently generate $isFunction checks for | 2519 // TODO(5022): We currently generate $isFunction checks for |
2520 // function types. | 2520 // function types. |
2521 world.registerIsCheck( | 2521 world.registerIsCheck( |
2522 compiler.functionClass.computeType(compiler), work.resolutionTree); | 2522 compiler.functionClass.computeType(compiler), work.resolutionTree); |
2523 } | 2523 } |
2524 world.registerIsCheck(type, work.resolutionTree); | 2524 world.registerIsCheck(type, work.resolutionTree); |
2525 | 2525 |
| 2526 CheckedModeHelper helper; |
2526 FunctionElement helperElement; | 2527 FunctionElement helperElement; |
2527 if (node.isBooleanConversionCheck) { | 2528 if (node.isBooleanConversionCheck) { |
2528 helperElement = | 2529 helper = |
2529 compiler.findHelper(const SourceString('boolConversionCheck')); | 2530 const CheckedModeHelper(const SourceString('boolConversionCheck')); |
2530 } else { | 2531 } else { |
2531 helperElement = backend.getCheckedModeHelper(type, | 2532 helper = |
2532 typeCast: node.isCastTypeCheck); | 2533 backend.getCheckedModeHelper(type, typeCast: node.isCastTypeCheck); |
2533 } | 2534 } |
2534 world.registerStaticUse(helperElement); | 2535 |
2535 List<js.Expression> arguments = <js.Expression>[]; | 2536 push(helper.generateCall(this, node)); |
2536 use(node.checkedInput); | |
2537 arguments.add(pop()); | |
2538 int parameterCount = | |
2539 helperElement.computeSignature(compiler).parameterCount; | |
2540 // TODO(johnniwinther): Refactor this to avoid using the parameter count | |
2541 // to determine how the helper should be called. | |
2542 if (node.typeExpression.kind == TypeKind.TYPE_VARIABLE) { | |
2543 assert(parameterCount == 2); | |
2544 use(node.typeRepresentation); | |
2545 arguments.add(pop()); | |
2546 } else if (parameterCount == 2) { | |
2547 // 2 arguments implies that the method is either [propertyTypeCheck], | |
2548 // [propertyTypeCast] or [assertObjectIsSubtype]. | |
2549 assert(!type.isMalformed); | |
2550 String additionalArgument = backend.namer.operatorIs(type.element); | |
2551 arguments.add(js.string(additionalArgument)); | |
2552 } else if (parameterCount == 3) { | |
2553 // 3 arguments implies that the method is [malformedTypeCheck]. | |
2554 assert(type.isMalformed); | |
2555 String reasons = Types.fetchReasonsFromMalformedType(type); | |
2556 arguments.add(js.string('$type')); | |
2557 // TODO(johnniwinther): Handle escaping correctly. | |
2558 arguments.add(js.string(reasons)); | |
2559 } else if (parameterCount == 4) { | |
2560 Element element = type.element; | |
2561 String isField = backend.namer.operatorIs(element); | |
2562 arguments.add(js.string(isField)); | |
2563 use(node.typeRepresentation); | |
2564 arguments.add(pop()); | |
2565 String asField = backend.namer.substitutionName(element); | |
2566 arguments.add(js.string(asField)); | |
2567 } else { | |
2568 assert(!type.isMalformed); | |
2569 // No additional arguments needed. | |
2570 } | |
2571 String helperName = backend.namer.isolateAccess(helperElement); | |
2572 push(new js.Call(new js.VariableUse(helperName), arguments)); | |
2573 } | 2537 } |
2574 } | 2538 } |
2575 | 2539 |
2576 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { | 2540 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { |
2577 SsaOptimizedCodeGenerator(backend, work) : super(backend, work); | 2541 SsaOptimizedCodeGenerator(backend, work) : super(backend, work); |
2578 | 2542 |
2579 HBasicBlock beginGraph(HGraph graph) { | 2543 HBasicBlock beginGraph(HGraph graph) { |
2580 return graph.entry; | 2544 return graph.entry; |
2581 } | 2545 } |
2582 | 2546 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3012 if (leftType.canBeNull() && rightType.canBeNull()) { | 2976 if (leftType.canBeNull() && rightType.canBeNull()) { |
3013 if (left.isConstantNull() || right.isConstantNull() || | 2977 if (left.isConstantNull() || right.isConstantNull() || |
3014 (leftType.isPrimitive(compiler) && leftType == rightType)) { | 2978 (leftType.isPrimitive(compiler) && leftType == rightType)) { |
3015 return '=='; | 2979 return '=='; |
3016 } | 2980 } |
3017 return null; | 2981 return null; |
3018 } else { | 2982 } else { |
3019 return '==='; | 2983 return '==='; |
3020 } | 2984 } |
3021 } | 2985 } |
OLD | NEW |