| 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 a0b092ec1f34067018540972df3d2e5e6867af06..f61af91664debeb47f8a0346e893212c739d5f14 100644
|
| --- a/pkg/analyzer/lib/src/fasta/ast_builder.dart
|
| +++ b/pkg/analyzer/lib/src/fasta/ast_builder.dart
|
| @@ -37,6 +37,10 @@ class AstBuilder extends ScopeListener {
|
| final KernelLibraryBuilder library;
|
| final Builder member;
|
|
|
| + ScriptTag scriptTag;
|
| + final List<Directive> directives = <Directive>[];
|
| + final List<CompilationUnitMember> declarations = <CompilationUnitMember>[];
|
| +
|
| @override
|
| final Uri uri;
|
|
|
| @@ -170,7 +174,7 @@ class AstBuilder extends ScopeListener {
|
|
|
| void handleScript(Token token) {
|
| debugEvent("Script");
|
| - push(ast.scriptTag(token));
|
| + scriptTag = ast.scriptTag(token);
|
| }
|
|
|
| void handleStringJuxtaposition(int literalCount) {
|
| @@ -1108,7 +1112,7 @@ class AstBuilder extends ScopeListener {
|
| Token externalKeyword = modifiers?.externalKeyword;
|
| List<Annotation> metadata = pop();
|
| Comment comment = pop();
|
| - push(ast.functionDeclaration(
|
| + declarations.add(ast.functionDeclaration(
|
| comment,
|
| metadata,
|
| externalKeyword,
|
| @@ -1130,7 +1134,6 @@ class AstBuilder extends ScopeListener {
|
| // TODO(danrubel): consider creating a AST node
|
| // representing the invalid declaration to better support code completion,
|
| // quick fixes, etc, rather than discarding the metadata and token
|
| - push(NullValue.InvalidTopLevelDeclaration);
|
| }
|
|
|
| @override
|
| @@ -1141,31 +1144,8 @@ class AstBuilder extends ScopeListener {
|
| @override
|
| void endCompilationUnit(int count, Token endToken) {
|
| debugEvent("CompilationUnit");
|
| - List<Object> elements = popList(count);
|
| Token beginToken = pop();
|
| -
|
| - ScriptTag scriptTag = null;
|
| - var directives = <Directive>[];
|
| - var declarations = <CompilationUnitMember>[];
|
| - if (elements != null) {
|
| - for (AstNode node in elements) {
|
| - if (node is ScriptTag) {
|
| - scriptTag = node;
|
| - } else if (node is Directive) {
|
| - directives.add(node);
|
| - } else if (node is CompilationUnitMember) {
|
| - declarations.add(node);
|
| - } else if (node == NullValue.InvalidTopLevelDeclaration) {
|
| - // TODO(danrubel): consider creating a AST node
|
| - // representing the invalid declaration
|
| - // to better support code completion, quick fixes, etc,
|
| - // rather than discarding the metadata and token
|
| - } else {
|
| - unhandled(
|
| - "${node.runtimeType}", "compilation unit", node?.offset, uri);
|
| - }
|
| - }
|
| - }
|
| + checkEmpty(endToken.charOffset);
|
|
|
| push(ast.compilationUnit(
|
| beginToken, scriptTag, directives, declarations, endToken));
|
| @@ -1182,7 +1162,7 @@ class AstBuilder extends ScopeListener {
|
| List<Annotation> metadata = pop();
|
| assert(metadata == null); // TODO(paulberry): fix.
|
| Comment comment = pop();
|
| - push(ast.importDirective(
|
| + directives.add(ast.importDirective(
|
| comment,
|
| metadata,
|
| importKeyword,
|
| @@ -1203,7 +1183,7 @@ class AstBuilder extends ScopeListener {
|
| List<Annotation> metadata = pop();
|
| assert(metadata == null);
|
| Comment comment = pop();
|
| - push(ast.exportDirective(comment, metadata, exportKeyword, uri,
|
| + directives.add(ast.exportDirective(comment, metadata, exportKeyword, uri,
|
| configurations, combinators, semicolon));
|
| }
|
|
|
| @@ -1334,7 +1314,7 @@ class AstBuilder extends ScopeListener {
|
| Token abstractKeyword = modifiers?.abstractKeyword;
|
| List<Annotation> metadata = pop();
|
| Comment comment = pop();
|
| - push(ast.classDeclaration(
|
| + declarations.add(ast.classDeclaration(
|
| comment,
|
| metadata,
|
| abstractKeyword,
|
| @@ -1377,7 +1357,7 @@ class AstBuilder extends ScopeListener {
|
| Token abstractKeyword = modifiers?.abstractKeyword;
|
| List<Annotation> metadata = pop();
|
| Comment comment = pop();
|
| - push(ast.classTypeAlias(
|
| + declarations.add(ast.classTypeAlias(
|
| comment,
|
| metadata,
|
| classKeyword,
|
| @@ -1406,7 +1386,7 @@ class AstBuilder extends ScopeListener {
|
| var name = ast.libraryIdentifier(libraryName);
|
| List<Annotation> metadata = pop();
|
| Comment comment = pop();
|
| - push(ast.libraryDirective(
|
| + directives.add(ast.libraryDirective(
|
| comment, metadata, libraryKeyword, name, semicolon));
|
| }
|
|
|
| @@ -1434,7 +1414,8 @@ class AstBuilder extends ScopeListener {
|
| StringLiteral uri = pop();
|
| List<Annotation> metadata = pop();
|
| Comment comment = pop();
|
| - push(ast.partDirective(comment, metadata, partKeyword, uri, semicolon));
|
| + directives
|
| + .add(ast.partDirective(comment, metadata, partKeyword, uri, semicolon));
|
| }
|
|
|
| @override
|
| @@ -1448,7 +1429,7 @@ class AstBuilder extends ScopeListener {
|
| var ofKeyword = partKeyword.next;
|
| List<Annotation> metadata = pop();
|
| Comment comment = pop();
|
| - push(ast.partOfDirective(
|
| + directives.add(ast.partOfDirective(
|
| comment, metadata, partKeyword, ofKeyword, uri, name, semicolon));
|
| }
|
|
|
| @@ -1575,7 +1556,7 @@ class AstBuilder extends ScopeListener {
|
| ast.variableDeclarationList(null, null, keyword, type, variables);
|
| List<Annotation> metadata = pop();
|
| Comment comment = pop();
|
| - push(ast.topLevelVariableDeclaration(
|
| + declarations.add(ast.topLevelVariableDeclaration(
|
| comment, metadata, variableList, endToken));
|
| }
|
|
|
| @@ -1689,8 +1670,8 @@ class AstBuilder extends ScopeListener {
|
| TypeAnnotation returnType = pop();
|
| List<Annotation> metadata = pop();
|
| Comment comment = pop();
|
| - push(ast.functionTypeAlias(comment, metadata, typedefKeyword, returnType,
|
| - name, typeParameters, parameters, endToken));
|
| + declarations.add(ast.functionTypeAlias(comment, metadata, typedefKeyword,
|
| + returnType, name, typeParameters, parameters, endToken));
|
| } else {
|
| TypeAnnotation type = pop();
|
| TypeParameterList templateParameters = pop();
|
| @@ -1702,8 +1683,8 @@ class AstBuilder extends ScopeListener {
|
| // this).
|
| type = null;
|
| }
|
| - push(ast.genericTypeAlias(comment, metadata, typedefKeyword, name,
|
| - templateParameters, equals, type, endToken));
|
| + declarations.add(ast.genericTypeAlias(comment, metadata, typedefKeyword,
|
| + name, templateParameters, equals, type, endToken));
|
| }
|
| }
|
|
|
| @@ -1719,8 +1700,8 @@ class AstBuilder extends ScopeListener {
|
| SimpleIdentifier name = pop();
|
| List<Annotation> metadata = pop();
|
| Comment comment = pop();
|
| - push(ast.enumDeclaration(comment, metadata, enumKeyword, name, openBrace,
|
| - constants, closeBrace));
|
| + declarations.add(ast.enumDeclaration(comment, metadata, enumKeyword, name,
|
| + openBrace, constants, closeBrace));
|
| }
|
|
|
| @override
|
| @@ -1753,7 +1734,7 @@ class AstBuilder extends ScopeListener {
|
| @override
|
| AstNode finishFields() {
|
| debugEvent("finishFields");
|
| - return pop();
|
| + return declarations.removeLast();
|
| }
|
|
|
| @override
|
|
|