Skip to content

Commit 8f82320

Browse files
committed
---
yaml --- r: 347867 b: refs/heads/master c: 98f25e0 h: refs/heads/master i: 347865: ce7229e 347863: 57b0eae
1 parent e393e91 commit 8f82320

File tree

6 files changed

+44
-7
lines changed

6 files changed

+44
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: fef9eeab4a8f64f91ece7261fd3f4a629e2abd5b
2+
refs/heads/master: 98f25e0af428f0159f12613cf7130750cc269339
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/Expr.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,15 +953,25 @@ class TapExpr : public Expr {
953953
class InterpolatedStringLiteralExpr : public LiteralExpr {
954954
/// Points at the beginning quote.
955955
SourceLoc Loc;
956+
/// Points at the ending quote.
957+
/// Needed for the upcoming \c ASTScope subsystem because lookups can be
958+
/// targeted to inside an \c InterpolatedStringLiteralExpr. It would be nicer
959+
/// to use \c EndLoc for this value, but then \c Lexer::getLocForEndOfToken()
960+
/// would not work for \c stringLiteral->getEndLoc().
961+
SourceLoc TrailingQuoteLoc;
956962
TapExpr *AppendingExpr;
957963
Expr *SemanticExpr;
958964

959965
public:
960-
InterpolatedStringLiteralExpr(SourceLoc Loc, unsigned LiteralCapacity,
966+
InterpolatedStringLiteralExpr(SourceLoc Loc,
967+
SourceLoc TrailingQuoteLoc,
968+
unsigned LiteralCapacity,
961969
unsigned InterpolationCount,
962970
TapExpr *AppendingExpr)
963971
: LiteralExpr(ExprKind::InterpolatedStringLiteral, /*Implicit=*/false),
964-
Loc(Loc), AppendingExpr(AppendingExpr), SemanticExpr() {
972+
Loc(Loc),
973+
TrailingQuoteLoc(TrailingQuoteLoc),
974+
AppendingExpr(AppendingExpr), SemanticExpr() {
965975
Bits.InterpolatedStringLiteralExpr.InterpolationCount = InterpolationCount;
966976
Bits.InterpolatedStringLiteralExpr.LiteralCapacity = LiteralCapacity;
967977
}
@@ -998,6 +1008,11 @@ class InterpolatedStringLiteralExpr : public LiteralExpr {
9981008
// token, so the range should be (Start == End).
9991009
return Loc;
10001010
}
1011+
SourceLoc getTrailingQuoteLoc() const {
1012+
// Except when computing a SourceRange for an ASTScope. Then the range
1013+
// must be (Start - TrainingQuoteLoc).
1014+
return TrailingQuoteLoc;
1015+
}
10011016

10021017
/// Call the \c callback with information about each segment in turn.
10031018
void forEachSegment(ASTContext &Ctx,

trunk/lib/AST/ASTDumper.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,19 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
19301930
}
19311931
void visitInterpolatedStringLiteralExpr(InterpolatedStringLiteralExpr *E) {
19321932
printCommon(E, "interpolated_string_literal_expr");
1933-
PrintWithColorRAII(OS, LiteralValueColor) << " literal_capacity="
1933+
1934+
// Print the trailing quote location
1935+
if (auto Ty = GetTypeOfExpr(E)) {
1936+
auto &Ctx = Ty->getASTContext();
1937+
auto TQL = E->getTrailingQuoteLoc();
1938+
if (TQL.isValid()) {
1939+
PrintWithColorRAII(OS, LocationColor) << " trailing_quote_loc=";
1940+
TQL.print(PrintWithColorRAII(OS, LocationColor).getOS(),
1941+
Ctx.SourceMgr);
1942+
}
1943+
}
1944+
PrintWithColorRAII(OS, LiteralValueColor)
1945+
<< " literal_capacity="
19341946
<< E->getLiteralCapacity() << " interpolation_count="
19351947
<< E->getInterpolationCount() << '\n';
19361948
printRec(E->getAppendingExpr());

trunk/lib/AST/Expr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ static LiteralExpr *
813813
shallowCloneImpl(const InterpolatedStringLiteralExpr *E, ASTContext &Ctx,
814814
llvm::function_ref<Type(const Expr *)> getType) {
815815
auto res = new (Ctx) InterpolatedStringLiteralExpr(E->getLoc(),
816+
E->getTrailingQuoteLoc(),
816817
E->getLiteralCapacity(),
817818
E->getInterpolationCount(),
818819
E->getAppendingExpr());

trunk/lib/Parse/ParseExpr.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,8 +2039,8 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
20392039
// Return an error, but include an empty InterpolatedStringLiteralExpr
20402040
// so that parseDeclPoundDiagnostic() can figure out why this string
20412041
// literal was bad.
2042-
return makeParserErrorResult(
2043-
new (Context) InterpolatedStringLiteralExpr(Loc, 0, 0, nullptr));
2042+
return makeParserErrorResult(new (Context) InterpolatedStringLiteralExpr(
2043+
Loc, Loc.getAdvancedLoc(CloseQuoteBegin), 0, 0, nullptr));
20442044
}
20452045

20462046
unsigned LiteralCapacity = 0;
@@ -2093,7 +2093,8 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
20932093
}
20942094

20952095
return makeParserResult(Status, new (Context) InterpolatedStringLiteralExpr(
2096-
Loc, LiteralCapacity, InterpolationCount,
2096+
Loc, Loc.getAdvancedLoc(CloseQuoteBegin),
2097+
LiteralCapacity, InterpolationCount,
20972098
AppendingExpr));
20982099
}
20992100

trunk/test/Parse/source_locs.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Check source locations (only InterpolatedStringLiteral for now).
2+
3+
func string_interpolation() {
4+
"\("abc")"
5+
}
6+
7+
// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
8+
// CHECK: (interpolated_string_literal_expr {{.*}} trailing_quote_loc=SOURCE_DIR/test/Parse/source_locs.swift:4:12 {{.*}}

0 commit comments

Comments
 (0)