[clang] 02dd73a - [clang] Migrate away from PointerUnion::{is,get} (NFC) (#119654)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 11 21:13:17 PST 2024
Author: Kazu Hirata
Date: 2024-12-11T21:13:13-08:00
New Revision: 02dd73a5d585af9a950baa38855305fdb17c76af
URL: https://github.com/llvm/llvm-project/commit/02dd73a5d585af9a950baa38855305fdb17c76af
DIFF: https://github.com/llvm/llvm-project/commit/02dd73a5d585af9a950baa38855305fdb17c76af.diff
LOG: [clang] Migrate away from PointerUnion::{is,get} (NFC) (#119654)
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/Lex/PreprocessingRecord.h
clang/include/clang/Lex/Preprocessor.h
clang/lib/Analysis/PathDiagnostic.cpp
clang/lib/Basic/FileManager.cpp
clang/lib/Index/FileIndexRecord.cpp
clang/lib/Index/IndexDecl.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CIndexCXX.cpp
clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Lex/PreprocessingRecord.h b/clang/include/clang/Lex/PreprocessingRecord.h
index 437d8e4cc174ed..7886aef7f0c7f3 100644
--- a/clang/include/clang/Lex/PreprocessingRecord.h
+++ b/clang/include/clang/Lex/PreprocessingRecord.h
@@ -180,13 +180,13 @@ class Token;
}
/// True if it is a builtin macro.
- bool isBuiltinMacro() const { return NameOrDef.is<IdentifierInfo *>(); }
+ bool isBuiltinMacro() const { return isa<IdentifierInfo *>(NameOrDef); }
/// The name of the macro being expanded.
const IdentifierInfo *getName() const {
if (MacroDefinitionRecord *Def = getDefinition())
return Def->getName();
- return NameOrDef.get<IdentifierInfo *>();
+ return cast<IdentifierInfo *>(NameOrDef);
}
/// The definition of the macro being expanded. May return null if
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 3312d4ed1d798d..3d223c345ea156 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -859,7 +859,7 @@ class Preprocessor {
auto *Info = State.dyn_cast<ModuleMacroInfo*>();
if (!Info) {
Info = new (PP.getPreprocessorAllocator())
- ModuleMacroInfo(State.get<MacroDirective *>());
+ ModuleMacroInfo(cast<MacroDirective *>(State));
State = Info;
}
@@ -892,7 +892,7 @@ class Preprocessor {
MacroDirective *getLatest() const {
if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
return Info->MD;
- return State.get<MacroDirective*>();
+ return cast<MacroDirective *>(State);
}
void setLatest(MacroDirective *MD) {
@@ -945,7 +945,7 @@ class Preprocessor {
if (Overrides.empty())
return;
Info = new (PP.getPreprocessorAllocator())
- ModuleMacroInfo(State.get<MacroDirective *>());
+ ModuleMacroInfo(cast<MacroDirective *>(State));
State = Info;
}
Info->OverriddenMacros.clear();
diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp
index 35472e705cfd8d..5b14d138b6e284 100644
--- a/clang/lib/Analysis/PathDiagnostic.cpp
+++ b/clang/lib/Analysis/PathDiagnostic.cpp
@@ -484,10 +484,10 @@ SourceLocation PathDiagnosticLocation::getValidSourceLocation(
// source code, so find an enclosing statement and use its location.
if (!L.isValid()) {
AnalysisDeclContext *ADC;
- if (LAC.is<const LocationContext*>())
- ADC = LAC.get<const LocationContext*>()->getAnalysisDeclContext();
+ if (auto *LC = dyn_cast<const LocationContext *>(LAC))
+ ADC = LC->getAnalysisDeclContext();
else
- ADC = LAC.get<AnalysisDeclContext*>();
+ ADC = cast<AnalysisDeclContext *>(LAC);
ParentMap &PM = ADC->getParentMap();
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 2876c290a26b13..f44b5e4c4b6389 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -398,7 +398,7 @@ FileEntryRef FileManager::getVirtualFileRef(StringRef Filename, off_t Size,
{Filename, std::errc::no_such_file_or_directory}).first;
if (NamedFileEnt.second) {
FileEntryRef::MapValue Value = *NamedFileEnt.second;
- if (LLVM_LIKELY(Value.V.is<FileEntry *>()))
+ if (LLVM_LIKELY(isa<FileEntry *>(Value.V)))
return FileEntryRef(NamedFileEnt);
return FileEntryRef(*Value.V.get<const FileEntryRef::MapEntry *>());
}
diff --git a/clang/lib/Index/FileIndexRecord.cpp b/clang/lib/Index/FileIndexRecord.cpp
index f3a5e6b63bbc2e..449c33637eb7e8 100644
--- a/clang/lib/Index/FileIndexRecord.cpp
+++ b/clang/lib/Index/FileIndexRecord.cpp
@@ -65,7 +65,7 @@ void FileIndexRecord::print(llvm::raw_ostream &OS, SourceManager &SM) const {
OS << ' ' << ND->getDeclName();
}
} else {
- const auto *MI = DclInfo.DeclOrMacro.get<const MacroInfo *>();
+ const auto *MI = cast<const MacroInfo *>(DclInfo.DeclOrMacro);
SourceLocation Loc = SM.getFileLoc(MI->getDefinitionLoc());
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
OS << llvm::sys::path::filename(PLoc.getFilename()) << ':'
diff --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp
index a7fa6c5e6898ec..19cff0398e21e3 100644
--- a/clang/lib/Index/IndexDecl.cpp
+++ b/clang/lib/Index/IndexDecl.cpp
@@ -665,9 +665,9 @@ class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> {
ClassTemplatePartialSpecializationDecl *>
Template = D->getSpecializedTemplateOrPartial();
const Decl *SpecializationOf =
- Template.is<ClassTemplateDecl *>()
+ isa<ClassTemplateDecl *>(Template)
? (Decl *)Template.get<ClassTemplateDecl *>()
- : Template.get<ClassTemplatePartialSpecializationDecl *>();
+ : cast<ClassTemplatePartialSpecializationDecl *>(Template);
if (!D->isThisDeclarationADefinition())
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);
IndexCtx.indexTagDecl(
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index def4524449355a..221f419861af10 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -5270,7 +5270,7 @@ CXString clang_getCursorSpelling(CXCursor C) {
if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>())
return cxstring::createDup(E->getName().getAsString());
OverloadedTemplateStorage *Ovl =
- Storage.get<OverloadedTemplateStorage *>();
+ cast<OverloadedTemplateStorage *>(Storage);
if (Ovl->size() == 0)
return cxstring::createEmpty();
return cxstring::createDup((*Ovl->begin())->getNameAsString());
@@ -7309,7 +7309,7 @@ unsigned clang_getNumOverloadedDecls(CXCursor C) {
Storage.dyn_cast<OverloadedTemplateStorage *>())
return S->size();
- const Decl *D = Storage.get<const Decl *>();
+ const Decl *D = cast<const Decl *>(Storage);
if (const UsingDecl *Using = dyn_cast<UsingDecl>(D))
return Using->shadow_size();
@@ -7332,7 +7332,7 @@ CXCursor clang_getOverloadedDecl(CXCursor cursor, unsigned index) {
Storage.dyn_cast<OverloadedTemplateStorage *>())
return MakeCXCursor(S->begin()[index], TU);
- const Decl *D = Storage.get<const Decl *>();
+ const Decl *D = cast<const Decl *>(Storage);
if (const UsingDecl *Using = dyn_cast<UsingDecl>(D)) {
// FIXME: This is, unfortunately, linear time.
UsingDecl::shadow_iterator Pos = Using->shadow_begin();
diff --git a/clang/tools/libclang/CIndexCXX.cpp b/clang/tools/libclang/CIndexCXX.cpp
index ea6f97d39644e1..a1be70dde9f670 100644
--- a/clang/tools/libclang/CIndexCXX.cpp
+++ b/clang/tools/libclang/CIndexCXX.cpp
@@ -101,11 +101,11 @@ CXCursor clang_getSpecializedCursorTemplate(CXCursor C) {
llvm::PointerUnion<ClassTemplateDecl *,
ClassTemplatePartialSpecializationDecl *> Result
= ClassSpec->getSpecializedTemplateOrPartial();
- if (Result.is<ClassTemplateDecl *>())
- Template = Result.get<ClassTemplateDecl *>();
+ if (isa<ClassTemplateDecl *>(Result))
+ Template = cast<ClassTemplateDecl *>(Result);
else
- Template = Result.get<ClassTemplatePartialSpecializationDecl *>();
-
+ Template = cast<ClassTemplatePartialSpecializationDecl *>(Result);
+
} else
Template = CXXRecord->getInstantiatedFromMemberClass();
} else if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index a9faba0d84403b..72b3468dac486f 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -362,7 +362,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
if (auto *V = DiagsInPedantic.dyn_cast<RecordVec *>())
V->push_back(R);
else
- DiagsInPedantic.get<RecordSet *>()->insert(R);
+ cast<RecordSet *>(DiagsInPedantic)->insert(R);
}
if (!GroupsInPedantic)
@@ -389,7 +389,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
if (auto *V = GroupsInPedantic.dyn_cast<RecordVec *>())
V->push_back(Group);
else
- GroupsInPedantic.get<RecordSet *>()->insert(Group);
+ cast<RecordSet *>(GroupsInPedantic)->insert(Group);
}
}
More information about the cfe-commits
mailing list