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_
18 #include "clang/Driver/Option.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
29 /// \brief A concrete instance of a particular driver option.
31 /// The Arg class encodes just enough information to be able to
32 /// derive the argument values efficiently. In addition, Arg
33 /// instances have an intrusive double linked list which is used by
34 /// ArgList to provide efficient iteration over all instances of a
35 /// particular option.
37 Arg(const Arg &) LLVM_DELETED_FUNCTION;
38 void operator=(const Arg &) LLVM_DELETED_FUNCTION;
41 /// \brief The option this argument is an instance of.
44 /// \brief The argument this argument was derived from (during tool chain
45 /// argument translation), if any.
48 /// \brief How this instance of the option was spelled.
51 /// \brief The index at which this argument appears in the containing
55 /// \brief Was this argument used to effect compilation?
57 /// This is used for generating "argument unused" diagnostics.
58 mutable unsigned Claimed : 1;
60 /// \brief Does this argument own its values?
61 mutable unsigned OwnsValues : 1;
63 /// \brief The argument values, as C strings.
64 SmallVector<const char *, 2> Values;
67 Arg(const Option Opt, StringRef Spelling, unsigned Index,
68 const Arg *BaseArg = 0);
69 Arg(const Option Opt, StringRef Spelling, unsigned Index,
70 const char *Value0, const Arg *BaseArg = 0);
71 Arg(const Option Opt, StringRef Spelling, unsigned Index,
72 const char *Value0, const char *Value1, const Arg *BaseArg = 0);
75 const Option getOption() const { return Opt; }
76 StringRef getSpelling() const { return Spelling; }
77 unsigned getIndex() const { return Index; }
79 /// \brief Return the base argument which generated this arg.
81 /// This is either the argument itself or the argument it was
82 /// derived from during tool chain specific argument translation.
83 const Arg &getBaseArg() const {
84 return BaseArg ? *BaseArg : *this;
86 void setBaseArg(const Arg *_BaseArg) {
90 bool getOwnsValues() const { return OwnsValues; }
91 void setOwnsValues(bool Value) const { OwnsValues = Value; }
93 bool isClaimed() const { return getBaseArg().Claimed; }
95 /// \brief Set the Arg claimed bit.
96 void claim() const { getBaseArg().Claimed = true; }
98 unsigned getNumValues() const { return Values.size(); }
99 const char *getValue(unsigned N = 0) const {
103 SmallVectorImpl<const char*> &getValues() {
107 bool containsValue(StringRef Value) const {
108 for (unsigned i = 0, e = getNumValues(); i != e; ++i)
109 if (Values[i] == Value)
114 /// \brief Append the argument onto the given array as strings.
115 void render(const ArgList &Args, ArgStringList &Output) const;
117 /// \brief Append the argument, render as an input, onto the given
118 /// array as strings.
120 /// The distinction is that some options only render their values
121 /// when rendered as a input (e.g., Xlinker).
122 void renderAsInput(const ArgList &Args, ArgStringList &Output) const;
126 /// \brief Return a formatted version of the argument and
127 /// its values, for debugging and diagnostics.
128 std::string getAsString(const ArgList &Args) const;
131 } // end namespace driver
132 } // end namespace clang