Beispiel #1
0
    def is_related(t1, t2):
        """Check whether two types\\classes t1 and t2 could introduce the problem"""

        if declarations.is_pointer(t1) and declarations.is_pointer(t2):
            return registration_order.is_related(
                declarations.remove_pointer(t1),
                declarations.remove_pointer(t2))
        elif declarations.is_pointer(t1) and not declarations.is_pointer(t2):
            t1 = declarations.remove_cv(declarations.remove_pointer(t1))
            t2 = declarations.remove_cv(t2)
            if declarations.is_same(t1, t2):
                return 1
        elif not declarations.is_pointer(t1) and declarations.is_pointer(t2):
            t1 = declarations.remove_cv(t1)
            t2 = declarations.remove_cv(declarations.remove_pointer(t2))
            if declarations.is_same(t1, t2):
                return -1
        else:  #not is_pointer( t1 ) and not is_pointer( t2 ):
            if declarations.is_integral( t1 ) and not declarations.is_bool( t1 ) \
               and declarations.is_bool( t2 ):
                return -1
            elif declarations.is_bool( t1 ) \
                 and declarations.is_integral( t2 ) and not declarations.is_bool( t2 ):
                return 1
            else:
                pass
        return None
 def is_related( t1, t2 ):
     """Check whether two types\\classes t1 and t2 could introduce the problem"""
     
     if declarations.is_pointer( t1 ) and declarations.is_pointer( t2 ):
         return registration_order.is_related( declarations.remove_pointer( t1 )
                                               , declarations.remove_pointer( t2 ) )
     elif declarations.is_pointer( t1 ) and not declarations.is_pointer( t2 ):
         t1 = declarations.remove_cv( declarations.remove_pointer( t1 ) )
         t2 = declarations.remove_cv( t2 )
         if declarations.is_same( t1, t2 ):
             return 1
     elif not declarations.is_pointer( t1 ) and declarations.is_pointer( t2 ):
         t1 = declarations.remove_cv( t1 )
         t2 = declarations.remove_cv( declarations.remove_pointer( t2 ) )
         if declarations.is_same( t1, t2 ):
             return -1
     else: #not is_pointer( t1 ) and not is_pointer( t2 ):     
         if declarations.is_integral( t1 ) and not declarations.is_bool( t1 ) \
            and declarations.is_bool( t2 ):
             return -1
         elif declarations.is_bool( t1 ) \
              and declarations.is_integral( t2 ) and not declarations.is_bool( t2 ):
             return 1
         else:
             pass
     return None
Beispiel #3
0
    def _update_containers_db( self, type_ ):
        #will return True is type was treated
        type_ = declarations.remove_alias( type_ )
        type_ = declarations.remove_pointer( type_ )
        type_ = declarations.remove_reference( type_ )
        type_ = declarations.remove_cv( type_ )
        type_ = declarations.remove_declarated( type_ )

        class_traits = declarations.class_traits
        class_declaration_traits = declarations.class_declaration_traits
        if not class_traits.is_my_case( type_ ) and not class_declaration_traits.is_my_case( type_ ):
            return False

        if class_traits.is_my_case( type_ ):
            container_cls = class_traits.get_declaration( type_ )
        else:
            container_cls = class_declaration_traits.get_declaration( type_ )

        if None is container_cls.indexing_suite:
            return False

        try:
            #check extraction of element type from container
            container_cls.indexing_suite.element_type
        except RuntimeError:
            decls_logger = _logging_.loggers.declarations
            if not messages.filter_disabled_msgs([messages.W1042], container_cls.disabled_messages ):
                return #user disabled property warning
            decls_logger.warn( "%s;%s" % ( container_cls, messages.W1042 ) )
        self.__containers.add( container_cls )
        return True
