コード例 #1
0
    def constructEnumTypeDescriptor(self, typeIndex):
        if self.isDefinedType(typeIndex):
            return self.typeIndexMap[typeIndex]
        else:
            descriptor = FFITypes.EnumTypeDescriptor()
            #descriptor.environment = self.environment
            descriptor.isNested = interrogate_type_is_nested(typeIndex)
            if descriptor.isNested:
                outerTypeIndex = interrogate_type_outer_class(typeIndex)
                descriptor.outerType = self.constructDescriptor(outerTypeIndex)
            if interrogate_type_has_module_name(typeIndex):
                descriptor.moduleName = 'lib' + interrogate_type_module_name(typeIndex)

            # Enums are ints in C++ but we do not want to redefine the int type
            # So we will just call them enums
            descriptor.enumName = FFIRename.classNameFromCppName(getTypeName(typeIndex))
            descriptor.foreignTypeName = '__enum__' + descriptor.enumName
            numValues = interrogate_type_number_of_enum_values(typeIndex)

            # Store the names and values of the enum in a dictionary
            for i in range(numValues):
                value = interrogate_type_enum_value(typeIndex, i)
                name = FFIRename.classNameFromCppName(
                    interrogate_type_enum_value_name(typeIndex, i))
                scopedName = FFIRename.classNameFromCppName(
                    interrogate_type_enum_value_scoped_name(typeIndex, i))
                descriptor.values[name] = value
            
            descriptor.typeIndex = typeIndex
            self.typeIndexMap[typeIndex] = descriptor
            return descriptor
コード例 #2
0
    def constructEnumTypeDescriptor(self, typeIndex):
        if self.isDefinedType(typeIndex):
            return self.typeIndexMap[typeIndex]
        else:
            descriptor = FFITypes.EnumTypeDescriptor()
            #descriptor.environment = self.environment
            descriptor.isNested = interrogate_type_is_nested(typeIndex)
            if descriptor.isNested:
                outerTypeIndex = interrogate_type_outer_class(typeIndex)
                descriptor.outerType = self.constructDescriptor(outerTypeIndex)
            if interrogate_type_has_module_name(typeIndex):
                descriptor.moduleName = 'lib' + interrogate_type_module_name(
                    typeIndex)

            # Enums are ints in C++ but we do not want to redefine the int type
            # So we will just call them enums
            descriptor.enumName = FFIRename.classNameFromCppName(
                getTypeName(typeIndex))
            descriptor.foreignTypeName = '__enum__' + descriptor.enumName
            numValues = interrogate_type_number_of_enum_values(typeIndex)

            # Store the names and values of the enum in a dictionary
            for i in range(numValues):
                value = interrogate_type_enum_value(typeIndex, i)
                name = FFIRename.classNameFromCppName(
                    interrogate_type_enum_value_name(typeIndex, i))
                scopedName = FFIRename.classNameFromCppName(
                    interrogate_type_enum_value_scoped_name(typeIndex, i))
                descriptor.values[name] = value

            descriptor.typeIndex = typeIndex
            self.typeIndexMap[typeIndex] = descriptor
            return descriptor
コード例 #3
0
    def constructManifest(self, manifestIndex):
        descriptor = None
        intValue = None
        getter = None

        if interrogate_manifest_has_type(manifestIndex):
            typeIndex = interrogate_manifest_get_type(manifestIndex)
            descriptor = self.constructDescriptor(typeIndex)

        definition = interrogate_manifest_definition(manifestIndex)

        # See if this manifest is an int. There are shortcuts if it is.
        # If it does have an int value, there will be no getter, we will
        # just output the value in the generated code
        if interrogate_manifest_has_int_value(manifestIndex):
            intValue = interrogate_manifest_get_int_value(manifestIndex)
        else:
            # See if this manifest has a getter
            if interrogate_manifest_has_getter(manifestIndex):
                getterIndex = interrogate_manifest_getter(manifestIndex)
                getter = self.constructGlobalFunction(getterIndex)

        manifestSpec = FFISpecs.ManifestSpecification()
        manifestSpec.typeDescriptor = descriptor
        manifestSpec.definition = definition
        manifestSpec.intValue = intValue
        manifestSpec.getter = getter
        cppName = interrogate_manifest_name(manifestIndex)
        manifestSpec.name = FFIRename.classNameFromCppName(cppName)
        return manifestSpec
