Skip to content

Commit 7b5ab28

Browse files
authored
[NFC][Clang] Adopt simplified getTrailingObjects in Stmt (#143250)
1 parent cf5e2b6 commit 7b5ab28

File tree

2 files changed

+47
-72
lines changed

2 files changed

+47
-72
lines changed

clang/include/clang/AST/Stmt.h

Lines changed: 43 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,10 +1953,6 @@ class CaseStmt final
19531953
return NumMandatoryStmtPtr + caseStmtIsGNURange();
19541954
}
19551955

1956-
unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1957-
return caseStmtIsGNURange();
1958-
}
1959-
19601956
unsigned lhsOffset() const { return LhsOffset; }
19611957
unsigned rhsOffset() const { return LhsOffset + caseStmtIsGNURange(); }
19621958
unsigned subStmtOffset() const { return rhsOffset() + SubStmtOffsetFromRhs; }
@@ -2228,10 +2224,8 @@ class AttributedStmt final
22282224
std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
22292225
}
22302226

2231-
const Attr *const *getAttrArrayPtr() const {
2232-
return getTrailingObjects<const Attr *>();
2233-
}
2234-
const Attr **getAttrArrayPtr() { return getTrailingObjects<const Attr *>(); }
2227+
const Attr *const *getAttrArrayPtr() const { return getTrailingObjects(); }
2228+
const Attr **getAttrArrayPtr() { return getTrailingObjects(); }
22352229

22362230
public:
22372231
static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
@@ -2543,7 +2537,7 @@ class SwitchStmt final : public Stmt,
25432537
SourceLocation LParenLoc;
25442538
SourceLocation RParenLoc;
25452539

2546-
unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2540+
unsigned numTrailingStatements() const {
25472541
return NumMandatoryStmtPtr + hasInitStorage() + hasVarStorage();
25482542
}
25492543

@@ -2579,40 +2573,34 @@ class SwitchStmt final : public Stmt,
25792573
bool hasVarStorage() const { return SwitchStmtBits.HasVar; }
25802574

25812575
Expr *getCond() {
2582-
return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2576+
return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
25832577
}
25842578

25852579
const Expr *getCond() const {
2586-
return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2580+
return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
25872581
}
25882582

25892583
void setCond(Expr *Cond) {
2590-
getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2584+
getTrailingObjects()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
25912585
}
25922586

2593-
Stmt *getBody() { return getTrailingObjects<Stmt *>()[bodyOffset()]; }
2594-
const Stmt *getBody() const {
2595-
return getTrailingObjects<Stmt *>()[bodyOffset()];
2596-
}
2587+
Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; }
2588+
const Stmt *getBody() const { return getTrailingObjects()[bodyOffset()]; }
25972589

2598-
void setBody(Stmt *Body) {
2599-
getTrailingObjects<Stmt *>()[bodyOffset()] = Body;
2600-
}
2590+
void setBody(Stmt *Body) { getTrailingObjects()[bodyOffset()] = Body; }
26012591

26022592
Stmt *getInit() {
2603-
return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2604-
: nullptr;
2593+
return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr;
26052594
}
26062595

26072596
const Stmt *getInit() const {
2608-
return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2609-
: nullptr;
2597+
return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr;
26102598
}
26112599

26122600
void setInit(Stmt *Init) {
26132601
assert(hasInitStorage() &&
26142602
"This switch statement has no storage for an init statement!");
2615-
getTrailingObjects<Stmt *>()[initOffset()] = Init;
2603+
getTrailingObjects()[initOffset()] = Init;
26162604
}
26172605

26182606
/// Retrieve the variable declared in this "switch" statement, if any.
@@ -2636,20 +2624,20 @@ class SwitchStmt final : public Stmt,
26362624
/// If this SwitchStmt has a condition variable, return the faux DeclStmt
26372625
/// associated with the creation of that condition variable.
26382626
DeclStmt *getConditionVariableDeclStmt() {
2639-
return hasVarStorage() ? static_cast<DeclStmt *>(
2640-
getTrailingObjects<Stmt *>()[varOffset()])
2641-
: nullptr;
2627+
return hasVarStorage()
2628+
? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2629+
: nullptr;
26422630
}
26432631

