Skip to content

[clang] Migrate away from PointerUnion::{is,get} (NFC) #119654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/include/clang/Lex/PreprocessingRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/Lex/Preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Analysis/PathDiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 *>());
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Index/FileIndexRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) << ':'
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Index/IndexDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();

Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions clang/tools/libclang/CIndexCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}

Expand Down
Loading