Skip to content

Commit

Permalink
Update handleType event to take questionMark token
Browse files Browse the repository at this point in the history
... which in this CL will always null.
This is the first step when adding NNDB support as outlined in
dart-lang/language#110

Change-Id: If3810bcaf1b73e70924f09d619e2a84e7d5ba8d6
Reviewed-on: https://dart-review.googlesource.com/c/86860
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
  • Loading branch information
danrubel authored and commit-bot@chromium.org committed Dec 11, 2018
1 parent 4d63202 commit 2a85a34
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 119 deletions.
5 changes: 3 additions & 2 deletions pkg/analyzer/lib/src/fasta/ast_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,9 @@ class AstBuilder extends StackListener {
}

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

TypeArgumentList arguments = pop();
Identifier name = pop();
Expand Down Expand Up @@ -2552,7 +2553,7 @@ class AstBuilder extends StackListener {
// keyword up to an element?
handleIdentifier(voidKeyword, IdentifierContext.typeReference);
handleNoTypeArguments(voidKeyword);
handleType(voidKeyword);
handleType(voidKeyword, null);
}

@override
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer/tool/summary/mini_ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,9 @@ class MiniAstBuilder extends StackListener {
}

@override
void handleType(Token beginToken) {
void handleType(Token beginToken, Token questionMark) {
debugEvent("Type");
reportErrorIfNullableType(questionMark);
List<TypeName> typeArguments = popTypedList();
String name = pop();
push(new TypeName(name, typeArguments));
Expand Down
3 changes: 2 additions & 1 deletion pkg/front_end/lib/src/fasta/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2467,9 +2467,10 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
}

@override
void handleType(Token beginToken) {
void handleType(Token beginToken, Token questionMark) {
// TODO(ahe): The scope is wrong for return types of generic functions.
debugEvent("Type");
reportErrorIfNullableType(questionMark);
List<UnresolvedType<KernelTypeBuilder>> arguments = pop();
Object name = pop();
if (name is QualifiedName) {
Expand Down
9 changes: 7 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 @@ -1349,8 +1349,8 @@ class ForwardingListener implements Listener {
}

@override
void handleType(Token beginToken) {
listener?.handleType(beginToken);
void handleType(Token beginToken, Token questionMark) {
listener?.handleType(beginToken, questionMark);
}

@override
Expand Down Expand Up @@ -1398,6 +1398,11 @@ class ForwardingListener implements Listener {
listener?.logEvent(name);
}

@override
void reportErrorIfNullableType(Token questionMark) {
listener?.reportErrorIfNullableType(questionMark);
}

@override
set suppressParseErrors(bool value) {
listener?.suppressParseErrors = value;
Expand Down
18 changes: 16 additions & 2 deletions pkg/front_end/lib/src/fasta/parser/listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library fasta.parser.listener;

import '../../scanner/token.dart' show Token;

import '../fasta_codes.dart' show Message;
import '../fasta_codes.dart' show Message, templateUnexpectedToken;

import '../quote.dart' show UnescapeErrorListener;

Expand All @@ -18,6 +18,8 @@ import 'identifier_context.dart' show IdentifierContext;

import 'member_kind.dart' show MemberKind;

import 'util.dart' show optional;

/// A parser event listener that does nothing except throw exceptions
/// on parser errors.
///
Expand Down Expand Up @@ -933,10 +935,22 @@ class Listener implements UnescapeErrorListener {
logEvent("TryStatement");
}

void handleType(Token beginToken) {
void handleType(Token beginToken, Token questionMark) {
logEvent("Type");
}

// TODO(danrubel): Remove this once all listeners have been updated
// to properly handle nullable types
void reportErrorIfNullableType(Token questionMark) {
if (questionMark != null) {
assert(optional('?', questionMark));
handleRecoverableError(
templateUnexpectedToken.withArguments(questionMark),
questionMark,
questionMark);
}
}

void handleNoName(Token token) {
logEvent("NoName");
}
Expand Down
22 changes: 14 additions & 8 deletions pkg/front_end/lib/src/fasta/parser/type_info_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class PrefixedType implements TypeInfo {
listener.handleQualified(period);

listener.handleNoTypeArguments(token.next);
listener.handleType(start);
listener.handleType(start, null);
return token;
}

Expand Down Expand Up @@ -183,10 +183,13 @@ class SimpleTypeWith1Argument implements TypeInfo {
Token parseType(Token token, Parser parser) {
Token start = token = token.next;
assert(token.isKeywordOrIdentifier);
Listener listener = parser.listener;
listener.handleIdentifier(token, IdentifierContext.typeReference);
parser.listener.handleIdentifier(token, IdentifierContext.typeReference);
token = typeArg.parseArguments(token, parser);
listener.handleType(start);
return parseTypeRest(start, token, parser);
}

Token parseTypeRest(Token start, Token token, Parser parser) {
parser.listener.handleType(start, null);
return token;
}

Expand Down Expand Up @@ -221,10 +224,13 @@ class SimpleType implements TypeInfo {
Token parseType(Token token, Parser parser) {
token = token.next;
assert(isValidTypeReference(token));
Listener listener = parser.listener;
listener.handleIdentifier(token, IdentifierContext.typeReference);
parser.listener.handleIdentifier(token, IdentifierContext.typeReference);
token = noTypeParamOrArg.parseArguments(token, parser);
listener.handleType(token);
return parseTypeRest(token, parser);
}

Token parseTypeRest(Token token, Parser parser) {
parser.listener.handleType(token, null);
return token;
}

Expand Down Expand Up @@ -372,7 +378,7 @@ class ComplexTypeInfo implements TypeInfo {
}
}
token = typeArguments.parseArguments(token, parser);
parser.listener.handleType(typeRefOrPrefix);
parser.listener.handleType(typeRefOrPrefix, null);
}
}

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 @@ -148,7 +148,7 @@ class DietListener extends StackListener {
}

@override
void handleType(Token beginToken) {
void handleType(Token beginToken, Token questionMark) {
debugEvent("Type");
discard(1);
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/front_end/lib/src/fasta/source/outline_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,9 @@ class OutlineBuilder extends StackListener {
}

@override
void handleType(Token beginToken) {
void handleType(Token beginToken, Token questionMark) {
debugEvent("Type");
reportErrorIfNullableType(questionMark);
List<TypeBuilder> arguments = pop();
int charOffset = pop();
Object name = pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ class TypePromotionLookAheadListener extends Listener {
}

@override
void handleType(Token beginToken) {
void handleType(Token beginToken, Token questionMark) {
debugEvent("Type", beginToken);
state.pop();
}
Expand Down
Loading

0 comments on commit 2a85a34

Please sign in to comment.