Driver: Add ArgList support for synthesizing arguments.

llvm-svn: 66805
This commit is contained in:
Daniel Dunbar 2009-03-12 18:20:18 +00:00
parent 2a332aa866
commit 7c8d653a2c
2 changed files with 68 additions and 0 deletions

View File

@ -15,6 +15,8 @@
#include "clang/Driver/Util.h" #include "clang/Driver/Util.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include <list>
namespace clang { namespace clang {
namespace driver { namespace driver {
class Arg; class Arg;
@ -38,6 +40,9 @@ namespace driver {
/// The full list of arguments. /// The full list of arguments.
arglist_type Args; arglist_type Args;
/// Strings for synthesized arguments.
std::list<std::string> SynthesizedStrings;
public: public:
ArgList(const char **ArgBegin, const char **ArgEnd); ArgList(const char **ArgBegin, const char **ArgEnd);
ArgList(const ArgList &); ArgList(const ArgList &);
@ -62,6 +67,33 @@ namespace driver {
/// getLastArg - Return the last argument matching \arg Id, or null. /// getLastArg - Return the last argument matching \arg Id, or null.
Arg *getLastArg(options::ID Id) const; 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 driver
} // end namespace clang } // end namespace clang

View File

@ -40,3 +40,39 @@ Arg *ArgList::getLastArg(options::ID Id) const {
return 0; 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()));
}