<commit_before>
# Note: do not import this file directly, it is meant to be used as part of
# a Python script (generatePythonCode) that sets up variables that this
# module depends on

import string
import os
import compileall

import FFIEnvironment
import FFITypes
import FFISpecs
import FFIRename
import FFIConstants
import FFIOverload
from PythonUtil import *

# FFIConstants.notify.setDebug(1)
FFIConstants.notify.info('Importing interrogate library: ' + FFIConstants.InterrogateModuleName)
# Note: we do a from lib import * here because we do not want
# to be dependent on the name of the interrogate library in this code
exec('from ' + FFIConstants.InterrogateModuleName + ' import *')


def constructGlobalFile(codeDir, CModuleName):
    """
    Open a file that will hold the global values and functions code
    """
    file = open(os.path.join(codeDir, CModuleName + 'Globals' + '.py'), 'w')
    return file


def constructDowncastFile(codeDir, CModuleName):
    """
    Open a file that will hold the global values and functions code
    """
    file = open(os.path.join(codeDir, CModuleName + 'Downcasts' + '.py'), 'w')
    return file


def constructImportFile(codeDir, CModuleName):
    """
    Open a file that will hold the global values and functions code
    """
    file = open(os.path.join(codeDir, CModuleName + 'Modules' + '.py'), 'w')
    return file

def outputGlobalFileImports(file, methodList, CModuleName):
    # Print the standard header
    file.write(FFIConstants.generatedHeader)
    file.write('# CMODULE [' + CModuleName + ']\n')

    # Import Python's builtin types
    file.write('import types\n')

    # Import the C modules
    CModuleList = []
    for method in methodList:
        if (not (method.typeDescriptor.moduleName in CModuleList)):
            CModuleList.append(method.typeDescriptor.moduleName)
    for CModuleName in CModuleList:
        if CModuleName:
            file.write('import ' + CModuleName + '\n')

    moduleList = []
    for method in methodList:
        returnType = method.typeDescriptor.returnType.recursiveTypeDescriptor()
        returnTypeName = returnType.foreignTypeName
        if (not (returnTypeName in moduleList)):
            if (returnType.__class__ == FFITypes.ClassTypeDescriptor):
                moduleList.append(returnTypeName)

        # Look at all the arguments
        argTypes = method.typeDescriptor.argumentTypes
        for argType in argTypes:
            # Get the real return type (not derived)
            argType = argType.typeDescriptor.recursiveTypeDescriptor()
            if (not argType.isNested):
                argTypeName = argType.foreignTypeName
                # Do not put our own module in the import list
                # Do not put modules already in the list (like a set)
                if (not (argTypeName in moduleList)):
                    # If this is a class (not a primitive), put it on the list
                    if (argType.__class__ == FFITypes.ClassTypeDescriptor):
                        moduleList.append(argTypeName)

    
    for moduleName in moduleList:
        if moduleName:
            file.write('import ' + moduleName + '\n')
    
    file.write('\n')


def outputImportFileImports(file, typeList, CModuleName):
    """
    This is the file that we will import to get all the panda modules
    """
    
    # Print the standard header
    file.write(FFIConstants.generatedHeader)
    file.write('# CMODULE [' + CModuleName + ']\n')
    file.write('# Import the interrogate module\n')
    file.write('import ' + FFIConstants.InterrogateModuleName + '\n')
    file.write('\n')
    
    file.write('# Import the C module\n')
    file.write('import ' + CModuleName + '\n')

    # Filter out only the class and enum type descriptors (not const, pointers, etc)
    classTypeList = []
    enumTypeList = []
    for type in typeList:
        if (type.__class__ == FFITypes.ClassTypeDescriptor):
            if (not type.isNested):
                classTypeList.append(type)
        elif (type.__class__ == FFITypes.EnumTypeDescriptor):
            if (not type.isNested):
                enumTypeList.append(type)
            
    # Sort the types based on inheritance, most generic first
    classTypeList.sort(FFIOverload.inheritanceLevelSort)

    moduleList = []
    for type in classTypeList:
        moduleList.append(type.foreignTypeName)

    file.write('# Import enums into the global name space\n')
    for type in enumTypeList:
        file.write('from ' + type.enumName + ' import *\n')
    file.write('\n')

    file.write('# Import classes\n')
    for moduleName in moduleList:
        if moduleName:
            file.write('import ' + moduleName + '\n')    
    file.write('\n')

    file.write('# Import the global module file into our name space\n')
    file.write('from ' + CModuleName + 'Globals' + ' import *\n')
    file.write('\n')

    file.write('# Generate the classes\n')
    #for moduleName in moduleList:
    #    file.write(moduleName + '.generateClass_' + moduleName + '()\n')
    file.write('\n')
        
    file.write('# Copy the classes into our own namespace\n')
    for moduleName in moduleList:
        file.write(moduleName + ' = ' + moduleName + '.' + moduleName + '\n')
    file.write('\n')

    file.write('# Put the classes in the wrapper class map\n')
    file.write('from FFIExternalObject import registerInTypeMap\n')
    file.write('\n')
    for moduleName in moduleList:
        file.write('registerInTypeMap(' + moduleName + ')\n')
    file.write('\n')



def getTypeName(typeIndex, scoped=0):
    """
    Return a fully specified type name for this type index
    Return the scoped name if asked for it
    """
    nameComponents = []
    name = ''

    <commit_msg>*** empty log message ***<commit_after>
# Note: do not import this file directly, it is meant to be used as part of
# a Python script (generatePythonCode) that sets up variables that this
# module depends on

import string
import os
import compileall

