[clang] [clang][TableGen] Change ASTProperties Emitter to use const RecordKeeper (PR #108274)

Rahul Joshi via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 11 11:54:52 PDT 2024


https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/108274

Change ASTProperties Emitter to use const RecordKeeper.

>From d5396fdc12a6a24960b42ec9f50556b00e42e08e Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Wed, 11 Sep 2024 11:51:51 -0700
Subject: [PATCH] [clang][TableGen] Change ASTProperties Emitter to use const
 RecordKeeper

---
 .../TableGen/ClangASTPropertiesEmitter.cpp    | 38 ++++++++++---------
 clang/utils/TableGen/TableGenBackends.h       | 12 ++++--
 2 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/clang/utils/TableGen/ClangASTPropertiesEmitter.cpp b/clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
index de8dda60681ff8..7cf437a4a2aa9b 100644
--- a/clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
+++ b/clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
@@ -89,21 +89,21 @@ struct CasedTypeInfo {
 
 class ASTPropsEmitter {
 	raw_ostream &Out;
-	RecordKeeper &Records;
-	std::map<HasProperties, NodeInfo> NodeInfos;
+        const RecordKeeper &Records;
+        std::map<HasProperties, NodeInfo> NodeInfos;
   std::vector<PropertyType> AllPropertyTypes;
   std::map<PropertyType, CasedTypeInfo> CasedTypeInfos;
 
 public:
-	ASTPropsEmitter(RecordKeeper &records, raw_ostream &out)
-		: Out(out), Records(records) {
-
-		// Find all the properties.
-		for (Property property :
-           records.getAllDerivedDefinitions(PropertyClassName)) {
-			HasProperties node = property.getClass();
-			NodeInfos[node].Properties.push_back(property);
-		}
+  ASTPropsEmitter(const RecordKeeper &records, raw_ostream &out)
+      : Out(out), Records(records) {
+
+    // Find all the properties.
+    for (Property property :
+         records.getAllDerivedDefinitions(PropertyClassName)) {
+      HasProperties node = property.getClass();
+      NodeInfos[node].Properties.push_back(property);
+    }
 
     // Find all the creation rules.
     for (CreationRule creationRule :
@@ -177,7 +177,7 @@ class ASTPropsEmitter {
     }
 
     Validator(*this).validate();
-	}
+  }
 
   void visitAllProperties(HasProperties derived, const NodeInfo &derivedInfo,
                           function_ref<void (Property)> visit) {
@@ -591,28 +591,28 @@ void ASTPropsEmitter::emitWriteOfProperty(StringRef writerName,
 /// Emit an .inc file that defines the AbstractFooReader class
 /// for the given AST class hierarchy.
 template <class NodeClass>
-static void emitASTReader(RecordKeeper &records, raw_ostream &out,
+static void emitASTReader(const RecordKeeper &records, raw_ostream &out,
                           StringRef description) {
   emitSourceFileHeader(description, out, records);
 
   ASTPropsEmitter(records, out).emitNodeReaderClass<NodeClass>();
 }
 
-void clang::EmitClangTypeReader(RecordKeeper &records, raw_ostream &out) {
+void clang::EmitClangTypeReader(const RecordKeeper &records, raw_ostream &out) {
   emitASTReader<TypeNode>(records, out, "A CRTP reader for Clang Type nodes");
 }
 
 /// Emit an .inc file that defines the AbstractFooWriter class
 /// for the given AST class hierarchy.
 template <class NodeClass>
-static void emitASTWriter(RecordKeeper &records, raw_ostream &out,
+static void emitASTWriter(const RecordKeeper &records, raw_ostream &out,
                           StringRef description) {
   emitSourceFileHeader(description, out, records);
 
   ASTPropsEmitter(records, out).emitNodeWriterClass<NodeClass>();
 }
 
-void clang::EmitClangTypeWriter(RecordKeeper &records, raw_ostream &out) {
+void clang::EmitClangTypeWriter(const RecordKeeper &records, raw_ostream &out) {
   emitASTWriter<TypeNode>(records, out, "A CRTP writer for Clang Type nodes");
 }
 
@@ -851,7 +851,8 @@ void ASTPropsEmitter::emitBasicReaderWriterFile(const ReaderWriterInfo &info) {
 
 /// Emit an .inc file that defines some helper classes for reading
 /// basic values.
-void clang::EmitClangBasicReader(RecordKeeper &records, raw_ostream &out) {
+void clang::EmitClangBasicReader(const RecordKeeper &records,
+                                 raw_ostream &out) {
   emitSourceFileHeader("Helper classes for BasicReaders", out, records);
 
   // Use any property, we won't be using those properties.
@@ -861,7 +862,8 @@ void clang::EmitClangBasicReader(RecordKeeper &records, raw_ostream &out) {
 
 /// Emit an .inc file that defines some helper classes for writing
 /// basic values.
-void clang::EmitClangBasicWriter(RecordKeeper &records, raw_ostream &out) {
+void clang::EmitClangBasicWriter(const RecordKeeper &records,
+                                 raw_ostream &out) {
   emitSourceFileHeader("Helper classes for BasicWriters", out, records);
 
   // Use any property, we won't be using those properties.
diff --git a/clang/utils/TableGen/TableGenBackends.h b/clang/utils/TableGen/TableGenBackends.h
index fe55ef2f423afe..afff329c0aadc1 100644
--- a/clang/utils/TableGen/TableGenBackends.h
+++ b/clang/utils/TableGen/TableGenBackends.h
@@ -35,11 +35,15 @@ void EmitClangDeclContext(llvm::RecordKeeper &RK, llvm::raw_ostream &OS);
 void EmitClangASTNodes(llvm::RecordKeeper &RK, llvm::raw_ostream &OS,
                        const std::string &N, const std::string &S,
                        std::string_view PriorizeIfSubclassOf = "");
-void EmitClangBasicReader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitClangBasicWriter(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitClangBasicReader(const llvm::RecordKeeper &Records,
+                          llvm::raw_ostream &OS);
+void EmitClangBasicWriter(const llvm::RecordKeeper &Records,
+                          llvm::raw_ostream &OS);
 void EmitClangTypeNodes(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitClangTypeReader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
-void EmitClangTypeWriter(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitClangTypeReader(const llvm::RecordKeeper &Records,
+                         llvm::raw_ostream &OS);
+void EmitClangTypeWriter(const llvm::RecordKeeper &Records,
+                         llvm::raw_ostream &OS);
 void EmitClangAttrParserStringSwitches(llvm::RecordKeeper &Records,
                                        llvm::raw_ostream &OS);
 void EmitClangAttrSubjectMatchRulesParserStringSwitches(



More information about the cfe-commits mailing list