[cfe-commits] r66805 - in /cfe/trunk: include/clang/Driver/ArgList.h lib/Driver/ArgList.cpp
Daniel Dunbar
daniel at zuster.org
Thu Mar 12 11:20:18 PDT 2009
Author: ddunbar
Date: Thu Mar 12 13:20:18 2009
New Revision: 66805
URL: http://llvm.org/viewvc/llvm-project?rev=66805&view=rev
Log:
Driver: Add ArgList support for synthesizing arguments.
Modified:
cfe/trunk/include/clang/Driver/ArgList.h
cfe/trunk/lib/Driver/ArgList.cpp
Modified: cfe/trunk/include/clang/Driver/ArgList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ArgList.h?rev=66805&r1=66804&r2=66805&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/ArgList.h (original)
+++ cfe/trunk/include/clang/Driver/ArgList.h Thu Mar 12 13:20:18 2009
@@ -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 @@
/// 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 @@
/// 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
Modified: cfe/trunk/lib/Driver/ArgList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ArgList.cpp?rev=66805&r1=66804&r2=66805&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ArgList.cpp (original)
+++ cfe/trunk/lib/Driver/ArgList.cpp Thu Mar 12 13:20:18 2009
@@ -40,3 +40,39 @@
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()));
+}
More information about the cfe-commits
mailing list