]> git.proxmox.com Git - rustc.git/blob - src/llvm/tools/clang/include/clang/Driver/Option.h
Imported Upstream version 0.6
[rustc.git] / src / 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/OptTable.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/ErrorHandling.h"
16 #include "clang/Basic/LLVM.h"
17
18 namespace clang {
19 namespace driver {
20 class Arg;
21 class ArgList;
22
23 namespace options {
24 enum DriverFlag {
25 DriverOption = (1 << 0),
26 HelpHidden = (1 << 1),
27 LinkerInput = (1 << 2),
28 NoArgumentUnused = (1 << 3),
29 NoForward = (1 << 4),
30 RenderAsInput = (1 << 5),
31 RenderJoined = (1 << 6),
32 RenderSeparate = (1 << 7),
33 Unsupported = (1 << 8),
34 CC1Option = (1 << 9)
35 };
36 }
37
38 /// Option - Abstract representation for a single form of driver
39 /// argument.
40 ///
41 /// An Option class represents a form of option that the driver
42 /// takes, for example how many arguments the option has and how
43 /// they can be provided. Individual option instances store
44 /// additional information about what group the option is a member
45 /// of (if any), if the option is an alias, and a number of
46 /// flags. At runtime the driver parses the command line into
47 /// concrete Arg instances, each of which corresponds to a
48 /// particular Option instance.
49 class Option {
50 public:
51 enum OptionClass {
52 GroupClass = 0,
53 InputClass,
54 UnknownClass,
55 FlagClass,
56 JoinedClass,
57 SeparateClass,
58 CommaJoinedClass,
59 MultiArgClass,
60 JoinedOrSeparateClass,
61 JoinedAndSeparateClass
62 };
63
64 enum RenderStyleKind {
65 RenderCommaJoinedStyle,
66 RenderJoinedStyle,
67 RenderSeparateStyle,
68 RenderValuesStyle
69 };
70
71 private:
72 const OptTable::Info *Info;
73
74 /// Group this option is a member of, if any.
75 const Option *Group;
76
77 /// Option that this is an alias for, if any.
78 const Option *Alias;
79
80 public:
81 Option(const OptTable::Info *Info,
82 const Option *Group, const Option *Alias);
83 ~Option();
84
85 unsigned getID() const { return Info->ID; }
86 OptionClass getKind() const { return OptionClass(Info->Kind); }
87 StringRef getName() const { return Info->Name; }
88 const Option *getGroup() const { return Group; }
89 const Option *getAlias() const { return Alias; }
90
91 unsigned getNumArgs() const { return Info->Param; }
92
93 bool isUnsupported() const { return Info->Flags & options::Unsupported; }
94
95 bool isLinkerInput() const { return Info->Flags & options::LinkerInput; }
96
97 bool hasNoOptAsInput() const { return Info->Flags & options::RenderAsInput;}
98
99 RenderStyleKind getRenderStyle() const {
100 if (Info->Flags & options::RenderJoined)
101 return RenderJoinedStyle;
102 if (Info->Flags & options::RenderSeparate)
103 return RenderSeparateStyle;
104 switch (getKind()) {
105 case GroupClass:
106 case InputClass:
107 case UnknownClass:
108 return RenderValuesStyle;
109 case JoinedClass:
110 case JoinedAndSeparateClass:
111 return RenderJoinedStyle;
112 case CommaJoinedClass:
113 return RenderCommaJoinedStyle;
114 case FlagClass:
115 case SeparateClass:
116 case MultiArgClass:
117 case JoinedOrSeparateClass:
118 return RenderSeparateStyle;
119 }
120 llvm_unreachable("Unexpected kind!");
121 }
122
123 bool isDriverOption() const { return Info->Flags & options::DriverOption; }
124
125 bool hasNoArgumentUnused() const {
126 return Info->Flags & options::NoArgumentUnused;
127 }
128
129 bool hasNoForward() const { return Info->Flags & options::NoForward; }
130
131 bool isCC1Option() const { return Info->Flags & options::CC1Option; }
132
133 bool hasForwardToGCC() const {
134 return !hasNoForward() && !isDriverOption() && !isLinkerInput();
135 }
136
137 /// getUnaliasedOption - Return the final option this option
138 /// aliases (itself, if the option has no alias).
139 const Option *getUnaliasedOption() const {
140 if (Alias) return Alias->getUnaliasedOption();
141 return this;
142 }
143
144 /// getRenderName - Return the name to use when rendering this
145 /// option.
146 StringRef getRenderName() const {
147 return getUnaliasedOption()->getName();
148 }
149
150 /// matches - Predicate for whether this option is part of the
151 /// given option (which may be a group).
152 ///
153 /// Note that matches against options which are an alias should never be
154 /// done -- aliases do not participate in matching and so such a query will
155 /// always be false.
156 bool matches(OptSpecifier ID) const;
157
158 /// accept - Potentially accept the current argument, returning a
159 /// new Arg instance, or 0 if the option does not accept this
160 /// argument (or the argument is missing values).
161 ///
162 /// If the option accepts the current argument, accept() sets
163 /// Index to the position where argument parsing should resume
164 /// (even if the argument is missing values).
165 Arg *accept(const ArgList &Args, unsigned &Index) const;
166
167 void dump() const;
168 };
169
170 } // end namespace driver
171 } // end namespace clang
172
173 #endif