@@ -34,7 +34,7 @@ class ClangASTNodesEmitter {
3434 typedef ChildMap::const_iterator ChildIterator;
3535
3636 std::set<ASTNode> PrioritizedClasses;
37- RecordKeeper &Records;
37+ const RecordKeeper &Records;
3838 ASTNode Root;
3939 const std::string &NodeClassName;
4040 const std::string &BaseSuffix;
@@ -70,14 +70,12 @@ class ClangASTNodesEmitter {
7070
7171 std::pair<ASTNode, ASTNode> EmitNode (raw_ostream& OS, ASTNode Base);
7272public:
73- explicit ClangASTNodesEmitter (RecordKeeper &R, const std::string &N,
73+ explicit ClangASTNodesEmitter (const RecordKeeper &R, const std::string &N,
7474 const std::string &S,
7575 std::string_view PriorizeIfSubclassOf)
7676 : 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);
8179 PrioritizedClasses =
8280 std::set<ASTNode>(vecPrioritized.begin (), vecPrioritized.end ());
8381 }
@@ -169,10 +167,7 @@ void ClangASTNodesEmitter::deriveChildTree() {
169167 assert (!Root && " already computed tree" );
170168
171169 // 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)) {
176171 if (auto B = R->getValueAsOptionalDef (BaseFieldName))
177172 Tree.insert (std::make_pair (B, R));
178173 else if (Root)
@@ -217,14 +212,14 @@ void ClangASTNodesEmitter::run(raw_ostream &OS) {
217212 OS << " #undef ABSTRACT_" << macroHierarchyName () << " \n " ;
218213}
219214
220- void clang::EmitClangASTNodes (RecordKeeper &RK, raw_ostream &OS,
215+ void clang::EmitClangASTNodes (const RecordKeeper &RK, raw_ostream &OS,
221216 const std::string &N, const std::string &S,
222217 std::string_view PriorizeIfSubclassOf) {
223218 ClangASTNodesEmitter (RK, N, S, PriorizeIfSubclassOf).run (OS);
224219}
225220
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) {
228223 if (!DeclContext->getValueAsBit (AbstractFieldName))
229224 OS << " DECL_CONTEXT(" << DeclContext->getName () << " )\n " ;
230225 auto i = Tree.lower_bound (DeclContext);
@@ -236,7 +231,7 @@ void printDeclContext(const std::multimap<Record *, Record *> &Tree,
236231
237232// Emits and addendum to a .inc file to enumerate the clang declaration
238233// contexts.
239- void clang::EmitClangDeclContext (RecordKeeper &Records, raw_ostream &OS) {
234+ void clang::EmitClangDeclContext (const RecordKeeper &Records, raw_ostream &OS) {
240235 // FIXME: Find a .td file format to allow for this to be represented better.
241236
242237 emitSourceFileHeader (" List of AST Decl nodes" , OS, Records);
@@ -245,22 +240,15 @@ void clang::EmitClangDeclContext(RecordKeeper &Records, raw_ostream &OS) {
245240 OS << " # define DECL_CONTEXT(DECL)\n " ;
246241 OS << " #endif\n " ;
247242
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;
257244
258- for (auto *R : Stmts ) {
245+ for (const Record *R : Records. getAllDerivedDefinitions (DeclNodeClassName) ) {
259246 if (auto *B = R->getValueAsOptionalDef (BaseFieldName))
260247 Tree.insert (std::make_pair (B, R));
261248 }
262249
263- for (auto *DeclContext : DeclContextsVector) {
250+ for (const Record *DeclContext :
251+ Records.getAllDerivedDefinitions (DeclContextNodeClassName)) {
264252 printDeclContext (Tree, DeclContext, OS);
265253 }
266254
0 commit comments