Beispiel #4
0
def filter_decls(mb):
    mb.global_ns.exclude()
    fx_ns = mb.namespace( 'FX' )
    fx_ns.include()
    fx_ns.decls( declarations_to_exclude.is_excluded ).exclude()
    fx_ns.decls( lambda decl: decl.name.startswith('FXIPCMsgHolder') ).exclude()
    fx_ns.namespace( 'Pol' ).exclude()
    fx_ns.decls( files_to_exclude.is_excluded ).exclude()
    fx_ns.class_( 'QValueList<FX::Pol::knowReferrers::ReferrerEntry>').exclude()
    try:
        fx_ns.variables( 'metaClass').exclude()
    except: pass
    try:
        fx_ns.class_( 'QPtrVector<FX::Generic::BoundFunctorV>').exclude()
    except: pass
    #Niall? wrapper for this function could not be compiled
    #TnFXSQLDBStatement = fx_ns.class_( 'TnFXSQLDBStatement' )
    #TnFXSQLDBStatement.member_function( name='bind', arg_types=[None,None,None] ).exclude()

    for func in fx_ns.calldefs():
        #I want to exclude all functions that returns pointer to pointer
        #and returns pointer to fundamental type
        if declarations.is_pointer( func.return_type ):
            temp = declarations.remove_pointer( func.return_type )
            if declarations.is_fundamental( temp ) and not declarations.is_const(temp):
                func.exclude()
            temp = declarations.remove_cv( func.return_type )
            temp = declarations.remove_pointer( temp )
            if declarations.is_pointer( temp ):
                func.exclude()
Beispiel #5
0
    def _update_containers_db(self, type_):
        #will return True is type was treated
        type_ = declarations.remove_alias(type_)
        type_ = declarations.remove_pointer(type_)
        type_ = declarations.remove_reference(type_)
        type_ = declarations.remove_cv(type_)
        type_ = declarations.remove_declarated(type_)

        class_traits = declarations.class_traits
        class_declaration_traits = declarations.class_declaration_traits
        if not class_traits.is_my_case(
                type_) and not class_declaration_traits.is_my_case(type_):
            return False

        if class_traits.is_my_case(type_):
            container_cls = class_traits.get_declaration(type_)
        else:
            container_cls = class_declaration_traits.get_declaration(type_)

        if None is container_cls.indexing_suite:
            return False

        try:
            #check extraction of element type from container
            container_cls.indexing_suite.element_type
        except RuntimeError:
            decls_logger = _logging_.loggers.declarations
            if not messages.filter_disabled_msgs(
                [messages.W1042], container_cls.disabled_messaged):
                return  #user disabled property warning
            decls_logger.warn("%s;%s" % (container_cls, messages.W1042))
        self.__containers.add(container_cls)
        return True
    def check_type_compatibility(self, fget, fset):
        #algorithms allows "const" differences between types
        t1 = fget.return_type
        t2 = fset.arguments[0].decl_type

        if declarations.is_same(t1, t2):
            return True
        elif declarations.is_pointer(t1) and declarations.is_pointer(t2):
            t1 = declarations.remove_cv(declarations.remove_pointer(t1))
            t2 = declarations.remove_cv(declarations.remove_pointer(t2))
            return declarations.is_same(t1, t2)
        elif declarations.is_reference(t1) and declarations.is_reference(t2):
            t1 = declarations.remove_cv(declarations.remove_reference(t1))
            t2 = declarations.remove_cv(declarations.remove_reference(t2))
            return declarations.is_same(t1, t2)
        else:
            return False
Beispiel #7
0
    def check_type_compatibility( self, fget, fset ):
        #algorithms allows "const" differences between types
        t1 = fget.return_type
        t2 = fset.arguments[0].type

        if declarations.is_same( t1, t2 ):
            return True
        elif declarations.is_pointer( t1 ) and declarations.is_pointer( t2 ):
            t1 = declarations.remove_cv( declarations.remove_pointer( t1 ) )
            t2 = declarations.remove_cv( declarations.remove_pointer( t2 ) )
            return declarations.is_same( t1, t2 )
        elif declarations.is_reference( t1 ) and declarations.is_reference( t2 ):
            t1 = declarations.remove_cv( declarations.remove_reference( t1 ) )
            t2 = declarations.remove_cv( declarations.remove_reference( t2 ) )
            return declarations.is_same( t1, t2 )
        else:
            return False
