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 //===----------------------------------------------------------------------===//
11 /// \brief Defines the clang::driver::Arg class for parsed arguments.
13 //===----------------------------------------------------------------------===//
15 #ifndef CLANG_DRIVER_ARG_H_
16 #define CLANG_DRIVER_ARG_H_
19 #include "clang/Driver/Option.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
28 /// \brief A concrete instance of a particular driver option.
30 /// The Arg class encodes just enough information to be able to
31 /// derive the argument values efficiently. In addition, Arg
32 /// instances have an intrusive double linked list which is used by
33 /// ArgList to provide efficient iteration over all instances of a
34 /// particular option.
36 Arg(const Arg &) LLVM_DELETED_FUNCTION;
37 void operator=(const Arg &) LLVM_DELETED_FUNCTION;
40 /// \brief The option this argument is an instance of.
43 /// \brief The argument this argument was derived from (during tool chain
44 /// argument translation), if any.
47 /// \brief How this instance of the option was spelled.
50 /// \brief The index at which this argument appears in the containing
54 /// \brief Was this argument used to affect compilation?
56 /// This is used for generating "argument unused" diagnostics.
57 mutable unsigned Claimed : 1;
59 /// \brief Does this argument own its values?
60 mutable unsigned OwnsValues : 1;
62 /// \brief The argument values, as C strings.
63 SmallVector<const char *, 2> Values;
66 Arg(const Option Opt, StringRef Spelling, unsigned Index,
67 const Arg *BaseArg = 0);
68 Arg(const Option Opt, StringRef Spelling, unsigned Index,
69 const char *Value0, const Arg *BaseArg = 0);
70 Arg(const Option Opt, StringRef Spelling, unsigned Index,
71 const char *Value0, const char *Value1, const Arg *BaseArg = 0);
74 Option getOption() const { return Opt; }
75 StringRef getSpelling() const { return Spelling; }
76 unsigned getIndex() const { return Index; }
78 /// \brief Return the base argument which generated this arg.
80 /// This is either the argument itself or the argument it was
81 /// derived from during tool chain specific argument translation.
82 const Arg &getBaseArg() const {
83 return BaseArg ? *BaseArg : *this;
85 void setBaseArg(const Arg *_BaseArg) {
89 bool getOwnsValues() const { return OwnsValues; }
90 void setOwnsValues(bool Value) const { OwnsValues = Value; }
92 bool isClaimed() const { return getBaseArg().Claimed; }
94 /// \brief Set the Arg claimed bit.
95 void claim() const { getBaseArg().Claimed = true; }
97 unsigned getNumValues() const { return Values.size(); }
98 const char *getValue(unsigned N = 0) const {
102 SmallVectorImpl<const char*> &getValues() {
106 bool containsValue(StringRef Value) const {
107 for (unsigned i = 0, e = getNumValues(); i != e; ++i)
108 if (Values[i] == Value)
113 /// \brief Append the argument onto the given array as strings.
114 void render(const ArgList &Args, ArgStringList &Output) const;
116 /// \brief Append the argument, render as an input, onto the given
117 /// array as strings.
119 /// The distinction is that some options only render their values
120 /// when rendered as a input (e.g., Xlinker).
121 void renderAsInput(const ArgList &Args, ArgStringList &Output) const;
125 /// \brief Return a formatted version of the argument and
126 /// its values, for debugging and diagnostics.
127 std::string getAsString(const ArgList &Args) const;
130 } // end namespace driver
131 } // end namespace clang