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