import os
###
class InvalidArgumentsError(ValueError):
"""InvalidArgumentsError - The driver arguments are invalid or
inconsistent."""
class MissingArgumentError(ValueError):
"""MissingArgumentError - An option required an argument but none
was given."""
###
class Option(object):
"""Option - Root option class."""
def __init__(self, name, group=None, alias=None,
isLinkerInput=False, noOptAsInput=False,
forceSeparateRender=False,
forceJoinedRender=False,
unsupported=False):
assert group is None or isinstance(group, OptionGroup)
# Multi-level aliases are not supported, and alias options
# cannot have groups. This just simplifies option tracking, it
# is not an inherent limitation.
assert alias is None or (alias.alias is None and
group is None)
self.name = name
self.group = group
self.alias = alias
self.isLinkerInput = isLinkerInput
self.noOptAsInput = noOptAsInput
self.forceSeparateRender = forceSeparateRender
self.forceJoinedRender = forceJoinedRender
self.unsupported = unsupported
def getUnaliasedOption(self):
if self.alias:
return self.alias.getUnaliasedOption()
return self
def getRenderName(self):
return self.getUnaliasedOption().name
def matches(self, opt):
"""matches(opt) -> bool
Predicate for whether this option is part of the given option
(which may be a group)."""
if self.alias:
return self.alias.matches(opt)
if self is opt:
return True
elif self.group:
return self.group.matches(opt)
else:
return False
def accept(self, index, arg, it):
"""accept(index, arg, iterator) -> Arg or None
Accept the argument at the given index, returning an Arg, or
return None if the option does not accept this argument.
May raise MissingArgumentError.
"""
abstract
def __repr__(self):
return '<%s name=%r>' % (self.__class__.__name__,
self.name)
def forwardToGCC(self):
# FIXME: Get rid of this hack.
if self.name == '<input>':
return False
if self.isLinkerInput:
return False
return self.name not in ('-E', '-S', '-c',
'-arch', '-fsyntax-only', '-combine', '-x',
'-###', '-o')
class OptionGroup(Option):
"""OptionGroup - A fake option class used to group options so that
the driver can efficiently refer to an entire set of options."""
def __init__(self, name, group=None):
super(OptionGroup, self).__init__(name, group)
def accept(self, index, arg, it):
raise RuntimeError,"accept() should never be called on an OptionGroup"
# Dummy options
class InputOption(Option):
def __init__(self):
super(InputOption, self).__init__('<input>')
def accept(self):
raise RuntimeError,"accept() should never be used on InputOption instance."
class UnknownOption(Option):
def __init__(self):
super(UnknownOption, self).__init__('<unknown>')
def accept(self):
raise RuntimeError,"accept() should never be used on UnknownOption instance."
# Normal options
class FlagOption(Option):
"""An option which takes no arguments."""
def accept(self, index, arg, it):
if arg == self.name:
return Arg(index, self)
class JoinedOption(Option):
"""An option which literally prefixes its argument."""
def accept(self, index, arg, it):
if arg.startswith(self.name):
return JoinedValueArg(index, self)
class CommaJoinedOption(Option):
"""An option which literally prefixs its argument, but which
conceptually may have an arbitrary number of arguments which are
separated by commas."""
def accept(