Chromium Code Reviews| 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 /** | 5 /** |
| 6 * The [CompileTimeConstantHandler] keeps track of compile-time constants, | 6 * The [CompileTimeConstantHandler] keeps track of compile-time constants, |
| 7 * initializations of global and static fields, and default values of | 7 * initializations of global and static fields, and default values of |
| 8 * optional parameters. | 8 * optional parameters. |
| 9 */ | 9 */ |
| 10 class CompileTimeConstantHandler extends CompilerTask { | 10 class CompileTimeConstantHandler extends CompilerTask { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 && element.modifiers.isFinal(); | 89 && element.modifiers.isFinal(); |
| 90 }); | 90 }); |
| 91 } | 91 } |
| 92 | 92 |
| 93 String getJsCodeForVariable(VariableElement element) { | 93 String getJsCodeForVariable(VariableElement element) { |
| 94 var value = initialVariableValues[element]; | 94 var value = initialVariableValues[element]; |
| 95 if (value === null) return "(void 0)"; | 95 if (value === null) return "(void 0)"; |
| 96 if (value is num) return "$value"; | 96 if (value is num) return "$value"; |
| 97 if (value === true) return "true"; | 97 if (value === true) return "true"; |
| 98 if (value === false) return "false"; | 98 if (value === false) return "false"; |
| 99 if (value is SourceString) return value.stringValue; | |
|
floitsch
2012/02/14 10:40:57
The string must be escaped.
Please also add a smal
| |
| 99 | 100 |
| 100 // TODO(floitsch): support more values. | 101 // TODO(floitsch): support more values. |
| 101 compiler.unimplemented("CompileTimeConstantHandler.getJsCodeForVariable", | 102 compiler.unimplemented("CompileTimeConstantHandler.getJsCodeForVariable", |
| 102 node: element.parseNode(compiler)); | 103 node: element.parseNode(compiler)); |
| 103 } | 104 } |
| 104 } | 105 } |
| 105 | 106 |
| 106 class CompileTimeConstantEvaluator extends AbstractVisitor { | 107 class CompileTimeConstantEvaluator extends AbstractVisitor { |
| 107 final CompileTimeConstantHandler constantHandler; | 108 final CompileTimeConstantHandler constantHandler; |
| 108 final TreeElements definitions; | 109 final TreeElements definitions; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 139 | 140 |
| 140 error(Element element) { | 141 error(Element element) { |
| 141 // TODO(floitsch): get the list of constants that are currently compiled | 142 // TODO(floitsch): get the list of constants that are currently compiled |
| 142 // and present some kind of stack-trace. | 143 // and present some kind of stack-trace. |
| 143 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; | 144 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; |
| 144 List arguments = [element.name]; | 145 List arguments = [element.name]; |
| 145 Node node = element.parseNode(compiler); | 146 Node node = element.parseNode(compiler); |
| 146 compiler.reportError(node, new CompileTimeConstantError(kind, arguments)); | 147 compiler.reportError(node, new CompileTimeConstantError(kind, arguments)); |
| 147 } | 148 } |
| 148 } | 149 } |
| OLD | NEW |