@@ -33,25 +33,26 @@ using namespace llvm::opt;
33
33
34
34
namespace {
35
35
struct OptNameLess {
36
- const char *StrTable;
37
- ArrayRef<unsigned > PrefixesTable;
36
+ const StringTable *StrTable;
37
+ ArrayRef<StringTable::Offset > PrefixesTable;
38
38
39
- explicit OptNameLess (const char *StrTable, ArrayRef<unsigned > PrefixesTable)
40
- : StrTable(StrTable), PrefixesTable(PrefixesTable) {}
39
+ explicit OptNameLess (const StringTable &StrTable,
40
+ ArrayRef<StringTable::Offset> PrefixesTable)
41
+ : StrTable(&StrTable), PrefixesTable(PrefixesTable) {}
41
42
42
43
#ifndef NDEBUG
43
44
inline bool operator ()(const OptTable::Info &A,
44
45
const OptTable::Info &B) const {
45
46
if (&A == &B)
46
47
return false ;
47
48
48
- if (int Cmp = StrCmpOptionName (A.getName (StrTable, PrefixesTable),
49
- B.getName (StrTable, PrefixesTable)))
49
+ if (int Cmp = StrCmpOptionName (A.getName (* StrTable, PrefixesTable),
50
+ B.getName (* StrTable, PrefixesTable)))
50
51
return Cmp < 0 ;
51
52
52
53
SmallVector<StringRef, 8 > APrefixes, BPrefixes;
53
- A.appendPrefixes (StrTable, PrefixesTable, APrefixes);
54
- B.appendPrefixes (StrTable, PrefixesTable, BPrefixes);
54
+ A.appendPrefixes (* StrTable, PrefixesTable, APrefixes);
55
+ B.appendPrefixes (* StrTable, PrefixesTable, BPrefixes);
55
56
56
57
if (int Cmp = StrCmpOptionPrefixes (APrefixes, BPrefixes))
57
58
return Cmp < 0 ;
@@ -68,17 +69,18 @@ struct OptNameLess {
68
69
// Support lower_bound between info and an option name.
69
70
inline bool operator ()(const OptTable::Info &I, StringRef Name) const {
70
71
// Do not fallback to case sensitive comparison.
71
- return StrCmpOptionName (I.getName (StrTable, PrefixesTable), Name, false ) <
72
+ return StrCmpOptionName (I.getName (* StrTable, PrefixesTable), Name, false ) <
72
73
0 ;
73
74
}
74
75
};
75
76
} // namespace
76
77
77
78
OptSpecifier::OptSpecifier (const Option *Opt) : ID(Opt->getID ()) {}
78
79
79
- OptTable::OptTable (const char *StrTable, ArrayRef<unsigned > PrefixesTable,
80
+ OptTable::OptTable (const StringTable &StrTable,
81
+ ArrayRef<StringTable::Offset> PrefixesTable,
80
82
ArrayRef<Info> OptionInfos, bool IgnoreCase)
81
- : StrTable(StrTable), PrefixesTable(PrefixesTable),
83
+ : StrTable(& StrTable), PrefixesTable(PrefixesTable),
82
84
OptionInfos(OptionInfos), IgnoreCase(IgnoreCase) {
83
85
// Explicitly zero initialize the error to work around a bug in array
84
86
// value-initialization on MinGW with gcc 4.3.5.
@@ -151,13 +153,13 @@ static bool isInput(const ArrayRef<StringRef> &Prefixes, StringRef Arg) {
151
153
}
152
154
153
155
// / \returns Matched size. 0 means no match.
154
- static unsigned matchOption (const char * StrTable,
155
- ArrayRef<unsigned > PrefixesTable,
156
+ static unsigned matchOption (const StringTable & StrTable,
157
+ ArrayRef<StringTable::Offset > PrefixesTable,
156
158
const OptTable::Info *I, StringRef Str,
157
159
bool IgnoreCase) {
158
160
StringRef Name = I->getName (StrTable, PrefixesTable);
159
- for (unsigned PrefixOffset : I->getPrefixOffsets (PrefixesTable)) {
160
- StringRef Prefix = & StrTable[PrefixOffset];
161
+ for (auto PrefixOffset : I->getPrefixOffsets (PrefixesTable)) {
162
+ StringRef Prefix = StrTable[PrefixOffset];
161
163
if (Str.starts_with (Prefix)) {
162
164
StringRef Rest = Str.substr (Prefix.size ());
163
165
bool Matched = IgnoreCase ? Rest.starts_with_insensitive (Name)
@@ -170,13 +172,13 @@ static unsigned matchOption(const char *StrTable,
170
172
}
171
173
172
174
// Returns true if one of the Prefixes + In.Names matches Option
173
- static bool optionMatches (const char * StrTable,
174
- ArrayRef<unsigned > PrefixesTable,
175
+ static bool optionMatches (const StringTable & StrTable,
176
+ ArrayRef<StringTable::Offset > PrefixesTable,
175
177
const OptTable::Info &In, StringRef Option) {
176
178
StringRef Name = In.getName (StrTable, PrefixesTable);
177
179
if (Option.consume_back (Name))
178
- for (unsigned PrefixOffset : In.getPrefixOffsets (PrefixesTable))
179
- if (Option == & StrTable[PrefixOffset])
180
+ for (auto PrefixOffset : In.getPrefixOffsets (PrefixesTable))
181
+ if (Option == StrTable[PrefixOffset])
180
182
return true ;
181
183
return false ;
182
184
}
@@ -189,7 +191,7 @@ OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const {
189
191
// Search all options and return possible values.
190
192
for (size_t I = FirstSearchableIndex, E = OptionInfos.size (); I < E; I++) {
191
193
const Info &In = OptionInfos[I];
192
- if (!In.Values || !optionMatches (StrTable, PrefixesTable, In, Option))
194
+ if (!In.Values || !optionMatches (* StrTable, PrefixesTable, In, Option))
193
195
continue ;
194
196
195
197
SmallVector<StringRef, 8 > Candidates;
@@ -217,9 +219,9 @@ OptTable::findByPrefix(StringRef Cur, Visibility VisibilityMask,
217
219
if (In.Flags & DisableFlags)
218
220
continue ;
219
221
220
- StringRef Name = In.getName (StrTable, PrefixesTable);
221
- for (unsigned PrefixOffset : In.getPrefixOffsets (PrefixesTable)) {
222
- StringRef Prefix = & StrTable[PrefixOffset];
222
+ StringRef Name = In.getName (* StrTable, PrefixesTable);
223
+ for (auto PrefixOffset : In.getPrefixOffsets (PrefixesTable)) {
224
+ StringRef Prefix = (* StrTable) [PrefixOffset];
223
225
std::string S = (Twine (Prefix) + Name + " \t " ).str ();
224
226
if (In.HelpText )
225
227
S += In.HelpText ;
@@ -271,7 +273,7 @@ unsigned OptTable::internalFindNearest(
271
273
272
274
for (const Info &CandidateInfo :
273
275
ArrayRef<Info>(OptionInfos).drop_front (FirstSearchableIndex)) {
274
- StringRef CandidateName = CandidateInfo.getName (StrTable, PrefixesTable);
276
+ StringRef CandidateName = CandidateInfo.getName (* StrTable, PrefixesTable);
275
277
276
278
// We can eliminate some option prefix/name pairs as candidates right away:
277
279
// * Ignore option candidates with empty names, such as "--", or names
@@ -304,9 +306,9 @@ unsigned OptTable::internalFindNearest(
304
306
// Consider each possible prefix for each candidate to find the most
305
307
// appropriate one. For example, if a user asks for "--helm", suggest
306
308
// "--help" over "-help".
307
- for (unsigned CandidatePrefixOffset :
309
+ for (auto CandidatePrefixOffset :
308
310
CandidateInfo.getPrefixOffsets (PrefixesTable)) {
309
- StringRef CandidatePrefix = & StrTable[CandidatePrefixOffset];
311
+ StringRef CandidatePrefix = (* StrTable) [CandidatePrefixOffset];
310
312
// If Candidate and NormalizedName have more than 'BestDistance'
311
313
// characters of difference, no need to compute the edit distance, it's
312
314
// going to be greater than BestDistance. Don't bother computing Candidate
@@ -359,14 +361,14 @@ std::unique_ptr<Arg> OptTable::parseOneArgGrouped(InputArgList &Args,
359
361
StringRef Name = Str.ltrim (PrefixChars);
360
362
const Info *Start =
361
363
std::lower_bound (OptionInfos.data () + FirstSearchableIndex, End, Name,
362
- OptNameLess (StrTable, PrefixesTable));
364
+ OptNameLess (* StrTable, PrefixesTable));
363
365
const Info *Fallback = nullptr ;
364
366
unsigned Prev = Index;
365
367
366
368
// Search for the option which matches Str.
367
369
for (; Start != End; ++Start) {
368
370
unsigned ArgSize =
369
- matchOption (StrTable, PrefixesTable, Start, Str, IgnoreCase);
371
+ matchOption (* StrTable, PrefixesTable, Start, Str, IgnoreCase);
370
372
if (!ArgSize)
371
373
continue ;
372
374
@@ -449,7 +451,7 @@ std::unique_ptr<Arg> OptTable::internalParseOneArg(
449
451
450
452
// Search for the first next option which could be a prefix.
451
453
Start =
452
- std::lower_bound (Start, End, Name, OptNameLess (StrTable, PrefixesTable));
454
+ std::lower_bound (Start, End, Name, OptNameLess (* StrTable, PrefixesTable));
453
455
454
456
// Options are stored in sorted order, with '\0' at the end of the
455
457
// alphabet. Since the only options which can accept a string must
@@ -464,7 +466,7 @@ std::unique_ptr<Arg> OptTable::internalParseOneArg(
464
466
// Scan for first option which is a proper prefix.
465
467
for (; Start != End; ++Start)
466
468
if ((ArgSize =
467
- matchOption (StrTable, PrefixesTable, Start, Str, IgnoreCase)))
469
+ matchOption (* StrTable, PrefixesTable, Start, Str, IgnoreCase)))
468
470
break ;
469
471
if (Start == End)
470
472
break ;
@@ -787,15 +789,15 @@ void OptTable::internalPrintHelp(
787
789
OS.flush ();
788
790
}
789
791
790
- GenericOptTable::GenericOptTable (const char * StrTable,
791
- ArrayRef<unsigned > PrefixesTable,
792
+ GenericOptTable::GenericOptTable (const StringTable & StrTable,
793
+ ArrayRef<StringTable::Offset > PrefixesTable,
792
794
ArrayRef<Info> OptionInfos, bool IgnoreCase)
793
795
: OptTable(StrTable, PrefixesTable, OptionInfos, IgnoreCase) {
794
796
795
797
std::set<StringRef> TmpPrefixesUnion;
796
798
for (auto const &Info : OptionInfos.drop_front (FirstSearchableIndex))
797
- for (unsigned PrefixOffset : Info.getPrefixOffsets (PrefixesTable))
798
- TmpPrefixesUnion.insert (StringRef (& StrTable[PrefixOffset]) );
799
+ for (auto PrefixOffset : Info.getPrefixOffsets (PrefixesTable))
800
+ TmpPrefixesUnion.insert (StrTable[PrefixOffset]);
799
801
PrefixesUnion.append (TmpPrefixesUnion.begin (), TmpPrefixesUnion.end ());
800
802
buildPrefixChars ();
801
803
}
0 commit comments