Skip to content

Commit cbae07e

Browse files
committed
[Parse] Clean up Interpolated string literal parsing
1 parent f1adf99 commit cbae07e

File tree

4 files changed

+2
-66
lines changed

4 files changed

+2
-66
lines changed

include/swift/AST/Expr.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -902,12 +902,6 @@ class TapExpr : public Expr {
902902
class InterpolatedStringLiteralExpr : public LiteralExpr {
903903
/// Points at the beginning quote.
904904
SourceLoc Loc;
905-
/// Points at the ending quote.
906-
/// Needed for the upcoming \c ASTScope subsystem because lookups can be
907-
/// targeted to inside an \c InterpolatedStringLiteralExpr. It would be nicer
908-
/// to use \c EndLoc for this value, but then \c Lexer::getLocForEndOfToken()
909-
/// would not work for \c stringLiteral->getEndLoc().
910-
SourceLoc TrailingQuoteLoc;
911905
TapExpr *AppendingExpr;
912906

913907
// Set by Sema:
@@ -918,13 +912,11 @@ class InterpolatedStringLiteralExpr : public LiteralExpr {
918912

919913
public:
920914
InterpolatedStringLiteralExpr(SourceLoc Loc,
921-
SourceLoc TrailingQuoteLoc,
922915
unsigned LiteralCapacity,
923916
unsigned InterpolationCount,
924917
TapExpr *AppendingExpr)
925918
: LiteralExpr(ExprKind::InterpolatedStringLiteral, /*Implicit=*/false),
926919
Loc(Loc),
927-
TrailingQuoteLoc(TrailingQuoteLoc),
928920
AppendingExpr(AppendingExpr) {
929921
Bits.InterpolatedStringLiteralExpr.InterpolationCount = InterpolationCount;
930922
Bits.InterpolatedStringLiteralExpr.LiteralCapacity = LiteralCapacity;
@@ -977,11 +969,6 @@ class InterpolatedStringLiteralExpr : public LiteralExpr {
977969
return Loc;
978970
}
979971

980-
/// Could also be computed by relaxing.
981-
SourceLoc getTrailingQuoteLoc() const {
982-
return TrailingQuoteLoc;
983-
}
984-
985972
/// Call the \c callback with information about each segment in turn.
986973
void forEachSegment(ASTContext &Ctx,
987974
llvm::function_ref<void(bool, CallExpr *)> callback);
@@ -5511,9 +5498,6 @@ class EditorPlaceholderExpr : public Expr {
55115498
Identifier getPlaceholder() const { return Placeholder; }
55125499
SourceRange getSourceRange() const { return Loc; }
55135500
TypeRepr *getPlaceholderTypeRepr() const { return PlaceholderTy; }
5514-
SourceLoc getTrailingAngleBracketLoc() const {
5515-
return Loc.getAdvancedLoc(Placeholder.getLength() - 1);
5516-
}
55175501

55185502
/// The TypeRepr to be considered for placeholder expansion.
55195503
TypeRepr *getTypeForExpansion() const { return ExpansionTyR; }

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,11 +2217,6 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
22172217
void visitInterpolatedStringLiteralExpr(InterpolatedStringLiteralExpr *E, StringRef label) {
22182218
printCommon(E, "interpolated_string_literal_expr", label);
22192219

2220-
// Print the trailing quote location
2221-
if (auto Ty = GetTypeOfExpr(E)) {
2222-
auto &Ctx = Ty->getASTContext();
2223-
printSourceLoc(E->getTrailingQuoteLoc(), &Ctx, "trailing_quote_loc");
2224-
}
22252220
printField(E->getLiteralCapacity(), "literal_capacity", ExprModifierColor);
22262221
printField(E->getInterpolationCount(), "interpolation_count",
22272222
ExprModifierColor);
@@ -3044,12 +3039,6 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
30443039
void visitEditorPlaceholderExpr(EditorPlaceholderExpr *E, StringRef label) {
30453040
printCommon(E, "editor_placeholder_expr", label);
30463041

3047-
// Print the trailing angle bracket location
3048-
if (auto Ty = GetTypeOfExpr(E)) {
3049-
auto &Ctx = Ty->getASTContext();
3050-
printSourceLoc(E->getTrailingAngleBracketLoc(), &Ctx,
3051-
"trailing_angle_bracket_loc");
3052-
}
30533042
auto *TyR = E->getPlaceholderTypeRepr();
30543043
auto *ExpTyR = E->getTypeForExpansion();
30553044
if (TyR)

lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,11 +2010,6 @@ parseStringSegments(SmallVectorImpl<Lexer::StringSegment> &Segments,
20102010
consumeExtraToken(Token(tok::string_literal,
20112011
CharSourceRange(SourceMgr, TokenLoc, TokEnd).str(),
20122012
CommentLength));
2013-
2014-
// Make an unknown token to encapsulate the entire string segment and add
2015-
// such token to the context.
2016-
Token content(tok::string_segment,
2017-
CharSourceRange(Segment.Loc, Segment.Length).str());
20182013
break;
20192014
}
20202015

@@ -2106,30 +2101,10 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
21062101
// The start location of the entire string literal.
21072102
SourceLoc Loc = Tok.getLoc();
21082103

2109-
StringRef OpenDelimiterStr, OpenQuoteStr, CloseQuoteStr, CloseDelimiterStr;
2110-
unsigned DelimiterLength = Tok.getCustomDelimiterLen();
2111-
unsigned QuoteLength;
2112-
tok QuoteKind;
2113-
std::tie(QuoteLength, QuoteKind) =
2114-
Tok.isMultilineString() ? std::make_tuple(3, tok::multiline_string_quote)
2115-
: std::make_tuple(1, Tok.getText().startswith("\'") ?
2116-
tok::single_quote: tok::string_quote);
2117-
unsigned CloseQuoteBegin = Tok.getLength() - DelimiterLength - QuoteLength;
2118-
2119-
OpenDelimiterStr = Tok.getRawText().take_front(DelimiterLength);
2120-
OpenQuoteStr = Tok.getRawText().substr(DelimiterLength, QuoteLength);
2121-
CloseQuoteStr = Tok.getRawText().substr(CloseQuoteBegin, QuoteLength);
2122-
CloseDelimiterStr = Tok.getRawText().take_back(DelimiterLength);
2123-
2124-
// Make unknown tokens to represent the open and close quote.
2125-
Token OpenQuote(QuoteKind, OpenQuoteStr);
2126-
Token CloseQuote(QuoteKind, CloseQuoteStr);
2127-
21282104
// The simple case: just a single literal segment.
21292105
if (Segments.size() == 1 &&
21302106
Segments.front().Kind == Lexer::StringSegment::Literal) {
2131-
consumeExtraToken(Tok);
2132-
consumeTokenWithoutFeedingReceiver();
2107+
consumeToken();
21332108

21342109
return makeParserResult(
21352110
createStringLiteralExprFromSegment(Context, L, Segments.front(), Loc));
@@ -2178,8 +2153,7 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
21782153
}
21792154

21802155
return makeParserResult(Status, new (Context) InterpolatedStringLiteralExpr(
2181-
Loc, Loc.getAdvancedLoc(CloseQuoteBegin),
2182-
LiteralCapacity, InterpolationCount,
2156+
Loc, LiteralCapacity, InterpolationCount,
21832157
AppendingExpr));
21842158
}
21852159

test/Parse/source_locs.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)