@@ -34,7 +34,7 @@ class ClangASTNodesEmitter {
34
34
typedef ChildMap::const_iterator ChildIterator;
35
35
36
36
std::set<ASTNode> PrioritizedClasses;
37
- RecordKeeper &Records;
37
+ const RecordKeeper &Records;
38
38
ASTNode Root;
39
39
const std::string &NodeClassName;
40
40
const std::string &BaseSuffix;
@@ -70,14 +70,12 @@ class ClangASTNodesEmitter {
70
70
71
71
std::pair<ASTNode, ASTNode> EmitNode (raw_ostream& OS, ASTNode Base);
72
72
public:
73
- explicit ClangASTNodesEmitter (RecordKeeper &R, const std::string &N,
73
+ explicit ClangASTNodesEmitter (const RecordKeeper &R, const std::string &N,
74
74
const std::string &S,
75
75
std::string_view PriorizeIfSubclassOf)
76
76
: Records(R), NodeClassName(N), BaseSuffix(S) {
77
- auto vecPrioritized =
78
- PriorizeIfSubclassOf.empty ()
79
- ? std::vector<Record *>{}
80
- : R.getAllDerivedDefinitions (PriorizeIfSubclassOf);
77
+ ArrayRef<const Record *> vecPrioritized =
78
+ R.getAllDerivedDefinitionsIfDefined (PriorizeIfSubclassOf);
81
79
PrioritizedClasses =
82
80
std::set<ASTNode>(vecPrioritized.begin (), vecPrioritized.end ());
83
81
}
@@ -169,10 +167,7 @@ void ClangASTNodesEmitter::deriveChildTree() {
169
167
assert (!Root && " already computed tree" );
170
168
171
169
// Emit statements
172
- const std::vector<Record*> Stmts
173
- = Records.getAllDerivedDefinitions (NodeClassName);
174
-
175
- for (auto *R : Stmts) {
170
+ for (const Record *R : Records.getAllDerivedDefinitions (NodeClassName)) {
176
171
if (auto B = R->getValueAsOptionalDef (BaseFieldName))
177
172
Tree.insert (std::make_pair (B, R));
178
173
else if (Root)
@@ -217,14 +212,14 @@ void ClangASTNodesEmitter::run(raw_ostream &OS) {
217
212
OS << " #undef ABSTRACT_" << macroHierarchyName () << " \n " ;
218
213
}
219
214
220
- void clang::EmitClangASTNodes (RecordKeeper &RK, raw_ostream &OS,
215
+ void clang::EmitClangASTNodes (const RecordKeeper &RK, raw_ostream &OS,
221
216
const std::string &N, const std::string &S,
222
217
std::string_view PriorizeIfSubclassOf) {
223
218
ClangASTNodesEmitter (RK, N, S, PriorizeIfSubclassOf).run (OS);
224
219
}
225
220
226
- void printDeclContext (const std::multimap<Record *, Record *> &Tree,
227
- Record *DeclContext, raw_ostream &OS) {
221
+ void printDeclContext (const std::multimap<const Record *, const Record *> &Tree,
222
+ const Record *DeclContext, raw_ostream &OS) {
228
223
if (!DeclContext->getValueAsBit (AbstractFieldName))
229
224
OS << " DECL_CONTEXT(" << DeclContext->getName () << " )\n " ;
230
225
auto i = Tree.lower_bound (DeclContext);
@@ -236,7 +231,7 @@ void printDeclContext(const std::multimap<Record *, Record *> &Tree,
236
231
237
232
// Emits and addendum to a .inc file to enumerate the clang declaration
238
233
// contexts.
239
- void clang::EmitClangDeclContext (RecordKeeper &Records, raw_ostream &OS) {
234
+ void clang::EmitClangDeclContext (const RecordKeeper &Records, raw_ostream &OS) {
240
235
// FIXME: Find a .td file format to allow for this to be represented better.
241
236
242
237
emitSourceFileHeader (" List of AST Decl nodes" , OS, Records);
@@ -245,22 +240,15 @@ void clang::EmitClangDeclContext(RecordKeeper &Records, raw_ostream &OS) {
245
240
OS << " # define DECL_CONTEXT(DECL)\n " ;
246
241
OS << " #endif\n " ;
247
242
248
- std::vector<Record *> DeclContextsVector =
249
- Records.getAllDerivedDefinitions (DeclContextNodeClassName);
250
- std::vector<Record *> Decls =
251
- Records.getAllDerivedDefinitions (DeclNodeClassName);
252
-
253
- std::multimap<Record *, Record *> Tree;
254
-
255
- const std::vector<Record *> Stmts =
256
- Records.getAllDerivedDefinitions (DeclNodeClassName);
243
+ std::multimap<const Record *, const Record *> Tree;
257
244
258
- for (auto *R : Stmts ) {
245
+ for (const Record *R : Records. getAllDerivedDefinitions (DeclNodeClassName) ) {
259
246
if (auto *B = R->getValueAsOptionalDef (BaseFieldName))
260
247
Tree.insert (std::make_pair (B, R));
261
248
}
262
249
263
- for (auto *DeclContext : DeclContextsVector) {
250
+ for (const Record *DeclContext :
251
+ Records.getAllDerivedDefinitions (DeclContextNodeClassName)) {
264
252
printDeclContext (Tree, DeclContext, OS);
265
253
}
266
254
0 commit comments