[TableGen] NFC: Switch to range-based for loops in OptParserEmitter

This simplifies the code a bit. No functionality change.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93526
This commit is contained in:
Jan Svoboda 2020-12-18 10:52:53 +01:00
parent d6abd7317a
commit 06b83fd6c7
1 changed files with 10 additions and 19 deletions

View File

@ -219,8 +219,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
PrefixesT Prefixes; PrefixesT Prefixes;
Prefixes.insert(std::make_pair(PrefixKeyT(), "prefix_0")); Prefixes.insert(std::make_pair(PrefixKeyT(), "prefix_0"));
unsigned CurPrefix = 0; unsigned CurPrefix = 0;
for (unsigned i = 0, e = Opts.size(); i != e; ++i) { for (const Record &R : llvm::make_pointee_range(Opts)) {
const Record &R = *Opts[i];
std::vector<StringRef> prf = R.getValueAsListOfStrings("Prefixes"); std::vector<StringRef> prf = R.getValueAsListOfStrings("Prefixes");
PrefixKeyT prfkey(prf.begin(), prf.end()); PrefixKeyT prfkey(prf.begin(), prf.end());
unsigned NewPrefix = CurPrefix + 1; unsigned NewPrefix = CurPrefix + 1;
@ -235,19 +234,16 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
OS << "// Prefixes\n\n"; OS << "// Prefixes\n\n";
OS << "#ifdef PREFIX\n"; OS << "#ifdef PREFIX\n";
OS << "#define COMMA ,\n"; OS << "#define COMMA ,\n";
for (PrefixesT::const_iterator I = Prefixes.begin(), E = Prefixes.end(); for (const auto &Prefix : Prefixes) {
I != E; ++I) {
OS << "PREFIX("; OS << "PREFIX(";
// Prefix name. // Prefix name.
OS << I->second; OS << Prefix.second;
// Prefix values. // Prefix values.
OS << ", {"; OS << ", {";
for (PrefixKeyT::const_iterator PI = I->first.begin(), for (StringRef PrefixKey : Prefix.first)
PE = I->first.end(); PI != PE; ++PI) { OS << "\"" << PrefixKey << "\" COMMA ";
OS << "\"" << *PI << "\" COMMA ";
}
OS << "nullptr})\n"; OS << "nullptr})\n";
} }
OS << "#undef COMMA\n"; OS << "#undef COMMA\n";
@ -256,9 +252,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
OS << "/////////\n"; OS << "/////////\n";
OS << "// Groups\n\n"; OS << "// Groups\n\n";
OS << "#ifdef OPTION\n"; OS << "#ifdef OPTION\n";
for (unsigned i = 0, e = Groups.size(); i != e; ++i) { for (const Record &R : llvm::make_pointee_range(Groups)) {
const Record &R = *Groups[i];
// Start a single option entry. // Start a single option entry.
OS << "OPTION("; OS << "OPTION(";
@ -343,8 +337,8 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
OS << "nullptr"; OS << "nullptr";
} else { } else {
OS << "\""; OS << "\"";
for (size_t i = 0, e = AliasArgs.size(); i != e; ++i) for (StringRef AliasArg : AliasArgs)
OS << AliasArgs[i] << "\\0"; OS << AliasArg << "\\0";
OS << "\""; OS << "\"";
} }
@ -394,9 +388,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
}; };
std::vector<const Record *> OptsWithMarshalling; std::vector<const Record *> OptsWithMarshalling;
for (unsigned I = 0, E = Opts.size(); I != E; ++I) { for (const Record &R : llvm::make_pointee_range(Opts)) {
const Record &R = *Opts[I];
// Start a single option entry. // Start a single option entry.
OS << "OPTION("; OS << "OPTION(";
WriteOptRecordFields(OS, R); WriteOptRecordFields(OS, R);
@ -462,8 +454,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
OS << "#ifdef OPTTABLE_ARG_INIT\n"; OS << "#ifdef OPTTABLE_ARG_INIT\n";
OS << "//////////\n"; OS << "//////////\n";
OS << "// Option Values\n\n"; OS << "// Option Values\n\n";
for (unsigned I = 0, E = Opts.size(); I != E; ++I) { for (const Record &R : llvm::make_pointee_range(Opts)) {
const Record &R = *Opts[I];
if (isa<UnsetInit>(R.getValueInit("ValuesCode"))) if (isa<UnsetInit>(R.getValueInit("ValuesCode")))
continue; continue;
OS << "{\n"; OS << "{\n";