Beispiel #8
0
 def __is_invalid_integral(self, func, arg):
     type_ = declarations.remove_reference( declarations.remove_cv( arg.type ) )        
     if not declarations.is_integral( type_ ):
         return False
     try:
         int( arg.default_value )
         return False
     except:
         return True
Beispiel #9
0
 def __is_invalid_integral(self, func, arg):
     type_ = declarations.remove_reference(declarations.remove_cv(arg.type))
     if not declarations.is_integral(type_):
         return False
     try:
         int(arg.default_value)
         return False
     except:
         return True
Beispiel #10
0
 def _resolve_by_type( self, some_type ):
     temp_type = declarations.remove_alias( some_type )
     temp_type = declarations.remove_cv( temp_type )
     if isinstance( temp_type, declarations.fundamental_t ) \
        or isinstance( temp_type, declarations.declarated_t ):
         return decl_wrappers.default_call_policies()
     if declarations.is_same( some_type, self.__const_char_pointer ):
         return decl_wrappers.default_call_policies()
     return None
Beispiel #11
0
 def __is_unqualified_enum(self, func, arg):
     type_ = declarations.remove_reference(declarations.remove_cv(arg.type))
     if not declarations.is_enum(type_):
         return False
     enum_type = declarations.enum_declaration(type_)
     # GCCXML does not qualify an enum value in the default argument
     # but CastXML does. Split the default value and use only the
     # enum value for fixing it.
     return enum_type.has_value_name(arg.default_value.split('::')[-1])
Beispiel #12
0
 def _resolve_by_type(self, some_type):
     temp_type = declarations.remove_alias(some_type)
     temp_type = declarations.remove_cv(temp_type)
     if isinstance( temp_type, declarations.fundamental_t ) \
        or isinstance( temp_type, declarations.declarated_t ):
         return decl_wrappers.default_call_policies()
     if declarations.is_same(some_type, self.__const_char_pointer):
         return decl_wrappers.default_call_policies()
     return None
Beispiel #13
0
 def __fix_unqualified_enum(self, func, arg):
     type_ = declarations.remove_reference(declarations.remove_cv(arg.type))
     enum_type = declarations.enum_declaration(type_)
     if self.__cxx_std.is_cxx11_or_greater:
         qualifier_decl_string = enum_type.decl_string
     else:
         qualifier_decl_string = enum_type.parent.decl_string
     return self.__join_names(qualifier_decl_string,
                              arg.default_value.split('::')[-1])
Beispiel #14
0
 def __is_unqualified_enum(self, func, arg):
     type_ = declarations.remove_reference(declarations.remove_cv(arg.type))
     if not declarations.is_enum(type_):
         return False
     enum_type = declarations.enum_declaration(type_)
     # GCCXML does not qualify an enum value in the default argument
     # but CastXML does. Split the default value and use only the
     # enum value for fixing it.
     return enum_type.has_value_name(
         arg.default_value.split('::')[-1])
Beispiel #15
0
 def __fix_unqualified_enum(self, func, arg):
     type_ = declarations.remove_reference(declarations.remove_cv(arg.type))
     enum_type = declarations.enum_declaration(type_)
     if self.__cxx_std.is_cxx11_or_greater:
         qualifier_decl_string = enum_type.decl_string
     else:
         qualifier_decl_string = enum_type.parent.decl_string
     return self.__join_names(
         qualifier_decl_string,
         arg.default_value.split('::')[-1])
