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