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

Side by Side Diff: tests/compiler/dart2js/backend_dart/sexpr_unstringifier.dart

Issue 813753002: Change the S-expression representation of constant values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | « tests/compiler/dart2js/backend_dart/opt_shrinking_test.dart ('k') | no next file » | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 // SExpressionUnstringifier implements the inverse operation to 5 // SExpressionUnstringifier implements the inverse operation to
6 // [SExpressionStringifier]. 6 // [SExpressionStringifier].
7 7
8 library sexpr_unstringifier; 8 library sexpr_unstringifier;
9 9
10 import 'package:compiler/src/constants/expressions.dart' 10 import 'package:compiler/src/constants/expressions.dart'
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 static const String GET_CLOSURE_VARIABLE = "GetClosureVariable"; 135 static const String GET_CLOSURE_VARIABLE = "GetClosureVariable";
136 static const String LITERAL_LIST = "LiteralList"; 136 static const String LITERAL_LIST = "LiteralList";
137 static const String LITERAL_MAP = "LiteralMap"; 137 static const String LITERAL_MAP = "LiteralMap";
138 static const String REIFY_TYPE_VAR = "ReifyTypeVar"; 138 static const String REIFY_TYPE_VAR = "ReifyTypeVar";
139 static const String THIS = "This"; 139 static const String THIS = "This";
140 140
141 // Other 141 // Other
142 static const String FUNCTION_DEFINITION = "FunctionDefinition"; 142 static const String FUNCTION_DEFINITION = "FunctionDefinition";
143 static const String IS_TRUE = "IsTrue"; 143 static const String IS_TRUE = "IsTrue";
144 144
145 // Constants
146 static const String BOOL = "Bool";
147 static const String DOUBLE = "Double";
148 static const String INT = "Int";
149 static const String NULL = "Null";
150 static const String STRING = "String";
151
145 final Map<String, Definition> name2variable = 152 final Map<String, Definition> name2variable =
146 <String, Definition>{ "return": new Continuation.retrn() }; 153 <String, Definition>{ "return": new Continuation.retrn() };
147 154
148 // Operator names used for canonicalization. In theory, we could simply use 155 // Operator names used for canonicalization. In theory, we could simply use
149 // Elements.isOperatorName() on the parsed tokens; however, comparisons are 156 // Elements.isOperatorName() on the parsed tokens; however, comparisons are
150 // done using identical() for performance reasons, which are reliable only for 157 // done using identical() for performance reasons, which are reliable only for
151 // compile-time literal strings. 158 // compile-time literal strings.
152 static Set<String> OPERATORS = new Set<String>.from( 159 static Set<String> OPERATORS = new Set<String>.from(
153 [ '~', '==', '[]', '*', '/', '%', '~/', '+', '<<', 'unary-' 160 [ '~', '==', '[]', '*', '/', '%', '~/', '+', '<<', 'unary-'
154 , '>>', '>=', '>', '<=', '<', '&', '^', '|', '[]=', '-' 161 , '>>', '>=', '>', '<=', '<', '&', '^', '|', '[]=', '-'
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 default: 576 default:
570 assert(false); 577 assert(false);
571 } 578 }
572 579
573 return null; 580 return null;
574 } 581 }
575 582
576 /// (Constant (constant)) 583 /// (Constant (constant))
577 Constant parseConstant() { 584 Constant parseConstant() {
578 tokens.consumeStart(CONSTANT); 585 tokens.consumeStart(CONSTANT);
586 tokens.consumeStart();
587 Constant result;
579 String tag = tokens.read(); 588 String tag = tokens.read();
580 589 switch (tag) {
581 // NullConstant. 590 case NULL:
582 if (tag == "NullConstant") { 591 result = new Constant(
583 tokens.consumeEnd(); 592 new PrimitiveConstantExpression(new NullConstantValue()));
584 return new Constant( 593 break;
585 new PrimitiveConstantExpression(new NullConstantValue())); 594 case BOOL:
595 String value = tokens.read();
596 if (value == "true") {
597 result = new Constant(
598 new PrimitiveConstantExpression(new TrueConstantValue()));
599 } else if (value == "false") {
600 result = new Constant(
601 new PrimitiveConstantExpression(new FalseConstantValue()));
602 } else {
603 throw "Invalid Boolean value '$value'.";
604 }
605 break;
606 case STRING:
607 List<String> strings = <String>[];
608 do {
609 strings.add(tokens.read());
610 } while (tokens.current != ")");
611 String string = strings.join(" ");
612 assert(string.startsWith('"') && string.endsWith('"'));
613 StringConstantValue value = new StringConstantValue(
614 new LiteralDartString(string.substring(1, string.length - 1)));
615 result = new Constant(new PrimitiveConstantExpression(value));
616 break;
617 case INT:
618 String value = tokens.read();
619 int intValue = int.parse(value, onError: (_) => null);
620 if (intValue == null) {
621 throw "Invalid int value 'value'.";
622 }
623 result = new Constant(
624 new PrimitiveConstantExpression(new IntConstantValue(intValue)));
625 break;
626 case DOUBLE:
627 String value = tokens.read();
628 double doubleValue = double.parse(value, (_) => null);
629 if (doubleValue == null) {
630 throw "Invalid double value '$value'.";
631 }
632 result = new Constant(new PrimitiveConstantExpression(
633 new DoubleConstantValue(doubleValue)));
634 break;
635 default:
636 throw "Unexpected constant tag '$tag'.";
586 } 637 }
587 638 tokens.consumeEnd();
588 // BoolConstant. 639 tokens.consumeEnd();
589 if (tag == "BoolConstant") { 640 return result;
590 tokens.consumeStart();
591 tag = tokens.read();
592 tokens.consumeEnd();
593 tokens.consumeEnd();
594 if (tag == "true") {
595 return new Constant(new PrimitiveConstantExpression(
596 new TrueConstantValue()));
597 } else if (tag == "false") {
598 return new Constant(new PrimitiveConstantExpression(
599 new FalseConstantValue()));
600 }
601 throw "Invalid bool value '$tag'.";
602 }
603
604 // StringConstant.
605 if (tag == "StringConstant") {
606 tokens.consumeStart();
607 List<String> strings = <String>[];
608 do {
609 strings.add(tokens.read());
610 } while (tokens.current != ")");
611 tokens.consumeEnd();
612
613 String string = strings.join(" ");
614 assert(string.startsWith('"') && string.endsWith('"'));
615
616 StringConstantValue value = new StringConstantValue(
617 new LiteralDartString(string.substring(1, string.length - 1)));
618
619 tokens.consumeEnd();
620 return new Constant(new PrimitiveConstantExpression(value));
621 }
622
623 // IntConstant.
624 if (tag == "IntConstant") {
625 tokens.consumeStart();
626 tag = tokens.read();
627 int intValue = int.parse(tag, onError: (_) => null);
628 if (intValue == null) {
629 throw "Invalid int value '$tag'.";
630 }
631 tokens.consumeEnd();
632 tokens.consumeEnd();
633 return new Constant(new PrimitiveConstantExpression(
634 new IntConstantValue(intValue)));
635 }
636
637 // DoubleConstant.
638 if (tag == "DoubleConstant") {
639 tokens.consumeStart();
640 tag = tokens.read();
641 double doubleValue = double.parse(tag, (_) => null);
642 if (doubleValue == null) {
643 throw "Invalid double value '$tag'.";
644 }
645 tokens.consumeEnd();
646 tokens.consumeEnd();
647 return new Constant(new PrimitiveConstantExpression(
648 new DoubleConstantValue(doubleValue)));
649 }
650
651 throw "Unhandled tag '$tag'.";
652 } 641 }
653 642
654 /// (CreateFunction (definition)) 643 /// (CreateFunction (definition))
655 CreateFunction parseCreateFunction() { 644 CreateFunction parseCreateFunction() {
656 tokens.consumeStart(CREATE_FUNCTION); 645 tokens.consumeStart(CREATE_FUNCTION);
657 FunctionDefinition def = parseFunctionDefinition(); 646 FunctionDefinition def = parseFunctionDefinition();
658 tokens.consumeEnd(); 647 tokens.consumeEnd();
659 return new CreateFunction(def); 648 return new CreateFunction(def);
660 } 649 }
661 650
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 return new ReifyTypeVar(type); 692 return new ReifyTypeVar(type);
704 } 693 }
705 694
706 /// (This) 695 /// (This)
707 This parseThis() { 696 This parseThis() {
708 tokens.consumeStart(THIS); 697 tokens.consumeStart(THIS);
709 tokens.consumeEnd(); 698 tokens.consumeEnd();
710 return new This(); 699 return new This();
711 } 700 }
712 } 701 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/backend_dart/opt_shrinking_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698