[Lldb-commits] [lldb] 6576120 - [clang][NFC] Refactor `LinkageSpecDecl::LanguageIDs`
Vlad Serebrennikov via lldb-commits
lldb-commits at lists.llvm.org
Wed Nov 1 06:44:40 PDT 2023
Author: Vlad Serebrennikov
Date: 2023-11-01T16:44:34+03:00
New Revision: 65761200ce4e1f366e8418652efdafd2f744291b
URL: https://github.com/llvm/llvm-project/commit/65761200ce4e1f366e8418652efdafd2f744291b
DIFF: https://github.com/llvm/llvm-project/commit/65761200ce4e1f366e8418652efdafd2f744291b.diff
LOG: [clang][NFC] Refactor `LinkageSpecDecl::LanguageIDs`
This patch converts `LinkageSpecDecl::LanguageIDs` into scoped enum, and moves it to namespace scope, so that it can be forward-declared where required.
Added:
Modified:
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclCXX.h
clang/lib/AST/DeclBase.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaModule.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
lldb/source/Plugins/ExpressionParser/Clang/NameSearchContext.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index 6f2c5b96554a9d1..32b6aed6397668c 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1430,6 +1430,8 @@ enum class OMPDeclareReductionInitKind {
enum class ObjCImplementationControl { None, Required, Optional };
+enum class LinkageSpecLanguageIDs;
+
/// DeclContext - This is used only as base class of specific decl types that
/// can act as declaration contexts. These decls are (only the top classes
/// that directly derive from DeclContext are mentioned, not their subclasses):
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index 5eaae6bdd2bc63e..df1dc5a401f39a5 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -2897,6 +2897,12 @@ class CXXConversionDecl : public CXXMethodDecl {
static bool classofKind(Kind K) { return K == CXXConversion; }
};
+/// Represents the language in a linkage specification.
+///
+/// The values are part of the serialization ABI for
+/// ASTs and cannot be changed without altering that ABI.
+enum class LinkageSpecLanguageIDs { C = 1, CXX = 2 };
+
/// Represents a linkage specification.
///
/// For example:
@@ -2907,14 +2913,7 @@ class LinkageSpecDecl : public Decl, public DeclContext {
virtual void anchor();
// This class stores some data in DeclContext::LinkageSpecDeclBits to save
// some space. Use the provided accessors to access it.
-public:
- /// Represents the language in a linkage specification.
- ///
- /// The values are part of the serialization ABI for
- /// ASTs and cannot be changed without altering that ABI.
- enum LanguageIDs { lang_c = 1, lang_cxx = 2 };
-private:
/// The source location for the extern keyword.
SourceLocation ExternLoc;
@@ -2922,22 +2921,25 @@ class LinkageSpecDecl : public Decl, public DeclContext {
SourceLocation RBraceLoc;
LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
- SourceLocation LangLoc, LanguageIDs lang, bool HasBraces);
+ SourceLocation LangLoc, LinkageSpecLanguageIDs lang,
+ bool HasBraces);
public:
static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation ExternLoc,
- SourceLocation LangLoc, LanguageIDs Lang,
- bool HasBraces);
+ SourceLocation LangLoc,
+ LinkageSpecLanguageIDs Lang, bool HasBraces);
static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
/// Return the language specified by this linkage specification.
- LanguageIDs getLanguage() const {
- return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language);
+ LinkageSpecLanguageIDs getLanguage() const {
+ return static_cast<LinkageSpecLanguageIDs>(LinkageSpecDeclBits.Language);
}
/// Set the language specified by this linkage specification.
- void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; }
+ void setLanguage(LinkageSpecLanguageIDs L) {
+ LinkageSpecDeclBits.Language = llvm::to_underlying(L);
+ }
/// Determines whether this linkage specification had braces in
/// its syntactic form.
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index a3847a73faf8183..3fd4751d6d1f31d 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1320,7 +1320,7 @@ bool DeclContext::isTransparentContext() const {
}
static bool isLinkageSpecContext(const DeclContext *DC,
- LinkageSpecDecl::LanguageIDs ID) {
+ LinkageSpecLanguageIDs ID) {
while (DC->getDeclKind() != Decl::TranslationUnit) {
if (DC->getDeclKind() == Decl::LinkageSpec)
return cast<LinkageSpecDecl>(DC)->getLanguage() == ID;
@@ -1330,14 +1330,14 @@ static bool isLinkageSpecContext(const DeclContext *DC,
}
bool DeclContext::isExternCContext() const {
- return isLinkageSpecContext(this, LinkageSpecDecl::lang_c);
+ return isLinkageSpecContext(this, LinkageSpecLanguageIDs::C);
}
const LinkageSpecDecl *DeclContext::getExternCContext() const {
const DeclContext *DC = this;
while (DC->getDeclKind() != Decl::TranslationUnit) {
if (DC->getDeclKind() == Decl::LinkageSpec &&
- cast<LinkageSpecDecl>(DC)->getLanguage() == LinkageSpecDecl::lang_c)
+ cast<LinkageSpecDecl>(DC)->getLanguage() == LinkageSpecLanguageIDs::C)
return cast<LinkageSpecDecl>(DC);
DC = DC->getLexicalParent();
}
@@ -1345,7 +1345,7 @@ const LinkageSpecDecl *DeclContext::getExternCContext() const {
}
bool DeclContext::isExternCXXContext() const {
- return isLinkageSpecContext(this, LinkageSpecDecl::lang_cxx);
+ return isLinkageSpecContext(this, LinkageSpecLanguageIDs::CXX);
}
bool DeclContext::Encloses(const DeclContext *DC) const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 7f42decda51216f..066b62b7c24110d 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -2854,8 +2854,8 @@ bool CXXConversionDecl::isLambdaToBlockPointerConversion() const {
}
LinkageSpecDecl::LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
- SourceLocation LangLoc, LanguageIDs lang,
- bool HasBraces)
+ SourceLocation LangLoc,
+ LinkageSpecLanguageIDs lang, bool HasBraces)
: Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
ExternLoc(ExternLoc), RBraceLoc(SourceLocation()) {
setLanguage(lang);
@@ -2864,19 +2864,19 @@ LinkageSpecDecl::LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
void LinkageSpecDecl::anchor() {}
-LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
- DeclContext *DC,
+LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation ExternLoc,
SourceLocation LangLoc,
- LanguageIDs Lang,
+ LinkageSpecLanguageIDs Lang,
bool HasBraces) {
return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces);
}
LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C,
unsigned ID) {
- return new (C, ID) LinkageSpecDecl(nullptr, SourceLocation(),
- SourceLocation(), lang_c, false);
+ return new (C, ID)
+ LinkageSpecDecl(nullptr, SourceLocation(), SourceLocation(),
+ LinkageSpecLanguageIDs::C, false);
}
void UsingDirectiveDecl::anchor() {}
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 98fba958064a106..30a26d518386c52 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -1194,10 +1194,10 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
const char *l;
- if (D->getLanguage() == LinkageSpecDecl::lang_c)
+ if (D->getLanguage() == LinkageSpecLanguageIDs::C)
l = "C";
else {
- assert(D->getLanguage() == LinkageSpecDecl::lang_cxx &&
+ assert(D->getLanguage() == LinkageSpecLanguageIDs::CXX &&
"unknown language in linkage specification");
l = "C++";
}
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index abc3b273433ac5e..dc82e05528d8f42 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -1027,8 +1027,12 @@ void JSONNodeDumper::VisitTemplateTemplateParmDecl(
void JSONNodeDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *LSD) {
StringRef Lang;
switch (LSD->getLanguage()) {
- case LinkageSpecDecl::lang_c: Lang = "C"; break;
- case LinkageSpecDecl::lang_cxx: Lang = "C++"; break;
+ case LinkageSpecLanguageIDs::C:
+ Lang = "C";
+ break;
+ case LinkageSpecLanguageIDs::CXX:
+ Lang = "C++";
+ break;
}
JOS.attribute("language", Lang);
attributeOnlyIfTrue("hasBraces", LSD->hasBraces());
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index bbdfd4523c8200c..8d0f421e3a7dbc9 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -2413,10 +2413,10 @@ void TextNodeDumper::VisitConstructorUsingShadowDecl(
void TextNodeDumper::VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
switch (D->getLanguage()) {
- case LinkageSpecDecl::lang_c:
+ case LinkageSpecLanguageIDs::C:
OS << " C";
break;
- case LinkageSpecDecl::lang_cxx:
+ case LinkageSpecLanguageIDs::CXX:
OS << " C++";
break;
}
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 5b80478d2265c7f..cc81a68b15c4324 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6514,8 +6514,8 @@ void CodeGenModule::EmitObjCIvarInitializations(ObjCImplementationDecl *D) {
// EmitLinkageSpec - Emit all declarations in a linkage spec.
void CodeGenModule::EmitLinkageSpec(const LinkageSpecDecl *LSD) {
- if (LSD->getLanguage() != LinkageSpecDecl::lang_c &&
- LSD->getLanguage() != LinkageSpecDecl::lang_cxx) {
+ if (LSD->getLanguage() != LinkageSpecLanguageIDs::C &&
+ LSD->getLanguage() != LinkageSpecLanguageIDs::CXX) {
ErrorUnsupported(LSD, "linkage spec");
return;
}
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 96128850f5be0c1..a1cafa0c6ad29a0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2407,7 +2407,7 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, QualType Type,
if (getLangOpts().CPlusPlus) {
LinkageSpecDecl *CLinkageDecl = LinkageSpecDecl::Create(
- Context, Parent, Loc, Loc, LinkageSpecDecl::lang_c, false);
+ Context, Parent, Loc, Loc, LinkageSpecLanguageIDs::C, false);
CLinkageDecl->setImplicit();
Parent->addDecl(CLinkageDecl);
Parent = CLinkageDecl;
@@ -16627,11 +16627,10 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
IdentifierInfo *Name = FD->getIdentifier();
if (!Name)
return;
- if ((!getLangOpts().CPlusPlus &&
- FD->getDeclContext()->isTranslationUnit()) ||
+ if ((!getLangOpts().CPlusPlus && FD->getDeclContext()->isTranslationUnit()) ||
(isa<LinkageSpecDecl>(FD->getDeclContext()) &&
cast<LinkageSpecDecl>(FD->getDeclContext())->getLanguage() ==
- LinkageSpecDecl::lang_c)) {
+ LinkageSpecLanguageIDs::C)) {
// Okay: this could be a libc/libm/Objective-C function we know
// about.
} else
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 8d74ecd375f6737..f2d6db41e77a377 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -16784,11 +16784,11 @@ Decl *Sema::ActOnStartLinkageSpecification(Scope *S, SourceLocation ExternLoc,
assert(Lit->isUnevaluated() && "Unexpected string literal kind");
StringRef Lang = Lit->getString();
- LinkageSpecDecl::LanguageIDs Language;
+ LinkageSpecLanguageIDs Language;
if (Lang == "C")
- Language = LinkageSpecDecl::lang_c;
+ Language = LinkageSpecLanguageIDs::C;
else if (Lang == "C++")
- Language = LinkageSpecDecl::lang_cxx;
+ Language = LinkageSpecLanguageIDs::CXX;
else {
Diag(LangStr->getExprLoc(), diag::err_language_linkage_spec_unknown)
<< LangStr->getSourceRange();
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index f8fc27188824eb5..5582afb119047bc 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -28,11 +28,11 @@ static void checkModuleImportContext(Sema &S, Module *M,
if (auto *LSD = dyn_cast<LinkageSpecDecl>(DC)) {
switch (LSD->getLanguage()) {
- case LinkageSpecDecl::lang_c:
+ case LinkageSpecLanguageIDs::C:
if (ExternCLoc.isInvalid())
ExternCLoc = LSD->getBeginLoc();
break;
- case LinkageSpecDecl::lang_cxx:
+ case LinkageSpecLanguageIDs::CXX:
break;
}
DC = LSD->getParent();
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 4b1d265d8250fe3..a97b992fcf6e97a 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1773,7 +1773,7 @@ void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) {
void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
VisitDecl(D);
- D->setLanguage((LinkageSpecDecl::LanguageIDs)Record.readInt());
+ D->setLanguage(static_cast<LinkageSpecLanguageIDs>(Record.readInt()));
D->setExternLoc(readSourceLocation());
D->setRBraceLoc(readSourceLocation());
}
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index 9e1816e97b3fd62..78c5e1750dbca64 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1273,7 +1273,7 @@ void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
"LinkageSpecDeclBits");
VisitDecl(D);
- Record.push_back(D->getLanguage());
+ Record.push_back(llvm::to_underlying(D->getLanguage()));
Record.AddSourceLocation(D->getExternLoc());
Record.AddSourceLocation(D->getRBraceLoc());
Code = serialization::DECL_LINKAGE_SPEC;
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/NameSearchContext.cpp b/lldb/source/Plugins/ExpressionParser/Clang/NameSearchContext.cpp
index a67cc8e10c175d4..da59855a9f1628f 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/NameSearchContext.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/NameSearchContext.cpp
@@ -62,9 +62,9 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type,
clang::DeclContext *context = const_cast<DeclContext *>(m_decl_context);
if (extern_c) {
- context = LinkageSpecDecl::Create(
- ast, context, SourceLocation(), SourceLocation(),
- clang::LinkageSpecDecl::LanguageIDs::lang_c, false);
+ context = LinkageSpecDecl::Create(ast, context, SourceLocation(),
+ SourceLocation(),
+ clang::LinkageSpecLanguageIDs::C, false);
// FIXME: The LinkageSpecDecl here should be added to m_decl_context.
}
More information about the lldb-commits
mailing list