File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed
llvm/include/llvm/TableGen Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -38,28 +38,29 @@ class IfDefEmitter {
38
38
// namespace (empty for anonymous namespace) or nested namespace.
39
39
class NamespaceEmitter {
40
40
public:
41
- NamespaceEmitter (raw_ostream &OS, StringRef Name) : OS(OS) {
42
- emitNamespaceStarts (Name);
41
+ NamespaceEmitter (raw_ostream &OS, StringRef Name)
42
+ : Name(trim(Name).str()), OS(OS) {
43
+ OS << " namespace " << this ->Name << " {\n " ;
43
44
}
44
45
45
46
~NamespaceEmitter () { close (); }
46
47
47
48
// Explicit function to close the namespace scopes.
48
49
void close () {
49
- for (StringRef NS : llvm::reverse (Namespaces) )
50
- OS << " } // namespace " << NS << " \n " ;
51
- Namespaces. clear () ;
50
+ if (!Closed )
51
+ OS << " } // namespace " << Name << " \n " ;
52
+ Closed = true ;
52
53
}
53
54
54
55
private:
55
- void emitNamespaceStarts (StringRef Name) {
56
- llvm::SplitString (Name, Namespaces, " :: " );
57
- for (StringRef NS : Namespaces)
58
- OS << " namespace " << NS << " { \n " ;
56
+ // Trim "::" prefix.
57
+ static StringRef trim (StringRef Name) {
58
+ Name. consume_front ( " :: " );
59
+ return Name ;
59
60
}
60
-
61
- SmallVector<StringRef, 2 > Namespaces;
61
+ std::string Name;
62
62
raw_ostream &OS;
63
+ bool Closed = false ;
63
64
};
64
65
65
66
} // end namespace llvm
You can’t perform that action at this time.
0 commit comments