Skip to content

Commit d84d541

Browse files
author
David Ungar
committed
De-lazify
1 parent 0dbf7e6 commit d84d541

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

include/swift/Parse/Parser.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,16 @@ class Parser {
813813
SourceLoc OtherLoc);
814814

815815
/// Returns the proper location for a missing right brace, parenthesis, etc.
816-
SourceLoc getConfabulatedMatchingTokenLoc() const;
817-
818-
SourceLoc getErrorOrMissingLocForLazyASTScopes() const;
816+
SourceLoc getLocForMissingMatchingToken() const;
817+
818+
/// When encountering an error or a missing matching token (e.g. '}') return
819+
/// its location. This value should be right at the end of the last token in
820+
/// the ASTNode being parsed so that it nests within any enclosing nodes, and,
821+
/// for ASTScope lookups, it does not preceed any identifiers to be looked up.
822+
/// The latter case obtaines when the parsing an interpolated string literal
823+
/// because there may be identifiers to be looked up and they must precede the
824+
/// location of a missing close brace.
825+
SourceLoc getErrorOrMissingLoc() const;
819826

820827
/// Parse a comma separated list of some elements.
821828
ParserStatus parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3434,7 +3434,7 @@ ParserResult<Expr> Parser::parseExprCollection() {
34343434
if (Status.isError()) {
34353435
// If we've already got errors, don't emit missing RightK diagnostics.
34363436
RSquareLoc = Tok.is(tok::r_square) ? consumeToken()
3437-
: getConfabulatedMatchingTokenLoc();
3437+
: getLocForMissingMatchingToken();
34383438
} else if (parseMatchingToken(tok::r_square, RSquareLoc,
34393439
diag::expected_rsquare_array_expr,
34403440
LSquareLoc)) {

lib/Parse/ParseType.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,8 @@ ParserResult<TypeRepr> Parser::parseDeclResultType(Diag<> MessageID) {
542542
}
543543

544544
SourceLoc Parser::getTypeErrorLoc() const {
545-
/// LazyASTScopes require that the ends of types, etc. which are at the end of
546-
/// \c IterableTypeContext \c Decls, such as \c StructDecl not be beyond the
547-
/// end of the enclosing \c Decl.
548-
return Context.LangOpts.LazyASTScopes ? getErrorOrMissingLocForLazyASTScopes() : Tok.getLoc();
545+
// Use the same location as a missing close brace, etc.
546+
return getErrorOrMissingLoc();
549547
}
550548

551549
ParserStatus Parser::parseGenericArguments(SmallVectorImpl<TypeRepr *> &Args,

lib/Parse/Parser.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -980,23 +980,29 @@ bool Parser::parseMatchingToken(tok K, SourceLoc &TokLoc, Diag<> ErrorDiag,
980980
if (parseToken(K, TokLoc, ErrorDiag)) {
981981
diagnose(OtherLoc, OtherNote);
982982

983-
TokLoc = getConfabulatedMatchingTokenLoc();
983+
TokLoc = getLocForMissingMatchingToken();
984984
return true;
985985
}
986986

987987
return false;
988988
}
989989

990-
SourceLoc Parser::getConfabulatedMatchingTokenLoc() const {
990+
SourceLoc Parser::getLocForMissingMatchingToken() const {
991991
// The right brace, parenthesis, etc. must include the whole of the previous
992992
// token in order so that an unexpanded lazy \c IterableTypeScope includes its
993993
// contents.
994-
return Context.LangOpts.LazyASTScopes
995-
? getErrorOrMissingLocForLazyASTScopes()
996-
: PreviousLoc;
994+
return getErrorOrMissingLoc();
997995
}
998996

999-
SourceLoc Parser::getErrorOrMissingLocForLazyASTScopes() const {
997+
SourceLoc Parser::getErrorOrMissingLoc() const {
998+
// LazyASTScopes require that the ends of types, etc. which are at the end of
999+
// \c IterableTypeContext \c Decls, such as \c StructDecl not be beyond the
1000+
// end of the enclosing \c Decl.
1001+
1002+
// The missing right brace, parenthesis, etc. must include the whole of the
1003+
// previous token in order so that an unexpanded lazy \c IterableTypeScope
1004+
// includes its contents.
1005+
10001006
auto const PreviousTok = Lexer::getTokenAtLocation(Context.SourceMgr,
10011007
PreviousLoc);
10021008
// If it's a string literal, it might be an InterpolatedStringLiteral.
@@ -1114,7 +1120,7 @@ Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
11141120
if (Status.isError()) {
11151121
// If we've already got errors, don't emit missing RightK diagnostics.
11161122
RightLoc =
1117-
Tok.is(RightK) ? consumeToken() : getConfabulatedMatchingTokenLoc();
1123+
Tok.is(RightK) ? consumeToken() : getLocForMissingMatchingToken();
11181124
} else if (parseMatchingToken(RightK, RightLoc, ErrorDiag, LeftLoc)) {
11191125
Status.setIsParseError();
11201126
}

0 commit comments

Comments
 (0)