Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
|
ahe
2017/02/03 17:26:42
It's 2017.
ahe
2017/02/06 10:17:54
Done.
| |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
|
ahe
2017/02/03 17:26:42
Add note to listener events about these helper met
ahe
2017/02/06 10:17:54
Done.
| |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /// Implements support for Dart VM native method bodies on this form: | |
| 6 /// | |
| 7 /// native STRING | |
|
Siggi Cherem (dart-lang)
2017/02/03 17:18:52
consider adding one more sentence saying that this
ahe
2017/02/06 10:17:54
Done.
| |
| 8 library fasta.parser.dart_vm_native; | |
| 9 | |
| 10 import '../scanner/token.dart' show | |
| 11 Token; | |
| 12 | |
| 13 import '../scanner/token_constants.dart' show | |
| 14 STRING_TOKEN; | |
| 15 | |
| 16 import '../util/link.dart' show | |
| 17 Link; | |
| 18 | |
| 19 import 'parser.dart' show | |
| 20 optional; | |
| 21 | |
| 22 /// When parsing a Dart VM library file, we may encounter a native clause | |
| 23 /// instead of a function body. This method skips such a clause. | |
| 24 /// | |
| 25 /// This method is designed to be called when encountering | |
| 26 /// [ErrorKind.ExpectedBlockToSkip] in [Listener.handleUnrecoverableError]. | |
| 27 Token skipNativeClause(Token token) { | |
| 28 if (!optional("native", token)) return null; | |
| 29 token = token.next; | |
| 30 if (token.kind != STRING_TOKEN) return null; | |
| 31 token = token.next; | |
| 32 if (!optional(";", token)) return null; | |
| 33 return token; | |
| 34 } | |
| 35 | |
| 36 /// When parsing a Dart VM library file, we may encounter native getters like | |
| 37 /// | |
| 38 /// int get length native "List_getLength"; | |
| 39 /// | |
| 40 /// This will result in [identifiers] being | |
| 41 /// | |
| 42 /// [";", '"List_getLength"', "native", "length", "get"] | |
| 43 /// | |
| 44 /// We need to remove '"List_getLength"' and "native" from that list. | |
| 45 /// | |
| 46 /// This method designed to be called from [Listener.handleMemberName]. | |
| 47 Link<Token> removeNativeClause(Link<Token> identifiers) { | |
| 48 Link<Token> result = identifiers.tail; | |
| 49 if (result.head.kind != STRING_TOKEN) return identifiers; | |
| 50 result = result.tail; | |
| 51 if (result.isEmpty) return identifiers; | |
| 52 if (optional('native', result.head)) { | |
| 53 return result.tail.prepend(identifiers.head); | |
| 54 } | |
| 55 return identifiers; | |
| 56 } | |
| OLD | NEW |