| 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/implementation/constants/values.dart' as values | 10 import 'package:compiler/implementation/constants/expressions.dart' |
| 11 show Constant, IntConstant, NullConstant, StringConstant, | 11 show PrimitiveConstantExpression; |
| 12 DoubleConstant, TrueConstant, FalseConstant; | 12 import 'package:compiler/implementation/constants/values.dart'; |
| 13 import 'package:compiler/implementation/dart2jslib.dart' as dart2js | 13 import 'package:compiler/implementation/dart2jslib.dart' as dart2js |
| 14 show MessageKind; | 14 show MessageKind; |
| 15 import 'package:compiler/implementation/dart_types.dart' as dart_types | 15 import 'package:compiler/implementation/dart_types.dart' as dart_types |
| 16 show DartType; | 16 show DartType; |
| 17 import 'package:compiler/implementation/elements/elements.dart' | 17 import 'package:compiler/implementation/elements/elements.dart' |
| 18 show Entity, Element, Elements, Local, TypeVariableElement, ErroneousElement, | 18 show Entity, Element, Elements, Local, TypeVariableElement, ErroneousElement, |
| 19 TypeDeclarationElement, ExecutableElement; | 19 TypeDeclarationElement, ExecutableElement; |
| 20 import 'package:compiler/implementation/elements/modelx.dart' | 20 import 'package:compiler/implementation/elements/modelx.dart' |
| 21 show ErroneousElementX, TypeVariableElementX; | 21 show ErroneousElementX, TypeVariableElementX; |
| 22 import 'package:compiler/implementation/tree/tree.dart' show LiteralDartString; | 22 import 'package:compiler/implementation/tree/tree.dart' show LiteralDartString; |
| 23 import 'package:compiler/implementation/universe/universe.dart' | 23 import 'package:compiler/implementation/universe/universe.dart' |
| 24 show Selector, SelectorKind; | 24 show Selector, SelectorKind; |
| 25 import 'package:compiler/implementation/cps_ir/cps_ir_nodes.dart'; | 25 import 'package:compiler/implementation/cps_ir/cps_ir_nodes.dart'; |
| 26 import 'package:compiler/implementation/constants/expressions.dart' | |
| 27 show PrimitiveConstExp; | |
| 28 | 26 |
| 29 /// Used whenever a node constructed by [SExpressionUnstringifier] needs a | 27 /// Used whenever a node constructed by [SExpressionUnstringifier] needs a |
| 30 /// named entity. | 28 /// named entity. |
| 31 class DummyEntity extends Entity { | 29 class DummyEntity extends Entity { |
| 32 final String name; | 30 final String name; |
| 33 DummyEntity(this.name); | 31 DummyEntity(this.name); |
| 34 } | 32 } |
| 35 | 33 |
| 36 /// Used whenever a node constructed by [SExpressionUnstringifier] needs a | 34 /// Used whenever a node constructed by [SExpressionUnstringifier] needs a |
| 37 /// local. | 35 /// local. |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 } | 549 } |
| 552 | 550 |
| 553 /// (Constant (constant)) | 551 /// (Constant (constant)) |
| 554 Constant parseConstant() { | 552 Constant parseConstant() { |
| 555 tokens.consumeStart(CONSTANT); | 553 tokens.consumeStart(CONSTANT); |
| 556 String tag = tokens.read(); | 554 String tag = tokens.read(); |
| 557 | 555 |
| 558 // NullConstant. | 556 // NullConstant. |
| 559 if (tag == "NullConstant") { | 557 if (tag == "NullConstant") { |
| 560 tokens.consumeEnd(); | 558 tokens.consumeEnd(); |
| 561 return new Constant(new PrimitiveConstExp(new values.NullConstant())); | 559 return new Constant( |
| 560 new PrimitiveConstantExpression(new NullConstantValue())); |
| 562 } | 561 } |
| 563 | 562 |
| 564 // BoolConstant. | 563 // BoolConstant. |
| 565 if (tag == "BoolConstant") { | 564 if (tag == "BoolConstant") { |
| 566 tokens.consumeStart(); | 565 tokens.consumeStart(); |
| 567 tag = tokens.read(); | 566 tag = tokens.read(); |
| 568 tokens.consumeEnd(); | 567 tokens.consumeEnd(); |
| 569 tokens.consumeEnd(); | 568 tokens.consumeEnd(); |
| 570 if (tag == "true") { | 569 if (tag == "true") { |
| 571 return new Constant(new PrimitiveConstExp( | 570 return new Constant(new PrimitiveConstantExpression( |
| 572 new values.TrueConstant())); | 571 new TrueConstantValue())); |
| 573 } else if (tag == "false") { | 572 } else if (tag == "false") { |
| 574 return new Constant(new PrimitiveConstExp( | 573 return new Constant(new PrimitiveConstantExpression( |
| 575 new values.FalseConstant())); | 574 new FalseConstantValue())); |
| 576 } | 575 } |
| 577 throw "Invalid bool value '$tag'."; | 576 throw "Invalid bool value '$tag'."; |
| 578 } | 577 } |
| 579 | 578 |
| 580 // StringConstant. | 579 // StringConstant. |
| 581 if (tag == "StringConstant") { | 580 if (tag == "StringConstant") { |
| 582 tokens.consumeStart(); | 581 tokens.consumeStart(); |
| 583 List<String> strings = <String>[]; | 582 List<String> strings = <String>[]; |
| 584 do { | 583 do { |
| 585 strings.add(tokens.read()); | 584 strings.add(tokens.read()); |
| 586 } while (tokens.current != ")"); | 585 } while (tokens.current != ")"); |
| 587 tokens.consumeEnd(); | 586 tokens.consumeEnd(); |
| 588 | 587 |
| 589 String string = strings.join(" "); | 588 String string = strings.join(" "); |
| 590 assert(string.startsWith('"') && string.endsWith('"')); | 589 assert(string.startsWith('"') && string.endsWith('"')); |
| 591 | 590 |
| 592 values.StringConstant value = new values.StringConstant( | 591 StringConstantValue value = new StringConstantValue( |
| 593 new LiteralDartString(string.substring(1, string.length - 1))); | 592 new LiteralDartString(string.substring(1, string.length - 1))); |
| 594 | 593 |
| 595 tokens.consumeEnd(); | 594 tokens.consumeEnd(); |
| 596 return new Constant(new PrimitiveConstExp(value)); | 595 return new Constant(new PrimitiveConstantExpression(value)); |
| 597 } | 596 } |
| 598 | 597 |
| 599 // IntConstant. | 598 // IntConstant. |
| 600 if (tag == "IntConstant") { | 599 if (tag == "IntConstant") { |
| 601 tokens.consumeStart(); | 600 tokens.consumeStart(); |
| 602 tag = tokens.read(); | 601 tag = tokens.read(); |
| 603 int intValue = int.parse(tag, onError: (_) => null); | 602 int intValue = int.parse(tag, onError: (_) => null); |
| 604 if (intValue == null) { | 603 if (intValue == null) { |
| 605 throw "Invalid int value '$tag'."; | 604 throw "Invalid int value '$tag'."; |
| 606 } | 605 } |
| 607 tokens.consumeEnd(); | 606 tokens.consumeEnd(); |
| 608 tokens.consumeEnd(); | 607 tokens.consumeEnd(); |
| 609 return new Constant(new PrimitiveConstExp( | 608 return new Constant(new PrimitiveConstantExpression( |
| 610 new values.IntConstant(intValue))); | 609 new IntConstantValue(intValue))); |
| 611 } | 610 } |
| 612 | 611 |
| 613 // DoubleConstant. | 612 // DoubleConstant. |
| 614 if (tag == "DoubleConstant") { | 613 if (tag == "DoubleConstant") { |
| 615 tokens.consumeStart(); | 614 tokens.consumeStart(); |
| 616 tag = tokens.read(); | 615 tag = tokens.read(); |
| 617 double doubleValue = double.parse(tag, (_) => null); | 616 double doubleValue = double.parse(tag, (_) => null); |
| 618 if (doubleValue == null) { | 617 if (doubleValue == null) { |
| 619 throw "Invalid double value '$tag'."; | 618 throw "Invalid double value '$tag'."; |
| 620 } | 619 } |
| 621 tokens.consumeEnd(); | 620 tokens.consumeEnd(); |
| 622 tokens.consumeEnd(); | 621 tokens.consumeEnd(); |
| 623 return new Constant(new PrimitiveConstExp( | 622 return new Constant(new PrimitiveConstantExpression( |
| 624 new values.DoubleConstant(doubleValue))); | 623 new DoubleConstantValue(doubleValue))); |
| 625 } | 624 } |
| 626 | 625 |
| 627 throw "Unhandled tag '$tag'."; | 626 throw "Unhandled tag '$tag'."; |
| 628 } | 627 } |
| 629 | 628 |
| 630 /// (CreateFunction (definition)) | 629 /// (CreateFunction (definition)) |
| 631 CreateFunction parseCreateFunction() { | 630 CreateFunction parseCreateFunction() { |
| 632 tokens.consumeStart(CREATE_FUNCTION); | 631 tokens.consumeStart(CREATE_FUNCTION); |
| 633 FunctionDefinition def = parseFunctionDefinition(); | 632 FunctionDefinition def = parseFunctionDefinition(); |
| 634 tokens.consumeEnd(); | 633 tokens.consumeEnd(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 return new ReifyTypeVar(type); | 673 return new ReifyTypeVar(type); |
| 675 } | 674 } |
| 676 | 675 |
| 677 /// (This) | 676 /// (This) |
| 678 This parseThis() { | 677 This parseThis() { |
| 679 tokens.consumeStart(THIS); | 678 tokens.consumeStart(THIS); |
| 680 tokens.consumeEnd(); | 679 tokens.consumeEnd(); |
| 681 return new This(); | 680 return new This(); |
| 682 } | 681 } |
| 683 } | 682 } |
| OLD | NEW |