blob: 9352a9912d49556b952af610d86d9aed0d270ba7 [file] [log] [blame]
Daniel Dunbara5677512009-01-05 19:53:30 +00001class Option(object):
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +00002 """Option - Root option class."""
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +00003
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +00004 def __init__(self, name, group=None, isLinkerInput=False, noOptAsInput=False):
5 assert group is None or isinstance(group, OptionGroup)
Daniel Dunbara5677512009-01-05 19:53:30 +00006 self.name = name
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +00007 self.group = group
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +00008 self.isLinkerInput = isLinkerInput
9 self.noOptAsInput = noOptAsInput
Daniel Dunbara5677512009-01-05 19:53:30 +000010
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +000011 def matches(self, opt):
12 """matches(opt) -> bool
13
14 Predicate for whether this option is part of the given option
15 (which may be a group)."""
16 if self is opt:
17 return True
18 elif self.group:
19 return self.group.matches(opt)
20 else:
21 return False
22
Daniel Dunbara5677512009-01-05 19:53:30 +000023 def accept(self, index, arg, it):
24 """accept(index, arg, iterator) -> Arg or None
25
26 Accept the argument at the given index, returning an Arg, or
27 return None if the option does not accept this argument.
28
29 May raise MissingArgumentError.
30 """
31 abstract
32
33 def __repr__(self):
34 return '<%s name=%r>' % (self.__class__.__name__,
35 self.name)
36
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +000037class OptionGroup(Option):
38 """OptionGroup - A fake option class used to group options so that
39 the driver can efficiently refer to an entire set of options."""
40
41 def __init__(self, name):
42 super(OptionGroup, self).__init__(name)
43
44 def accept(self, index, arg, it):
45 raise RuntimeError,"accept() should never be called on an OptionGroup"
46
Daniel Dunbar5039f212009-01-06 02:30:10 +000047# Dummy options
48
49class InputOption(Option):
50 def __init__(self):
51 super(InputOption, self).__init__('<input>')
52
53 def accept(self):
54 raise RuntimeError,"accept() should never be used on InputOption instance."
55
56class UnknownOption(Option):
57 def __init__(self):
58 super(UnknownOption, self).__init__('<unknown>')
59
60 def accept(self):
61 raise RuntimeError,"accept() should never be used on UnknownOption instance."
62
63# Normal options
64
Daniel Dunbara5677512009-01-05 19:53:30 +000065class FlagOption(Option):
66 """An option which takes no arguments."""
67
68 def accept(self, index, arg, it):
69 if arg == self.name:
70 return Arg(index, self)
71
72class JoinedOption(Option):
73 """An option which literally prefixes its argument."""
74
75 def accept(self, index, arg, it):
76 if arg.startswith(self.name):
77 return JoinedValueArg(index, self)
78
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +000079class CommaJoinedOption(Option):
80 """An option which literally prefixs its argument, but which
81 conceptually may have an arbitrary number of arguments which are
82 separated by commas."""
83
84 def accept(self, index, arg, it):
85 if arg.startswith(self.name):
86 return CommaJoinedValuesArg(index, self)
87
Daniel Dunbara5677512009-01-05 19:53:30 +000088class SeparateOption(Option):
89 """An option which is followed by its value."""
90
91 def accept(self, index, arg, it):
92 if arg == self.name:
93 try:
94 _,value = it.next()
95 except StopIteration:
96 raise MissingArgumentError,self
97 return SeparateValueArg(index, self)
98
99class MultiArgOption(Option):
100 """An option which takes multiple arguments."""
101
102 def __init__(self, name, numArgs):
103 assert numArgs > 1
104 super(MultiArgOption, self).__init__(name)
105 self.numArgs = numArgs
106
107 def accept(self, index, arg, it):
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000108 if arg == self.name:
Daniel Dunbara5677512009-01-05 19:53:30 +0000109 try:
110 values = [it.next()[1] for i in range(self.numArgs)]
111 except StopIteration:
112 raise MissingArgumentError,self
113 return MultipleValuesArg(index, self)
114
115class JoinedOrSeparateOption(Option):
116 """An option which either literally prefixes its value or is
117 followed by an value."""
118
119 def accept(self, index, arg, it):
120 if arg.startswith(self.name):
121 if len(arg) != len(self.name): # Joined case
122 return JoinedValueArg(index, self)
123 else:
124 try:
125 _,value = it.next()
126 except StopIteration:
127 raise MissingArgumentError,self
128 return SeparateValueArg(index, self)
129
130class JoinedAndSeparateOption(Option):
131 """An option which literally prefixes its value and is followed by
132 an value."""
133
134 def accept(self, index, arg, it):
135 if arg.startswith(self.name):
136 try:
137 _,value = it.next()
138 except StopIteration:
139 raise MissingArgumentError,self
140 return JoinedAndSeparateValuesArg(index, self)
141
142###
143
144class Arg(object):
145 """Arg - Base class for actual driver arguments."""
146 def __init__(self, index, opt):
Daniel Dunbar5039f212009-01-06 02:30:10 +0000147 assert opt is not None
Daniel Dunbara5677512009-01-05 19:53:30 +0000148 self.index = index
149 self.opt = opt
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000150
Daniel Dunbara5677512009-01-05 19:53:30 +0000151 def __repr__(self):
152 return '<%s index=%r opt=%r>' % (self.__class__.__name__,
153 self.index,
154 self.opt)
155
156 def render(self, args):
157 """render(args) -> [str]
158
159 Map the argument into a list of actual program arguments,
160 given the source argument array."""
161 assert self.opt
162 return [self.opt.name]
163
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000164 def renderAsInput(self, args):
165 return self.render(args)
166
Daniel Dunbara5677512009-01-05 19:53:30 +0000167class ValueArg(Arg):
168 """ValueArg - An instance of an option which has an argument."""
169
170 def getValue(self, args):
171 abstract
172
Daniel Dunbar996ce962009-01-12 07:40:25 +0000173 def getValues(self, args):
174 return [self.getValue(args)]
175
Daniel Dunbar5039f212009-01-06 02:30:10 +0000176class PositionalArg(ValueArg):
177 """PositionalArg - A simple positional argument."""
Daniel Dunbara5677512009-01-05 19:53:30 +0000178
179 def getValue(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000180 return args.getInputString(self.index)
Daniel Dunbara5677512009-01-05 19:53:30 +0000181
182 def render(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000183 return [args.getInputString(self.index)]
Daniel Dunbara5677512009-01-05 19:53:30 +0000184
185class JoinedValueArg(ValueArg):
Daniel Dunbar5039f212009-01-06 02:30:10 +0000186 """JoinedValueArg - A single value argument where the value is
187 joined (suffixed) to the option."""
188
Daniel Dunbara5677512009-01-05 19:53:30 +0000189 def getValue(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000190 return args.getInputString(self.index)[len(self.opt.name):]
Daniel Dunbara5677512009-01-05 19:53:30 +0000191
Daniel Dunbara5677512009-01-05 19:53:30 +0000192 def render(self, args):
193 return [self.opt.name + self.getValue(args)]
194
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000195 def renderAsInput(self, args):
196 if self.opt.noOptAsInput:
197 return [self.getValue(args)]
198 return self.render(args)
199
Daniel Dunbara5677512009-01-05 19:53:30 +0000200class SeparateValueArg(ValueArg):
Daniel Dunbar5039f212009-01-06 02:30:10 +0000201 """SeparateValueArg - A single value argument where the value
202 follows the option in the argument vector."""
203
Daniel Dunbara5677512009-01-05 19:53:30 +0000204 def getValue(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000205 return args.getInputString(self.index, offset=1)
Daniel Dunbara5677512009-01-05 19:53:30 +0000206
Daniel Dunbara5677512009-01-05 19:53:30 +0000207 def render(self, args):
208 return [self.opt.name, self.getValue(args)]
209
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000210 def renderAsInput(self, args):
211 if self.opt.noOptAsInput:
212 return [self.getValue(args)]
213 return self.render(args)
214
Daniel Dunbara5677512009-01-05 19:53:30 +0000215class MultipleValuesArg(Arg):
Daniel Dunbar5039f212009-01-06 02:30:10 +0000216 """MultipleValuesArg - An argument with multiple values which
217 follow the option in the argument vector."""
218
219 # FIXME: Should we unify this with SeparateValueArg?
220
Daniel Dunbara5677512009-01-05 19:53:30 +0000221 def getValues(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000222 return [args.getInputString(self.index, offset=1+i)
223 for i in range(self.opt.numArgs)]
Daniel Dunbara5677512009-01-05 19:53:30 +0000224
Daniel Dunbara5677512009-01-05 19:53:30 +0000225 def render(self, args):
226 return [self.opt.name] + self.getValues(args)
227
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000228class CommaJoinedValuesArg(Arg):
229 """CommaJoinedValuesArg - An argument with multiple values joined
230 by commas and joined (suffixed) to the option.
231
232 The key point of this arg is that it renders its values into
233 separate arguments, which allows it to be used as a generic
234 mechanism for passing arguments through to tools."""
235
236 def getValues(self, args):
237 return args.getInputString(self.index)[len(self.opt.name):].split(',')
238
239 def render(self, args):
240 return [self.opt.name + ','.join(self.getValues(args))]
241
242 def renderAsInput(self, args):
243 return self.getValues(args)
244
Daniel Dunbara5677512009-01-05 19:53:30 +0000245# FIXME: Man, this is lame. It is only used by -Xarch. Maybe easier to
246# just special case?
247class JoinedAndSeparateValuesArg(Arg):
248 """JoinedAndSeparateValuesArg - An argument with both joined and
249 separate values."""
250
251 def getJoinedValue(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000252 return args.getInputString(self.index)[len(self.opt.name):]
Daniel Dunbara5677512009-01-05 19:53:30 +0000253
254 def getSeparateValue(self, args):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000255 return args.getInputString(self.index, offset=1)
Daniel Dunbara5677512009-01-05 19:53:30 +0000256
257 def render(self, args):
258 return ([self.opt.name + self.getJoinedValue(args)] +
259 [self.getSeparateValue(args)])
260
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000261###
262
263class InputIndex:
264 def __init__(self, sourceId, pos):
265 self.sourceId = sourceId
266 self.pos = pos
267
268 def __repr__(self):
269 return 'InputIndex(%d, %d)' % (self.sourceId, self.pos)
270
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000271class ArgList:
Daniel Dunbar5039f212009-01-06 02:30:10 +0000272 """ArgList - Collect an input argument vector along with a set of parsed Args
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000273 and supporting information."""
274
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000275 def __init__(self, parser, argv):
276 self.parser = parser
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000277 self.argv = list(argv)
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000278 self.syntheticArgv = []
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000279 self.lastArgs = {}
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000280 self.lastGroupArgs = {}
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000281 self.args = []
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000282
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000283 def getArgs(self, option):
284 # FIXME: How efficient do we want to make this. One reasonable
285 # solution would be to embed a linked list inside each arg and
286 # automatically chain them (with pointers to head and
287 # tail). This gives us efficient access to the (first, last,
288 # all) arg(s) with little overhead.
289 for arg in self.args:
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000290 if arg.opt.matches(option):
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000291 yield arg
292
Daniel Dunbar996ce962009-01-12 07:40:25 +0000293 def getArgs2(self, optionA, optionB):
294 """getArgs2 - Iterate over all arguments for two options, in
295 the order they were specified."""
296 # As long as getArgs is efficient, we can easily make this
297 # efficient by iterating both at once and always taking the
298 # earlier arg.
299 for arg in self.args:
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000300 if (arg.opt.matches(optionA) or
301 arg.opt.matches(optionB)):
Daniel Dunbar996ce962009-01-12 07:40:25 +0000302 yield arg
303
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000304 def getArgs3(self, optionA, optionB, optionC):
305 """getArgs3 - Iterate over all arguments for three options, in
306 the order they were specified."""
307 for arg in self.args:
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000308 if (arg.opt.matches(optionA) or
309 arg.opt.matches(optionB) or
310 arg.opt.matches(optionC)):
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000311 yield arg
312
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000313 def getLastArg(self, option):
314 return self.lastArgs.get(option)
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000315
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000316 def getInputString(self, index, offset=0):
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000317 # Source 0 is argv.
318 if index.sourceId == 0:
319 return self.argv[index.pos + offset]
320
321 # Source 1 is synthetic argv.
322 if index.sourceId == 1:
323 return self.syntheticArgv[index.pos + offset]
324
325 raise RuntimeError,'Unknown source ID for index.'
326
Daniel Dunbar0fe5a4f2009-01-11 22:42:24 +0000327 def addLastArg(self, output, option):
328 """addLastArgs - Extend the given output vector with the last
329 instance of a given option."""
330 arg = self.getLastArg(option)
331 if arg:
332 output.extend(self.render(arg))
333
334 def addAllArgs(self, output, option):
335 """addAllArgs - Extend the given output vector with all
336 instances of a given option."""
337 for arg in self.getArgs(option):
338 output.extend(self.render(arg))
339
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000340 def addAllArgs2(self, output, optionA, optionB):
341 """addAllArgs2 - Extend the given output vector with all
342 instances of two given option, with relative order preserved."""
343 for arg in self.getArgs2(optionA, optionB):
344 output.extend(self.render(arg))
345
346 def addAllArgs3(self, output, optionA, optionB, optionC):
347 """addAllArgs3 - Extend the given output vector with all
348 instances of three given option, with relative order preserved."""
349 for arg in self.getArgs3(optionA, optionB, optionC):
350 output.extend(self.render(arg))
351
Daniel Dunbar0fe5a4f2009-01-11 22:42:24 +0000352 def addAllArgsTranslated(self, output, option, translation):
353 """addAllArgsTranslated - Extend the given output vector with
354 all instances of a given option, rendered as separate
355 arguments with the actual option name translated to a user
356 specified string. For example, '-foox' will be render as
357 ['-bar', 'x'] if '-foo' was the option and '-bar' was the
358 translation.
359
360 This routine expects that the option can only yield ValueArg
361 instances."""
362 for arg in self.getArgs(option):
363 assert isinstance(arg, ValueArg)
364 output.append(translation)
365 output.append(self.getValue(arg))
366
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000367 def makeIndex(self, *strings):
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000368 pos = len(self.syntheticArgv)
369 self.syntheticArgv.extend(strings)
370 return InputIndex(1, pos)
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000371
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000372 def makeFlagArg(self, option):
373 return Arg(self.makeIndex(option.name),
374 option)
375
376 def makeInputArg(self, string):
377 return PositionalArg(self.makeIndex(string),
378 self.parser.inputOption)
379
380 def makeUnknownArg(self, string):
381 return PositionalArg(self.makeIndex(string),
382 self.parser.unknownOption)
383
384 def makeSeparateArg(self, string, option):
385 return SeparateValueArg(self.makeIndex(option.name, string),
386 option)
387
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000388 # Support use as a simple arg list.
389
390 def __iter__(self):
391 return iter(self.args)
392
393 def append(self, arg):
394 self.args.append(arg)
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000395 self.lastArgs[arg.opt] = arg
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000396 if arg.opt.group is not None:
397 self.lastArgs[arg.opt.group] = arg
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000398
399 # Forwarding methods.
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000400 #
401 # FIXME: Clean this up once restructuring is done.
402
403 def render(self, arg):
404 return arg.render(self)
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000405
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000406 def renderAsInput(self, arg):
407 return arg.renderAsInput(self)
408
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000409 def getValue(self, arg):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000410 return arg.getValue(self)
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000411
412 def getValues(self, arg):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000413 return arg.getValues(self)
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000414
415 def getSeparateValue(self, arg):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000416 return arg.getSeparateValue(self)
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000417
418 def getJoinedValue(self, arg):
Daniel Dunbarfb2c5c42009-01-07 01:29:28 +0000419 return arg.getJoinedValue(self)
Daniel Dunbar1dd2ada2009-01-06 06:32:49 +0000420
421###
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000422
Daniel Dunbara5677512009-01-05 19:53:30 +0000423class OptionParser:
424 def __init__(self):
425 self.options = []
Daniel Dunbar5039f212009-01-06 02:30:10 +0000426 self.inputOption = InputOption()
427 self.unknownOption = UnknownOption()
428
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000429 # Driver driver options
430 self.archOption = self.addOption(SeparateOption('-arch'))
431
432 # Misc driver options
433 self.addOption(FlagOption('-pass-exit-codes'))
434 self.addOption(FlagOption('--help'))
435 self.addOption(FlagOption('--target-help'))
436
437 self.dumpspecsOption = self.addOption(FlagOption('-dumpspecs'))
438 self.dumpversionOption = self.addOption(FlagOption('-dumpversion'))
439 self.dumpmachineOption = self.addOption(FlagOption('-dumpmachine'))
440 self.printSearchDirsOption = self.addOption(FlagOption('-print-search-dirs'))
441 self.printLibgccFilenameOption = self.addOption(FlagOption('-print-libgcc-file-name'))
442 # FIXME: Hrm, where does this come from? It isn't always true that
443 # we take both - and --. For example, gcc --S ... ends up sending
444 # -fS to cc1. Investigate.
445 #
446 # FIXME: Need to implement some form of alias support inside
447 # getLastOption to handle this.
448 self.printLibgccFileNameOption2 = self.addOption(FlagOption('--print-libgcc-file-name'))
449 self.printFileNameOption = self.addOption(JoinedOption('-print-file-name='))
450 self.printProgNameOption = self.addOption(JoinedOption('-print-prog-name='))
451 self.printProgNameOption2 = self.addOption(JoinedOption('--print-prog-name='))
452 self.printMultiDirectoryOption = self.addOption(FlagOption('-print-multi-directory'))
453 self.printMultiLibOption = self.addOption(FlagOption('-print-multi-lib'))
454 self.addOption(FlagOption('-print-multi-os-directory'))
455
456 # Hmmm, who really takes this?
457 self.addOption(FlagOption('--version'))
458
459 # Pipeline control
460 self.hashHashHashOption = self.addOption(FlagOption('-###'))
461 self.EOption = self.addOption(FlagOption('-E'))
462 self.SOption = self.addOption(FlagOption('-S'))
463 self.cOption = self.addOption(FlagOption('-c'))
464 self.combineOption = self.addOption(FlagOption('-combine'))
465 self.noIntegratedCPPOption = self.addOption(FlagOption('-no-integrated-cpp'))
466 self.pipeOption = self.addOption(FlagOption('-pipe'))
467 self.saveTempsOption = self.addOption(FlagOption('-save-temps'))
468 self.saveTempsOption2 = self.addOption(FlagOption('--save-temps'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000469 # FIXME: Error out if this is used.
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000470 self.addOption(JoinedOption('-specs='))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000471 # FIXME: Implement.
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000472 self.addOption(FlagOption('-time'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000473 # FIXME: Implement.
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000474 self.vOption = self.addOption(FlagOption('-v'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000475
476 # Input/output stuff
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000477 self.oOption = self.addOption(JoinedOrSeparateOption('-o', noOptAsInput=True))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000478 self.xOption = self.addOption(JoinedOrSeparateOption('-x'))
479
Daniel Dunbaree8cc262009-01-12 02:24:21 +0000480 self.ObjCOption = self.addOption(FlagOption('-ObjC'))
481 self.ObjCXXOption = self.addOption(FlagOption('-ObjC++'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000482
483 # FIXME: Weird, gcc claims this here in help but I'm not sure why;
484 # perhaps interaction with preprocessor? Investigate.
Daniel Dunbar816dd502009-01-12 17:53:19 +0000485
486 # FIXME: This is broken in Darwin cc1, it wants std* and this
487 # is std=. May need an option group for this as well.
488 self.stdOption = self.addOption(JoinedOption('-std='))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000489 self.addOption(JoinedOrSeparateOption('--sysroot'))
490
491 # Version control
492 self.addOption(JoinedOrSeparateOption('-B'))
493 self.addOption(JoinedOrSeparateOption('-V'))
494 self.addOption(JoinedOrSeparateOption('-b'))
495
496 # Blanket pass-through options.
497
Daniel Dunbar996ce962009-01-12 07:40:25 +0000498 self.WaOption = self.addOption(CommaJoinedOption('-Wa,'))
499 self.XassemblerOption = self.addOption(SeparateOption('-Xassembler'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000500
Daniel Dunbarb37c9652009-01-12 21:44:10 +0000501 self.WpOption = self.addOption(CommaJoinedOption('-Wp,'))
502 self.XpreprocessorOption = self.addOption(SeparateOption('-Xpreprocessor'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000503
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000504 self.addOption(CommaJoinedOption('-Wl,', isLinkerInput=True))
505 self.addOption(SeparateOption('-Xlinker', isLinkerInput=True, noOptAsInput=True))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000506
507 ####
508 # Bring on the random garbage.
509
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000510 self.MOption = self.addOption(FlagOption('-M'))
511 self.MDOption = self.addOption(FlagOption('-MD'))
512 self.MGOption = self.addOption(FlagOption('-MG'))
513 self.MMDOption = self.addOption(FlagOption('-MMD'))
514 self.MPOption = self.addOption(FlagOption('-MP'))
515 self.MMOption = self.addOption(FlagOption('-MM'))
516 self.MFOption = self.addOption(JoinedOrSeparateOption('-MF'))
517 self.MTOption = self.addOption(JoinedOrSeparateOption('-MT'))
518 self.MQOption = self.addOption(JoinedOrSeparateOption('-MQ'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000519 self.MachOption = self.addOption(FlagOption('-Mach'))
Daniel Dunbar816dd502009-01-12 17:53:19 +0000520 self.undefOption = self.addOption(FlagOption('-undef'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000521
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000522 self.wOption = self.addOption(FlagOption('-w'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000523 self.addOption(JoinedOrSeparateOption('-allowable_client'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000524 self.client_nameOption = self.addOption(JoinedOrSeparateOption('-client_name'))
525 self.compatibility_versionOption = self.addOption(JoinedOrSeparateOption('-compatibility_version'))
526 self.current_versionOption = self.addOption(JoinedOrSeparateOption('-current_version'))
527 self.dylinkerOption = self.addOption(FlagOption('-dylinker'))
528 self.dylinker_install_nameOption = self.addOption(JoinedOrSeparateOption('-dylinker_install_name'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000529 self.addOption(JoinedOrSeparateOption('-exported_symbols_list'))
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000530
531 self.iGroup = OptionGroup('-i')
532 self.addOption(JoinedOrSeparateOption('-idirafter', self.iGroup))
533 self.addOption(JoinedOrSeparateOption('-iquote', self.iGroup))
534 self.isysrootOption = self.addOption(JoinedOrSeparateOption('-isysroot', self.iGroup))
535 self.addOption(JoinedOrSeparateOption('-include', self.iGroup))
536 self.addOption(JoinedOption('-i', self.iGroup))
537
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000538 self.keep_private_externsOption = self.addOption(JoinedOrSeparateOption('-keep_private_externs'))
539 self.private_bundleOption = self.addOption(FlagOption('-private_bundle'))
540 self.seg1addrOption = self.addOption(JoinedOrSeparateOption('-seg1addr'))
541 self.segprotOption = self.addOption(JoinedOrSeparateOption('-segprot'))
542 self.sub_libraryOption = self.addOption(JoinedOrSeparateOption('-sub_library'))
543 self.sub_umbrellaOption = self.addOption(JoinedOrSeparateOption('-sub_umbrella'))
544 self.umbrellaOption = self.addOption(JoinedOrSeparateOption('-umbrella'))
545 self.undefinedOption = self.addOption(JoinedOrSeparateOption('-undefined'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000546 self.addOption(JoinedOrSeparateOption('-unexported_symbols_list'))
547 self.addOption(JoinedOrSeparateOption('-weak_framework'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000548 self.headerpad_max_install_namesOption = self.addOption(JoinedOption('-headerpad_max_install_names'))
549 self.twolevel_namespaceOption = self.addOption(FlagOption('-twolevel_namespace'))
550 self.twolevel_namespace_hintsOption = self.addOption(FlagOption('-twolevel_namespace_hints'))
551 self.prebindOption = self.addOption(FlagOption('-prebind'))
552 self.noprebindOption = self.addOption(FlagOption('-noprebind'))
553 self.nofixprebindingOption = self.addOption(FlagOption('-nofixprebinding'))
554 self.prebind_all_twolevel_modulesOption = self.addOption(FlagOption('-prebind_all_twolevel_modules'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000555 self.remapOption = self.addOption(FlagOption('-remap'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000556 self.read_only_relocsOption = self.addOption(SeparateOption('-read_only_relocs'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000557 self.addOption(FlagOption('-single_module'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000558 self.nomultidefsOption = self.addOption(FlagOption('-nomultidefs'))
559 self.nostartfilesOption = self.addOption(FlagOption('-nostartfiles'))
560 self.nodefaultlibsOption = self.addOption(FlagOption('-nodefaultlibs'))
561 self.nostdlibOption = self.addOption(FlagOption('-nostdlib'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000562 self.nostdincOption = self.addOption(FlagOption('-nostdinc'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000563 self.objectOption = self.addOption(FlagOption('-object'))
564 self.preloadOption = self.addOption(FlagOption('-preload'))
565 self.staticOption = self.addOption(FlagOption('-static'))
566 self.pagezero_sizeOption = self.addOption(FlagOption('-pagezero_size'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000567 self.addOption(FlagOption('-shared'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000568 self.staticLibgccOption = self.addOption(FlagOption('-static-libgcc'))
569 self.sharedLibgccOption = self.addOption(FlagOption('-shared-libgcc'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000570 self.COption = self.addOption(FlagOption('-C'))
571 self.CCOption = self.addOption(FlagOption('-CC'))
572 self.HOption = self.addOption(FlagOption('-H'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000573 self.addOption(FlagOption('-R'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000574 self.POption = self.addOption(FlagOption('-P'))
575 self.QOption = self.addOption(FlagOption('-Q'))
Daniel Dunbar816dd502009-01-12 17:53:19 +0000576 self.QnOption = self.addOption(FlagOption('-Qn'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000577 self.addOption(FlagOption('-all_load'))
578 self.addOption(FlagOption('--constant-cfstrings'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000579 self.traditionalOption = self.addOption(FlagOption('-traditional'))
580 self.traditionalCPPOption = self.addOption(FlagOption('-traditional-cpp'))
581 # FIXME: Alias.
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000582 self.addOption(FlagOption('--traditional'))
583 self.addOption(FlagOption('-no_dead_strip_inits_and_terms'))
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000584 self.addOption(JoinedOption('-weak-l', isLinkerInput=True))
585 self.addOption(SeparateOption('-weak_framework', isLinkerInput=True))
586 self.addOption(SeparateOption('-weak_library', isLinkerInput=True))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000587 self.whyloadOption = self.addOption(FlagOption('-whyload'))
588 self.whatsloadedOption = self.addOption(FlagOption('-whatsloaded'))
589 self.sectalignOption = self.addOption(MultiArgOption('-sectalign', numArgs=3))
590 self.sectobjectsymbolsOption = self.addOption(MultiArgOption('-sectobjectsymbols', numArgs=2))
591 self.segcreateOption = self.addOption(MultiArgOption('-segcreate', numArgs=3))
592 self.segs_read_Option = self.addOption(JoinedOption('-segs_read_'))
593 self.seglinkeditOption = self.addOption(FlagOption('-seglinkedit'))
594 self.noseglinkeditOption = self.addOption(FlagOption('-noseglinkedit'))
595 self.sectcreateOption = self.addOption(MultiArgOption('-sectcreate', numArgs=3))
596 self.sectorderOption = self.addOption(MultiArgOption('-sectorder', numArgs=3))
597 self.Zall_loadOption = self.addOption(FlagOption('-Zall_load'))
598 self.Zallowable_clientOption = self.addOption(SeparateOption('-Zallowable_client'))
599 self.Zbind_at_loadOption = self.addOption(SeparateOption('-Zbind_at_load'))
600 self.ZbundleOption = self.addOption(FlagOption('-Zbundle'))
601 self.Zbundle_loaderOption = self.addOption(JoinedOrSeparateOption('-Zbundle_loader'))
602 self.Zdead_stripOption = self.addOption(FlagOption('-Zdead_strip'))
603 self.Zdylib_fileOption = self.addOption(JoinedOrSeparateOption('-Zdylib_file'))
604 self.ZdynamicOption = self.addOption(FlagOption('-Zdynamic'))
605 self.ZdynamiclibOption = self.addOption(FlagOption('-Zdynamiclib'))
606 self.Zexported_symbols_listOption = self.addOption(JoinedOrSeparateOption('-Zexported_symbols_list'))
607 self.Zflat_namespaceOption = self.addOption(FlagOption('-Zflat_namespace'))
608 self.Zfn_seg_addr_table_filenameOption = self.addOption(JoinedOrSeparateOption('-Zfn_seg_addr_table_filename'))
609 self.Zforce_cpusubtype_ALLOption = self.addOption(FlagOption('-Zforce_cpusubtype_ALL'))
610 self.Zforce_flat_namespaceOption = self.addOption(FlagOption('-Zforce_flat_namespace'))
611 self.Zimage_baseOption = self.addOption(FlagOption('-Zimage_base'))
612 self.ZinitOption = self.addOption(JoinedOrSeparateOption('-Zinit'))
613 self.Zmulti_moduleOption = self.addOption(FlagOption('-Zmulti_module'))
614 self.Zmultiply_definedOption = self.addOption(JoinedOrSeparateOption('-Zmultiply_defined'))
615 self.ZmultiplydefinedunusedOption = self.addOption(JoinedOrSeparateOption('-Zmultiplydefinedunused'))
616 self.ZmultiplydefinedunusedOption = self.addOption(JoinedOrSeparateOption('-Zmultiplydefinedunused'))
617 self.Zno_dead_strip_inits_and_termsOption = self.addOption(FlagOption('-Zno_dead_strip_inits_and_terms'))
618 self.Zseg_addr_tableOption = self.addOption(JoinedOrSeparateOption('-Zseg_addr_table'))
619 self.ZsegaddrOption = self.addOption(JoinedOrSeparateOption('-Zsegaddr'))
620 self.Zsegs_read_only_addrOption = self.addOption(JoinedOrSeparateOption('-Zsegs_read_only_addr'))
621 self.Zsegs_read_write_addrOption = self.addOption(JoinedOrSeparateOption('-Zsegs_read_write_addr'))
622 self.Zsingle_moduleOption = self.addOption(FlagOption('-Zsingle_module'))
Daniel Dunbar0fe5a4f2009-01-11 22:42:24 +0000623 self.ZumbrellaOption = self.addOption(JoinedOrSeparateOption('-Zumbrella'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000624 self.Zunexported_symbols_listOption = self.addOption(JoinedOrSeparateOption('-Zunexported_symbols_list'))
625 self.Zweak_reference_mismatchesOption = self.addOption(JoinedOrSeparateOption('-Zweak_reference_mismatches'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000626
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000627 self.addOption(SeparateOption('-filelist', isLinkerInput=True))
628 self.addOption(SeparateOption('-framework', isLinkerInput=True))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000629 # FIXME: Alias.
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000630 self.addOption(SeparateOption('-install_name'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000631 self.Zinstall_nameOption = self.addOption(JoinedOrSeparateOption('-Zinstall_name'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000632 self.addOption(SeparateOption('-seg_addr_table'))
633 self.addOption(SeparateOption('-seg_addr_table_filename'))
634
635 # Where are these coming from? I can't find them...
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000636 self.eOption = self.addOption(JoinedOrSeparateOption('-e'))
637 self.rOption = self.addOption(JoinedOrSeparateOption('-r'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000638
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000639 self.pgOption = self.addOption(FlagOption('-pg'))
Daniel Dunbar816dd502009-01-12 17:53:19 +0000640 self.pOption = self.addOption(FlagOption('-p'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000641
642 doNotReallySupport = 1
643 if doNotReallySupport:
644 # Archaic gcc option.
645 self.addOption(FlagOption('-cpp-precomp'))
646 self.addOption(FlagOption('-no-cpp-precomp'))
647
648 # C options for testing
649
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000650 # FIXME: This is broken, we need -A as a single option to send
651 # stuff to cc1, but the way the ld spec is constructed it
652 # wants to see -A options but only as a separate arg.
653 self.AOption = self.addOption(JoinedOrSeparateOption('-A'))
654 self.DOption = self.addOption(JoinedOrSeparateOption('-D'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000655 self.FOption = self.addOption(JoinedOrSeparateOption('-F'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000656 self.IOption = self.addOption(JoinedOrSeparateOption('-I'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000657 self.LOption = self.addOption(JoinedOrSeparateOption('-L'))
658 self.TOption = self.addOption(JoinedOrSeparateOption('-T'))
Daniel Dunbar6325fcf2009-01-12 09:23:15 +0000659 self.UOption = self.addOption(JoinedOrSeparateOption('-U'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000660 self.ZOption = self.addOption(JoinedOrSeparateOption('-Z'))
661
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000662 self.addOption(JoinedOrSeparateOption('-l', isLinkerInput=True))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000663 self.uOption = self.addOption(JoinedOrSeparateOption('-u'))
664 self.tOption = self.addOption(JoinedOrSeparateOption('-t'))
665 self.yOption = self.addOption(JoinedOption('-y'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000666
667 # FIXME: What is going on here? '-X' goes to linker, and -X ... goes nowhere?
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000668 self.XOption = self.addOption(FlagOption('-X'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000669 # Not exactly sure how to decompose this. I split out -Xarch_
670 # because we need to recognize that in the driver driver part.
671 # FIXME: Man, this is lame it needs its own option.
672 self.XarchOption = self.addOption(JoinedAndSeparateOption('-Xarch_'))
673 self.addOption(JoinedOption('-X'))
674
675 # The driver needs to know about this flag.
676 self.syntaxOnlyOption = self.addOption(FlagOption('-fsyntax-only'))
677
678 # FIXME: Wrong?
679 # FIXME: What to do about the ambiguity of options like
680 # -dumpspecs? How is this handled in gcc?
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000681 # FIXME: Naming convention.
682 self.dOption = self.addOption(FlagOption('-d'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000683
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000684 # Use a group for this in anticipation of adding more -d
685 # options explicitly. Note that we don't put many -d things in
686 # the -d group (like -dylinker, or '-d' by itself) because it
687 # is really a gcc bug that it ships these to cc1.
688 self.dGroup = OptionGroup('-d')
689 self.addOption(JoinedOption('-d', group=self.dGroup))
Daniel Dunbar996ce962009-01-12 07:40:25 +0000690
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000691 self.gGroup = OptionGroup('-g')
692 self.g3Option = self.addOption(JoinedOption('-g3', self.gGroup))
693 self.gOption = self.addOption(JoinedOption('-g', self.gGroup))
Daniel Dunbar816dd502009-01-12 17:53:19 +0000694
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000695 self.fGroup = OptionGroup('-f')
696 self.fastOption = self.addOption(FlagOption('-fast', self.fGroup))
697 self.fastfOption = self.addOption(FlagOption('-fastf', self.fGroup))
698 self.fastcpOption = self.addOption(FlagOption('-fastcp', self.fGroup))
699
700 self.f_appleKextOption = self.addOption(FlagOption('-fapple-kext', self.fGroup))
701 self.f_noEliminateUnusedDebugSymbolsOption = self.addOption(FlagOption('-fno-eliminate-unused-debug-symbols', self.fGroup))
702 self.f_exceptionsOption = self.addOption(FlagOption('-fexceptions', self.fGroup))
703 self.f_objcOption = self.addOption(FlagOption('-fobjc', self.fGroup))
704 self.f_openmpOption = self.addOption(FlagOption('-fopenmp', self.fGroup))
705 self.f_gnuRuntimeOption = self.addOption(FlagOption('-fgnu-runtime', self.fGroup))
706 self.f_mudflapOption = self.addOption(FlagOption('-fmudflap', self.fGroup))
707 self.f_mudflapthOption = self.addOption(FlagOption('-fmudflapth', self.fGroup))
708 self.f_nestedFunctionsOption = self.addOption(FlagOption('-fnested-functions', self.fGroup))
709 self.f_pieOption = self.addOption(FlagOption('-fpie', self.fGroup))
710 self.f_profileArcsOption = self.addOption(FlagOption('-fprofile-arcs', self.fGroup))
711 self.f_profileGenerateOption = self.addOption(FlagOption('-fprofile-generate', self.fGroup))
712 self.f_createProfileOption = self.addOption(FlagOption('-fcreate-profile', self.fGroup))
713 self.f_traditionalOption = self.addOption(FlagOption('-ftraditional', self.fGroup))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000714 self.coverageOption = self.addOption(FlagOption('-coverage'))
715 self.coverageOption2 = self.addOption(FlagOption('--coverage'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000716 self.addOption(JoinedOption('-f'))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000717
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000718 self.mGroup = OptionGroup('-m')
719 self.m_32Option = self.addOption(FlagOption('-m32', self.mGroup))
720 self.m_64Option = self.addOption(FlagOption('-m64', self.mGroup))
721 self.m_dynamicNoPicOption = self.addOption(JoinedOption('-mdynamic-no-pic', self.mGroup))
722 self.m_iphoneosVersionMinOption = self.addOption(JoinedOption('-miphoneos-version-min=', self.mGroup))
723 self.m_kernelOption = self.addOption(FlagOption('-mkernel', self.mGroup))
724 self.m_macosxVersionMinOption = self.addOption(JoinedOption('-mmacosx-version-min=', self.mGroup))
725 self.m_tuneOption = self.addOption(JoinedOption('-mtune=', self.mGroup))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000726
727 # Ugh. Need to disambiguate our naming convetion. -m x goes to
728 # the linker sometimes, wheres -mxxxx is used for a variety of
729 # other things.
730 self.mOption = self.addOption(SeparateOption('-m'))
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000731 self.addOption(JoinedOption('-m', self.mGroup))
Daniel Dunbar6f5d65a2009-01-11 22:12:37 +0000732
Daniel Dunbar8bf90fd2009-01-13 05:54:38 +0000733 # FIXME: Why does Darwin send -a* to cc1?
734 self.aGroup = OptionGroup('-a')
735 self.ansiOption = self.addOption(FlagOption('-ansi', self.aGroup))
736 self.aOption = self.addOption(JoinedOption('-a', self.aGroup))
737
Daniel Dunbar816dd502009-01-12 17:53:19 +0000738 self.trigraphsOption = self.addOption(FlagOption('-trigraphs'))
739 self.pedanticOption = self.addOption(FlagOption('-pedantic'))
Daniel Dunbar816dd502009-01-12 17:53:19 +0000740 self.OOption = self.addOption(JoinedOption('-O'))
741 self.WOption = self.addOption(JoinedOption('-W'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000742 # FIXME: Weird. This option isn't really separate, --param=a=b
Daniel Dunbar816dd502009-01-12 17:53:19 +0000743 # works. There is something else going on which interprets the
744 # '='.
745 self._paramOption = self.addOption(SeparateOption('--param'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000746
Daniel Dunbardff9f502009-01-12 18:51:02 +0000747 # FIXME: What is this? I think only one is valid, but have a
748 # log that uses both.
749 self.pthreadOption = self.addOption(FlagOption('-pthread'))
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000750 self.addOption(FlagOption('-pthreads'))
751
Daniel Dunbara5677512009-01-05 19:53:30 +0000752 def addOption(self, opt):
753 self.options.append(opt)
Daniel Dunbarba6e3232009-01-06 06:12:13 +0000754 return opt
Daniel Dunbara5677512009-01-05 19:53:30 +0000755
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000756 def parseArgs(self, argv):
Daniel Dunbara5677512009-01-05 19:53:30 +0000757 """
Daniel Dunbar1e5f3eb2009-01-06 01:35:44 +0000758 parseArgs([str]) -> ArgList
Daniel Dunbara5677512009-01-05 19:53:30 +0000759
760 Parse command line into individual option instances.
761 """
762
763 iargs = enumerate(argv)
764 it = iter(iargs)
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000765 args = ArgList(self, argv)
Daniel Dunbarefb4aeb2009-01-07 01:57:39 +0000766 for pos,a in it:
767 i = InputIndex(0, pos)
Daniel Dunbara5677512009-01-05 19:53:30 +0000768 # FIXME: Handle '@'
769 if not a:
770 # gcc's handling of empty arguments doesn't make
771 # sense, but this is not a common use case. :)
772 #
773 # We just ignore them here (note that other things may
774 # still take them as arguments).
775 pass
776 elif a[0] == '-' and a != '-':
777 args.append(self.lookupOptForArg(i, a, it))
778 else:
Daniel Dunbar5039f212009-01-06 02:30:10 +0000779 args.append(PositionalArg(i, self.inputOption))
Daniel Dunbara5677512009-01-05 19:53:30 +0000780 return args
781
Daniel Dunbar5039f212009-01-06 02:30:10 +0000782 def lookupOptForArg(self, i, string, it):
783 for o in self.options:
784 arg = o.accept(i, string, it)
785 if arg is not None:
786 return arg
787 return PositionalArg(i, self.unknownOption)