Beispiel #16
0
def find_out_opaque_decl( type_, ensure_opaque_decl ):
    naked_type = declarations.remove_cv( type_ )
    if not declarations.is_pointer( naked_type ):
        return None
    naked_type = declarations.remove_pointer( declarations.remove_cv( type_ ) )
    if decl_wrappers.python_traits.is_immutable( naked_type ):
        return None#immutable types could not be opaque
    decl = None
    if declarations.is_class( naked_type ):
        decl = declarations.class_traits.get_declaration( naked_type )
    elif declarations.is_class_declaration( naked_type ):#class declaration:
        decl = declarations.class_declaration_traits.get_declaration( naked_type )
    else:
        return None
    if ensure_opaque_decl:
        if decl.opaque:
            return decl
        else:
            return None
    else:
        return decl
def find_out_opaque_decl(type_, ensure_opaque_decl):
    naked_type = declarations.remove_cv(type_)
    if not declarations.is_pointer(naked_type):
        return None
    naked_type = declarations.remove_pointer(declarations.remove_cv(type_))
    if decl_wrappers.python_traits.is_immutable(naked_type):
        return None  #immutable types could not be opaque
    decl = None
    if declarations.is_class(naked_type):
        decl = declarations.class_traits.get_declaration(naked_type)
    elif declarations.is_class_declaration(naked_type):  #class declaration:
        decl = declarations.class_declaration_traits.get_declaration(
            naked_type)
    else:
        return None
    if ensure_opaque_decl:
        if decl.opaque:
            return decl
        else:
            return None
    else:
        return decl
