Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: tests/compiler/dart2js/backend_dart/sexpr_unstringifier.dart

Issue 1021813002: Redo "Use an explicit 'this' parameter instead of 'This' nodes." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 assert(current == expected); 90 if (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 }
91 } 101 }
92 return _list[_index++]; 102 return _list[_index++];
93 } 103 }
94 104
95 /// Consumes the preamble to a new node, consisting of an opening parenthesis 105 /// Consumes the preamble to a new node, consisting of an opening parenthesis
96 /// and a tag. 106 /// and a tag.
97 void consumeStart([String tag]) { 107 void consumeStart([String tag]) {
98 read("("); 108 read("(");
99 if (tag != null) { 109 if (tag != null) {
100 read(tag); 110 read(tag);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 FunctionDefinition parseFunctionDefinition() { 271 FunctionDefinition parseFunctionDefinition() {
262 tokens.consumeStart(FUNCTION_DEFINITION); 272 tokens.consumeStart(FUNCTION_DEFINITION);
263 273
264 // name 274 // name
265 Element element = new DummyElement(""); 275 Element element = new DummyElement("");
266 if (tokens.current != '(') { 276 if (tokens.current != '(') {
267 // This is a named function. 277 // This is a named function.
268 element = new DummyElement(tokens.read()); 278 element = new DummyElement(tokens.read());
269 } 279 }
270 280
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
271 // (parameters) 295 // (parameters)
272 List<Definition> parameters = <Definition>[]; 296 List<Definition> parameters = <Definition>[];
273 tokens.consumeStart(); 297 tokens.consumeStart();
274 while (tokens.current != ")") { 298 while (tokens.current != ")") {
275 String paramName = tokens.read(); 299 String paramName = tokens.read();
276 if (name2variable.containsKey(paramName)) { 300 if (name2variable.containsKey(paramName)) {
277 parameters.add(name2variable[paramName]); 301 parameters.add(name2variable[paramName]);
278 } else { 302 } else {
279 Parameter param = new Parameter(new DummyElement(paramName)); 303 Parameter param = new Parameter(new DummyElement(paramName));
280 name2variable[paramName] = param; 304 name2variable[paramName] = param;
281 parameters.add(param); 305 parameters.add(param);
282 } 306 }
283 } 307 }
284 tokens.consumeEnd(); 308 tokens.consumeEnd();
285 309
286 // continuation 310 // continuation
287 String contName = tokens.read("return"); 311 String contName = tokens.read("return");
288 Continuation cont = name2variable[contName]; 312 Continuation cont = name2variable[contName];
289 assert(cont != null); 313 assert(cont != null);
290 314
291 // body 315 // body
292 Expression body = parseExpression(); 316 Expression body = parseExpression();
293 317
294 tokens.consumeEnd(); 318 tokens.consumeEnd();
295 return new FunctionDefinition(element, parameters, 319 return new FunctionDefinition(element, thisParameter, parameters,
296 new RunnableBody(body, cont), null, null); 320 new RunnableBody(body, cont), null, null);
297 } 321 }
298 322
299 /// (IsTrue arg) 323 /// (IsTrue arg)
300 Condition parseCondition() { 324 Condition parseCondition() {
301 // Handles IsTrue only for now. 325 // Handles IsTrue only for now.
302 tokens.consumeStart(IS_TRUE); 326 tokens.consumeStart(IS_TRUE);
303 327
304 Definition value = name2variable[tokens.read()]; 328 Definition value = name2variable[tokens.read()];
305 assert(value != null); 329 assert(value != null);
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 return new ReifyTypeVar(type); 729 return new ReifyTypeVar(type);
706 } 730 }
707 731
708 /// (This) 732 /// (This)
709 This parseThis() { 733 This parseThis() {
710 tokens.consumeStart(THIS); 734 tokens.consumeStart(THIS);
711 tokens.consumeEnd(); 735 tokens.consumeEnd();
712 return new This(); 736 return new This();
713 } 737 }
714 } 738 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/backend_dart/sexpr_test.dart ('k') | tests/language/parameter_initializer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698