Skip to content

Commit e22f525

Browse files
committed
Handle empty names by not emitting any namespace scope
1 parent 95ee942 commit e22f525

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
@@ -35,19 +35,21 @@ class IfDefEmitter {
3535
};
3636

3737
// Simple RAII helper for emitting namespace scope. Name can be a single
38-
// namespace (empty for anonymous namespace) or nested namespace.
38+
// namespace or nested namespace. If the name is empty, will not generate any
39+
// namespace scope.
3940
class NamespaceEmitter {
4041
public:
41-
NamespaceEmitter(raw_ostream &OS, StringRef Name)
42-
: Name(trim(Name).str()), OS(OS) {
43-
OS << "namespace " << this->Name << " {\n";
42+
NamespaceEmitter(raw_ostream &OS, StringRef NameUntrimmed)
43+
: Name(trim(NameUntrimmed).str()), OS(OS) {
44+
if (!Name.empty())
45+
OS << "namespace " << Name << " {\n";
4446
}
4547

4648
~NamespaceEmitter() { close(); }
4749

4850
// Explicit function to close the namespace scopes.
4951
void close() {
50-
if (!Closed)
52+
if (!Closed && !Name.empty())
5153
OS << "} // namespace " << Name << "\n";
5254
Closed = true;
5355
}

0 commit comments

Comments
 (0)