Beispiel #18
0
	def check_type_compatibility(self, fget, fset):
		if decl_wrappers.name_based_recognizer_t.check_type_compatibility(self, fget, fset):
			return True
			
		# N.B.: la base non contempla il caso il cui la get restituisca "type" e la set abbia come parametro "const type &" (capita ad esempio in circostanze dove il valore di ritorno della get viene ottenuto tramite conversione da stringa)		
			
		t1 = fget.return_type
		t2 = fset.arguments[0].type			
			
		if declarations.is_reference(t2):
			t2 = declarations.remove_cv( declarations.remove_reference( t2 ) )
			if declarations.is_same( t1, t2 ):
				return True
				
		return False
    def __has_unexposed_dependency(self, exported_ids, depend_on_decl,
                                   dependency):
        sptr_traits = declarations.smart_pointer_traits

        if None is depend_on_decl:
            return

        if self.__is_std_decl(depend_on_decl):
            return

        if sptr_traits.is_smart_pointer(depend_on_decl):
            try:
                value_type = sptr_traits.value_type(depend_on_decl)
                if isinstance(value_type, declarations.type_t):
                    value_type = declarations.remove_cv(value_type)
                    value_type = declarations.remove_declarated(value_type)
                if isinstance(value_type, declarations.declaration_t):
                    return self.__has_unexposed_dependency(
                        exported_ids, value_type, dependency)
            except RuntimeError:
                pass

        if isinstance(depend_on_decl, decl_wrappers.decl_wrapper_t):
            if depend_on_decl.already_exposed:
                return
            if isinstance(depend_on_decl, declarations.class_types):
                if depend_on_decl.opaque:
                    return
                if dependency.hint == "base class":
                    return  #base class for some class don't have to be exported
            if isinstance(depend_on_decl, declarations.variable_t):
                if not decl.expose_value:
                    return

        if isinstance(dependency.decl, declarations.variable_t):
            #the only dependency of the variable is its type
            if not dependency.decl.expose_value:
                return

        if dependency.hint == "return type":
            #in this case we don't check, the return type but the function
            if isinstance(dependency.decl, declarations.calldef_t):
                if dependency.decl.return_type and dependency.decl.call_policies \
                   and decl_wrappers.is_return_opaque_pointer_policy( dependency.decl.call_policies ):
                    return

        return id(depend_on_decl) not in exported_ids
    def __has_unexposed_dependency( self, exported_ids, depend_on_decl, dependency ):
        sptr_traits = declarations.smart_pointer_traits

        if None is depend_on_decl:
            return

        if self.__is_std_decl( depend_on_decl ):
            return

        if sptr_traits.is_smart_pointer( depend_on_decl ):
            try:
                value_type = sptr_traits.value_type( depend_on_decl )
                if isinstance( value_type, declarations.type_t ):
                    value_type = declarations.remove_cv( value_type )
                    value_type = declarations.remove_declarated( value_type )
                if isinstance( value_type, declarations.declaration_t ):
                    return self.__has_unexposed_dependency( exported_ids, value_type, dependency )
            except RuntimeError:
                pass

        if isinstance( depend_on_decl, decl_wrappers.decl_wrapper_t ):
            if depend_on_decl.already_exposed:
                return
            if isinstance( depend_on_decl, declarations.class_types ):
                if depend_on_decl.opaque:
                    return
                if dependency.hint == "base class":
                    return #base class for some class don't have to be exported
            if isinstance( depend_on_decl, declarations.variable_t ):
                if not depend_on_decl.expose_value:
                    return

        if isinstance( dependency.declaration, declarations.variable_t ):
            #the only dependency of the variable is its type
            if not dependency.declaration.expose_value:
                return

        if dependency.hint == "return type":
            #in this case we don't check, the return type but the function
            if isinstance( dependency.declaration, declarations.calldef_t ):
                if dependency.declaration.return_type and dependency.declaration.call_policies \
                   and decl_wrappers.is_return_opaque_pointer_policy( dependency.declaration.call_policies ):
                   return

        return id( depend_on_decl ) not in exported_ids
    def __init__(self, function, arg_ref, size):
        """Constructor.

        :param maxsize: The maximum string size we will allow...
        :type maxsize: int
        """
        transformer.transformer_t.__init__( self, function )

        self.arg = self.get_argument( arg_ref )
        self.arg_index = self.function.arguments.index( self.arg )

        if not is_ptr_or_array( self.arg.type ):
            raise ValueError( '%s\nin order to use "input_array" transformation, argument %s type must be a array or a pointer (got %s).' ) \
                  % ( function, self.arg.name, self.arg.type)

        self.max_size = size
        self.array_item_type = declarations.remove_const( declarations.array_item_type( self.arg.type ) )
        self.array_item_rawtype = declarations.remove_cv( self.arg.type )
        self.array_item_rawtype = declarations.pointer_t( self.array_item_type )
Beispiel #22
0
    def __call__(self, calldef, hint=None):
        if not isinstance( calldef, declarations.calldef_t ):
            return None

        if not isinstance( calldef, declarations.member_operator_t ):
            return None
        
        if calldef.symbol != '[]':
            return None
            
        return_type = declarations.remove_cv( calldef.return_type )
        if declarations.is_reference( return_type ): 
            return_type = declarations.remove_reference( return_type )
        if python_traits.is_immutable( return_type ):
            if declarations.is_const( calldef.return_type ):
                return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference )
            else:
                return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference )
        else:
            return decl_wrappers.return_internal_reference()
    def __call__(self, calldef, hint=None):
        if not isinstance( calldef, declarations.calldef_t ):
            return None

        if not isinstance( calldef, declarations.member_operator_t ):
            return None
        
        if calldef.symbol != '[]':
            return None
            
        return_type = declarations.remove_cv( calldef.return_type )
        if declarations.is_reference( return_type ): 
            return_type = declarations.remove_reference( return_type )
        if python_traits.is_immutable( return_type ):
            if declarations.is_const( calldef.return_type ):
                return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference )
            else:
                return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference )
        else:
            return decl_wrappers.return_internal_reference()
