| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import 'builder_kernel.dart'; | 8 import 'builder_kernel.dart'; |
| 9 import 'kernel_ast_adapter.dart'; | |
| 10 import 'nodes.dart'; | 9 import 'nodes.dart'; |
| 11 | 10 |
| 12 /// Visits and concatenates the expressions in a string concatenation. | 11 /// Visits and concatenates the expressions in a string concatenation. |
| 13 class KernelStringBuilder extends ir.Visitor { | 12 class KernelStringBuilder extends ir.Visitor { |
| 14 final KernelSsaGraphBuilder builder; | 13 final KernelSsaGraphBuilder builder; |
| 15 KernelAstAdapter get astAdapter => builder.astAdapter; | |
| 16 | 14 |
| 17 /// The string value generated so far. | 15 /// The string value generated so far. |
| 18 HInstruction result = null; | 16 HInstruction result = null; |
| 19 | 17 |
| 20 KernelStringBuilder(this.builder); | 18 KernelStringBuilder(this.builder); |
| 21 | 19 |
| 22 @override | 20 @override |
| 23 void defaultNode(ir.Node node) { | 21 void defaultNode(ir.Node node) { |
| 24 throw new SpannableAssertionFailure( | 22 throw new SpannableAssertionFailure( |
| 25 astAdapter.getNode(node), 'Unexpected node.'); | 23 CURRENT_ELEMENT_SPANNABLE, 'Unexpected node: $node'); |
| 26 } | 24 } |
| 27 | 25 |
| 28 @override | 26 @override |
| 29 void defaultExpression(ir.Expression node) { | 27 void defaultExpression(ir.Expression node) { |
| 30 node.accept(builder); | 28 node.accept(builder); |
| 31 HInstruction expression = builder.pop(); | 29 HInstruction expression = builder.pop(); |
| 32 | 30 |
| 33 // We want to use HStringify when: | 31 // We want to use HStringify when: |
| 34 // 1. The value is known to be a primitive type, because it might get | 32 // 1. The value is known to be a primitive type, because it might get |
| 35 // constant-folded and codegen has some tricks with JavaScript | 33 // constant-folded and codegen has some tricks with JavaScript |
| (...skipping 29 matching lines...) Expand all Loading... |
| 65 return instruction; | 63 return instruction; |
| 66 } | 64 } |
| 67 | 65 |
| 68 HInstruction stringify(HInstruction expression) { | 66 HInstruction stringify(HInstruction expression) { |
| 69 HInstruction instruction = | 67 HInstruction instruction = |
| 70 new HStringify(expression, builder.commonMasks.stringType); | 68 new HStringify(expression, builder.commonMasks.stringType); |
| 71 builder.add(instruction); | 69 builder.add(instruction); |
| 72 return instruction; | 70 return instruction; |
| 73 } | 71 } |
| 74 } | 72 } |
| OLD | NEW |