Beispiel #1
0
    def target_class(oper):
        """this functions returns reference to class/class declaration
        in scope of which, the operator should be exposed."""
        if isinstance(oper.parent, declarations.class_t):
            return oper.parent
        # now we deal with free operators
        def find_class(type_):
            type_ = declarations.remove_reference(type_)
            if declarations.is_class(type_):
                return declarations.class_traits.get_declaration(type_)
            elif declarations.is_class_declaration(type_):
                return declarations.class_declaration_traits.get_declaration(type_)
            else:
                return None

        arg_1_class = find_class(oper.arguments[0].type)
        arg_2_class = None
        if 2 == len(oper.arguments):
            arg_2_class = find_class(oper.arguments[1].type)

        if arg_1_class:
            if declarations.is_std_ostream(arg_1_class) or declarations.is_std_wostream(arg_1_class):
                # in most cases users doesn't expose std::ostream class
                return arg_2_class
            else:
                return arg_1_class
        else:
            return arg_2_class
Beispiel #2
0
    def is_supported( oper ):
        """returns True if Boost.Python support the operator"""
        if oper.symbol == '*' and len( oper.arguments ) == 0:
            #dereference does not make sense
            return False
        if oper.symbol != '<<':
            return oper.symbol in operators_helper.all

        args_len = len( oper.arguments )
        if isinstance( oper, declarations.member_operator_t ):# and args_len != 1:
            return False #Boost.Python does not support member operator<< :-(
        if isinstance( oper, declarations.free_operator_t ) and args_len != 2:
            return False
        if not declarations.is_same( oper.return_type, oper.arguments[0].type ):
            return False
        type_ = oper.return_type
        if not declarations.is_reference( type_ ):
            return False
        type_ = declarations.remove_reference( type_ )
        if declarations.is_const( type_ ):
            return False
        if args_len == 2:
            #second argument should has "T const &" type, otherwise the code will not compile
            tmp = oper.arguments[1].type
            if not declarations.is_reference( tmp ):
                return False
            tmp = declarations.remove_reference( tmp )
            if not declarations.is_const( tmp ):
                return False
        return declarations.is_std_ostream( type_ ) or declarations.is_std_wostream( type_ )
Beispiel #3
0
    def is_supported(oper):
        """returns True if Boost.Python support the operator"""
        if oper.symbol == "*" and len(oper.arguments) == 0:
            # dereference does not make sense
            return False
        if oper.symbol != "<<":
            return oper.symbol in operators_helper.all

        args_len = len(oper.arguments)
        if isinstance(oper, declarations.member_operator_t):  # and args_len != 1:
            return False  # Boost.Python does not support member operator<< :-(
        if isinstance(oper, declarations.free_operator_t) and args_len != 2:
            return False
        if not declarations.is_same(oper.return_type, oper.arguments[0].type):
            return False
        type_ = oper.return_type
        if not declarations.is_reference(type_):
            return False
        type_ = declarations.remove_reference(type_)
        if declarations.is_const(type_):
            return False
        if args_len == 2:
            # second argument should has "T const &" type, otherwise the code will not compile
            tmp = oper.arguments[1].type
            if not declarations.is_reference(tmp):
                return False
            tmp = declarations.remove_reference(tmp)
            if not declarations.is_const(tmp):
                return False
        return declarations.is_std_ostream(type_) or declarations.is_std_wostream(type_)
Beispiel #4
0
    def target_class( oper ):
        """this functions returns reference to class/class declaration
        in scope of which, the operator should be exposed."""
        if isinstance( oper.parent, declarations.class_t ):
            return oper.parent
        #now we deal with free operators
        def find_class( type_ ):
            type_ = declarations.remove_reference( type_ )
            if declarations.is_class( type_ ):
                return declarations.class_traits.get_declaration( type_ )
            elif declarations.is_class_declaration( type_ ):
                return declarations.class_declaration_traits.get_declaration( type_ )
            else:
                return None

        arg_1_class = find_class( oper.arguments[0].decl_type )
        arg_2_class = None
        if 2 == len( oper.arguments ):
            arg_2_class = find_class( oper.arguments[1].decl_type )

        if arg_1_class:
            if declarations.is_std_ostream( arg_1_class ) or declarations.is_std_wostream( arg_1_class ):
                #in most cases users doesn't expose std::ostream class
                return arg_2_class
            else:
                return arg_1_class
        else:
            return arg_2_class