 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
30.8% |
8 / 26 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
53.8% |
14 / 26 |
| |
|
Line Coverage: |
85.7% |
24 / 28 |
| |
 |
|
 |
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 : #ifndef CLANG_DRIVER_ARG_H_
11 : #define CLANG_DRIVER_ARG_H_
12 :
13 : #include "llvm/Support/Casting.h"
14 : using llvm::isa;
15 : using llvm::cast;
16 : using llvm::cast_or_null;
17 : using llvm::dyn_cast;
18 : using llvm::dyn_cast_or_null;
19 :
20 : #include "Util.h"
21 : #include <vector>
22 : #include <string>
23 :
24 : namespace clang {
25 : namespace driver {
26 : class ArgList;
27 : class Option;
28 :
29 : /// Arg - A concrete instance of a particular driver option.
30 : ///
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.
36 : class Arg {
37 : public:
38 : enum ArgClass {
39 : FlagClass = 0,
40 : PositionalClass,
41 : JoinedClass,
42 : SeparateClass,
43 : CommaJoinedClass,
44 : JoinedAndSeparateClass
45 : };
46 :
47 : private:
48 : ArgClass Kind;
49 :
50 : /// The option this argument is an instance of.
51 : const Option *Opt;
52 :
53 : /// The argument this argument was derived from (during tool chain
54 : /// argument translation), if any.
55 : const Arg *BaseArg;
56 :
57 : /// The index at which this argument appears in the containing
58 : /// ArgList.
59 : unsigned Index;
60 :
61 : /// Flag indicating whether this argument was used to effect
62 : /// compilation; used for generating "argument unused"
63 : /// diagnostics.
64 : mutable bool Claimed;
65 :
66 : protected:
67 : Arg(ArgClass Kind, const Option *Opt, unsigned Index,
68 : const Arg *BaseArg = 0);
69 :
70 : public:
71 : Arg(const Arg &);
72 : virtual ~Arg();
73 :
74 221: ArgClass getKind() const { return Kind; }
75 2004678: const Option &getOption() const { return *Opt; }
76 7264: unsigned getIndex() const { return Index; }
77 :
78 : /// getBaseArg - Return the base argument which generated this
79 : /// arg; this is either the argument itself or the argument it was
80 : /// derived from during tool chain specific argument translation.
81 14313: const Arg &getBaseArg() const {
11: branch 0 taken
14302: branch 1 taken
82 14313: return BaseArg ? *BaseArg : *this;
83 : }
84 1: void setBaseArg(const Arg *_BaseArg) {
85 1: BaseArg = _BaseArg;
86 1: }
87 :
88 1225: bool isClaimed() const { return getBaseArg().Claimed; }
89 :
90 : /// claim - Set the Arg claimed bit.
91 :
92 : // FIXME: We need to deal with derived arguments and set the bit
93 : // in the original argument; not the derived one.
94 13088: void claim() const { getBaseArg().Claimed = true; }
95 :
96 : virtual unsigned getNumValues() const = 0;
97 : virtual const char *getValue(const ArgList &Args, unsigned N=0) const = 0;
98 :
99 : /// render - Append the argument onto the given array as strings.
100 : virtual void render(const ArgList &Args, ArgStringList &Output) const = 0;
101 :
102 : /// renderAsInput - Append the argument, render as an input, onto
103 : /// the given array as strings. The distinction is that some
104 : /// options only render their values when rendered as a input
105 : /// (e.g., Xlinker).
106 : void renderAsInput(const ArgList &Args, ArgStringList &Output) const;
107 :
108 : static bool classof(const Arg *) { return true; }
109 :
110 : void dump() const;
111 :
112 : /// getAsString - Return a formatted version of the argument and
113 : /// its values, for debugging and diagnostics.
114 : std::string getAsString(const ArgList &Args) const;
115 : };
116 :
117 : /// FlagArg - An argument with no value.
6064: branch 1 taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
118 6064: class FlagArg : public Arg {
119 : public:
120 : FlagArg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0);
121 :
122 : virtual void render(const ArgList &Args, ArgStringList &Output) const;
123 :
124 8: virtual unsigned getNumValues() const { return 0; }
125 : virtual const char *getValue(const ArgList &Args, unsigned N=0) const;
126 :
127 : static bool classof(const Arg *A) {
128 : return A->getKind() == Arg::FlagClass;
129 : }
130 : static bool classof(const FlagArg *) { return true; }
131 : };
132 :
133 : /// PositionalArg - A simple positional argument.
2684: branch 1 taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
134 2684: class PositionalArg : public Arg {
135 : public:
136 : PositionalArg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0);
137 :
138 : virtual void render(const ArgList &Args, ArgStringList &Output) const;
139 :
140 5363: virtual unsigned getNumValues() const { return 1; }
141 : virtual const char *getValue(const ArgList &Args, unsigned N=0) const;
142 :
143 221: static bool classof(const Arg *A) {
144 221: return A->getKind() == Arg::PositionalClass;
145 : }
146 : static bool classof(const PositionalArg *) { return true; }
147 : };
148 :
149 : /// JoinedArg - A single value argument where the value is joined
150 : /// (suffixed) to the option.
885: branch 1 taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
151 885: class JoinedArg : public Arg {
152 : public:
153 : JoinedArg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0);
154 :
155 : virtual void render(const ArgList &Args, ArgStringList &Output) const;
156 :
157 1107: virtual unsigned getNumValues() const { return 1; }
158 : virtual const char *getValue(const ArgList &Args, unsigned N=0) const;
159 :
160 : static bool classof(const Arg *A) {
161 : return A->getKind() == Arg::JoinedClass;
162 : }
163 : static bool classof(const JoinedArg *) { return true; }
164 : };
165 :
166 : /// SeparateArg - An argument where one or more values follow the
167 : /// option specifier immediately in the argument vector.
2926: branch 1 taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
168 2926: class SeparateArg : public Arg {
169 : unsigned NumValues;
170 :
171 : public:
172 : SeparateArg(const Option *Opt, unsigned Index, unsigned NumValues,
173 : const Arg *BaseArg = 0);
174 :
175 : virtual void render(const ArgList &Args, ArgStringList &Output) const;
176 :
177 3224: virtual unsigned getNumValues() const { return NumValues; }
178 : virtual const char *getValue(const ArgList &Args, unsigned N=0) const;
179 :
180 0: static bool classof(const Arg *A) {
181 0: return A->getKind() == Arg::SeparateClass;
182 : }
183 : static bool classof(const SeparateArg *) { return true; }
184 : };
185 :
186 : /// CommaJoinedArg - An argument with multiple values joined by
187 : /// commas and joined (suffixed) to the option specifier.
188 : ///
189 : /// The key point of this arg is that it renders its values into
190 : /// separate arguments, which allows it to be used as a generic
191 : /// mechanism for passing arguments through to tools.
1: branch 2 taken
0: branch 3 not taken
0: branch 7 not taken
0: branch 8 not taken
192 1: class CommaJoinedArg : public Arg {
193 : std::vector<std::string> Values;
194 :
195 : public:
196 : CommaJoinedArg(const Option *Opt, unsigned Index, const char *Str,
197 : const Arg *BaseArg = 0);
198 :
199 : virtual void render(const ArgList &Args, ArgStringList &Output) const;
200 :
201 5: virtual unsigned getNumValues() const { return Values.size(); }
202 : virtual const char *getValue(const ArgList &Args, unsigned N=0) const;
203 :
204 0: static bool classof(const Arg *A) {
205 0: return A->getKind() == Arg::CommaJoinedClass;
206 : }
207 : static bool classof(const CommaJoinedArg *) { return true; }
208 : };
209 :
210 : /// JoinedAndSeparateArg - An argument with both joined and separate
211 : /// values.
6: branch 1 taken
0: branch 2 not taken
0: branch 5 not taken
0: branch 6 not taken
212 6: class JoinedAndSeparateArg : public Arg {
213 : public:
214 : JoinedAndSeparateArg(const Option *Opt, unsigned Index,
215 : const Arg *BaseArg = 0);
216 :
217 : virtual void render(const ArgList &Args, ArgStringList &Output) const;
218 :
219 10: virtual unsigned getNumValues() const { return 2; }
220 : virtual const char *getValue(const ArgList &Args, unsigned N=0) const;
221 :
222 : static bool classof(const Arg *A) {
223 : return A->getKind() == Arg::JoinedAndSeparateClass;
224 : }
225 : static bool classof(const JoinedAndSeparateArg *) { return true; }
226 : };
227 : } // end namespace driver
228 : } // end namespace clang
229 :
230 : #endif
Generated: 2010-02-10 01:31 by zcov