コード例 #4
0
    def constructGlobal(self, globalIndex, CModuleName):
        # We really do not need the descriptor for the value, just
        # the getter and setter
        # typeIndex = interrogate_element_type(globalIndex)
        # descriptor = self.constructDescriptor(typeIndex)

        if interrogate_element_has_getter(globalIndex):
            getterIndex = interrogate_element_getter(globalIndex)
            # If this function is not in this Cmodule just return
            if not self.functionInCModule(getterIndex, CModuleName):
                return None
            getter = self.constructGlobalFunction(getterIndex)
        else:
            getter = None

        if interrogate_element_has_setter(globalIndex):
            setterIndex = interrogate_element_setter(globalIndex)
            # If this function is not in this Cmodule just return
            if not self.functionInCModule(setterIndex, CModuleName):
                return None
            setter = self.constructGlobalFunction(setterIndex)
        else:
            setter = None
        globalSpec = FFISpecs.GlobalValueSpecification()
        globalSpec.getter = getter
        globalSpec.setter = setter
        # globalSpec.typeDescriptor = descriptor
        cppName = interrogate_element_name(globalIndex)
        globalSpec.name = FFIRename.classNameFromCppName(cppName)
        return globalSpec
コード例 #5
0
    def constructGlobal(self, globalIndex, CModuleName):
        # We really do not need the descriptor for the value, just
        # the getter and setter
        # typeIndex = interrogate_element_type(globalIndex)
        # descriptor = self.constructDescriptor(typeIndex)
        
        if interrogate_element_has_getter(globalIndex):
            getterIndex = interrogate_element_getter(globalIndex)
            # If this function is not in this Cmodule just return
            if not self.functionInCModule(getterIndex, CModuleName):
                return None
            getter = self.constructGlobalFunction(getterIndex)
        else:
            getter = None

        if interrogate_element_has_setter(globalIndex):
            setterIndex = interrogate_element_setter(globalIndex)
            # If this function is not in this Cmodule just return
            if not self.functionInCModule(setterIndex, CModuleName):
                return None
            setter = self.constructGlobalFunction(setterIndex)
        else:
            setter = None
        globalSpec = FFISpecs.GlobalValueSpecification()
        globalSpec.getter = getter
        globalSpec.setter = setter
        # globalSpec.typeDescriptor = descriptor
        cppName = interrogate_element_name(globalIndex)
        globalSpec.name = FFIRename.classNameFromCppName(cppName)
        return globalSpec
コード例 #6
0
    def constructManifest(self, manifestIndex):
        descriptor = None
        intValue = None
        getter = None

        if interrogate_manifest_has_type(manifestIndex):
            typeIndex = interrogate_manifest_get_type(manifestIndex)
            descriptor = self.constructDescriptor(typeIndex)

        definition = interrogate_manifest_definition(manifestIndex)

        # See if this manifest is an int. There are shortcuts if it is.
        # If it does have an int value, there will be no getter, we will
        # just output the value in the generated code
        if interrogate_manifest_has_int_value(manifestIndex):
            intValue = interrogate_manifest_get_int_value(manifestIndex)
        else:
            # See if this manifest has a getter
            if interrogate_manifest_has_getter(manifestIndex):
                getterIndex = interrogate_manifest_getter(manifestIndex)
                getter = self.constructGlobalFunction(getterIndex)

        manifestSpec = FFISpecs.ManifestSpecification()
        manifestSpec.typeDescriptor = descriptor
        manifestSpec.definition = definition
        manifestSpec.intValue = intValue
        manifestSpec.getter = getter
        cppName = interrogate_manifest_name(manifestIndex)
        manifestSpec.name = FFIRename.classNameFromCppName(cppName)
        return manifestSpec
