Skip to content

Commit 3c9db3a

Browse files
authored
[clang][TableGen] Change ASTProperties Emitter to use const RecordKeeper (#108274)
Change ASTProperties Emitter to use const RecordKeeper. This is a part of effort to have better const correctness in TableGen backends: https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
1 parent 17ff616 commit 3c9db3a

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

clang/utils/TableGen/ClangASTPropertiesEmitter.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ struct CasedTypeInfo {
8989

9090
class ASTPropsEmitter {
9191
raw_ostream &Out;
92-
RecordKeeper &Records;
92+
const RecordKeeper &Records;
9393
std::map<HasProperties, NodeInfo> NodeInfos;
9494
std::vector<PropertyType> AllPropertyTypes;
9595
std::map<PropertyType, CasedTypeInfo> CasedTypeInfos;
9696

9797
public:
98-
ASTPropsEmitter(RecordKeeper &records, raw_ostream &out)
98+
ASTPropsEmitter(const RecordKeeper &records, raw_ostream &out)
9999
: Out(out), Records(records) {
100100

101101
// Find all the properties.
@@ -587,28 +587,28 @@ void ASTPropsEmitter::emitWriteOfProperty(StringRef writerName,
587587
/// Emit an .inc file that defines the AbstractFooReader class
588588
/// for the given AST class hierarchy.
589589
template <class NodeClass>
590-
static void emitASTReader(RecordKeeper &records, raw_ostream &out,
590+
static void emitASTReader(const RecordKeeper &records, raw_ostream &out,
591591
StringRef description) {
592592
emitSourceFileHeader(description, out, records);
593593

594594
ASTPropsEmitter(records, out).emitNodeReaderClass<NodeClass>();
595595
}
596596

597-
void clang::EmitClangTypeReader(RecordKeeper &records, raw_ostream &out) {
597+
void clang::EmitClangTypeReader(const RecordKeeper &records, raw_ostream &out) {
598598
emitASTReader<TypeNode>(records, out, "A CRTP reader for Clang Type nodes");
599599
}
600600

601601
/// Emit an .inc file that defines the AbstractFooWriter class
602602
/// for the given AST class hierarchy.
603603
template <class NodeClass>
604-
static void emitASTWriter(RecordKeeper &records, raw_ostream &out,
604+
static void emitASTWriter(const RecordKeeper &records, raw_ostream &out,
605605
StringRef description) {
606606
emitSourceFileHeader(description, out, records);
607607

608608
ASTPropsEmitter(records, out).emitNodeWriterClass<NodeClass>();
609609
}
610610

611-
void clang::EmitClangTypeWriter(RecordKeeper &records, raw_ostream &out) {
611+
void clang::EmitClangTypeWriter(const RecordKeeper &records, raw_ostream &out) {
612612
emitASTWriter<TypeNode>(records, out, "A CRTP writer for Clang Type nodes");
613613
}
614614

@@ -847,7 +847,8 @@ void ASTPropsEmitter::emitBasicReaderWriterFile(const ReaderWriterInfo &info) {
847847

848848
/// Emit an .inc file that defines some helper classes for reading
849849
/// basic values.
850-
void clang::EmitClangBasicReader(RecordKeeper &records, raw_ostream &out) {
850+
void clang::EmitClangBasicReader(const RecordKeeper &records,
851+
raw_ostream &out) {
851852
emitSourceFileHeader("Helper classes for BasicReaders", out, records);
852853

853854
// Use any property, we won't be using those properties.
@@ -857,7 +858,8 @@ void clang::EmitClangBasicReader(RecordKeeper &records, raw_ostream &out) {
857858

858859
/// Emit an .inc file that defines some helper classes for writing
859860
/// basic values.
860-
void clang::EmitClangBasicWriter(RecordKeeper &records, raw_ostream &out) {
861+
void clang::EmitClangBasicWriter(const RecordKeeper &records,
862+
raw_ostream &out) {
861863
emitSourceFileHeader("Helper classes for BasicWriters", out, records);
862864

863865
// Use any property, we won't be using those properties.

clang/utils/TableGen/TableGenBackends.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ void EmitClangDeclContext(const llvm::RecordKeeper &RK, llvm::raw_ostream &OS);
3535
void EmitClangASTNodes(const llvm::RecordKeeper &RK, llvm::raw_ostream &OS,
3636
const std::string &N, const std::string &S,
3737
std::string_view PriorizeIfSubclassOf = "");
38-
void EmitClangBasicReader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
39-
void EmitClangBasicWriter(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
38+
void EmitClangBasicReader(const llvm::RecordKeeper &Records,
39+
llvm::raw_ostream &OS);
40+
void EmitClangBasicWriter(const llvm::RecordKeeper &Records,
41+
llvm::raw_ostream &OS);
4042
void EmitClangTypeNodes(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
41-
void EmitClangTypeReader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
42-
void EmitClangTypeWriter(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
43+
void EmitClangTypeReader(const llvm::RecordKeeper &Records,
44+
llvm::raw_ostream &OS);
45+
void EmitClangTypeWriter(const llvm::RecordKeeper &Records,
46+
llvm::raw_ostream &OS);
4347
void EmitClangAttrParserStringSwitches(const llvm::RecordKeeper &Records,
4448
llvm::raw_ostream &OS);
4549
void EmitClangAttrSubjectMatchRulesParserStringSwitches(

0 commit comments

Comments
 (0)