[AST] Migrate away from PointerUnion::{is,get} (NFC) (#119523)
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:
// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa<T>, cast<T> and the llvm::dyn_cast<T>
I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 8c39ef3d5..88d93a7 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -747,9 +747,9 @@
/// 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,
@@ -762,9 +762,8 @@
friend class ASTDeclWriter;
TypeSourceInfo *getTypeSourceInfo() const {
- return hasExtInfo()
- ? getExtInfo()->TInfo
- : DeclInfo.get<TypeSourceInfo*>();
+ return hasExtInfo() ? getExtInfo()->TInfo
+ : cast<TypeSourceInfo *>(DeclInfo);
}
void setTypeSourceInfo(TypeSourceInfo *TI) {
@@ -3587,10 +3586,10 @@
/// 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:
@@ -3793,7 +3792,7 @@
TypedefNameDecl *getTypedefNameForAnonDecl() const {
return hasExtInfo() ? nullptr
- : TypedefNameDeclOrQualifier.get<TypedefNameDecl *>();
+ : cast<TypedefNameDecl *>(TypedefNameDeclOrQualifier);
}
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD);
@@ -4011,7 +4010,7 @@
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.
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index a3447d1..82932e0 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -271,16 +271,12 @@
/// // 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;
@@ -1340,7 +1336,7 @@
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; }
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index e389b5c..c232556 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -2388,19 +2388,19 @@
/// 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
@@ -2416,7 +2416,7 @@
/// 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.
@@ -2457,21 +2457,21 @@
/// 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;
}
diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h
index dd92d40..44ccf89 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -1965,7 +1965,7 @@
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
@@ -2013,7 +2013,7 @@
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.
@@ -2734,7 +2734,7 @@
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
@@ -2782,7 +2782,7 @@
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.
@@ -3309,7 +3309,7 @@
return PD;
if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>())
return PD;
- return P.get<TemplateTemplateParmDecl *>();
+ return cast<TemplateTemplateParmDecl *>(P);
}
inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) {
diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h
index 1a24b88..4cec89c 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -878,7 +878,7 @@
/// 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).
@@ -887,11 +887,11 @@
/// 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(); }
@@ -1093,7 +1093,7 @@
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).
@@ -1102,11 +1102,11 @@
/// 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; }
@@ -4750,24 +4750,24 @@
/// 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);
}
@@ -4782,8 +4782,8 @@
/// 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 {
@@ -4793,8 +4793,8 @@
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();
}
@@ -4820,17 +4820,17 @@
// 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();
}
};
diff --git a/clang/include/clang/AST/ExprConcepts.h b/clang/include/clang/AST/ExprConcepts.h
index f3e32ce..86c4155 100644
--- a/clang/include/clang/AST/ExprConcepts.h
+++ b/clang/include/clang/AST/ExprConcepts.h
@@ -261,13 +261,13 @@
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) {
@@ -409,14 +409,14 @@
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) {
diff --git a/clang/include/clang/AST/ExprObjC.h b/clang/include/clang/AST/ExprObjC.h
index f833916..1fccc26 100644
--- a/clang/include/clang/AST/ExprObjC.h
+++ b/clang/include/clang/AST/ExprObjC.h
@@ -752,28 +752,24 @@
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;
@@ -787,7 +783,7 @@
// 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);
}
diff --git a/clang/include/clang/AST/Redeclarable.h b/clang/include/clang/AST/Redeclarable.h
index 8d320a9..bba7893 100644
--- a/clang/include/clang/AST/Redeclarable.h
+++ b/clang/include/clang/AST/Redeclarable.h
@@ -113,25 +113,24 @@
DeclLink(PreviousTag, decl_type *D) : Link(NotKnownLatest(Previous(D))) {}
bool isFirst() const {
- return Link.is<KnownLatest>() ||
+ return isa<KnownLatest>(Link) ||
// FIXME: 'template' is required on the next line due to an
// apparent clang bug.
- Link.get<NotKnownLatest>().template is<UninitializedLatest>();
+ cast<NotKnownLatest>(Link).template is<UninitializedLatest>();
}
decl_type *getPrevious(const decl_type *D) const {
- if (Link.is<NotKnownLatest>()) {
- NotKnownLatest NKL = Link.get<NotKnownLatest>();
- if (NKL.is<Previous>())
- return static_cast<decl_type*>(NKL.get<Previous>());
+ if (NotKnownLatest NKL = dyn_cast<NotKnownLatest>(Link)) {
+ if (auto *Prev = dyn_cast<Previous>(NKL))
+ return static_cast<decl_type *>(Prev);
// Allocate the generational 'most recent' cache now, if needed.
Link = KnownLatest(*reinterpret_cast<const ASTContext *>(
- NKL.get<UninitializedLatest>()),
+ cast<UninitializedLatest>(NKL)),
const_cast<decl_type *>(D));
}
- return static_cast<decl_type*>(Link.get<KnownLatest>().get(D));
+ return static_cast<decl_type *>(cast<KnownLatest>(Link).get(D));
}
void setPrevious(decl_type *D) {
@@ -141,25 +140,24 @@
void setLatest(decl_type *D) {
assert(isFirst() && "decl became canonical unexpectedly");
- if (Link.is<NotKnownLatest>()) {
- NotKnownLatest NKL = Link.get<NotKnownLatest>();
+ if (NotKnownLatest NKL = dyn_cast<NotKnownLatest>(Link)) {
Link = KnownLatest(*reinterpret_cast<const ASTContext *>(
- NKL.get<UninitializedLatest>()),
+ cast<UninitializedLatest>(NKL)),
D);
} else {
- auto Latest = Link.get<KnownLatest>();
+ auto Latest = cast<KnownLatest>(Link);
Latest.set(D);
Link = Latest;
}
}
- void markIncomplete() { Link.get<KnownLatest>().markIncomplete(); }
+ void markIncomplete() { cast<KnownLatest>(Link).markIncomplete(); }
Decl *getLatestNotUpdated() const {
assert(isFirst() && "expected a canonical decl");
- if (Link.is<NotKnownLatest>())
+ if (isa<NotKnownLatest>(Link))
return nullptr;
- return Link.get<KnownLatest>().getNotUpdated();
+ return cast<KnownLatest>(Link).getNotUpdated();
}
};
diff --git a/clang/include/clang/AST/TemplateBase.h b/clang/include/clang/AST/TemplateBase.h
index a8f0263..9d0ee24 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -484,7 +484,7 @@
Pointer;
TemplateTemplateArgLocInfo *getTemplate() const {
- return Pointer.get<TemplateTemplateArgLocInfo *>();
+ return cast<TemplateTemplateArgLocInfo *>(Pointer);
}
public:
@@ -499,10 +499,10 @@
SourceLocation EllipsisLoc);
TypeSourceInfo *getAsTypeSourceInfo() const {
- return Pointer.get<TypeSourceInfo *>();
+ return cast<TypeSourceInfo *>(Pointer);
}
- Expr *getAsExpr() const { return Pointer.get<Expr *>(); }
+ Expr *getAsExpr() const { return cast<Expr *>(Pointer); }
NestedNameSpecifierLoc getTemplateQualifierLoc() const {
const auto *Template = getTemplate();