26442632
const DeclStmt *getConditionVariableDeclStmt() const {
2645-
return hasVarStorage() ? static_cast<DeclStmt *>(
2646-
getTrailingObjects<Stmt *>()[varOffset()])
2647-
: nullptr;
2633+
return hasVarStorage()
2634+
? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2635+
: nullptr;
26482636
}
26492637

26502638
void setConditionVariableDeclStmt(DeclStmt *CondVar) {
26512639
assert(hasVarStorage());
2652-
getTrailingObjects<Stmt *>()[varOffset()] = CondVar;
2640+
getTrailingObjects()[varOffset()] = CondVar;
26532641
}
26542642

26552643
SwitchCase *getSwitchCaseList() { return FirstCase; }
@@ -2693,15 +2681,13 @@ class SwitchStmt final : public Stmt,
26932681

26942682
// Iterators
26952683
child_range children() {
2696-
return child_range(getTrailingObjects<Stmt *>(),
2697-
getTrailingObjects<Stmt *>() +
2698-
numTrailingObjects(OverloadToken<Stmt *>()));
2684+
return child_range(getTrailingObjects(),
2685+
getTrailingObjects() + numTrailingStatements());
26992686
}
27002687

27012688
const_child_range children() const {
2702-
return const_child_range(getTrailingObjects<Stmt *>(),
2703-
getTrailingObjects<Stmt *>() +
2704-
numTrailingObjects(OverloadToken<Stmt *>()));
2689+
return const_child_range(getTrailingObjects(),
2690+
getTrailingObjects() + numTrailingStatements());
27052691
}
27062692

27072693
static bool classof(const Stmt *T) {
@@ -2738,7 +2724,7 @@ class WhileStmt final : public Stmt,
27382724
unsigned condOffset() const { return VarOffset + hasVarStorage(); }
27392725
unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
27402726

2741-
unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2727+
unsigned numTrailingStatements() const {
27422728
return NumMandatoryStmtPtr + hasVarStorage();
27432729
}
27442730

@@ -2764,25 +2750,21 @@ class WhileStmt final : public Stmt,
27642750
bool hasVarStorage() const { return WhileStmtBits.HasVar; }
27652751

27662752
Expr *getCond() {
2767-
return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2753+
return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
27682754
}
27692755

27702756
const Expr *getCond() const {
2771-
return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2757+
return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
27722758
}
27732759

27742760
void setCond(Expr *Cond) {
2775-
getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2761+
getTrailingObjects()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
27762762
}
27772763

2778-
Stmt *getBody() { return getTrailingObjects<Stmt *>()[bodyOffset()]; }
2779-
const Stmt *getBody() const {
2780-
return getTrailingObjects<Stmt *>()[bodyOffset()];
2781-
}
2764+
Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; }
2765+
const Stmt *getBody() const { return getTrailingObjects()[bodyOffset()]; }
27822766

2783-
void setBody(Stmt *Body) {
2784-
getTrailingObjects<Stmt *>()[bodyOffset()] = Body;
2785-
}
2767+
void setBody(Stmt *Body) { getTrailingObjects()[bodyOffset()] = Body; }
27862768

27872769
/// Retrieve the variable declared in this "while" statement, if any.
27882770
///
@@ -2804,20 +2786,20 @@ class WhileStmt final : public Stmt,
28042786
/// If this WhileStmt has a condition variable, return the faux DeclStmt
28052787
/// associated with the creation of that condition variable.
28062788
DeclStmt *getConditionVariableDeclStmt() {
2807-
return hasVarStorage() ? static_cast<DeclStmt *>(
2808-
getTrailingObjects<Stmt *>()[varOffset()])
2809-
: nullptr;
2789+
return hasVarStorage()
2790+
? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2791+
: nullptr;
28102792
}
28112793

28122794
const DeclStmt *getConditionVariableDeclStmt() const {
2813-
return hasVarStorage() ? static_cast<DeclStmt *>(
2814-
getTrailingObjects<Stmt *>()[varOffset()])
2815-
: nullptr;
2795+
return hasVarStorage()
2796+
? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2797+
: nullptr;
28162798
}
28172799

