1 //===--- Arg.h - Parsed Argument Classes ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_DRIVER_ARG_H_
11 #define CLANG_DRIVER_ARG_H_
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringRef.h"
23 /// Arg - A concrete instance of a particular driver option.
25 /// The Arg class encodes just enough information to be able to
26 /// derive the argument values efficiently. In addition, Arg
27 /// instances have an intrusive double linked list which is used by
28 /// ArgList to provide efficient iteration over all instances of a
29 /// particular option.
31 Arg(const Arg &); // DO NOT IMPLEMENT
32 void operator=(const Arg &); // DO NOT IMPLEMENT
35 /// The option this argument is an instance of.
38 /// The argument this argument was derived from (during tool chain
39 /// argument translation), if any.
42 /// The index at which this argument appears in the containing
46 /// Was this argument used to effect compilation; used for generating
47 /// "argument unused" diagnostics.
48 mutable unsigned Claimed : 1;
50 /// Does this argument own its values.
51 mutable unsigned OwnsValues : 1;
53 /// The argument values, as C strings.
54 SmallVector<const char *, 2> Values;
57 Arg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0);
58 Arg(const Option *Opt, unsigned Index,
59 const char *Value0, const Arg *BaseArg = 0);
60 Arg(const Option *Opt, unsigned Index,
61 const char *Value0, const char *Value1, const Arg *BaseArg = 0);
64 const Option &getOption() const { return *Opt; }
65 unsigned getIndex() const { return Index; }
67 /// getBaseArg - Return the base argument which generated this
68 /// arg; this is either the argument itself or the argument it was
69 /// derived from during tool chain specific argument translation.
70 const Arg &getBaseArg() const {
71 return BaseArg ? *BaseArg : *this;
73 void setBaseArg(const Arg *_BaseArg) {
77 bool getOwnsValues() const { return OwnsValues; }
78 void setOwnsValues(bool Value) const { OwnsValues = Value; }
80 bool isClaimed() const { return getBaseArg().Claimed; }
82 /// claim - Set the Arg claimed bit.
83 void claim() const { getBaseArg().Claimed = true; }
85 unsigned getNumValues() const { return Values.size(); }
86 const char *getValue(const ArgList &Args, unsigned N=0) const {
90 SmallVectorImpl<const char*> &getValues() {
94 bool containsValue(StringRef Value) const {
95 for (unsigned i = 0, e = getNumValues(); i != e; ++i)
96 if (Values[i] == Value)
101 /// render - Append the argument onto the given array as strings.
102 void render(const ArgList &Args, ArgStringList &Output) const;
104 /// renderAsInput - Append the argument, render as an input, onto
105 /// the given array as strings. The distinction is that some
106 /// options only render their values when rendered as a input
108 void renderAsInput(const ArgList &Args, ArgStringList &Output) const;
110 static bool classof(const Arg *) { return true; }
114 /// getAsString - Return a formatted version of the argument and
115 /// its values, for debugging and diagnostics.
116 std::string getAsString(const ArgList &Args) const;
119 } // end namespace driver
120 } // end namespace clang