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 class Constant implements Hashable { | 5 class Constant implements Hashable { |
| 6 const Constant(); | 6 const Constant(); |
| 7 | 7 |
| 8 bool isNull() => false; | 8 bool isNull() => false; |
| 9 bool isBool() => false; | 9 bool isBool() => false; |
| 10 bool isTrue() => false; | 10 bool isTrue() => false; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 key.writeJsCode(buffer, handler); | 326 key.writeJsCode(buffer, handler); |
| 327 buffer.add(": "); | 327 buffer.add(": "); |
| 328 Constant value = values[i]; | 328 Constant value = values[i]; |
| 329 // TODO(floitsch): share this code with the ListConstant and | 329 // TODO(floitsch): share this code with the ListConstant and |
| 330 // ConstructedConstant. | 330 // ConstructedConstant. |
| 331 if (value.isObject()) { | 331 if (value.isObject()) { |
| 332 String name = handler.getNameForConstant(value); | 332 String name = handler.getNameForConstant(value); |
| 333 buffer.add("$isolatePrototype.$name"); | 333 buffer.add("$isolatePrototype.$name"); |
| 334 } else { | 334 } else { |
| 335 value.writeJsCode(buffer, handler); | 335 value.writeJsCode(buffer, handler); |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 buffer.add("}"); | 338 buffer.add("}"); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void badFieldCountError() { | 341 void badFieldCountError() { |
| 342 handler.compiler.internalError( | 342 handler.compiler.internalError( |
| 343 "Compiler and ConstantMap disagree on number of fields."); | 343 "Compiler and ConstantMap disagree on number of fields."); |
| 344 } | 344 } |
| 345 | 345 |
| 346 ClassElement classElement = type.element; | 346 ClassElement classElement = type.element; |
| 347 buffer.add("new "); | 347 buffer.add("new "); |
| 348 buffer.add(handler.getJsConstructor(classElement)); | 348 buffer.add(handler.getJsConstructor(classElement)); |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 761 } | 761 } |
| 762 | 762 |
| 763 Constant visitLiteralNull(LiteralNull node) { | 763 Constant visitLiteralNull(LiteralNull node) { |
| 764 return new NullConstant(); | 764 return new NullConstant(); |
| 765 } | 765 } |
| 766 | 766 |
| 767 Constant visitLiteralString(LiteralString node) { | 767 Constant visitLiteralString(LiteralString node) { |
| 768 return new StringConstant(node.dartString); | 768 return new StringConstant(node.dartString); |
| 769 } | 769 } |
| 770 | 770 |
| 771 Constant visitStringJuxtapostion(StringJuxtaposition node) { | |
| 772 if (node.dartString !== null) { | |
|
ngeoffray
2012/03/14 12:29:58
Replace with !node.isInterpolation?
Lasse Reichstein Nielsen
2012/03/14 13:04:49
True.
I'm still not sure I like the isInterpolatio
| |
| 773 return new StringConstant(node.dartString); | |
| 774 } | |
| 775 super.visitStringJuxtapostion(node); | |
| 776 } | |
| 777 | |
| 771 // TODO(floitsch): provide better error-messages. | 778 // TODO(floitsch): provide better error-messages. |
| 772 Constant visitSend(Send send) { | 779 Constant visitSend(Send send) { |
| 773 Element element = elements[send]; | 780 Element element = elements[send]; |
| 774 if (Elements.isStaticOrTopLevelField(element)) { | 781 if (Elements.isStaticOrTopLevelField(element)) { |
| 775 if (element.modifiers === null || | 782 if (element.modifiers === null || |
| 776 !element.modifiers.isFinal()) { | 783 !element.modifiers.isFinal()) { |
| 777 error(send); | 784 error(send); |
| 778 } | 785 } |
| 779 return constantHandler.compileVariable(element); | 786 return constantHandler.compileVariable(element); |
| 780 } else if (send.isPrefix) { | 787 } else if (send.isPrefix) { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1015 return constant; | 1022 return constant; |
| 1016 } | 1023 } |
| 1017 | 1024 |
| 1018 error(Node node) { | 1025 error(Node node) { |
| 1019 // TODO(floitsch): get the list of constants that are currently compiled | 1026 // TODO(floitsch): get the list of constants that are currently compiled |
| 1020 // and present some kind of stack-trace. | 1027 // and present some kind of stack-trace. |
| 1021 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; | 1028 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; |
| 1022 compiler.reportError(node, new CompileTimeConstantError(kind, const [])); | 1029 compiler.reportError(node, new CompileTimeConstantError(kind, const [])); |
| 1023 } | 1030 } |
| 1024 } | 1031 } |
| OLD | NEW |