Skip to content

Commit

Permalink
Revise beginTypeVariable event in event sequence
Browse files Browse the repository at this point in the history
This is the first CL in a series aimed at removing the need to reparse type variables in
https://github.com/dart-lang/sdk/blob/master/pkg/front_end/lib/src/fasta/kernel/body_builder.dart#L3669
and ultimately improving recovery by removing parseType.

* Move calls to listener.beginTypeVariable after parsing metadata and identifier
* Pass variable name via beginTypeVariable rather than via handleIdentifier
* Add additional check in test for issue 31846

Change-Id: I983b9d17675fc899c83df69fa1777059903e3f52
Reviewed-on: https://dart-review.googlesource.com/58300
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Dan Rubel <[email protected]>
  • Loading branch information
Dan Rubel authored and [email protected] committed Jun 5, 2018
1 parent e0ca151 commit daee781
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 66 deletions.
7 changes: 7 additions & 0 deletions pkg/analyzer/lib/src/fasta/ast_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ class AstBuilder extends StackListener {
push(ast.thisExpression(thisKeyword));
}

@override
void handleType(Token beginToken, Token endToken) {
debugEvent("Type");

Expand Down Expand Up @@ -2162,6 +2163,12 @@ class AstBuilder extends StackListener {
comment, metadata, variableList, semicolon));
}

@override
void beginTypeVariable(Token name) {
debugEvent("beginTypeVariable");
push(ast.simpleIdentifier(name, isDeclaration: true));
}

@override
void endTypeVariable(Token token, Token extendsOrSuper) {
// TODO(paulberry): set up scopes properly to resolve parameters and type
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/test/generated/parser_fasta_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ class ForwardingTestListener extends ForwardingListener {
}

@override
void beginTypeVariable(Token token) {
super.beginTypeVariable(token);
void beginTypeVariable(Token name) {
super.beginTypeVariable(name);
begin('TypeVariable');
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/front_end/lib/src/fasta/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3690,6 +3690,12 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
library.types.clear();
}

@override
void beginTypeVariable(Token name) {
debugEvent("beginTypeVariable");
push(new Identifier(name));
}

@override
void handleNoTypeVariables(Token token) {
debugEvent("NoTypeVariables");
Expand Down
4 changes: 2 additions & 2 deletions pkg/front_end/lib/src/fasta/parser/forwarding_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ class ForwardingListener implements Listener {
}

@override
void beginTypeVariable(Token token) {
listener?.beginTypeVariable(token);
void beginTypeVariable(Token name) {
listener?.beginTypeVariable(name);
}

@override
Expand Down
9 changes: 6 additions & 3 deletions pkg/front_end/lib/src/fasta/parser/listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -898,13 +898,16 @@ class Listener {
logEvent("NoTypeArguments");
}

void beginTypeVariable(Token token) {}
/// Handle the begin of a type formal parameter (e.g. "X extends Y").
/// Substructures:
/// - Metadata
void beginTypeVariable(Token name) {}

/// Handle the end of a type formal parameter (e.g. "X extends Y").
/// Substructures:
/// - Metadata
/// - Name (identifier)
/// - Type bound
///
/// See [beginTypeVariable] for additional substructures.
void endTypeVariable(Token token, Token extendsOrSuper) {
logEvent("TypeVariable");
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/front_end/lib/src/fasta/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1961,9 +1961,12 @@ class Parser {
/// ;
/// ```
Token parseTypeVariable(Token token) {
listener.beginTypeVariable(token.next);
token = parseMetadataStar(token);
token = ensureIdentifier(token, IdentifierContext.typeVariableDeclaration);
token = token.next.kind == IDENTIFIER_TOKEN
? token.next
: IdentifierContext.typeVariableDeclaration
.ensureIdentifier(token, this);
listener.beginTypeVariable(token);
Token extendsOrSuper = null;
Token next = token.next;
if (optional('extends', next) || optional('super', next)) {
Expand Down
24 changes: 12 additions & 12 deletions pkg/front_end/lib/src/fasta/parser/type_info_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ class SimpleTypeWith1Argument implements TypeInfo {

@override
Token skipType(Token token) {
token = token.next.next;
assert(optional('<', token));
assert(token.endGroup != null || optional('>>', token.next.next));
return token.endGroup ?? token.next;
token = token.next;
assert(token.isKeywordOrIdentifier);
return simpleTypeArgument1.skip(token);
}
}

Expand Down Expand Up @@ -510,10 +509,9 @@ class SimpleTypeArgument1 implements TypeParamOrArgInfo {
Listener listener = parser.listener;
listener.beginTypeVariables(token);
token = token.next;
listener.beginTypeVariable(token);
listener.beginMetadataStar(token);
listener.endMetadataStar(0);
listener.handleIdentifier(token, IdentifierContext.typeVariableDeclaration);
listener.beginTypeVariable(token);
listener.handleNoType(token);
token = processEndGroup(token, start, parser);
listener.endTypeVariable(token, null);
Expand All @@ -527,9 +525,9 @@ class SimpleTypeArgument1 implements TypeParamOrArgInfo {
assert(optional('<', token));
assert(token.endGroup != null ||
(optional('>', token.next.next) || optional('>>', token.next.next)));
return (optional('>>', token.endGroup ?? token.next.next)
? token.next
: token.next.next);
return (optional('>', token.endGroup ?? token.next.next)
? token.next.next
: token.next);
}
}

Expand Down Expand Up @@ -659,10 +657,12 @@ class ComplexTypeParamOrArgInfo implements TypeParamOrArgInfo {
parser.listener.beginTypeVariables(start);
int count = 0;
while (true) {
parser.listener.beginTypeVariable(next.next);
token = parser.parseMetadataStar(next);
token = parser.ensureIdentifier(
token, IdentifierContext.typeVariableDeclaration);
token = token.next.kind == IDENTIFIER_TOKEN
? token.next
: IdentifierContext.typeVariableDeclaration
.ensureIdentifier(token, parser);
parser.listener.beginTypeVariable(token);
Token extendsOrSuper = null;
next = token.next;
if (optional('extends', next) || optional('super', next)) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/fasta/source/diet_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class DietListener extends StackListener {
@override
void endTypeVariable(Token token, Token extendsOrSuper) {
debugEvent("TypeVariable");
discard(2); // Name and metadata.
discard(1); // Metadata.
}

@override
Expand Down
7 changes: 7 additions & 0 deletions pkg/front_end/lib/src/fasta/source/outline_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,13 @@ class OutlineBuilder extends StackListener {
documentationComment, metadata, modifiers, type, fieldsInfo);
}

@override
void beginTypeVariable(Token token) {
debugEvent("beginTypeVariable");
push(token.lexeme);
push(token.charOffset);
}

@override
void endTypeVariable(Token token, Token extendsOrSuper) {
debugEvent("endTypeVariable");
Expand Down
Loading

0 comments on commit daee781

Please sign in to comment.