@@ -55,11 +55,11 @@ class DiagGroupParentMap {
55
55
};
56
56
} // end anonymous namespace.
57
57
58
- static std::string
58
+ static StringRef
59
59
getCategoryFromDiagGroup (const Record *Group,
60
60
DiagGroupParentMap &DiagGroupParents) {
61
61
// If the DiagGroup has a category, return it.
62
- std::string CatName = std::string ( Group->getValueAsString (" CategoryName" ) );
62
+ StringRef CatName = Group->getValueAsString (" CategoryName" );
63
63
if (!CatName.empty ()) return CatName;
64
64
65
65
// The diag group may the subgroup of one or more other diagnostic groups,
@@ -73,25 +73,26 @@ getCategoryFromDiagGroup(const Record *Group,
73
73
74
74
// / getDiagnosticCategory - Return the category that the specified diagnostic
75
75
// / lives in.
76
- static std::string getDiagnosticCategory (const Record *R,
77
- DiagGroupParentMap &DiagGroupParents) {
76
+ static StringRef getDiagnosticCategory (const Record *R,
77
+ DiagGroupParentMap &DiagGroupParents) {
78
78
// If the diagnostic is in a group, and that group has a category, use it.
79
79
if (const auto *Group = dyn_cast<DefInit>(R->getValueInit (" Group" ))) {
80
80
// Check the diagnostic's diag group for a category.
81
- std::string CatName = getCategoryFromDiagGroup (Group-> getDef (),
82
- DiagGroupParents);
81
+ StringRef CatName =
82
+ getCategoryFromDiagGroup (Group-> getDef (), DiagGroupParents);
83
83
if (!CatName.empty ()) return CatName;
84
84
}
85
85
86
86
// If the diagnostic itself has a category, get it.
87
- return std::string ( R->getValueAsString (" CategoryName" ) );
87
+ return R->getValueAsString (" CategoryName" );
88
88
}
89
89
90
90
namespace {
91
91
class DiagCategoryIDMap {
92
92
const RecordKeeper &Records;
93
93
StringMap<unsigned > CategoryIDs;
94
- std::vector<std::string> CategoryStrings;
94
+ std::vector<StringRef> CategoryStrings;
95
+
95
96
public:
96
97
DiagCategoryIDMap (const RecordKeeper &records) : Records(records) {
97
98
DiagGroupParentMap ParentInfo (Records);
@@ -102,7 +103,7 @@ namespace {
102
103
103
104
for (const Record *Diag :
104
105
Records.getAllDerivedDefinitions (" Diagnostic" )) {
105
- std::string Category = getDiagnosticCategory (Diag, ParentInfo);
106
+ StringRef Category = getDiagnosticCategory (Diag, ParentInfo);
106
107
if (Category.empty ()) continue ; // Skip diags with no category.
107
108
108
109
unsigned &ID = CategoryIDs[Category];
@@ -117,15 +118,15 @@ namespace {
117
118
return CategoryIDs[CategoryString];
118
119
}
119
120
120
- typedef std::vector<std::string >::const_iterator const_iterator;
121
+ typedef std::vector<StringRef >::const_iterator const_iterator;
121
122
const_iterator begin () const { return CategoryStrings.begin (); }
122
123
const_iterator end () const { return CategoryStrings.end (); }
123
124
};
124
125
125
126
struct GroupInfo {
126
127
StringRef GroupName;
127
128
std::vector<const Record*> DiagsInGroup;
128
- std::vector<std::string > SubGroups;
129
+ std::vector<StringRef > SubGroups;
129
130
unsigned IDNo = 0 ;
130
131
131
132
SmallVector<const Record *, 1 > Defs;
@@ -145,7 +146,7 @@ static bool diagGroupBeforeByName(const Record *LHS, const Record *RHS) {
145
146
RHS->getValueAsString (" GroupName" );
146
147
}
147
148
148
- using DiagsInGroupTy = std::map<std::string , GroupInfo, std::less<> >;
149
+ using DiagsInGroupTy = std::map<StringRef , GroupInfo>;
149
150
150
151
// / Invert the 1-[0/1] mapping of diags to group into a one to many
151
152
// / mapping of groups to diags in the group.
@@ -158,21 +159,19 @@ static void groupDiagnostics(ArrayRef<const Record *> Diags,
158
159
continue ;
159
160
assert (R->getValueAsDef (" Class" )->getName () != " CLASS_NOTE" &&
160
161
" Note can't be in a DiagGroup" );
161
- std::string GroupName =
162
- std::string (DI->getDef ()->getValueAsString (" GroupName" ));
162
+ StringRef GroupName = DI->getDef ()->getValueAsString (" GroupName" );
163
163
DiagsInGroup[GroupName].DiagsInGroup .push_back (R);
164
164
}
165
165
166
166
// Add all DiagGroup's to the DiagsInGroup list to make sure we pick up empty
167
167
// groups (these are warnings that GCC supports that clang never produces).
168
168
for (const Record *Group : DiagGroups) {
169
- GroupInfo &GI =
170
- DiagsInGroup[std::string (Group->getValueAsString (" GroupName" ))];
169
+ GroupInfo &GI = DiagsInGroup[Group->getValueAsString (" GroupName" )];
171
170
GI.GroupName = Group->getName ();
172
171
GI.Defs .push_back (Group);
173
172
174
173
for (const Record *SubGroup : Group->getValueAsListOfDefs (" SubGroups" ))
175
- GI.SubGroups .push_back (SubGroup->getValueAsString (" GroupName" ). str () );
174
+ GI.SubGroups .push_back (SubGroup->getValueAsString (" GroupName" ));
176
175
}
177
176
178
177
// Assign unique ID numbers to the groups.
@@ -281,8 +280,7 @@ class InferPedantic {
281
280
} // end anonymous namespace
282
281
283
282
bool InferPedantic::isSubGroupOfGroup (const Record *Group, StringRef GName) {
284
- const std::string &GroupName =
285
- std::string (Group->getValueAsString (" GroupName" ));
283
+ StringRef GroupName = Group->getValueAsString (" GroupName" );
286
284
if (GName == GroupName)
287
285
return true ;
288
286
@@ -307,8 +305,7 @@ bool InferPedantic::groupInPedantic(const Record *Group, bool increment) {
307
305
GMap::mapped_type &V = GroupCount[Group];
308
306
// Lazily compute the threshold value for the group count.
309
307
if (!V.second ) {
310
- const GroupInfo &GI =
311
- DiagsInGroup[std::string (Group->getValueAsString (" GroupName" ))];
308
+ const GroupInfo &GI = DiagsInGroup[Group->getValueAsString (" GroupName" )];
312
309
V.second = GI.SubGroups .size () + GI.DiagsInGroup .size ();
313
310
}
314
311
@@ -1183,15 +1180,11 @@ std::string DiagnosticTextBuilder::buildForDefinition(const Record *R) {
1183
1180
// ===----------------------------------------------------------------------===//
1184
1181
1185
1182
static bool isError (const Record &Diag) {
1186
- const std::string &ClsName =
1187
- std::string (Diag.getValueAsDef (" Class" )->getName ());
1188
- return ClsName == " CLASS_ERROR" ;
1183
+ return Diag.getValueAsDef (" Class" )->getName () == " CLASS_ERROR" ;
1189
1184
}
1190
1185
1191
1186
static bool isRemark (const Record &Diag) {
1192
- const std::string &ClsName =
1193
- std::string (Diag.getValueAsDef (" Class" )->getName ());
1194
- return ClsName == " CLASS_REMARK" ;
1187
+ return Diag.getValueAsDef (" Class" )->getName () == " CLASS_REMARK" ;
1195
1188
}
1196
1189
1197
1190
// Presumes the text has been split at the first whitespace or hyphen.
@@ -1419,16 +1412,13 @@ void clang::EmitClangDiagsDefs(const RecordKeeper &Records, raw_ostream &OS,
1419
1412
InferPedantic inferPedantic (DGParentMap, Diags, DiagGroups, DiagsInGroup);
1420
1413
inferPedantic.compute (&DiagsInPedantic, (RecordVec*)nullptr );
1421
1414
1422
- for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
1423
- const Record &R = *Diags[i];
1424
-
1415
+ for (const Record &R : make_pointee_range (Diags)) {
1425
1416
// Check if this is an error that is accidentally in a warning
1426
1417
// group.
1427
1418
if (isError (R)) {
1428
1419
if (const auto *Group = dyn_cast<DefInit>(R.getValueInit (" Group" ))) {
1429
1420
const Record *GroupRec = Group->getDef ();
1430
- const std::string &GroupName =
1431
- std::string (GroupRec->getValueAsString (" GroupName" ));
1421
+ StringRef GroupName = GroupRec->getValueAsString (" GroupName" );
1432
1422
PrintFatalError (R.getLoc (), " Error " + R.getName () +
1433
1423
" cannot be in a warning group [" + GroupName + " ]" );
1434
1424
}
@@ -1461,13 +1451,11 @@ void clang::EmitClangDiagsDefs(const RecordKeeper &Records, raw_ostream &OS,
1461
1451
// Warning group associated with the diagnostic. This is stored as an index
1462
1452
// into the alphabetically sorted warning group table.
1463
1453
if (const auto *DI = dyn_cast<DefInit>(R.getValueInit (" Group" ))) {
1464
- std::map<std::string, GroupInfo>::iterator I = DiagsInGroup.find (
1465
- std::string (DI->getDef ()->getValueAsString (" GroupName" )));
1454
+ auto I = DiagsInGroup.find (DI->getDef ()->getValueAsString (" GroupName" ));
1466
1455
assert (I != DiagsInGroup.end ());
1467
1456
OS << " , " << I->second .IDNo ;
1468
1457
} else if (DiagsInPedantic.count (&R)) {
1469
- std::map<std::string, GroupInfo>::iterator I =
1470
- DiagsInGroup.find (" pedantic" );
1458
+ auto I = DiagsInGroup.find (" pedantic" );
1471
1459
assert (I != DiagsInGroup.end () && " pedantic group not defined" );
1472
1460
OS << " , " << I->second .IDNo ;
1473
1461
} else {
@@ -1537,19 +1525,18 @@ static void emitDiagSubGroups(DiagsInGroupTy &DiagsInGroup,
1537
1525
<< " /* Empty */ -1,\n " ;
1538
1526
for (auto const &[Name, Group] : DiagsInGroup) {
1539
1527
const bool IsPedantic = Name == " pedantic" ;
1540
- const std::vector<std::string > &SubGroups = Group.SubGroups ;
1528
+ const std::vector<StringRef > &SubGroups = Group.SubGroups ;
1541
1529
if (!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ())) {
1542
1530
OS << " /* DiagSubGroup" << Group.IDNo << " */ " ;
1543
- for (auto const & SubGroup : SubGroups) {
1531
+ for (StringRef SubGroup : SubGroups) {
1544
1532
auto RI = DiagsInGroup.find (SubGroup);
1545
1533
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1546
1534
OS << RI->second .IDNo << " , " ;
1547
1535
}
1548
1536
// Emit the groups implicitly in "pedantic".
1549
1537
if (IsPedantic) {
1550
1538
for (auto const &Group : GroupsInPedantic) {
1551
- const std::string &GroupName =
1552
- std::string (Group->getValueAsString (" GroupName" ));
1539
+ StringRef GroupName = Group->getValueAsString (" GroupName" );
1553
1540
auto RI = DiagsInGroup.find (GroupName);
1554
1541
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1555
1542
OS << RI->second .IDNo << " , " ;
@@ -1682,7 +1669,7 @@ static void emitDiagTable(DiagsInGroupTy &DiagsInGroup,
1682
1669
PrintFatalError (" Invalid character in diagnostic group '" + Name + " '" );
1683
1670
OS << Name << " */, " ;
1684
1671
// Store a pascal-style length byte at the beginning of the string.
1685
- std::string PascalName = char (Name.size ()) + Name;
1672
+ std::string PascalName = char (Name.size ()) + Name. str () ;
1686
1673
OS << *GroupNames.GetStringOffset (PascalName) << " , " ;
1687
1674
1688
1675
// Special handling for 'pedantic'.
@@ -1703,7 +1690,7 @@ static void emitDiagTable(DiagsInGroupTy &DiagsInGroup,
1703
1690
}
1704
1691
1705
1692
// Subgroups.
1706
- const std::vector<std::string > &SubGroups = GroupInfo.SubGroups ;
1693
+ const std::vector<StringRef > &SubGroups = GroupInfo.SubGroups ;
1707
1694
const bool hasSubGroups =
1708
1695
!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ());
1709
1696
if (hasSubGroups) {
@@ -1771,13 +1758,10 @@ void clang::EmitClangDiagGroups(const RecordKeeper &Records, raw_ostream &OS) {
1771
1758
inferPedantic.compute (&DiagsInPedantic, &GroupsInPedantic);
1772
1759
1773
1760
StringToOffsetTable GroupNames;
1774
- for (std::map<std::string, GroupInfo>::const_iterator
1775
- I = DiagsInGroup.begin (),
1776
- E = DiagsInGroup.end ();
1777
- I != E; ++I) {
1761
+ for (const auto &[Name, Group] : DiagsInGroup) {
1778
1762
// Store a pascal-style length byte at the beginning of the string.
1779
- std::string Name = char (I-> first .size ()) + I-> first ;
1780
- GroupNames.GetOrAddStringOffset (Name , false );
1763
+ std::string PascalName = char (Name .size ()) + Name. str () ;
1764
+ GroupNames.GetOrAddStringOffset (PascalName , false );
1781
1765
}
1782
1766
1783
1767
emitAllDiagArrays (DiagsInGroup, DiagsInPedantic, GroupsInPedantic, GroupNames,
@@ -1819,7 +1803,7 @@ bool isRemarkGroup(const Record *DiagGroup,
1819
1803
auto &GroupInfo = DiagsInGroup.find (GroupName)->second ;
1820
1804
for (const Record *Diag : GroupInfo.DiagsInGroup )
1821
1805
(isRemark (*Diag) ? AnyRemarks : AnyNonRemarks) = true ;
1822
- for (const auto & Name : GroupInfo.SubGroups )
1806
+ for (StringRef Name : GroupInfo.SubGroups )
1823
1807
Visit (Name);
1824
1808
};
1825
1809
Visit (DiagGroup->getValueAsString (" GroupName" ));
@@ -1916,8 +1900,7 @@ void clang::EmitClangDiagDocs(const RecordKeeper &Records, raw_ostream &OS) {
1916
1900
DiagsInPedantic.begin (),
1917
1901
DiagsInPedantic.end ());
1918
1902
for (auto *Group : GroupsInPedantic)
1919
- PedDiags.SubGroups .push_back (
1920
- std::string (Group->getValueAsString (" GroupName" )));
1903
+ PedDiags.SubGroups .push_back (Group->getValueAsString (" GroupName" ));
1921
1904
}
1922
1905
1923
1906
// FIXME: Write diagnostic categories and link to diagnostic groups in each.
@@ -1963,7 +1946,7 @@ void clang::EmitClangDiagDocs(const RecordKeeper &Records, raw_ostream &OS) {
1963
1946
1964
1947
bool First = true ;
1965
1948
sort (GroupInfo.SubGroups );
1966
- for (const auto & Name : GroupInfo.SubGroups ) {
1949
+ for (StringRef Name : GroupInfo.SubGroups ) {
1967
1950
if (!First) OS << " , " ;
1968
1951
OS << " `" << (IsRemarkGroup ? " -R" : " -W" ) << Name << " `_" ;
1969
1952
First = false ;
0 commit comments