From: Daniel Dunbar Date: Thu, 12 Mar 2009 18:20:18 +0000 (+0000) Subject: Driver: Add ArgList support for synthesizing arguments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bca58cb5100a4fdff63165af6a1742f5160ec73b;p=clang Driver: Add ArgList support for synthesizing arguments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66805 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/ArgList.h b/include/clang/Driver/ArgList.h index 2e47ee4c39..bd2586ecb6 100644 --- a/include/clang/Driver/ArgList.h +++ b/include/clang/Driver/ArgList.h @@ -15,6 +15,8 @@ #include "clang/Driver/Util.h" #include "llvm/ADT/SmallVector.h" +#include + namespace clang { namespace driver { class Arg; @@ -38,6 +40,9 @@ namespace driver { /// The full list of arguments. arglist_type Args; + /// Strings for synthesized arguments. + std::list SynthesizedStrings; + public: ArgList(const char **ArgBegin, const char **ArgEnd); ArgList(const ArgList &); @@ -62,6 +67,33 @@ namespace driver { /// getLastArg - Return the last argument matching \arg Id, or null. Arg *getLastArg(options::ID Id) const; + + /// @name Arg Synthesis + /// @{ + + private: + /// MakeIndex - Get an index for the given string(s). + unsigned MakeIndex(const char *String0); + unsigned MakeIndex(const char *String0, const char *String1); + + public: + /// MakeFlagArg - Construct a new FlagArg for the given option + /// \arg Id. + Arg *MakeFlagArg(const Option *Opt); + + /// MakePositionalArg - Construct a new Positional arg for the + /// given option \arg Id, with the provided \arg Value. + Arg *MakePositionalArg(const Option *Opt, const char *Value); + + /// MakeSeparateArg - Construct a new Positional arg for the + /// given option \arg Id, with the provided \arg Value. + Arg *MakeSeparateArg(const Option *Opt, const char *Value); + + /// MakeJoinedArg - Construct a new Positional arg for the + /// given option \arg Id, with the provided \arg Value. + Arg *MakeJoinedArg(const Option *Opt, const char *Value); + + /// @} }; } // end namespace driver } // end namespace clang diff --git a/lib/Driver/ArgList.cpp b/lib/Driver/ArgList.cpp index e29977fb0e..87847c0c13 100644 --- a/lib/Driver/ArgList.cpp +++ b/lib/Driver/ArgList.cpp @@ -40,3 +40,39 @@ Arg *ArgList::getLastArg(options::ID Id) const { return 0; } + +unsigned ArgList::MakeIndex(const char *String0) { + 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) { + unsigned Index0 = MakeIndex(String0); + unsigned Index1 = MakeIndex(String1); + assert(Index0 == Index1 && "Unexpected non-consecutive indices!"); + (void) Index1; + return Index0; +} + +Arg *ArgList::MakeFlagArg(const Option *Opt) { + return new FlagArg(Opt, MakeIndex(Opt->getName())); +} + +Arg *ArgList::MakePositionalArg(const Option *Opt, const char *Value) { + return new PositionalArg(Opt, MakeIndex(Value)); +} + +Arg *ArgList::MakeSeparateArg(const Option *Opt, const char *Value) { + return new SeparateArg(Opt, MakeIndex(Opt->getName(), Value), 1); +} + +Arg *ArgList::MakeJoinedArg(const Option *Opt, const char *Value) { + std::string Joined(Opt->getName()); + Joined += Value; + return new JoinedArg(Opt, MakeIndex(Joined.c_str())); +}