Skip to content

Commit 1feae67

Browse files
committed
More refactorings
1 parent 3bc51b7 commit 1feae67

File tree

4 files changed

+41
-41
lines changed

4 files changed

+41
-41
lines changed

llvm/include/llvm/Option/ArgList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class ArgList {
283283

284284
/// getSubcommand - Find subcommand from the arguments if the usage is valid.
285285
///
286-
/// \param Commands - A list of all valid subcommands.
286+
/// \param AllSubCommands - A list of all valid subcommands.
287287
/// \param HandleMultipleSubcommands - A callback for the case where multiple
288288
/// subcommands are present in the arguments. It gets a list of all found
289289
/// subcommands.

llvm/include/llvm/Option/OptTable.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class LLVM_ABI OptTable {
8787
unsigned short AliasID;
8888
const char *AliasArgs;
8989
const char *Values;
90-
unsigned CommandIDsOffset;
90+
unsigned SubCommandIDsOffset;
9191

9292
bool hasNoPrefix() const { return PrefixesOffset == 0; }
9393

@@ -103,17 +103,17 @@ class LLVM_ABI OptTable {
103103
getNumPrefixes(PrefixesTable));
104104
}
105105

106-
bool hasCommands() const { return CommandIDsOffset != 0; }
106+
bool hasCommands() const { return SubCommandIDsOffset != 0; }
107107

108108
unsigned getNumCommandIDs(ArrayRef<unsigned> SubCommandIDsTable) const {
109-
// We embed the number of command IDs in the value of the first offset.
110-
return SubCommandIDsTable[CommandIDsOffset];
109+
// We embed the number of subcommand IDs in the value of the first offset.
110+
return SubCommandIDsTable[SubCommandIDsOffset];
111111
}
112112

113113
ArrayRef<unsigned>
114114
getCommandIDs(ArrayRef<unsigned> SubCommandIDsTable) const {
115115
return hasCommands() ? SubCommandIDsTable.slice(
116-
CommandIDsOffset + 1,
116+
SubCommandIDsOffset + 1,
117117
getNumCommandIDs(SubCommandIDsTable))
118118
: ArrayRef<unsigned>();
119119
}
@@ -159,10 +159,10 @@ class LLVM_ABI OptTable {
159159

160160
bool IgnoreCase;
161161

162-
/// The command information table.
162+
/// The subcommand information table.
163163
ArrayRef<SubCommand> SubCommands;
164164

165-
/// The command IDs table.
165+
/// The subcommand IDs table.
166166
ArrayRef<unsigned> SubCommandIDsTable;
167167

168168
bool GroupedShortOptions = false;
@@ -466,7 +466,7 @@ class GenericOptTable : public OptTable {
466466
LLVM_ABI GenericOptTable(const StringTable &StrTable,
467467
ArrayRef<StringTable::Offset> PrefixesTable,
468468
ArrayRef<Info> OptionInfos, bool IgnoreCase = false,
469-
ArrayRef<SubCommand> Commands = {},
469+
ArrayRef<SubCommand> SubCommands = {},
470470
ArrayRef<unsigned> SubCommandIDsTable = {});
471471
};
472472

llvm/lib/Option/OptTable.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,11 @@ void OptTable::internalPrintHelp(
776776
}
777777

778778
auto DoesOptionBelongToSubcommand = [&](const Info &CandidateInfo) {
779-
// llvm::outs() << CandidateInfo.
780-
ArrayRef<unsigned> CommandIDs =
779+
ArrayRef<unsigned> SubCommandIDs =
781780
CandidateInfo.getCommandIDs(SubCommandIDsTable);
782781

783-
// Options with no commands are global.
784-
if (CommandIDs.empty()) {
782+
// Options with no subcommands are global.
783+
if (SubCommandIDs.empty()) {
785784
// if Subcommand is not empty then don't print global options.
786785
return Subcommand.empty();
787786
}
@@ -790,12 +789,12 @@ void OptTable::internalPrintHelp(
790789
if (Subcommand.empty())
791790
return false;
792791

793-
// The command ID is its index in the Commands table.
794-
unsigned ActiveCommandID = ActiveSubCommand - &SubCommands[0];
792+
// The subcommand ID is its index in the SubCommands table.
793+
unsigned ActiveSubCommandID = ActiveSubCommand - &SubCommands[0];
795794

796795
// Check if the option belongs to the active subcommand.
797-
for (unsigned ID : CommandIDs) {
798-
if (ID == ActiveCommandID) {
796+
for (unsigned ID : SubCommandIDs) {
797+
if (ID == ActiveSubCommandID) {
799798
return true;
800799
}
801800
}
@@ -846,9 +845,9 @@ void OptTable::internalPrintHelp(
846845
GenericOptTable::GenericOptTable(const StringTable &StrTable,
847846
ArrayRef<StringTable::Offset> PrefixesTable,
848847
ArrayRef<Info> OptionInfos, bool IgnoreCase,
849-
ArrayRef<SubCommand> Commands,
848+
ArrayRef<SubCommand> SubCommands,
850849
ArrayRef<unsigned> SubCommandIDsTable)
851-
: OptTable(StrTable, PrefixesTable, OptionInfos, IgnoreCase, Commands,
850+
: OptTable(StrTable, PrefixesTable, OptionInfos, IgnoreCase, SubCommands,
852851
SubCommandIDsTable) {
853852

854853
std::set<StringRef> TmpPrefixesUnion;

llvm/utils/TableGen/OptionParserEmitter.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@ static void emitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
285285
if (R.getValue("SubCommands") != nullptr) {
286286
std::vector<const Record *> SubCommands =
287287
R.getValueAsListOfDefs("SubCommands");
288-
SubCommandKeyT CommandKey;
288+
SubCommandKeyT SubCommandKey;
289289
for (const auto &SubCommand : SubCommands)
290-
CommandKey.push_back(SubCommand->getName());
291-
OS << SubCommandIDs[CommandKey];
290+
SubCommandKey.push_back(SubCommand->getName());
291+
OS << SubCommandIDs[SubCommandKey];
292292
} else {
293293
// The option SubCommandIDsOffset (for default top level toolname is 0).
294294
OS << " 0";
@@ -299,10 +299,10 @@ static void emitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
299299
for (const Record &R : llvm::make_pointee_range(Opts)) {
300300
std::vector<const Record *> RSubCommands =
301301
R.getValueAsListOfDefs("SubCommands");
302-
SubCommandKeyT CommandKey;
302+
SubCommandKeyT SubCommandKey;
303303
for (const auto &SubCommand : RSubCommands)
304-
CommandKey.push_back(SubCommand->getName());
305-
SubCommandIDs.try_emplace(CommandKey, 0);
304+
SubCommandKey.push_back(SubCommand->getName());
305+
SubCommandIDs.try_emplace(SubCommandKey, 0);
306306
}
307307

308308
DenseSet<StringRef> PrefixesUnionSet;
@@ -357,34 +357,35 @@ static void emitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
357357
OS << "\n};\n";
358358
OS << "#endif // OPTTABLE_PREFIXES_TABLE_CODE\n\n";
359359

360-
// Dump command IDs.
360+
// Dump subcommand IDs.
361361
OS << "/////////";
362-
OS << "// Command IDs\n\n";
362+
OS << "// SubCommand IDs\n\n";
363363
OS << "#ifdef OPTTABLE_SUBCOMMAND_IDS_TABLE_CODE\n";
364364
OS << "static constexpr unsigned OptionSubCommandIDsTable[] = {\n";
365365
{
366-
// Ensure the first command set is always empty.
366+
// Ensure the first subcommand set is always empty.
367367
assert(!SubCommandIDs.empty() &&
368-
"We should always emit an empty set of commands");
368+
"We should always emit an empty set of subcommands");
369369
assert(SubCommandIDs.begin()->first.empty() &&
370-
"First command set should always be empty");
370+
"First subcommand set should always be empty");
371371
llvm::ListSeparator Sep(",\n");
372372
unsigned CurIndex = 0;
373-
for (auto &[Command, CommandIndex] : SubCommandIDs) {
374-
// First emit the number of command strings in this list of commands.
375-
OS << Sep << " " << Command.size() << " /* commands */";
376-
CommandIndex = CurIndex;
377-
assert((CurIndex == 0 || !Command.empty()) &&
378-
"Only first command set should be empty!");
379-
for (const auto &CommandKey : Command) {
373+
for (auto &[SubCommand, SubCommandIndex] : SubCommandIDs) {
374+
// First emit the number of subcommand strings in this list of
375+
// subcommands.
376+
OS << Sep << " " << SubCommand.size() << " /* subcommands */";
377+
SubCommandIndex = CurIndex;
378+
assert((CurIndex == 0 || !SubCommand.empty()) &&
379+
"Only first subcommand set should be empty!");
380+
for (const auto &SubCommandKey : SubCommand) {
380381
auto It = std::find_if(
381382
SubCommands.begin(), SubCommands.end(),
382-
[&](const Record *R) { return R->getName() == CommandKey; });
383-
assert(It != SubCommands.end() && "Command not found");
383+
[&](const Record *R) { return R->getName() == SubCommandKey; });
384+
assert(It != SubCommands.end() && "SubCommand not found");
384385
OS << ", " << std::distance(SubCommands.begin(), It) << " /* '"
385-
<< CommandKey << "' */";
386+
<< SubCommandKey << "' */";
386387
}
387-
CurIndex += Command.size() + 1;
388+
CurIndex += SubCommand.size() + 1;
388389
}
389390
}
390391
OS << "\n};\n";

0 commit comments

Comments
 (0)