28182800
void setConditionVariableDeclStmt(DeclStmt *CondVar) {
28192801
assert(hasVarStorage());
2820-
getTrailingObjects<Stmt *>()[varOffset()] = CondVar;
2802+
getTrailingObjects()[varOffset()] = CondVar;
28212803
}
28222804

28232805
SourceLocation getWhileLoc() const { return WhileStmtBits.WhileLoc; }
@@ -2839,15 +2821,13 @@ class WhileStmt final : public Stmt,
28392821

28402822
// Iterators
28412823
child_range children() {
2842-
return child_range(getTrailingObjects<Stmt *>(),
2843-
getTrailingObjects<Stmt *>() +
2844-
numTrailingObjects(OverloadToken<Stmt *>()));
2824+
return child_range(getTrailingObjects(),
2825+
getTrailingObjects() + numTrailingStatements());
28452826
}
28462827

28472828
const_child_range children() const {
2848-
return const_child_range(getTrailingObjects<Stmt *>(),
2849-
getTrailingObjects<Stmt *>() +
2850-
numTrailingObjects(OverloadToken<Stmt *>()));
2829+
return const_child_range(getTrailingObjects(),
2830+
getTrailingObjects() + numTrailingStatements());
28512831
}
28522832
};
28532833

@@ -3158,10 +3138,6 @@ class ReturnStmt final
31583138
/// True if this ReturnStmt has storage for an NRVO candidate.
31593139
bool hasNRVOCandidate() const { return ReturnStmtBits.HasNRVOCandidate; }
31603140

3161-
unsigned numTrailingObjects(OverloadToken<const VarDecl *>) const {
3162-
return hasNRVOCandidate();
3163-
}
3164-
31653141
/// Build a return statement.
31663142
ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate);
31673143

@@ -3187,8 +3163,7 @@ class ReturnStmt final
31873163
/// The optimization itself can only be performed if the variable is
31883164
/// also marked as an NRVO object.
31893165
const VarDecl *getNRVOCandidate() const {
3190-
return hasNRVOCandidate() ? *getTrailingObjects<const VarDecl *>()
3191-
: nullptr;
3166+
return hasNRVOCandidate() ? *getTrailingObjects() : nullptr;
31923167
}
31933168

31943169
/// Set the variable that might be used for the named return value
@@ -3197,7 +3172,7 @@ class ReturnStmt final
31973172
void setNRVOCandidate(const VarDecl *Var) {
31983173
assert(hasNRVOCandidate() &&
31993174
"This return statement has no storage for an NRVO candidate!");
3200-
*getTrailingObjects<const VarDecl *>() = Var;
3175+
*getTrailingObjects() = Var;
32013176
}
32023177

32033178
SourceLocation getReturnLoc() const { return ReturnStmtBits.RetLoc; }

clang/lib/AST/Stmt.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,12 +1154,12 @@ void SwitchStmt::setConditionVariable(const ASTContext &Ctx, VarDecl *V) {
11541154
"This switch statement has no storage for a condition variable!");
11551155

11561156
if (!V) {
1157-
getTrailingObjects<Stmt *>()[varOffset()] = nullptr;
1157+
getTrailingObjects()[varOffset()] = nullptr;
11581158
return;
11591159
}
11601160

11611161
SourceRange VarRange = V->getSourceRange();
1162-
getTrailingObjects<Stmt *>()[varOffset()] = new (Ctx)
1162+
getTrailingObjects()[varOffset()] = new (Ctx)
11631163
DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd());
11641164
}
11651165

@@ -1215,12 +1215,12 @@ void WhileStmt::setConditionVariable(const ASTContext &Ctx, VarDecl *V) {
12151215
"This while statement has no storage for a condition variable!");
12161216

12171217
if (!V) {
1218-
getTrailingObjects<Stmt *>()[varOffset()] = nullptr;
1218+
getTrailingObjects()[varOffset()] = nullptr;
12191219
return;
12201220
}
12211221

12221222
SourceRange VarRange = V->getSourceRange();
1223-
getTrailingObjects<Stmt *>()[varOffset()] = new (Ctx)
1223+
getTrailingObjects()[varOffset()] = new (Ctx)
12241224
DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd());
12251225
}
12261226

0 commit comments

Comments
 (0)