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