@@ -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
@@ -468,7 +442,7 @@ static StringRef getModifierName(ModifierType MT) {
468
442
return " objcclass" ;
469
443
case MT_ObjCInstance:
470
444
return " objcinstance" ;
471
- case MT_Unknown:
445
+ case MT_Unknown
472
446
llvm_unreachable (" invalid modifier type" );
473
447
}
474
448
// Unhandled case
@@ -477,16 +451,17 @@ static StringRef getModifierName(ModifierType MT) {
477
451
478
452
struct Piece {
479
453
// This type and its derived classes are move-only.
480
- Piece (PieceKind Kind) : ClassKind(Kind) {}
481
- Piece (Piece const &O) = delete ;
482
- Piece &operator =(Piece const &) = delete ;
483
- virtual ~Piece () {}
454
+ Piece (PieceKind Kind) :
455
+ ClassKind (Kind) {}
456
+ Piece (Piece const &O) = delete ;
457
+ Piece &operator =(Piece const &) = delete ;
458
+ virtual ~Piece () {}
484
459
485
- PieceKind getPieceClass () const { return ClassKind; }
486
- static bool classof (const Piece *) { return true ; }
460
+ PieceKind getPieceClass () const { return ClassKind; }
461
+ static bool classof (const Piece *) { return true ; }
487
462
488
- private:
489
- PieceKind ClassKind;
463
+ private:
464
+ PieceKind ClassKind;
490
465
};
491
466
492
467
struct MultiPiece : Piece {
@@ -970,10 +945,11 @@ struct DiagTextPrinter : DiagTextVisitor<DiagTextPrinter> {
970
945
void VisitPlural (PluralPiece *P) {
971
946
Result += " %plural{" ;
972
947
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]);
948
+ for (const auto &[Prefix, Option] :
949
+ zip_equal (P->OptionPrefixes , P->Options )) {
950
+ if (Prefix)
951
+ Visit (Prefix);
952
+ Visit (Option);
977
953
Result += " |" ;
978
954
}
979
955
if (!P->Options .empty ())
@@ -1553,15 +1529,13 @@ static void emitDiagSubGroups(std::map<std::string, GroupInfo> &DiagsInGroup,
1553
1529
RecordVec &GroupsInPedantic, raw_ostream &OS) {
1554
1530
OS << " static const int16_t DiagSubGroups[] = {\n "
1555
1531
<< " /* 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 ;
1532
+ for (auto const &[Name, Group] : DiagsInGroup) {
1533
+ const bool IsPedantic = Name == " pedantic" ;
1534
+ const std::vector<std::string> &SubGroups = Group.SubGroups ;
1560
1535
if (!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ())) {
1561
- OS << " /* DiagSubGroup" << I. second .IDNo << " */ " ;
1536
+ OS << " /* DiagSubGroup" << Group .IDNo << " */ " ;
1562
1537
for (auto const &SubGroup : SubGroups) {
1563
- std::map<std::string, GroupInfo>::const_iterator RI =
1564
- DiagsInGroup.find (SubGroup);
1538
+ auto RI = DiagsInGroup.find (SubGroup);
1565
1539
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1566
1540
OS << RI->second .IDNo << " , " ;
1567
1541
}
@@ -1570,8 +1544,7 @@ static void emitDiagSubGroups(std::map<std::string, GroupInfo> &DiagsInGroup,
1570
1544
for (auto const &Group : GroupsInPedantic) {
1571
1545
const std::string &GroupName =
1572
1546
std::string (Group->getValueAsString (" GroupName" ));
1573
- std::map<std::string, GroupInfo>::const_iterator RI =
1574
- DiagsInGroup.find (GroupName);
1547
+ auto RI = DiagsInGroup.find (GroupName);
1575
1548
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1576
1549
OS << RI->second .IDNo << " , " ;
1577
1550
}
@@ -1605,12 +1578,12 @@ static void emitDiagArrays(std::map<std::string, GroupInfo> &DiagsInGroup,
1605
1578
RecordVec &DiagsInPedantic, raw_ostream &OS) {
1606
1579
OS << " static const int16_t DiagArrays[] = {\n "
1607
1580
<< " /* Empty */ -1,\n " ;
1608
- for (auto const &I : DiagsInGroup) {
1609
- const bool IsPedantic = I. first == " pedantic" ;
1581
+ for (auto const &[Name, Group] : DiagsInGroup) {
1582
+ const bool IsPedantic = Name == " pedantic" ;
1610
1583
1611
- const std::vector<const Record *> &V = I. second .DiagsInGroup ;
1584
+ const std::vector<const Record *> &V = Group .DiagsInGroup ;
1612
1585
if (!V.empty () || (IsPedantic && !DiagsInPedantic.empty ())) {
1613
- OS << " /* DiagArray" << I. second .IDNo << " */ " ;
1586
+ OS << " /* DiagArray" << Group .IDNo << " */ " ;
1614
1587
for (auto *Record : V)
1615
1588
OS << " diag::" << Record->getName () << " , " ;
1616
1589
// Emit the diagnostics implicitly in "pedantic".
@@ -1692,31 +1665,29 @@ static void emitDiagTable(std::map<std::string, GroupInfo> &DiagsInGroup,
1692
1665
1693
1666
OS << " \n #ifdef DIAG_ENTRY\n " ;
1694
1667
unsigned SubGroupIndex = 1 , DiagArrayIndex = 1 ;
1695
- for (auto const &I : DiagsInGroup) {
1668
+ for (auto const &[Name, GroupInfo] : DiagsInGroup) {
1696
1669
// Group option string.
1697
1670
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 << " */, " ;
1671
+ OS << GroupInfo.GroupName << " /* " ;
1672
+
1673
+ if (Name.find_first_not_of (" abcdefghijklmnopqrstuvwxyz"
1674
+ " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1675
+ " 0123456789!@#$%^*-+=:?" ) != std::string::npos)
1676
+ PrintFatalError (" Invalid character in diagnostic group '" + Name + " '" );
1677
+ OS << Name << " */, " ;
1707
1678
// 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 ) << " , " ;
1679
+ std::string PascalName = char (Name. size ()) + Name ;
1680
+ OS << *GroupNames.GetStringOffset (PascalName ) << " , " ;
1710
1681
1711
1682
// Special handling for 'pedantic'.
1712
- const bool IsPedantic = I. first == " pedantic" ;
1683
+ const bool IsPedantic = Name == " pedantic" ;
1713
1684
1714
1685
// Diagnostics in the group.
1715
- const std::vector<const Record *> &V = I. second .DiagsInGroup ;
1686
+ const std::vector<const Record *> &V = GroupInfo .DiagsInGroup ;
1716
1687
const bool hasDiags =
1717
1688
!V.empty () || (IsPedantic && !DiagsInPedantic.empty ());
1718
1689
if (hasDiags) {
1719
- OS << " /* DiagArray" << I. second .IDNo << " */ " << DiagArrayIndex
1690
+ OS << " /* DiagArray" << GroupInfo .IDNo << " */ " << DiagArrayIndex
1720
1691
<< " , " ;
1721
1692
if (IsPedantic)
1722
1693
DiagArrayIndex += DiagsInPedantic.size ();
@@ -1726,11 +1697,11 @@ static void emitDiagTable(std::map<std::string, GroupInfo> &DiagsInGroup,
1726
1697
}
1727
1698
1728
1699
// Subgroups.
1729
- const std::vector<std::string> &SubGroups = I. second .SubGroups ;
1700
+ const std::vector<std::string> &SubGroups = GroupInfo .SubGroups ;
1730
1701
const bool hasSubGroups =
1731
1702
!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ());
1732
1703
if (hasSubGroups) {
1733
- OS << " /* DiagSubGroup" << I. second .IDNo << " */ " << SubGroupIndex
1704
+ OS << " /* DiagSubGroup" << GroupInfo .IDNo << " */ " << SubGroupIndex
1734
1705
<< " , " ;
1735
1706
if (IsPedantic)
1736
1707
SubGroupIndex += GroupsInPedantic.size ();
@@ -1739,7 +1710,7 @@ static void emitDiagTable(std::map<std::string, GroupInfo> &DiagsInGroup,
1739
1710
OS << " 0, " ;
1740
1711
}
1741
1712
1742
- std::string Documentation = I. second .Defs .back ()
1713
+ std::string Documentation = GroupInfo .Defs .back ()
1743
1714
->getValue (" Documentation" )
1744
1715
->getValue ()
1745
1716
->getAsUnquotedString ();
@@ -1832,20 +1803,15 @@ void clang::EmitClangDiagsIndexName(const RecordKeeper &Records,
1832
1803
1833
1804
std::vector<RecordIndexElement> Index;
1834
1805
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
- }
1806
+ for (const Record *R : Diags)
1807
+ Index.push_back (RecordIndexElement (*R));
1839
1808
1840
1809
sort (Index, [](const RecordIndexElement &Lhs, const RecordIndexElement &Rhs) {
1841
1810
return Lhs.Name < Rhs.Name ;
1842
1811
});
1843
1812
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
- }
1813
+ for (const auto &Elem : Index)
1814
+ OS << " DIAG_NAME_INDEX(" << Elem.Name << " )\n " ;
1849
1815
}
1850
1816
1851
1817
// ===----------------------------------------------------------------------===//
0 commit comments