Skip to content

Commit 624cc70

Browse files
[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.
1 parent 00e1cc4 commit 624cc70

File tree

9 files changed

+77
-88
lines changed

9 files changed

+77
-88
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -747,9 +747,9 @@ class DeclaratorDecl : public ValueDecl {
747747
/// ignoring outer template declarations.
748748
SourceLocation InnerLocStart;
749749

750-
bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); }
751-
ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); }
752-
const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); }
750+
bool hasExtInfo() const { return isa<ExtInfo *>(DeclInfo); }
751+
ExtInfo *getExtInfo() { return cast<ExtInfo *>(DeclInfo); }
752+
const ExtInfo *getExtInfo() const { return cast<ExtInfo *>(DeclInfo); }
753753

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

764764
TypeSourceInfo *getTypeSourceInfo() const {
765-
return hasExtInfo()
766-
? getExtInfo()->TInfo
767-
: DeclInfo.get<TypeSourceInfo*>();
765+
return hasExtInfo() ? getExtInfo()->TInfo
766+
: cast<TypeSourceInfo *>(DeclInfo);
768767
}
769768

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

3590-
bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo *>(); }
3591-
ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo *>(); }
3589+
bool hasExtInfo() const { return isa<ExtInfo *>(TypedefNameDeclOrQualifier); }
3590+
ExtInfo *getExtInfo() { return cast<ExtInfo *>(TypedefNameDeclOrQualifier); }
35923591
const ExtInfo *getExtInfo() const {
3593-
return TypedefNameDeclOrQualifier.get<ExtInfo *>();
3592+
return cast<ExtInfo *>(TypedefNameDeclOrQualifier);
35943593
}
35953594

35963595
protected:
@@ -3793,7 +3792,7 @@ class TagDecl : public TypeDecl,
37933792

37943793
TypedefNameDecl *getTypedefNameForAnonDecl() const {
37953794
return hasExtInfo() ? nullptr
3796-
: TypedefNameDeclOrQualifier.get<TypedefNameDecl *>();
3795+
: cast<TypedefNameDecl *>(TypedefNameDeclOrQualifier);
37973796
}
37983797

37993798
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD);
@@ -4011,7 +4010,7 @@ class EnumDecl : public TagDecl {
40114010
return QualType();
40124011
if (const Type *T = IntegerType.dyn_cast<const Type*>())
40134012
return QualType(T, 0);
4014-
return IntegerType.get<TypeSourceInfo*>()->getType().getUnqualifiedType();
4013+
return cast<TypeSourceInfo *>(IntegerType)->getType().getUnqualifiedType();
40154014
}
40164015

40174016
/// Set the underlying integer type.

clang/include/clang/AST/DeclBase.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,12 @@ class alignas(8) Decl {
271271
/// // LexicalDC == global namespace
272272
llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;
273273

274-
bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); }
275-
bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); }
274+
bool isInSemaDC() const { return isa<DeclContext *>(DeclCtx); }
275+
bool isOutOfSemaDC() const { return isa<MultipleDC *>(DeclCtx); }
276276

277-
MultipleDC *getMultipleDC() const {
278-
return DeclCtx.get<MultipleDC*>();
279-
}
277+
MultipleDC *getMultipleDC() const { return cast<MultipleDC *>(DeclCtx); }
280278

281-
DeclContext *getSemanticDC() const {
282-
return DeclCtx.get<DeclContext*>();
283-
}
279+
DeclContext *getSemanticDC() const { return cast<DeclContext *>(DeclCtx); }
284280

285281
/// Loc - The location of this decl.
286282
SourceLocation Loc;
@@ -1340,7 +1336,7 @@ class DeclListNode {
13401336
assert(Ptr && "dereferencing end() iterator");
13411337
if (DeclListNode *CurNode = Ptr.dyn_cast<DeclListNode*>())
13421338
return CurNode->D;
1343-
return Ptr.get<NamedDecl*>();
1339+
return cast<NamedDecl *>(Ptr);
13441340
}
13451341
void operator->() const { } // Unsupported.
13461342
bool operator==(const iterator &X) const { return Ptr == X.Ptr; }

clang/include/clang/AST/DeclCXX.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,19 +2388,19 @@ class CXXCtorInitializer final {
23882388

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

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

23982398
bool isAnyMemberInitializer() const {
23992399
return isMemberInitializer() || isIndirectMemberInitializer();
24002400
}
24012401

24022402
bool isIndirectMemberInitializer() const {
2403-
return Initializee.is<IndirectFieldDecl*>();
2403+
return isa<IndirectFieldDecl *>(Initializee);
24042404
}
24052405

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

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

24642464
FieldDecl *getAnyMember() const {
24652465
if (isMemberInitializer())
2466-
return Initializee.get<FieldDecl*>();
2466+
return cast<FieldDecl *>(Initializee);
24672467
if (isIndirectMemberInitializer())
2468-
return Initializee.get<IndirectFieldDecl*>()->getAnonField();
2468+
return cast<IndirectFieldDecl *>(Initializee)->getAnonField();
24692469
return nullptr;
24702470
}
24712471

24722472
IndirectFieldDecl *getIndirectMember() const {
24732473
if (isIndirectMemberInitializer())
2474-
return Initializee.get<IndirectFieldDecl*>();
2474+
return cast<IndirectFieldDecl *>(Initializee);
24752475
return nullptr;
24762476
}
24772477

clang/include/clang/AST/DeclTemplate.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
19651965
SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
19661966
return PartialSpec->PartialSpecialization;
19671967

1968-
return SpecializedTemplate.get<ClassTemplateDecl*>();
1968+
return cast<ClassTemplateDecl *>(SpecializedTemplate);
19691969
}
19701970

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

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

