]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/clang/include/clang/Driver/Arg.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / tools / clang / include / clang / Driver / Arg.h
1 //===--- Arg.h - Parsed Argument Classes ------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Defines the clang::driver::Arg class for parsed arguments.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef CLANG_DRIVER_ARG_H_
16 #define CLANG_DRIVER_ARG_H_
17
18 #include "Util.h"
19 #include "clang/Driver/Option.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
22 #include <string>
23
24 namespace clang {
25 namespace driver {
26   class ArgList;
27
28   /// \brief A concrete instance of a particular driver option.
29   ///
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.
35   class Arg {
36     Arg(const Arg &) LLVM_DELETED_FUNCTION;
37     void operator=(const Arg &) LLVM_DELETED_FUNCTION;
38
39   private:
40     /// \brief The option this argument is an instance of.
41     const Option Opt;
42
43     /// \brief The argument this argument was derived from (during tool chain
44     /// argument translation), if any.
45     const Arg *BaseArg;
46
47     /// \brief How this instance of the option was spelled.
48     StringRef Spelling;
49
50     /// \brief The index at which this argument appears in the containing
51     /// ArgList.
52     unsigned Index;
53
54     /// \brief Was this argument used to affect compilation?
55     ///
56     /// This is used for generating "argument unused" diagnostics.
57     mutable unsigned Claimed : 1;
58
59     /// \brief Does this argument own its values?
60     mutable unsigned OwnsValues : 1;
61
62     /// \brief The argument values, as C strings.
63     SmallVector<const char *, 2> Values;
64
65   public:
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);
72     ~Arg();
73
74     Option getOption() const { return Opt; }
75     StringRef getSpelling() const { return Spelling; }
76     unsigned getIndex() const { return Index; }
77
78     /// \brief Return the base argument which generated this arg.
79     ///
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;
84     }
85     void setBaseArg(const Arg *_BaseArg) {
86       BaseArg = _BaseArg;
87     }
88
89     bool getOwnsValues() const { return OwnsValues; }
90     void setOwnsValues(bool Value) const { OwnsValues = Value; }
91
92     bool isClaimed() const { return getBaseArg().Claimed; }
93
94     /// \brief Set the Arg claimed bit.
95     void claim() const { getBaseArg().Claimed = true; }
96
97     unsigned getNumValues() const { return Values.size(); }
98     const char *getValue(unsigned N = 0) const {
99       return Values[N];
100     }
101
102     SmallVectorImpl<const char*> &getValues() {
103       return Values;
104     }
105
106     bool containsValue(StringRef Value) const {
107       for (unsigned i = 0, e = getNumValues(); i != e; ++i)
108         if (Values[i] == Value)
109           return true;
110       return false;
111     }
112
113     /// \brief Append the argument onto the given array as strings.
114     void render(const ArgList &Args, ArgStringList &Output) const;
115
116     /// \brief Append the argument, render as an input, onto the given
117     /// array as strings.
118     ///
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;
122
123     void dump() const;
124
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;
128   };
129
130 } // end namespace driver
131 } // end namespace clang
132
133 #endif