@@ -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];
@@ -160,9 +152,7 @@ using DiagsInGroupTy = std::map<std::string, GroupInfo, std::less<>>;
160
152
static void groupDiagnostics (ArrayRef<const Record *> Diags,
161
153
ArrayRef<const Record *> DiagGroups,
162
154
DiagsInGroupTy &DiagsInGroup) {
163
-
164
- for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
165
- const Record *R = Diags[i];
155
+ for (const Record *R : Diags) {
166
156
const auto *DI = dyn_cast<DefInit>(R->getValueInit (" Group" ));
167
157
if (!DI)
168
158
continue ;
@@ -175,8 +165,7 @@ static void groupDiagnostics(ArrayRef<const Record *> Diags,
175
165
176
166
// Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
177
167
// groups (these are warnings that GCC supports that clang never produces).
178
- for (unsigned i = 0 , e = DiagGroups.size (); i != e; ++i) {
179
- const Record *Group = DiagGroups[i];
168
+ for (const Record *Group : DiagGroups) {
180
169
GroupInfo &GI =
181
170
DiagsInGroup[std::string (Group->getValueAsString (" GroupName" ))];
182
171
GI.GroupName = Group->getName ();
@@ -187,10 +176,8 @@ static void groupDiagnostics(ArrayRef<const Record *> Diags,
187
176
}
188
177
189
178
// Assign unique ID numbers to the groups.
190
- unsigned IDNo = 0 ;
191
- for (std::map<std::string, GroupInfo>::iterator
192
- I = DiagsInGroup.begin (), E = DiagsInGroup.end (); I != E; ++I, ++IDNo)
193
- I->second .IDNo = IDNo;
179
+ for (auto [IdNo, Iter] : enumerate(DiagsInGroup))
180
+ Iter.second .IDNo = IdNo;
194
181
195
182
// Warn if the same group is defined more than once (including implicitly).
196
183
for (auto &Group : DiagsInGroup) {
@@ -299,26 +286,21 @@ bool InferPedantic::isSubGroupOfGroup(const Record *Group, StringRef GName) {
299
286
if (GName == GroupName)
300
287
return true ;
301
288
302
- const std::vector<const Record *> &Parents =
303
- DiagGroupParents.getParents (Group);
304
- for (unsigned i = 0 , e = Parents.size (); i != e; ++i)
305
- if (isSubGroupOfGroup (Parents[i], GName))
289
+ for (const Record *Parent : DiagGroupParents.getParents (Group))
290
+ if (isSubGroupOfGroup (Parent, GName))
306
291
return true ;
307
292
308
293
return false ;
309
294
}
310
295
311
296
// / Determine if the diagnostic is an extension.
312
297
bool InferPedantic::isExtension (const Record *Diag) {
313
- const std::string &ClsName =
314
- std::string (Diag->getValueAsDef (" Class" )->getName ());
315
- return ClsName == " CLASS_EXTENSION" ;
298
+ return Diag->getValueAsDef (" Class" )->getName () == " CLASS_EXTENSION" ;
316
299
}
317
300
318
301
bool InferPedantic::isOffByDefault (const Record *Diag) {
319
- const std::string &DefSeverity = std::string (
320
- Diag->getValueAsDef (" DefaultSeverity" )->getValueAsString (" Name" ));
321
- return DefSeverity == " Ignored" ;
302
+ return Diag->getValueAsDef (" DefaultSeverity" )->getValueAsString (" Name" ) ==
303
+ " Ignored" ;
322
304
}
323
305
324
306
bool InferPedantic::groupInPedantic (const Record *Group, bool increment) {
@@ -344,37 +326,32 @@ void InferPedantic::markGroup(const Record *Group) {
344
326
// covered by -Wpedantic, increment the count of parent groups. Once the
345
327
// group's count is equal to the number of subgroups and diagnostics in
346
328
// that group, we can safely add this group to -Wpedantic.
347
- if (groupInPedantic (Group, /* increment */ true )) {
348
- const std::vector<const Record *> &Parents =
349
- DiagGroupParents.getParents (Group);
350
- for (unsigned i = 0 , e = Parents.size (); i != e; ++i)
351
- markGroup (Parents[i]);
352
- }
329
+ if (groupInPedantic (Group, /* increment */ true ))
330
+ for (const Record *Parent : DiagGroupParents.getParents (Group))
331
+ markGroup (Parent);
353
332
}
354
333
355
334
void InferPedantic::compute (VecOrSet DiagsInPedantic,
356
335
VecOrSet GroupsInPedantic) {
357
336
// All extensions that are not on by default are implicitly in the
358
337
// "pedantic" group. For those that aren't explicitly included in -Wpedantic,
359
338
// mark them for consideration to be included in -Wpedantic directly.
360
- for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
361
- const Record *R = Diags[i];
362
- if (isExtension (R) && isOffByDefault (R)) {
363
- DiagsSet.insert (R);
364
- if (const auto *Group = dyn_cast<DefInit>(R->getValueInit (" Group" ))) {
365
- const Record *GroupRec = Group->getDef ();
366
- if (!isSubGroupOfGroup (GroupRec, " pedantic" )) {
367
- markGroup (GroupRec);
368
- }
339
+ for (const Record *R : Diags) {
340
+ if (!isExtension (R) || !isOffByDefault (R))
341
+ continue ;
342
+ DiagsSet.insert (R);
343
+ if (const auto *Group = dyn_cast<DefInit>(R->getValueInit (" Group" ))) {
344
+ const Record *GroupRec = Group->getDef ();
345
+ if (!isSubGroupOfGroup (GroupRec, " pedantic" )) {
346
+ markGroup (GroupRec);
369
347
}
370
348
}
371
349
}
372
350
373
351
// Compute the set of diagnostics that are directly in -Wpedantic. We
374
352
// march through Diags a second time to ensure the results are emitted
375
353
// in deterministic order.
376
- for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
377
- const Record *R = Diags[i];
354
+ for (const Record *R : Diags) {
378
355
if (!DiagsSet.count (R))
379
356
continue ;
380
357
// Check if the group is implicitly in -Wpedantic. If so,
@@ -388,9 +365,8 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
388
365
// -Wpedantic. Include it in -Wpedantic directly.
389
366
if (auto *V = DiagsInPedantic.dyn_cast <RecordVec *>())
390
367
V->push_back (R);
391
- else {
392
- DiagsInPedantic.get <RecordSet*>()->insert (R);
393
- }
368
+ else
369
+ DiagsInPedantic.get <RecordSet *>()->insert (R);
394
370
}
395
371
396
372
if (!GroupsInPedantic)
@@ -399,8 +375,7 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
399
375
// Compute the set of groups that are directly in -Wpedantic. We
400
376
// march through the groups to ensure the results are emitted
401
377
// / in a deterministc order.
402
- for (unsigned i = 0 , ei = DiagGroups.size (); i != ei; ++i) {
403
- const Record *Group = DiagGroups[i];
378
+ for (const Record *Group : DiagGroups) {
404
379
if (!groupInPedantic (Group))
405
380
continue ;
406
381
@@ -417,9 +392,8 @@ void InferPedantic::compute(VecOrSet DiagsInPedantic,
417
392
418
393
if (auto *V = GroupsInPedantic.dyn_cast <RecordVec *>())
419
394
V->push_back (Group);
420
- else {
421
- GroupsInPedantic.get <RecordSet*>()->insert (Group);
422
- }
395
+ else
396
+ GroupsInPedantic.get <RecordSet *>()->insert (Group);
423
397
}
424
398
}
425
399
@@ -972,10 +946,11 @@ struct DiagTextPrinter : DiagTextVisitor<DiagTextPrinter> {
972
946
void VisitPlural (PluralPiece *P) {
973
947
Result += " %plural{" ;
974
948
assert (P->Options .size () == P->OptionPrefixes .size ());
975
- for (unsigned I = 0 , End = P->Options .size (); I < End; ++I) {
976
- if (P->OptionPrefixes [I])
977
- Visit (P->OptionPrefixes [I]);
978
- Visit (P->Options [I]);
949
+ for (const auto [Prefix, Option] :
950
+ zip_equal (P->OptionPrefixes , P->Options )) {
951
+ if (Prefix)
952
+ Visit (Prefix);
953
+ Visit (Option);
979
954
Result += " |" ;
980
955
}
981
956
if (!P->Options .empty ())
@@ -1555,15 +1530,13 @@ static void emitDiagSubGroups(DiagsInGroupTy &DiagsInGroup,
1555
1530
RecordVec &GroupsInPedantic, raw_ostream &OS) {
1556
1531
OS << " static const int16_t DiagSubGroups[] = {\n "
1557
1532
<< " /* Empty */ -1,\n " ;
1558
- for (auto const &I : DiagsInGroup) {
1559
- const bool IsPedantic = I.first == " pedantic" ;
1560
-
1561
- const std::vector<std::string> &SubGroups = I.second .SubGroups ;
1533
+ for (auto const &[Name, Group] : DiagsInGroup) {
1534
+ const bool IsPedantic = Name == " pedantic" ;
1535
+ const std::vector<std::string> &SubGroups = Group.SubGroups ;
1562
1536
if (!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ())) {
1563
- OS << " /* DiagSubGroup" << I. second .IDNo << " */ " ;
1537
+ OS << " /* DiagSubGroup" << Group .IDNo << " */ " ;
1564
1538
for (auto const &SubGroup : SubGroups) {
1565
- std::map<std::string, GroupInfo>::const_iterator RI =
1566
- DiagsInGroup.find (SubGroup);
1539
+ auto RI = DiagsInGroup.find (SubGroup);
1567
1540
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1568
1541
OS << RI->second .IDNo << " , " ;
1569
1542
}
@@ -1572,8 +1545,7 @@ static void emitDiagSubGroups(DiagsInGroupTy &DiagsInGroup,
1572
1545
for (auto const &Group : GroupsInPedantic) {
1573
1546
const std::string &GroupName =
1574
1547
std::string (Group->getValueAsString (" GroupName" ));
1575
- std::map<std::string, GroupInfo>::const_iterator RI =
1576
- DiagsInGroup.find (GroupName);
1548
+ auto RI = DiagsInGroup.find (GroupName);
1577
1549
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1578
1550
OS << RI->second .IDNo << " , " ;
1579
1551
}
@@ -1607,12 +1579,12 @@ static void emitDiagArrays(DiagsInGroupTy &DiagsInGroup,
1607
1579
RecordVec &DiagsInPedantic, raw_ostream &OS) {
1608
1580
OS << " static const int16_t DiagArrays[] = {\n "
1609
1581
<< " /* Empty */ -1,\n " ;
1610
- for (auto const &I : DiagsInGroup) {
1611
- const bool IsPedantic = I. first == " pedantic" ;
1582
+ for (const auto &[Name, Group] : DiagsInGroup) {
1583
+ const bool IsPedantic = Name == " pedantic" ;
1612
1584
1613
- const std::vector<const Record *> &V = I. second .DiagsInGroup ;
1585
+ const std::vector<const Record *> &V = Group .DiagsInGroup ;
1614
1586
if (!V.empty () || (IsPedantic && !DiagsInPedantic.empty ())) {
1615
- OS << " /* DiagArray" << I. second .IDNo << " */ " ;
1587
+ OS << " /* DiagArray" << Group .IDNo << " */ " ;
1616
1588
for (auto *Record : V)
1617
1589
OS << " diag::" << Record->getName () << " , " ;
1618
1590
// Emit the diagnostics implicitly in "pedantic".
@@ -1694,31 +1666,29 @@ static void emitDiagTable(DiagsInGroupTy &DiagsInGroup,
1694
1666
1695
1667
OS << " \n #ifdef DIAG_ENTRY\n " ;
1696
1668
unsigned SubGroupIndex = 1 , DiagArrayIndex = 1 ;
1697
- for (auto const &I : DiagsInGroup) {
1669
+ for (auto const &[Name, GroupInfo] : DiagsInGroup) {
1698
1670
// Group option string.
1699
1671
OS << " DIAG_ENTRY(" ;
1700
- OS << I.second .GroupName << " /* " ;
1701
-
1702
- if (I.first .find_first_not_of (" abcdefghijklmnopqrstuvwxyz"
1703
- " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1704
- " 0123456789!@#$%^*-+=:?" ) !=
1705
- std::string::npos)
1706
- PrintFatalError (" Invalid character in diagnostic group '" + I.first +
1707
- " '" );
1708
- 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 << " */, " ;
1709
1679
// Store a pascal-style length byte at the beginning of the string.
1710
- std::string Name = char (I. first . size ()) + I. first ;
1711
- OS << *GroupNames.GetStringOffset (Name ) << " , " ;
1680
+ std::string PascalName = char (Name. size ()) + Name ;
1681
+ OS << *GroupNames.GetStringOffset (PascalName ) << " , " ;
1712
1682
1713
1683
// Special handling for 'pedantic'.
1714
- const bool IsPedantic = I. first == " pedantic" ;
1684
+ const bool IsPedantic = Name == " pedantic" ;
1715
1685
1716
1686
// Diagnostics in the group.
1717
- const std::vector<const Record *> &V = I. second .DiagsInGroup ;
1687
+ const std::vector<const Record *> &V = GroupInfo .DiagsInGroup ;
1718
1688
const bool hasDiags =
1719
1689
!V.empty () || (IsPedantic && !DiagsInPedantic.empty ());
1720
1690
if (hasDiags) {
1721
- OS << " /* DiagArray" << I. second .IDNo << " */ " << DiagArrayIndex
1691
+ OS << " /* DiagArray" << GroupInfo .IDNo << " */ " << DiagArrayIndex
1722
1692
<< " , " ;
1723
1693
if (IsPedantic)
1724
1694
DiagArrayIndex += DiagsInPedantic.size ();
@@ -1728,11 +1698,11 @@ static void emitDiagTable(DiagsInGroupTy &DiagsInGroup,
1728
1698
}
1729
1699
1730
1700
// Subgroups.
1731
- const std::vector<std::string> &SubGroups = I. second .SubGroups ;
1701
+ const std::vector<std::string> &SubGroups = GroupInfo .SubGroups ;
1732
1702
const bool hasSubGroups =
1733
1703
!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ());
1734
1704
if (hasSubGroups) {
1735
- OS << " /* DiagSubGroup" << I. second .IDNo << " */ " << SubGroupIndex
1705
+ OS << " /* DiagSubGroup" << GroupInfo .IDNo << " */ " << SubGroupIndex
1736
1706
<< " , " ;
1737
1707
if (IsPedantic)
1738
1708
SubGroupIndex += GroupsInPedantic.size ();
@@ -1741,7 +1711,7 @@ static void emitDiagTable(DiagsInGroupTy &DiagsInGroup,
1741
1711
OS << " 0, " ;
1742
1712
}
1743
1713
1744
- std::string Documentation = I. second .Defs .back ()
1714
+ std::string Documentation = GroupInfo .Defs .back ()
1745
1715
->getValue (" Documentation" )
1746
1716
->getValue ()
1747
1717
->getAsUnquotedString ();
@@ -1834,20 +1804,15 @@ void clang::EmitClangDiagsIndexName(const RecordKeeper &Records,
1834
1804
1835
1805
std::vector<RecordIndexElement> Index;
1836
1806
Index.reserve (Diags.size ());
1837
- for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
1838
- const Record &R = *(Diags[i]);
1839
- Index.push_back (RecordIndexElement (R));
1840
- }
1807
+ for (const Record *R : Diags)
1808
+ Index.push_back (RecordIndexElement (*R));
1841
1809
1842
1810
sort (Index, [](const RecordIndexElement &Lhs, const RecordIndexElement &Rhs) {
1843
1811
return Lhs.Name < Rhs.Name ;
1844
1812
});
1845
1813
1846
- for (unsigned i = 0 , e = Index.size (); i != e; ++i) {
1847
- const RecordIndexElement &R = Index[i];
1848
-
1849
- OS << " DIAG_NAME_INDEX(" << R.Name << " )\n " ;
1850
- }
1814
+ for (const auto &Elem : Index)
1815
+ OS << " DIAG_NAME_INDEX(" << Elem.Name << " )\n " ;
1851
1816
}
1852
1817
1853
1818
// ===----------------------------------------------------------------------===//
0 commit comments