| 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' |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 static const String BRANCH = "Branch"; | 117 static const String BRANCH = "Branch"; |
| 118 static const String CONCATENATE_STRINGS = "ConcatenateStrings"; | 118 static const String CONCATENATE_STRINGS = "ConcatenateStrings"; |
| 119 static const String DECLARE_FUNCTION = "DeclareFunction"; | 119 static const String DECLARE_FUNCTION = "DeclareFunction"; |
| 120 static const String INVOKE_CONSTRUCTOR = "InvokeConstructor"; | 120 static const String INVOKE_CONSTRUCTOR = "InvokeConstructor"; |
| 121 static const String INVOKE_CONTINUATION = "InvokeContinuation"; | 121 static const String INVOKE_CONTINUATION = "InvokeContinuation"; |
| 122 static const String INVOKE_STATIC = "InvokeStatic"; | 122 static const String INVOKE_STATIC = "InvokeStatic"; |
| 123 static const String INVOKE_METHOD_DIRECTLY = "InvokeMethodDirectly"; | 123 static const String INVOKE_METHOD_DIRECTLY = "InvokeMethodDirectly"; |
| 124 static const String INVOKE_METHOD = "InvokeMethod"; | 124 static const String INVOKE_METHOD = "InvokeMethod"; |
| 125 static const String LET_PRIM = "LetPrim"; | 125 static const String LET_PRIM = "LetPrim"; |
| 126 static const String LET_CONT = "LetCont"; | 126 static const String LET_CONT = "LetCont"; |
| 127 static const String SET_CLOSURE_VARIABLE = "SetClosureVariable"; | 127 static const String LET_MUTABLE = "LetMutable"; |
| 128 static const String SET_MUTABLE_VARIABLE = "SetMutableVariable"; |
| 128 static const String TYPE_OPERATOR = "TypeOperator"; | 129 static const String TYPE_OPERATOR = "TypeOperator"; |
| 129 | 130 |
| 130 // Primitives | 131 // Primitives |
| 131 static const String CONSTANT = "Constant"; | 132 static const String CONSTANT = "Constant"; |
| 132 static const String CREATE_FUNCTION = "CreateFunction"; | 133 static const String CREATE_FUNCTION = "CreateFunction"; |
| 133 static const String GET_CLOSURE_VARIABLE = "GetClosureVariable"; | 134 static const String GET_MUTABLE_VARIABLE = "GetMutableVariable"; |
| 134 static const String LITERAL_LIST = "LiteralList"; | 135 static const String LITERAL_LIST = "LiteralList"; |
| 135 static const String LITERAL_MAP = "LiteralMap"; | 136 static const String LITERAL_MAP = "LiteralMap"; |
| 136 static const String REIFY_TYPE_VAR = "ReifyTypeVar"; | 137 static const String REIFY_TYPE_VAR = "ReifyTypeVar"; |
| 137 static const String THIS = "This"; | 138 static const String THIS = "This"; |
| 138 | 139 |
| 139 // Other | 140 // Other |
| 140 static const String FUNCTION_DEFINITION = "FunctionDefinition"; | 141 static const String FUNCTION_DEFINITION = "FunctionDefinition"; |
| 141 static const String IS_TRUE = "IsTrue"; | 142 static const String IS_TRUE = "IsTrue"; |
| 142 | 143 |
| 143 // Constants | 144 // Constants |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 case INVOKE_METHOD: | 224 case INVOKE_METHOD: |
| 224 return parseInvokeMethod(); | 225 return parseInvokeMethod(); |
| 225 case INVOKE_STATIC: | 226 case INVOKE_STATIC: |
| 226 return parseInvokeStatic(); | 227 return parseInvokeStatic(); |
| 227 case INVOKE_METHOD_DIRECTLY: | 228 case INVOKE_METHOD_DIRECTLY: |
| 228 return parseInvokeMethodDirectly(); | 229 return parseInvokeMethodDirectly(); |
| 229 case LET_PRIM: | 230 case LET_PRIM: |
| 230 return parseLetPrim(); | 231 return parseLetPrim(); |
| 231 case LET_CONT: | 232 case LET_CONT: |
| 232 return parseLetCont(); | 233 return parseLetCont(); |
| 233 case SET_CLOSURE_VARIABLE: | 234 case LET_MUTABLE: |
| 234 return parseSetClosureVariable(); | 235 return parseLetMutable(); |
| 236 case SET_MUTABLE_VARIABLE: |
| 237 return parseSetMutableVariable(); |
| 235 case TYPE_OPERATOR: | 238 case TYPE_OPERATOR: |
| 236 return parseTypeOperator(); | 239 return parseTypeOperator(); |
| 237 default: | 240 default: |
| 238 assert(false); | 241 assert(false); |
| 239 } | 242 } |
| 240 | 243 |
| 241 return null; | 244 return null; |
| 242 } | 245 } |
| 243 | 246 |
| 244 /// (prim1 prim2 ... primn) | 247 /// (prim1 prim2 ... primn) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 332 |
| 330 tokens.consumeEnd(); | 333 tokens.consumeEnd(); |
| 331 return new ConcatenateStrings(cont, args); | 334 return new ConcatenateStrings(cont, args); |
| 332 } | 335 } |
| 333 | 336 |
| 334 /// (DeclareFunction name = function in body) | 337 /// (DeclareFunction name = function in body) |
| 335 DeclareFunction parseDeclareFunction() { | 338 DeclareFunction parseDeclareFunction() { |
| 336 tokens.consumeStart(DECLARE_FUNCTION); | 339 tokens.consumeStart(DECLARE_FUNCTION); |
| 337 | 340 |
| 338 // name = | 341 // name = |
| 339 ClosureVariable local = getClosureVariable(tokens.read()); | 342 MutableVariable local = addMutableVariable(tokens.read()); |
| 340 tokens.read("="); | 343 tokens.read("="); |
| 341 | 344 |
| 342 // function in | 345 // function in |
| 343 FunctionDefinition def = parseFunctionDefinition(); | 346 FunctionDefinition def = parseFunctionDefinition(); |
| 344 tokens.read("in"); | 347 tokens.read("in"); |
| 345 | 348 |
| 346 // body | 349 // body |
| 347 Expression body = parseExpression(); | 350 Expression body = parseExpression(); |
| 348 | 351 |
| 349 tokens.consumeEnd(); | 352 tokens.consumeEnd(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 } | 486 } |
| 484 tokens.consumeEnd(); | 487 tokens.consumeEnd(); |
| 485 | 488 |
| 486 // body) | 489 // body) |
| 487 Expression body = parseExpression(); | 490 Expression body = parseExpression(); |
| 488 tokens.consumeEnd(); | 491 tokens.consumeEnd(); |
| 489 | 492 |
| 490 return new LetCont.many(continuations, body); | 493 return new LetCont.many(continuations, body); |
| 491 } | 494 } |
| 492 | 495 |
| 493 /// (SetClosureVariable name value body) | 496 /// (LetMutable (name value) body) |
| 494 SetClosureVariable parseSetClosureVariable() { | 497 LetMutable parseLetMutable() { |
| 495 tokens.consumeStart(SET_CLOSURE_VARIABLE); | 498 tokens.consumeStart(LET_MUTABLE); |
| 496 | 499 |
| 500 tokens.consumeStart(); |
| 497 String name = tokens.read(); | 501 String name = tokens.read(); |
| 498 ClosureVariable local = getClosureVariable(name); | 502 MutableVariable local = addMutableVariable(name); |
| 503 Primitive value = name2variable[tokens.read()]; |
| 504 tokens.consumeEnd(); |
| 505 |
| 506 Expression body = parseExpression(); |
| 507 tokens.consumeEnd(); |
| 508 return new LetMutable(local, value)..plug(body); |
| 509 } |
| 510 |
| 511 /// (SetMutableVariable name value body) |
| 512 SetMutableVariable parseSetMutableVariable() { |
| 513 tokens.consumeStart(SET_MUTABLE_VARIABLE); |
| 514 |
| 515 MutableVariable local = name2variable[tokens.read()]; |
| 499 Primitive value = name2variable[tokens.read()]; | 516 Primitive value = name2variable[tokens.read()]; |
| 500 assert(value != null); | 517 assert(value != null); |
| 501 | 518 |
| 502 Expression body = parseExpression(); | 519 Expression body = parseExpression(); |
| 503 | 520 |
| 504 tokens.consumeEnd(); | 521 tokens.consumeEnd(); |
| 505 return new SetClosureVariable(local, value) | 522 return new SetMutableVariable(local, value) |
| 506 ..plug(body); | 523 ..plug(body); |
| 507 } | 524 } |
| 508 | 525 |
| 509 /// (TypeOperator operator recv type cont) | 526 /// (TypeOperator operator recv type cont) |
| 510 TypeOperator parseTypeOperator() { | 527 TypeOperator parseTypeOperator() { |
| 511 tokens.consumeStart(TYPE_OPERATOR); | 528 tokens.consumeStart(TYPE_OPERATOR); |
| 512 | 529 |
| 513 String operator = tokens.read(); | 530 String operator = tokens.read(); |
| 514 | 531 |
| 515 Primitive recv = name2variable[tokens.read()]; | 532 Primitive recv = name2variable[tokens.read()]; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 545 } | 562 } |
| 546 | 563 |
| 547 Primitive parsePrimitive() { | 564 Primitive parsePrimitive() { |
| 548 assert(tokens.current == "("); | 565 assert(tokens.current == "("); |
| 549 | 566 |
| 550 switch (tokens.next) { | 567 switch (tokens.next) { |
| 551 case CONSTANT: | 568 case CONSTANT: |
| 552 return parseConstant(); | 569 return parseConstant(); |
| 553 case CREATE_FUNCTION: | 570 case CREATE_FUNCTION: |
| 554 return parseCreateFunction(); | 571 return parseCreateFunction(); |
| 555 case GET_CLOSURE_VARIABLE: | 572 case GET_MUTABLE_VARIABLE: |
| 556 return parseGetClosureVariable(); | 573 return parseGetMutableVariable(); |
| 557 case LITERAL_LIST: | 574 case LITERAL_LIST: |
| 558 return parseLiteralList(); | 575 return parseLiteralList(); |
| 559 case LITERAL_MAP: | 576 case LITERAL_MAP: |
| 560 return parseLiteralMap(); | 577 return parseLiteralMap(); |
| 561 case REIFY_TYPE_VAR: | 578 case REIFY_TYPE_VAR: |
| 562 return parseReifyTypeVar(); | 579 return parseReifyTypeVar(); |
| 563 case THIS: | 580 case THIS: |
| 564 return parseThis(); | 581 return parseThis(); |
| 565 default: | 582 default: |
| 566 assert(false); | 583 assert(false); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 } | 647 } |
| 631 | 648 |
| 632 /// (CreateFunction (definition)) | 649 /// (CreateFunction (definition)) |
| 633 CreateFunction parseCreateFunction() { | 650 CreateFunction parseCreateFunction() { |
| 634 tokens.consumeStart(CREATE_FUNCTION); | 651 tokens.consumeStart(CREATE_FUNCTION); |
| 635 FunctionDefinition def = parseFunctionDefinition(); | 652 FunctionDefinition def = parseFunctionDefinition(); |
| 636 tokens.consumeEnd(); | 653 tokens.consumeEnd(); |
| 637 return new CreateFunction(def); | 654 return new CreateFunction(def); |
| 638 } | 655 } |
| 639 | 656 |
| 640 ClosureVariable getClosureVariable(String name) { | 657 MutableVariable addMutableVariable(String name) { |
| 641 if (!name2variable.containsKey(name)) { | 658 assert(!name2variable.containsKey(name)); |
| 642 ClosureVariable variable = | 659 MutableVariable variable = |
| 643 new ClosureVariable(new DummyElement(""), new DummyElement(name)); | 660 new MutableVariable(new DummyElement(""), new DummyElement(name)); |
| 644 name2variable[name] = variable; | 661 name2variable[name] = variable; |
| 645 } | 662 return variable; |
| 646 return name2variable[name]; | |
| 647 } | 663 } |
| 648 | 664 |
| 649 /// (GetClosureVariable name) | 665 /// (GetMutableVariable name) |
| 650 GetClosureVariable parseGetClosureVariable() { | 666 GetMutableVariable parseGetMutableVariable() { |
| 651 tokens.consumeStart(GET_CLOSURE_VARIABLE); | 667 tokens.consumeStart(GET_MUTABLE_VARIABLE); |
| 652 | 668 MutableVariable local = name2variable[tokens.read()]; |
| 653 String name = tokens.read(); | |
| 654 ClosureVariable local = getClosureVariable(name); | |
| 655 tokens.consumeEnd(); | 669 tokens.consumeEnd(); |
| 656 | 670 |
| 657 return new GetClosureVariable(local); | 671 return new GetMutableVariable(local); |
| 658 } | 672 } |
| 659 | 673 |
| 660 /// (LiteralList (values)) | 674 /// (LiteralList (values)) |
| 661 LiteralList parseLiteralList() { | 675 LiteralList parseLiteralList() { |
| 662 tokens.consumeStart(LITERAL_LIST); | 676 tokens.consumeStart(LITERAL_LIST); |
| 663 List<Primitive> values = parsePrimitiveList(); | 677 List<Primitive> values = parsePrimitiveList(); |
| 664 tokens.consumeEnd(); | 678 tokens.consumeEnd(); |
| 665 return new LiteralList(null, values); | 679 return new LiteralList(null, values); |
| 666 } | 680 } |
| 667 | 681 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 691 return new ReifyTypeVar(type); | 705 return new ReifyTypeVar(type); |
| 692 } | 706 } |
| 693 | 707 |
| 694 /// (This) | 708 /// (This) |
| 695 This parseThis() { | 709 This parseThis() { |
| 696 tokens.consumeStart(THIS); | 710 tokens.consumeStart(THIS); |
| 697 tokens.consumeEnd(); | 711 tokens.consumeEnd(); |
| 698 return new This(); | 712 return new This(); |
| 699 } | 713 } |
| 700 } | 714 } |
| OLD | NEW |