Skip to content

Commit 02dd73a

Browse files
authoredDec 12, 2024··
[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.
1 parent 48ed918 commit 02dd73a

File tree

9 files changed

+21
-21
lines changed

9 files changed

+21
-21
lines changed
 

‎clang/include/clang/Lex/PreprocessingRecord.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ class Token;
180180
}
181181

182182
/// True if it is a builtin macro.
183-
bool isBuiltinMacro() const { return NameOrDef.is<IdentifierInfo *>(); }
183+
bool isBuiltinMacro() const { return isa<IdentifierInfo *>(NameOrDef); }
184184

185185
/// The name of the macro being expanded.
186186
const IdentifierInfo *getName() const {
187187
if (MacroDefinitionRecord *Def = getDefinition())
188188
return Def->getName();
189-
return NameOrDef.get<IdentifierInfo *>();
189+
return cast<IdentifierInfo *>(NameOrDef);
190190
}
191191

192192
/// The definition of the macro being expanded. May return null if

‎clang/include/clang/Lex/Preprocessor.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ class Preprocessor {
859859
auto *Info = State.dyn_cast<ModuleMacroInfo*>();
860860
if (!Info) {
861861
Info = new (PP.getPreprocessorAllocator())
862-
ModuleMacroInfo(State.get<MacroDirective *>());
862+
ModuleMacroInfo(cast<MacroDirective *>(State));
863863
State = Info;
864864
}
865865

@@ -892,7 +892,7 @@ class Preprocessor {
892892
MacroDirective *getLatest() const {
893893
if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
894894
return Info->MD;
895-
return State.get<MacroDirective*>();
895+
return cast<MacroDirective *>(State);
896896
}
897897

898898
void setLatest(MacroDirective *MD) {
@@ -945,7 +945,7 @@ class Preprocessor {
945945
if (Overrides.empty())
946946
return;
947947
Info = new (PP.getPreprocessorAllocator())
948-
ModuleMacroInfo(State.get<MacroDirective *>());
948+
ModuleMacroInfo(cast<MacroDirective *>(State));
949949
State = Info;
950950
}
951951
Info->OverriddenMacros.clear();

‎clang/lib/Analysis/PathDiagnostic.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,10 @@ SourceLocation PathDiagnosticLocation::getValidSourceLocation(
484484
// source code, so find an enclosing statement and use its location.
485485
if (!L.isValid()) {
486486
AnalysisDeclContext *ADC;
487-
if (LAC.is<const LocationContext*>())
488-
ADC = LAC.get<const LocationContext*>()->getAnalysisDeclContext();
487+
if (auto *LC = dyn_cast<const LocationContext *>(LAC))
488+
ADC = LC->getAnalysisDeclContext();
489489
else
490-
ADC = LAC.get<AnalysisDeclContext*>();
490+
ADC = cast<AnalysisDeclContext *>(LAC);
491491

492492
ParentMap &PM = ADC->getParentMap();
493493

‎clang/lib/Basic/FileManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ FileEntryRef FileManager::getVirtualFileRef(StringRef Filename, off_t Size,
398398
{Filename, std::errc::no_such_file_or_directory}).first;
399399
if (NamedFileEnt.second) {
400400
FileEntryRef::MapValue Value = *NamedFileEnt.second;
401-
if (LLVM_LIKELY(Value.V.is<FileEntry *>()))
401+
if (LLVM_LIKELY(isa<FileEntry *>(Value.V)))
402402
return FileEntryRef(NamedFileEnt);
403403
return FileEntryRef(*Value.V.get<const FileEntryRef::MapEntry *>());
404404
}

‎clang/lib/Index/FileIndexRecord.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void FileIndexRecord::print(llvm::raw_ostream &OS, SourceManager &SM) const {
6565
OS << ' ' << ND->getDeclName();
6666
}
6767
} else {
68-
const auto *MI = DclInfo.DeclOrMacro.get<const MacroInfo *>();
68+
const auto *MI = cast<const MacroInfo *>(DclInfo.DeclOrMacro);
6969
SourceLocation Loc = SM.getFileLoc(MI->getDefinitionLoc());
7070
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
7171
OS << llvm::sys::path::filename(PLoc.getFilename()) << ':'

‎clang/lib/Index/IndexDecl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,9 @@ class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> {
665665
ClassTemplatePartialSpecializationDecl *>
666666
Template = D->getSpecializedTemplateOrPartial();
667667
const Decl *SpecializationOf =
668-
Template.is<ClassTemplateDecl *>()
668+
isa<ClassTemplateDecl *>(Template)
669669
? (Decl *)Template.get<ClassTemplateDecl *>()
670-
: Template.get<ClassTemplatePartialSpecializationDecl *>();
670+
: cast<ClassTemplatePartialSpecializationDecl *>(Template);
671671
if (!D->isThisDeclarationADefinition())
672672
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);
673673
IndexCtx.indexTagDecl(

‎clang/tools/libclang/CIndex.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5270,7 +5270,7 @@ CXString clang_getCursorSpelling(CXCursor C) {
52705270
if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>())
52715271
return cxstring::createDup(E->getName().getAsString());
52725272
OverloadedTemplateStorage *Ovl =
5273-
Storage.get<OverloadedTemplateStorage *>();
5273+
cast<OverloadedTemplateStorage *>(Storage);
52745274
if (Ovl->size() == 0)
52755275
return cxstring::createEmpty();
52765276
return cxstring::createDup((*Ovl->begin())->getNameAsString());
@@ -7309,7 +7309,7 @@ unsigned clang_getNumOverloadedDecls(CXCursor C) {
73097309
Storage.dyn_cast<OverloadedTemplateStorage *>())
73107310
return S->size();
73117311

7312-
const Decl *D = Storage.get<const Decl *>();
7312+
const Decl *D = cast<const Decl *>(Storage);
73137313
if (const UsingDecl *Using = dyn_cast<UsingDecl>(D))
73147314
return Using->shadow_size();
73157315

@@ -7332,7 +7332,7 @@ CXCursor clang_getOverloadedDecl(CXCursor cursor, unsigned index) {
73327332
Storage.dyn_cast<OverloadedTemplateStorage *>())
73337333
return MakeCXCursor(S->begin()[index], TU);
73347334

7335-
const Decl *D = Storage.get<const Decl *>();
7335+
const Decl *D = cast<const Decl *>(Storage);
73367336
if (const UsingDecl *Using = dyn_cast<UsingDecl>(D)) {
73377337
// FIXME: This is, unfortunately, linear time.
73387338
UsingDecl::shadow_iterator Pos = Using->shadow_begin();

‎clang/tools/libclang/CIndexCXX.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ CXCursor clang_getSpecializedCursorTemplate(CXCursor C) {
101101
llvm::PointerUnion<ClassTemplateDecl *,
102102
ClassTemplatePartialSpecializationDecl *> Result
103103
= ClassSpec->getSpecializedTemplateOrPartial();
104-
if (Result.is<ClassTemplateDecl *>())
105-
Template = Result.get<ClassTemplateDecl *>();
104+
if (isa<ClassTemplateDecl *>(Result))
105+
Template = cast<ClassTemplateDecl *>(Result);
106106
else
107-
Template = Result.get<ClassTemplatePartialSpecializationDecl *>();
108-
107+
Template = cast<ClassTemplatePartialSpecializationDecl *>(Result);
108+
109109
} else
110110
Template = CXXRecord->getInstantiatedFromMemberClass();
111111
} else if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {

‎clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
362362
if (auto *V = DiagsInPedantic.dyn_cast<RecordVec *>())
363363
V->push_back(R);
364364
else
365-
DiagsInPedantic.get<RecordSet *>()->insert(R);
365+
cast<RecordSet *>(DiagsInPedantic)->insert(R);
366366
}
367367

368368
if (!GroupsInPedantic)
@@ -389,7 +389,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
389389
if (auto *V = GroupsInPedantic.dyn_cast<RecordVec *>())
390390
V->push_back(Group);
391391
else
392-
GroupsInPedantic.get<RecordSet *>()->insert(Group);
392+
cast<RecordSet *>(GroupsInPedantic)->insert(Group);
393393
}
394394
}
395395

0 commit comments

Comments
 (0)
Please sign in to comment.