Inline utility method closeBraceTokenFor
Now that Token implements endGroup, there is no need for a type check and the associated utility method can be inlined. Change-Id: Ibb7b54837e4b459dbfa35b987c67794b05e0d579 Reviewed-on: https://dart-review.googlesource.com/46576 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Dan Rubel <danrubel@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
f36358c370
commit
f1ebe2bd5c
@@ -22,7 +22,6 @@ import '../parser.dart'
|
||||
FormalParameterKind,
|
||||
IdentifierContext,
|
||||
MemberKind,
|
||||
closeBraceTokenFor,
|
||||
lengthForToken,
|
||||
lengthOfSpan,
|
||||
offsetForToken,
|
||||
@@ -816,8 +815,7 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
|
||||
@override
|
||||
void handleParenthesizedExpression(Token token) {
|
||||
debugEvent("ParenthesizedExpression");
|
||||
push(new ParenthesizedExpression(
|
||||
this, popForValue(), closeBraceTokenFor(token)));
|
||||
push(new ParenthesizedExpression(this, popForValue(), token.endGroup));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1786,7 +1784,7 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
|
||||
addProblem(
|
||||
fasta.messageListLiteralTooManyTypeArguments,
|
||||
offsetForToken(beginToken),
|
||||
lengthOfSpan(beginToken, closeBraceTokenFor(beginToken)));
|
||||
lengthOfSpan(beginToken, beginToken.endGroup));
|
||||
} else if (library.loader.target.strongMode) {
|
||||
typeArgument = instantiateToBounds(typeArgument, coreTypes.objectClass);
|
||||
}
|
||||
@@ -1834,7 +1832,7 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
|
||||
addProblem(
|
||||
fasta.messageListLiteralTypeArgumentMismatch,
|
||||
offsetForToken(beginToken),
|
||||
lengthOfSpan(beginToken, closeBraceTokenFor(beginToken)));
|
||||
lengthOfSpan(beginToken, beginToken.endGroup));
|
||||
} else {
|
||||
if (library.loader.target.strongMode) {
|
||||
keyType =
|
||||
|
||||
@@ -31,12 +31,7 @@ export 'parser/parser_error.dart' show ParserError;
|
||||
export 'parser/top_level_parser.dart' show TopLevelParser;
|
||||
|
||||
export 'parser/util.dart'
|
||||
show
|
||||
closeBraceTokenFor,
|
||||
lengthForToken,
|
||||
lengthOfSpan,
|
||||
offsetForToken,
|
||||
optional;
|
||||
show lengthForToken, lengthOfSpan, offsetForToken, optional;
|
||||
|
||||
List<ParserError> parse(Token tokens) {
|
||||
Listener listener = new Listener();
|
||||
|
||||
@@ -101,7 +101,7 @@ import 'type_info.dart'
|
||||
isValidTypeReference,
|
||||
noTypeInfo;
|
||||
|
||||
import 'util.dart' show closeBraceTokenFor, optional;
|
||||
import 'util.dart' show optional;
|
||||
|
||||
/// An event generating parser of Dart programs. This parser expects all tokens
|
||||
/// in a linked list (aka a token stream).
|
||||
@@ -1076,7 +1076,7 @@ class Parser {
|
||||
listener.endFormalParameters(0, token, token, kind);
|
||||
return reportUnexpectedToken(token);
|
||||
}
|
||||
Token closeBrace = closeBraceTokenFor(token);
|
||||
Token closeBrace = token.endGroup;
|
||||
listener.endFormalParameters(0, token, closeBrace, kind);
|
||||
return closeBrace;
|
||||
}
|
||||
@@ -1488,7 +1488,7 @@ class Parser {
|
||||
/// [isValidMethodTypeArguments].
|
||||
Token tryParseMethodTypeArguments(Token token) {
|
||||
if (!identical(token.kind, LT_TOKEN)) return null;
|
||||
Token endToken = closeBraceTokenFor(token);
|
||||
Token endToken = token.endGroup;
|
||||
if (endToken == null ||
|
||||
!identical(endToken.next.kind, OPEN_PAREN_TOKEN)) {
|
||||
return null;
|
||||
@@ -1596,7 +1596,7 @@ class Parser {
|
||||
|
||||
Token skipBlock(Token token) {
|
||||
token = ensureBlock(token, null);
|
||||
Token closeBrace = closeBraceTokenFor(token);
|
||||
Token closeBrace = token.endGroup;
|
||||
if (closeBrace == null ||
|
||||
!identical(closeBrace.kind, $CLOSE_CURLY_BRACKET)) {
|
||||
return reportUnmatchedToken(token).next;
|
||||
@@ -2278,7 +2278,7 @@ class Parser {
|
||||
/// The tokens before the start of type variables of function types seen
|
||||
/// during analysis. Notice that the tokens in this list might precede
|
||||
/// either `'<'` or `'('` as not all function types have type parameters.
|
||||
/// Also, it is safe to assume that [closeBraceTokenFor] will return
|
||||
/// Also, it is safe to assume that token.endGroup will return
|
||||
/// non-null for all of the tokens following these tokens.
|
||||
Link<Token> typeVariableStarters = const Link<Token>();
|
||||
|
||||
@@ -2316,7 +2316,7 @@ class Parser {
|
||||
token = beforeToken.next;
|
||||
}
|
||||
if (optional("<", token)) {
|
||||
Token close = closeBraceTokenFor(token);
|
||||
Token close = token.endGroup;
|
||||
if (close != null &&
|
||||
(optional(">", close) || optional(">>", close))) {
|
||||
// We found some type arguments.
|
||||
@@ -2338,7 +2338,7 @@ class Parser {
|
||||
while (optional("Function", token)) {
|
||||
Token typeVariableStart = token;
|
||||
if (optional("<", token.next)) {
|
||||
Token close = closeBraceTokenFor(token.next);
|
||||
Token close = token.next.endGroup;
|
||||
if (close != null && optional(">", close)) {
|
||||
beforeToken = previousToken(token, close);
|
||||
token = close;
|
||||
@@ -2348,7 +2348,7 @@ class Parser {
|
||||
}
|
||||
if (optional("(", token.next)) {
|
||||
// This is a function type.
|
||||
Token close = closeBraceTokenFor(token.next);
|
||||
Token close = token.next.endGroup;
|
||||
assert(optional(")", close));
|
||||
looksLikeType = true;
|
||||
functionTypes++;
|
||||
@@ -2398,7 +2398,7 @@ class Parser {
|
||||
Token functionToken = next;
|
||||
if (optional("<", next.next)) {
|
||||
// Skip type parameters, they were parsed above.
|
||||
next = closeBraceTokenFor(next.next);
|
||||
next = next.next.endGroup;
|
||||
}
|
||||
token = parseFormalParametersRequiredOpt(
|
||||
next, MemberKind.GeneralizedFunctionType);
|
||||
@@ -2439,12 +2439,12 @@ class Parser {
|
||||
}
|
||||
token = token.next;
|
||||
if (optional('<', token)) {
|
||||
Token closeBrace = closeBraceTokenFor(token);
|
||||
Token closeBrace = token.endGroup;
|
||||
if (closeBrace == null) return false;
|
||||
token = closeBrace.next;
|
||||
}
|
||||
if (optional('(', token)) {
|
||||
return looksLikeFunctionBody(closeBraceTokenFor(token).next);
|
||||
return looksLikeFunctionBody(token.endGroup.next);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2513,7 +2513,7 @@ class Parser {
|
||||
return parseVariablesDeclaration(beforeBegin);
|
||||
} else if (OPEN_PAREN_TOKEN == afterIdKind) {
|
||||
// We are looking at `type identifier '('`.
|
||||
if (looksLikeFunctionBody(closeBraceTokenFor(afterId).next)) {
|
||||
if (looksLikeFunctionBody(afterId.endGroup.next)) {
|
||||
// We are looking at `type identifier '(' ... ')'` followed
|
||||
// `( '{' | '=>' | 'async' | 'sync' )`.
|
||||
|
||||
@@ -2533,11 +2533,10 @@ class Parser {
|
||||
}
|
||||
} else if (identical(afterIdKind, LT_TOKEN)) {
|
||||
// We are looking at `type identifier '<'`.
|
||||
Token beforeFormals = closeBraceTokenFor(afterId);
|
||||
Token beforeFormals = afterId.endGroup;
|
||||
if (beforeFormals?.next != null &&
|
||||
optional("(", beforeFormals.next)) {
|
||||
if (looksLikeFunctionBody(
|
||||
closeBraceTokenFor(beforeFormals.next).next)) {
|
||||
if (looksLikeFunctionBody(beforeFormals.next.endGroup.next)) {
|
||||
// We are looking at "type identifier '<' ... '>' '(' ... ')'"
|
||||
// followed by '{', '=>', 'async', or 'sync'.
|
||||
parseTypeVariablesOpt(token);
|
||||
@@ -2560,7 +2559,7 @@ class Parser {
|
||||
if (optional(':', token.next)) {
|
||||
return parseLabeledStatement(beforeToken);
|
||||
} else if (optional('(', token.next)) {
|
||||
if (looksLikeFunctionBody(closeBraceTokenFor(token.next).next)) {
|
||||
if (looksLikeFunctionBody(token.next.endGroup.next)) {
|
||||
// We are looking at `identifier '(' ... ')'` followed by `'{'`,
|
||||
// `'=>'`, `'async'`, or `'sync'`.
|
||||
|
||||
@@ -2574,9 +2573,9 @@ class Parser {
|
||||
return parseNamedFunctionRest(beforeToken, begin, formals, false);
|
||||
}
|
||||
} else if (optional('<', token.next)) {
|
||||
Token gt = closeBraceTokenFor(token.next);
|
||||
Token gt = token.next.endGroup;
|
||||
if (gt?.next != null && optional("(", gt.next)) {
|
||||
if (looksLikeFunctionBody(closeBraceTokenFor(gt.next).next)) {
|
||||
if (looksLikeFunctionBody(gt.next.endGroup.next)) {
|
||||
// We are looking at `identifier '<' ... '>' '(' ... ')'`
|
||||
// followed by `'{'`, `'=>'`, `'async'`, or `'sync'`.
|
||||
parseTypeVariablesOpt(token);
|
||||
@@ -2760,7 +2759,7 @@ class Parser {
|
||||
|
||||
Token inlineFunctionTypeStart;
|
||||
if (optional("<", token)) {
|
||||
Token closer = closeBraceTokenFor(token);
|
||||
Token closer = token.endGroup;
|
||||
if (closer != null) {
|
||||
if (optional("(", closer.next)) {
|
||||
if (varFinalOrConst != null) {
|
||||
@@ -2778,7 +2777,7 @@ class Parser {
|
||||
varFinalOrConst, fasta.messageFunctionTypedParameterVar);
|
||||
}
|
||||
inlineFunctionTypeStart = beforeToken;
|
||||
beforeToken = closeBraceTokenFor(token);
|
||||
beforeToken = token.endGroup;
|
||||
token = beforeToken.next;
|
||||
}
|
||||
|
||||
@@ -3561,7 +3560,7 @@ class Parser {
|
||||
if (!optional('{', token)) {
|
||||
token = ensureBlock(previousToken, fasta.templateExpectedClassBody);
|
||||
}
|
||||
Token closeBrace = closeBraceTokenFor(token);
|
||||
Token closeBrace = token.endGroup;
|
||||
if (closeBrace == null ||
|
||||
!identical(closeBrace.kind, $CLOSE_CURLY_BRACKET)) {
|
||||
return reportUnmatchedToken(token).next;
|
||||
@@ -4518,7 +4517,7 @@ class Parser {
|
||||
// Foo() : map = {};
|
||||
// Foo.x() : map = true ? {} : {};
|
||||
// }
|
||||
token = closeBraceTokenFor(next.next) ?? next;
|
||||
token = next.next.endGroup ?? next;
|
||||
next = token.next;
|
||||
continue;
|
||||
}
|
||||
@@ -4529,10 +4528,10 @@ class Parser {
|
||||
// Foo() : map = <String, Foo>{};
|
||||
// Foo.x() : map = true ? <String, Foo>{} : <String, Foo>{};
|
||||
// }
|
||||
token = closeBraceTokenFor(next.next) ?? next;
|
||||
token = next.next.endGroup ?? next;
|
||||
next = token.next;
|
||||
if (identical(next.stringValue, '{')) {
|
||||
token = closeBraceTokenFor(next) ?? next;
|
||||
token = next.endGroup ?? next;
|
||||
next = token.next;
|
||||
}
|
||||
continue;
|
||||
@@ -4542,7 +4541,7 @@ class Parser {
|
||||
break;
|
||||
}
|
||||
if (next is BeginToken) {
|
||||
token = closeBraceTokenFor(next) ?? next;
|
||||
token = next.endGroup ?? next;
|
||||
} else {
|
||||
if (next is ErrorToken) {
|
||||
reportErrorToken(next, false);
|
||||
@@ -4882,7 +4881,7 @@ class Parser {
|
||||
Token parseParenthesizedExpressionOrFunctionLiteral(Token token) {
|
||||
Token next = token.next;
|
||||
assert(optional('(', next));
|
||||
Token nextToken = closeBraceTokenFor(next).next;
|
||||
Token nextToken = next.endGroup.next;
|
||||
int kind = nextToken.kind;
|
||||
if (mayParseFunctionExpressions) {
|
||||
if ((identical(kind, FUNCTION_TOKEN) ||
|
||||
@@ -5071,7 +5070,7 @@ class Parser {
|
||||
Token parseLiteralFunctionSuffix(Token token) {
|
||||
Token next = token.next;
|
||||
assert(optional('(', next));
|
||||
Token closeBrace = closeBraceTokenFor(next);
|
||||
Token closeBrace = next.endGroup;
|
||||
if (closeBrace != null) {
|
||||
Token nextToken = closeBrace.next;
|
||||
int kind = nextToken.kind;
|
||||
@@ -5098,7 +5097,7 @@ class Parser {
|
||||
Token parseLiteralListOrMapOrFunction(Token token, Token constKeyword) {
|
||||
Token next = token.next;
|
||||
assert(optional('<', next));
|
||||
Token closeBrace = closeBraceTokenFor(next);
|
||||
Token closeBrace = next.endGroup;
|
||||
if (constKeyword == null &&
|
||||
closeBrace != null &&
|
||||
identical(closeBrace.next.kind, OPEN_PAREN_TOKEN)) {
|
||||
@@ -5382,7 +5381,7 @@ class Parser {
|
||||
Token next = token.next;
|
||||
listener.handleNoArguments(next);
|
||||
if (optional('(', next)) {
|
||||
return closeBraceTokenFor(next);
|
||||
return next.endGroup;
|
||||
} else {
|
||||
return token;
|
||||
}
|
||||
|
||||
@@ -17,12 +17,6 @@ bool optional(String value, Token token) {
|
||||
return identical(value, token.stringValue);
|
||||
}
|
||||
|
||||
/// Returns the close brace, bracket, or parenthesis of [left]. For '<', it may
|
||||
/// return null.
|
||||
Token closeBraceTokenFor(Token token) {
|
||||
return token is BeginToken ? token.endGroup : null;
|
||||
}
|
||||
|
||||
/// Returns the token before the close brace, bracket, or parenthesis
|
||||
/// associated with [left]. For '<', it may return `null`.
|
||||
Token beforeCloseBraceTokenFor(BeginToken left) {
|
||||
|
||||
@@ -26,8 +26,7 @@ import '../fasta_codes.dart'
|
||||
|
||||
import '../kernel/body_builder.dart' show BodyBuilder;
|
||||
|
||||
import '../parser.dart'
|
||||
show IdentifierContext, MemberKind, Parser, closeBraceTokenFor, optional;
|
||||
import '../parser.dart' show IdentifierContext, MemberKind, Parser, optional;
|
||||
|
||||
import '../problems.dart' show internalProblem, unexpected;
|
||||
|
||||
@@ -475,8 +474,7 @@ class DietListener extends StackListener {
|
||||
Object name = pop();
|
||||
Token metadata = pop();
|
||||
checkEmpty(beginToken.charOffset);
|
||||
if (bodyToken == null ||
|
||||
optional("=", closeBraceTokenFor(bodyToken).next)) {
|
||||
if (bodyToken == null || optional("=", bodyToken.endGroup.next)) {
|
||||
// TODO(ahe): Don't skip this. We need to compile metadata and
|
||||
// redirecting factory bodies.
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user