コード例 #7
0
 def constructGlobalFunction(self, globalIndex):
     descriptors = self.constructFunctionTypeDescriptors(globalIndex)
     if len(descriptors) == 0:
         return None
     funcSpecs = []
     for descriptor in descriptors:
         funcSpec = FFISpecs.GlobalFunctionSpecification()
         funcSpec.typeDescriptor = descriptor
         funcSpec.name = FFIRename.methodNameFromCppName(funcSpec.typeDescriptor.foreignTypeName)
         funcSpec.index = globalIndex
         funcSpecs.append(funcSpec)
     return funcSpecs
コード例 #8
0
 def constructPrimitiveTypeDescriptor(self, typeIndex):
     if self.isDefinedType(typeIndex):
         return self.typeIndexMap[typeIndex]
     else:
         descriptor = FFITypes.PrimitiveTypeDescriptor()
         # descriptor.environment = self.environment
         descriptor.atomicType = interrogate_type_atomic_token(typeIndex)
         if interrogate_type_has_module_name(typeIndex):
             descriptor.moduleName = "lib" + interrogate_type_module_name(typeIndex)
         descriptor.foreignTypeName = FFIRename.nonClassNameFromCppName(getTypeName(typeIndex))
         descriptor.typeIndex = typeIndex
         self.typeIndexMap[typeIndex] = descriptor
         return descriptor
コード例 #9
0
 def constructGlobalFunction(self, globalIndex):
     descriptors = self.constructFunctionTypeDescriptors(globalIndex)
     if (len(descriptors) == 0):
         return None
     funcSpecs = []
     for descriptor in descriptors:
         funcSpec = FFISpecs.GlobalFunctionSpecification()
         funcSpec.typeDescriptor = descriptor
         funcSpec.name = FFIRename.methodNameFromCppName(
             funcSpec.typeDescriptor.foreignTypeName)
         funcSpec.index = globalIndex
         funcSpecs.append(funcSpec)
     return funcSpecs
コード例 #10
0
 def constructPrimitiveTypeDescriptor(self, typeIndex):
     if self.isDefinedType(typeIndex):
         return self.typeIndexMap[typeIndex]
     else:
         descriptor = FFITypes.PrimitiveTypeDescriptor()
         #descriptor.environment = self.environment
         descriptor.atomicType = interrogate_type_atomic_token(typeIndex)
         if interrogate_type_has_module_name(typeIndex):
             descriptor.moduleName = 'lib' + interrogate_type_module_name(typeIndex)
         descriptor.foreignTypeName = \
             FFIRename.nonClassNameFromCppName(getTypeName(typeIndex))
         descriptor.typeIndex = typeIndex
         self.typeIndexMap[typeIndex] = descriptor
         return descriptor
コード例 #11
0
 def constructMemberFunctionSpecifications(self, typeIndex):
     funcSpecs = []
     numFuncs = interrogate_type_number_of_methods(typeIndex)
     for i in range(numFuncs):
         funcIndex = interrogate_type_get_method(typeIndex, i)
         typeDescs = self.constructFunctionTypeDescriptors(funcIndex)
         for typeDesc in typeDescs:
             funcSpec = FFISpecs.MethodSpecification()
             funcSpec.name = FFIRename.methodNameFromCppName(
                 interrogate_function_name(funcIndex),
                 getTypeName(typeIndex))
             funcSpec.typeDescriptor = typeDesc
             funcSpec.index = funcIndex
             funcSpecs.append(funcSpec)
     return funcSpecs
コード例 #12
0
 def constructMemberFunctionSpecifications(self, typeIndex):
     funcSpecs = []
     numFuncs = interrogate_type_number_of_methods(typeIndex)
     for i in range(numFuncs):
         funcIndex = interrogate_type_get_method(typeIndex, i)
         typeDescs = self.constructFunctionTypeDescriptors(funcIndex)
         for typeDesc in typeDescs:
             funcSpec = FFISpecs.MethodSpecification()
             funcSpec.name = FFIRename.methodNameFromCppName(
                 interrogate_function_name(funcIndex),
                 getTypeName(typeIndex))
             funcSpec.typeDescriptor = typeDesc
             funcSpec.index = funcIndex
             funcSpecs.append(funcSpec)
     return funcSpecs
