jansvoboda11 updated this revision to Diff 547298. jansvoboda11 added a comment.
Improve `Option::getPrefixedName()` instead of introducing new `Option::getSpelling()`. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D157029/new/ https://reviews.llvm.org/D157029 Files: clang-tools-extra/clangd/CompileCommands.cpp clang/lib/Driver/Driver.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Tooling/Tooling.cpp llvm/include/llvm/Option/OptTable.h llvm/include/llvm/Option/Option.h llvm/lib/Option/OptTable.cpp llvm/utils/TableGen/OptParserEmitter.cpp
Index: llvm/utils/TableGen/OptParserEmitter.cpp =================================================================== --- llvm/utils/TableGen/OptParserEmitter.cpp +++ llvm/utils/TableGen/OptParserEmitter.cpp @@ -105,8 +105,6 @@ } void emit(raw_ostream &OS) const { - write_cstring(OS, StringRef(getOptionSpelling(R))); - OS << ", "; OS << ShouldParse; OS << ", "; OS << ShouldAlwaysEmit; @@ -306,6 +304,9 @@ // The option string. OS << ", \"" << R.getValueAsString("Name") << '"'; + // The option spelling. + OS << ", \"" << R.getValueAsString("Name") << '"'; + // The option identifier name. OS << ", " << getOptionName(R); @@ -349,6 +350,11 @@ // The option string. emitNameUsingSpelling(OS, R); + // The option spelling. + OS << ", llvm::StringLiteral("; + write_cstring(OS, getOptionSpelling(R)); + OS << ")"; + // The option identifier name. OS << ", " << getOptionName(R); Index: llvm/lib/Option/OptTable.cpp =================================================================== --- llvm/lib/Option/OptTable.cpp +++ llvm/lib/Option/OptTable.cpp @@ -529,7 +529,7 @@ static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id) { const Option O = Opts.getOption(Id); - std::string Name = O.getPrefixedName(); + std::string Name = O.getPrefixedName().str(); // Add metavar, if used. switch (O.getKind()) { Index: llvm/include/llvm/Option/Option.h =================================================================== --- llvm/include/llvm/Option/Option.h +++ llvm/include/llvm/Option/Option.h @@ -130,10 +130,9 @@ } /// Get the name of this option with the default prefix. - std::string getPrefixedName() const { - std::string Ret(getPrefix()); - Ret += getName(); - return Ret; + StringLiteral getPrefixedName() const { + assert(Info && "Must have a valid info!"); + return Info->PrefixedName; } /// Get the help text for this option. Index: llvm/include/llvm/Option/OptTable.h =================================================================== --- llvm/include/llvm/Option/OptTable.h +++ llvm/include/llvm/Option/OptTable.h @@ -44,7 +44,9 @@ /// A null terminated array of prefix strings to apply to name while /// matching. ArrayRef<StringLiteral> Prefixes; + // TODO: Compute this from PrefixedName. StringRef Name; + StringLiteral PrefixedName; const char *HelpText; const char *MetaVar; unsigned ID; @@ -298,31 +300,31 @@ } // end namespace llvm -#define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(ID_PREFIX, PREFIX, NAME, ID, KIND, \ - GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ - HELPTEXT, METAVAR, VALUES) \ +#define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \ + ID_PREFIX, PREFIX, NAME, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \ + FLAGS, PARAM, HELPTEXT, METAVAR, VALUES) \ ID_PREFIX##ID -#define LLVM_MAKE_OPT_ID(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \ - FLAGS, PARAM, HELPTEXT, METAVAR, VALUES) \ - LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(OPT_, PREFIX, NAME, ID, KIND, GROUP, ALIAS, \ - ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR, \ - VALUE) +#define LLVM_MAKE_OPT_ID(PREFIX, NAME, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, \ + ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR, VALUES) \ + LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(OPT_, PREFIX, NAME, PREFIXED_NAME, ID, KIND, \ + GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR, VALUE) #define LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \ - ID_PREFIX, PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ - HELPTEXT, METAVAR, VALUES) \ + ID_PREFIX, PREFIX, NAME, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \ + FLAGS, PARAM, HELPTEXT, METAVAR, VALUES) \ llvm::opt::OptTable::Info { \ - PREFIX, NAME, HELPTEXT, METAVAR, ID_PREFIX##ID, \ + PREFIX, NAME, PREFIXED_NAME, HELPTEXT, METAVAR, ID_PREFIX##ID, \ llvm::opt::Option::KIND##Class, PARAM, FLAGS, ID_PREFIX##GROUP, \ ID_PREFIX##ALIAS, ALIASARGS, VALUES \ } -#define LLVM_CONSTRUCT_OPT_INFO(PREFIX, NAME, ID, KIND, GROUP, ALIAS, \ - ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR, \ - VALUES) \ - LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX(OPT_, PREFIX, NAME, ID, KIND, GROUP, \ - ALIAS, ALIASARGS, FLAGS, PARAM, \ - HELPTEXT, METAVAR, VALUES) +#define LLVM_CONSTRUCT_OPT_INFO(PREFIX, NAME, PREFIXED_NAME, ID, KIND, GROUP, \ + ALIAS, ALIASARGS, FLAGS, PARAM, HELPTEXT, \ + METAVAR, VALUES) \ + LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \ + OPT_, PREFIX, NAME, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \ + FLAGS, PARAM, HELPTEXT, METAVAR, VALUES) #endif // LLVM_OPTION_OPTTABLE_H Index: clang/lib/Tooling/Tooling.cpp =================================================================== --- clang/lib/Tooling/Tooling.cpp +++ clang/lib/Tooling/Tooling.cpp @@ -269,14 +269,14 @@ return; const auto &Table = driver::getDriverOptTable(); // --target=X - const std::string TargetOPT = + StringRef TargetOPT = Table.getOption(driver::options::OPT_target).getPrefixedName(); // -target X - const std::string TargetOPTLegacy = + StringRef TargetOPTLegacy = Table.getOption(driver::options::OPT_target_legacy_spelling) .getPrefixedName(); // --driver-mode=X - const std::string DriverModeOPT = + StringRef DriverModeOPT = Table.getOption(driver::options::OPT_driver_mode).getPrefixedName(); auto TargetMode = driver::ToolChain::getTargetAndModeFromProgramName(InvokedAs); @@ -296,7 +296,7 @@ } if (ShouldAddTarget) { CommandLine.insert(++CommandLine.begin(), - TargetOPT + TargetMode.TargetPrefix); + (TargetOPT + TargetMode.TargetPrefix).str()); } } Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -422,10 +422,10 @@ } #define PARSE_OPTION_WITH_MARSHALLING( \ - ARGS, DIAGS, PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \ - PARAM, HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, \ - KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, \ - DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \ + ARGS, DIAGS, PREFIX_TYPE, NAME, SPELLING, ID, KIND, GROUP, ALIAS, \ + ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, \ + ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, \ + NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \ if ((FLAGS)&options::CC1Option) { \ KEYPATH = MERGER(KEYPATH, DEFAULT_VALUE); \ if (IMPLIED_CHECK) \ @@ -439,8 +439,8 @@ // Capture the extracted value as a lambda argument to avoid potential issues // with lifetime extension of the reference. #define GENERATE_OPTION_WITH_MARSHALLING( \ - CONSUMER, PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \ - PARAM, HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, \ + CONSUMER, PREFIX_TYPE, NAME, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS, \ + FLAGS, PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, ALWAYS_EMIT, \ KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, \ DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \ if ((FLAGS)&options::CC1Option) { \ Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -238,7 +238,7 @@ } void Driver::setDriverMode(StringRef Value) { - static const std::string OptName = + static StringRef OptName = getOpts().getOption(options::OPT_driver_mode).getPrefixedName(); if (auto M = llvm::StringSwitch<std::optional<DriverMode>>(Value) .Case("gcc", GCCMode) @@ -6554,7 +6554,7 @@ llvm::StringRef clang::driver::getDriverMode(StringRef ProgName, ArrayRef<const char *> Args) { - static const std::string OptName = + static StringRef OptName = getDriverOptTable().getOption(options::OPT_driver_mode).getPrefixedName(); llvm::StringRef Opt; for (StringRef Arg : Args) { Index: clang-tools-extra/clangd/CompileCommands.cpp =================================================================== --- clang-tools-extra/clangd/CompileCommands.cpp +++ clang-tools-extra/clangd/CompileCommands.cpp @@ -493,8 +493,8 @@ static constexpr llvm::StringLiteral NAME##_init[] = VALUE; \ static constexpr llvm::ArrayRef<llvm::StringLiteral> NAME( \ NAME##_init, std::size(NAME##_init) - 1); -#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ - HELP, METAVAR, VALUES) \ +#define OPTION(PREFIX, NAME, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \ + FLAGS, PARAM, HELP, METAVAR, VALUES) \ Prefixes[DriverID::OPT_##ID] = PREFIX; #include "clang/Driver/Options.inc" #undef OPTION @@ -505,8 +505,8 @@ DriverID AliasID; const void *AliasArgs; } AliasTable[] = { -#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ - HELP, METAVAR, VALUES) \ +#define OPTION(PREFIX, NAME, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \ + FLAGS, PARAM, HELP, METAVAR, VALUES) \ {DriverID::OPT_##ID, DriverID::OPT_##ALIAS, ALIASARGS}, #include "clang/Driver/Options.inc" #undef OPTION
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits