aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-12 18:20:18 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-12 18:20:18 +0000
commitbca58cb5100a4fdff63165af6a1742f5160ec73b (patch)
tree5b8eb62395eab1ccf2339a99420a245d26f00056
parent76e10ef2d19c0233c6efbf288600b6fba4569fc4 (diff)
Driver: Add ArgList support for synthesizing arguments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66805 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Driver/ArgList.h32
-rw-r--r--lib/Driver/ArgList.cpp36
2 files changed, 68 insertions, 0 deletions
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 <list>
+
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<std::string> 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()));
+}