Skip to content

Commit 23bf93f

Browse files
committed
Use NamespaceEmitter in DirectiveEmitter
1 parent 3f343bb commit 23bf93f

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

llvm/include/llvm/TableGen/CodeGenHelpers.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ class NamespaceEmitter {
4242
emitNamespaceStarts(Name);
4343
}
4444

45-
~NamespaceEmitter() {
45+
~NamespaceEmitter() { close(); }
46+
47+
// Explicit function to close the namespace scopes.
48+
void close() {
4649
for (StringRef NS : llvm::reverse(Namespaces))
4750
OS << "} // namespace " << NS << "\n";
51+
Namespaces.clear();
4852
}
4953

5054
private:

llvm/utils/TableGen/Basic/DirectiveEmitter.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,8 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
281281
OS << "#include <cstddef>\n"; // for size_t
282282
OS << "#include <utility>\n"; // for std::pair
283283
OS << "\n";
284-
OS << "namespace llvm {\n";
285-
286-
// Open namespaces defined in the directive language
287-
SmallVector<StringRef, 2> Namespaces;
288-
SplitString(DirLang.getCppNamespace(), Namespaces, "::");
289-
for (auto Ns : Namespaces)
290-
OS << "namespace " << Ns << " {\n";
284+
NamespaceEmitter LlvmNS(OS, "llvm");
285+
NamespaceEmitter DirLangNS(OS, DirLang.getCppNamespace());
291286

292287
if (DirLang.hasEnableBitmaskEnumInNamespace())
293288
OS << "\nLLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();\n";
@@ -364,9 +359,7 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
364359
OS << "\n";
365360
}
366361

367-
// Closing namespaces
368-
for (auto Ns : reverse(Namespaces))
369-
OS << "} // namespace " << Ns << "\n";
362+
DirLangNS.close();
370363

371364
// These specializations need to be in ::llvm.
372365
for (StringRef Enum : {"Association", "Category", "Directive", "Clause"}) {
@@ -376,9 +369,7 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
376369
OS << " static constexpr bool is_iterable = true;\n";
377370
OS << "};\n";
378371
}
379-
380-
OS << "} // namespace llvm\n";
381-
372+
LlvmNS.close();
382373
OS << "#endif // LLVM_" << Lang << "_INC\n";
383374
}
384375

0 commit comments

Comments
 (0)