Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: frog/leg/compile_time_constants.dart

Issue 9706018: Make string interpolations be compile-time-constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated to tip of tree. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/co19/co19-leg.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 763
764 Constant visitLiteralNull(LiteralNull node) { 764 Constant visitLiteralNull(LiteralNull node) {
765 return new NullConstant(); 765 return new NullConstant();
766 } 766 }
767 767
768 Constant visitLiteralString(LiteralString node) { 768 Constant visitLiteralString(LiteralString node) {
769 return new StringConstant(node.dartString); 769 return new StringConstant(node.dartString);
770 } 770 }
771 771
772 Constant visitStringJuxtaposition(StringJuxtaposition node) { 772 Constant visitStringJuxtaposition(StringJuxtaposition node) {
773 if (!node.isInterpolation) { 773 StringConstant left = evaluate(node.first);
774 return new StringConstant(node.dartString); 774 StringConstant right = evaluate(node.second);
775 } 775 return new StringConstant(new DartString.concat(left.value, right.value));
776 return super.visitStringJuxtaposition(node); 776 }
777
778 Constant visitStringInterpolation(StringInterpolation node) {
779 StringConstant initialString = evaluate(node.string);
780 DartString accumulator = initialString.value;
781 for (StringInterpolationPart part in node.parts) {
782 Constant expression = evaluate(part.expression);
783 DartString expressionString;
784 if (expression.isNum() || expression.isBool()) {
785 Object value = expression.value;
786 expressionString = new DartString.literal(value.toString());
787 } else if (expression.isString()) {
788 expressionString = expression.value;
789 } else {
790 error(part.expression);
791 }
792 accumulator = new DartString.concat(accumulator, expressionString);
793 StringConstant partString = evaluate(part.string);
794 accumulator = new DartString.concat(accumulator, partString.value);
795 };
796 return new StringConstant(accumulator);
777 } 797 }
778 798
779 // TODO(floitsch): provide better error-messages. 799 // TODO(floitsch): provide better error-messages.
780 Constant visitSend(Send send) { 800 Constant visitSend(Send send) {
781 Element element = elements[send]; 801 Element element = elements[send];
782 if (Elements.isStaticOrTopLevelField(element)) { 802 if (Elements.isStaticOrTopLevelField(element)) {
783 if (element.modifiers === null || 803 if (element.modifiers === null ||
784 !element.modifiers.isFinal()) { 804 !element.modifiers.isFinal()) {
785 error(send); 805 error(send);
786 } 806 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 return constant; 1043 return constant;
1024 } 1044 }
1025 1045
1026 error(Node node) { 1046 error(Node node) {
1027 // TODO(floitsch): get the list of constants that are currently compiled 1047 // TODO(floitsch): get the list of constants that are currently compiled
1028 // and present some kind of stack-trace. 1048 // and present some kind of stack-trace.
1029 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; 1049 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT;
1030 compiler.reportError(node, new CompileTimeConstantError(kind, const [])); 1050 compiler.reportError(node, new CompileTimeConstantError(kind, const []));
1031 } 1051 }
1032 } 1052 }
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698