 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
54.1% |
33 / 61 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
52.5% |
32 / 61 |
| |
|
Line Coverage: |
69.4% |
77 / 111 |
| |
 |
|
 |
1 : //===--- Option.cpp - Abstract Driver Options ---------------------------*-===//
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 : #include "clang/Driver/Option.h"
11 :
12 : #include "clang/Driver/Arg.h"
13 : #include "clang/Driver/ArgList.h"
14 : #include "llvm/Support/raw_ostream.h"
15 : #include <cassert>
16 : #include <algorithm>
17 : using namespace clang::driver;
18 :
19 : Option::Option(OptionClass _Kind, OptSpecifier _ID, const char *_Name,
20 18773: const OptionGroup *_Group, const Option *_Alias)
21 : : Kind(_Kind), ID(_ID.getID()), Name(_Name), Group(_Group), Alias(_Alias),
22 : Unsupported(false), LinkerInput(false), NoOptAsInput(false),
23 : ForceSeparateRender(false), ForceJoinedRender(false),
24 18773: DriverOption(false), NoArgumentUnused(false) {
25 :
26 : // Multi-level aliases are not supported, and alias options cannot
27 : // have groups. This just simplifies option tracking, it is not an
28 : // inherent limitation.
29 : assert((!Alias || (!Alias->Alias && !Group)) &&
18773: branch 0 taken
18773: branch 1 taken
18773: branch 2 taken
18773: branch 3 taken
18773: branch 4 taken
18773: branch 5 taken
408: branch 7 taken
18365: branch 8 taken
408: branch 9 taken
0: branch 10 not taken
0: branch 11 not taken
408: branch 12 taken
30 18773: "Multi-level aliases and aliases with groups are unsupported.");
31 18773: }
32 :
33 18773: Option::~Option() {
18773: branch 0 taken
18773: branch 1 taken
0: branch 3 not taken
0: branch 4 not taken
0: branch 6 not taken
18773: branch 7 taken
34 18773: }
35 :
36 0: void Option::dump() const {
37 0: llvm::errs() << "<";
0: branch 0 not taken
0: branch 1 not taken
0: branch 2 not taken
0: branch 3 not taken
0: branch 4 not taken
0: branch 5 not taken
0: branch 6 not taken
0: branch 7 not taken
0: branch 8 not taken
0: branch 9 not taken
0: branch 10 not taken
38 0: switch (Kind) {
39 : default:
40 0: assert(0 && "Invalid kind");
41 : #define P(N) case N: llvm::errs() << #N; break
42 0: P(GroupClass);
43 0: P(InputClass);
44 0: P(UnknownClass);
45 0: P(FlagClass);
46 0: P(JoinedClass);
47 0: P(SeparateClass);
48 0: P(CommaJoinedClass);
49 0: P(MultiArgClass);
50 0: P(JoinedOrSeparateClass);
51 0: P(JoinedAndSeparateClass);
52 : #undef P
53 : }
54 :
55 0: llvm::errs() << " Name:\"" << Name << '"';
56 :
0: branch 0 not taken
0: branch 1 not taken
57 0: if (Group) {
58 0: llvm::errs() << " Group:";
59 0: Group->dump();
60 : }
61 :
0: branch 0 not taken
0: branch 1 not taken
62 0: if (Alias) {
63 0: llvm::errs() << " Alias:";
64 0: Alias->dump();
65 : }
66 :
0: branch 1 not taken
0: branch 2 not taken
67 0: if (const MultiArgOption *MOA = dyn_cast<MultiArgOption>(this))
68 0: llvm::errs() << " NumArgs:" << MOA->getNumArgs();
69 :
70 0: llvm::errs() << ">\n";
71 0: }
72 :
73 2687615: bool Option::matches(OptSpecifier Opt) const {
74 : // Aliases are never considered in matching, look through them.
65945: branch 0 taken
2621670: branch 1 taken
75 2687615: if (Alias)
76 65945: return Alias->matches(Opt);
77 :
78 : // Check exact match.
13111: branch 1 taken
2608559: branch 2 taken
79 2621670: if (ID == Opt)
80 13111: return true;
81 :
554444: branch 0 taken
2054115: branch 1 taken
82 2608559: if (Group)
83 554444: return Group->matches(Opt);
84 2054115: return false;
85 : }
86 :
87 : OptionGroup::OptionGroup(OptSpecifier ID, const char *Name,
88 3056: const OptionGroup *Group)
89 3056: : Option(Option::GroupClass, ID, Name, Group, 0) {
90 3056: }
91 :
92 0: Arg *OptionGroup::accept(const InputArgList &Args, unsigned &Index) const {
93 0: assert(0 && "accept() should never be called on an OptionGroup");
94 : return 0;
95 : }
96 :
97 2771: InputOption::InputOption(OptSpecifier ID)
98 2771: : Option(Option::InputClass, ID, "<input>", 0, 0) {
99 2771: }
100 :
101 0: Arg *InputOption::accept(const InputArgList &Args, unsigned &Index) const {
102 0: assert(0 && "accept() should never be called on an InputOption");
103 : return 0;
104 : }
105 :
106 2771: UnknownOption::UnknownOption(OptSpecifier ID)
107 2771: : Option(Option::UnknownClass, ID, "<unknown>", 0, 0) {
108 2771: }
109 :
110 0: Arg *UnknownOption::accept(const InputArgList &Args, unsigned &Index) const {
111 0: assert(0 && "accept() should never be called on an UnknownOption");
112 : return 0;
113 : }
114 :
115 : FlagOption::FlagOption(OptSpecifier ID, const char *Name,
116 6069: const OptionGroup *Group, const Option *Alias)
117 6069: : Option(Option::FlagClass, ID, Name, Group, Alias) {
118 6069: }
119 :
120 6072: Arg *FlagOption::accept(const InputArgList &Args, unsigned &Index) const {
121 : // Matches iff this is an exact match.
122 : // FIXME: Avoid strlen.
7: branch 4 taken
6065: branch 5 taken
123 6072: if (strlen(getName()) != strlen(Args.getArgString(Index)))
124 7: return 0;
125 :
126 6065: return new FlagArg(this, Index++);
127 : }
128 :
129 : JoinedOption::JoinedOption(OptSpecifier ID, const char *Name,
130 877: const OptionGroup *Group, const Option *Alias)
131 877: : Option(Option::JoinedClass, ID, Name, Group, Alias) {
132 877: }
133 :
134 798: Arg *JoinedOption::accept(const InputArgList &Args, unsigned &Index) const {
135 : // Always matches.
136 798: return new JoinedArg(this, Index++);
137 : }
138 :
139 : CommaJoinedOption::CommaJoinedOption(OptSpecifier ID, const char *Name,
140 : const OptionGroup *Group,
141 1: const Option *Alias)
142 1: : Option(Option::CommaJoinedClass, ID, Name, Group, Alias) {
143 1: }
144 :
145 : Arg *CommaJoinedOption::accept(const InputArgList &Args,
146 1: unsigned &Index) const {
147 : // Always matches. We count the commas now so we can answer
148 : // getNumValues easily.
149 :
150 : // Get the suffix string.
151 : // FIXME: Avoid strlen, and move to helper method?
152 1: const char *Suffix = Args.getArgString(Index) + strlen(getName());
153 1: return new CommaJoinedArg(this, Index++, Suffix);
154 : }
155 :
156 : SeparateOption::SeparateOption(OptSpecifier ID, const char *Name,
157 2985: const OptionGroup *Group, const Option *Alias)
158 2985: : Option(Option::SeparateClass, ID, Name, Group, Alias) {
159 2985: }
160 :
161 2743: Arg *SeparateOption::accept(const InputArgList &Args, unsigned &Index) const {
162 : // Matches iff this is an exact match.
163 : // FIXME: Avoid strlen.
1: branch 4 taken
2742: branch 5 taken
164 2743: if (strlen(getName()) != strlen(Args.getArgString(Index)))
165 1: return 0;
166 :
167 2742: Index += 2;
0: branch 1 not taken
2742: branch 2 taken
168 2742: if (Index > Args.getNumInputArgStrings())
169 0: return 0;
170 :
171 2742: return new SeparateArg(this, Index - 2, 1);
172 : }
173 :
174 : MultiArgOption::MultiArgOption(OptSpecifier ID, const char *Name,
175 : const OptionGroup *Group, const Option *Alias,
176 9: unsigned _NumArgs)
177 9: : Option(Option::MultiArgClass, ID, Name, Group, Alias), NumArgs(_NumArgs) {
0: branch 0 not taken
9: branch 1 taken
0: branch 3 not taken
0: branch 4 not taken
178 9: assert(NumArgs > 1 && "Invalid MultiArgOption!");
179 9: }
180 :
181 9: Arg *MultiArgOption::accept(const InputArgList &Args, unsigned &Index) const {
182 : // Matches iff this is an exact match.
183 : // FIXME: Avoid strlen.
0: branch 4 not taken
9: branch 5 taken
184 9: if (strlen(getName()) != strlen(Args.getArgString(Index)))
185 0: return 0;
186 :
187 9: Index += 1 + NumArgs;
1: branch 1 taken
8: branch 2 taken
188 9: if (Index > Args.getNumInputArgStrings())
189 1: return 0;
190 :
191 8: return new SeparateArg(this, Index - 1 - NumArgs, NumArgs);
192 : }
193 :
194 : JoinedOrSeparateOption::JoinedOrSeparateOption(OptSpecifier ID, const char *Name,
195 : const OptionGroup *Group,
196 230: const Option *Alias)
197 230: : Option(Option::JoinedOrSeparateClass, ID, Name, Group, Alias) {
198 230: }
199 :
200 : Arg *JoinedOrSeparateOption::accept(const InputArgList &Args,
201 267: unsigned &Index) const {
202 : // If this is not an exact match, it is a joined arg.
203 : // FIXME: Avoid strlen.
88: branch 4 taken
179: branch 5 taken
204 267: if (strlen(getName()) != strlen(Args.getArgString(Index)))
205 88: return new JoinedArg(this, Index++);
206 :
207 : // Otherwise it must be separate.
208 179: Index += 2;
2: branch 1 taken
177: branch 2 taken
209 179: if (Index > Args.getNumInputArgStrings())
210 2: return 0;
211 :
212 177: return new SeparateArg(this, Index - 2, 1);
213 : }
214 :
215 : JoinedAndSeparateOption::JoinedAndSeparateOption(OptSpecifier ID,
216 : const char *Name,
217 : const OptionGroup *Group,
218 4: const Option *Alias)
219 4: : Option(Option::JoinedAndSeparateClass, ID, Name, Group, Alias) {
220 4: }
221 :
222 : Arg *JoinedAndSeparateOption::accept(const InputArgList &Args,
223 6: unsigned &Index) const {
224 : // Always matches.
225 :
226 6: Index += 2;
0: branch 1 not taken
6: branch 2 taken
227 6: if (Index > Args.getNumInputArgStrings())
228 0: return 0;
229 :
230 6: return new JoinedAndSeparateArg(this, Index - 2);
231 : }
232 :
Generated: 2010-02-10 01:31 by zcov