Chromium Code Reviews| Index: pkg/front_end/lib/src/fasta/parser/dart_vm_native.dart |
| diff --git a/pkg/front_end/lib/src/fasta/parser/dart_vm_native.dart b/pkg/front_end/lib/src/fasta/parser/dart_vm_native.dart |
| index ce766765e524b363d5718ab497ceb47a39a638fe..f198db0ccca6e9f2f7d1c9f00f6943a458e6b2e2 100644 |
| --- a/pkg/front_end/lib/src/fasta/parser/dart_vm_native.dart |
| +++ b/pkg/front_end/lib/src/fasta/parser/dart_vm_native.dart |
| @@ -2,15 +2,26 @@ |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| -/// Implements support for Dart VM native method bodies of this form: |
| +/// Implements support for two variants of the native syntax extension. |
|
ahe
2017/07/05 13:29:40
I'd say that we should rename this file, but as I
Siggi Cherem (dart-lang)
2017/07/05 18:42:10
Done.
|
| /// |
| -/// native STRING |
| +/// * The Dart VM variant, where native method bodies have this form: |
| +/// |
| +/// methodDeclaration() native STRING; |
| +/// |
| +/// * The Dart2js and DDC variant, where native method bodies have this form: |
| +/// |
| +/// methodDeclaration() native; |
| /// |
| /// This support is kept separate from parser.dart as this isn't specified in |
| /// the Dart Language Specification, also we hope to remove this syntax long |
| -/// term and replace it with annotations as in `dart2js`. |
| +/// term and replace it with annotations and external declarations. |
| library fasta.parser.dart_vm_native; |
| +/// CODE REVIEW COMMENT: I was going to also rename this file to native.dart or |
| +/// native_support.dart. Peter - if that will conflict with changes you were |
| +/// planning to do in this area, I can avoid it, if not I'll do it on the next |
| +/// patch set. |
|
ahe
2017/07/05 13:29:39
This comment was 15 lines to late for my thought p
Siggi Cherem (dart-lang)
2017/07/05 18:42:10
:)
|
| + |
| import '../../scanner/token.dart' show Token; |
| import '../scanner/token_constants.dart' show STRING_TOKEN; |
| @@ -19,20 +30,26 @@ import '../util/link.dart' show Link; |
| import 'parser.dart' show optional; |
| -/// When parsing a Dart VM library file, we may encounter a native clause |
| -/// instead of a function body. This method skips such a clause. |
| +import '../quote.dart' show unescapeString; |
| + |
| +/// When parsing a library file, we may encounter a native clause |
| +/// instead of a function body. This method skips such a clause. The |
| +/// [expectString] argument is used to choose which variant of the native clause |
| +/// we expect to parse. |
| /// |
| /// This method is designed to be called when encountering |
| /// [ErrorKind.ExpectedBlockToSkip] in [Listener.handleUnrecoverableError]. |
| -Token skipNativeClause(Token token) { |
| +Token skipNativeClause(Token token, bool expectString) { |
| if (!optional("native", token)) return null; |
| - token = token.next; |
| - if (token.kind != STRING_TOKEN) return null; |
| + if (expectString) { |
| + token = token.next; |
| + if (token.kind != STRING_TOKEN) return null; |
| + } |
| if (!optional(";", token.next)) return null; |
| return token; |
| } |
| -/// When parsing a Dart VM library file, we may encounter native getters like |
| +/// When parsing a library file, we may encounter native getters like |
| /// |
| /// int get length native "List_getLength"; |
| /// |
| @@ -40,17 +57,35 @@ Token skipNativeClause(Token token) { |
| /// |
| /// [";", '"List_getLength"', "native", "length", "get"] |
| /// |
| -/// We need to remove '"List_getLength"' and "native" from that list. |
| +/// Similarly if [expectString] is false, we expect a getter like: |
| +/// |
| +/// int get length native; |
| /// |
| -/// This method designed to be called from [Listener.handleMemberName]. |
| -Link<Token> removeNativeClause(Link<Token> identifiers) { |
| +/// And [identifiers] being |
| +/// |
| +/// [";", "native", "length", "get"] |
| +/// |
| +/// This method returns a new list where '"List_getLength"' and "native" are |
| +/// removed. |
| +/// |
| +/// This method is designed to be called from [Listener.handleMemberName]. |
| +Link<Token> removeNativeClause(Link<Token> identifiers, bool expectString) { |
| Link<Token> result = identifiers.tail; |
| if (result.isEmpty) return identifiers; |
| - if (result.head.kind != STRING_TOKEN) return identifiers; |
| - result = result.tail; |
| + if (expectString) { |
| + if (result.head.kind != STRING_TOKEN) return identifiers; |
| + result = result.tail; |
| + } |
| if (result.isEmpty) return identifiers; |
| if (optional('native', result.head)) { |
| return result.tail.prepend(identifiers.head); |
| } |
| return identifiers; |
| } |
| + |
| +/// When the parser encounters a native clause and expects a string (like in VM |
| +/// and flutter patch files), this method extracts the native name in that |
| +/// string. |
| +String extractNativeMethodName(Token token) { |
| + return unescapeString(token.next.lexeme); |
| +} |