OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library fasta.stack_listener; | 5 library fasta.stack_listener; |
6 | 6 |
7 import '../fasta_codes.dart' show FastaMessage; | 7 import '../fasta_codes.dart' show FastaMessage; |
8 | 8 |
9 import '../parser.dart' show Listener, MemberKind; | 9 import '../parser.dart' show Listener, MemberKind; |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 Object peek() => stack.last; | 79 Object peek() => stack.last; |
80 | 80 |
81 Object pop() => stack.pop(); | 81 Object pop() => stack.pop(); |
82 | 82 |
83 Object popIfNotNull(Object value) { | 83 Object popIfNotNull(Object value) { |
84 return value == null ? null : pop(); | 84 return value == null ? null : pop(); |
85 } | 85 } |
86 | 86 |
87 List popList(int n) { | 87 List popList(int n, [List list]) { |
88 if (n == 0) return null; | 88 if (n == 0) return null; |
89 return stack.popList(n); | 89 return stack.popList(n, list); |
90 } | 90 } |
91 | 91 |
92 void debugEvent(String name) { | 92 void debugEvent(String name) { |
93 // printEvent(name); | 93 // printEvent(name); |
94 } | 94 } |
95 | 95 |
96 void printEvent(String name) { | 96 void printEvent(String name) { |
97 for (Object o in stack.values) { | 97 for (Object o in stack.values) { |
98 String s = " $o"; | 98 String s = " $o"; |
99 int index = s.indexOf("\n"); | 99 int index = s.indexOf("\n"); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 Object pop() { | 294 Object pop() { |
295 assert(arrayLength > 0); | 295 assert(arrayLength > 0); |
296 final Object value = array[--arrayLength]; | 296 final Object value = array[--arrayLength]; |
297 array[arrayLength] = null; | 297 array[arrayLength] = null; |
298 return value is NullValue ? null : value; | 298 return value is NullValue ? null : value; |
299 } | 299 } |
300 | 300 |
301 List popList(int count) { | 301 List popList(int count, List list) { |
302 assert(arrayLength >= count); | 302 assert(arrayLength >= count); |
303 | 303 |
304 final table = array; | 304 final table = array; |
305 final length = arrayLength; | 305 final length = arrayLength; |
306 | 306 |
307 final tailList = new List.filled(count, null, growable: true); | 307 final tailList = list ?? new List.filled(count, null, growable: true); |
308 final startIndex = length - count; | 308 final startIndex = length - count; |
309 for (int i = 0; i < count; i++) { | 309 for (int i = 0; i < count; i++) { |
310 final value = table[startIndex + i]; | 310 final value = table[startIndex + i]; |
311 tailList[i] = value is NullValue ? null : value; | 311 tailList[i] = value is NullValue ? null : value; |
312 } | 312 } |
313 arrayLength -= count; | 313 arrayLength -= count; |
314 | 314 |
315 return tailList; | 315 return tailList; |
316 } | 316 } |
317 | 317 |
318 List get values { | 318 List get values { |
319 final List list = new List(arrayLength); | 319 final List list = new List(arrayLength); |
320 list.setRange(0, arrayLength, array); | 320 list.setRange(0, arrayLength, array); |
321 return list; | 321 return list; |
322 } | 322 } |
323 | 323 |
324 void _grow() { | 324 void _grow() { |
325 final List newTable = new List(array.length * 2); | 325 final List newTable = new List(array.length * 2); |
326 newTable.setRange(0, array.length, array, 0); | 326 newTable.setRange(0, array.length, array, 0); |
327 array = newTable; | 327 array = newTable; |
328 } | 328 } |
329 } | 329 } |
OLD | NEW |