-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[NFC][TableGen] Adopt NamespaceEmitter in DirectiveEmitter #165600
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
jurahul
merged 1 commit into
llvm:main
from
jurahul:nfc_adopt_ns_emitter_in_directive_emitter
Nov 5, 2025
Merged
[NFC][TableGen] Adopt NamespaceEmitter in DirectiveEmitter #165600
jurahul
merged 1 commit into
llvm:main
from
jurahul:nfc_adopt_ns_emitter_in_directive_emitter
Nov 5, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-tablegen Author: Rahul Joshi (jurahul) ChangesFull diff: https://github.com/llvm/llvm-project/pull/165600.diff 3 Files Affected:
diff --git a/llvm/test/TableGen/directive1.td b/llvm/test/TableGen/directive1.td
index 475faf9254157..ef85a94f1ec41 100644
--- a/llvm/test/TableGen/directive1.td
+++ b/llvm/test/TableGen/directive1.td
@@ -184,8 +184,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// IMPL: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-EMPTY:
-// IMPL-NEXT: namespace llvm {
-// IMPL-NEXT: namespace tdl {
+// IMPL-NEXT: namespace llvm::tdl {
// IMPL-EMPTY:
// IMPL-NEXT: // Sets for dira
// IMPL-EMPTY:
@@ -202,8 +201,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// IMPL-EMPTY:
// IMPL-NEXT: static requiredClauses_TDLD_dira {
// IMPL-NEXT: };
-// IMPL-NEXT: } // namespace tdl
-// IMPL-NEXT: } // namespace llvm
+// IMPL-NEXT: } // namespace llvm::tdl
// IMPL-EMPTY:
// IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-EMPTY:
diff --git a/llvm/test/TableGen/directive2.td b/llvm/test/TableGen/directive2.td
index ccc09446b4465..a2535be269d5e 100644
--- a/llvm/test/TableGen/directive2.td
+++ b/llvm/test/TableGen/directive2.td
@@ -156,8 +156,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// IMPL: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-EMPTY:
-// IMPL-NEXT: namespace llvm {
-// IMPL-NEXT: namespace tdl {
+// IMPL-NEXT: namespace llvm::tdl {
// IMPL-EMPTY:
// IMPL-NEXT: // Sets for dira
// IMPL-EMPTY:
@@ -174,8 +173,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// IMPL-EMPTY:
// IMPL-NEXT: static requiredClauses_TDLD_dira {
// IMPL-NEXT: };
-// IMPL-NEXT: } // namespace tdl
-// IMPL-NEXT: } // namespace llvm
+// IMPL-NEXT: } // namespace llvm::tdl
// IMPL-EMPTY:
// IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-EMPTY:
diff --git a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
index 3c6ff1132230b..33721e23d50a0 100644
--- a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
@@ -353,10 +353,8 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
OS << "LLVM_ABI Association getDirectiveAssociation(Directive D);\n";
OS << "LLVM_ABI Category getDirectiveCategory(Directive D);\n";
OS << "LLVM_ABI SourceLanguage getDirectiveLanguages(Directive D);\n";
- if (EnumHelperFuncs.length() > 0) {
- OS << EnumHelperFuncs;
- OS << "\n";
- }
+ if (EnumHelperFuncs.length() > 0)
+ OS << EnumHelperFuncs << '\n';
DirLangNS.close();
@@ -368,7 +366,6 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
OS << " static constexpr bool is_iterable = true;\n";
OS << "};\n";
}
- LlvmNS.close();
}
// Given a list of spellings (for a given clause/directive), order them
@@ -940,24 +937,18 @@ static void generateClauseSet(ArrayRef<const Record *> VerClauses,
// Generate an enum set for the 4 kinds of clauses linked to a directive.
static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
Frontend FE, raw_ostream &OS) {
+ IfDefEmitter Scope(OS, "GEN_" + getFESpelling(FE).upper() +
+ "_DIRECTIVE_CLAUSE_SETS");
- std::string IfDefName{"GEN_"};
- IfDefName += getFESpelling(FE).upper();
- IfDefName += "_DIRECTIVE_CLAUSE_SETS";
- IfDefEmitter Scope(OS, IfDefName);
-
- StringRef Namespace =
- getFESpelling(FE == Frontend::Flang ? Frontend::LLVM : FE);
+ std::string Namespace =
+ getFESpelling(FE == Frontend::Flang ? Frontend::LLVM : FE).str();
// The namespace has to be different for clang vs flang, as 2 structs with the
// same name but different layout is UB. So just put the 'clang' on in the
// clang namespace.
- OS << "namespace " << Namespace << " {\n";
-
- // Open namespaces defined in the directive language.
- SmallVector<StringRef, 2> Namespaces;
- SplitString(DirLang.getCppNamespace(), Namespaces, "::");
- for (auto Ns : Namespaces)
- OS << "namespace " << Ns << " {\n";
+ // Additionally, open namespaces defined in the directive language.
+ if (!DirLang.getCppNamespace().empty())
+ Namespace += "::" + DirLang.getCppNamespace().str();
+ NamespaceEmitter NS(OS, Namespace);
for (const Directive Dir : DirLang.getDirectives()) {
OS << "\n";
@@ -972,12 +963,6 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
generateClauseSet(Dir.getRequiredClauses(), OS, "requiredClauses_", Dir,
DirLang, FE);
}
-
- // Closing namespaces
- for (auto Ns : reverse(Namespaces))
- OS << "} // namespace " << Ns << "\n";
-
- OS << "} // namespace " << Namespace << "\n";
}
// Generate a map of directive (key) with DirectiveClauses struct as values.
@@ -985,10 +970,8 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
// allowances (allowed, allowed once, allowed exclusive and required).
static void generateDirectiveClauseMap(const DirectiveLanguage &DirLang,
Frontend FE, raw_ostream &OS) {
- std::string IfDefName{"GEN_"};
- IfDefName += getFESpelling(FE).upper();
- IfDefName += "_DIRECTIVE_CLAUSE_MAP";
- IfDefEmitter Scope(OS, IfDefName);
+ IfDefEmitter Scope(OS, "GEN_" + getFESpelling(FE).upper() +
+ "_DIRECTIVE_CLAUSE_MAP");
OS << "{\n";
|
kparzysz
approved these changes
Oct 29, 2025
Contributor
kparzysz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM,
c760588 to
67afd76
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.