| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 List<Primitive> prims = <Primitive>[]; | 247 List<Primitive> prims = <Primitive>[]; |
| 248 while (tokens.current != ")") { | 248 while (tokens.current != ")") { |
| 249 Primitive prim = name2variable[tokens.read()]; | 249 Primitive prim = name2variable[tokens.read()]; |
| 250 assert(prim != null); | 250 assert(prim != null); |
| 251 prims.add(prim); | 251 prims.add(prim); |
| 252 } | 252 } |
| 253 tokens.consumeEnd(); | 253 tokens.consumeEnd(); |
| 254 return prims; | 254 return prims; |
| 255 } | 255 } |
| 256 | 256 |
| 257 /// (FunctionDefinition name (args cont) body) | 257 /// (FunctionDefinition name (parameters) continuation body) |
| 258 FunctionDefinition parseFunctionDefinition() { | 258 FunctionDefinition parseFunctionDefinition() { |
| 259 tokens.consumeStart(FUNCTION_DEFINITION); | 259 tokens.consumeStart(FUNCTION_DEFINITION); |
| 260 | 260 |
| 261 // name | 261 // name |
| 262 Element element = new DummyElement(""); | 262 Element element = new DummyElement(""); |
| 263 if (tokens.current != '(') { | 263 if (tokens.current != '(') { |
| 264 // This is a named function. | 264 // This is a named function. |
| 265 element = new DummyElement(tokens.read()); | 265 element = new DummyElement(tokens.read()); |
| 266 } | 266 } |
| 267 | 267 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 278 parameters.add(param); | 278 parameters.add(param); |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 tokens.consumeEnd(); | 281 tokens.consumeEnd(); |
| 282 | 282 |
| 283 // continuation | 283 // continuation |
| 284 String contName = tokens.read("return"); | 284 String contName = tokens.read("return"); |
| 285 Continuation cont = name2variable[contName]; | 285 Continuation cont = name2variable[contName]; |
| 286 assert(cont != null); | 286 assert(cont != null); |
| 287 | 287 |
| 288 // [closure-variables] | |
| 289 List<ClosureVariable> closureVariables = <ClosureVariable>[]; | |
| 290 tokens.consumeStart(); | |
| 291 while (tokens.current != ')') { | |
| 292 String varName = tokens.read(); | |
| 293 ClosureVariable variable = | |
| 294 new ClosureVariable(element, new DummyElement(varName)); | |
| 295 closureVariables.add(variable); | |
| 296 name2variable[varName] = variable; | |
| 297 } | |
| 298 tokens.consumeEnd(); | |
| 299 | |
| 300 // body | 288 // body |
| 301 Expression body = parseExpression(); | 289 Expression body = parseExpression(); |
| 302 | 290 |
| 303 tokens.consumeEnd(); | 291 tokens.consumeEnd(); |
| 304 return new FunctionDefinition(element, parameters, | 292 return new FunctionDefinition(element, parameters, |
| 305 new RunnableBody(body, cont), null, null, | 293 new RunnableBody(body, cont), null, null); |
| 306 closureVariables); | |
| 307 } | 294 } |
| 308 | 295 |
| 309 /// (IsTrue arg) | 296 /// (IsTrue arg) |
| 310 Condition parseCondition() { | 297 Condition parseCondition() { |
| 311 // Handles IsTrue only for now. | 298 // Handles IsTrue only for now. |
| 312 tokens.consumeStart(IS_TRUE); | 299 tokens.consumeStart(IS_TRUE); |
| 313 | 300 |
| 314 Definition value = name2variable[tokens.read()]; | 301 Definition value = name2variable[tokens.read()]; |
| 315 assert(value != null); | 302 assert(value != null); |
| 316 | 303 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 342 | 329 |
| 343 tokens.consumeEnd(); | 330 tokens.consumeEnd(); |
| 344 return new ConcatenateStrings(cont, args); | 331 return new ConcatenateStrings(cont, args); |
| 345 } | 332 } |
| 346 | 333 |
| 347 /// (DeclareFunction name = function in body) | 334 /// (DeclareFunction name = function in body) |
| 348 DeclareFunction parseDeclareFunction() { | 335 DeclareFunction parseDeclareFunction() { |
| 349 tokens.consumeStart(DECLARE_FUNCTION); | 336 tokens.consumeStart(DECLARE_FUNCTION); |
| 350 | 337 |
| 351 // name = | 338 // name = |
| 352 ClosureVariable local = name2variable[tokens.read()]; | 339 ClosureVariable local = getClosureVariable(tokens.read()); |
| 353 tokens.read("="); | 340 tokens.read("="); |
| 354 | 341 |
| 355 // function in | 342 // function in |
| 356 FunctionDefinition def = parseFunctionDefinition(); | 343 FunctionDefinition def = parseFunctionDefinition(); |
| 357 tokens.read("in"); | 344 tokens.read("in"); |
| 358 | 345 |
| 359 // body | 346 // body |
| 360 Expression body = parseExpression(); | 347 Expression body = parseExpression(); |
| 361 | 348 |
| 362 tokens.consumeEnd(); | 349 tokens.consumeEnd(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 383 Selector selector = dummySelector(constructorName, args.length); | 370 Selector selector = dummySelector(constructorName, args.length); |
| 384 return new InvokeConstructor(type, element, selector, cont, args); | 371 return new InvokeConstructor(type, element, selector, cont, args); |
| 385 } | 372 } |
| 386 | 373 |
| 387 /// (InvokeContinuation rec? name (args)) | 374 /// (InvokeContinuation rec? name (args)) |
| 388 InvokeContinuation parseInvokeContinuation() { | 375 InvokeContinuation parseInvokeContinuation() { |
| 389 tokens.consumeStart(INVOKE_CONTINUATION); | 376 tokens.consumeStart(INVOKE_CONTINUATION); |
| 390 String name = tokens.read(); | 377 String name = tokens.read(); |
| 391 bool isRecursive = name == "rec"; | 378 bool isRecursive = name == "rec"; |
| 392 if (isRecursive) name = tokens.read(); | 379 if (isRecursive) name = tokens.read(); |
| 393 | 380 |
| 394 Continuation cont = name2variable[name]; | 381 Continuation cont = name2variable[name]; |
| 395 assert(cont != null); | 382 assert(cont != null); |
| 396 | 383 |
| 397 List<Primitive> args = parsePrimitiveList(); | 384 List<Primitive> args = parsePrimitiveList(); |
| 398 | 385 |
| 399 tokens.consumeEnd(); | 386 tokens.consumeEnd(); |
| 400 return new InvokeContinuation(cont, args, recursive: isRecursive); | 387 return new InvokeContinuation(cont, args, recursive: isRecursive); |
| 401 } | 388 } |
| 402 | 389 |
| 403 /// (InvokeMethod receiver method (args) cont) | 390 /// (InvokeMethod receiver method (args) cont) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 Expression body = parseExpression(); | 487 Expression body = parseExpression(); |
| 501 tokens.consumeEnd(); | 488 tokens.consumeEnd(); |
| 502 | 489 |
| 503 return new LetCont.many(continuations, body); | 490 return new LetCont.many(continuations, body); |
| 504 } | 491 } |
| 505 | 492 |
| 506 /// (SetClosureVariable name value body) | 493 /// (SetClosureVariable name value body) |
| 507 SetClosureVariable parseSetClosureVariable() { | 494 SetClosureVariable parseSetClosureVariable() { |
| 508 tokens.consumeStart(SET_CLOSURE_VARIABLE); | 495 tokens.consumeStart(SET_CLOSURE_VARIABLE); |
| 509 | 496 |
| 510 ClosureVariable local = name2variable[tokens.read()]; | 497 String name = tokens.read(); |
| 498 ClosureVariable local = getClosureVariable(name); |
| 511 Primitive value = name2variable[tokens.read()]; | 499 Primitive value = name2variable[tokens.read()]; |
| 512 assert(value != null); | 500 assert(value != null); |
| 513 | 501 |
| 514 Expression body = parseExpression(); | 502 Expression body = parseExpression(); |
| 515 | 503 |
| 516 tokens.consumeEnd(); | 504 tokens.consumeEnd(); |
| 517 return new SetClosureVariable(local, value) | 505 return new SetClosureVariable(local, value) |
| 518 ..plug(body); | 506 ..plug(body); |
| 519 } | 507 } |
| 520 | 508 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 } | 630 } |
| 643 | 631 |
| 644 /// (CreateFunction (definition)) | 632 /// (CreateFunction (definition)) |
| 645 CreateFunction parseCreateFunction() { | 633 CreateFunction parseCreateFunction() { |
| 646 tokens.consumeStart(CREATE_FUNCTION); | 634 tokens.consumeStart(CREATE_FUNCTION); |
| 647 FunctionDefinition def = parseFunctionDefinition(); | 635 FunctionDefinition def = parseFunctionDefinition(); |
| 648 tokens.consumeEnd(); | 636 tokens.consumeEnd(); |
| 649 return new CreateFunction(def); | 637 return new CreateFunction(def); |
| 650 } | 638 } |
| 651 | 639 |
| 640 ClosureVariable getClosureVariable(String name) { |
| 641 if (!name2variable.containsKey(name)) { |
| 642 ClosureVariable variable = |
| 643 new ClosureVariable(new DummyElement(""), new DummyElement(name)); |
| 644 name2variable[name] = variable; |
| 645 } |
| 646 return name2variable[name]; |
| 647 } |
| 648 |
| 652 /// (GetClosureVariable name) | 649 /// (GetClosureVariable name) |
| 653 GetClosureVariable parseGetClosureVariable() { | 650 GetClosureVariable parseGetClosureVariable() { |
| 654 tokens.consumeStart(GET_CLOSURE_VARIABLE); | 651 tokens.consumeStart(GET_CLOSURE_VARIABLE); |
| 655 | 652 |
| 656 ClosureVariable local = name2variable[tokens.read()]; | 653 String name = tokens.read(); |
| 654 ClosureVariable local = getClosureVariable(name); |
| 657 tokens.consumeEnd(); | 655 tokens.consumeEnd(); |
| 658 | 656 |
| 659 return new GetClosureVariable(local); | 657 return new GetClosureVariable(local); |
| 660 } | 658 } |
| 661 | 659 |
| 662 /// (LiteralList (values)) | 660 /// (LiteralList (values)) |
| 663 LiteralList parseLiteralList() { | 661 LiteralList parseLiteralList() { |
| 664 tokens.consumeStart(LITERAL_LIST); | 662 tokens.consumeStart(LITERAL_LIST); |
| 665 List<Primitive> values = parsePrimitiveList(); | 663 List<Primitive> values = parsePrimitiveList(); |
| 666 tokens.consumeEnd(); | 664 tokens.consumeEnd(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 693 return new ReifyTypeVar(type); | 691 return new ReifyTypeVar(type); |
| 694 } | 692 } |
| 695 | 693 |
| 696 /// (This) | 694 /// (This) |
| 697 This parseThis() { | 695 This parseThis() { |
| 698 tokens.consumeStart(THIS); | 696 tokens.consumeStart(THIS); |
| 699 tokens.consumeEnd(); | 697 tokens.consumeEnd(); |
| 700 return new This(); | 698 return new This(); |
| 701 } | 699 } |
| 702 } | 700 } |
| OLD | NEW |