@@ -39,12 +39,13 @@ using namespace llvm;
39
39
40
40
namespace {
41
41
class DiagGroupParentMap {
42
- RecordKeeper &Records;
43
- std::map<const Record*, std::vector<Record*> > Mapping;
42
+ const RecordKeeper &Records;
43
+ std::map<const Record *, std::vector<const Record *>> Mapping;
44
+
44
45
public:
45
- DiagGroupParentMap (RecordKeeper &records) : Records(records) {
46
- std::vector< Record*> DiagGroups
47
- = Records.getAllDerivedDefinitions (" DiagGroup" );
46
+ DiagGroupParentMap (const RecordKeeper &records) : Records(records) {
47
+ ArrayRef< const Record *> DiagGroups =
48
+ Records.getAllDerivedDefinitions (" DiagGroup" );
48
49
for (unsigned i = 0 , e = DiagGroups.size (); i != e; ++i) {
49
50
std::vector<Record*> SubGroups =
50
51
DiagGroups[i]->getValueAsListOfDefs (" SubGroups" );
@@ -53,7 +54,7 @@ class DiagGroupParentMap {
53
54
}
54
55
}
55
56
56
- const std::vector<Record*> &getParents (const Record *Group) {
57
+ const std::vector<const Record *> &getParents (const Record *Group) {
57
58
return Mapping[Group];
58
59
}
59
60
};
@@ -68,7 +69,8 @@ getCategoryFromDiagGroup(const Record *Group,
68
69
69
70
// The diag group may the subgroup of one or more other diagnostic groups,
70
71
// check these for a category as well.
71
- const std::vector<Record*> &Parents = DiagGroupParents.getParents (Group);
72
+ const std::vector<const Record *> &Parents =
73
+ DiagGroupParents.getParents (Group);
72
74
for (unsigned i = 0 , e = Parents.size (); i != e; ++i) {
73
75
CatName = getCategoryFromDiagGroup (Parents[i], DiagGroupParents);
74
76
if (!CatName.empty ()) return CatName;
@@ -94,19 +96,19 @@ static std::string getDiagnosticCategory(const Record *R,
94
96
95
97
namespace {
96
98
class DiagCategoryIDMap {
97
- RecordKeeper &Records;
99
+ const RecordKeeper &Records;
98
100
StringMap<unsigned > CategoryIDs;
99
101
std::vector<std::string> CategoryStrings;
100
102
public:
101
- DiagCategoryIDMap (RecordKeeper &records) : Records(records) {
103
+ DiagCategoryIDMap (const RecordKeeper &records) : Records(records) {
102
104
DiagGroupParentMap ParentInfo (Records);
103
105
104
106
// The zero'th category is "".
105
107
CategoryStrings.push_back (" " );
106
108
CategoryIDs[" " ] = 0 ;
107
109
108
- std::vector< Record*> Diags =
109
- Records.getAllDerivedDefinitions (" Diagnostic" );
110
+ ArrayRef< const Record *> Diags =
111
+ Records.getAllDerivedDefinitions (" Diagnostic" );
110
112
for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
111
113
std::string Category = getDiagnosticCategory (Diags[i], ParentInfo);
112
114
if (Category.empty ()) continue ; // Skip diags with no category.
@@ -153,8 +155,8 @@ static bool diagGroupBeforeByName(const Record *LHS, const Record *RHS) {
153
155
154
156
// / Invert the 1-[0/1] mapping of diags to group into a one to many
155
157
// / mapping of groups to diags in the group.
156
- static void groupDiagnostics (const std::vector< Record*> & Diags,
157
- const std::vector< Record*> & DiagGroups,
158
+ static void groupDiagnostics (ArrayRef< const Record *> Diags,
159
+ ArrayRef< const Record *> DiagGroups,
158
160
std::map<std::string, GroupInfo> &DiagsInGroup) {
159
161
160
162
for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
@@ -172,7 +174,7 @@ static void groupDiagnostics(const std::vector<Record*> &Diags,
172
174
// Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
173
175
// groups (these are warnings that GCC supports that clang never produces).
174
176
for (unsigned i = 0 , e = DiagGroups.size (); i != e; ++i) {
175
- Record *Group = DiagGroups[i];
177
+ const Record *Group = DiagGroups[i];
176
178
GroupInfo &GI =
177
179
DiagsInGroup[std::string (Group->getValueAsString (" GroupName" ))];
178
180
GI.GroupName = Group->getName ();
@@ -255,20 +257,18 @@ class InferPedantic {
255
257
GMap;
256
258
257
259
DiagGroupParentMap &DiagGroupParents;
258
- const std::vector< Record*> & Diags;
259
- const std::vector<Record*> DiagGroups;
260
+ ArrayRef< const Record *> Diags;
261
+ const std::vector<const Record *> DiagGroups;
260
262
std::map<std::string, GroupInfo> &DiagsInGroup;
261
263
llvm::DenseSet<const Record*> DiagsSet;
262
264
GMap GroupCount;
263
265
public:
264
266
InferPedantic (DiagGroupParentMap &DiagGroupParents,
265
- const std::vector< Record*> & Diags,
266
- const std::vector< Record*> & DiagGroups,
267
+ ArrayRef< const Record *> Diags,
268
+ ArrayRef< const Record *> DiagGroups,
267
269
std::map<std::string, GroupInfo> &DiagsInGroup)
268
- : DiagGroupParents(DiagGroupParents),
269
- Diags (Diags),
270
- DiagGroups(DiagGroups),
271
- DiagsInGroup(DiagsInGroup) {}
270
+ : DiagGroupParents(DiagGroupParents), Diags(Diags),
271
+ DiagGroups (DiagGroups), DiagsInGroup(DiagsInGroup) {}
272
272
273
273
// / Compute the set of diagnostics and groups that are immediately
274
274
// / in -Wpedantic.
@@ -302,7 +302,8 @@ bool InferPedantic::isSubGroupOfGroup(const Record *Group,
302
302
if (GName == GroupName)
303
303
return true ;
304
304
305
- const std::vector<Record*> &Parents = DiagGroupParents.getParents (Group);
305
+ const std::vector<const Record *> &Parents =
306
+ DiagGroupParents.getParents (Group);
306
307
for (unsigned i = 0 , e = Parents.size (); i != e; ++i)
307
308
if (isSubGroupOfGroup (Parents[i], GName))
308
309
return true ;
@@ -347,7 +348,8 @@ void InferPedantic::markGroup(const Record *Group) {
347
348
// group's count is equal to the number of subgroups and diagnostics in
348
349
// that group, we can safely add this group to -Wpedantic.
349
350
if (groupInPedantic (Group, /* increment */ true )) {
350
- const std::vector<Record*> &Parents = DiagGroupParents.getParents (Group);
351
+ const std::vector<const Record *> &Parents =
352
+ DiagGroupParents.getParents (Group);
351
353
for (unsigned i = 0 , e = Parents.size (); i != e; ++i)
352
354
markGroup (Parents[i]);
353
355
}
@@ -359,7 +361,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
359
361
// "pedantic" group. For those that aren't explicitly included in -Wpedantic,
360
362
// mark them for consideration to be included in -Wpedantic directly.
361
363
for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
362
- Record *R = Diags[i];
364
+ const Record *R = Diags[i];
363
365
if (isExtension (R) && isOffByDefault (R)) {
364
366
DiagsSet.insert (R);
365
367
if (DefInit *Group = dyn_cast<DefInit>(R->getValueInit (" Group" ))) {
@@ -375,7 +377,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
375
377
// march through Diags a second time to ensure the results are emitted
376
378
// in deterministic order.
377
379
for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
378
- Record *R = Diags[i];
380
+ const Record *R = Diags[i];
379
381
if (!DiagsSet.count (R))
380
382
continue ;
381
383
// Check if the group is implicitly in -Wpedantic. If so,
@@ -401,13 +403,14 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
401
403
// march through the groups to ensure the results are emitted
402
404
// / in a deterministc order.
403
405
for (unsigned i = 0 , ei = DiagGroups.size (); i != ei; ++i) {
404
- Record *Group = DiagGroups[i];
406
+ const Record *Group = DiagGroups[i];
405
407
if (!groupInPedantic (Group))
406
408
continue ;
407
409
408
- const std::vector<Record*> &Parents = DiagGroupParents.getParents (Group);
409
- bool AllParentsInPedantic =
410
- llvm::all_of (Parents, [&](Record *R) { return groupInPedantic (R); });
410
+ const std::vector<const Record *> &Parents =
411
+ DiagGroupParents.getParents (Group);
412
+ bool AllParentsInPedantic = llvm::all_of (
413
+ Parents, [&](const Record *R) { return groupInPedantic (R); });
411
414
// If all the parents are in -Wpedantic, this means that this diagnostic
412
415
// group will be indirectly included by -Wpedantic already. In that
413
416
// case, do not add it directly to -Wpedantic. If the group has no
@@ -583,7 +586,7 @@ struct DiagnosticTextBuilder {
583
586
DiagnosticTextBuilder (DiagnosticTextBuilder const &) = delete ;
584
587
DiagnosticTextBuilder &operator =(DiagnosticTextBuilder const &) = delete ;
585
588
586
- DiagnosticTextBuilder (RecordKeeper &Records) {
589
+ DiagnosticTextBuilder (const RecordKeeper &Records) {
587
590
// Build up the list of substitution records.
588
591
for (auto *S : Records.getAllDerivedDefinitions (" TextSubstitution" )) {
589
592
EvaluatingRecordGuard Guard (&EvaluatingRecord, S);
@@ -593,7 +596,7 @@ struct DiagnosticTextBuilder {
593
596
594
597
// Check that no diagnostic definitions have the same name as a
595
598
// substitution.
596
- for (Record *Diag : Records.getAllDerivedDefinitions (" Diagnostic" )) {
599
+ for (const Record *Diag : Records.getAllDerivedDefinitions (" Diagnostic" )) {
597
600
StringRef Name = Diag->getName ();
598
601
if (Substitutions.count (Name))
599
602
llvm::PrintFatalError (
@@ -1407,7 +1410,7 @@ static void verifyDiagnosticWording(const Record &Diag) {
1407
1410
1408
1411
// / ClangDiagsDefsEmitter - The top-level class emits .def files containing
1409
1412
// / declarations of Clang diagnostics.
1410
- void clang::EmitClangDiagsDefs (RecordKeeper &Records, raw_ostream &OS,
1413
+ void clang::EmitClangDiagsDefs (const RecordKeeper &Records, raw_ostream &OS,
1411
1414
const std::string &Component) {
1412
1415
// Write the #if guard
1413
1416
if (!Component.empty ()) {
@@ -1421,10 +1424,11 @@ void clang::EmitClangDiagsDefs(RecordKeeper &Records, raw_ostream &OS,
1421
1424
1422
1425
DiagnosticTextBuilder DiagTextBuilder (Records);
1423
1426
1424
- std::vector<Record *> Diags = Records.getAllDerivedDefinitions (" Diagnostic" );
1427
+ ArrayRef<const Record *> Diags =
1428
+ Records.getAllDerivedDefinitions (" Diagnostic" );
1425
1429
1426
- std::vector< Record*> DiagGroups
1427
- = Records.getAllDerivedDefinitions (" DiagGroup" );
1430
+ ArrayRef< const Record *> DiagGroups =
1431
+ Records.getAllDerivedDefinitions (" DiagGroup" );
1428
1432
1429
1433
std::map<std::string, GroupInfo> DiagsInGroup;
1430
1434
groupDiagnostics (Diags, DiagGroups, DiagsInGroup);
@@ -1764,21 +1768,22 @@ static void emitDiagTable(std::map<std::string, GroupInfo> &DiagsInGroup,
1764
1768
// / CATEGORY("Lambda Issue", DiagCat_Lambda_Issue)
1765
1769
// / #endif
1766
1770
// / \endcode
1767
- static void emitCategoryTable (RecordKeeper &Records, raw_ostream &OS) {
1771
+ static void emitCategoryTable (const RecordKeeper &Records, raw_ostream &OS) {
1768
1772
DiagCategoryIDMap CategoriesByID (Records);
1769
1773
OS << " \n #ifdef GET_CATEGORY_TABLE\n " ;
1770
1774
for (auto const &C : CategoriesByID)
1771
1775
OS << " CATEGORY(\" " << C << " \" , " << getDiagCategoryEnum (C) << " )\n " ;
1772
1776
OS << " #endif // GET_CATEGORY_TABLE\n\n " ;
1773
1777
}
1774
1778
1775
- void clang::EmitClangDiagGroups (RecordKeeper &Records, raw_ostream &OS) {
1779
+ void clang::EmitClangDiagGroups (const RecordKeeper &Records, raw_ostream &OS) {
1776
1780
// Compute a mapping from a DiagGroup to all of its parents.
1777
1781
DiagGroupParentMap DGParentMap (Records);
1778
1782
1779
- std::vector<Record *> Diags = Records.getAllDerivedDefinitions (" Diagnostic" );
1783
+ ArrayRef<const Record *> Diags =
1784
+ Records.getAllDerivedDefinitions (" Diagnostic" );
1780
1785
1781
- std::vector< Record *> DiagGroups =
1786
+ ArrayRef< const Record *> DiagGroups =
1782
1787
Records.getAllDerivedDefinitions (" DiagGroup" );
1783
1788
1784
1789
std::map<std::string, GroupInfo> DiagsInGroup;
@@ -1824,9 +1829,10 @@ struct RecordIndexElement
1824
1829
};
1825
1830
} // end anonymous namespace.
1826
1831
1827
- void clang::EmitClangDiagsIndexName (RecordKeeper &Records, raw_ostream &OS) {
1828
- const std::vector<Record*> &Diags =
1829
- Records.getAllDerivedDefinitions (" Diagnostic" );
1832
+ void clang::EmitClangDiagsIndexName (const RecordKeeper &Records,
1833
+ raw_ostream &OS) {
1834
+ ArrayRef<const Record *> Diags =
1835
+ Records.getAllDerivedDefinitions (" Diagnostic" );
1830
1836
1831
1837
std::vector<RecordIndexElement> Index;
1832
1838
Index.reserve (Diags.size ());
@@ -1915,7 +1921,7 @@ void writeDiagnosticText(DiagnosticTextBuilder &Builder, const Record *R,
1915
1921
} // namespace
1916
1922
} // namespace docs
1917
1923
1918
- void clang::EmitClangDiagDocs (RecordKeeper &Records, raw_ostream &OS) {
1924
+ void clang::EmitClangDiagDocs (const RecordKeeper &Records, raw_ostream &OS) {
1919
1925
using namespace docs ;
1920
1926
1921
1927
// Get the documentation introduction paragraph.
@@ -1930,10 +1936,10 @@ void clang::EmitClangDiagDocs(RecordKeeper &Records, raw_ostream &OS) {
1930
1936
1931
1937
DiagnosticTextBuilder Builder (Records);
1932
1938
1933
- std::vector< Record*> Diags =
1939
+ ArrayRef< const Record *> Diags =
1934
1940
Records.getAllDerivedDefinitions (" Diagnostic" );
1935
1941
1936
- std::vector<Record*> DiagGroups =
1942
+ std::vector<const Record *> DiagGroups =
1937
1943
Records.getAllDerivedDefinitions (" DiagGroup" );
1938
1944
llvm::sort (DiagGroups, diagGroupBeforeByName);
1939
1945
0 commit comments