Skip to content

Commit 5d3f717

Browse files
committed
Remove setters from CXXTypeidExpr and CXXUuidofExpr.
We generally prefer to have the ASTReader directly set fields rather than including public setter functions.
1 parent b8aa1e3 commit 5d3f717

File tree

2 files changed

+12
-38
lines changed

2 files changed

+12
-38
lines changed

clang/include/clang/AST/ExprCXX.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ class CXXStdInitializerListExpr : public Expr {
778778
///
779779
/// This represents code like \c typeid(int) or \c typeid(*objPtr)
780780
class CXXTypeidExpr : public Expr {
781+
friend class ASTStmtReader;
782+
781783
private:
782784
llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
783785
SourceRange Range;
@@ -818,22 +820,11 @@ class CXXTypeidExpr : public Expr {
818820
assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
819821
return Operand.get<TypeSourceInfo *>();
820822
}
821-
822-
void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
823-
assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
824-
Operand = TSI;
825-
}
826-
827823
Expr *getExprOperand() const {
828824
assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
829825
return static_cast<Expr*>(Operand.get<Stmt *>());
830826
}
831827

832-
void setExprOperand(Expr *E) {
833-
assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
834-
Operand = E;
835-
}
836-
837828
SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
838829
SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
839830
SourceRange getSourceRange() const LLVM_READONLY { return Range; }
@@ -1000,6 +991,8 @@ class MSPropertySubscriptExpr : public Expr {
1000991
///
1001992
/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
1002993
class CXXUuidofExpr : public Expr {
994+
friend class ASTStmtReader;
995+
1003996
private:
1004997
llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
1005998
StringRef UuidStr;
@@ -1038,22 +1031,11 @@ class CXXUuidofExpr : public Expr {
10381031
assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
10391032
return Operand.get<TypeSourceInfo *>();
10401033
}
1041-
1042-
void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
1043-
assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
1044-
Operand = TSI;
1045-
}
1046-
10471034
Expr *getExprOperand() const {
10481035
assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
10491036
return static_cast<Expr*>(Operand.get<Stmt *>());
10501037
}
10511038

1052-
void setExprOperand(Expr *E) {
1053-
assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
1054-
Operand = E;
1055-
}
1056-
10571039
void setUuidStr(StringRef US) { UuidStr = US; }
10581040
StringRef getUuidStr() const { return UuidStr; }
10591041

clang/lib/Serialization/ASTReaderStmt.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,14 +1748,10 @@ void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
17481748
void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
17491749
VisitExpr(E);
17501750
E->setSourceRange(readSourceRange());
1751-
if (E->isTypeOperand()) { // typeid(int)
1752-
E->setTypeOperandSourceInfo(
1753-
readTypeSourceInfo());
1754-
return;
1755-
}
1756-
1757-
// typeid(42+2)
1758-
E->setExprOperand(Record.readSubExpr());
1751+
if (E->isTypeOperand())
1752+
E->Operand = readTypeSourceInfo();
1753+
else
1754+
E->Operand = Record.readSubExpr();
17591755
}
17601756

17611757
void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
@@ -2162,14 +2158,10 @@ void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
21622158
E->setSourceRange(readSourceRange());
21632159
std::string UuidStr = readString();
21642160
E->setUuidStr(StringRef(UuidStr).copy(Record.getContext()));
2165-
if (E->isTypeOperand()) { // __uuidof(ComType)
2166-
E->setTypeOperandSourceInfo(
2167-
readTypeSourceInfo());
2168-
return;
2169-
}
2170-
2171-
// __uuidof(expr)
2172-
E->setExprOperand(Record.readSubExpr());
2161+
if (E->isTypeOperand())
2162+
E->Operand = readTypeSourceInfo();
2163+
else
2164+
E->Operand = Record.readSubExpr();
21732165
}
21742166

21752167
void ASTStmtReader::VisitSEHLeaveStmt(SEHLeaveStmt *S) {

0 commit comments

Comments
 (0)