#NEWLINE# def prepare( self ) : #NEWLINE# #INDENT# config = self . config #NEWLINE# lib = self . library #NEWLINE# for fileName in config . get ( 'apiheaders' , [ ] ) : #NEWLINE# #INDENT# Log . notice ( ( "Parsing functions from '%s'." % fileName ) ) #NEWLINE# source = self . parserTool . readSource ( fileName ) #NEWLINE# newLib = Parser . parseSource ( source ) #NEWLINE# for f in newLib . functions . values ( ) : #NEWLINE# #INDENT# f . headerName = fileName #NEWLINE# #UNINDENT# for f in newLib . functions . values ( ) : #NEWLINE# #INDENT# Log . debug ( ( '%s %s(%s)' % ( f . type , f . name , ', ' . join ( [ ( '%s %s' % ( t . type , p ) ) for ( p , t ) in f . parameters . items ( ) ] ) ) ) ) #NEWLINE# #UNINDENT# if ( not newLib . functions ) : #NEWLINE# #INDENT# Log . warn ( 'No new functions found.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# Log . notice ( ( '%d functions found.' % len ( newLib . functions ) ) ) #NEWLINE# #UNINDENT# lib . merge ( newLib ) #NEWLINE# #UNINDENT# self . parserTool . loadHooks ( ) #NEWLINE# def parseBool( s ) : #NEWLINE# #INDENT# return bool ( int ( s ) ) #NEWLINE# #UNINDENT# for ( typeDecl , mapping ) in self . config . types . items ( ) : #NEWLINE# #INDENT# attrs = self . config . types [ typeDecl ] . attrs #NEWLINE# ( name , type ) = Parser . parseVariableDeclaration ( ( typeDecl + ' dummy' ) ) #NEWLINE# assert ( name == 'dummy' ) #NEWLINE# if ( mapping == 'object' ) : #NEWLINE# #INDENT# if ( not ( mapping in self . library . classes ) ) : #NEWLINE# #INDENT# cls = Library . Class ( type ) #NEWLINE# if ( 'namespace' in attrs ) : #NEWLINE# #INDENT# cls . namespacePath = attrs [ 'namespace' ] . split ( '.' ) #NEWLINE# #UNINDENT# self . library . classes [ type ] = cls #NEWLINE# #UNINDENT# #UNINDENT# if ( 'decorationhint' in newLib ) : #NEWLINE# #INDENT# for function in self . library . functions . values ( ) : #NEWLINE# #INDENT# for t in ( [ p . type for p in function . parameters . values ( ) ] + [ function . type ] ) : #NEWLINE# #INDENT# if ( t == type ) : #NEWLINE# #INDENT# t . decorationHint = attrs [ 'decorationhint' ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# self . library . typeMap [ type ] = str ( mapping ) #NEWLINE# #UNINDENT# for function in config . functions . keys ( ) : #NEWLINE# #INDENT# if ( not ( function in lib . functions ) ) : #NEWLINE# #INDENT# self . fail ( ( "Attributes specified for non-existent function '%s'." % function ) ) #NEWLINE# #UNINDENT# attrs = config . functions [ function ] . attrs #NEWLINE# if ( 'terminator' in attrs ) : #NEWLINE# #INDENT# lib . functions [ function ] . isTerminator = parseBool ( attrs [ 'terminator' ] ) #NEWLINE# #UNINDENT# if ( 'generate' in attrs ) : #NEWLINE# #INDENT# lib . functions [ function ] . generate = parseBool ( attrs [ 'generate' ] ) #NEWLINE# #UNINDENT# if ( 'runtimestate' in attrs ) : #NEWLINE# #INDENT# lib . functions [ function ] . runtimeStateTracking = parseBool ( attrs [ 'runtimestate' ] ) #NEWLINE# #UNINDENT# if ( 'framemarker' in attrs ) : #NEWLINE# #INDENT# lib . functions [ function ] . isFrameMarker = parseBool ( attrs [ 'framemarker' ] ) #NEWLINE# #UNINDENT# if ( 'staticlinkage' in attrs ) : #NEWLINE# #INDENT# lib . functions [ function ] . staticLinkage = parseBool ( attrs [ 'staticlinkage' ] ) #NEWLINE# #UNINDENT# if ( 'rendercall' in attrs ) : #NEWLINE# #INDENT# lib . functions [ function ] . isRenderCall = parseBool ( attrs [ 'rendercall' ] ) #NEWLINE# #UNINDENT# if ( 'passthrough' in attrs ) : #NEWLINE# #INDENT# lib . functions [ function ] . passthrough = parseBool ( attrs [ 'passthrough' ] ) #NEWLINE# #UNINDENT# if ( not isinstance ( config . functions [ function ] , Config . Group ) ) : #NEWLINE# #INDENT# self . fail ( ( "Syntax error: State map definition for function '%s' is missing braces." % function ) ) #NEWLINE# #UNINDENT# reservedNames = [ '@return' , '@modify' , '@set' , '@get' , '@copy' ] #NEWLINE# funcAttrs = attrs #NEWLINE# for ( arg , parameter ) in config . functions [ function ] . items ( ) : #NEWLINE# #INDENT# if ( ( not ( arg in reservedNames ) ) and ( not ( arg in lib . functions [ function ] . parameters ) ) ) : #NEWLINE# #INDENT# self . fail ( ( "State mapping for nonexistent parameter '%s' of function '%s' specified." % ( arg , function ) ) ) #NEWLINE# #UNINDENT# if ( ( arg in [ '@copy' ] ) and parseBool ( funcAttrs . get ( 'runtimestate' , '0' ) ) ) : #NEWLINE# #INDENT# Log . warn ( ( 'Function %s state relation %s not implemented for runtime state tracking.' % ( function , arg ) ) ) #NEWLINE# #UNINDENT# attrs = config . functions [ function ] [ arg ] . attrs #NEWLINE# if ( 'decoration' in attrs ) : #NEWLINE# #INDENT# lib . functions [ function ] . parameters [ arg ] . decoration = attrs [ 'decoration' ] #NEWLINE# #UNINDENT# if ( 'decorationhint' in attrs ) : #NEWLINE# #INDENT# lib . functions [ function ] . parameters [ arg ] . decorationHint = attrs [ 'decorationhint' ] #NEWLINE# #UNINDENT# if ( 'out' in attrs ) : #NEWLINE# #INDENT# lib . functions [ function ] . parameters [ arg ] . isOut = parseBool ( attrs [ 'out' ] ) #NEWLINE# #UNINDENT# if ( 'object_class' in attrs ) : #NEWLINE# #INDENT# if ( arg == '@return' ) : #NEWLINE# #INDENT# type = lib . functions [ function ] . type #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# type = lib . functions [ function ] . parameters [ arg ] . type #NEWLINE# #UNINDENT# newType = copy . deepcopy ( type ) #NEWLINE# newType . isObject = True #NEWLINE# newType . name = attrs [ 'object_class' ] #NEWLINE# if ( arg == '@return' ) : #NEWLINE# #INDENT# lib . functions [ function ] . type = newType #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# lib . functions [ function ] . parameters [ arg ] . type = newType #NEWLINE# #UNINDENT# classType = Library . Type ( attrs [ 'object_class' ] ) #NEWLINE# if ( not ( classType in self . library . classes ) ) : #NEWLINE# #INDENT# self . fail ( ( "Undefined object class '%s'." % classType ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( 'metatype' in config . functions [ function ] [ arg ] ) : #NEWLINE# #INDENT# metaGroup = config . functions [ function ] [ arg ] . metatype #NEWLINE# try : #NEWLINE# #INDENT# metaType = Library . MetaType ( metaGroup . attrs [ 'class' ] ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# self . fail ( ( "Meta type for parameter '%s' does not define class." % arg ) ) #NEWLINE# #UNINDENT# if ( metaType . name == 'array' ) : #NEWLINE# #INDENT# metaType . values [ 'size' ] = Library . MetaValue ( 'size' , metaGroup . attrs . get ( 'size' , 1 ) ) #NEWLINE# if ( 'type' in metaGroup . attrs ) : #NEWLINE# #INDENT# metaType . values [ 'type' ] = Library . MetaValue ( 'type' , metaGroup . attrs [ 'type' ] ) #NEWLINE# if ( metaGroup . attrs [ 'type' ] == 'object' ) : #NEWLINE# #INDENT# if ( not ( 'object_class' in metaGroup . attrs ) ) : #NEWLINE# #INDENT# self . fail ( 'Required metatype attribute object_class missing' ) #NEWLINE# #UNINDENT# metaType . values [ 'object_class' ] = Library . MetaValue ( 'object_class' , metaGroup . attrs [ 'object_class' ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( metaType . name == 'image' ) : #NEWLINE# #INDENT# metaType . values [ 'stride' ] = Library . MetaValue ( 'stride' , metaGroup . attrs . get ( 'stride' , 'width' ) ) #NEWLINE# metaType . values [ 'height' ] = Library . MetaValue ( 'height' , metaGroup . attrs . get ( 'height' , 'height' ) ) #NEWLINE# metaType . values [ 'components' ] = Library . MetaValue ( 'components' , metaGroup . attrs . get ( 'components' , '1' ) ) #NEWLINE# metaType . values [ 'type' ] = Library . MetaValue ( 'type' , metaGroup . attrs . get ( 'type' , 'byte' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . fail ( ( "Unknown meta type class '%s'." % metaclass ) ) #NEWLINE# #UNINDENT# #UNINDENT# Log . debug ( ( 'Meta type: %s.%s: %s' % ( function , arg , metaType . name ) ) ) #NEWLINE# if isinstance ( metaGroup , Config . List ) : #NEWLINE# #INDENT# for item in metaGroup : #NEWLINE# #INDENT# predicate = item . attrs [ 'condition' ] #NEWLINE# predicateValue = item . attrs [ 'value' ] #NEWLINE# result = item . attrs [ 'result' ] #NEWLINE# metaType . values [ item ] . addPredicate ( predicate , predicateValue , result ) #NEWLINE# Log . debug ( ( 'Meta type condition: If %s is %s, then %s = %s' % ( predicate , predicateValue , item , result ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( metaGroup , Config . Group ) : #NEWLINE# #INDENT# Log . error ( ( "Meta type variations for parameter '%s' represented in a group instead of a list." % arg ) ) #NEWLINE# #UNINDENT# #UNINDENT# lib . functions [ function ] . parameters [ arg ] . metaType = metaType #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# path = parameter . split ( '.' ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# path = config . functions [ function ] [ arg ] . state . split ( '.' ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# path = [ ] #NEWLINE# #UNINDENT# #UNINDENT# if ( path and ( not ( 'state' in config ) ) ) : #NEWLINE# #INDENT# Log . warn ( 'State structure not defined.' ) #NEWLINE# continue #NEWLINE# #UNINDENT# relation = None #NEWLINE# checkPaths = [ ] #NEWLINE# if ( arg == '@copy' ) : #NEWLINE# #INDENT# relation = Library . StateRelationCopy ( attrs [ 'src' ] . split ( '.' ) , attrs [ 'dest' ] . split ( '.' ) ) #NEWLINE# checkPaths = [ relation . sourcePath , relation . destPath ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( arg == '@get' ) : #NEWLINE# #INDENT# relation = Library . StateRelationGet ( path ) #NEWLINE# checkPaths = [ relation . path ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( arg == '@set' ) : #NEWLINE# #INDENT# relation = Library . StateRelationSet ( path ) #NEWLINE# checkPaths = [ relation . path ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( arg == '@modify' ) : #NEWLINE# #INDENT# relation = Library . StateRelationModify ( path ) #NEWLINE# checkPaths = [ relation . path ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not '' . join ( path ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if relation : #NEWLINE# #INDENT# for path in checkPaths : #NEWLINE# #INDENT# if ( traverseStatePath ( config , path ) is None ) : #NEWLINE# #INDENT# self . fail ( ( "Relation state path '%s' for function '%s' does not exist." % ( '.' . join ( path ) , function ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# Log . debug ( ( 'State relation: %s %s' % ( function , relation ) ) ) #NEWLINE# lib . functions [ function ] . stateRelations . append ( relation ) #NEWLINE# continue #NEWLINE# #UNINDENT# Log . debug ( ( 'State mapping: %s.%s -> %s' % ( function , arg , '.' . join ( path ) ) ) ) #NEWLINE# type = None #NEWLINE# if ( arg == '@return' ) : #NEWLINE# #INDENT# type = lib . functions [ function ] . type #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# type = lib . functions [ function ] . parameters [ arg ] . type #NEWLINE# #UNINDENT# if ( lib . functions [ function ] . runtimeStateTracking and type and ( lib . getNativeType ( type ) in [ 'float' , 'double' ] ) ) : #NEWLINE# #INDENT# self . fail ( ( "Values of type '%s' can not be saved to the runtime state tree" % type ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# node = traverseStatePath ( config , path ) #NEWLINE# if ( node is None ) : #NEWLINE# #INDENT# self . fail ( ( "State path '%s' for function '%s' does not exist." % ( '.' . join ( path ) , function ) ) ) #NEWLINE# #UNINDENT# if ( arg == '@return' ) : #NEWLINE# #INDENT# lib . functions [ function ] . retStateRelation = Library . StateRelationSet ( path ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# lib . functions [ function ] . parameters [ arg ] . stateRelation = Library . StateRelationSet ( path )