Skip to content

Commit 2a825cd

Browse files
[AST] Migrate away from PointerUnion::{is,get} (NFC) (#119673)
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 b3cba9b commit 2a825cd

File tree

8 files changed

+31
-37
lines changed

8 files changed

+31
-37
lines changed

clang/include/clang/AST/APValue.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,9 @@ class APValue {
157157

158158
void Profile(llvm::FoldingSetNodeID &ID) const;
159159

160-
template <class T>
161-
bool is() const { return Ptr.is<T>(); }
160+
template <class T> bool is() const { return isa<T>(Ptr); }
162161

163-
template <class T>
164-
T get() const { return Ptr.get<T>(); }
162+
template <class T> T get() const { return cast<T>(Ptr); }
165163

166164
template <class T>
167165
T dyn_cast() const { return Ptr.dyn_cast<T>(); }

clang/include/clang/AST/Decl.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3457,18 +3457,17 @@ class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
34573457
using redeclarable_base::isFirstDecl;
34583458

34593459
bool isModed() const {
3460-
return MaybeModedTInfo.getPointer().is<ModedTInfo *>();
3460+
return isa<ModedTInfo *>(MaybeModedTInfo.getPointer());
34613461
}
34623462

34633463
TypeSourceInfo *getTypeSourceInfo() const {
3464-
return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->first
3465-
: MaybeModedTInfo.getPointer().get<TypeSourceInfo *>();
3464+
return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->first
3465+
: cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer());
34663466
}
34673467

34683468
QualType getUnderlyingType() const {
3469-
return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->second
3470-
: MaybeModedTInfo.getPointer()
3471-
.get<TypeSourceInfo *>()
3469+
return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->second
3470+
: cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer())
34723471
->getType();
34733472
}
34743473

clang/include/clang/AST/DeclContextInternals.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class StoredDeclsList {
7070
// want to keep (if any) will be of the form DeclListNode(D, <rest>);
7171
// replace it with just D.
7272
if (NewLast) {
73-
DeclListNode *Node = NewLast->get<DeclListNode*>();
73+
DeclListNode *Node = cast<DeclListNode *>(*NewLast);
7474
*NewLast = Node->D;
7575
C.DeallocateDeclListNode(Node);
7676
}
@@ -84,11 +84,11 @@ class StoredDeclsList {
8484
if (!Data.getPointer())
8585
// All declarations are erased.
8686
return nullptr;
87-
else if (NewHead.is<NamedDecl *>())
87+
else if (isa<NamedDecl *>(NewHead))
8888
// The list only contains a declaration, the header itself.
8989
return (DeclListNode::Decls *)&Data;
9090
else {
91-
assert(NewLast && NewLast->is<NamedDecl *>() && "Not the tail?");
91+
assert(NewLast && isa<NamedDecl *>(*NewLast) && "Not the tail?");
9292
return NewLast;
9393
}
9494
}
@@ -207,7 +207,7 @@ class StoredDeclsList {
207207
}
208208

209209
// Append the Decls.
210-
DeclListNode *Node = C.AllocateDeclListNode(Tail->get<NamedDecl *>());
210+
DeclListNode *Node = C.AllocateDeclListNode(cast<NamedDecl *>(*Tail));
211211
Node->Rest = DeclsAsList;
212212
*Tail = Node;
213213
}
@@ -293,7 +293,7 @@ class StoredDeclsList {
293293
llvm::errs() << '[' << Node->D << "] -> ";
294294
D = Node->Rest;
295295
} else {
296-
llvm::errs() << '[' << D.get<NamedDecl*>() << "]\n";
296+
llvm::errs() << '[' << cast<NamedDecl *>(D) << "]\n";
297297
return;
298298
}
299299
}

clang/include/clang/AST/DeclTemplate.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ class DefaultArgStorage {
319319
const DefaultArgStorage &Storage = Parm->getDefaultArgStorage();
320320
if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>())
321321
Parm = Prev;
322-
assert(!Parm->getDefaultArgStorage()
323-
.ValueOrInherited.template is<ParmDecl *>() &&
322+
assert(!isa<ParmDecl *>(Parm->getDefaultArgStorage().ValueOrInherited) &&
324323
"should only be one level of indirection");
325324
return Parm;
326325
}
@@ -333,7 +332,7 @@ class DefaultArgStorage {
333332

334333
/// Determine whether the default argument for this parameter was inherited
335334
/// from a previous declaration of the same entity.
336-
bool isInherited() const { return ValueOrInherited.template is<ParmDecl*>(); }
335+
bool isInherited() const { return isa<ParmDecl *>(ValueOrInherited); }
337336

338337
/// Get the default argument's value. This does not consider whether the
339338
/// default argument is visible.
@@ -343,7 +342,7 @@ class DefaultArgStorage {
343342
Storage = &Prev->getDefaultArgStorage();
344343
if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>())
345344
return C->Value;
346-
return Storage->ValueOrInherited.template get<ArgType>();
345+
return cast<ArgType>(Storage->ValueOrInherited);
347346
}
348347

349348
/// Get the parameter from which we inherit the default argument, if any.
@@ -379,7 +378,7 @@ class DefaultArgStorage {
379378
Inherited->PrevDeclWithDefaultArg = InheritedFrom;
380379
} else
381380
ValueOrInherited = new (allocateDefaultArgStorageChain(C))
382-
Chain{InheritedFrom, ValueOrInherited.template get<ArgType>()};
381+
Chain{InheritedFrom, cast<ArgType>(ValueOrInherited)};
383382
}
384383

385384
/// Remove the default argument, even if it was inherited.
@@ -1992,7 +1991,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
19921991
/// template arguments have been deduced.
19931992
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec,
19941993
const TemplateArgumentList *TemplateArgs) {
1995-
assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
1994+
assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
19961995
"Already set to a class template partial specialization!");
19971996
auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
19981997
PS->PartialSpecialization = PartialSpec;
@@ -2003,7 +2002,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
20032002
/// Note that this class template specialization is an instantiation
20042003
/// of the given class template.
20052004
void setInstantiationOf(ClassTemplateDecl *TemplDecl) {
2006-
assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
2005+
assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
20072006
"Previously set to a class template partial specialization!");
20082007
SpecializedTemplate = TemplDecl;
20092008
}
@@ -2761,7 +2760,7 @@ class VarTemplateSpecializationDecl : public VarDecl,
27612760
/// template arguments have been deduced.
27622761
void setInstantiationOf(VarTemplatePartialSpecializationDecl *PartialSpec,
27632762
const TemplateArgumentList *TemplateArgs) {
2764-
assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&
2763+
assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
27652764
"Already set to a variable template partial specialization!");
27662765
auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
27672766
PS->PartialSpecialization = PartialSpec;
@@ -2772,7 +2771,7 @@ class VarTemplateSpecializationDecl : public VarDecl,
27722771
/// Note that this variable template specialization is an instantiation
27732772
/// of the given variable template.
27742773
void setInstantiationOf(VarTemplateDecl *TemplDecl) {
2775-
assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&
2774+
assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
27762775
"Previously set to a variable template partial specialization!");
27772776
SpecializedTemplate = TemplDecl;
27782777
}

clang/include/clang/AST/ExprConcepts.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,24 +329,24 @@ class ExprRequirement : public Requirement {
329329

330330
bool isSubstitutionFailure() const {
331331
return !isEmpty() &&
332-
TypeConstraintInfo.getPointer().is<SubstitutionDiagnostic *>();
332+
isa<SubstitutionDiagnostic *>(TypeConstraintInfo.getPointer());
333333
}
334334

335335
bool isTypeConstraint() const {
336336
return !isEmpty() &&
337-
TypeConstraintInfo.getPointer().is<TemplateParameterList *>();
337+
isa<TemplateParameterList *>(TypeConstraintInfo.getPointer());
338338
}
339339

340340
SubstitutionDiagnostic *getSubstitutionDiagnostic() const {
341341
assert(isSubstitutionFailure());
342-
return TypeConstraintInfo.getPointer().get<SubstitutionDiagnostic *>();
342+
return cast<SubstitutionDiagnostic *>(TypeConstraintInfo.getPointer());
343343
}
344344

345345
const TypeConstraint *getTypeConstraint() const;
346346

347347
TemplateParameterList *getTypeConstraintTemplateParameterList() const {
348348
assert(isTypeConstraint());
349-
return TypeConstraintInfo.getPointer().get<TemplateParameterList *>();
349+
return cast<TemplateParameterList *>(TypeConstraintInfo.getPointer());
350350
}
351351
};
352352
private:

clang/include/clang/AST/ExternalASTSource.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,7 @@ struct LazyGenerationalUpdatePtr {
462462
: Value(Value) {}
463463

464464
/// Forcibly set this pointer (which must be lazy) as needing updates.
465-
void markIncomplete() {
466-
Value.template get<LazyData *>()->LastGeneration = 0;
467-
}
465+
void markIncomplete() { cast<LazyData *>(Value)->LastGeneration = 0; }
468466

469467
/// Set the value of this pointer, in the current generation.
470468
void set(T NewValue) {
@@ -487,14 +485,14 @@ struct LazyGenerationalUpdatePtr {
487485
}
488486
return LazyVal->LastValue;
489487
}
490-
return Value.template get<T>();
488+
return cast<T>(Value);
491489
}
492490

493491
/// Get the most recently computed value of this pointer without updating it.
494492
T getNotUpdated() const {
495493
if (auto *LazyVal = Value.template dyn_cast<LazyData *>())
496494
return LazyVal->LastValue;
497-
return Value.template get<T>();
495+
return cast<T>(Value);
498496
}
499497

500498
void *getOpaqueValue() { return Value.getOpaqueValue(); }

clang/include/clang/AST/Redeclarable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Redeclarable {
116116
return isa<KnownLatest>(Link) ||
117117
// FIXME: 'template' is required on the next line due to an
118118
// apparent clang bug.
119-
cast<NotKnownLatest>(Link).template is<UninitializedLatest>();
119+
isa<UninitializedLatest>(cast<NotKnownLatest>(Link));
120120
}
121121

122122
decl_type *getPrevious(const decl_type *D) const {

clang/include/clang/AST/Type.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,11 +934,11 @@ class QualType {
934934
Qualifiers::FastWidth> Value;
935935

936936
const ExtQuals *getExtQualsUnsafe() const {
937-
return Value.getPointer().get<const ExtQuals*>();
937+
return cast<const ExtQuals *>(Value.getPointer());
938938
}
939939

940940
const Type *getTypePtrUnsafe() const {
941-
return Value.getPointer().get<const Type*>();
941+
return cast<const Type *>(Value.getPointer());
942942
}
943943

944944
const ExtQualsTypeCommonBase *getCommonPtr() const {
@@ -1064,7 +1064,7 @@ class QualType {
10641064
/// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
10651065
/// instance.
10661066
bool hasLocalNonFastQualifiers() const {
1067-
return Value.getPointer().is<const ExtQuals*>();
1067+
return isa<const ExtQuals *>(Value.getPointer());
10681068
}
10691069

10701070
/// Retrieve the set of qualifiers local to this particular QualType

0 commit comments

Comments
 (0)