| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 /// Constructs a minimal in-memory representation of the IR represented | 112 /// Constructs a minimal in-memory representation of the IR represented |
| 113 /// by the given string. Many fields are currently simply set to null. | 113 /// by the given string. Many fields are currently simply set to null. |
| 114 class SExpressionUnstringifier { | 114 class SExpressionUnstringifier { |
| 115 | 115 |
| 116 // Expressions | 116 // Expressions |
| 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_CONTINUATION_RECURSIVE = "InvokeContinuation*"; |
| 122 static const String INVOKE_STATIC = "InvokeStatic"; | 123 static const String INVOKE_STATIC = "InvokeStatic"; |
| 123 static const String INVOKE_METHOD_DIRECTLY = "InvokeMethodDirectly"; | 124 static const String INVOKE_METHOD_DIRECTLY = "InvokeMethodDirectly"; |
| 124 static const String INVOKE_METHOD = "InvokeMethod"; | 125 static const String INVOKE_METHOD = "InvokeMethod"; |
| 125 static const String LET_PRIM = "LetPrim"; | 126 static const String LET_PRIM = "LetPrim"; |
| 126 static const String LET_CONT = "LetCont"; | 127 static const String LET_CONT = "LetCont"; |
| 127 static const String SET_CLOSURE_VARIABLE = "SetClosureVariable"; | 128 static const String SET_CLOSURE_VARIABLE = "SetClosureVariable"; |
| 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"; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 switch (tokens.next) { | 213 switch (tokens.next) { |
| 213 case BRANCH: | 214 case BRANCH: |
| 214 return parseBranch(); | 215 return parseBranch(); |
| 215 case CONCATENATE_STRINGS: | 216 case CONCATENATE_STRINGS: |
| 216 return parseConcatenateStrings(); | 217 return parseConcatenateStrings(); |
| 217 case DECLARE_FUNCTION: | 218 case DECLARE_FUNCTION: |
| 218 return parseDeclareFunction(); | 219 return parseDeclareFunction(); |
| 219 case INVOKE_CONSTRUCTOR: | 220 case INVOKE_CONSTRUCTOR: |
| 220 return parseInvokeConstructor(); | 221 return parseInvokeConstructor(); |
| 221 case INVOKE_CONTINUATION: | 222 case INVOKE_CONTINUATION: |
| 222 return parseInvokeContinuation(); | 223 return parseInvokeContinuation(false); |
| 224 case INVOKE_CONTINUATION_RECURSIVE: |
| 225 return parseInvokeContinuation(true); |
| 223 case INVOKE_METHOD: | 226 case INVOKE_METHOD: |
| 224 return parseInvokeMethod(); | 227 return parseInvokeMethod(); |
| 225 case INVOKE_STATIC: | 228 case INVOKE_STATIC: |
| 226 return parseInvokeStatic(); | 229 return parseInvokeStatic(); |
| 227 case INVOKE_METHOD_DIRECTLY: | 230 case INVOKE_METHOD_DIRECTLY: |
| 228 return parseInvokeMethodDirectly(); | 231 return parseInvokeMethodDirectly(); |
| 229 case LET_PRIM: | 232 case LET_PRIM: |
| 230 return parseLetPrim(); | 233 return parseLetPrim(); |
| 231 case LET_CONT: | 234 case LET_CONT: |
| 232 return parseLetCont(); | 235 return parseLetCont(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 List<Primitive> args = parsePrimitiveList(); | 380 List<Primitive> args = parsePrimitiveList(); |
| 378 | 381 |
| 379 Continuation cont = name2variable[tokens.read()]; | 382 Continuation cont = name2variable[tokens.read()]; |
| 380 assert(cont != null); | 383 assert(cont != null); |
| 381 | 384 |
| 382 tokens.consumeEnd(); | 385 tokens.consumeEnd(); |
| 383 Selector selector = dummySelector(constructorName, args.length); | 386 Selector selector = dummySelector(constructorName, args.length); |
| 384 return new InvokeConstructor(type, element, selector, cont, args); | 387 return new InvokeConstructor(type, element, selector, cont, args); |
| 385 } | 388 } |
| 386 | 389 |
| 387 /// (InvokeContinuation rec? name (args)) | 390 /// (InvokeContinuation name (args)) |
| 388 InvokeContinuation parseInvokeContinuation() { | 391 InvokeContinuation parseInvokeContinuation(bool recursive) { |
| 389 tokens.consumeStart(INVOKE_CONTINUATION); | 392 tokens.consumeStart(recursive |
| 390 String name = tokens.read(); | 393 ? INVOKE_CONTINUATION_RECURSIVE : INVOKE_CONTINUATION); |
| 391 bool isRecursive = name == "rec"; | 394 |
| 392 if (isRecursive) name = tokens.read(); | 395 Continuation cont = name2variable[tokens.read()]; |
| 393 | |
| 394 Continuation cont = name2variable[name]; | |
| 395 assert(cont != null); | 396 assert(cont != null); |
| 396 | 397 |
| 397 List<Primitive> args = parsePrimitiveList(); | 398 List<Primitive> args = parsePrimitiveList(); |
| 398 | 399 |
| 399 tokens.consumeEnd(); | 400 tokens.consumeEnd(); |
| 400 return new InvokeContinuation(cont, args, recursive: isRecursive); | 401 return new InvokeContinuation(cont, args, recursive: recursive); |
| 401 } | 402 } |
| 402 | 403 |
| 403 /// (InvokeMethod receiver method (args) cont) | 404 /// (InvokeMethod receiver method (args) cont) |
| 404 InvokeMethod parseInvokeMethod() { | 405 InvokeMethod parseInvokeMethod() { |
| 405 tokens.consumeStart(INVOKE_METHOD); | 406 tokens.consumeStart(INVOKE_METHOD); |
| 406 | 407 |
| 407 Definition receiver = name2variable[tokens.read()]; | 408 Definition receiver = name2variable[tokens.read()]; |
| 408 assert(receiver != null); | 409 assert(receiver != null); |
| 409 | 410 |
| 410 String methodName = tokens.read(); | 411 String methodName = tokens.read(); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 return new ReifyTypeVar(type); | 694 return new ReifyTypeVar(type); |
| 694 } | 695 } |
| 695 | 696 |
| 696 /// (This) | 697 /// (This) |
| 697 This parseThis() { | 698 This parseThis() { |
| 698 tokens.consumeStart(THIS); | 699 tokens.consumeStart(THIS); |
| 699 tokens.consumeEnd(); | 700 tokens.consumeEnd(); |
| 700 return new This(); | 701 return new This(); |
| 701 } | 702 } |
| 702 } | 703 } |
| OLD | NEW |