Beispiel #24
0
    def get_type(self, pgxtype: d.type_t) -> CType:
        if isinstance(pgxtype, d.pointer_t):
            return ct.POINTER(self.get_type(pgxtype.base))

        elif isinstance(pgxtype, d.array_t):
            return self.get_type(pgxtype.base) * pgxtype.size

        elif isinstance(pgxtype, d.free_function_type_t):
            return CTSignature.make(
                *unzip(
                    ((f'_{i}', self.get_type(argpgxtype))
                     for i, argpgxtype in enumerate(pgxtype.arguments_types)),
                    2), self.get_type(pgxtype.return_type)).as_parameter
        else:
            try:
                return self.typemap[d.remove_cv(pgxtype)]
            except KeyError as e:
                if isinstance(pgxtype, d.declarated_t):
                    return self.process_declaration(pgxtype.declaration)
                else:
                    raise e
Beispiel #25
0
 def __fix_unqualified_enum( self, func, arg):
     type_ = declarations.remove_reference( declarations.remove_cv( arg.type ) )
     enum_type = declarations.enum_declaration( type_ )
     return self.__join_names( enum_type.parent.decl_string, arg.default_value )
def set_array_item_type_as_size_t(klass, member_name):
    _D.remove_cv(_D.remove_alias(klass.var(member_name).type)).base = size_t_t()
Beispiel #27
0
cv1 = global_namespace.variable("cv1")
print(str(cv1.decl_type), type(cv1.decl_type))
# > 'int const volatile', <class 'pygccxml.declarations.cpptypes.volatile_t'>

# Remove one level:
base = declarations.remove_volatile(cv1.decl_type)
print(str(base), type(base))
# > 'int const', <class 'pygccxml.declarations.cpptypes.const_t'>

# Remove the second level:
base = declarations.remove_const(base)
print(str(base), type(base))
# > 'int', <class 'pygccxml.declarations.cpptypes.int_t'>

# We can also directly do this in one step:
base = declarations.remove_cv(cv1.decl_type)
print(str(base), type(base))
# > 'int', <class 'pygccxml.declarations.cpptypes.int_t'>

# As for consts, the const and volatile are on the right hand side
# (by convention), and always in the same order
cv2 = global_namespace.variable("cv2")
print(str(cv2.decl_type), type(cv2.decl_type))
# > 'int const volatile', <class 'pygccxml.declarations.cpptypes.volatile_t'>

# And a last example with a pointer_t:
cptr1 = global_namespace.variable("cptr1")
print(str(cptr1.decl_type), type(cptr1.decl_type))
# > 'int const * const', <class 'pygccxml.declarations.cpptypes.const_t'>)

base = declarations.remove_const(cptr1.decl_type)
def set_array_item_type_as_size_t(klass, member_name):
    _D.remove_cv(_D.remove_alias(
        klass.var(member_name).type)).base = size_t_t()
Beispiel #29
0
 def __is_invalid_integral(self, func, arg):
     type_ = declarations.remove_reference( declarations.remove_cv( arg.type ) )        
     return declarations.is_integral( type_ )
Beispiel #30
0
 def __is_unqualified_enum(self, func, arg):
     type_ = declarations.remove_reference( declarations.remove_cv( arg.type ) )        
     if not declarations.is_enum( type_ ):
         return False
     enum_type = declarations.enum_declaration( type_ )
     return enum_type.has_value_name( arg.default_value )
Beispiel #31
0
 def __is_unqualified_enum(self, func, arg):
     type_ = declarations.remove_reference( declarations.remove_cv( arg.type ) )
     if not declarations.is_enum( type_ ):
         return False
     enum_type = declarations.enum_declaration( type_ )
     return enum_type.has_value_name( arg.default_value )
Beispiel #32
0
 def __fix_unqualified_enum( self, func, arg):
     type_ = declarations.remove_reference( declarations.remove_cv( arg.type ) )
     enum_type = declarations.enum_declaration( type_ )
     return self.__join_names( enum_type.parent.decl_string, arg.default_value )