@@ -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, std::less<>>;
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,16 +159,14 @@ 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
@@ -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
@@ -1178,15 +1175,11 @@ std::string DiagnosticTextBuilder::buildForDefinition(const Record *R) {
1178
1175
// ===----------------------------------------------------------------------===//
1179
1176
1180
1177
static bool isError (const Record &Diag) {
1181
- const std::string &ClsName =
1182
- std::string (Diag.getValueAsDef (" Class" )->getName ());
1183
- return ClsName == " CLASS_ERROR" ;
1178
+ return Diag.getValueAsDef (" Class" )->getName () == " CLASS_ERROR" ;
1184
1179
}
1185
1180
1186
1181
static bool isRemark (const Record &Diag) {
1187
- const std::string &ClsName =
1188
- std::string (Diag.getValueAsDef (" Class" )->getName ());
1189
- return ClsName == " CLASS_REMARK" ;
1182
+ return Diag.getValueAsDef (" Class" )->getName () == " CLASS_REMARK" ;
1190
1183
}
1191
1184
1192
1185
// Presumes the text has been split at the first whitespace or hyphen.
@@ -1414,16 +1407,14 @@ void clang::EmitClangDiagsDefs(const RecordKeeper &Records, raw_ostream &OS,
1414
1407
InferPedantic inferPedantic (DGParentMap, Diags, DiagGroups, DiagsInGroup);
1415
1408
inferPedantic.compute (&DiagsInPedantic, (RecordVec*)nullptr );
1416
1409
1417
- for (unsigned i = 0 , e = Diags.size (); i != e; ++i) {
1418
- const Record &R = *Diags[i];
1419
-
1410
+ for (const Record *RP : Diags) {
1411
+ const Record &R = *RP;
1420
1412
// Check if this is an error that is accidentally in a warning
1421
1413
// group.
1422
1414
if (isError (R)) {
1423
1415
if (const auto *Group = dyn_cast<DefInit>(R.getValueInit (" Group" ))) {
1424
1416
const Record *GroupRec = Group->getDef ();
1425
- const std::string &GroupName =
1426
- std::string (GroupRec->getValueAsString (" GroupName" ));
1417
+ StringRef GroupName = GroupRec->getValueAsString (" GroupName" );
1427
1418
PrintFatalError (R.getLoc (), " Error " + R.getName () +
1428
1419
" cannot be in a warning group [" + GroupName + " ]" );
1429
1420
}
@@ -1456,13 +1447,11 @@ void clang::EmitClangDiagsDefs(const RecordKeeper &Records, raw_ostream &OS,
1456
1447
// Warning group associated with the diagnostic. This is stored as an index
1457
1448
// into the alphabetically sorted warning group table.
1458
1449
if (const auto *DI = dyn_cast<DefInit>(R.getValueInit (" Group" ))) {
1459
- std::map<std::string, GroupInfo>::iterator I = DiagsInGroup.find (
1460
- std::string (DI->getDef ()->getValueAsString (" GroupName" )));
1450
+ auto I = DiagsInGroup.find (DI->getDef ()->getValueAsString (" GroupName" ));
1461
1451
assert (I != DiagsInGroup.end ());
1462
1452
OS << " , " << I->second .IDNo ;
1463
1453
} else if (DiagsInPedantic.count (&R)) {
1464
- std::map<std::string, GroupInfo>::iterator I =
1465
- DiagsInGroup.find (" pedantic" );
1454
+ auto I = DiagsInGroup.find (" pedantic" );
1466
1455
assert (I != DiagsInGroup.end () && " pedantic group not defined" );
1467
1456
OS << " , " << I->second .IDNo ;
1468
1457
} else {
@@ -1532,19 +1521,18 @@ static void emitDiagSubGroups(DiagsInGroupTy &DiagsInGroup,
1532
1521
<< " /* Empty */ -1,\n " ;
1533
1522
for (auto const &[Name, Group] : DiagsInGroup) {
1534
1523
const bool IsPedantic = Name == " pedantic" ;
1535
- const std::vector<std::string > &SubGroups = Group.SubGroups ;
1524
+ const std::vector<StringRef > &SubGroups = Group.SubGroups ;
1536
1525
if (!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ())) {
1537
1526
OS << " /* DiagSubGroup" << Group.IDNo << " */ " ;
1538
- for (auto const & SubGroup : SubGroups) {
1527
+ for (StringRef SubGroup : SubGroups) {
1539
1528
auto RI = DiagsInGroup.find (SubGroup);
1540
1529
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1541
1530
OS << RI->second .IDNo << " , " ;
1542
1531
}
1543
1532
// Emit the groups implicitly in "pedantic".
1544
1533
if (IsPedantic) {
1545
1534
for (auto const &Group : GroupsInPedantic) {
1546
- const std::string &GroupName =
1547
- std::string (Group->getValueAsString (" GroupName" ));
1535
+ StringRef GroupName = Group->getValueAsString (" GroupName" );
1548
1536
auto RI = DiagsInGroup.find (GroupName);
1549
1537
assert (RI != DiagsInGroup.end () && " Referenced without existing?" );
1550
1538
OS << RI->second .IDNo << " , " ;
@@ -1677,7 +1665,7 @@ static void emitDiagTable(DiagsInGroupTy &DiagsInGroup,
1677
1665
PrintFatalError (" Invalid character in diagnostic group '" + Name + " '" );
1678
1666
OS << Name << " */, " ;
1679
1667
// Store a pascal-style length byte at the beginning of the string.
1680
- std::string PascalName = char (Name.size ()) + Name;
1668
+ std::string PascalName = char (Name.size ()) + Name. str () ;
1681
1669
OS << *GroupNames.GetStringOffset (PascalName) << " , " ;
1682
1670
1683
1671
// Special handling for 'pedantic'.
@@ -1698,7 +1686,7 @@ static void emitDiagTable(DiagsInGroupTy &DiagsInGroup,
1698
1686
}
1699
1687
1700
1688
// Subgroups.
1701
- const std::vector<std::string > &SubGroups = GroupInfo.SubGroups ;
1689
+ const std::vector<StringRef > &SubGroups = GroupInfo.SubGroups ;
1702
1690
const bool hasSubGroups =
1703
1691
!SubGroups.empty () || (IsPedantic && !GroupsInPedantic.empty ());
1704
1692
if (hasSubGroups) {
@@ -1766,13 +1754,10 @@ void clang::EmitClangDiagGroups(const RecordKeeper &Records, raw_ostream &OS) {
1766
1754
inferPedantic.compute (&DiagsInPedantic, &GroupsInPedantic);
1767
1755
1768
1756
StringToOffsetTable GroupNames;
1769
- for (std::map<std::string, GroupInfo>::const_iterator
1770
- I = DiagsInGroup.begin (),
1771
- E = DiagsInGroup.end ();
1772
- I != E; ++I) {
1757
+ for (const auto &[Name, Group] : DiagsInGroup) {
1773
1758
// Store a pascal-style length byte at the beginning of the string.
1774
- std::string Name = char (I-> first .size ()) + I-> first ;
1775
- GroupNames.GetOrAddStringOffset (Name , false );
1759
+ std::string PascalName = char (Name .size ()) + Name. str () ;
1760
+ GroupNames.GetOrAddStringOffset (PascalName , false );
1776
1761
}
1777
1762
1778
1763
emitAllDiagArrays (DiagsInGroup, DiagsInPedantic, GroupsInPedantic, GroupNames,
0 commit comments