Skip to content

[AST] Migrate away from PointerUnion::{is,get} (NFC) #119523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,9 @@ class DeclaratorDecl : public ValueDecl {
/// ignoring outer template declarations.
SourceLocation InnerLocStart;

bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); }
ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); }
const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); }
bool hasExtInfo() const { return isa<ExtInfo *>(DeclInfo); }
ExtInfo *getExtInfo() { return cast<ExtInfo *>(DeclInfo); }
const ExtInfo *getExtInfo() const { return cast<ExtInfo *>(DeclInfo); }

protected:
DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L,
Expand All @@ -762,9 +762,8 @@ class DeclaratorDecl : public ValueDecl {
friend class ASTDeclWriter;

TypeSourceInfo *getTypeSourceInfo() const {
return hasExtInfo()
? getExtInfo()->TInfo
: DeclInfo.get<TypeSourceInfo*>();
return hasExtInfo() ? getExtInfo()->TInfo
: cast<TypeSourceInfo *>(DeclInfo);
}

void setTypeSourceInfo(TypeSourceInfo *TI) {
Expand Down Expand Up @@ -3587,10 +3586,10 @@ class TagDecl : public TypeDecl,
/// otherwise, it is a null (TypedefNameDecl) pointer.
llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;

bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo *>(); }
ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo *>(); }
bool hasExtInfo() const { return isa<ExtInfo *>(TypedefNameDeclOrQualifier); }
ExtInfo *getExtInfo() { return cast<ExtInfo *>(TypedefNameDeclOrQualifier); }
const ExtInfo *getExtInfo() const {
return TypedefNameDeclOrQualifier.get<ExtInfo *>();
return cast<ExtInfo *>(TypedefNameDeclOrQualifier);
}

protected:
Expand Down Expand Up @@ -3793,7 +3792,7 @@ class TagDecl : public TypeDecl,

TypedefNameDecl *getTypedefNameForAnonDecl() const {
return hasExtInfo() ? nullptr
: TypedefNameDeclOrQualifier.get<TypedefNameDecl *>();
: cast<TypedefNameDecl *>(TypedefNameDeclOrQualifier);
}

void setTypedefNameForAnonDecl(TypedefNameDecl *TDD);
Expand Down Expand Up @@ -4011,7 +4010,7 @@ class EnumDecl : public TagDecl {
return QualType();
if (const Type *T = IntegerType.dyn_cast<const Type*>())
return QualType(T, 0);
return IntegerType.get<TypeSourceInfo*>()->getType().getUnqualifiedType();
return cast<TypeSourceInfo *>(IntegerType)->getType().getUnqualifiedType();
}

/// Set the underlying integer type.
Expand Down
14 changes: 5 additions & 9 deletions clang/include/clang/AST/DeclBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,12 @@ class alignas(8) Decl {
/// // LexicalDC == global namespace
llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;

bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); }
bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); }
bool isInSemaDC() const { return isa<DeclContext *>(DeclCtx); }
bool isOutOfSemaDC() const { return isa<MultipleDC *>(DeclCtx); }

MultipleDC *getMultipleDC() const {
return DeclCtx.get<MultipleDC*>();
}
MultipleDC *getMultipleDC() const { return cast<MultipleDC *>(DeclCtx); }

DeclContext *getSemanticDC() const {
return DeclCtx.get<DeclContext*>();
}
DeclContext *getSemanticDC() const { return cast<DeclContext *>(DeclCtx); }