import FFIEnvironment
import FFITypes
import FFISpecs
import FFIRename
import FFIConstants
import FFIOverload
from PythonUtil import *

# FFIConstants.notify.setDebug(1)
FFIConstants.notify.info('Importing interrogate library: ' + FFIConstants.InterrogateModuleName)
# Note: we do a from lib import * here because we do not want
# to be dependent on the name of the interrogate library in this code
exec('from ' + FFIConstants.InterrogateModuleName + ' import *')


def constructGlobalFile(codeDir, CModuleName):
    """
    Open a file that will hold the global values and functions code
    """
    file = open(os.path.join(codeDir, CModuleName + 'Globals' + '.py'), 'w')
    return file


def constructDowncastFile(codeDir, CModuleName):
    """
    Open a file that will hold the global values and functions code
    """
    file = open(os.path.join(codeDir, CModuleName + 'Downcasts' + '.py'), 'w')
    return file


def constructImportFile(codeDir, CModuleName):
    """
    Open a file that will hold the global values and functions code
    """
    file = open(os.path.join(codeDir, CModuleName + 'Modules' + '.py'), 'w')
    return file

def outputGlobalFileImports(file, methodList, CModuleName):
    # Print the standard header
    file.write(FFIConstants.generatedHeader)
    file.write('# CMODULE [' + CModuleName + ']\n')

    # Import Python's builtin types
    file.write('import types\n')

    # Import the C modules
    CModuleList = []
    for method in methodList:
        if (not (method.typeDescriptor.moduleName in CModuleList)):
            CModuleList.append(method.typeDescriptor.moduleName)
    for CModuleName in CModuleList:
        if CModuleName:
            file.write('import ' + CModuleName + '\n')

    moduleList = []
    for method in methodList:
        returnType = method.typeDescriptor.returnType.recursiveTypeDescriptor()
        returnTypeName = returnType.foreignTypeName
        if (not (returnTypeName in moduleList)):
            if (returnType.__class__ == FFITypes.ClassTypeDescriptor):
                moduleList.append(returnTypeName)

        # Look at all the arguments
        argTypes = method.typeDescriptor.argumentTypes
        for argType in argTypes:
            # Get the real return type (not derived)
            argType = argType.typeDescriptor.recursiveTypeDescriptor()
            if (not argType.isNested):
                argTypeName = argType.foreignTypeName
                # Do not put our own module in the import list
                # Do not put modules already in the list (like a set)
                if (not (argTypeName in moduleList)):
                    # If this is a class (not a primitive), put it on the list
                    if (argType.__class__ == FFITypes.ClassTypeDescriptor):
                        moduleList.append(argTypeName)

    
    for moduleName in moduleList:
        if moduleName:
            file.write('import ' + moduleName + '\n')
    
    file.write('\n')


def outputImportFileImports(file, typeList, CModuleName):
    """
    This is the file that we will import to get all the panda modules
    """
    
    # Print the standard header
    file.write(FFIConstants.generatedHeader)
    file.write('# CMODULE [' + CModuleName + ']\n')
    file.write('# Import the interrogate module\n')
    file.write('import ' + FFIConstants.InterrogateModuleName + '\n')
    file.write('\n')
    
    file.write('# Import the C module\n')
    file.write('import ' + CModuleName + '\n')

    # Filter out only the class and enum type descriptors (not const, pointers, etc)
    classTypeList = []
    enumTypeList = []
    for type in typeList:
        if (type.__class__ == FFITypes.ClassTypeDescriptor):
            if (not type.isNested):
                classTypeList.append(type)
        elif (type.__class__ == FFITypes.EnumTypeDescriptor):
            if (not type.isNested):
                enumTypeList.append(type)
            
    # Sort the types based on inheritance, most generic first
    classTypeList.sort(FFIOverload.inheritanceLevelSort)

    moduleList = []
    for type in classTypeList:
        moduleList.append(type.foreignTypeName)

    file.write('# Import enums into the global name space\n')
    for type in enumTypeList:
        file.write('from ' + type.enumName + ' import *\n')
    file.write('\n')

    file.write('# Import downcast functions\n')
    file.write('from ' + CModuleName + 'Downcasts import *\n')
    file.write('\n')

    file.write('# Import classes\n')
    for moduleName in moduleList:
        if moduleName:
            file.write('import ' + moduleName + '\n')    
    file.write('\n')

    file.write('# Import the global module file into our name space\n')
    file.write('from ' + CModuleName + 'Globals import *\n')
    file.write('\n')

    file.write('# Generate the classes\n')
    #for moduleName in moduleList:
    #    file.write(moduleName + '.generateClass_' + moduleName + '()\n')
    file.write('\n')
        
    file.write('# Copy the classes into our own namespace\n')
    for moduleName in moduleList:
        file.write(moduleName + ' = ' + moduleName + '.' + moduleName + '\n')
    file.write('\n')

    file.write('# Put the classes in the wrapper class map\n')
    file.write('from FFIExternalObject import registerInTypeMap\n')
    file.write('\n')
    for moduleName in moduleList:
        file.write('registerInTypeMap(' + moduleName + ')\n')
    file.write('\n')



def getTypeName(typeIndex, scoped=0):
    """
    Return a fully specified type name for this type index
    Return the scoped name if asked for it
    """
    nameComponents = []
    name = ''

    
{'fraction_non_alphanumeric': 0.10331501202335967, 'fraction_numerical': 0.00034352456200618345, 'mean_word_length': 2.740764535817539, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5311806', 'n_tokens_mistral': 3354, 'n_tokens_neox': 3276, 'n_words': 1028}