OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library code_generator; | 5 library code_generator; |
6 | 6 |
7 import 'glue.dart'; | 7 import 'glue.dart'; |
8 | 8 |
9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; | 9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; |
10 import '../../js/js.dart' as js; | 10 import '../../js/js.dart' as js; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 glue.reportInternalError('$node did not produce code.'); | 89 glue.reportInternalError('$node did not produce code.'); |
90 } | 90 } |
91 return result; | 91 return result; |
92 } | 92 } |
93 | 93 |
94 /// Generates a name for the given variable. First trying with the name of | 94 /// Generates a name for the given variable. First trying with the name of |
95 /// the [Variable.element] if it is non-null. | 95 /// the [Variable.element] if it is non-null. |
96 String getVariableName(tree_ir.Variable variable) { | 96 String getVariableName(tree_ir.Variable variable) { |
97 // TODO(sigurdm): Handle case where the variable belongs to an enclosing | 97 // TODO(sigurdm): Handle case where the variable belongs to an enclosing |
98 // function. | 98 // function. |
99 if (variable.host.element != currentFunction) giveup(variable); | 99 if (variable.host != currentFunction) giveup(variable); |
100 | 100 |
101 // Get the name if we already have one. | 101 // Get the name if we already have one. |
102 String name = variableNames[variable]; | 102 String name = variableNames[variable]; |
103 if (name != null) { | 103 if (name != null) { |
104 return name; | 104 return name; |
105 } | 105 } |
106 | 106 |
107 // Synthesize a variable name that isn't used elsewhere. | 107 // Synthesize a variable name that isn't used elsewhere. |
108 // The [usedVariableNames] set is shared between nested emitters, | 108 // The [usedVariableNames] set is shared between nested emitters, |
109 // so this also prevents clash with variables in an enclosing/inner scope. | 109 // so this also prevents clash with variables in an enclosing/inner scope. |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 accumulator.add( | 391 accumulator.add( |
392 buildWhile(new js.LiteralBool(true), node.body, node.label, node)); | 392 buildWhile(new js.LiteralBool(true), node.body, node.label, node)); |
393 } | 393 } |
394 | 394 |
395 @override | 395 @override |
396 void visitReturn(tree_ir.Return node) { | 396 void visitReturn(tree_ir.Return node) { |
397 accumulator.add(new js.Return(visitExpression(node.value))); | 397 accumulator.add(new js.Return(visitExpression(node.value))); |
398 } | 398 } |
399 | 399 |
400 } | 400 } |
OLD | NEW |