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

Side by Side Diff: dart/lib/compiler/implementation/compile_time_constants.dart

Issue 10389143: Add locations to diagnostics. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove all references to unreachable() Created 8 years, 7 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 | dart/lib/compiler/implementation/compiler.dart » ('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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 bool operator ==(var other) => this === other; 218 bool operator ==(var other) => this === other;
219 // The magic constant is just a random value. It does not have any 219 // The magic constant is just a random value. It does not have any
220 // significance. 220 // significance.
221 int hashCode() => 536555975; 221 int hashCode() => 536555975;
222 DartString toDartString() => const LiteralDartString("false"); 222 DartString toDartString() => const LiteralDartString("false");
223 } 223 }
224 224
225 class StringConstant extends PrimitiveConstant { 225 class StringConstant extends PrimitiveConstant {
226 final DartString value; 226 final DartString value;
227 int _hashCode; 227 int _hashCode;
228 final Node node;
228 229
229 StringConstant(this.value) { 230 StringConstant(this.value, this.node) {
230 // TODO(floitsch): cache StringConstants. 231 // TODO(floitsch): cache StringConstants.
231 // TODO(floitsch): compute hashcode without calling toString() on the 232 // TODO(floitsch): compute hashcode without calling toString() on the
232 // DartString. 233 // DartString.
233 _hashCode = value.slowToString().hashCode(); 234 _hashCode = value.slowToString().hashCode();
234 } 235 }
235 bool isString() => true; 236 bool isString() => true;
236 237
237 void _writeJsCode(StringBuffer buffer, ConstantHandler handler) { 238 void _writeJsCode(StringBuffer buffer, ConstantHandler handler) {
238 buffer.add("'"); 239 buffer.add("'");
239 ConstantHandler.writeEscapedString(value, buffer, (reason) { 240 ConstantHandler.writeEscapedString(value, buffer, (reason) {
240 throw new CompilerCancelledException(reason); 241 handler.compiler.reportError(node, reason);
241 }); 242 });
242 buffer.add("'"); 243 buffer.add("'");
243 } 244 }
244 245
245 bool operator ==(var other) { 246 bool operator ==(var other) {
246 if (other is !StringConstant) return false; 247 if (other is !StringConstant) return false;
247 StringConstant otherString = other; 248 StringConstant otherString = other;
248 return (_hashCode == otherString._hashCode) && (value == otherString.value); 249 return (_hashCode == otherString._hashCode) && (value == otherString.value);
249 } 250 }
250 251
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 Constant constant = new MapConstant(type, keysList, values, protoValue); 778 Constant constant = new MapConstant(type, keysList, values, protoValue);
778 compiler.constantHandler.registerCompileTimeConstant(constant); 779 compiler.constantHandler.registerCompileTimeConstant(constant);
779 return constant; 780 return constant;
780 } 781 }
781 782
782 Constant visitLiteralNull(LiteralNull node) { 783 Constant visitLiteralNull(LiteralNull node) {
783 return new NullConstant(); 784 return new NullConstant();
784 } 785 }
785 786
786 Constant visitLiteralString(LiteralString node) { 787 Constant visitLiteralString(LiteralString node) {
787 return new StringConstant(node.dartString); 788 return new StringConstant(node.dartString, node);
788 } 789 }
789 790
790 Constant visitStringJuxtaposition(StringJuxtaposition node) { 791 Constant visitStringJuxtaposition(StringJuxtaposition node) {
791 StringConstant left = evaluate(node.first); 792 StringConstant left = evaluate(node.first);
792 StringConstant right = evaluate(node.second); 793 StringConstant right = evaluate(node.second);
793 return new StringConstant(new DartString.concat(left.value, right.value)); 794 return new StringConstant(new DartString.concat(left.value, right.value),
795 node);
794 } 796 }
795 797
796 Constant visitStringInterpolation(StringInterpolation node) { 798 Constant visitStringInterpolation(StringInterpolation node) {
797 StringConstant initialString = evaluate(node.string); 799 StringConstant initialString = evaluate(node.string);
798 DartString accumulator = initialString.value; 800 DartString accumulator = initialString.value;
799 for (StringInterpolationPart part in node.parts) { 801 for (StringInterpolationPart part in node.parts) {
800 Constant expression = evaluate(part.expression); 802 Constant expression = evaluate(part.expression);
801 DartString expressionString; 803 DartString expressionString;
802 if (expression.isNum() || expression.isBool()) { 804 if (expression.isNum() || expression.isBool()) {
803 PrimitiveConstant primitive = expression; 805 PrimitiveConstant primitive = expression;
804 expressionString = new DartString.literal(primitive.value.toString()); 806 expressionString = new DartString.literal(primitive.value.toString());
805 } else if (expression.isString()) { 807 } else if (expression.isString()) {
806 PrimitiveConstant primitive = expression; 808 PrimitiveConstant primitive = expression;
807 expressionString = primitive.value; 809 expressionString = primitive.value;
808 } else { 810 } else {
809 error(part.expression); 811 error(part.expression);
810 } 812 }
811 accumulator = new DartString.concat(accumulator, expressionString); 813 accumulator = new DartString.concat(accumulator, expressionString);
812 StringConstant partString = evaluate(part.string); 814 StringConstant partString = evaluate(part.string);
813 accumulator = new DartString.concat(accumulator, partString.value); 815 accumulator = new DartString.concat(accumulator, partString.value);
814 }; 816 };
815 return new StringConstant(accumulator); 817 return new StringConstant(accumulator, node);
816 } 818 }
817 819
818 // TODO(floitsch): provide better error-messages. 820 // TODO(floitsch): provide better error-messages.
819 Constant visitSend(Send send) { 821 Constant visitSend(Send send) {
820 Element element = elements[send]; 822 Element element = elements[send];
821 if (Elements.isStaticOrTopLevelField(element)) { 823 if (Elements.isStaticOrTopLevelField(element)) {
822 if (element.modifiers === null || 824 if (element.modifiers === null ||
823 !element.modifiers.isFinal()) { 825 !element.modifiers.isFinal()) {
824 error(send); 826 error(send);
825 } 827 }
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 Constant fieldValue = fieldValues[field]; 1146 Constant fieldValue = fieldValues[field];
1145 if (fieldValue === null) { 1147 if (fieldValue === null) {
1146 // Use the default value. 1148 // Use the default value.
1147 fieldValue = compiler.compileVariable(field); 1149 fieldValue = compiler.compileVariable(field);
1148 } 1150 }
1149 jsNewArguments.add(fieldValue); 1151 jsNewArguments.add(fieldValue);
1150 }); 1152 });
1151 return jsNewArguments; 1153 return jsNewArguments;
1152 } 1154 }
1153 } 1155 }
OLDNEW
« no previous file with comments | « no previous file | dart/lib/compiler/implementation/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698