def cullOverloadedMethods(self):
     """
     Find all the entries that have multiple indexes for the same method name
     Get rid of all others. Do this for class methods and instance methods
     """
     self.overloadedClassMethods = FFIOverload.cullOverloadedMethods(self.overloadedClassMethods)
     self.overloadedInstanceMethods = FFIOverload.cullOverloadedMethods(self.overloadedInstanceMethods)
Exemple #2
0
 def cullOverloadedMethods(self):
     """
     Find all the entries that have multiple indexes for the same method name
     Get rid of all others. Do this for class methods and instance methods
     """
     self.overloadedClassMethods = FFIOverload.cullOverloadedMethods(
         self.overloadedClassMethods)
     self.overloadedInstanceMethods = FFIOverload.cullOverloadedMethods(
         self.overloadedInstanceMethods)
Exemple #3
0
    def generateCodeLib(self, codeDir, extensionsDir, CModuleName):
        # Reset the environment so we are clean from any old modules
        self.environment.reset()

        FFIConstants.notify.info('=' * 50)
        FFIConstants.notify.warning('Importing code library: ' + CModuleName)
        exec('import ' + CModuleName)

        if interrogate_error_flag():
            FFIConstants.notify.error(
                "Error reading interrogate database; can't continue.")

        self.updateBindings(CModuleName)

        FFIConstants.notify.info('Generating type code...')
        for type in self.environment.types.values():
            # Do not generate code for nested types at the top level
            if (not type.isNested):
                type.generateGlobalCode(codeDir, extensionsDir)

        FFIConstants.notify.info('Generating global downcast code...')
        downcastFile = constructDowncastFile(codeDir, CModuleName)
        # Output all the imports based on this list of functions
        outputGlobalFileImports(downcastFile,
                                self.environment.downcastFunctions,
                                CModuleName)
        for type in self.environment.downcastFunctions:
            type.generateGlobalDowncastCode(downcastFile)

        FFIConstants.notify.info('Generating global code...')
        globalFile = constructGlobalFile(codeDir, CModuleName)

        # Make a list of all the global functions. This includes the normal
        # global functions as well as the getters and setters on all the
        # global values. This list is used to figure out what files to import
        # Only include the global functions from the current C module
        globalFunctions = self.environment.globalFunctions
        for globalValue in self.environment.globalValues:
            if globalValue.getter:
                globalFunctions.append(globalValue.getter)
            if globalValue.setter:
                globalFunctions.append(globalValue.setter)
        # Output all the imports based on this list of functions
        outputGlobalFileImports(globalFile, globalFunctions, CModuleName)

        # Generate overloading
        overloadedGlobalFunctions = {}
        for methodSpec in globalFunctions:
            methodList = overloadedGlobalFunctions.setdefault(
                methodSpec.name, [])
            methodList.append(methodSpec)

        overloadedGlobalFunctions = FFIOverload.cullOverloadedMethods(
            overloadedGlobalFunctions)

        for methodSpecList in overloadedGlobalFunctions.values():
            treeColl = FFIOverload.FFIMethodArgumentTreeCollection(
                None, methodSpecList)
            treeColl.generateCode(globalFile, -1)

        FFIConstants.notify.info('Generating global values...')
        for type in self.environment.globalValues:
            type.generateGlobalCode(globalFile)

        FFIConstants.notify.info('Generating global functions...')
        for type in self.environment.globalFunctions:
            type.generateGlobalCode(globalFile)

        FFIConstants.notify.info('Generating manifests...')
        for type in self.environment.manifests:
            type.generateGlobalCode(globalFile)

        globalFile.close()

        FFIConstants.notify.info('Generating import code...')
        importFile = constructImportFile(codeDir, CModuleName)
        outputImportFileImports(importFile, self.environment.types.values(),
                                CModuleName)
    def generateCodeLib(self, codeDir, extensionsDir, CModuleName):
        # Reset the environment so we are clean from any old modules
        self.environment.reset()

        FFIConstants.notify.info('='*50)
        FFIConstants.notify.warning('Importing code library: ' + CModuleName)
        exec('import ' + CModuleName)

        if interrogate_error_flag():
            FFIConstants.notify.error("Error reading interrogate database; can't continue.")

        self.updateBindings(CModuleName)
        
        FFIConstants.notify.info('Generating type code...')
        for type in self.environment.types.values():
            # Do not generate code for nested types at the top level
            if (not type.isNested):
                type.generateGlobalCode(codeDir, extensionsDir)


        FFIConstants.notify.info('Generating global downcast code...')
        downcastFile = constructDowncastFile(codeDir, CModuleName)
        # Output all the imports based on this list of functions
        outputGlobalFileImports(downcastFile,
                                self.environment.downcastFunctions,
                                CModuleName)
        for type in self.environment.downcastFunctions:
            type.generateGlobalDowncastCode(downcastFile)
            
        FFIConstants.notify.info('Generating global code...')
        globalFile = constructGlobalFile(codeDir, CModuleName)

        # Make a list of all the global functions. This includes the normal
        # global functions as well as the getters and setters on all the
        # global values. This list is used to figure out what files to import
        # Only include the global functions from the current C module
        globalFunctions = self.environment.globalFunctions
        for globalValue in self.environment.globalValues:
            if globalValue.getter:
                globalFunctions.append(globalValue.getter)
            if globalValue.setter:
                globalFunctions.append(globalValue.setter)
        # Output all the imports based on this list of functions
        outputGlobalFileImports(globalFile, globalFunctions, CModuleName)

        # Generate overloading
        overloadedGlobalFunctions = {}
        for methodSpec in globalFunctions:
            methodList = overloadedGlobalFunctions.setdefault(methodSpec.name, [])
            methodList.append(methodSpec)

        overloadedGlobalFunctions = FFIOverload.cullOverloadedMethods(overloadedGlobalFunctions)

        for methodSpecList in overloadedGlobalFunctions.values():
            treeColl = FFIOverload.FFIMethodArgumentTreeCollection(None, methodSpecList)
            treeColl.generateCode(globalFile, -1)

        FFIConstants.notify.info('Generating global values...')
        for type in self.environment.globalValues:
            type.generateGlobalCode(globalFile)
            
        FFIConstants.notify.info('Generating global functions...')
        for type in self.environment.globalFunctions:
            type.generateGlobalCode(globalFile)

        FFIConstants.notify.info('Generating manifests...')
        for type in self.environment.manifests:
            type.generateGlobalCode(globalFile)

        globalFile.close()

        FFIConstants.notify.info('Generating import code...')
        importFile = constructImportFile(codeDir, CModuleName)
        outputImportFileImports(importFile, self.environment.types.values(), CModuleName)