Skip to content

Commit a7d33aa

Browse files
committed
Fix to make minimum AST nodes for StringLiteralExpr
1 parent 9155ed8 commit a7d33aa

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,39 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
20312031
llvm::SaveAndRestore<Token> SavedTok(Tok);
20322032
llvm::SaveAndRestore<ParsedTrivia> SavedLeadingTrivia(LeadingTrivia);
20332033
llvm::SaveAndRestore<ParsedTrivia> SavedTrailingTrivia(TrailingTrivia);
2034+
2035+
// The simple case: just a single literal segment.
2036+
if (Segments.size() == 1 &&
2037+
Segments.front().Kind == Lexer::StringSegment::Literal) {
2038+
{
2039+
SyntaxParsingContext SegmentsCtx(SyntaxContext,
2040+
SyntaxKind::StringLiteralSegments);
2041+
2042+
// First segment shall inherit the attached comments.
2043+
unsigned CommentLength = 0;
2044+
CommentLength = SourceMgr.getByteDistance(EntireTok.getCommentRange().
2045+
getStart(), Loc);
2046+
consumeExtraToken(Token(tok::string_literal,
2047+
CharSourceRange(SourceMgr, Loc, EndLoc).str(),
2048+
CommentLength));
2049+
2050+
SyntaxParsingContext StrSegContext(SyntaxContext,
2051+
SyntaxKind::StringSegment);
2052+
2053+
// Make an unknown token to encapsulate the entire string segment and add
2054+
// such token to the context.
2055+
auto Segment = Segments.front();
2056+
Token content(tok::string_segment,
2057+
CharSourceRange(Segment.Loc, Segment.Length).str());
2058+
SyntaxContext->addToken(content, EmptyTrivia, EmptyTrivia);
2059+
}
2060+
2061+
// Add the close quote the context; the quote should have a void leading trivia
2062+
// and the trailing trivia of the entire string token.
2063+
SyntaxContext->addToken(CloseQuote, EmptyTrivia, EntireTrailingTrivia);
2064+
2065+
return makeParserResult(createStringLiteralExprFromSegment(Context, L, Segments.front(), Loc));
2066+
}
20342067

20352068
unsigned LiteralCapacity = 0;
20362069
unsigned InterpolationCount = 0;
@@ -2073,13 +2106,6 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
20732106
Status.setIsParseError();
20742107
return makeParserResult(Status, new (Context) ErrorExpr(Loc));
20752108
}
2076-
2077-
// The simple case: just a single literal segment.
2078-
if (Segments.size() == 1 &&
2079-
Segments.front().Kind == Lexer::StringSegment::Literal) {
2080-
return makeParserResult(
2081-
createStringLiteralExprFromSegment(Context, L, Segments.front(), Loc));
2082-
}
20832109

20842110
return makeParserResult(Status, new (Context) InterpolatedStringLiteralExpr(
20852111
Loc, LiteralCapacity, InterpolationCount,

0 commit comments

Comments
 (0)