@@ -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,14 @@ 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 *RP : Diags) {
1416
+ const Record &R = *RP;
1425
1417
// Check if this is an error that is accidentally in a warning
1426
1418
// group.
1427
1419
if (isError (R)) {
1428
1420
if (const auto *Group = dyn_cast<DefInit>(R.getValueInit (" Group" ))) {
1429
1421
const Record *GroupRec = Group->getDef ();
1430
- const std::string &GroupName =
1431
- std::string (GroupRec->getValueAsString (" GroupName" ));
1422
+ StringRef GroupName = GroupRec->getValueAsString (" GroupName" );
1432
1423
PrintFatalError (R.getLoc (), " Error " + R.getName () +
1433
1424
" cannot be in a warning group [" + GroupName + " ]" );
1434
1425
}
@@ -1461,13 +1452,11 @@ void clang::EmitClangDiagsDefs(const RecordKeeper &Records, raw_ostream &OS,
1461
1452
// Warning group associated with the diagnostic. This is stored as an index
1462
1453
// into the alphabetically sorted warning group table.
1463
1454
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" )));
1455
+ auto I = DiagsInGroup.find (DI->getDef ()->getValueAsString (" GroupName" ));
1466
1456
assert (I != DiagsInGroup.end ());
1467
1457
OS << " , " << I->second .IDNo ;
1468
1458
} else if (DiagsInPedantic.count (&R)) {
1469
- std::map<std::string, GroupInfo>::iterator I =
1470
- DiagsInGroup.find (" pedantic" );
1459
+ auto I = DiagsInGroup.find (" pedantic" );
1471
1460
assert (I != DiagsInGroup.end () && " pedantic group not defined" );
1472
1461
OS << " , " << I->second .IDNo ;
1473
1462
} else {
@@ -1537,19 +1526,18 @@ static void emitDiagSubGroups(DiagsInGroupTy &DiagsInGroup,
1537
1526
<< " /* Empty */ -1,\n " ;
1538
1527
for (auto const &[Name, Group] : DiagsInGroup) {
1539
1528
const bool IsPedantic = Name == " pedantic" ;
1540
- const std::vector<std::string > &SubGroups = Group.SubGroups ;
1529
+ const std::vector<StringRef > &SubGroups = Group.SubGroups ;
1541
1530
if (!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ())) {
1542
1531
OS << " /* DiagSubGroup" << Group.IDNo << " */ " ;
1543
- for (auto const & SubGroup : SubGroups) {
1532
+ for (StringRef SubGroup : SubGroups) {
1544
1533
auto RI = DiagsInGroup.find (SubGroup);
1545
1534
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1546
1535
OS << RI->second .IDNo << " , " ;
1547
1536
}
1548
1537
// Emit the groups implicitly in "pedantic".
1549
1538
if (IsPedantic) {
1550
1539
for (auto const &Group : GroupsInPedantic) {
1551
- const std::string &GroupName =
1552
- std::string (Group->getValueAsString (" GroupName" ));
1540
+ StringRef GroupName = Group->getValueAsString (" GroupName" );
1553
1541
auto RI = DiagsInGroup.find (GroupName);
1554
1542
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1555
1543
OS << RI->second .IDNo << " , " ;
@@ -1682,7 +1670,7 @@ static void emitDiagTable(DiagsInGroupTy &DiagsInGroup,
1682
1670
PrintFatalError (" Invalid character in diagnostic group '" + Name + " '" );
1683
1671
OS << Name << " */, " ;
1684
1672
// Store a pascal-style length byte at the beginning of the string.
1685
- std::string PascalName = char (Name.size ()) + Name;
1673
+ std::string PascalName = char (Name.size ()) + Name. str () ;
1686
1674
OS << *GroupNames.GetStringOffset (PascalName) << " , " ;
1687
1675
1688
1676
// Special handling for 'pedantic'.
@@ -1703,7 +1691,7 @@ static void emitDiagTable(DiagsInGroupTy &DiagsInGroup,
1703
1691
}
1704
1692
1705
1693
// Subgroups.
1706
- const std::vector<std::string > &SubGroups = GroupInfo.SubGroups ;
1694
+ const std::vector<StringRef > &SubGroups = GroupInfo.SubGroups ;
1707
1695
const bool hasSubGroups =
1708
1696
!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ());
1709
1697
if (hasSubGroups) {
@@ -1771,13 +1759,10 @@ void clang::EmitClangDiagGroups(const RecordKeeper &Records, raw_ostream &OS) {
1771
1759
inferPedantic.compute (&DiagsInPedantic, &GroupsInPedantic);
1772
1760
1773
1761
StringToOffsetTable GroupNames;
1774
- for (std::map<std::string, GroupInfo>::const_iterator
1775
- I = DiagsInGroup.begin (),
1776
- E = DiagsInGroup.end ();
1777
- I != E; ++I) {
1762
+ for (const auto &[Name, Group] : DiagsInGroup) {
1778
1763
// 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 );
1764
+ std::string PascalName = char (Name .size ()) + Name. str () ;
1765
+ GroupNames.GetOrAddStringOffset (PascalName , false );
1781
1766
}
1782
1767
1783
1768
emitAllDiagArrays (DiagsInGroup, DiagsInPedantic, GroupsInPedantic, GroupNames,
@@ -1835,7 +1820,7 @@ bool isRemarkGroup(const Record *DiagGroup,
1835
1820
auto &GroupInfo = DiagsInGroup.find (GroupName)->second ;
1836
1821
for (const Record *Diag : GroupInfo.DiagsInGroup )
1837
1822
(isRemark (*Diag) ? AnyRemarks : AnyNonRemarks) = true ;
1838
- for (const auto & Name : GroupInfo.SubGroups )
1823
+ for (StringRef Name : GroupInfo.SubGroups )
1839
1824
Visit (Name);
1840
1825
};
1841
1826
Visit (DiagGroup->getValueAsString (" GroupName" ));
@@ -1932,8 +1917,7 @@ void clang::EmitClangDiagDocs(const RecordKeeper &Records, raw_ostream &OS) {
1932
1917
DiagsInPedantic.begin (),
1933
1918
DiagsInPedantic.end ());
1934
1919
for (auto *Group : GroupsInPedantic)
1935
- PedDiags.SubGroups .push_back (
1936
- std::string (Group->getValueAsString (" GroupName" )));
1920
+ PedDiags.SubGroups .push_back (Group->getValueAsString (" GroupName" ));
1937
1921
}
1938
1922
1939
1923
// FIXME: Write diagnostic categories and link to diagnostic groups in each.
@@ -1979,7 +1963,7 @@ void clang::EmitClangDiagDocs(const RecordKeeper &Records, raw_ostream &OS) {
1979
1963
1980
1964
bool First = true ;
1981
1965
sort (GroupInfo.SubGroups );
1982
- for (const auto & Name : GroupInfo.SubGroups ) {
1966
+ for (StringRef Name : GroupInfo.SubGroups ) {
1983
1967
if (!First) OS << " , " ;
1984
1968
OS << " `" << (IsRemarkGroup ? " -R" : " -W" ) << Name << " `_" ;
1985
1969
First = false ;
0 commit comments