| OLD | NEW |
| 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'; |
| 11 show PrimitiveConstantExpression; | |
| 12 import 'package:compiler/src/constants/values.dart'; | 11 import 'package:compiler/src/constants/values.dart'; |
| 13 import 'package:compiler/src/dart2jslib.dart' as dart2js | 12 import 'package:compiler/src/dart2jslib.dart' as dart2js |
| 14 show MessageKind; | 13 show MessageKind; |
| 15 import 'package:compiler/src/dart_types.dart' as dart_types | 14 import 'package:compiler/src/dart_types.dart' as dart_types |
| 16 show DartType; | 15 show DartType; |
| 17 import 'package:compiler/src/elements/elements.dart' | 16 import 'package:compiler/src/elements/elements.dart' |
| 18 show Entity, Element, Elements, Local, TypeVariableElement, ErroneousElement, | 17 show Entity, Element, Elements, Local, TypeVariableElement, ErroneousElement, |
| 19 TypeDeclarationElement, ExecutableElement, PublicName; | 18 TypeDeclarationElement, ExecutableElement, PublicName; |
| 20 import 'package:compiler/src/elements/modelx.dart' | 19 import 'package:compiler/src/elements/modelx.dart' |
| 21 show ErroneousElementX, TypeVariableElementX; | 20 show ErroneousElementX, TypeVariableElementX; |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 | 609 |
| 611 /// (Constant (constant)) | 610 /// (Constant (constant)) |
| 612 Constant parseConstant() { | 611 Constant parseConstant() { |
| 613 tokens.consumeStart(CONSTANT); | 612 tokens.consumeStart(CONSTANT); |
| 614 tokens.consumeStart(); | 613 tokens.consumeStart(); |
| 615 Constant result; | 614 Constant result; |
| 616 String tag = tokens.read(); | 615 String tag = tokens.read(); |
| 617 switch (tag) { | 616 switch (tag) { |
| 618 case NULL: | 617 case NULL: |
| 619 result = new Constant( | 618 result = new Constant( |
| 620 new PrimitiveConstantExpression(new NullConstantValue())); | 619 new NullConstantExpression(new NullConstantValue())); |
| 621 break; | 620 break; |
| 622 case BOOL: | 621 case BOOL: |
| 623 String value = tokens.read(); | 622 String value = tokens.read(); |
| 624 if (value == "true") { | 623 if (value == "true") { |
| 625 result = new Constant( | 624 result = new Constant( |
| 626 new PrimitiveConstantExpression(new TrueConstantValue())); | 625 new BoolConstantExpression(true, new TrueConstantValue())); |
| 627 } else if (value == "false") { | 626 } else if (value == "false") { |
| 628 result = new Constant( | 627 result = new Constant( |
| 629 new PrimitiveConstantExpression(new FalseConstantValue())); | 628 new BoolConstantExpression(false, new FalseConstantValue())); |
| 630 } else { | 629 } else { |
| 631 throw "Invalid Boolean value '$value'."; | 630 throw "Invalid Boolean value '$value'."; |
| 632 } | 631 } |
| 633 break; | 632 break; |
| 634 case STRING: | 633 case STRING: |
| 635 List<String> strings = <String>[]; | 634 List<String> strings = <String>[]; |
| 636 do { | 635 do { |
| 637 strings.add(tokens.read()); | 636 strings.add(tokens.read()); |
| 638 } while (tokens.current != ")"); | 637 } while (tokens.current != ")"); |
| 639 String string = strings.join(" "); | 638 String string = strings.join(" "); |
| 640 assert(string.startsWith('"') && string.endsWith('"')); | 639 assert(string.startsWith('"') && string.endsWith('"')); |
| 640 String text = string.substring(1, string.length - 1); |
| 641 StringConstantValue value = new StringConstantValue( | 641 StringConstantValue value = new StringConstantValue( |
| 642 new LiteralDartString(string.substring(1, string.length - 1))); | 642 new LiteralDartString(text)); |
| 643 result = new Constant(new PrimitiveConstantExpression(value)); | 643 result = new Constant(new StringConstantExpression(text, value)); |
| 644 break; | 644 break; |
| 645 case INT: | 645 case INT: |
| 646 String value = tokens.read(); | 646 String value = tokens.read(); |
| 647 int intValue = int.parse(value, onError: (_) => null); | 647 int intValue = int.parse(value, onError: (_) => null); |
| 648 if (intValue == null) { | 648 if (intValue == null) { |
| 649 throw "Invalid int value 'value'."; | 649 throw "Invalid int value 'value'."; |
| 650 } | 650 } |
| 651 result = new Constant( | 651 result = new Constant(new IntConstantExpression( |
| 652 new PrimitiveConstantExpression(new IntConstantValue(intValue))); | 652 intValue, new IntConstantValue(intValue))); |
| 653 break; | 653 break; |
| 654 case DOUBLE: | 654 case DOUBLE: |
| 655 String value = tokens.read(); | 655 String value = tokens.read(); |
| 656 double doubleValue = double.parse(value, (_) => null); | 656 double doubleValue = double.parse(value, (_) => null); |
| 657 if (doubleValue == null) { | 657 if (doubleValue == null) { |
| 658 throw "Invalid double value '$value'."; | 658 throw "Invalid double value '$value'."; |
| 659 } | 659 } |
| 660 result = new Constant(new PrimitiveConstantExpression( | 660 result = new Constant(new DoubleConstantExpression( |
| 661 new DoubleConstantValue(doubleValue))); | 661 doubleValue, new DoubleConstantValue(doubleValue))); |
| 662 break; | 662 break; |
| 663 default: | 663 default: |
| 664 throw "Unexpected constant tag '$tag'."; | 664 throw "Unexpected constant tag '$tag'."; |
| 665 } | 665 } |
| 666 tokens.consumeEnd(); | 666 tokens.consumeEnd(); |
| 667 tokens.consumeEnd(); | 667 tokens.consumeEnd(); |
| 668 return result; | 668 return result; |
| 669 } | 669 } |
| 670 | 670 |
| 671 /// (CreateFunction (definition)) | 671 /// (CreateFunction (definition)) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 /// (ReifyTypeVar type) | 720 /// (ReifyTypeVar type) |
| 721 ReifyTypeVar parseReifyTypeVar() { | 721 ReifyTypeVar parseReifyTypeVar() { |
| 722 tokens.consumeStart(REIFY_TYPE_VAR); | 722 tokens.consumeStart(REIFY_TYPE_VAR); |
| 723 | 723 |
| 724 TypeVariableElement type = new DummyElement(tokens.read()); | 724 TypeVariableElement type = new DummyElement(tokens.read()); |
| 725 | 725 |
| 726 tokens.consumeEnd(); | 726 tokens.consumeEnd(); |
| 727 return new ReifyTypeVar(type); | 727 return new ReifyTypeVar(type); |
| 728 } | 728 } |
| 729 } | 729 } |
| OLD | NEW |