declarations.py

来自「Boost provides free peer-reviewed portab」· Python 代码 · 共 654 行 · 第 1/2 页

PY
654
字号
    '''A class' constructor.    '''    def __init__(self, name, class_, params, visib):        Method.__init__(self, name, class_, None, params, visib, False, False, False, False)    def IsDefault(self):        '''Returns True if this constructor is a default constructor.        '''        return len(self.parameters) == 0 and self.visibility == Scope.public    def IsCopy(self):        '''Returns True if this constructor is a copy constructor.        '''        if len(self.parameters) != 1:            return False        param = self.parameters[0]        class_as_param = self.parameters[0].name == self.class_        param_reference = isinstance(param, ReferenceType)         is_public = self.visibility == Scope.public        return param_reference and class_as_param and param.const and is_public            def PointerDeclaration(self, force=False):        return ''#==============================================================================# Destructor#==============================================================================class Destructor(Method):    'The destructor of a class.'    def __init__(self, name, class_, visib, virtual):        Method.__init__(self, name, class_, None, [], visib, virtual, False, False, False)    def FullName(self):        return self.class_ + '::~' + self.name    def PointerDeclaration(self, force=False):        return ''#==============================================================================# ClassOperator#==============================================================================class ClassOperator(Method):    'A custom operator in a class.'        def FullName(self):        return self.class_ + '::operator ' + self.name#==============================================================================# ConverterOperator#==============================================================================class ConverterOperator(ClassOperator):    'An operator in the form "operator OtherClass()".'        def FullName(self):        return self.class_ + '::operator ' + self.result.FullName()    #==============================================================================# Type#==============================================================================class Type(Declaration):    '''Represents the type of a variable or parameter.    @ivar _const: if the type is constant.    @ivar _default: if this type has a default value associated with it.    @ivar _volatile: if this type was declared with the keyword volatile.    @ivar _restricted: if this type was declared with the keyword restricted.    @ivar _suffix: Suffix to get the full type name. '*' for pointers, for    example.    '''    def __init__(self, name, const=False, default=None, suffix=''):        Declaration.__init__(self, name, None)        # whatever the type is constant or not        self.const = const        # used when the Type is a function argument        self.default = default        self.volatile = False        self.restricted = False        self.suffix = suffix    def __repr__(self):        if self.const:            const = 'const '        else:            const = ''        return '<Type ' + const + self.name + '>'    def FullName(self):        if self.const:            const = 'const '        else:            const = ''        return const + self.name + self.suffix#==============================================================================# ArrayType#==============================================================================class ArrayType(Type):    '''Represents an array.    @ivar min: the lower bound of the array, usually 0. Can be None.    @ivar max: the upper bound of the array. Can be None.    '''    def __init__(self, name, const, min, max):         'min and max can be None.'        Type.__init__(self, name, const)        self.min = min        self.max = max        #==============================================================================# ReferenceType    #==============================================================================class ReferenceType(Type):     '''A reference type.'''    def __init__(self, name, const=False, default=None, expandRef=True, suffix=''):        Type.__init__(self, name, const, default)        if expandRef:            self.suffix = suffix + '&'                #==============================================================================# PointerType#==============================================================================class PointerType(Type):    'A pointer type.'        def __init__(self, name, const=False, default=None, expandPointer=False, suffix=''):        Type.__init__(self, name, const, default)        if expandPointer:            self.suffix = suffix + '*'   #==============================================================================# FundamentalType#==============================================================================class FundamentalType(Type):     'One of the fundamental types, like int, void, etc.'    def __init__(self, name, const=False, default=None):         Type.__init__(self, name, const, default)#==============================================================================# FunctionType#==============================================================================class FunctionType(Type):    '''A pointer to a function.    @ivar _result: the return value    @ivar _parameters: a list of Types, indicating the parameters of the function.    @ivar _name: the name of the function.    '''    def __init__(self, result, parameters):          Type.__init__(self, '', False)        self.result = result        self.parameters = parameters        self.name = self.FullName()    def FullName(self):        full = '%s (*)' % self.result.FullName()        params = [x.FullName() for x in self.parameters]        full += '(%s)' % ', '.join(params)                return full        #==============================================================================# MethodType#==============================================================================class MethodType(FunctionType):    '''A pointer to a member function of a class.    @ivar _class: The fullname of the class that the method belongs to.    '''    def __init__(self, result, parameters, class_):          self.class_ = class_        FunctionType.__init__(self, result, parameters)    def FullName(self):        full = '%s (%s::*)' % (self.result.FullName(), self.class_)        params = [x.FullName() for x in self.parameters]        full += '(%s)' % ', '.join(params)        return full         #==============================================================================# Variable#==============================================================================class Variable(Declaration):    '''Represents a global variable.    @type _type: L{Type}    @ivar _type: The type of the variable.    '''        def __init__(self, type, name, namespace):        Declaration.__init__(self, name, namespace)        self.type = type#==============================================================================# ClassVariable#==============================================================================class ClassVariable(Variable):    '''Represents a class variable.    @type _visibility: L{Scope}    @ivar _visibility: The visibility of this variable within the class.    @type _static: bool    @ivar _static: Indicates if the variable is static.    @ivar _class: Full name of the class that this variable belongs to.    '''    def __init__(self, type, name, class_, visib, static):        Variable.__init__(self, type, name, None)        self.visibility = visib        self.static = static        self.class_ = class_        def FullName(self):        return self.class_ + '::' + self.name        #==============================================================================# Enumeration    #==============================================================================class Enumeration(Declaration):    '''Represents an enum.    @type _values: dict of str => int    @ivar _values: holds the values for this enum.    '''        def __init__(self, name, namespace):        Declaration.__init__(self, name, namespace)        self.values = {} # dict of str => int    def ValueFullName(self, name):        '''Returns the full name for a value in the enum.        '''        assert name in self.values        namespace = self.namespace        if namespace:            namespace += '::'        return namespace + name#==============================================================================# ClassEnumeration#==============================================================================class ClassEnumeration(Enumeration):    '''Represents an enum inside a class.    @ivar _class: The full name of the class where this enum belongs.    @ivar _visibility: The visibility of this enum inside his class.    '''    def __init__(self, name, class_, visib):        Enumeration.__init__(self, name, None)        self.class_ = class_        self.visibility = visib    def FullName(self):        return '%s::%s' % (self.class_, self.name)    def ValueFullName(self, name):        assert name in self.values        return '%s::%s' % (self.class_, name)    #==============================================================================# Typedef#==============================================================================class Typedef(Declaration):    '''A Typedef declaration.    @type _type: L{Type}    @ivar _type: The type of the typedef.    @type _visibility: L{Scope}    @ivar _visibility: The visibility of this typedef.    '''    def __init__(self, type, name, namespace):        Declaration.__init__(self, name, namespace)        self.type = type        self.visibility = Scope.public                          #==============================================================================# Unknown        #==============================================================================class Unknown(Declaration):    '''A declaration that Pyste does not know how to handle.    '''    def __init__(self, name):        Declaration.__init__(self, name, None)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?