def __init__(self, line): Definition.__init__( self, line, '([a-zA-Z_][a-zA-Z0-9_]*)(|\\[.+\\])/([^ ]+)Ref(?:|/([!m]+))$') self.refname = self.matches.group(1) arrdef = self.matches.group(2) self.objname = self.matches.group(3) try: objdef = PhysicsObject.get(self.objname) except KeyError: raise Definition.NoMatch() if objdef.is_singlet(): raise RuntimeError('Cannot create reference to single object ' + objdef.name) modifier = self.matches.group(4) if modifier is None: mod = '' else: mod = '/' + modifier # create a branch for the index with name {name}_ Branch.__init__( self, '{name}_{arrdef}/S{mod} = -1'.format(name=self.refname, arrdef=arrdef, mod=mod))
def __init__(self, line, source): """ Argument: re match object """ Definition.__init__( self, line, '\\[([A-Z][a-zA-Z0-9]+)(>[A-Z][a-zA-Z0-9]+|)(\\:SINGLE|)\\] *$') PhysicsObject._known_objects.append(self) # is this a singlet? if self.matches.group(3) == ':SINGLE': self.parent = 'Singlet' self._singlet = True else: self.parent = 'Element' self._singlet = False # if >parent is present, update the parent class name if self.matches.group(2): self.parent = self.matches.group(2)[1:] self._singlet = None Object.__init__(self, self.matches.group(1), source) if len([f for f in self.functions if f.is_pure_virtual]) == 0: self.instantiable = True else: self.instantiable = False
def __init__(self, line, source): """ Argument: re match object """ Definition.__init__(self, line, '<([A-Z][a-zA-Z0-9]+)>$') Object.__init__(self, self.matches.group(1), source)
def __init__(self, line): Definition.__init__( self, line, '([a-zA-Z_][a-zA-Z0-9_]*)/([^ \\(]+)(\\([0-9]+\\)|)$') self.name = self.matches.group(1) self.objname = self.matches.group(2) if self.objname.endswith('Collection'): self.objname = self.objname.replace('Collection', '') self.conttype = 'Collection' elif self.objname.endswith('Array'): self.objname = self.objname.replace('Array', '') self.conttype = 'Array' else: self.conttype = '' self.init_size = self.matches.group(3).strip('()') try: # is this a valid object? objdef = PhysicsObject.get(self.objname) except KeyError: raise Definition.NoMatch() if objdef.is_singlet() and (self.conttype != '' or self.init_size != ''): raise RuntimeError('Cannot create container of object ' + objdef.name) if self.conttype == 'Array' and self.init_size == '': raise RuntimeError('Array object ' + objdef.name + ' needs a size')
def __init__(self, line, source): Definition.__init__(self, line, '\\{([A-Z][a-zA-Z0-9]+)(>[A-Z][a-zA-Z0-9]+|)\\}$') Object.__init__(self, self.matches.group(1), source) if self.matches.group(2): self.parent = self.matches.group(2)[1:] else: self.parent = 'TreeEntry'
def __init__(self, line, source): Definition.__init__(self, line, '\\{([A-Z][a-zA-Z0-9]+)(>[A-Z][a-zA-Z0-9]+|)\\}$') Object.__init__(self, self.matches.group(1), source) Inheritable.__init__(self) Tree._known_objects.append(self) if self.matches.group(2): self.parent = self.matches.group(2)[1:] else: self.parent = 'TreeEntry'
def __init__(self, line): Definition.__init__( self, line, '(?:static +|)(?:const +([^ ]+)|([^ ]+) +const) +([a-zA-Z0-9_]+(?:\[[^\]]+\])*)(.*);' ) self.type = self.matches.group(1) if self.type is None: self.type = self.matches.group(2) self.decl = self.matches.group(3) self.value = self.matches.group(4)
def __init__(self, line): Definition.__init__( self, line, '([a-zA-Z_][a-zA-Z0-9_]*)(|\\[.+\\])/([^ /]+)(?:|/([!m]+))(?:| += +([a-zA-Z0-9_.-]+))(?:| *( //.+))$' ) self.type = self.matches.group(3) if self.type not in Branch.TYPE_MAP: raise Definition.NoMatch() self.name = self.matches.group(1) # is this an array branch? arrdef = self.matches.group(2) if arrdef: self.arrdef = arrdef.strip('[]').split('][') else: self.arrdef = [] self.modifier = self.matches.group(4) if self.modifier is None: self.modifier = '' self.init = self.matches.group(5) # used in decl if self.init is None: self.init = '' # initializer: used in init() if self.init: init = self.init elif self.type == 'O': init = 'false' elif self.type in 'FD': init = '0.' else: init = '0' if self.is_array(): self.initializer = '' arr = self.name for iarr in range(len(self.arrdef)): self.initializer += 'for (auto& p{iarr} : {arr}) '.format( iarr=iarr, arr=arr) arr = 'p{iarr}'.format(iarr=iarr) self.initializer += 'p{iarr} = {init};'.format(iarr=iarr, init=init) else: self.initializer = '{name} = {init};'.format(name=self.name, init=init) self.comment = self.matches.group(6) if self.comment is None: self.comment = ''
def __init__(self, line): Definition.__init__( self, line, '([a-zA-Z_][a-zA-Z0-9_]*)(|\\[.+\\])/([^ ]+)(?:|/([!m]+))(?:| += +(.*))$' ) self.name = self.matches.group(1) # is this an array branch? arrdef = self.matches.group(2) if arrdef: self.arrdef = arrdef.strip('[]').split('][') else: self.arrdef = [] self.type = self.matches.group(3) for dim in reversed(self.arrdef): self.type = 'std::array<{type}, {dim}>'.format(type=self.type, dim=dim) self.modifier = self.matches.group(4) if self.modifier is None: self.modifier = '' self.init = self.matches.group(5) # used in decl if self.init is None: self.init = '' # initializer: used in init() if self.init: init = self.init else: init = '{type}()'.format(type=self.matches.group(3)) if self.is_array(): self.initializer = '' arr = '*{name}'.format(name=self.name) for iarr in range(len(self.arrdef)): self.initializer += 'for (auto& p{iarr} : {arr}) '.format( iarr=iarr, arr=arr) arr = 'p{iarr}'.format(iarr=iarr) self.initializer += 'p{iarr} = {init};'.format(iarr=iarr, init=init) else: self.initializer = '*{name} = {init};'.format(name=self.name, init=init)
def __init__(self, line, source): Definition.__init__( self, line, '(?:static +|)(?:const +([^ ]+)|([^ ]+) +const) +([a-zA-Z0-9_]+(?:\[[^\]]+\])*)([^\(\)]+)$' ) self.type = self.matches.group(1) if self.type is None: self.type = self.matches.group(2) self.decl = self.matches.group(3) self.value = self.matches.group(4) # if value ends with semicolon in one line, either the value must be given in the .cc file or is given by a one-liner init expression if not self.value.endswith(';'): # we are in the middle of a multi-line brace-init expression self.value += '\n' depth = self.value.count('{') - self.value.count('}') while True: line = source.readline() if line == '': break self.value += line depth += line.count('{') depth -= line.count('}') if depth == 0: break self.value = self.value[:-1] # last character is \n if not self.value.endswith(';'): raise RuntimeError( 'Const expression %s %s did not end with a semicolon' % (self.type, self.decl)) # remove the trailing semicolon self.value = self.value[:-1]
def __init__(self, line, source): Definition.__init__( self, line, '((?:virtual +|static +|)([^\(]+) +([^ \(]+\([^\)]*\)(?: +const|))(?: +override|))(.*)' ) self.decl = self.matches.group( 1) # includes virtual/static, const, override self.type = self.matches.group(2) # return type self.signature = self.matches.group(3) # function name and arguments self.impl = self.matches.group(4).strip() if re.match('^ *= *0 *;$', self.impl): self.is_pure_virtual = True else: self.is_pure_virtual = False if self.impl.endswith(';'): # implementation must be given by hand in the .cc file return depth = self.impl.count('{') - self.impl.count('}') if self.impl != '' and depth == 0: # a one-liner return while True: line = source.readline() if line == '': break self.impl += line depth += line.count('{') depth -= line.count('}') if depth == 0: break
def __init__(self, line, source): Definition.__init__(self, line, 'enum *([^ ]+) *\\{') self.name = self.matches.group(1) if type(source) is list: # a list is already given self.elements = source else: # otherwise parse the source text self.elements = [] while True: line = source.readline() if line == '': break if line.strip().startswith('}'): break for elem in line.strip().split(','): elem = elem.strip() if elem: self.elements.append(elem) # last entry is always n{name}s (e.g. enum Trigger -> nTriggers) last_name = 'n' + self.name if last_name.endswith('y'): last_name = last_name[:-1] + 'ies' elif last_name.endswith('s') or last_name.endswith( 'x') or last_name.endswith('z'): last_name += 'es' else: last_name += 's' self.elements.append(last_name)
def __init__(self, line): Definition.__init__( self, line, '([a-zA-Z_][a-zA-Z0-9_]*)/([^ \\(]+)(\\([0-9]+\\)|)( *//.+=.+)?$') self.name = self.matches.group(1) self.objname = self.matches.group(2) if self.matches.group(4): self.comment = self.matches.group(4) self.modifiers = dict([ x.split('=') for x in self.matches.group(4).replace('//', '').split() ]) else: self.comment = '' self.modifiers = {} if self.objname.endswith('Collection'): self.objname = self.objname.replace('Collection', '') self.conttype = 'Collection' elif self.objname.endswith('Array'): self.objname = self.objname.replace('Array', '') self.conttype = 'Array' else: self.conttype = '' self.init_size = self.matches.group(3).strip('()') try: # is this a valid object? objdef = next(o for o in PhysicsObject._known_objects if o.name == self.objname) except StopIteration: raise Definition.NoMatch() if self.conttype == 'Array' and self.init_size == '': raise RuntimeError('Array object ' + objdef.name + ' needs a size')
def __init__(self, line, pattern): Definition.__init__(self, line, pattern) self.code = line.strip()
def __init__(self, line): Definition.__init__(self, line, '([^ ]+)->([^ ]+)') self.ref_name = self.matches.group(1).split('.') self.target = self.matches.group(2)
def __init__(self, line): Definition.__init__(self, line, 'ASSERT +(.+)')