OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart2js; | 5 part of dart2js; |
6 | 6 |
7 /** | 7 /** |
8 * The [ConstantHandler] keeps track of compile-time constants, | 8 * The [ConstantHandler] keeps track of compile-time constants, |
9 * initializations of global and static fields, and default values of | 9 * initializations of global and static fields, and default values of |
10 * optional parameters. | 10 * optional parameters. |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 Constant constant = new MapConstant(type, keysList, values, protoValue); | 343 Constant constant = new MapConstant(type, keysList, values, protoValue); |
344 compiler.constantHandler.registerCompileTimeConstant(constant); | 344 compiler.constantHandler.registerCompileTimeConstant(constant); |
345 return constant; | 345 return constant; |
346 } | 346 } |
347 | 347 |
348 Constant visitLiteralNull(LiteralNull node) { | 348 Constant visitLiteralNull(LiteralNull node) { |
349 return constantSystem.createNull(); | 349 return constantSystem.createNull(); |
350 } | 350 } |
351 | 351 |
352 Constant visitLiteralString(LiteralString node) { | 352 Constant visitLiteralString(LiteralString node) { |
353 compiler.enqueuer.codegen.registerSpecialInstantiatedClass( | |
354 compiler.jsStringClass); | |
ahe
2012/11/09 13:45:29
Looks like a good candidate for a small shared met
ngeoffray
2012/11/13 11:45:16
Done.
| |
353 return constantSystem.createString(node.dartString, node); | 355 return constantSystem.createString(node.dartString, node); |
354 } | 356 } |
355 | 357 |
356 Constant visitStringJuxtaposition(StringJuxtaposition node) { | 358 Constant visitStringJuxtaposition(StringJuxtaposition node) { |
357 StringConstant left = evaluate(node.first); | 359 StringConstant left = evaluate(node.first); |
358 StringConstant right = evaluate(node.second); | 360 StringConstant right = evaluate(node.second); |
359 if (left == null || right == null) return null; | 361 if (left == null || right == null) return null; |
362 compiler.enqueuer.codegen.registerSpecialInstantiatedClass( | |
363 compiler.jsStringClass); | |
360 return constantSystem.createString( | 364 return constantSystem.createString( |
361 new DartString.concat(left.value, right.value), node); | 365 new DartString.concat(left.value, right.value), node); |
362 } | 366 } |
363 | 367 |
364 Constant visitStringInterpolation(StringInterpolation node) { | 368 Constant visitStringInterpolation(StringInterpolation node) { |
365 StringConstant initialString = evaluate(node.string); | 369 StringConstant initialString = evaluate(node.string); |
366 if (initialString == null) return null; | 370 if (initialString == null) return null; |
371 compiler.enqueuer.codegen.registerSpecialInstantiatedClass( | |
372 compiler.jsStringClass); | |
367 DartString accumulator = initialString.value; | 373 DartString accumulator = initialString.value; |
368 for (StringInterpolationPart part in node.parts) { | 374 for (StringInterpolationPart part in node.parts) { |
369 Constant expression = evaluate(part.expression); | 375 Constant expression = evaluate(part.expression); |
370 DartString expressionString; | 376 DartString expressionString; |
371 if (expression == null) { | 377 if (expression == null) { |
372 return signalNotCompileTimeConstant(part.expression); | 378 return signalNotCompileTimeConstant(part.expression); |
373 } else if (expression.isNum() || expression.isBool()) { | 379 } else if (expression.isNum() || expression.isBool()) { |
374 PrimitiveConstant primitive = expression; | 380 PrimitiveConstant primitive = expression; |
375 expressionString = new DartString.literal(primitive.value.toString()); | 381 expressionString = new DartString.literal(primitive.value.toString()); |
376 } else if (expression.isString()) { | 382 } else if (expression.isString()) { |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 // Use the default value. | 815 // Use the default value. |
810 fieldValue = compiler.compileConstant(field); | 816 fieldValue = compiler.compileConstant(field); |
811 } | 817 } |
812 jsNewArguments.add(fieldValue); | 818 jsNewArguments.add(fieldValue); |
813 }, | 819 }, |
814 includeBackendMembers: true, | 820 includeBackendMembers: true, |
815 includeSuperMembers: true); | 821 includeSuperMembers: true); |
816 return jsNewArguments; | 822 return jsNewArguments; |
817 } | 823 } |
818 } | 824 } |
OLD | NEW |