コード例 #13
0
    def constructFunctionArgumentTypes(self, functionIndex):
        numArgs = interrogate_wrapper_number_of_parameters(functionIndex)
        arguments = []
        for argIndex in range(numArgs):
            if interrogate_wrapper_parameter_has_name(functionIndex, argIndex):
                name = FFIRename.nonClassNameFromCppName(interrogate_wrapper_parameter_name(functionIndex, argIndex))
            else:
                name = "parameter" + ` argIndex `
            descriptor = self.constructDescriptor(interrogate_wrapper_parameter_type(functionIndex, argIndex))

            argSpec = FFISpecs.MethodArgumentSpecification()
            if interrogate_wrapper_parameter_is_this(functionIndex, argIndex):
                argSpec.isThis = 1
            argSpec.name = name
            argSpec.typeDescriptor = descriptor
            arguments.append(argSpec)
        return arguments
コード例 #14
0
    def constructClassTypeDescriptor(self, typeIndex):
        if self.isDefinedType(typeIndex):
            return self.typeIndexMap[typeIndex]
        typeName = FFIRename.classNameFromCppName(getTypeName(typeIndex))
        if typeName == "PyObject":
            # A special case: the PyObject type is really a native
            # Python object, not to be molested--it's not really an
            # FFI class object.
            descriptor = FFITypes.PyObjectTypeDescriptor()
            self.typeIndexMap[typeIndex] = descriptor
            return descriptor

        descriptor = FFITypes.ClassTypeDescriptor()
        self.typeIndexMap[typeIndex] = descriptor
        #descriptor.environment = self.environment
        descriptor.foreignTypeName = typeName

        if (typeName == "TypedObject"):
            FFITypes.TypedObjectDescriptor = descriptor

        descriptor.isNested = interrogate_type_is_nested(typeIndex)
        if descriptor.isNested:
            outerTypeIndex = interrogate_type_outer_class(typeIndex)
            descriptor.outerType = self.constructDescriptor(outerTypeIndex)
        if interrogate_type_has_module_name(typeIndex):
            descriptor.moduleName = 'lib' + interrogate_type_module_name(
                typeIndex)
        if FFIConstants.wantComments:
            if interrogate_type_has_comment(typeIndex):
                descriptor.comment = interrogate_type_comment(typeIndex)
        descriptor.typeIndex = typeIndex
        descriptor.instanceMethods = self.constructMemberFunctionSpecifications(
            typeIndex)
        descriptor.upcastMethods = self.constructUpcastFunctionSpecifications(
            typeIndex)
        # Constructing downcasts does not return the functions, it just puts them in the class
        # See the comment in that function
        self.constructDowncastFunctionSpecifications(typeIndex)
        descriptor.filterOutStaticMethods()
        descriptor.constructors = self.constructConstructorSpecifications(
            typeIndex)
        descriptor.destructor = self.constructDestructorSpecification(
            typeIndex)
        descriptor.parentTypes = self.constructParentTypeDescriptors(typeIndex)
        descriptor.nestedTypes = self.constructNestedTypeDescriptors(typeIndex)
        return descriptor
コード例 #15
0
 def constructConstTypeDescriptor(self, typeIndex):
     if self.isDefinedType(typeIndex):
         return self.typeIndexMap[typeIndex]
     descriptor = FFITypes.ConstTypeDescriptor()
     # descriptor.environment = self.environment
     descriptor.isNested = interrogate_type_is_nested(typeIndex)
     if descriptor.isNested:
         outerTypeIndex = interrogate_type_outer_class(typeIndex)
         descriptor.outerType = self.constructDescriptor(outerTypeIndex)
     if interrogate_type_has_module_name(typeIndex):
         descriptor.moduleName = "lib" + interrogate_type_module_name(typeIndex)
     descriptor.foreignTypeName = FFIRename.nonClassNameFromCppName(getTypeName(typeIndex))
     descriptor.typeIndex = typeIndex
     wrappedTypeIndex = interrogate_type_wrapped_type(typeIndex)
     wrappedTypeDescriptor = self.constructDescriptor(wrappedTypeIndex)
     descriptor.typeDescriptor = wrappedTypeDescriptor
     self.typeIndexMap[typeIndex] = descriptor
     return descriptor
