Skip to content

Commit 9821d46

Browse files
author
David Ungar
authored
Merge pull request swiftlang#25105 from davidungar/EdPlH
Add TrailingAngleBrackLoc to EditorPlaceholder for upcoming scope code.
2 parents 4904888 + ed097f8 commit 9821d46

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

include/swift/AST/Expr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4685,6 +4685,9 @@ class EditorPlaceholderExpr : public Expr {
46854685
SourceRange getSourceRange() const { return Loc; }
46864686
TypeLoc &getTypeLoc() { return PlaceholderTy; }
46874687
TypeLoc getTypeLoc() const { return PlaceholderTy; }
4688+
SourceLoc getTrailingAngleBracketLoc() const {
4689+
return Loc.getAdvancedLoc(Placeholder.getLength() - 1);
4690+
}
46884691

46894692
/// The TypeRepr to be considered for placeholder expansion.
46904693
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)

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:9
11+

0 commit comments

Comments
 (0)