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

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

Issue 2996163002: support class native clause (Closed)
Patch Set: add new fasta native clause error code 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 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);

Powered by Google App Engine
This is Rietveld 408576698