コード例 #16
0
 def constructConstTypeDescriptor(self, typeIndex):
     if self.isDefinedType(typeIndex):
         return self.typeIndexMap[typeIndex]
     descriptor = FFITypes.ConstTypeDescriptor()
     #descriptor.environment = self.environment
     descriptor.isNested = interrogate_type_is_nested(typeIndex)
     if descriptor.isNested:
         outerTypeIndex = interrogate_type_outer_class(typeIndex)
         descriptor.outerType = self.constructDescriptor(outerTypeIndex)
     if interrogate_type_has_module_name(typeIndex):
         descriptor.moduleName = 'lib' + interrogate_type_module_name(typeIndex)
     descriptor.foreignTypeName = \
          FFIRename.nonClassNameFromCppName(getTypeName(typeIndex))
     descriptor.typeIndex = typeIndex
     wrappedTypeIndex = interrogate_type_wrapped_type(typeIndex)
     wrappedTypeDescriptor = self.constructDescriptor(wrappedTypeIndex)
     descriptor.typeDescriptor = wrappedTypeDescriptor
     self.typeIndexMap[typeIndex] = descriptor
     return descriptor
コード例 #17
0
 def constructFunctionArgumentTypes(self, functionIndex):
     numArgs = interrogate_wrapper_number_of_parameters(functionIndex)
     arguments = []
     for argIndex in range(numArgs):
         if interrogate_wrapper_parameter_has_name(functionIndex, argIndex):
             name =  FFIRename.nonClassNameFromCppName(
                 interrogate_wrapper_parameter_name(functionIndex, argIndex))
         else:
             name = ('parameter' + `argIndex`)
         descriptor = self.constructDescriptor(
             interrogate_wrapper_parameter_type(functionIndex, argIndex))
         
         argSpec = FFISpecs.MethodArgumentSpecification()
         if interrogate_wrapper_parameter_is_this(functionIndex, argIndex):
             argSpec.isThis = 1
         argSpec.name = name
         argSpec.typeDescriptor = descriptor
         arguments.append(argSpec)
     return arguments
コード例 #18
0
    def constructClassTypeDescriptor(self, typeIndex):
        if self.isDefinedType(typeIndex):
            return self.typeIndexMap[typeIndex]
        typeName = FFIRename.classNameFromCppName(getTypeName(typeIndex))
        if typeName == "PyObject":
            # A special case: the PyObject type is really a native
            # Python object, not to be molested--it's not really an
            # FFI class object.
            descriptor = FFITypes.PyObjectTypeDescriptor()
            self.typeIndexMap[typeIndex] = descriptor
            return descriptor
            
        descriptor = FFITypes.ClassTypeDescriptor()
        self.typeIndexMap[typeIndex] = descriptor
        #descriptor.environment = self.environment
        descriptor.foreignTypeName = typeName

        if (typeName == "TypedObject"):
            FFITypes.TypedObjectDescriptor = descriptor
        
        descriptor.isNested = interrogate_type_is_nested(typeIndex)
        if descriptor.isNested:
            outerTypeIndex = interrogate_type_outer_class(typeIndex)
            descriptor.outerType = self.constructDescriptor(outerTypeIndex)
        if interrogate_type_has_module_name(typeIndex):
            descriptor.moduleName = 'lib' + interrogate_type_module_name(typeIndex)
        if FFIConstants.wantComments:
            if interrogate_type_has_comment(typeIndex):
                descriptor.comment = interrogate_type_comment(typeIndex)
        descriptor.typeIndex = typeIndex
        descriptor.instanceMethods = self.constructMemberFunctionSpecifications(typeIndex)
        descriptor.upcastMethods = self.constructUpcastFunctionSpecifications(typeIndex)
        # Constructing downcasts does not return the functions, it just puts them in the class
        # See the comment in that function
        self.constructDowncastFunctionSpecifications(typeIndex)
        descriptor.filterOutStaticMethods()
        descriptor.constructors = self.constructConstructorSpecifications(typeIndex)
        descriptor.destructor = self.constructDestructorSpecification(typeIndex)
        descriptor.parentTypes = self.constructParentTypeDescriptors(typeIndex)
        descriptor.nestedTypes = self.constructNestedTypeDescriptors(typeIndex)
        return descriptor
