| 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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 == "null") { |
| 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 == "true") { |
| 562 tokens.consumeEnd(); | 564 tokens.consumeEnd(); |
| 563 return new Constant(null, new dart2js.TrueConstant()); | 565 return new Constant(new PrimitiveConstExp( |
| 566 new dart2js.TrueConstant())); |
| 564 } else if (tag == "false") { | 567 } else if (tag == "false") { |
| 565 tokens.consumeEnd(); | 568 tokens.consumeEnd(); |
| 566 return new Constant(null, new dart2js.FalseConstant()); | 569 return new Constant(new PrimitiveConstExp( |
| 570 new dart2js.FalseConstant())); |
| 567 } | 571 } |
| 568 | 572 |
| 569 // StringConstant. | 573 // StringConstant. |
| 570 if (tag == "StringConstant") { | 574 if (tag == "StringConstant") { |
| 571 tokens.consumeStart(); | 575 tokens.consumeStart(); |
| 572 List<String> strings = <String>[]; | 576 List<String> strings = <String>[]; |
| 573 do { | 577 do { |
| 574 strings.add(tokens.read()); | 578 strings.add(tokens.read()); |
| 575 } while (tokens.current != ")"); | 579 } while (tokens.current != ")"); |
| 576 tokens.consumeEnd(); | 580 tokens.consumeEnd(); |
| 577 | 581 |
| 578 String string = strings.join(" "); | 582 String string = strings.join(" "); |
| 579 assert(string.startsWith('"') && string.endsWith('"')); | 583 assert(string.startsWith('"') && string.endsWith('"')); |
| 580 | 584 |
| 581 dart2js.StringConstant value = new dart2js.StringConstant( | 585 dart2js.StringConstant value = new dart2js.StringConstant( |
| 582 new LiteralDartString(string.substring(1, string.length - 1))); | 586 new LiteralDartString(string.substring(1, string.length - 1))); |
| 583 | 587 |
| 584 tokens.consumeEnd(); | 588 tokens.consumeEnd(); |
| 585 return new Constant(null, value); | 589 return new Constant(new PrimitiveConstExp(value)); |
| 586 } | 590 } |
| 587 | 591 |
| 588 // IntConstant. | 592 // IntConstant. |
| 589 int intValue = int.parse(tag, onError: (_) => null); | 593 int intValue = int.parse(tag, onError: (_) => null); |
| 590 if (intValue != null) { | 594 if (intValue != null) { |
| 591 tokens.consumeEnd(); | 595 tokens.consumeEnd(); |
| 592 return new Constant(null, new dart2js.IntConstant(intValue)); | 596 return new Constant(new PrimitiveConstExp( |
| 597 new dart2js.IntConstant(intValue))); |
| 593 } | 598 } |
| 594 | 599 |
| 595 // DoubleConstant. | 600 // DoubleConstant. |
| 596 double doubleValue = double.parse(tag, (_) => null); | 601 double doubleValue = double.parse(tag, (_) => null); |
| 597 if (doubleValue != null) { | 602 if (doubleValue != null) { |
| 598 tokens.consumeEnd(); | 603 tokens.consumeEnd(); |
| 599 return new Constant(null, new dart2js.DoubleConstant(doubleValue)); | 604 return new Constant(new PrimitiveConstExp( |
| 605 new dart2js.DoubleConstant(doubleValue))); |
| 600 } | 606 } |
| 601 | 607 |
| 602 assert(false); | 608 assert(false); |
| 603 return null; | 609 return null; |
| 604 } | 610 } |
| 605 | 611 |
| 606 /// (CreateFunction (definition)) | 612 /// (CreateFunction (definition)) |
| 607 CreateFunction parseCreateFunction() { | 613 CreateFunction parseCreateFunction() { |
| 608 tokens.consumeStart(CREATE_FUNCTION); | 614 tokens.consumeStart(CREATE_FUNCTION); |
| 609 FunctionDefinition def = parseFunctionDefinition(); | 615 FunctionDefinition def = parseFunctionDefinition(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 return new ReifyTypeVar(type); | 656 return new ReifyTypeVar(type); |
| 651 } | 657 } |
| 652 | 658 |
| 653 /// (This) | 659 /// (This) |
| 654 This parseThis() { | 660 This parseThis() { |
| 655 tokens.consumeStart(THIS); | 661 tokens.consumeStart(THIS); |
| 656 tokens.consumeEnd(); | 662 tokens.consumeEnd(); |
| 657 return new This(); | 663 return new This(); |
| 658 } | 664 } |
| 659 } | 665 } |
| OLD | NEW |