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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 166 } |
167 | 167 |
168 @override | 168 @override |
169 js.Expression visitConcatenateStrings(tree_ir.ConcatenateStrings node) { | 169 js.Expression visitConcatenateStrings(tree_ir.ConcatenateStrings node) { |
170 js.Expression addStrings(js.Expression left, js.Expression right) { | 170 js.Expression addStrings(js.Expression left, js.Expression right) { |
171 return new js.Binary('+', left, right); | 171 return new js.Binary('+', left, right); |
172 } | 172 } |
173 | 173 |
174 js.Expression toString(tree_ir.Expression input) { | 174 js.Expression toString(tree_ir.Expression input) { |
175 bool useDirectly = input is tree_ir.Constant && | 175 bool useDirectly = input is tree_ir.Constant && |
176 (input.expression.value.isString || | 176 (input.value.isString || |
177 input.expression.value.isInt || | 177 input.value.isInt || |
178 input.expression.value.isBool); | 178 input.value.isBool); |
179 js.Expression value = visitExpression(input); | 179 js.Expression value = visitExpression(input); |
180 if (useDirectly) { | 180 if (useDirectly) { |
181 return value; | 181 return value; |
182 } else { | 182 } else { |
183 Element convertToString = glue.getStringConversion(); | 183 Element convertToString = glue.getStringConversion(); |
184 registry.registerStaticUse(convertToString); | 184 registry.registerStaticUse(convertToString); |
185 js.Expression access = glue.staticFunctionAccess(convertToString); | 185 js.Expression access = glue.staticFunctionAccess(convertToString); |
186 return (new js.Call(access, <js.Expression>[value])); | 186 return (new js.Call(access, <js.Expression>[value])); |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 return node.arguments.map(toString).reduce(addStrings); | 190 return node.arguments.map(toString).reduce(addStrings); |
191 } | 191 } |
192 | 192 |
193 @override | 193 @override |
194 js.Expression visitConditional(tree_ir.Conditional node) { | 194 js.Expression visitConditional(tree_ir.Conditional node) { |
195 return new js.Conditional( | 195 return new js.Conditional( |
196 visitExpression(node.condition), | 196 visitExpression(node.condition), |
197 visitExpression(node.thenExpression), | 197 visitExpression(node.thenExpression), |
198 visitExpression(node.elseExpression)); | 198 visitExpression(node.elseExpression)); |
199 } | 199 } |
200 | 200 |
201 js.Expression buildConstant(ConstantValue constant) { | 201 js.Expression buildConstant(ConstantValue constant) { |
202 registry.registerCompileTimeConstant(constant); | 202 registry.registerCompileTimeConstant(constant); |
203 return glue.constantReference(constant); | 203 return glue.constantReference(constant); |
204 } | 204 } |
205 | 205 |
206 @override | 206 @override |
207 js.Expression visitConstant(tree_ir.Constant node) { | 207 js.Expression visitConstant(tree_ir.Constant node) { |
208 return buildConstant(node.expression.value); | 208 return buildConstant(node.value); |
209 } | 209 } |
210 | 210 |
211 js.Expression compileConstant(ParameterElement parameter) { | 211 js.Expression compileConstant(ParameterElement parameter) { |
212 return buildConstant(glue.getConstantForVariable(parameter).value); | 212 return buildConstant(glue.getConstantValueForVariable(parameter)); |
213 } | 213 } |
214 | 214 |
215 // TODO(karlklose): get rid of the selector argument. | 215 // TODO(karlklose): get rid of the selector argument. |
216 js.Expression buildStaticInvoke(Selector selector, | 216 js.Expression buildStaticInvoke(Selector selector, |
217 Element target, | 217 Element target, |
218 List<js.Expression> arguments, | 218 List<js.Expression> arguments, |
219 {SourceInformation sourceInformation}) { | 219 {SourceInformation sourceInformation}) { |
220 registry.registerStaticInvocation(target.declaration); | 220 registry.registerStaticInvocation(target.declaration); |
221 if (target == glue.getInterceptorMethod) { | 221 if (target == glue.getInterceptorMethod) { |
222 // This generates a call to the specialized interceptor function, which | 222 // This generates a call to the specialized interceptor function, which |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 node.arguments.map(visitExpression).toList(growable: false); | 682 node.arguments.map(visitExpression).toList(growable: false); |
683 return glue.generateTypeRepresentation(node.dartType, arguments); | 683 return glue.generateTypeRepresentation(node.dartType, arguments); |
684 } | 684 } |
685 | 685 |
686 visitFunctionExpression(tree_ir.FunctionExpression node) { | 686 visitFunctionExpression(tree_ir.FunctionExpression node) { |
687 // FunctionExpressions are currently unused. | 687 // FunctionExpressions are currently unused. |
688 // We might need them if we want to emit raw JS nested functions. | 688 // We might need them if we want to emit raw JS nested functions. |
689 throw 'FunctionExpressions should not be used'; | 689 throw 'FunctionExpressions should not be used'; |
690 } | 690 } |
691 } | 691 } |
OLD | NEW |