]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Driver/Option.h
Merge mandoc from vendor into contrib and provide the necessary Makefile glue.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Driver / Option.h
1 //===--- Option.h - Abstract Driver Options ---------------------*- 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_OPTION_H_
11 #define CLANG_DRIVER_OPTION_H_
12
13 #include "clang/Driver/OptSpecifier.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "clang/Basic/LLVM.h"
16
17 namespace clang {
18 namespace driver {
19   class Arg;
20   class ArgList;
21   class OptionGroup;
22
23   /// Option - Abstract representation for a single form of driver
24   /// argument.
25   ///
26   /// An Option class represents a form of option that the driver
27   /// takes, for example how many arguments the option has and how
28   /// they can be provided. Individual option instances store
29   /// additional information about what group the option is a member
30   /// of (if any), if the option is an alias, and a number of
31   /// flags. At runtime the driver parses the command line into
32   /// concrete Arg instances, each of which corresponds to a
33   /// particular Option instance.
34   class Option {
35   public:
36     enum OptionClass {
37       GroupClass = 0,
38       InputClass,
39       UnknownClass,
40       FlagClass,
41       JoinedClass,
42       SeparateClass,
43       CommaJoinedClass,
44       MultiArgClass,
45       JoinedOrSeparateClass,
46       JoinedAndSeparateClass
47     };
48
49     enum RenderStyleKind {
50       RenderCommaJoinedStyle,
51       RenderJoinedStyle,
52       RenderSeparateStyle,
53       RenderValuesStyle
54     };
55
56   private:
57     OptionClass Kind;
58
59     /// The option ID.
60     OptSpecifier ID;
61
62     /// The option name.
63     StringRef Name;
64
65     /// Group this option is a member of, if any.
66     const OptionGroup *Group;
67
68     /// Option that this is an alias for, if any.
69     const Option *Alias;
70
71     /// Unsupported options will be rejected.
72     bool Unsupported : 1;
73
74     /// Treat this option like a linker input?
75     bool LinkerInput : 1;
76
77     /// When rendering as an input, don't render the option.
78
79     // FIXME: We should ditch the render/renderAsInput distinction.
80     bool NoOptAsInput : 1;
81
82     /// The style to using when rendering arguments parsed by this option.
83     unsigned RenderStyle : 2;
84
85     /// This option is only consumed by the driver.
86     bool DriverOption : 1;
87
88     /// This option should not report argument unused errors.
89     bool NoArgumentUnused : 1;
90
91     /// This option should not be implicitly forwarded.
92     bool NoForward : 1;
93
94     /// CC1Option - This option should be accepted by clang -cc1.
95     bool CC1Option : 1;
96
97   protected:
98     Option(OptionClass Kind, OptSpecifier ID, const char *Name,
99            const OptionGroup *Group, const Option *Alias);
100   public:
101     virtual ~Option();
102
103     unsigned getID() const { return ID.getID(); }
104     OptionClass getKind() const { return Kind; }
105     StringRef getName() const { return Name; }
106     const OptionGroup *getGroup() const { return Group; }
107     const Option *getAlias() const { return Alias; }
108
109     bool isUnsupported() const { return Unsupported; }
110     void setUnsupported(bool Value) { Unsupported = Value; }
111
112     bool isLinkerInput() const { return LinkerInput; }
113     void setLinkerInput(bool Value) { LinkerInput = Value; }
114
115     bool hasNoOptAsInput() const { return NoOptAsInput; }
116     void setNoOptAsInput(bool Value) { NoOptAsInput = Value; }
117
118     RenderStyleKind getRenderStyle() const {
119       return RenderStyleKind(RenderStyle);
120     }
121     void setRenderStyle(RenderStyleKind Value) { RenderStyle = Value; }
122
123     bool isDriverOption() const { return DriverOption; }
124     void setDriverOption(bool Value) { DriverOption = Value; }
125
126     bool hasNoArgumentUnused() const { return NoArgumentUnused; }
127     void setNoArgumentUnused(bool Value) { NoArgumentUnused = Value; }
128
129     bool hasNoForward() const { return NoForward; }
130     void setNoForward(bool Value) { NoForward = Value; }
131
132     bool isCC1Option() const { return CC1Option; }
133     void setIsCC1Option(bool Value) { CC1Option = Value; }
134
135     bool hasForwardToGCC() const {
136       return !NoForward && !DriverOption && !LinkerInput;
137     }
138
139     /// getUnaliasedOption - Return the final option this option
140     /// aliases (itself, if the option has no alias).
141     const Option *getUnaliasedOption() const {
142       if (Alias) return Alias->getUnaliasedOption();
143       return this;
144     }
145
146     /// getRenderName - Return the name to use when rendering this
147     /// option.
148     StringRef getRenderName() const {
149       return getUnaliasedOption()->getName();
150     }
151
152     /// matches - Predicate for whether this option is part of the
153     /// given option (which may be a group).
154     ///
155     /// Note that matches against options which are an alias should never be
156     /// done -- aliases do not participate in matching and so such a query will
157     /// always be false.
158     bool matches(OptSpecifier ID) const;
159
160     /// accept - Potentially accept the current argument, returning a
161     /// new Arg instance, or 0 if the option does not accept this
162     /// argument (or the argument is missing values).
163     ///
164     /// If the option accepts the current argument, accept() sets
165     /// Index to the position where argument parsing should resume
166     /// (even if the argument is missing values).
167     virtual Arg *accept(const ArgList &Args, unsigned &Index) const = 0;
168
169     void dump() const;
170
171     static bool classof(const Option *) { return true; }
172   };
173
174   /// OptionGroup - A set of options which are can be handled uniformly
175   /// by the driver.
176   class OptionGroup : public Option {
177   public:
178     OptionGroup(OptSpecifier ID, const char *Name, const OptionGroup *Group);
179
180     virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
181
182     static bool classof(const Option *O) {
183       return O->getKind() == Option::GroupClass;
184     }
185     static bool classof(const OptionGroup *) { return true; }
186   };
187
188   // Dummy option classes.
189
190   /// InputOption - Dummy option class for representing driver inputs.
191   class InputOption : public Option {
192   public:
193     InputOption(OptSpecifier ID);
194
195     virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
196
197     static bool classof(const Option *O) {
198       return O->getKind() == Option::InputClass;
199     }
200     static bool classof(const InputOption *) { return true; }
201   };
202
203   /// UnknownOption - Dummy option class for represent unknown arguments.
204   class UnknownOption : public Option {
205   public:
206     UnknownOption(OptSpecifier ID);
207
208     virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
209
210     static bool classof(const Option *O) {
211       return O->getKind() == Option::UnknownClass;
212     }
213     static bool classof(const UnknownOption *) { return true; }
214   };
215
216   // Normal options.
217
218   class FlagOption : public Option {
219   public:
220     FlagOption(OptSpecifier ID, const char *Name, const OptionGroup *Group,
221                const Option *Alias);
222
223     virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
224
225     static bool classof(const Option *O) {
226       return O->getKind() == Option::FlagClass;
227     }
228     static bool classof(const FlagOption *) { return true; }
229   };
230
231   class JoinedOption : public Option {
232   public:
233     JoinedOption(OptSpecifier ID, const char *Name, const OptionGroup *Group,
234                  const Option *Alias);
235
236     virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
237
238     static bool classof(const Option *O) {
239       return O->getKind() == Option::JoinedClass;
240     }
241     static bool classof(const JoinedOption *) { return true; }
242   };
243
244   class SeparateOption : public Option {
245   public:
246     SeparateOption(OptSpecifier ID, const char *Name,
247                    const OptionGroup *Group, const Option *Alias);
248
249     virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
250
251     static bool classof(const Option *O) {
252       return O->getKind() == Option::SeparateClass;
253     }
254     static bool classof(const SeparateOption *) { return true; }
255   };
256
257   class CommaJoinedOption : public Option {
258   public:
259     CommaJoinedOption(OptSpecifier ID, const char *Name,
260                       const OptionGroup *Group, const Option *Alias);
261
262     virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
263
264     static bool classof(const Option *O) {
265       return O->getKind() == Option::CommaJoinedClass;
266     }
267     static bool classof(const CommaJoinedOption *) { return true; }
268   };
269
270   // FIXME: Fold MultiArgOption into SeparateOption?
271
272   /// MultiArgOption - An option which takes multiple arguments (these
273   /// are always separate arguments).
274   class MultiArgOption : public Option {
275     unsigned NumArgs;
276
277   public:
278     MultiArgOption(OptSpecifier ID, const char *Name, const OptionGroup *Group,
279                    const Option *Alias, unsigned NumArgs);
280
281     unsigned getNumArgs() const { return NumArgs; }
282
283     virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
284
285     static bool classof(const Option *O) {
286       return O->getKind() == Option::MultiArgClass;
287     }
288     static bool classof(const MultiArgOption *) { return true; }
289   };
290
291   /// JoinedOrSeparateOption - An option which either literally
292   /// prefixes its (non-empty) value, or is follwed by a value.
293   class JoinedOrSeparateOption : public Option {
294   public:
295     JoinedOrSeparateOption(OptSpecifier ID, const char *Name,
296                            const OptionGroup *Group, const Option *Alias);
297
298     virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
299
300     static bool classof(const Option *O) {
301       return O->getKind() == Option::JoinedOrSeparateClass;
302     }
303     static bool classof(const JoinedOrSeparateOption *) { return true; }
304   };
305
306   /// JoinedAndSeparateOption - An option which literally prefixes its
307   /// value and is followed by another value.
308   class JoinedAndSeparateOption : public Option {
309   public:
310     JoinedAndSeparateOption(OptSpecifier ID, const char *Name,
311                             const OptionGroup *Group, const Option *Alias);
312
313     virtual Arg *accept(const ArgList &Args, unsigned &Index) const;
314
315     static bool classof(const Option *O) {
316       return O->getKind() == Option::JoinedAndSeparateClass;
317     }
318     static bool classof(const JoinedAndSeparateOption *) { return true; }
319   };
320
321 } // end namespace driver
322 } // end namespace clang
323
324 #endif