@@ -44,17 +44,12 @@ class DiagGroupParentMap {
44
44
45
45
public:
46
46
DiagGroupParentMap (const RecordKeeper &records) : Records(records) {
47
- ArrayRef<const Record *> DiagGroups =
48
- Records.getAllDerivedDefinitions (" DiagGroup" );
49
- for (unsigned i = 0 , e = DiagGroups.size (); i != e; ++i) {
50
- std::vector<const Record *> SubGroups =
51
- DiagGroups[i]->getValueAsListOfDefs (" SubGroups" );
52
- for (unsigned j = 0 , e = SubGroups.size (); j != e; ++j)
53
- Mapping[SubGroups[j]].push_back (DiagGroups[i]);
54
- }
47
+ for (const Record *Group : Records.getAllDerivedDefinitions (" DiagGroup" ))
48
+ for (const Record *SubGroup : Group->getValueAsListOfDefs (" SubGroups" ))
49
+ Mapping[SubGroup].push_back (Group);
55
50
}
56
51
57
- const std::vector <const Record *> & getParents (const Record *Group) {
52
+ ArrayRef <const Record *> getParents (const Record *Group) {
58
53
return Mapping[Group];
59
54
}
60
55
};
@@ -69,10 +64,8 @@ getCategoryFromDiagGroup(const Record *Group,
69
64
70
65
// The diag group may the subgroup of one or more other diagnostic groups,
71
66
// check these for a category as well.
72
- const std::vector<const Record *> &Parents =
73
- DiagGroupParents.getParents (Group);
74
- for (unsigned i = 0 , e = Parents.size (); i != e; ++i) {
75
- CatName = getCategoryFromDiagGroup (Parents[i], DiagGroupParents);
67
+ for (const Record *Parent : DiagGroupParents.getParents (Group)) {
68
+ CatName = getCategoryFromDiagGroup (Parent, DiagGroupParents);
76
69
if (!CatName.empty ()) return CatName;
77
70
}
78
71
return " " ;
@@ -107,10 +100,9 @@ namespace {
107
100
CategoryStrings.push_back (" " );
108
101
CategoryIDs[" " ] = 0 ;
109
102
110
- ArrayRef<const Record *> Diags =
111
- Records.getAllDerivedDefinitions (" Diagnostic" );
112
- for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
113
- std::string Category = getDiagnosticCategory (Diags[i], ParentInfo);
103
+ for (const Record *Diag :
104
+ Records.getAllDerivedDefinitions (" Diagnostic" )) {
105
+ std::string Category = getDiagnosticCategory (Diag, ParentInfo);
114
106
if (Category.empty ()) continue ; // Skip diags with no category.
115
107
116
108
unsigned &ID = CategoryIDs[Category];
@@ -158,9 +150,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const Record *RHS) {
158
150
static void groupDiagnostics (ArrayRef<const Record *> Diags,
159
151
ArrayRef<const Record *> DiagGroups,
160
152
std::map<std::string, GroupInfo> &DiagsInGroup) {
161
-
162
- for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
163
- const Record *R = Diags[i];
153
+ for (const Record *R : Diags) {
164
154
const auto *DI = dyn_cast<DefInit>(R->getValueInit (" Group" ));
165
155
if (!DI)
166
156
continue ;
@@ -173,8 +163,7 @@ static void groupDiagnostics(ArrayRef<const Record *> Diags,
173
163
174
164
// Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
175
165
// groups (these are warnings that GCC supports that clang never produces).
176
- for (unsigned i = 0 , e = DiagGroups.size (); i != e; ++i) {
177
- const Record *Group = DiagGroups[i];
166
+ for (const Record *Group : DiagGroups) {
178
167
GroupInfo &GI =
179
168
DiagsInGroup[std::string (Group->getValueAsString (" GroupName" ))];
180
169
GI.GroupName = Group->getName ();
@@ -185,10 +174,8 @@ static void groupDiagnostics(ArrayRef<const Record *> Diags,
185
174
}
186
175
187
176
// Assign unique ID numbers to the groups.
188
- unsigned IDNo = 0 ;
189
- for (std::map<std::string, GroupInfo>::iterator
190
- I = DiagsInGroup.begin (), E = DiagsInGroup.end (); I != E; ++I, ++IDNo)
191
- I->second .IDNo = IDNo;
177
+ for (auto [IdNo, Iter] : enumerate(DiagsInGroup))
178
+ Iter.second .IDNo = IdNo;
192
179
193
180
// Warn if the same group is defined more than once (including implicitly).
194
181
for (auto &Group : DiagsInGroup) {
@@ -297,26 +284,21 @@ bool InferPedantic::isSubGroupOfGroup(const Record *Group, StringRef GName) {
297
284
if (GName == GroupName)
298
285
return true ;
299
286
300
- const std::vector<const Record *> &Parents =
301
- DiagGroupParents.getParents (Group);
302
- for (unsigned i = 0 , e = Parents.size (); i != e; ++i)
303
- if (isSubGroupOfGroup (Parents[i], GName))
287
+ for (const Record *Parent : DiagGroupParents.getParents (Group))
288
+ if (isSubGroupOfGroup (Parent, GName))
304
289
return true ;
305
290
306
291
return false ;
307
292
}
308
293
309
294
// / Determine if the diagnostic is an extension.
310
295
bool InferPedantic::isExtension (const Record *Diag) {
311
- const std::string &ClsName =
312
- std::string (Diag->getValueAsDef (" Class" )->getName ());
313
- return ClsName == " CLASS_EXTENSION" ;
296
+ return Diag->getValueAsDef (" Class" )->getName () == " CLASS_EXTENSION" ;
314
297
}
315
298
316
299
bool InferPedantic::isOffByDefault (const Record *Diag) {
317
- const std::string &DefSeverity = std::string (
318
- Diag->getValueAsDef (" DefaultSeverity" )->getValueAsString (" Name" ));
319
- return DefSeverity == " Ignored" ;
300
+ return Diag->getValueAsDef (" DefaultSeverity" )->getValueAsString (" Name" ) ==
301
+ " Ignored" ;
320
302
}
321
303
322
304
bool InferPedantic::groupInPedantic (const Record *Group, bool increment) {
@@ -342,37 +324,32 @@ void InferPedantic::markGroup(const Record *Group) {
342
324
// covered by -Wpedantic, increment the count of parent groups. Once the
343
325
// group's count is equal to the number of subgroups and diagnostics in
344
326
// that group, we can safely add this group to -Wpedantic.
345
- if (groupInPedantic (Group, /* increment */ true )) {
346
- const std::vector<const Record *> &Parents =
347
- DiagGroupParents.getParents (Group);
348
- for (unsigned i = 0 , e = Parents.size (); i != e; ++i)
349
- markGroup (Parents[i]);
350
- }
327
+ if (groupInPedantic (Group, /* increment */ true ))
328
+ for (const Record *Parent : DiagGroupParents.getParents (Group))
329
+ markGroup (Parent);
351
330
}
352
331
353
332
void InferPedantic::compute (VecOrSet DiagsInPedantic,
354
333
VecOrSet GroupsInPedantic) {
355
334
// All extensions that are not on by default are implicitly in the
356
335
// "pedantic" group. For those that aren't explicitly included in -Wpedantic,
357
336
// mark them for consideration to be included in -Wpedantic directly.
358
- for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
359
- const Record *R = Diags[i];
360
- if (isExtension (R) && isOffByDefault (R)) {
361
- DiagsSet.insert (R);
362
- if (const auto *Group = dyn_cast<DefInit>(R->getValueInit (" Group" ))) {
363
- const Record *GroupRec = Group->getDef ();
364
- if (!isSubGroupOfGroup (GroupRec, " pedantic" )) {
365
- markGroup (GroupRec);
366
- }
337
+ for (const Record *R : Diags) {
338
+ if (!isExtension (R) || !isOffByDefault (R))
339
+ continue ;
340
+ DiagsSet.insert (R);
341
+ if (const auto *Group = dyn_cast<DefInit>(R->getValueInit (" Group" ))) {
342
+ const Record *GroupRec = Group->getDef ();
343
+ if (!isSubGroupOfGroup (GroupRec, " pedantic" )) {
344
+ markGroup (GroupRec);
367
345
}
368
346
}
369
347
}
370
348
371
349
// Compute the set of diagnostics that are directly in -Wpedantic. We
372
350
// march through Diags a second time to ensure the results are emitted
373
351
// in deterministic order.
374
- for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
375
- const Record *R = Diags[i];
352
+ for (const Record *R : Diags) {
376
353
if (!DiagsSet.count (R))
377
354
continue ;
378
355
// Check if the group is implicitly in -Wpedantic. If so,
@@ -386,9 +363,8 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
386
363
// -Wpedantic. Include it in -Wpedantic directly.
387
364
if (auto *V = DiagsInPedantic.dyn_cast <RecordVec *>())
388
365
V->push_back (R);
389
- else {
390
- DiagsInPedantic.get <RecordSet*>()->insert (R);
391
- }
366
+ else
367
+ DiagsInPedantic.get <RecordSet *>()->insert (R);
392
368
}
393
369
394
370
if (!GroupsInPedantic)
@@ -397,8 +373,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
397
373
// Compute the set of groups that are directly in -Wpedantic. We
398
374
// march through the groups to ensure the results are emitted
399
375
// / in a deterministc order.
400
- for (unsigned i = 0 , ei = DiagGroups.size (); i != ei; ++i) {
401
- const Record *Group = DiagGroups[i];
376
+ for (const Record *Group : DiagGroups) {
402
377
if (!groupInPedantic (Group))
403
378
continue ;
404
379
@@ -415,9 +390,8 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
415
390
416
391
if (auto *V = GroupsInPedantic.dyn_cast <RecordVec *>())
417
392
V->push_back (Group);
418
- else {
419
- GroupsInPedantic.get <RecordSet*>()->insert (Group);
420
- }
393
+ else
394
+ GroupsInPedantic.get <RecordSet *>()->insert (Group);
421
395
}
422
396
}
423
397
@@ -970,10 +944,11 @@ struct DiagTextPrinter : DiagTextVisitor<DiagTextPrinter> {
970
944
void VisitPlural (PluralPiece *P) {
971
945
Result += " %plural{" ;
972
946
assert (P->Options .size () == P->OptionPrefixes .size ());
973
- for (unsigned I = 0 , End = P->Options .size (); I < End; ++I) {
974
- if (P->OptionPrefixes [I])
975
- Visit (P->OptionPrefixes [I]);
976
- Visit (P->Options [I]);
947
+ for (const auto [Prefix, Option] :
948
+ zip_equal (P->OptionPrefixes , P->Options )) {
949
+ if (Prefix)
950
+ Visit (Prefix);
951
+ Visit (Option);
977
952
Result += " |" ;
978
953
}
979
954
if (!P->Options .empty ())
@@ -1553,15 +1528,13 @@ static void emitDiagSubGroups(std::map<std::string, GroupInfo> &DiagsInGroup,
1553
1528
RecordVec &GroupsInPedantic, raw_ostream &OS) {
1554
1529
OS << " static const int16_t DiagSubGroups[] = {\n "
1555
1530
<< " /* Empty */ -1,\n " ;
1556
- for (auto const &I : DiagsInGroup) {
1557
- const bool IsPedantic = I.first == " pedantic" ;
1558
-
1559
- const std::vector<std::string> &SubGroups = I.second .SubGroups ;
1531
+ for (auto const &[Name, Group] : DiagsInGroup) {
1532
+ const bool IsPedantic = Name == " pedantic" ;
1533
+ const std::vector<std::string> &SubGroups = Group.SubGroups ;
1560
1534
if (!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ())) {
1561
- OS << " /* DiagSubGroup" << I. second .IDNo << " */ " ;
1535
+ OS << " /* DiagSubGroup" << Group .IDNo << " */ " ;
1562
1536
for (auto const &SubGroup : SubGroups) {
1563
- std::map<std::string, GroupInfo>::const_iterator RI =
1564
- DiagsInGroup.find (SubGroup);
1537
+ auto RI = DiagsInGroup.find (SubGroup);
1565
1538
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1566
1539
OS << RI->second .IDNo << " , " ;
1567
1540
}
@@ -1570,8 +1543,7 @@ static void emitDiagSubGroups(std::map<std::string, GroupInfo> &DiagsInGroup,
1570
1543
for (auto const &Group : GroupsInPedantic) {
1571
1544
const std::string &GroupName =
1572
1545
std::string (Group->getValueAsString (" GroupName" ));
1573
- std::map<std::string, GroupInfo>::const_iterator RI =
1574
- DiagsInGroup.find (GroupName);
1546
+ auto RI = DiagsInGroup.find (GroupName);
1575
1547
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1576
1548
OS << RI->second .IDNo << " , " ;
1577
1549
}
@@ -1601,16 +1573,18 @@ static void emitDiagSubGroups(std::map<std::string, GroupInfo> &DiagsInGroup,
1601
1573
// / };
1602
1574
// / \endcode
1603
1575
// /
1576
+ #include < type_traits>
1577
+
1604
1578
static void emitDiagArrays (std::map<std::string, GroupInfo> &DiagsInGroup,
1605
1579
RecordVec &DiagsInPedantic, raw_ostream &OS) {
1606
1580
OS << " static const int16_t DiagArrays[] = {\n "
1607
1581
<< " /* Empty */ -1,\n " ;
1608
- for (auto const &I : DiagsInGroup) {
1609
- const bool IsPedantic = I. first == " pedantic" ;
1582
+ for (const auto &[Name, Group] : DiagsInGroup) {
1583
+ const bool IsPedantic = Name == " pedantic" ;
1610
1584
1611
- const std::vector<const Record *> &V = I. second .DiagsInGroup ;
1585
+ const std::vector<const Record *> &V = Group .DiagsInGroup ;
1612
1586
if (!V.empty () || (IsPedantic && !DiagsInPedantic.empty ())) {
1613
- OS << " /* DiagArray" << I. second .IDNo << " */ " ;
1587
+ OS << " /* DiagArray" << Group .IDNo << " */ " ;
1614
1588
for (auto *Record : V)
1615
1589
OS << " diag::" << Record->getName () << " , " ;
1616
1590
// Emit the diagnostics implicitly in "pedantic".
@@ -1692,31 +1666,29 @@ static void emitDiagTable(std::map<std::string, GroupInfo> &DiagsInGroup,
1692
1666
1693
1667
OS << " \n #ifdef DIAG_ENTRY\n " ;
1694
1668
unsigned SubGroupIndex = 1 , DiagArrayIndex = 1 ;
1695
- for (auto const &I : DiagsInGroup) {
1669
+ for (auto const &[Name, GroupInfo] : DiagsInGroup) {
1696
1670
// Group option string.
1697
1671
OS << " DIAG_ENTRY(" ;
1698
- OS << I.second .GroupName << " /* " ;
1699
-
1700
- if (I.first .find_first_not_of (" abcdefghijklmnopqrstuvwxyz"
1701
- " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1702
- " 0123456789!@#$%^*-+=:?" ) !=
1703
- std::string::npos)
1704
- PrintFatalError (" Invalid character in diagnostic group '" + I.first +
1705
- " '" );
1706
- OS << I.first << " */, " ;
1672
+ OS << GroupInfo.GroupName << " /* " ;
1673
+
1674
+ if (Name.find_first_not_of (" abcdefghijklmnopqrstuvwxyz"
1675
+ " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1676
+ " 0123456789!@#$%^*-+=:?" ) != std::string::npos)
1677
+ PrintFatalError (" Invalid character in diagnostic group '" + Name + " '" );
1678
+ OS << Name << " */, " ;
1707
1679
// Store a pascal-style length byte at the beginning of the string.
1708
- std::string Name = char (I. first . size ()) + I. first ;
1709
- OS << *GroupNames.GetStringOffset (Name ) << " , " ;
1680
+ std::string PascalName = char (Name. size ()) + Name ;
1681
+ OS << *GroupNames.GetStringOffset (PascalName ) << " , " ;
1710
1682
1711
1683
// Special handling for 'pedantic'.
1712
- const bool IsPedantic = I. first == " pedantic" ;
1684
+ const bool IsPedantic = Name == " pedantic" ;
1713
1685
1714
1686
// Diagnostics in the group.
1715
- const std::vector<const Record *> &V = I. second .DiagsInGroup ;
1687
+ const std::vector<const Record *> &V = GroupInfo .DiagsInGroup ;
1716
1688
const bool hasDiags =
1717
1689
!V.empty () || (IsPedantic && !DiagsInPedantic.empty ());
1718
1690
if (hasDiags) {
1719
- OS << " /* DiagArray" << I. second .IDNo << " */ " << DiagArrayIndex
1691
+ OS << " /* DiagArray" << GroupInfo .IDNo << " */ " << DiagArrayIndex
1720
1692
<< " , " ;
1721
1693
if (IsPedantic)
1722
1694
DiagArrayIndex += DiagsInPedantic.size ();
@@ -1726,11 +1698,11 @@ static void emitDiagTable(std::map<std::string, GroupInfo> &DiagsInGroup,
1726
1698
}
1727
1699
1728
1700
// Subgroups.
1729
- const std::vector<std::string> &SubGroups = I. second .SubGroups ;
1701
+ const std::vector<std::string> &SubGroups = GroupInfo .SubGroups ;
1730
1702
const bool hasSubGroups =
1731
1703
!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ());
1732
1704
if (hasSubGroups) {
1733
- OS << " /* DiagSubGroup" << I. second .IDNo << " */ " << SubGroupIndex
1705
+ OS << " /* DiagSubGroup" << GroupInfo .IDNo << " */ " << SubGroupIndex
1734
1706
<< " , " ;
1735
1707
if (IsPedantic)
1736
1708
SubGroupIndex += GroupsInPedantic.size ();
@@ -1739,7 +1711,7 @@ static void emitDiagTable(std::map<std::string, GroupInfo> &DiagsInGroup,
1739
1711
OS << " 0, " ;
1740
1712
}
1741
1713
1742
- std::string Documentation = I. second .Defs .back ()
1714
+ std::string Documentation = GroupInfo .Defs .back ()
1743
1715
->getValue (" Documentation" )
1744
1716
->getValue ()
1745
1717
->getAsUnquotedString ();
@@ -1832,20 +1804,15 @@ void clang::EmitClangDiagsIndexName(const RecordKeeper &Records,
1832
1804
1833
1805
std::vector<RecordIndexElement> Index;
1834
1806
Index.reserve (Diags.size ());
1835
- for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
1836
- const Record &R = *(Diags[i]);
1837
- Index.push_back (RecordIndexElement (R));
1838
- }
1807
+ for (const Record *R : Diags)
1808
+ Index.push_back (RecordIndexElement (*R));
1839
1809
1840
1810
sort (Index, [](const RecordIndexElement &Lhs, const RecordIndexElement &Rhs) {
1841
1811
return Lhs.Name < Rhs.Name ;
1842
1812
});
1843
1813
1844
- for (unsigned i = 0 , e = Index.size (); i != e; ++i) {
1845
- const RecordIndexElement &R = Index[i];
1846
-
1847
- OS << " DIAG_NAME_INDEX(" << R.Name << " )\n " ;
1848
- }
1814
+ for (const auto &Elem : Index)
1815
+ OS << " DIAG_NAME_INDEX(" << Elem.Name << " )\n " ;
1849
1816
}
1850
1817
1851
1818
// ===----------------------------------------------------------------------===//
0 commit comments