From: Daniel Dunbar Date: Thu, 12 Mar 2009 03:42:54 +0000 (+0000) Subject: Driver: Tweak option naming/def: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b349fccc4a6e416483b0b36b4f74e39787c62344;p=clang Driver: Tweak option naming/def: - Use OPT_ prefix for ids. - Reference groups and aliases by shortend id (on the theory that this is more readable). - Rename the special option ids to more protected names. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66767 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Options.def b/include/clang/Driver/Options.def index f50729f42e..79a257f9e6 100644 --- a/include/clang/Driver/Options.def +++ b/include/clang/Driver/Options.def @@ -27,11 +27,11 @@ // The third value is the option type, one of Group, Flag, Joined, // Separate, CommaJoined, JoinedOrSeparate, JoinedAndSeparate. -// The fourth value is the internal name of the option group, or 0 if -// the option is not part of a group. +// The fourth value is the internal name of the option group, or +// INVALID if the option is not part of a group. -// The fifth value is the internal name of an aliased option, or 0 if -// the option is not an alias. +// The fifth value is the internal name of an aliased option, or +// INVALID if the option is not an alias. // The sixth value is a string containing option flags. Valid values: // l: The option is a linker input. @@ -48,11 +48,11 @@ // U: The option is unsupported, and the driver will reject command // lines that use it. -/// The seventh value is an arbitrary integer parameter; currently -/// this is only used for specifying the number of arguments for -/// Separate options. +// The seventh value is an arbitrary integer parameter; currently +// this is only used for specifying the number of arguments for +// Separate options. -OPTION("-arch", ArchOpt, Separate, 0, 0, "", 0) -OPTION("-pass-exit-codes", PassExitCodesFlag, Flag, 0, 0, "", 0) -OPTION("-print-file-name=", PrintFileNameOpt, Joined, 0, 0, "", 0) -OPTION("-Wp,", WpOpt, CommaJoined, 0, 0, "", 0) +OPTION("-arch", ArchOpt, Separate, INVALID, INVALID, "", 0) +OPTION("-pass-exit-codes", PassExitCodesFlag, Flag, INVALID, INVALID, "", 0) +OPTION("-print-file-name=", PrintFileNameOpt, Joined, INVALID, INVALID, "", 0) +OPTION("-Wp,", WpOpt, CommaJoined, INVALID, INVALID, "", 0) diff --git a/include/clang/Driver/Options.h b/include/clang/Driver/Options.h index f5551e644a..9690d3afb3 100644 --- a/include/clang/Driver/Options.h +++ b/include/clang/Driver/Options.h @@ -14,10 +14,10 @@ namespace clang { namespace driver { namespace options { enum ID { - NotOption = 0, // This is not an option ID. - InputOpt, // Reserved ID for input option. - UnknownOpt, // Reserved ID for unknown option. -#define OPTION(NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM) ID, + OPT_INVALID = 0, // This is not an option ID. + OPT_INPUT, // Reserved ID for input option. + OPT_UNKNOWN, // Reserved ID for unknown option. +#define OPTION(NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM) OPT_##ID, #include "clang/Driver/Options.def" LastOption #undef OPTION diff --git a/lib/Driver/OptTable.cpp b/lib/Driver/OptTable.cpp index db910e1a31..5caaace3ad 100644 --- a/lib/Driver/OptTable.cpp +++ b/lib/Driver/OptTable.cpp @@ -30,12 +30,12 @@ struct Info { static Info OptionInfos[] = { // The InputOption info - { "", "", Option::InputClass, 0, 0, 0 }, + { "", "", Option::InputClass, OPT_INVALID, OPT_INVALID, 0 }, // The UnknownOption info - { "", "", Option::UnknownClass, 0, 0, 0 }, + { "", "", Option::UnknownClass, OPT_INVALID, OPT_INVALID, 0 }, -#define OPTION(NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM) \ - { NAME, FLAGS, Option::KIND##Class, GROUP, ALIAS, PARAM }, +#define OPTION(NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM) \ + { NAME, FLAGS, Option::KIND##Class, OPT_##GROUP, OPT_##ALIAS, PARAM }, #include "clang/Driver/Options.def" }; static const unsigned numOptions = sizeof(OptionInfos) / sizeof(OptionInfos[0]); @@ -63,7 +63,7 @@ const char *OptTable::getOptionName(options::ID id) const { } const Option *OptTable::getOption(options::ID id) const { - if (id == NotOption) + if (id == OPT_INVALID) return 0; assert((unsigned) (id - 1) < numOptions && "Invalid ID."); @@ -125,9 +125,9 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index, // Anything that doesn't start with '-' is an input. if (Str[0] != '-') - return new PositionalArg(getOption(InputOpt), Index++); + return new PositionalArg(getOption(OPT_INPUT), Index++); - for (unsigned j = UnknownOpt + 1; j < LastOption; ++j) { + for (unsigned j = OPT_UNKNOWN + 1; j < LastOption; ++j) { const char *OptName = getOptionName((options::ID) j); // Arguments are only accepted by options which prefix them. @@ -136,6 +136,6 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index, return A; } - return new PositionalArg(getOption(UnknownOpt), Index++); + return new PositionalArg(getOption(OPT_UNKNOWN), Index++); } diff --git a/lib/Driver/Option.cpp b/lib/Driver/Option.cpp index 7a74d34a86..7a53009455 100644 --- a/lib/Driver/Option.cpp +++ b/lib/Driver/Option.cpp @@ -113,7 +113,7 @@ Arg *OptionGroup::accept(const ArgList &Args, unsigned &Index) const { } InputOption::InputOption() - : Option(Option::InputClass, options::InputOpt, "", 0, 0) { + : Option(Option::InputClass, options::OPT_INPUT, "", 0, 0) { } Arg *InputOption::accept(const ArgList &Args, unsigned &Index) const { @@ -122,7 +122,7 @@ Arg *InputOption::accept(const ArgList &Args, unsigned &Index) const { } UnknownOption::UnknownOption() - : Option(Option::UnknownClass, options::UnknownOpt, "", 0, 0) { + : Option(Option::UnknownClass, options::OPT_UNKNOWN, "", 0, 0) { } Arg *UnknownOption::accept(const ArgList &Args, unsigned &Index) const {