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