コード例 #19
0
    def constructDowncastFunctionSpecifications(self, typeIndex):
        """
        The strange thing about downcast functions is that they appear in the
        class they are being downcast TO, not downcast FROM. But they should be
        built into the class they are being downcast from. For instance, a method
        downcastToNode(ptrBoundedObject) will appear in Node's list of methods
        but should be compiled into BoundedObject's class
        UPDATE: These are no longer compiled into the from-class. That was
        preventing the libraries from being independent since the from class
        now had knowledge of the to class which is potentially in a library
        downstream. Now these functions are just global functions
        """
        numFuncs = interrogate_type_number_of_derivations(typeIndex)
        for i in range(numFuncs):
            # Make sure this downcast is possible
            if (not interrogate_type_derivation_downcast_is_impossible(
                    typeIndex, i)):
                if interrogate_type_derivation_has_downcast(typeIndex, i):
                    funcIndex = interrogate_type_get_downcast(typeIndex, i)
                    typeDescs = self.constructFunctionTypeDescriptors(
                        funcIndex)
                    for typeDesc in typeDescs:
                        funcSpec = FFISpecs.GlobalFunctionSpecification()
                        funcSpec.name = FFIRename.methodNameFromCppName(
                            interrogate_function_name(funcIndex),
                            getTypeName(typeIndex))
                        funcSpec.typeDescriptor = typeDesc
                        funcSpec.index = funcIndex
                        # Here we look for the class in the first argument
                        fromClass = typeDesc.argumentTypes[
                            0].typeDescriptor.recursiveTypeDescriptor()

                        # Append the from class name on the method to uniquify it now
                        # that these are global methods
                        funcSpec.name = funcSpec.name + 'From' + fromClass.foreignTypeName

                        # Append this funcSpec to that class's downcast methods
                        # fromClass.downcastMethods.append(funcSpec)
                        self.environment.addDowncastFunction(funcSpec)
コード例 #20
0
    def constructDowncastFunctionSpecifications(self, typeIndex):
        """
        The strange thing about downcast functions is that they appear in the
        class they are being downcast TO, not downcast FROM. But they should be
        built into the class they are being downcast from. For instance, a method
        downcastToNode(ptrBoundedObject) will appear in Node's list of methods
        but should be compiled into BoundedObject's class
        UPDATE: These are no longer compiled into the from-class. That was
        preventing the libraries from being independent since the from class
        now had knowledge of the to class which is potentially in a library
        downstream. Now these functions are just global functions
        """
        numFuncs = interrogate_type_number_of_derivations(typeIndex)
        for i in range(numFuncs):
            # Make sure this downcast is possible
            if (not interrogate_type_derivation_downcast_is_impossible(typeIndex, i)):
                if interrogate_type_derivation_has_downcast(typeIndex, i):
                    funcIndex = interrogate_type_get_downcast(typeIndex, i)
                    typeDescs = self.constructFunctionTypeDescriptors(funcIndex)
                    for typeDesc in typeDescs:
                        funcSpec = FFISpecs.GlobalFunctionSpecification()
                        funcSpec.name = FFIRename.methodNameFromCppName(
                            interrogate_function_name(funcIndex),
                            getTypeName(typeIndex))
                        funcSpec.typeDescriptor = typeDesc
                        funcSpec.index = funcIndex
                        # Here we look for the class in the first argument
                        fromClass = typeDesc.argumentTypes[0].typeDescriptor.recursiveTypeDescriptor()

                        # Append the from class name on the method to uniquify it now
                        # that these are global methods
                        funcSpec.name = funcSpec.name + 'From' + fromClass.foreignTypeName
                        
                        # Append this funcSpec to that class's downcast methods
                        # fromClass.downcastMethods.append(funcSpec)
                        self.environment.addDowncastFunction(funcSpec)