diff options
Diffstat (limited to 'include/clang/Driver/Arg.h')
-rw-r--r-- | include/clang/Driver/Arg.h | 181 |
1 files changed, 37 insertions, 144 deletions
diff --git a/include/clang/Driver/Arg.h b/include/clang/Driver/Arg.h index ebf40d4..a52789e 100644 --- a/include/clang/Driver/Arg.h +++ b/include/clang/Driver/Arg.h @@ -10,14 +10,9 @@ #ifndef CLANG_DRIVER_ARG_H_ #define CLANG_DRIVER_ARG_H_ -#include "llvm/Support/Casting.h" -using llvm::isa; -using llvm::cast; -using llvm::cast_or_null; -using llvm::dyn_cast; -using llvm::dyn_cast_or_null; - #include "Util.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include <vector> #include <string> @@ -34,19 +29,10 @@ namespace driver { /// ArgList to provide efficient iteration over all instances of a /// particular option. class Arg { - public: - enum ArgClass { - FlagClass = 0, - PositionalClass, - JoinedClass, - SeparateClass, - CommaJoinedClass, - JoinedAndSeparateClass - }; + Arg(const Arg &); // DO NOT IMPLEMENT + void operator=(const Arg &); // DO NOT IMPLEMENT private: - ArgClass Kind; - /// The option this argument is an instance of. const Option *Opt; @@ -58,20 +44,24 @@ namespace driver { /// ArgList. unsigned Index; - /// Flag indicating whether this argument was used to effect - /// compilation; used for generating "argument unused" - /// diagnostics. - mutable bool Claimed; + /// Was this argument used to effect compilation; used for generating + /// "argument unused" diagnostics. + mutable unsigned Claimed : 1; + + /// Does this argument own its values. + mutable unsigned OwnsValues : 1; - protected: - Arg(ArgClass Kind, const Option *Opt, unsigned Index, - const Arg *BaseArg = 0); + /// The argument values, as C strings. + llvm::SmallVector<const char *, 2> Values; public: - Arg(const Arg &); - virtual ~Arg(); + Arg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0); + Arg(const Option *Opt, unsigned Index, + const char *Value0, const Arg *BaseArg = 0); + Arg(const Option *Opt, unsigned Index, + const char *Value0, const char *Value1, const Arg *BaseArg = 0); + ~Arg(); - ArgClass getKind() const { return Kind; } const Option &getOption() const { return *Opt; } unsigned getIndex() const { return Index; } @@ -85,19 +75,32 @@ namespace driver { BaseArg = _BaseArg; } + bool getOwnsValues() const { return OwnsValues; } + void setOwnsValues(bool Value) const { OwnsValues = Value; } + bool isClaimed() const { return getBaseArg().Claimed; } /// claim - Set the Arg claimed bit. - - // FIXME: We need to deal with derived arguments and set the bit - // in the original argument; not the derived one. void claim() const { getBaseArg().Claimed = true; } - virtual unsigned getNumValues() const = 0; - virtual const char *getValue(const ArgList &Args, unsigned N=0) const = 0; + unsigned getNumValues() const { return Values.size(); } + const char *getValue(const ArgList &Args, unsigned N=0) const { + return Values[N]; + } + + llvm::SmallVectorImpl<const char*> &getValues() { + return Values; + } + + bool containsValue(llvm::StringRef Value) const { + for (unsigned i = 0, e = getNumValues(); i != e; ++i) + if (Values[i] == Value) + return true; + return false; + } /// render - Append the argument onto the given array as strings. - virtual void render(const ArgList &Args, ArgStringList &Output) const = 0; + void render(const ArgList &Args, ArgStringList &Output) const; /// renderAsInput - Append the argument, render as an input, onto /// the given array as strings. The distinction is that some @@ -114,116 +117,6 @@ namespace driver { std::string getAsString(const ArgList &Args) const; }; - /// FlagArg - An argument with no value. - class FlagArg : public Arg { - public: - FlagArg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0); - - virtual void render(const ArgList &Args, ArgStringList &Output) const; - - virtual unsigned getNumValues() const { return 0; } - virtual const char *getValue(const ArgList &Args, unsigned N=0) const; - - static bool classof(const Arg *A) { - return A->getKind() == Arg::FlagClass; - } - static bool classof(const FlagArg *) { return true; } - }; - - /// PositionalArg - A simple positional argument. - class PositionalArg : public Arg { - public: - PositionalArg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0); - - virtual void render(const ArgList &Args, ArgStringList &Output) const; - - virtual unsigned getNumValues() const { return 1; } - virtual const char *getValue(const ArgList &Args, unsigned N=0) const; - - static bool classof(const Arg *A) { - return A->getKind() == Arg::PositionalClass; - } - static bool classof(const PositionalArg *) { return true; } - }; - - /// JoinedArg - A single value argument where the value is joined - /// (suffixed) to the option. - class JoinedArg : public Arg { - public: - JoinedArg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0); - - virtual void render(const ArgList &Args, ArgStringList &Output) const; - - virtual unsigned getNumValues() const { return 1; } - virtual const char *getValue(const ArgList &Args, unsigned N=0) const; - - static bool classof(const Arg *A) { - return A->getKind() == Arg::JoinedClass; - } - static bool classof(const JoinedArg *) { return true; } - }; - - /// SeparateArg - An argument where one or more values follow the - /// option specifier immediately in the argument vector. - class SeparateArg : public Arg { - unsigned NumValues; - - public: - SeparateArg(const Option *Opt, unsigned Index, unsigned NumValues, - const Arg *BaseArg = 0); - - virtual void render(const ArgList &Args, ArgStringList &Output) const; - - virtual unsigned getNumValues() const { return NumValues; } - virtual const char *getValue(const ArgList &Args, unsigned N=0) const; - - static bool classof(const Arg *A) { - return A->getKind() == Arg::SeparateClass; - } - static bool classof(const SeparateArg *) { return true; } - }; - - /// CommaJoinedArg - An argument with multiple values joined by - /// commas and joined (suffixed) to the option specifier. - /// - /// The key point of this arg is that it renders its values into - /// separate arguments, which allows it to be used as a generic - /// mechanism for passing arguments through to tools. - class CommaJoinedArg : public Arg { - std::vector<std::string> Values; - - public: - CommaJoinedArg(const Option *Opt, unsigned Index, const char *Str, - const Arg *BaseArg = 0); - - virtual void render(const ArgList &Args, ArgStringList &Output) const; - - virtual unsigned getNumValues() const { return Values.size(); } - virtual const char *getValue(const ArgList &Args, unsigned N=0) const; - - static bool classof(const Arg *A) { - return A->getKind() == Arg::CommaJoinedClass; - } - static bool classof(const CommaJoinedArg *) { return true; } - }; - - /// JoinedAndSeparateArg - An argument with both joined and separate - /// values. - class JoinedAndSeparateArg : public Arg { - public: - JoinedAndSeparateArg(const Option *Opt, unsigned Index, - const Arg *BaseArg = 0); - - virtual void render(const ArgList &Args, ArgStringList &Output) const; - - virtual unsigned getNumValues() const { return 2; } - virtual const char *getValue(const ArgList &Args, unsigned N=0) const; - - static bool classof(const Arg *A) { - return A->getKind() == Arg::JoinedAndSeparateClass; - } - static bool classof(const JoinedAndSeparateArg *) { return true; } - }; } // end namespace driver } // end namespace clang |