2737-
return SpecializedTemplate.get<VarTemplateDecl *>();
2737+
return cast<VarTemplateDecl *>(SpecializedTemplate);
27382738
}
27392739

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

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

33153315
inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) {

clang/include/clang/AST/ExprCXX.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ class CXXTypeidExpr : public Expr {
878878
/// object. This is not a strong guarantee.
879879
bool isMostDerived(const ASTContext &Context) const;
880880

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

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

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

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

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

11121112
MSGuidDecl *getGuidDecl() const { return Guid; }
@@ -4750,24 +4750,24 @@ class MaterializeTemporaryExpr : public Expr {
47504750
/// be materialized into a glvalue.
47514751
Expr *getSubExpr() const {
47524752
return cast<Expr>(
4753-
State.is<Stmt *>()
4754-
? State.get<Stmt *>()
4755-
: State.get<LifetimeExtendedTemporaryDecl *>()->getTemporaryExpr());
4753+
isa<Stmt *>(State)
4754+
? cast<Stmt *>(State)
4755+
: cast<LifetimeExtendedTemporaryDecl *>(State)->getTemporaryExpr());
47564756
}
47574757

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

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

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

47954795
unsigned getManglingNumber() const {
4796-
return State.is<Stmt *>() ? 0
4797-
: State.get<LifetimeExtendedTemporaryDecl *>()
4796+
return isa<Stmt *>(State) ? 0
4797+
: cast<LifetimeExtendedTemporaryDecl *>(State)
47984798
->getManglingNumber();
47994799
}
48004800

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

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

48284828
const_child_range children() const {
4829-
return State.is<Stmt *>()
4829+
return isa<Stmt *>(State)
48304830
? const_child_range(State.getAddrOfPtr1(),
48314831
State.getAddrOfPtr1() + 1)
48324832
: const_cast<const LifetimeExtendedTemporaryDecl *>(
4833-
State.get<LifetimeExtendedTemporaryDecl *>())
4833+
cast<LifetimeExtendedTemporaryDecl *>(State))
48344834
->childrenExpr();
48354835
}
48364836
};

clang/include/clang/AST/ExprConcepts.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,13 @@ class TypeRequirement : public Requirement {
261261
assert(Status == SS_SubstitutionFailure &&
262262
"Attempted to get substitution diagnostic when there has been no "
263263
"substitution failure.");
264-
return Value.get<SubstitutionDiagnostic *>();
264+
return cast<SubstitutionDiagnostic *>(Value);
265265
}
266266

267267
TypeSourceInfo *getType() const {
268268
assert(!isSubstitutionFailure() &&
269269
"Attempted to get type when there has been a substitution failure.");
270-
return Value.get<TypeSourceInfo *>();
270+
return cast<TypeSourceInfo *>(Value);
271271
}
272272

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

415415
Expr *getExpr() const {
416416
assert(!isExprSubstitutionFailure() &&
417417
"ExprRequirement has no expression because there has been a "
418418
"substitution failure.");
419-
return Value.get<Expr *>();
419+
return cast<Expr *>(Value);
420420
}
421421

422422
static bool classof(const Requirement *R) {

clang/include/clang/AST/ExprObjC.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -752,28 +752,24 @@ class ObjCPropertyRefExpr : public Expr {
752752
setMethodRefFlag(MethodRef_Setter, val);
753753
}
754754

755-
const Expr *getBase() const {
756-
return cast<Expr>(Receiver.get<Stmt*>());
757-
}
758-
Expr *getBase() {
759-
return cast<Expr>(Receiver.get<Stmt*>());
760-
}
755+
const Expr *getBase() const { return cast<Expr>(cast<Stmt *>(Receiver)); }
756+
Expr *getBase() { return cast<Expr>(cast<Stmt *>(Receiver)); }
761757

762758
SourceLocation getLocation() const { return IdLoc; }
763759

764760
SourceLocation getReceiverLocation() const { return ReceiverLoc; }
765761

766762
QualType getSuperReceiverType() const {
767-
return QualType(Receiver.get<const Type*>(), 0);
763+
return QualType(cast<const Type *>(Receiver), 0);
768764
}
769765

770766
ObjCInterfaceDecl *getClassReceiver() const {
771-
return Receiver.get<ObjCInterfaceDecl*>();
767+
return cast<ObjCInterfaceDecl *>(Receiver);
772768
}
773769

774-
bool isObjectReceiver() const { return Receiver.is<Stmt*>(); }
775-
bool isSuperReceiver() const { return Receiver.is<const Type*>(); }
776-
bool isClassReceiver() const { return Receiver.is<ObjCInterfaceDecl*>(); }
770+
bool isObjectReceiver() const { return isa<Stmt *>(Receiver); }
771+
bool isSuperReceiver() const { return isa<const Type *>(Receiver); }
772+
bool isClassReceiver() const { return isa<ObjCInterfaceDecl *>(Receiver); }
777773

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

788784
// Iterators
789785
child_range children() {
790-
if (Receiver.is<Stmt*>()) {
786+
if (isa<Stmt *>(Receiver)) {
791787
Stmt **begin = reinterpret_cast<Stmt**>(&Receiver); // hack!
792788
return child_range(begin, begin+1);
793789
}

0 commit comments

Comments
 (0)