| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 final List<String> _list; | 80 final List<String> _list; |
| 81 int _index; // Current index into the list. | 81 int _index; // Current index into the list. |
| 82 | 82 |
| 83 Tokens(List<String> this._list) : _index = 0; | 83 Tokens(List<String> this._list) : _index = 0; |
| 84 | 84 |
| 85 String get current => _list[_index]; | 85 String get current => _list[_index]; |
| 86 String get next => _list[_index + 1]; | 86 String get next => _list[_index + 1]; |
| 87 | 87 |
| 88 String read([String expected]) { | 88 String read([String expected]) { |
| 89 if (expected != null) { | 89 if (expected != null) { |
| 90 if (current != expected) { | 90 assert(current == expected); |
| 91 print('expected "$expected", found "$current"'); | |
| 92 int start = _index - 15; | |
| 93 String dotdotdot = '... '; | |
| 94 if (start < 0) { | |
| 95 start = 0; | |
| 96 dotdotdot = ''; | |
| 97 } | |
| 98 print('${dotdotdot}${_list.sublist(start, _index + 1).join(' ')}'); | |
| 99 assert(current == expected); | |
| 100 } | |
| 101 } | 91 } |
| 102 return _list[_index++]; | 92 return _list[_index++]; |
| 103 } | 93 } |
| 104 | 94 |
| 105 /// Consumes the preamble to a new node, consisting of an opening parenthesis | 95 /// Consumes the preamble to a new node, consisting of an opening parenthesis |
| 106 /// and a tag. | 96 /// and a tag. |
| 107 void consumeStart([String tag]) { | 97 void consumeStart([String tag]) { |
| 108 read("("); | 98 read("("); |
| 109 if (tag != null) { | 99 if (tag != null) { |
| 110 read(tag); | 100 read(tag); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 FunctionDefinition parseFunctionDefinition() { | 261 FunctionDefinition parseFunctionDefinition() { |
| 272 tokens.consumeStart(FUNCTION_DEFINITION); | 262 tokens.consumeStart(FUNCTION_DEFINITION); |
| 273 | 263 |
| 274 // name | 264 // name |
| 275 Element element = new DummyElement(""); | 265 Element element = new DummyElement(""); |
| 276 if (tokens.current != '(') { | 266 if (tokens.current != '(') { |
| 277 // This is a named function. | 267 // This is a named function. |
| 278 element = new DummyElement(tokens.read()); | 268 element = new DummyElement(tokens.read()); |
| 279 } | 269 } |
| 280 | 270 |
| 281 // (this) or () | |
| 282 Definition thisParameter = null; | |
| 283 tokens.consumeStart(); | |
| 284 if (tokens.current != ')') { | |
| 285 String thisName = tokens.read(); | |
| 286 if (name2variable.containsKey(thisName)) { | |
| 287 thisParameter = name2variable[thisName]; | |
| 288 } else { | |
| 289 thisParameter = new Parameter(new DummyElement(thisName)); | |
| 290 name2variable[thisName] = thisParameter; | |
| 291 } | |
| 292 } | |
| 293 tokens.consumeEnd(); | |
| 294 | |
| 295 // (parameters) | 271 // (parameters) |
| 296 List<Definition> parameters = <Definition>[]; | 272 List<Definition> parameters = <Definition>[]; |
| 297 tokens.consumeStart(); | 273 tokens.consumeStart(); |
| 298 while (tokens.current != ")") { | 274 while (tokens.current != ")") { |
| 299 String paramName = tokens.read(); | 275 String paramName = tokens.read(); |
| 300 if (name2variable.containsKey(paramName)) { | 276 if (name2variable.containsKey(paramName)) { |
| 301 parameters.add(name2variable[paramName]); | 277 parameters.add(name2variable[paramName]); |
| 302 } else { | 278 } else { |
| 303 Parameter param = new Parameter(new DummyElement(paramName)); | 279 Parameter param = new Parameter(new DummyElement(paramName)); |
| 304 name2variable[paramName] = param; | 280 name2variable[paramName] = param; |
| 305 parameters.add(param); | 281 parameters.add(param); |
| 306 } | 282 } |
| 307 } | 283 } |
| 308 tokens.consumeEnd(); | 284 tokens.consumeEnd(); |
| 309 | 285 |
| 310 // continuation | 286 // continuation |
| 311 String contName = tokens.read("return"); | 287 String contName = tokens.read("return"); |
| 312 Continuation cont = name2variable[contName]; | 288 Continuation cont = name2variable[contName]; |
| 313 assert(cont != null); | 289 assert(cont != null); |
| 314 | 290 |
| 315 // body | 291 // body |
| 316 Expression body = parseExpression(); | 292 Expression body = parseExpression(); |
| 317 | 293 |
| 318 tokens.consumeEnd(); | 294 tokens.consumeEnd(); |
| 319 return new FunctionDefinition(element, thisParameter, parameters, | 295 return new FunctionDefinition(element, parameters, |
| 320 new RunnableBody(body, cont), null, null); | 296 new RunnableBody(body, cont), null, null); |
| 321 } | 297 } |
| 322 | 298 |
| 323 /// (IsTrue arg) | 299 /// (IsTrue arg) |
| 324 Condition parseCondition() { | 300 Condition parseCondition() { |
| 325 // Handles IsTrue only for now. | 301 // Handles IsTrue only for now. |
| 326 tokens.consumeStart(IS_TRUE); | 302 tokens.consumeStart(IS_TRUE); |
| 327 | 303 |
| 328 Definition value = name2variable[tokens.read()]; | 304 Definition value = name2variable[tokens.read()]; |
| 329 assert(value != null); | 305 assert(value != null); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 return new ReifyTypeVar(type); | 705 return new ReifyTypeVar(type); |
| 730 } | 706 } |
| 731 | 707 |
| 732 /// (This) | 708 /// (This) |
| 733 This parseThis() { | 709 This parseThis() { |
| 734 tokens.consumeStart(THIS); | 710 tokens.consumeStart(THIS); |
| 735 tokens.consumeEnd(); | 711 tokens.consumeEnd(); |
| 736 return new This(); | 712 return new This(); |
| 737 } | 713 } |
| 738 } | 714 } |
| OLD | NEW |