Skip to content

Commit 4183969

Browse files
committed
Handle empty names by not emitting any namespace scope
1 parent 3588bde commit 4183969

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

llvm/include/llvm/TableGen/CodeGenHelpers.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,21 @@ class IncludeGuardEmitter {
5050
};
5151

5252
// Simple RAII helper for emitting namespace scope. Name can be a single
53-
// namespace (empty for anonymous namespace) or nested namespace.
53+
// namespace or nested namespace. If the name is empty, will not generate any
54+
// namespace scope.
5455
class NamespaceEmitter {
5556
public:
56-
NamespaceEmitter(raw_ostream &OS, StringRef Name)
57-
: Name(trim(Name).str()), OS(OS) {
58-
OS << "namespace " << this->Name << " {\n";
57+
NamespaceEmitter(raw_ostream &OS, StringRef NameUntrimmed)
58+
: Name(trim(NameUntrimmed).str()), OS(OS) {
59+
if (!Name.empty())
60+
OS << "namespace " << Name << " {\n";
5961
}
6062

6163
~NamespaceEmitter() { close(); }
6264

6365
// Explicit function to close the namespace scopes.
6466
void close() {
65-
if (!Closed)
67+
if (!Closed && !Name.empty())
6668
OS << "} // namespace " << Name << "\n";
6769
Closed = true;
6870
}

0 commit comments

Comments
 (0)