| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_CONTINUATION_RECURSIVE = "InvokeContinuation*"; | 122 static const String INVOKE_CONTINUATION_RECURSIVE = "InvokeContinuation*"; |
| 123 static const String INVOKE_STATIC = "InvokeStatic"; | 123 static const String INVOKE_STATIC = "InvokeStatic"; |
| 124 static const String INVOKE_SUPER_METHOD = "InvokeSuperMethod"; | 124 static const String INVOKE_SUPER_METHOD = "InvokeSuperMethod"; |
| 125 static const String INVOKE_METHOD = "InvokeMethod"; | 125 static const String INVOKE_METHOD = "InvokeMethod"; |
| 126 static const String LET_PRIM = "LetPrim"; | 126 static const String LET_PRIM = "LetPrim"; |
| 127 static const String LET_CONT = "LetCont"; | 127 static const String LET_CONT = "LetCont"; |
| 128 static const String LET_CONT_RECURSIVE = "LetCont*"; |
| 128 static const String SET_CLOSURE_VARIABLE = "SetClosureVariable"; | 129 static const String SET_CLOSURE_VARIABLE = "SetClosureVariable"; |
| 129 static const String TYPE_OPERATOR = "TypeOperator"; | 130 static const String TYPE_OPERATOR = "TypeOperator"; |
| 130 | 131 |
| 131 // Primitives | 132 // Primitives |
| 132 static const String CONSTANT = "Constant"; | 133 static const String CONSTANT = "Constant"; |
| 133 static const String CREATE_FUNCTION = "CreateFunction"; | 134 static const String CREATE_FUNCTION = "CreateFunction"; |
| 134 static const String GET_CLOSURE_VARIABLE = "GetClosureVariable"; | 135 static const String GET_CLOSURE_VARIABLE = "GetClosureVariable"; |
| 135 static const String LITERAL_LIST = "LiteralList"; | 136 static const String LITERAL_LIST = "LiteralList"; |
| 136 static const String LITERAL_MAP = "LiteralMap"; | 137 static const String LITERAL_MAP = "LiteralMap"; |
| 137 static const String REIFY_TYPE_VAR = "ReifyTypeVar"; | 138 static const String REIFY_TYPE_VAR = "ReifyTypeVar"; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return parseInvokeContinuation(true); | 226 return parseInvokeContinuation(true); |
| 226 case INVOKE_METHOD: | 227 case INVOKE_METHOD: |
| 227 return parseInvokeMethod(); | 228 return parseInvokeMethod(); |
| 228 case INVOKE_STATIC: | 229 case INVOKE_STATIC: |
| 229 return parseInvokeStatic(); | 230 return parseInvokeStatic(); |
| 230 case INVOKE_SUPER_METHOD: | 231 case INVOKE_SUPER_METHOD: |
| 231 return parseInvokeSuperMethod(); | 232 return parseInvokeSuperMethod(); |
| 232 case LET_PRIM: | 233 case LET_PRIM: |
| 233 return parseLetPrim(); | 234 return parseLetPrim(); |
| 234 case LET_CONT: | 235 case LET_CONT: |
| 235 return parseLetCont(); | 236 return parseLetCont(false); |
| 237 case LET_CONT_RECURSIVE: |
| 238 return parseLetCont(true); |
| 236 case SET_CLOSURE_VARIABLE: | 239 case SET_CLOSURE_VARIABLE: |
| 237 return parseSetClosureVariable(); | 240 return parseSetClosureVariable(); |
| 238 case TYPE_OPERATOR: | 241 case TYPE_OPERATOR: |
| 239 return parseTypeOperator(); | 242 return parseTypeOperator(); |
| 240 default: | 243 default: |
| 241 assert(false); | 244 assert(false); |
| 242 } | 245 } |
| 243 | 246 |
| 244 return null; | 247 return null; |
| 245 } | 248 } |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 List<Primitive> args = parsePrimitiveList(); | 450 List<Primitive> args = parsePrimitiveList(); |
| 448 | 451 |
| 449 Continuation cont = name2variable[tokens.read()]; | 452 Continuation cont = name2variable[tokens.read()]; |
| 450 assert(cont != null); | 453 assert(cont != null); |
| 451 | 454 |
| 452 tokens.consumeEnd(); | 455 tokens.consumeEnd(); |
| 453 Selector selector = dummySelector(methodName, args.length); | 456 Selector selector = dummySelector(methodName, args.length); |
| 454 return new InvokeSuperMethod(selector, cont, args); | 457 return new InvokeSuperMethod(selector, cont, args); |
| 455 } | 458 } |
| 456 | 459 |
| 457 // (rec? name (args) body) | 460 /// (LetCont (name (args) cont_body) body) |
| 458 Continuation parseContinuation() { | 461 LetCont parseLetCont(bool recursive) { |
| 459 // (rec? name | 462 tokens.consumeStart(recursive ? LET_CONT_RECURSIVE : LET_CONT); |
| 463 |
| 464 // (name |
| 460 tokens.consumeStart(); | 465 tokens.consumeStart(); |
| 461 String name = tokens.read(); | 466 String name = tokens.read(); |
| 462 bool isRecursive = name == "rec"; | |
| 463 if (isRecursive) name = tokens.read(); | |
| 464 | 467 |
| 465 // (args) | 468 // (args) |
| 466 tokens.consumeStart(); | 469 tokens.consumeStart(); |
| 467 List<Parameter> params = <Parameter>[]; | 470 List<Parameter> params = <Parameter>[]; |
| 468 while (tokens.current != ")") { | 471 while (tokens.current != ")") { |
| 469 String paramName = tokens.read(); | 472 String paramName = tokens.read(); |
| 470 Parameter param = new Parameter(new DummyElement(paramName)); | 473 Parameter param = new Parameter(new DummyElement(paramName)); |
| 471 name2variable[paramName] = param; | 474 name2variable[paramName] = param; |
| 472 params.add(param); | 475 params.add(param); |
| 473 } | 476 } |
| 474 tokens.consumeEnd(); | 477 tokens.consumeEnd(); |
| 475 | 478 |
| 476 Continuation cont = new Continuation(params); | 479 Continuation cont = new Continuation(params); |
| 477 name2variable[name] = cont; | 480 name2variable[name] = cont; |
| 478 | 481 |
| 479 cont.isRecursive = isRecursive; | 482 cont.isRecursive = recursive; |
| 480 // cont_body | 483 // cont_body |
| 481 cont.body = parseExpression(); | 484 cont.body = parseExpression(); |
| 482 tokens.consumeEnd(); | 485 tokens.consumeEnd(); |
| 483 return cont; | |
| 484 } | |
| 485 | |
| 486 /// (LetCont (continuations) body) | |
| 487 LetCont parseLetCont() { | |
| 488 tokens.consumeStart(LET_CONT); | |
| 489 tokens.consumeStart(); | |
| 490 List<Continuation> continuations = <Continuation>[]; | |
| 491 while (tokens.current != ")") { | |
| 492 continuations.add(parseContinuation()); | |
| 493 } | |
| 494 tokens.consumeEnd(); | |
| 495 | 486 |
| 496 // body) | 487 // body) |
| 497 Expression body = parseExpression(); | 488 Expression body = parseExpression(); |
| 498 tokens.consumeEnd(); | 489 tokens.consumeEnd(); |
| 499 | 490 |
| 500 return new LetCont(continuations, body); | 491 return new LetCont(cont, body); |
| 501 } | 492 } |
| 502 | 493 |
| 503 /// (SetClosureVariable name value body) | 494 /// (SetClosureVariable name value body) |
| 504 SetClosureVariable parseSetClosureVariable() { | 495 SetClosureVariable parseSetClosureVariable() { |
| 505 tokens.consumeStart(SET_CLOSURE_VARIABLE); | 496 tokens.consumeStart(SET_CLOSURE_VARIABLE); |
| 506 | 497 |
| 507 ClosureVariable local = name2variable[tokens.read()]; | 498 ClosureVariable local = name2variable[tokens.read()]; |
| 508 Primitive value = name2variable[tokens.read()]; | 499 Primitive value = name2variable[tokens.read()]; |
| 509 assert(value != null); | 500 assert(value != null); |
| 510 | 501 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 return new ReifyTypeVar(type); | 681 return new ReifyTypeVar(type); |
| 691 } | 682 } |
| 692 | 683 |
| 693 /// (This) | 684 /// (This) |
| 694 This parseThis() { | 685 This parseThis() { |
| 695 tokens.consumeStart(THIS); | 686 tokens.consumeStart(THIS); |
| 696 tokens.consumeEnd(); | 687 tokens.consumeEnd(); |
| 697 return new This(); | 688 return new This(); |
| 698 } | 689 } |
| 699 } | 690 } |
| OLD | NEW |