Skip to content

Commit

Permalink
Handle TypeVariable and TypeVariables in AstBuilder.
Browse files Browse the repository at this point in the history
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2705153004 .
  • Loading branch information
stereotype441 committed Feb 21, 2017
1 parent dbe5e64 commit 7647e90
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
27 changes: 3 additions & 24 deletions pkg/analyzer/test/generated/parser_fasta_test.dart
Expand Up @@ -551,13 +551,6 @@ class TopLevelParserTest_Fasta extends FastaParserTestCase
super.test_parseClassDeclaration_typeAlias_withB();
}

@override
@failingTest
void test_parseClassDeclaration_typeParameters() {
// TODO(paulberry): Unhandled event: TypeVariable
super.test_parseClassDeclaration_typeParameters();
}

@override
@failingTest
void test_parseCompilationUnit_abstractAsPrefix_parameterized() {
Expand Down Expand Up @@ -644,13 +637,6 @@ class TopLevelParserTest_Fasta extends FastaParserTestCase
super.test_parseCompilationUnitMember_function_external_type();
}

@override
@failingTest
void test_parseCompilationUnitMember_function_generic_noReturnType() {
// TODO(paulberry): Unhandled event: TypeVariable
super.test_parseCompilationUnitMember_function_generic_noReturnType();
}

@override
@failingTest
void
Expand All @@ -661,13 +647,6 @@ class TopLevelParserTest_Fasta extends FastaParserTestCase
.test_parseCompilationUnitMember_function_generic_noReturnType_annotated();
}

@override
@failingTest
void test_parseCompilationUnitMember_function_generic_returnType() {
// TODO(paulberry): Unhandled event: TypeVariable
super.test_parseCompilationUnitMember_function_generic_returnType();
}

@override
@failingTest
void test_parseCompilationUnitMember_function_generic_void() {
Expand Down Expand Up @@ -727,7 +706,7 @@ class TopLevelParserTest_Fasta extends FastaParserTestCase
@override
@failingTest
void test_parseCompilationUnitMember_typeAlias_generic() {
// TODO(paulberry): Unhandled event: TypeVariable
// TODO(paulberry): Unhandled event: TypeArguments
super.test_parseCompilationUnitMember_typeAlias_generic();
}

Expand Down Expand Up @@ -828,7 +807,7 @@ class TopLevelParserTest_Fasta extends FastaParserTestCase
@override
@failingTest
void test_parseFunctionDeclaration_functionWithTypeParameters() {
// TODO(paulberry): Unhandled event: TypeVariable
// TODO(paulberry): handle doc comments
super.test_parseFunctionDeclaration_functionWithTypeParameters();
}

Expand Down Expand Up @@ -917,7 +896,7 @@ class TopLevelParserTest_Fasta extends FastaParserTestCase
@override
@failingTest
void test_parseTypeAlias_function_typeParameters() {
// TODO(paulberry): Unhandled event: TypeVariable
// TODO(paulberry): Unhandled event: FunctionTypeAlias
super.test_parseTypeAlias_function_typeParameters();
}

Expand Down
23 changes: 23 additions & 0 deletions pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
Expand Up @@ -995,6 +995,29 @@ class AstBuilder extends ScopeListener {
push(ast.topLevelVariableDeclaration(
comment, metadata, variableList, toAnalyzerToken(endToken)));
}

@override
void endTypeVariable(Token token, Token extendsOrSuper) {
// 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("TypeVariable");
TypeAnnotation bound = pop();
SimpleIdentifier name = pop();
List<Annotation> metadata = null; // TODO(paulberry)
Comment comment = null; // TODO(paulberry)
push(ast.typeParameter(
comment, metadata, name, toAnalyzerToken(extendsOrSuper), bound));
}

@override
void endTypeVariables(int count, Token beginToken, Token endToken) {
debugEvent("TypeVariables");
List<TypeParameter> typeParameters = popList(count);
push(ast.typeParameterList(toAnalyzerToken(beginToken), typeParameters,
toAnalyzerToken(endToken)));
}
}

/// Data structure placed on the stack to represent a class body.
Expand Down
4 changes: 4 additions & 0 deletions pkg/front_end/lib/src/fasta/parser/listener.dart
Expand Up @@ -628,6 +628,10 @@ class Listener {

void beginTypeVariable(Token token) {}

/// Handle the end of a type formal parameter (e.g. "X extends Y").
/// Substructures:
/// - Name (identifier)
/// - Type bound
void endTypeVariable(Token token, Token extendsOrSuper) {
logEvent("TypeVariable");
}
Expand Down

0 comments on commit 7647e90

Please sign in to comment.