diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-03-25 04:13:45 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-03-25 04:13:45 +0000 |
commit | f3cad36e59a41b5767fe662b5ac8911ee174b801 (patch) | |
tree | 63dc6f58c11d1e55925b68a3bf76eeb5c047e70d /lib/Driver/ArgList.cpp | |
parent | 515455ac32e2accac51c33ceaa7e2dd7c36ef3f2 (diff) |
Driver: Prep for tool chain specific argument translation.
- Lift ArgList to a base class for InputArgList and DerivedArgList.
- This is not a great decomposition, but it does embed the
translation into the type system, and keep things efficient for
tool chains that don't want to do any translation.
- No intended functionality change.
Eventually I hope to get rid of tool chain specific translation and
have each tool do the right thing, but for now this is the easiest way
to match gcc precisely (which is good for testing).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67676 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/ArgList.cpp')
-rw-r--r-- | lib/Driver/ArgList.cpp | 128 |
1 files changed, 78 insertions, 50 deletions
diff --git a/lib/Driver/ArgList.cpp b/lib/Driver/ArgList.cpp index d74e3bd59d..bd3aab351d 100644 --- a/lib/Driver/ArgList.cpp +++ b/lib/Driver/ArgList.cpp @@ -13,22 +13,13 @@ using namespace clang::driver; -ArgList::ArgList(const char **ArgBegin, const char **ArgEnd) - : NumInputArgStrings(ArgEnd - ArgBegin) -{ - ArgStrings.append(ArgBegin, ArgEnd); +ArgList::ArgList(arglist_type &_Args) : Args(_Args) { } ArgList::~ArgList() { - for (iterator it = begin(), ie = end(); it != ie; ++it) - delete *it; } void ArgList::append(Arg *A) { - if (A->getOption().isUnsupported()) { - assert(0 && "FIXME: unsupported unsupported."); - } - Args.push_back(A); } @@ -68,46 +59,6 @@ bool ArgList::hasFlag(options::ID Pos, options::ID Neg, bool Default) const { return Default; } -unsigned ArgList::MakeIndex(const char *String0) const { - unsigned Index = ArgStrings.size(); - - // Tuck away so we have a reliable const char *. - SynthesizedStrings.push_back(String0); - ArgStrings.push_back(SynthesizedStrings.back().c_str()); - - return Index; -} - -unsigned ArgList::MakeIndex(const char *String0, const char *String1) const { - unsigned Index0 = MakeIndex(String0); - unsigned Index1 = MakeIndex(String1); - assert(Index0 + 1 == Index1 && "Unexpected non-consecutive indices!"); - (void) Index1; - return Index0; -} - -const char *ArgList::MakeArgString(const char *Str) const { - return getArgString(MakeIndex(Str)); -} - -Arg *ArgList::MakeFlagArg(const Option *Opt) const { - return new FlagArg(Opt, MakeIndex(Opt->getName())); -} - -Arg *ArgList::MakePositionalArg(const Option *Opt, const char *Value) const { - return new PositionalArg(Opt, MakeIndex(Value)); -} - -Arg *ArgList::MakeSeparateArg(const Option *Opt, const char *Value) const { - return new SeparateArg(Opt, MakeIndex(Opt->getName(), Value), 1); -} - -Arg *ArgList::MakeJoinedArg(const Option *Opt, const char *Value) const { - std::string Joined(Opt->getName()); - Joined += Value; - return new JoinedArg(Opt, MakeIndex(Joined.c_str())); -} - void ArgList::AddLastArg(ArgStringList &Output, options::ID Id) const { if (Arg *A = getLastArg(Id)) { A->claim(); @@ -175,3 +126,80 @@ void ArgList::AddAllArgValues(ArgStringList &Output, options::ID Id0, } } } + +// + +InputArgList::InputArgList(const char **ArgBegin, const char **ArgEnd) + : ArgList(ActualArgs), NumInputArgStrings(ArgEnd - ArgBegin) +{ + ArgStrings.append(ArgBegin, ArgEnd); +} + +InputArgList::~InputArgList() { + // An InputArgList always owns its arguments. + for (iterator it = begin(), ie = end(); it != ie; ++it) + delete *it; +} + +unsigned InputArgList::MakeIndex(const char *String0) const { + unsigned Index = ArgStrings.size(); + + // Tuck away so we have a reliable const char *. + SynthesizedStrings.push_back(String0); + ArgStrings.push_back(SynthesizedStrings.back().c_str()); + + return Index; +} + +unsigned InputArgList::MakeIndex(const char *String0, + const char *String1) const { + unsigned Index0 = MakeIndex(String0); + unsigned Index1 = MakeIndex(String1); + assert(Index0 + 1 == Index1 && "Unexpected non-consecutive indices!"); + (void) Index1; + return Index0; +} + +const char *InputArgList::MakeArgString(const char *Str) const { + return getArgString(MakeIndex(Str)); +} + +// + +DerivedArgList::DerivedArgList(InputArgList &_BaseArgs, bool _OnlyProxy) + : ArgList(_OnlyProxy ? _BaseArgs.getArgs() : ActualArgs), + BaseArgs(_BaseArgs), OnlyProxy(_OnlyProxy) +{ +} + +DerivedArgList::~DerivedArgList() { + // We only own the arguments we explicitly synthesized. + for (iterator it = SynthesizedArgs.begin(), ie = SynthesizedArgs.end(); + it != ie; ++it) + delete *it; +} + +const char *DerivedArgList::MakeArgString(const char *Str) const { + return BaseArgs.MakeArgString(Str); +} + +Arg *DerivedArgList::MakeFlagArg(const Option *Opt) const { + return new FlagArg(Opt, BaseArgs.MakeIndex(Opt->getName())); +} + +Arg *DerivedArgList::MakePositionalArg(const Option *Opt, + const char *Value) const { + return new PositionalArg(Opt, BaseArgs.MakeIndex(Value)); +} + +Arg *DerivedArgList::MakeSeparateArg(const Option *Opt, + const char *Value) const { + return new SeparateArg(Opt, BaseArgs.MakeIndex(Opt->getName(), Value), 1); +} + +Arg *DerivedArgList::MakeJoinedArg(const Option *Opt, + const char *Value) const { + std::string Joined(Opt->getName()); + Joined += Value; + return new JoinedArg(Opt, BaseArgs.MakeIndex(Joined.c_str())); +} |