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

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

Issue 2711813002: Add AstBuilder support for enum declarations. (Closed)
Patch Set: Created 3 years, 10 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/front_end/lib/src/fasta/analyzer/ast_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart b/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
index 97d19b158ff889bb032dbd180d632777e1ab3b75..33c595c6f0f95785295c955280cc73ba18443cf6 100644
--- a/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
+++ b/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
@@ -121,6 +121,13 @@ class AstBuilder extends ScopeListener {
} else {
push(identifier);
}
+ } else if (context == IdentifierContext.enumValueDeclaration) {
+ // TODO(paulberry): analyzer's ASTs allow for enumerated values to have
+ // metadata, but the spec doesn't permit it.
ahe 2017/02/23 16:47:25 I think we should accept it for error recovery.
+ List<Annotation> metadata;
+ // TODO(paulberry): capture doc comments. See dartbug.com/28851.
+ Comment comment = null;
+ push(ast.enumConstantDeclaration(comment, metadata, identifier));
} else {
if (context.isScopeReference) {
Builder builder = scope.lookup(name, token.charOffset, uri);
@@ -1078,6 +1085,28 @@ class AstBuilder extends ScopeListener {
toAnalyzerToken(endToken)));
}
+ void endEnum(Token enumKeyword, Token endBrace, int count) {
+ debugEvent("Enum");
+ List<EnumConstantDeclaration> constants = popList(count);
+ // TODO(paulberry,ahe): the parser should pass in the openBrace token.
+ var openBrace = enumKeyword.next.next as BeginGroupToken;
ahe 2017/02/23 16:47:25 I would recommend against casts as they have to be
+ // TODO(paulberry): what if the '}' is missing and the parser has performed
+ // error recovery?
ahe 2017/02/23 16:47:25 The scanner always provides a synthetic end token.
+ Token closeBrace = openBrace.endGroup;
+ SimpleIdentifier name = pop();
+ List<Annotation> metadata = pop();
+ // TODO(paulberry): capture doc comments. See dartbug.com/28851.
+ Comment comment = null;
+ push(ast.enumDeclaration(
+ comment,
+ metadata,
+ toAnalyzerToken(enumKeyword),
+ name,
+ toAnalyzerToken(openBrace),
+ constants,
+ toAnalyzerToken(closeBrace)));
+ }
+
/**
* Pop the modifiers list, if the list is empty return `null`, if the list
* has one item return it; otherwise return `null`.
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | pkg/front_end/lib/src/fasta/parser/listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698