16
16
#include " llvm/TableGen/Error.h"
17
17
#include " llvm/TableGen/Record.h"
18
18
#include " llvm/TableGen/TableGenBackend.h"
19
- #include < cctype>
20
19
#include < map>
21
20
#include < set>
22
21
#include < string>
@@ -42,17 +41,12 @@ class ClangASTNodesEmitter {
42
41
ChildMap Tree;
43
42
44
43
// Create a macro-ized version of a name
45
- static std::string macroName (std::string S) {
46
- for (unsigned i = 0 ; i < S.size (); ++i)
47
- S[i] = std::toupper (S[i]);
48
-
49
- return S;
50
- }
44
+ static std::string macroName (StringRef S) { return S.upper (); }
51
45
52
46
const std::string ¯oHierarchyName () {
53
47
assert (Root && " root node not yet derived!" );
54
48
if (MacroHierarchyName.empty ())
55
- MacroHierarchyName = macroName (std::string ( Root.getName () ));
49
+ MacroHierarchyName = macroName (Root.getName ());
56
50
return MacroHierarchyName;
57
51
}
58
52
@@ -93,34 +87,30 @@ class ClangASTNodesEmitter {
93
87
// Called recursively to ensure that nodes remain contiguous
94
88
std::pair<ASTNode, ASTNode> ClangASTNodesEmitter::EmitNode (raw_ostream &OS,
95
89
ASTNode Base) {
96
- std::string BaseName = macroName (std::string ( Base.getName () ));
90
+ std::string BaseName = macroName (Base.getName ());
97
91
98
- ChildIterator i = Tree. lower_bound (Base), e = Tree.upper_bound (Base);
99
- bool HasChildren = (i != e) ;
92
+ auto [II, E] = Tree.equal_range (Base);
93
+ bool HasChildren = II != E ;
100
94
101
95
ASTNode First, Last;
102
96
if (!Base.isAbstract ())
103
97
First = Last = Base;
104
98
105
- auto comp = [this ](ASTNode LHS, ASTNode RHS) {
106
- auto LHSPrioritized = PrioritizedClasses.count (LHS) > 0 ;
107
- auto RHSPrioritized = PrioritizedClasses.count (RHS) > 0 ;
108
- if (LHSPrioritized && !RHSPrioritized)
109
- return true ;
110
- if (!LHSPrioritized && RHSPrioritized)
111
- return false ;
112
-
113
- return LHS.getName () > RHS.getName ();
99
+ auto Comp = [this ](const ASTNode &LHS, const ASTNode &RHS) {
100
+ bool LHSPrioritized = PrioritizedClasses.count (LHS) > 0 ;
101
+ bool RHSPrioritized = PrioritizedClasses.count (RHS) > 0 ;
102
+ return std::tuple (LHSPrioritized, LHS.getName ()) >
103
+ std::tuple (RHSPrioritized, RHS.getName ());
114
104
};
115
- auto SortedChildren = std::set<ASTNode, decltype (comp )>(comp );
105
+ auto SortedChildren = std::set<ASTNode, decltype (Comp )>(Comp );
116
106
117
- for (; i != e ; ++i ) {
118
- SortedChildren.insert (i ->second );
107
+ for (; II != E ; ++II ) {
108
+ SortedChildren.insert (II ->second );
119
109
}
120
110
121
111
for (const auto &Child : SortedChildren) {
122
112
bool Abstract = Child.isAbstract ();
123
- std::string NodeName = macroName (std::string ( Child.getName () ));
113
+ std::string NodeName = macroName (Child.getName ());
124
114
125
115
OS << " #ifndef " << NodeName << " \n " ;
126
116
OS << " # define " << NodeName << " (Type, Base) "
@@ -144,9 +134,8 @@ std::pair<ASTNode, ASTNode> ClangASTNodesEmitter::EmitNode(raw_ostream &OS,
144
134
145
135
// If there aren't first/last nodes, it must be because there were no
146
136
// children and this node was abstract, which is not a sensible combination.
147
- if (!First) {
137
+ if (!First)
148
138
PrintFatalError (Base.getLoc (), " abstract node has no children" );
149
- }
150
139
assert (Last && " set First without Last" );
151
140
152
141
if (HasChildren) {
@@ -169,7 +158,7 @@ void ClangASTNodesEmitter::deriveChildTree() {
169
158
// Emit statements
170
159
for (const Record *R : Records.getAllDerivedDefinitions (NodeClassName)) {
171
160
if (auto B = R->getValueAsOptionalDef (BaseFieldName))
172
- Tree.insert (std::make_pair ( B, R) );
161
+ Tree.insert ({ B, R} );
173
162
else if (Root)
174
163
PrintFatalError (R->getLoc (),
175
164
Twine (" multiple root nodes in \" " ) + NodeClassName
@@ -222,10 +211,9 @@ void printDeclContext(const std::multimap<const Record *, const Record *> &Tree,
222
211
const Record *DeclContext, raw_ostream &OS) {
223
212
if (!DeclContext->getValueAsBit (AbstractFieldName))
224
213
OS << " DECL_CONTEXT(" << DeclContext->getName () << " )\n " ;
225
- auto i = Tree.lower_bound (DeclContext);
226
- auto end = Tree.upper_bound (DeclContext);
227
- for (; i != end; ++i) {
228
- printDeclContext (Tree, i->second , OS);
214
+ auto [II, E] = Tree.equal_range (DeclContext);
215
+ for (; II != E; ++II) {
216
+ printDeclContext (Tree, II->second , OS);
229
217
}
230
218
}
231
219
@@ -244,7 +232,7 @@ void clang::EmitClangDeclContext(const RecordKeeper &Records, raw_ostream &OS) {
244
232
245
233
for (const Record *R : Records.getAllDerivedDefinitions (DeclNodeClassName)) {
246
234
if (auto *B = R->getValueAsOptionalDef (BaseFieldName))
247
- Tree.insert (std::make_pair ( B, R) );
235
+ Tree.insert ({ B, R} );
248
236
}
249
237
250
238
for (const Record *DeclContext :
0 commit comments