Skip to content

Commit 6164f5b

Browse files
author
David Ungar
committed
Add TrailingAngleBrackLoc to EditorPlaceholder for upcoming scope code.
1 parent 967f1e6 commit 6164f5b

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

include/swift/AST/Expr.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4666,16 +4666,19 @@ class UnresolvedPatternExpr : public Expr {
46664666
class EditorPlaceholderExpr : public Expr {
46674667
Identifier Placeholder;
46684668
SourceLoc Loc;
4669+
SourceLoc TrailingAngleBracketLoc;
46694670
TypeLoc PlaceholderTy;
46704671
TypeRepr *ExpansionTyR;
46714672
Expr *SemanticExpr;
46724673

46734674
public:
46744675
EditorPlaceholderExpr(Identifier Placeholder, SourceLoc Loc,
4676+
SourceLoc TrailingAngleBracketLoc,
46754677
TypeLoc PlaceholderTy,
46764678
TypeRepr *ExpansionTyR)
46774679
: Expr(ExprKind::EditorPlaceholder, /*Implicit=*/false),
46784680
Placeholder(Placeholder), Loc(Loc),
4681+
TrailingAngleBracketLoc(TrailingAngleBracketLoc),
46794682
PlaceholderTy(PlaceholderTy),
46804683
ExpansionTyR(ExpansionTyR),
46814684
SemanticExpr(nullptr) {
@@ -4685,6 +4688,9 @@ class EditorPlaceholderExpr : public Expr {
46854688
SourceRange getSourceRange() const { return Loc; }
46864689
TypeLoc &getTypeLoc() { return PlaceholderTy; }
46874690
TypeLoc getTypeLoc() const { return PlaceholderTy; }
4691+
SourceLoc getTrailingAngleBracketLoc() const {
4692+
return TrailingAngleBracketLoc;
4693+
}
46884694

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

lib/AST/ASTDumper.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,19 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
26352635
PrintWithColorRAII(OS, ParenthesisColor) << ')';
26362636
}
26372637
void visitEditorPlaceholderExpr(EditorPlaceholderExpr *E) {
2638-
printCommon(E, "editor_placeholder_expr") << '\n';
2638+
printCommon(E, "editor_placeholder_expr") << ' ';
2639+
2640+
// Print the trailing angle bracket location
2641+
if (auto Ty = GetTypeOfExpr(E)) {
2642+
auto &Ctx = Ty->getASTContext();
2643+
auto TABL = E->getTrailingAngleBracketLoc();
2644+
if (TABL.isValid()) {
2645+
PrintWithColorRAII(OS, LocationColor) << " trailing_angle_bracket_loc=";
2646+
TABL.print(PrintWithColorRAII(OS, LocationColor).getOS(),
2647+
Ctx.SourceMgr);
2648+
}
2649+
}
2650+
OS << '\n';
26392651
auto *TyR = E->getTypeLoc().getTypeRepr();
26402652
auto *ExpTyR = E->getTypeForExpansion();
26412653
if (TyR)

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,7 @@ Expr *Parser::parseExprEditorPlaceholder(Token PlaceholderTok,
23852385
parseTypeForPlaceholder(TyLoc, ExpansionTyR);
23862386
return new (Context) EditorPlaceholderExpr(PlaceholderId,
23872387
PlaceholderTok.getLoc(),
2388+
PlaceholderTok.getRange().getEnd(),
23882389
TyLoc, ExpansionTyR);
23892390
}
23902391

test/Parse/source_locs.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
func string_interpolation() {
44
"\("abc")"
5+
<#Int#>
56
}
67

7-
// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
8+
// RUN: not %target-swift-frontend -dump-ast %s | %FileCheck %s
89
// CHECK: (interpolated_string_literal_expr {{.*}} trailing_quote_loc=SOURCE_DIR{{/|\\}}test{{/|\\}}Parse{{/|\\}}source_locs.swift:4:12 {{.*}}
10+
// CHECK: (editor_placeholder_expr type='()' {{.*}} trailing_angle_bracket_loc=SOURCE_DIR{{/|\\}}test{{/|\\}}Parse{{/|\\}}source_locs.swift:5:10
11+

0 commit comments

Comments
 (0)