/// Loc - The location of this decl.
SourceLocation Loc;
Expand Down Expand Up @@ -1340,7 +1336,7 @@ class DeclListNode {
assert(Ptr && "dereferencing end() iterator");
if (DeclListNode *CurNode = Ptr.dyn_cast<DeclListNode*>())
return CurNode->D;
return Ptr.get<NamedDecl*>();
return cast<NamedDecl *>(Ptr);
}
void operator->() const { } // Unsupported.
bool operator==(const iterator &X) const { return Ptr == X.Ptr; }
Expand Down
16 changes: 8 additions & 8 deletions clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -2388,19 +2388,19 @@ class CXXCtorInitializer final {

/// Determine whether this initializer is initializing a base class.
bool isBaseInitializer() const {
return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
return isa<TypeSourceInfo *>(Initializee) && !IsDelegating;
}

/// Determine whether this initializer is initializing a non-static
/// data member.
bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
bool isMemberInitializer() const { return isa<FieldDecl *>(Initializee); }

bool isAnyMemberInitializer() const {
return isMemberInitializer() || isIndirectMemberInitializer();
}

bool isIndirectMemberInitializer() const {
return Initializee.is<IndirectFieldDecl*>();
return isa<IndirectFieldDecl *>(Initializee);
}

/// Determine whether this initializer is an implicit initializer
Expand All @@ -2416,7 +2416,7 @@ class CXXCtorInitializer final {
/// Determine whether this initializer is creating a delegating
/// constructor.
bool isDelegatingInitializer() const {
return Initializee.is<TypeSourceInfo*>() && IsDelegating;
return isa<TypeSourceInfo *>(Initializee) && IsDelegating;
}

/// Determine whether this initializer is a pack expansion.
Expand Down Expand Up @@ -2457,21 +2457,21 @@ class CXXCtorInitializer final {
/// non-static data member being initialized. Otherwise, returns null.
FieldDecl *getMember() const {
if (isMemberInitializer())
return Initializee.get<FieldDecl*>();
return cast<FieldDecl *>(Initializee);
return nullptr;
}

FieldDecl *getAnyMember() const {
if (isMemberInitializer())
return Initializee.get<FieldDecl*>();
return cast<FieldDecl *>(Initializee);
if (isIndirectMemberInitializer())
return Initializee.get<IndirectFieldDecl*>()->getAnonField();
return cast<IndirectFieldDecl *>(Initializee)->getAnonField();
return nullptr;
}

IndirectFieldDecl *getIndirectMember() const {
if (isIndirectMemberInitializer())
return Initializee.get<IndirectFieldDecl*>();
return cast<IndirectFieldDecl *>(Initializee);
return nullptr;
}

Expand Down
10 changes: 5 additions & 5 deletions clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
return PartialSpec->PartialSpecialization;

return SpecializedTemplate.get<ClassTemplateDecl*>();
return cast<ClassTemplateDecl *>(SpecializedTemplate);
}

/// Retrieve the set of template arguments that should be used
Expand Down Expand Up @@ -2013,7 +2013,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
return Info->TemplateArgsAsWritten;
return ExplicitInfo.get<const ASTTemplateArgumentListInfo *>();
return cast<const ASTTemplateArgumentListInfo *>(ExplicitInfo);
}

/// Set the template argument list as written in the sources.
Expand Down Expand Up @@ -2734,7 +2734,7 @@ class VarTemplateSpecializationDecl : public VarDecl,
SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
return PartialSpec->PartialSpecialization;

return SpecializedTemplate.get<VarTemplateDecl *>();
return cast<VarTemplateDecl *>(SpecializedTemplate);
}

/// Retrieve the set of template arguments that should be used
Expand Down Expand Up @@ -2782,7 +2782,7 @@ class VarTemplateSpecializationDecl : public VarDecl,
const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
return Info->TemplateArgsAsWritten;
return ExplicitInfo.get<const ASTTemplateArgumentListInfo *>();
return cast<const ASTTemplateArgumentListInfo *>(ExplicitInfo);
}

/// Set the template argument list as written in the sources.
Expand Down Expand Up @@ -3309,7 +3309,7 @@ inline NamedDecl *getAsNamedDecl(TemplateParameter P) {
return PD;
if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>())
return PD;
return P.get<TemplateTemplateParmDecl *>();
return cast<TemplateTemplateParmDecl *>(P);
}

inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) {
Expand Down
42 changes: 21 additions & 21 deletions clang/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ class CXXTypeidExpr : public Expr {
/// object. This is not a strong guarantee.
bool isMostDerived(const ASTContext &Context) const;

bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
bool isTypeOperand() const { return isa<TypeSourceInfo *>(Operand); }

/// Retrieves the type operand of this typeid() expression after
/// various required adjustments (removing reference types, cv-qualifiers).
Expand All @@ -887,11 +887,11 @@ class CXXTypeidExpr : public Expr {
/// Retrieve source information for the type operand.
TypeSourceInfo *getTypeOperandSourceInfo() const {
assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
return Operand.get<TypeSourceInfo *>();
return cast<TypeSourceInfo *>(Operand);
}
Expr *getExprOperand() const {
assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
return static_cast<Expr*>(Operand.get<Stmt *>());
return static_cast<Expr *>(cast<Stmt *>(Operand));
}

SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
Expand Down Expand Up @@ -1093,7 +1093,7 @@ class CXXUuidofExpr : public Expr {
Operand = (TypeSourceInfo*)nullptr;
}

bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
bool isTypeOperand() const { return isa<TypeSourceInfo *>(Operand); }

/// Retrieves the type operand of this __uuidof() expression after
/// various required adjustments (removing reference types, cv-qualifiers).
Expand All @@ -1102,11 +1102,11 @@ class CXXUuidofExpr : public Expr {
/// Retrieve source information for the type operand.
TypeSourceInfo *getTypeOperandSourceInfo() const {
assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
return Operand.get<TypeSourceInfo *>();
return cast<TypeSourceInfo *>(Operand);
}
Expr *getExprOperand() const {
assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
return static_cast<Expr*>(Operand.get<Stmt *>());
return static_cast<Expr *>(cast<Stmt *>(Operand));
}

MSGuidDecl *getGuidDecl() const { return Guid; }
Expand Down Expand Up @@ -4750,24 +4750,24 @@ class MaterializeTemporaryExpr : public Expr {
/// be materialized into a glvalue.
Expr *getSubExpr() const {
return cast<Expr>(
State.is<Stmt *>()
? State.get<Stmt *>()
: State.get<LifetimeExtendedTemporaryDecl *>()->getTemporaryExpr());
isa<Stmt *>(State)
? cast<Stmt *>(State)
: cast<LifetimeExtendedTemporaryDecl *>(State)->getTemporaryExpr());
}

/// Retrieve the storage duration for the materialized temporary.
StorageDuration getStorageDuration() const {
return State.is<Stmt *>() ? SD_FullExpression
: State.get<LifetimeExtendedTemporaryDecl *>()
return isa<Stmt *>(State) ? SD_FullExpression
: cast<LifetimeExtendedTemporaryDecl *>(State)
->getStorageDuration();
}

/// Get the storage for the constant value of a materialized temporary
/// of static storage duration.
APValue *getOrCreateValue(bool MayCreate) const {
assert(State.is<LifetimeExtendedTemporaryDecl *>() &&
assert(isa<LifetimeExtendedTemporaryDecl *>(State) &&
"the temporary has not been lifetime extended");
return State.get<LifetimeExtendedTemporaryDecl *>()->getOrCreateValue(
return cast<LifetimeExtendedTemporaryDecl *>(State)->getOrCreateValue(
MayCreate);
}

Expand All @@ -4782,8 +4782,8 @@ class MaterializeTemporaryExpr : public Expr {
/// Get the declaration which triggered the lifetime-extension of this
/// temporary, if any.
ValueDecl *getExtendingDecl() {
return State.is<Stmt *>() ? nullptr
: State.get<LifetimeExtendedTemporaryDecl *>()
return isa<Stmt *>(State) ? nullptr
: cast<LifetimeExtendedTemporaryDecl *>(State)
->getExtendingDecl();
}
const ValueDecl *getExtendingDecl() const {
Expand All @@ -4793,8 +4793,8 @@ class MaterializeTemporaryExpr : public Expr {
void setExtendingDecl(ValueDecl *ExtendedBy, unsigned ManglingNumber);

unsigned getManglingNumber() const {
return State.is<Stmt *>() ? 0
: State.get<LifetimeExtendedTemporaryDecl *>()
return isa<Stmt *>(State) ? 0
: cast<LifetimeExtendedTemporaryDecl *>(State)
->getManglingNumber();
}

Expand All @@ -4820,17 +4820,17 @@ class MaterializeTemporaryExpr : public Expr {

// Iterators
child_range children() {
return State.is<Stmt *>()
return isa<Stmt *>(State)
? child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1)
: State.get<LifetimeExtendedTemporaryDecl *>()->childrenExpr();
: cast<LifetimeExtendedTemporaryDecl *>(State)->childrenExpr();
}

const_child_range children() const {
return State.is<Stmt *>()
return isa<Stmt *>(State)
? const_child_range(State.getAddrOfPtr1(),
State.getAddrOfPtr1() + 1)
: const_cast<const LifetimeExtendedTemporaryDecl *>(
State.get<LifetimeExtendedTemporaryDecl *>())
cast<LifetimeExtendedTemporaryDecl *>(State))
->childrenExpr();
}
};
Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/AST/ExprConcepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ class TypeRequirement : public Requirement {
assert(Status == SS_SubstitutionFailure &&
"Attempted to get substitution diagnostic when there has been no "
"substitution failure.");
return Value.get<SubstitutionDiagnostic *>();
return cast<SubstitutionDiagnostic *>(Value);
}

TypeSourceInfo *getType() const {
assert(!isSubstitutionFailure() &&
"Attempted to get type when there has been a substitution failure.");
return Value.get<TypeSourceInfo *>();
return cast<TypeSourceInfo *>(Value);
}

static bool classof(const Requirement *R) {
Expand Down Expand Up @@ -409,14 +409,14 @@ class ExprRequirement : public Requirement {
assert(isExprSubstitutionFailure() &&
"Attempted to get expression substitution diagnostic when there has "
"been no expression substitution failure");
return Value.get<SubstitutionDiagnostic *>();
return cast<SubstitutionDiagnostic *>(Value);
}

Expr *getExpr() const {
assert(!isExprSubstitutionFailure() &&
"ExprRequirement has no expression because there has been a "
"substitution failure.");
return Value.get<Expr *>();
return cast<Expr *>(Value);
}

static bool classof(const Requirement *R) {
Expand Down
20 changes: 8 additions & 12 deletions clang/include/clang/AST/ExprObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,28 +752,24 @@ class ObjCPropertyRefExpr : public Expr {
setMethodRefFlag(MethodRef_Setter, val);
}

const Expr *getBase() const {
return cast<Expr>(Receiver.get<Stmt*>());
}
Expr *getBase() {
return cast<Expr>(Receiver.get<Stmt*>());
}
const Expr *getBase() const { return cast<Expr>(cast<Stmt *>(Receiver)); }
Expr *getBase() { return cast<Expr>(cast<Stmt *>(Receiver)); }

SourceLocation getLocation() const { return IdLoc; }

SourceLocation getReceiverLocation() const { return ReceiverLoc; }

QualType getSuperReceiverType() const {
return QualType(Receiver.get<const Type*>(), 0);
return QualType(cast<const Type *>(Receiver), 0);
}

ObjCInterfaceDecl *getClassReceiver() const {
return Receiver.get<ObjCInterfaceDecl*>();
return cast<ObjCInterfaceDecl *>(Receiver);
}

bool isObjectReceiver() const { return Receiver.is<Stmt*>(); }
bool isSuperReceiver() const { return Receiver.is<const Type*>(); }
bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); }
bool isObjectReceiver() const { return isa<Stmt *>(Receiver); }
bool isSuperReceiver() const { return isa<const Type *>(Receiver); }
bool isClassReceiver() const { return isa<ObjCInterfaceDecl *>(Receiver); }

/// Determine the type of the base, regardless of the kind of receiver.
QualType getReceiverType(const ASTContext &ctx) const;
Expand All @@ -787,7 +783,7 @@ class ObjCPropertyRefExpr : public Expr {

// Iterators
child_range children() {
if (Receiver.is<Stmt*>()) {
if (isa<Stmt *>(Receiver)) {
Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack!
return child_range(begin, begin+1);
}
Expand Down
Loading
Loading