@@ -46,8 +46,8 @@ class IfDefScope {
46
46
47
47
// Generate enum class. Entries are emitted in the order in which they appear
48
48
// in the `Records` vector.
49
- static void GenerateEnumClass (const std::vector< Record *> & Records,
50
- raw_ostream &OS, StringRef Enum, StringRef Prefix,
49
+ static void GenerateEnumClass (ArrayRef< const Record *> Records, raw_ostream &OS ,
50
+ StringRef Enum, StringRef Prefix,
51
51
const DirectiveLanguage &DirLang,
52
52
bool ExportEnums) {
53
53
OS << " \n " ;
@@ -79,7 +79,7 @@ static void GenerateEnumClass(const std::vector<Record *> &Records,
79
79
80
80
// Generate enums for values that clauses can take.
81
81
// Also generate function declarations for get<Enum>Name(StringRef Str).
82
- static void GenerateEnumClauseVal (const std::vector< Record *> & Records,
82
+ static void GenerateEnumClauseVal (ArrayRef< const Record *> Records,
83
83
raw_ostream &OS,
84
84
const DirectiveLanguage &DirLang,
85
85
std::string &EnumHelperFuncs) {
@@ -144,7 +144,7 @@ static bool HasDuplicateClauses(const std::vector<Record *> &Clauses,
144
144
// three allowed list. Also, since required implies allowed, clauses cannot
145
145
// appear in both the allowedClauses and requiredClauses lists.
146
146
static bool
147
- HasDuplicateClausesInDirectives (const std::vector< Record *> & Directives) {
147
+ HasDuplicateClausesInDirectives (ArrayRef< const Record *> Directives) {
148
148
bool HasDuplicate = false ;
149
149
for (const auto &D : Directives) {
150
150
Directive Dir{D};
@@ -184,7 +184,7 @@ bool DirectiveLanguage::HasValidityErrors() const {
184
184
// Count the maximum number of leaf constituents per construct.
185
185
static size_t GetMaxLeafCount (const DirectiveLanguage &DirLang) {
186
186
size_t MaxCount = 0 ;
187
- for (Record *R : DirLang.getDirectives ()) {
187
+ for (const Record *R : DirLang.getDirectives ()) {
188
188
size_t Count = Directive{R}.getLeafConstructs ().size ();
189
189
MaxCount = std::max (MaxCount, Count);
190
190
}
@@ -193,7 +193,7 @@ static size_t GetMaxLeafCount(const DirectiveLanguage &DirLang) {
193
193
194
194
// Generate the declaration section for the enumeration in the directive
195
195
// language
196
- static void EmitDirectivesDecl (RecordKeeper &Records, raw_ostream &OS) {
196
+ static void EmitDirectivesDecl (const RecordKeeper &Records, raw_ostream &OS) {
197
197
const auto DirLang = DirectiveLanguage{Records};
198
198
if (DirLang.HasValidityErrors ())
199
199
return ;
@@ -220,7 +220,7 @@ static void EmitDirectivesDecl(RecordKeeper &Records, raw_ostream &OS) {
220
220
OS << " \n LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();\n " ;
221
221
222
222
// Emit Directive associations
223
- std::vector<Record *> associations;
223
+ std::vector<const Record *> associations;
224
224
llvm::copy_if (
225
225
DirLang.getAssociations (), std::back_inserter (associations),
226
226
// Skip the "special" value
@@ -283,9 +283,8 @@ static void EmitDirectivesDecl(RecordKeeper &Records, raw_ostream &OS) {
283
283
}
284
284
285
285
// Generate function implementation for get<Enum>Name(StringRef Str)
286
- static void GenerateGetName (const std::vector<Record *> &Records,
287
- raw_ostream &OS, StringRef Enum,
288
- const DirectiveLanguage &DirLang,
286
+ static void GenerateGetName (ArrayRef<const Record *> Records, raw_ostream &OS,
287
+ StringRef Enum, const DirectiveLanguage &DirLang,
289
288
StringRef Prefix) {
290
289
OS << " \n " ;
291
290
OS << " llvm::StringRef llvm::" << DirLang.getCppNamespace () << " ::get"
@@ -308,13 +307,13 @@ static void GenerateGetName(const std::vector<Record *> &Records,
308
307
}
309
308
310
309
// Generate function implementation for get<Enum>Kind(StringRef Str)
311
- static void GenerateGetKind (const std::vector<Record *> &Records,
312
- raw_ostream &OS, StringRef Enum,
313
- const DirectiveLanguage &DirLang, StringRef Prefix,
314
- bool ImplicitAsUnknown) {
310
+ static void GenerateGetKind (ArrayRef<const Record *> Records, raw_ostream &OS,
311
+ StringRef Enum, const DirectiveLanguage &DirLang,
312
+ StringRef Prefix, bool ImplicitAsUnknown) {
315
313
316
- auto DefaultIt = llvm::find_if (
317
- Records, [](Record *R) { return R->getValueAsBit (" isDefault" ) == true ; });
314
+ auto DefaultIt = llvm::find_if (Records, [](const Record *R) {
315
+ return R->getValueAsBit (" isDefault" ) == true ;
316
+ });
318
317
319
318
if (DefaultIt == Records.end ()) {
320
319
PrintError (" At least one " + Enum + " must be defined as default." );
@@ -506,8 +505,8 @@ static void EmitLeafTable(const DirectiveLanguage &DirLang, raw_ostream &OS,
506
505
// row. To avoid this, an auxiliary ordering table is created, such that
507
506
// row for Dir_A = table[auxiliary[Dir_A]].
508
507
509
- std::vector< Record *> Directives = DirLang.getDirectives ();
510
- DenseMap<Record *, int > DirId; // Record * -> llvm::omp::Directive
508
+ ArrayRef< const Record *> Directives = DirLang.getDirectives ();
509
+ DenseMap<const Record *, int > DirId; // Record * -> llvm::omp::Directive
511
510
512
511
for (auto [Idx, Rec] : llvm::enumerate (Directives))
513
512
DirId.insert (std::make_pair (Rec, Idx));
@@ -628,7 +627,7 @@ static void GenerateGetDirectiveAssociation(const DirectiveLanguage &DirLang,
628
627
Invalid,
629
628
};
630
629
631
- std::vector< Record *> associations = DirLang.getAssociations ();
630
+ ArrayRef< const Record *> associations = DirLang.getAssociations ();
632
631
633
632
auto getAssocValue = [](StringRef name) -> Association {
634
633
return StringSwitch<Association>(name)
@@ -720,7 +719,7 @@ static void GenerateGetDirectiveAssociation(const DirectiveLanguage &DirLang,
720
719
return Result;
721
720
};
722
721
723
- for (Record *R : DirLang.getDirectives ())
722
+ for (const Record *R : DirLang.getDirectives ())
724
723
compAssocImpl (R, compAssocImpl); // Updates AsMap.
725
724
726
725
OS << ' \n ' ;
@@ -739,7 +738,7 @@ static void GenerateGetDirectiveAssociation(const DirectiveLanguage &DirLang,
739
738
OS << AssociationTypeName << " llvm::" << DirLang.getCppNamespace ()
740
739
<< " ::getDirectiveAssociation(" << DirectiveTypeName << " Dir) {\n " ;
741
740
OS << " switch (Dir) {\n " ;
742
- for (Record *R : DirLang.getDirectives ()) {
741
+ for (const Record *R : DirLang.getDirectives ()) {
743
742
if (auto F = AsMap.find (R); F != AsMap.end ()) {
744
743
Directive Dir{R};
745
744
OS << " case " << getQualifiedName (Dir.getFormattedName ()) << " :\n " ;
@@ -763,7 +762,7 @@ static void GenerateGetDirectiveCategory(const DirectiveLanguage &DirLang,
763
762
<< GetDirectiveType (DirLang) << " Dir) {\n " ;
764
763
OS << " switch (Dir) {\n " ;
765
764
766
- for (Record *R : DirLang.getDirectives ()) {
765
+ for (const Record *R : DirLang.getDirectives ()) {
767
766
Directive D{R};
768
767
OS << " case " << GetDirectiveName (DirLang, R) << " :\n " ;
769
768
OS << " return " << CategoryNamespace
@@ -903,7 +902,7 @@ static void GenerateFlangClauseParserClassList(const DirectiveLanguage &DirLang,
903
902
IfDefScope Scope (" GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST" , OS);
904
903
905
904
OS << " \n " ;
906
- llvm::interleaveComma (DirLang.getClauses (), OS, [&](Record *C) {
905
+ llvm::interleaveComma (DirLang.getClauses (), OS, [&](const Record *C) {
907
906
Clause Clause{C};
908
907
OS << Clause.getFormattedParserClassName () << " \n " ;
909
908
});
@@ -1013,7 +1012,7 @@ static void GenerateFlangClauseParserKindMap(const DirectiveLanguage &DirLang,
1013
1012
<< " Parser clause\" );\n " ;
1014
1013
}
1015
1014
1016
- static bool compareClauseName (Record *R1, Record *R2) {
1015
+ static bool compareClauseName (const Record *R1, const Record *R2) {
1017
1016
Clause C1{R1};
1018
1017
Clause C2{R2};
1019
1018
return (C1.getName () > C2.getName ());
@@ -1022,7 +1021,7 @@ static bool compareClauseName(Record *R1, Record *R2) {
1022
1021
// Generate the parser for the clauses.
1023
1022
static void GenerateFlangClausesParser (const DirectiveLanguage &DirLang,
1024
1023
raw_ostream &OS) {
1025
- std::vector<Record *> Clauses = DirLang.getClauses ();
1024
+ std::vector<const Record *> Clauses = DirLang.getClauses ();
1026
1025
// Sort clauses in reverse alphabetical order so with clauses with same
1027
1026
// beginning, the longer option is tried before.
1028
1027
llvm::sort (Clauses, compareClauseName);
@@ -1231,7 +1230,7 @@ void EmitDirectivesBasicImpl(const DirectiveLanguage &DirLang,
1231
1230
1232
1231
// Generate the implemenation section for the enumeration in the directive
1233
1232
// language.
1234
- static void EmitDirectivesImpl (RecordKeeper &Records, raw_ostream &OS) {
1233
+ static void EmitDirectivesImpl (const RecordKeeper &Records, raw_ostream &OS) {
1235
1234
const auto DirLang = DirectiveLanguage{Records};
1236
1235
if (DirLang.HasValidityErrors ())
1237
1236
return ;
0 commit comments