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

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

Issue 2699423002: Implement AstBuilder support for top level variables and function literals. (Closed)
Patch Set: Comment changes 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 849100a1c5cdf19c83674b42dcf77f815740d6b4..66bcb5986b30763f8bcb3b82f4c0154c18249009 100644
--- a/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
+++ b/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
@@ -313,6 +313,10 @@ class AstBuilder extends ScopeListener {
debugEvent("InitializedIdentifier");
AstNode node = pop();
VariableDeclaration variable;
+ // TODO(paulberry): This seems kludgy. It would be preferable if we
+ // could respond to a "handleNoVariableInitializer" event by converting a
+ // SimpleIdentifier into a VariableDeclaration, and then when this code was
+ // reached, node would always be a VariableDeclaration.
if (node is VariableDeclaration) {
variable = node;
} else if (node is SimpleIdentifier) {
@@ -626,6 +630,8 @@ class AstBuilder extends ScopeListener {
}
void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) {
+ // TODO(paulberry): set up scopes properly to resolve parameters and type
+ // variables.
debugEvent("TopLevelMethod");
FunctionBody body = _endFunctionBody();
FormalParameterList parameters = pop();
@@ -932,6 +938,50 @@ class AstBuilder extends ScopeListener {
toAnalyzerToken(ofKeyword), uri, name, toAnalyzerToken(semicolon)));
accumulateIdentifierComponents = false;
}
+
+ void endUnnamedFunction(Token token) {
+ // TODO(paulberry): set up scopes properly to resolve parameters and type
+ // variables. Note that this is tricky due to the handling of initializers
+ // in constructors, so the logic should be shared with BodyBuilder as much
+ // as possible.
+ debugEvent("UnnamedFunction");
+ var body = _endFunctionBody();
+ FormalParameterList parameters = pop();
+ TypeParameterList typeParameters = pop();
+ push(ast.functionExpression(typeParameters, parameters, body));
+ }
+
+ @override
+ void handleNoFieldInitializer(Token token) {
+ debugEvent("NoFieldInitializer");
+ SimpleIdentifier name = pop();
+ push(ast.variableDeclaration(name, null, null));
+ }
+
+ void endFieldInitializer(Token assignment) {
+ debugEvent("FieldInitializer");
+ Expression initializer = pop();
+ SimpleIdentifier name = pop();
+ push(ast.variableDeclaration(
+ name, toAnalyzerToken(assignment), initializer));
+ }
+
+ void endTopLevelFields(int count, Token beginToken, Token endToken) {
+ debugEvent("TopLevelFields");
+ List<VariableDeclaration> variables = popList(count);
+ TypeAnnotation type = pop();
+ // TODO(paulberry): the var/const/final keyword should be pointed to by
+ // beginToken.
+ var keyword = null; // TODO(paulberry)
+ var variableList = ast.variableDeclarationList(
+ null, null, toAnalyzerToken(keyword), type, variables);
+ var modifiers = pop();
+ assert(modifiers == null); // TODO(paulberry)
+ List<Annotation> metadata = pop();
+ Comment comment = null; // TODO(paulberry)
+ push(ast.topLevelVariableDeclaration(
+ comment, metadata, variableList, toAnalyzerToken(endToken)));
+ }
}
/// Data structure placed on the stack to represent a class body.

Powered by Google App Engine
This is Rietveld 408576698