diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2012-10-10 21:48:26 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2012-10-10 21:48:26 +0000 |
commit | 0464fd5e4ce2193e786e5adcab6b828f9366dae3 (patch) | |
tree | 72b476462a53dc48deb42a48fc89285a11e28517 /lib/Driver/OptTable.cpp | |
parent | cf9030e480f77ab349672f00ad302e216c26c92c (diff) |
[Options] make Option a value type.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165663 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/OptTable.cpp')
-rw-r--r-- | lib/Driver/OptTable.cpp | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/lib/Driver/OptTable.cpp b/lib/Driver/OptTable.cpp index e108106fa7..433c3869b5 100644 --- a/lib/Driver/OptTable.cpp +++ b/lib/Driver/OptTable.cpp @@ -11,6 +11,7 @@ #include "clang/Driver/Arg.h" #include "clang/Driver/ArgList.h" #include "clang/Driver/Option.h" +#include "clang/Driver/Options.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/ErrorHandling.h" #include <algorithm> @@ -79,22 +80,16 @@ OptSpecifier::OptSpecifier(const Option *Opt) : ID(Opt->getID()) {} OptTable::OptTable(const Info *_OptionInfos, unsigned _NumOptionInfos) : OptionInfos(_OptionInfos), NumOptionInfos(_NumOptionInfos), - Options(new Option*[NumOptionInfos]), - TheInputOption(0), TheUnknownOption(0), FirstSearchableIndex(0) + FirstSearchableIndex(0) { // Explicitly zero initialize the error to work around a bug in array // value-initialization on MinGW with gcc 4.3.5. - memset(Options, 0, sizeof(*Options) * NumOptionInfos); // Find start of normal options. for (unsigned i = 0, e = getNumOptions(); i != e; ++i) { unsigned Kind = getInfo(i + 1).Kind; if (Kind == Option::InputClass) { - assert(!TheInputOption && "Cannot have multiple input options!"); - TheInputOption = getOption(i + 1); } else if (Kind == Option::UnknownClass) { - assert(!TheUnknownOption && "Cannot have multiple input options!"); - TheUnknownOption = getOption(i + 1); } else if (Kind != Option::GroupClass) { FirstSearchableIndex = i; break; @@ -115,8 +110,8 @@ OptTable::OptTable(const Info *_OptionInfos, unsigned _NumOptionInfos) // Check that options are in order. for (unsigned i = FirstSearchableIndex+1, e = getNumOptions(); i != e; ++i) { if (!(getInfo(i) < getInfo(i + 1))) { - getOption(i)->dump(); - getOption(i + 1)->dump(); + getOption(i).dump(); + getOption(i + 1).dump(); llvm_unreachable("Options are not in order!"); } } @@ -124,17 +119,18 @@ OptTable::OptTable(const Info *_OptionInfos, unsigned _NumOptionInfos) } OptTable::~OptTable() { - for (unsigned i = 0, e = getNumOptions(); i != e; ++i) - delete Options[i]; - delete[] Options; } -bool OptTable::isOptionHelpHidden(OptSpecifier id) const { - return getInfo(id).Flags & options::HelpHidden; +const Option OptTable::getOption(OptSpecifier Opt) const { + unsigned id = Opt.getID(); + if (id == 0) + return Option(0, 0); + assert((unsigned) (id - 1) < getNumOptions() && "Invalid ID."); + return Option(&getInfo(id), this); } -Option *OptTable::CreateOption(unsigned id) const { - return new Option(&getInfo(id), this); +bool OptTable::isOptionHelpHidden(OptSpecifier id) const { + return getInfo(id).Flags & options::HelpHidden; } Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index) const { @@ -143,7 +139,7 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index) const { // Anything that doesn't start with '-' is an input, as is '-' itself. if (Str[0] != '-' || Str[1] == '\0') - return new Arg(TheInputOption, Index++, Str); + return new Arg(getOption(options::OPT_INPUT), Index++, Str); const Info *Start = OptionInfos + FirstSearchableIndex; const Info *End = OptionInfos + getNumOptions(); @@ -169,7 +165,7 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index) const { break; // See if this option matches. - if (Arg *A = getOption(Start - OptionInfos + 1)->accept(Args, Index)) + if (Arg *A = getOption(Start - OptionInfos + 1).accept(Args, Index)) return A; // Otherwise, see if this argument was missing values. @@ -177,7 +173,7 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index) const { return 0; } - return new Arg(TheUnknownOption, Index++, Str); + return new Arg(getOption(options::OPT_UNKNOWN), Index++, Str); } InputArgList *OptTable::ParseArgs(const char* const *ArgBegin, |