Author: Kazu Hirata Date: 2024-12-12T01:15:39-08:00 New Revision: 2a825cd2f93b5f83029c36d6c8229f65b6ef2ec7
URL: https://github.com/llvm/llvm-project/commit/2a825cd2f93b5f83029c36d6c8229f65b6ef2ec7 DIFF: https://github.com/llvm/llvm-project/commit/2a825cd2f93b5f83029c36d6c8229f65b6ef2ec7.diff LOG: [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. Added: Modified: clang/include/clang/AST/APValue.h clang/include/clang/AST/Decl.h clang/include/clang/AST/DeclContextInternals.h clang/include/clang/AST/DeclTemplate.h clang/include/clang/AST/ExprConcepts.h clang/include/clang/AST/ExternalASTSource.h clang/include/clang/AST/Redeclarable.h clang/include/clang/AST/Type.h Removed: ################################################################################ diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h index 7869ee386689d7..4401f3a8ff482c 100644 --- a/clang/include/clang/AST/APValue.h +++ b/clang/include/clang/AST/APValue.h @@ -157,11 +157,9 @@ class APValue { void Profile(llvm::FoldingSetNodeID &ID) const; - template <class T> - bool is() const { return Ptr.is<T>(); } + template <class T> bool is() const { return isa<T>(Ptr); } - template <class T> - T get() const { return Ptr.get<T>(); } + template <class T> T get() const { return cast<T>(Ptr); } template <class T> T dyn_cast() const { return Ptr.dyn_cast<T>(); } diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 88d93a79d00f8f..67ee0bb412692a 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -3457,18 +3457,17 @@ class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> { using redeclarable_base::isFirstDecl; bool isModed() const { - return MaybeModedTInfo.getPointer().is<ModedTInfo *>(); + return isa<ModedTInfo *>(MaybeModedTInfo.getPointer()); } TypeSourceInfo *getTypeSourceInfo() const { - return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->first - : MaybeModedTInfo.getPointer().get<TypeSourceInfo *>(); + return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->first + : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer()); } QualType getUnderlyingType() const { - return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->second - : MaybeModedTInfo.getPointer() - .get<TypeSourceInfo *>() + return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->second + : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer()) ->getType(); } diff --git a/clang/include/clang/AST/DeclContextInternals.h b/clang/include/clang/AST/DeclContextInternals.h index e169c485921929..b17b7627ac90c5 100644 --- a/clang/include/clang/AST/DeclContextInternals.h +++ b/clang/include/clang/AST/DeclContextInternals.h @@ -70,7 +70,7 @@ class StoredDeclsList { // want to keep (if any) will be of the form DeclListNode(D, <rest>); // replace it with just D. if (NewLast) { - DeclListNode *Node = NewLast->get<DeclListNode*>(); + DeclListNode *Node = cast<DeclListNode *>(*NewLast); *NewLast = Node->D; C.DeallocateDeclListNode(Node); } @@ -84,11 +84,11 @@ class StoredDeclsList { if (!Data.getPointer()) // All declarations are erased. return nullptr; - else if (NewHead.is<NamedDecl *>()) + else if (isa<NamedDecl *>(NewHead)) // The list only contains a declaration, the header itself. return (DeclListNode::Decls *)&Data; else { - assert(NewLast && NewLast->is<NamedDecl *>() && "Not the tail?"); + assert(NewLast && isa<NamedDecl *>(*NewLast) && "Not the tail?"); return NewLast; } } @@ -207,7 +207,7 @@ class StoredDeclsList { } // Append the Decls. - DeclListNode *Node = C.AllocateDeclListNode(Tail->get<NamedDecl *>()); + DeclListNode *Node = C.AllocateDeclListNode(cast<NamedDecl *>(*Tail)); Node->Rest = DeclsAsList; *Tail = Node; } @@ -293,7 +293,7 @@ class StoredDeclsList { llvm::errs() << '[' << Node->D << "] -> "; D = Node->Rest; } else { - llvm::errs() << '[' << D.get<NamedDecl*>() << "]\n"; + llvm::errs() << '[' << cast<NamedDecl *>(D) << "]\n"; return; } } diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 44ccf8932a1830..d3a466a8617bb1 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -319,8 +319,7 @@ class DefaultArgStorage { const DefaultArgStorage &Storage = Parm->getDefaultArgStorage(); if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>()) Parm = Prev; - assert(!Parm->getDefaultArgStorage() - .ValueOrInherited.template is<ParmDecl *>() && + assert(!isa<ParmDecl *>(Parm->getDefaultArgStorage().ValueOrInherited) && "should only be one level of indirection"); return Parm; } @@ -333,7 +332,7 @@ class DefaultArgStorage { /// Determine whether the default argument for this parameter was inherited /// from a previous declaration of the same entity. - bool isInherited() const { return ValueOrInherited.template is<ParmDecl*>(); } + bool isInherited() const { return isa<ParmDecl *>(ValueOrInherited); } /// Get the default argument's value. This does not consider whether the /// default argument is visible. @@ -343,7 +342,7 @@ class DefaultArgStorage { Storage = &Prev->getDefaultArgStorage(); if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>()) return C->Value; - return Storage->ValueOrInherited.template get<ArgType>(); + return cast<ArgType>(Storage->ValueOrInherited); } /// Get the parameter from which we inherit the default argument, if any. @@ -379,7 +378,7 @@ class DefaultArgStorage { Inherited->PrevDeclWithDefaultArg = InheritedFrom; } else ValueOrInherited = new (allocateDefaultArgStorageChain(C)) - Chain{InheritedFrom, ValueOrInherited.template get<ArgType>()}; + Chain{InheritedFrom, cast<ArgType>(ValueOrInherited)}; } /// Remove the default argument, even if it was inherited. @@ -1992,7 +1991,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, /// template arguments have been deduced. void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs) { - assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && + assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) && "Already set to a class template partial specialization!"); auto *PS = new (getASTContext()) SpecializedPartialSpecialization(); PS->PartialSpecialization = PartialSpec; @@ -2003,7 +2002,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl, /// Note that this class template specialization is an instantiation /// of the given class template. void setInstantiationOf(ClassTemplateDecl *TemplDecl) { - assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() && + assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) && "Previously set to a class template partial specialization!"); SpecializedTemplate = TemplDecl; } @@ -2761,7 +2760,7 @@ class VarTemplateSpecializationDecl : public VarDecl, /// template arguments have been deduced. void setInstantiationOf(VarTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs) { - assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && + assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) && "Already set to a variable template partial specialization!"); auto *PS = new (getASTContext()) SpecializedPartialSpecialization(); PS->PartialSpecialization = PartialSpec; @@ -2772,7 +2771,7 @@ class VarTemplateSpecializationDecl : public VarDecl, /// Note that this variable template specialization is an instantiation /// of the given variable template. void setInstantiationOf(VarTemplateDecl *TemplDecl) { - assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() && + assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) && "Previously set to a variable template partial specialization!"); SpecializedTemplate = TemplDecl; } diff --git a/clang/include/clang/AST/ExprConcepts.h b/clang/include/clang/AST/ExprConcepts.h index 86c4155b6a853e..f988d40cf73c32 100644 --- a/clang/include/clang/AST/ExprConcepts.h +++ b/clang/include/clang/AST/ExprConcepts.h @@ -329,24 +329,24 @@ class ExprRequirement : public Requirement { bool isSubstitutionFailure() const { return !isEmpty() && - TypeConstraintInfo.getPointer().is<SubstitutionDiagnostic *>(); + isa<SubstitutionDiagnostic *>(TypeConstraintInfo.getPointer()); } bool isTypeConstraint() const { return !isEmpty() && - TypeConstraintInfo.getPointer().is<TemplateParameterList *>(); + isa<TemplateParameterList *>(TypeConstraintInfo.getPointer()); } SubstitutionDiagnostic *getSubstitutionDiagnostic() const { assert(isSubstitutionFailure()); - return TypeConstraintInfo.getPointer().get<SubstitutionDiagnostic *>(); + return cast<SubstitutionDiagnostic *>(TypeConstraintInfo.getPointer()); } const TypeConstraint *getTypeConstraint() const; TemplateParameterList *getTypeConstraintTemplateParameterList() const { assert(isTypeConstraint()); - return TypeConstraintInfo.getPointer().get<TemplateParameterList *>(); + return cast<TemplateParameterList *>(TypeConstraintInfo.getPointer()); } }; private: diff --git a/clang/include/clang/AST/ExternalASTSource.h b/clang/include/clang/AST/ExternalASTSource.h index 9f968ba05b4466..4d7ff822fceb75 100644 --- a/clang/include/clang/AST/ExternalASTSource.h +++ b/clang/include/clang/AST/ExternalASTSource.h @@ -462,9 +462,7 @@ struct LazyGenerationalUpdatePtr { : Value(Value) {} /// Forcibly set this pointer (which must be lazy) as needing updates. - void markIncomplete() { - Value.template get<LazyData *>()->LastGeneration = 0; - } + void markIncomplete() { cast<LazyData *>(Value)->LastGeneration = 0; } /// Set the value of this pointer, in the current generation. void set(T NewValue) { @@ -487,14 +485,14 @@ struct LazyGenerationalUpdatePtr { } return LazyVal->LastValue; } - return Value.template get<T>(); + return cast<T>(Value); } /// Get the most recently computed value of this pointer without updating it. T getNotUpdated() const { if (auto *LazyVal = Value.template dyn_cast<LazyData *>()) return LazyVal->LastValue; - return Value.template get<T>(); + return cast<T>(Value); } void *getOpaqueValue() { return Value.getOpaqueValue(); } diff --git a/clang/include/clang/AST/Redeclarable.h b/clang/include/clang/AST/Redeclarable.h index bba789375cb6ed..ee21f11e5f7072 100644 --- a/clang/include/clang/AST/Redeclarable.h +++ b/clang/include/clang/AST/Redeclarable.h @@ -116,7 +116,7 @@ class Redeclarable { return isa<KnownLatest>(Link) || // FIXME: 'template' is required on the next line due to an // apparent clang bug. - cast<NotKnownLatest>(Link).template is<UninitializedLatest>(); + isa<UninitializedLatest>(cast<NotKnownLatest>(Link)); } decl_type *getPrevious(const decl_type *D) const { diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index f0eee77c73ef06..09c98f642852fc 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -934,11 +934,11 @@ class QualType { Qualifiers::FastWidth> Value; const ExtQuals *getExtQualsUnsafe() const { - return Value.getPointer().get<const ExtQuals*>(); + return cast<const ExtQuals *>(Value.getPointer()); } const Type *getTypePtrUnsafe() const { - return Value.getPointer().get<const Type*>(); + return cast<const Type *>(Value.getPointer()); } const ExtQualsTypeCommonBase *getCommonPtr() const { @@ -1064,7 +1064,7 @@ class QualType { /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType /// instance. bool hasLocalNonFastQualifiers() const { - return Value.getPointer().is<const ExtQuals*>(); + return isa<const ExtQuals *>(Value.getPointer()); } /// Retrieve the set of qualifiers local to this particular QualType _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits