Chromium Code Reviews| 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 7580511ad0e7d1d44dadacb5129acc57205adbaa..359712b9e4f4b056a4bfa63dbc33e9cd08088375 100644 |
| --- a/pkg/analyzer/lib/src/fasta/ast_builder.dart |
| +++ b/pkg/analyzer/lib/src/fasta/ast_builder.dart |
| @@ -31,6 +31,10 @@ import 'package:front_end/src/fasta/source/scope_listener.dart' |
| import 'package:analyzer/src/dart/error/syntactic_errors.dart'; |
| class AstBuilder extends ScopeListener { |
| + /// The native clause in class, method, and function declarations |
| + /// is being replaced by the @native(...) annotation. |
| + static bool isNativeClauseAllowed = true; |
|
ahe
2017/08/21 12:04:10
I think this should only be true if:
* The curren
danrubel
2017/08/22 01:35:27
Good point. Cleaned up and added TODO per discussi
|
| + |
| final AstFactory ast = standard.astFactory; |
| final ErrorReporter errorReporter; |
| @@ -1284,9 +1288,14 @@ class AstBuilder extends ScopeListener { |
| Token classKeyword, |
| Token extendsKeyword, |
| Token implementsKeyword, |
| + Token nativeToken, |
| Token endToken) { |
| debugEvent("ClassDeclaration"); |
| _ClassBody body = pop(); |
| + NativeClause nativeClause; |
| + if (nativeToken?.next?.type == TokenType.STRING) { |
|
ahe
2017/08/21 12:04:10
This feels like implementing parser logic in the l
danrubel
2017/08/22 01:35:27
I was trying for the simplest thing given that thi
|
| + nativeClause = ast.nativeClause(nativeToken, pop()); |
| + } |
| ImplementsClause implementsClause; |
| if (implementsKeyword != null) { |
| List<TypeName> interfaces = popList(interfacesCount); |
| @@ -1314,7 +1323,7 @@ class AstBuilder extends ScopeListener { |
| Token abstractKeyword = modifiers?.abstractKeyword; |
| List<Annotation> metadata = pop(); |
| Comment comment = pop(); |
| - declarations.add(ast.classDeclaration( |
| + ClassDeclaration classDeclaration = ast.classDeclaration( |
| comment, |
| metadata, |
| abstractKeyword, |
| @@ -1326,7 +1335,9 @@ class AstBuilder extends ScopeListener { |
| implementsClause, |
| body.beginToken, |
| body.members, |
| - body.endToken)); |
| + body.endToken); |
| + classDeclaration.nativeClause = nativeClause; |
| + declarations.add(classDeclaration); |
| } |
| @override |
| @@ -1891,6 +1902,14 @@ class AstBuilder extends ScopeListener { |
| errorReporter?.reportErrorForOffset( |
| ParserErrorCode.EXPECTED_TYPE_NAME, charOffset, 1); |
| return; |
| + case "NATIVE_CLAUSE_SHOULD_BE_ANNOTATION": |
| + if (!isNativeClauseAllowed) { |
| + errorReporter?.reportErrorForOffset( |
| + ParserErrorCode.NATIVE_CLAUSE_SHOULD_BE_ANNOTATION, |
| + charOffset, |
| + 1); |
| + } |
| + return; |
| case "EXPECTED_STRING_LITERAL": |
| errorReporter?.reportErrorForOffset( |
| ParserErrorCode.EXPECTED_STRING_LITERAL, charOffset, 1); |