| 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 // TODO(floitsch): finish implementation. | 5 // TODO(floitsch): finish implementation. |
| 6 class Constant implements Hashable { | 6 class Constant implements Hashable { |
| 7 // TODO(floitsch): remove the direct access to the string. | 7 // TODO(floitsch): remove the direct access to the string. |
| 8 final String jsCode; | 8 final String jsCode; |
| 9 Constant(this.jsCode); | 9 Constant(this.jsCode); |
| 10 | 10 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 compiler.registerInstantiatedClass(classElement); | 106 compiler.registerInstantiatedClass(classElement); |
| 107 Namer namer = compiler.namer; | 107 Namer namer = compiler.namer; |
| 108 String instantiation = "new ${namer.isolatePropertyAccess(classElement)}()"; | 108 String instantiation = "new ${namer.isolatePropertyAccess(classElement)}()"; |
| 109 Constant constant = new Constant(instantiation); | 109 Constant constant = new Constant(instantiation); |
| 110 registerCompileTimeConstant(constant); | 110 registerCompileTimeConstant(constant); |
| 111 return constant; | 111 return constant; |
| 112 } | 112 } |
| 113 | 113 |
| 114 compileListLiteral(Node node, List arguments) { | 114 compileListLiteral(Node node, List arguments) { |
| 115 StringBuffer buffer = new StringBuffer(); | 115 StringBuffer buffer = new StringBuffer(); |
| 116 buffer.add(compiler.namer.ISOLATE); |
| 117 buffer.add(".prototype.makeConstantList"); |
| 118 buffer.add("(["); |
| 116 for (int i = 0; i < arguments.length; i++) { | 119 for (int i = 0; i < arguments.length; i++) { |
| 117 if (i != 0) buffer.add(", "); | 120 if (i != 0) buffer.add(", "); |
| 118 // TODO(floitsch): canonicalize if the constant is in the | 121 // TODO(floitsch): canonicalize if the constant is in the |
| 119 // [compiledConstant] set. | 122 // [compiledConstant] set. |
| 120 writeJsCode(buffer, arguments[i]); | 123 writeJsCode(buffer, arguments[i]); |
| 121 } | 124 } |
| 125 buffer.add("])"); |
| 122 // TODO(floitsch): do we have to register 'List' as instantiated class? | 126 // TODO(floitsch): do we have to register 'List' as instantiated class? |
| 123 String array = "[$buffer]"; | 127 String array = buffer.toString(); |
| 124 Constant constant = new Constant(array); | 128 Constant constant = new Constant(array); |
| 125 registerCompileTimeConstant(constant); | 129 registerCompileTimeConstant(constant); |
| 126 return constant; | 130 return constant; |
| 127 } | 131 } |
| 128 | 132 |
| 129 /** | 133 /** |
| 130 * Returns a [List] of static non final fields that need to be initialized. | 134 * Returns a [List] of static non final fields that need to be initialized. |
| 131 * The list must be evaluated in order since the fields might depend on each | 135 * The list must be evaluated in order since the fields might depend on each |
| 132 * other. | 136 * other. |
| 133 */ | 137 */ |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 return constantHandler.compileListLiteral(node, arguments); | 402 return constantHandler.compileListLiteral(node, arguments); |
| 399 } | 403 } |
| 400 | 404 |
| 401 error(Node node) { | 405 error(Node node) { |
| 402 // TODO(floitsch): get the list of constants that are currently compiled | 406 // TODO(floitsch): get the list of constants that are currently compiled |
| 403 // and present some kind of stack-trace. | 407 // and present some kind of stack-trace. |
| 404 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; | 408 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; |
| 405 compiler.reportError(node, new CompileTimeConstantError(kind, const [])); | 409 compiler.reportError(node, new CompileTimeConstantError(kind, const [])); |
| 406 } | 410 } |
| 407 } | 411 } |
| OLD | NEW |