Skip to content

Commit 8af4db2

Browse files
committed
[AST] Add getter for content of BraceStmt without the braces
1 parent 9f6bc90 commit 8af4db2

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

include/swift/AST/Stmt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ class BraceStmt final : public Stmt,
171171
SourceLoc getStartLoc() const;
172172
SourceLoc getEndLoc() const;
173173

174+
SourceLoc getContentStartLoc() const;
175+
SourceLoc getContentEndLoc() const;
176+
/// The range of the brace statement without the braces.
177+
SourceRange getContentRange() const {
178+
return {getContentStartLoc(), getContentEndLoc()};
179+
}
180+
174181
bool empty() const { return getNumElements() == 0; }
175182
unsigned getNumElements() const { return Bits.BraceStmt.NumElements; }
176183

lib/AST/Stmt.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ SourceLoc BraceStmt::getStartLoc() const {
160160
if (LBLoc) {
161161
return LBLoc;
162162
}
163+
return getContentStartLoc();
164+
}
165+
166+
SourceLoc BraceStmt::getEndLoc() const {
167+
if (RBLoc) {
168+
return RBLoc;
169+
}
170+
return getContentEndLoc();
171+
}
172+
173+
SourceLoc BraceStmt::getContentStartLoc() const {
163174
for (auto elt : getElements()) {
164175
if (auto loc = elt.getStartLoc()) {
165176
return loc;
@@ -168,10 +179,7 @@ SourceLoc BraceStmt::getStartLoc() const {
168179
return SourceLoc();
169180
}
170181

171-
SourceLoc BraceStmt::getEndLoc() const {
172-
if (RBLoc) {
173-
return RBLoc;
174-
}
182+
SourceLoc BraceStmt::getContentEndLoc() const {
175183
for (auto elt : llvm::reverse(getElements())) {
176184
if (auto loc = elt.getEndLoc()) {
177185
return loc;

0 commit comments

Comments
 (0)