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): 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): 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_]*)/([^ \\(]+)(\\([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')