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

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

Loading