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

Unified Diff: pkg/analyzer/lib/src/fasta/ast_builder.dart

Issue 3003263002: add support for native methods in class
Patch Set: update listeners Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/fasta/ast_builder.dart
diff --git a/pkg/analyzer/lib/src/fasta/ast_builder.dart b/pkg/analyzer/lib/src/fasta/ast_builder.dart
index 6425a7ebfb9c4b0af48f8e45f6df0836d6273029..aa47114daea0367ba5b2f4287365f18e80705062 100644
--- a/pkg/analyzer/lib/src/fasta/ast_builder.dart
+++ b/pkg/analyzer/lib/src/fasta/ast_builder.dart
@@ -1290,7 +1290,7 @@ class AstBuilder extends ScopeListener {
@override
void handleNativeClause(Token nativeToken, bool hasName) {
- push(ast.nativeClause(nativeToken, hasName ? pop() : null));
+ if (!hasName) push(NullValue.StringLiteral);
}
@override
@@ -1304,7 +1304,12 @@ class AstBuilder extends ScopeListener {
Token endToken) {
debugEvent("ClassDeclaration");
_ClassBody body = pop();
- NativeClause nativeClause = nativeToken != null ? pop() : null;
+ NativeClause nativeClause;
+ if (nativeToken != null) {
+ var nativeName = pop();
+ nativeClause = ast.nativeClause(nativeToken,
+ nativeName == NullValue.StringLiteral ? null : nativeName);
+ }
ImplementsClause implementsClause;
if (implementsKeyword != null) {
List<TypeName> interfaces = popList(interfacesCount);
@@ -1607,9 +1612,22 @@ class AstBuilder extends ScopeListener {
}
@override
- void endMethod(Token getOrSet, Token beginToken, Token endToken) {
+ void endMethod(
+ Token getOrSet, Token beginToken, Token nativeToken, Token endToken) {
debugEvent("Method");
FunctionBody body = pop();
+ if (nativeToken != null) {
+ var nativeName = pop();
+ if (nativeName == NullValue.StringLiteral) {
+ nativeName = null;
+ }
+ if (body is EmptyFunctionBody) {
+ body = ast.nativeFunctionBody(nativeToken, nativeName, body.endToken);
+ } else {
+ // TODO(danrubel): Report error if native clause is used with
+ // non-empty function body.
+ }
+ }
ConstructorName redirectedConstructor = null; // TODO(paulberry)
List<ConstructorInitializer> initializers = pop() ?? const [];
Token separator = pop();
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_fasta_listener.dart » ('j') | pkg/front_end/lib/src/fasta/parser/parser.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698