Exemple #1
0
    def test_calldef_free_functions(self):
        ns = self.global_ns.namespace('calldef')

        no_return_no_args = ns.free_function('no_return_no_args')

        self._test_calldef_return_type(no_return_no_args, declarations.void_t)

        # TODO: gccxml reported no_return_no_args as having an extern
        # qualifier, which is wrong; Keep the test like this for gccxml as
        # gccxml will be dropped one day. With castxml check if function has
        # no extern qualifier.
        if self.xml_generator_from_xml_file.is_gccxml:
            self.assertTrue(
                no_return_no_args.has_extern,
                "function 'no_return_no_args' should have an extern qualifier")
        else:
            self.assertTrue(
                not no_return_no_args.has_extern,
                "function 'no_return_no_args' should have an extern qualifier")

        # Static_call is explicetely defined as extern, this works with gccxml
        # and castxml.
        static_call = ns.free_function('static_call')
        self.assertTrue(
            static_call,
            "function 'no_return_no_args' should have an extern qualifier")

        return_no_args = ns.free_function('return_no_args')
        self._test_calldef_return_type(return_no_args, declarations.int_t)
        # from now there is no need to check return type.
        no_return_1_arg = ns.free_function(name='no_return_1_arg')
        self.assertTrue(no_return_1_arg,
                        "unable to find 'no_return_1_arg' function")
        self.assertTrue(no_return_1_arg.arguments[0].name in ['arg', 'arg0'])
        self._test_calldef_args(no_return_1_arg, [
            declarations.argument_t(name=no_return_1_arg.arguments[0].name,
                                    decl_type=declarations.int_t())
        ])

        return_default_args = ns.free_function('return_default_args')
        self.assertTrue(
            return_default_args.arguments[0].name in ['arg', 'arg0'])
        self.assertTrue(
            return_default_args.arguments[1].name in ['arg1', 'flag'])
        self._test_calldef_args(return_default_args, [
            declarations.argument_t(name=return_default_args.arguments[0].name,
                                    decl_type=declarations.int_t(),
                                    default_value='1'),
            declarations.argument_t(name=return_default_args.arguments[1].name,
                                    decl_type=declarations.bool_t(),
                                    default_value='false')
        ])
        self._test_calldef_exceptions(return_default_args, [])

        calldef_with_throw = ns.free_function('calldef_with_throw')
        self.assertTrue(calldef_with_throw,
                        "unable to find 'calldef_with_throw' function")
        self._test_calldef_exceptions(
            calldef_with_throw, ['some_exception_t', 'other_exception_t'])
    def test_calldef_free_functions(self):
        ns = self.global_ns.namespace('calldef')

        no_return_no_args = ns.free_function('no_return_no_args')
        self._test_calldef_return_type(no_return_no_args, declarations.void_t)
        self.failUnless(
            no_return_no_args.has_extern,
            "function 'no_return_no_args' should have extern qualifier")

        return_no_args = ns.free_function('return_no_args')
        self._test_calldef_return_type(return_no_args, declarations.int_t)
        # from now there is no need to check return type.
        no_return_1_arg = ns.free_function(name='no_return_1_arg')
        self.failUnless(
            no_return_1_arg,
            "unable to find 'no_return_1_arg' function")
        self.failUnless(no_return_1_arg.arguments[0].name in ['arg', 'arg0'])
        self._test_calldef_args(
            no_return_1_arg,
            [declarations.argument_t(
                name=no_return_1_arg.arguments[0].name,
                type=declarations.int_t())])

        return_default_args = ns.free_function('return_default_args')
        self.failUnless(
            return_default_args.arguments[0].name in [
                'arg',
                'arg0'])
        self.failUnless(
            return_default_args.arguments[1].name in [
                'arg1',
                'flag'])
        self._test_calldef_args(
            return_default_args,
            [declarations.argument_t(
                name=return_default_args.arguments[0].name,
                type=declarations.int_t(),
                default_value='1'),
                declarations.argument_t(
                    name=return_default_args.arguments[1].name,
                    type=declarations.bool_t(),
                    default_value='false')])
        self._test_calldef_exceptions(return_default_args, [])

        calldef_with_throw = ns.free_function('calldef_with_throw')
        self.failUnless(
            calldef_with_throw,
            "unable to find 'calldef_with_throw' function")
        self._test_calldef_exceptions(
            calldef_with_throw, [
                'some_exception_t', 'other_exception_t'])
    def test_calldef_free_functions(self):
        ns = self.global_ns.namespace('calldef')

        no_return_no_args = ns.free_function('no_return_no_args')

        self._test_calldef_return_type(no_return_no_args, declarations.void_t)
        self.assertTrue(
            not no_return_no_args.has_extern,
            "function 'no_return_no_args' should have an extern qualifier")

        # Static_call is explicetely defined as extern, this works with gccxml
        # and castxml.
        static_call = ns.free_function('static_call')
        self.assertTrue(
            static_call,
            "function 'no_return_no_args' should have an extern qualifier")

        return_no_args = ns.free_function('return_no_args')
        self._test_calldef_return_type(return_no_args, declarations.int_t)
        # from now there is no need to check return type.
        no_return_1_arg = ns.free_function(name='no_return_1_arg')
        self.assertTrue(no_return_1_arg,
                        "unable to find 'no_return_1_arg' function")
        self.assertTrue(no_return_1_arg.arguments[0].name in ['arg', 'arg0'])
        self._test_calldef_args(no_return_1_arg, [
            declarations.argument_t(name=no_return_1_arg.arguments[0].name,
                                    decl_type=declarations.int_t())
        ])

        return_default_args = ns.free_function('return_default_args')
        self.assertTrue(
            return_default_args.arguments[0].name in ['arg', 'arg0'])
        self.assertTrue(
            return_default_args.arguments[1].name in ['arg1', 'flag'])
        self._test_calldef_args(return_default_args, [
            declarations.argument_t(name=return_default_args.arguments[0].name,
                                    decl_type=declarations.int_t(),
                                    default_value='1'),
            declarations.argument_t(name=return_default_args.arguments[1].name,
                                    decl_type=declarations.bool_t(),
                                    default_value='false')
        ])
        self._test_calldef_exceptions(return_default_args, [])

        calldef_with_throw = ns.free_function('calldef_with_throw')
        self.assertTrue(calldef_with_throw,
                        "unable to find 'calldef_with_throw' function")
        self._test_calldef_exceptions(
            calldef_with_throw, ['some_exception_t', 'other_exception_t'])
 def __init__( self, function ):
     sealed_fun_controller_t.__init__( self, function )
     
     inst_arg_type = declarations.declarated_t( self.function.parent )
     if self.function.has_const:
         inst_arg_type = declarations.const_t( inst_arg_type )
     inst_arg_type = declarations.reference_t( inst_arg_type )
     
     self.__inst_arg = declarations.argument_t( name=self.register_variable_name( 'inst' )
                                                , decl_type=inst_arg_type )
Exemple #5
0
 def __init__( self, function ):
     sealed_fun_controller_t.__init__( self, function )
     
     inst_arg_type = declarations.declarated_t( self.function.parent )
     if self.function.has_const:
         inst_arg_type = declarations.const_t( inst_arg_type )
     inst_arg_type = declarations.reference_t( inst_arg_type )
     
     self.__inst_arg = declarations.argument_t( name=self.register_variable_name( 'inst' )
                                                , type=inst_arg_type )
Exemple #6
0
 def __read_argument(self, attrs):
     if isinstance(self.__inst, declarations.calldef_type_t):
         self.__inst.arguments_types.append(attrs[XML_AN_TYPE])
     else:
         argument = declarations.argument_t()
         argument.name = attrs.get(XML_AN_NAME,
                                   'arg%d' % len(self.__inst.arguments))
         argument.type = attrs[XML_AN_TYPE]
         argument.default_value = attrs.get(XML_AN_DEFAULT, None)
         self.__read_attributes(argument, attrs)
         if 'CastXML' not in utils.xml_generator:
             # GCCXML only
             if argument.default_value == '<gccxml-cast-expr>':
                 argument.default_value = None
         self.__inst.arguments.append(argument)
Exemple #7
0
 def __read_argument(self, attrs):
     if isinstance(self.__inst, declarations.calldef_type_t):
         self.__inst.arguments_types.append(attrs[XML_AN_TYPE])
     else:
         argument = declarations.argument_t()
         argument.name = attrs.get(
             XML_AN_NAME,
             'arg%d' % len(
                 self.__inst.arguments))
         argument.type = attrs[XML_AN_TYPE]
         argument.default_value = attrs.get(XML_AN_DEFAULT, None)
         self.__read_attributes(argument, attrs)
         if 'CastXML' not in utils.xml_generator:
             # GCCXML only
             if argument.default_value == '<gccxml-cast-expr>':
                 argument.default_value = None
         self.__inst.arguments.append(argument)
Exemple #8
0
    def prepareWrapper(self, wm):
        # Remove the original argument...
        arg = wm.removeArg(self.idx)
        if not (isinstance(arg.type, declarations.pointer_t) or isinstance(arg.type, declarations.array_t)):
            raise ValueError, "Argument %d (%s) must be a pointer." % (self.idx, arg.name)

        # ...and replace it with a Python object.
        newarg = declarations.argument_t(arg.name, "boost::python::object")
        wm.insertArg(self.idx, newarg)

        self.argname = arg.name
        self.basetype = str(arg.type.base).replace("const", "").strip()

        # Declare a variable that will hold the C array...
        self.carray = wm.declareLocal("c_" + arg.name, self.basetype, size=self.size)
        # and a int which is used for the loop
        self.ivar = wm.declareLocal("i", "int")

        wm.replaceCallArg(self.idx, self.carray)
Exemple #9
0
    def __init__(self, decl, transformers):

        self.decl = decl
        self.transformers = transformers

        # The original function name
        self.funcname = decl.name

        # Create the arg list of the original function (including the
        # return type)
        argnames = map(lambda a: a.name, decl.arguments)
        if str(decl.return_type) == "void":
            ret = None
            argnames = [None] + argnames
        else:
            resname = self._makeNameUnique("res", argnames)
            ret = declarations.argument_t(resname, decl.return_type, None)
            argnames = [resname] + argnames
        self.funcargs = [ret] + decl.arguments
        # Initialize the argument strings used for invoking the original
        # function
        self.callargs = argnames

        # The name of the wrapper function
        self.wrappername = "%s_wrapper" % decl.name
        # The arguments of the wrapper function
        self.wrapperargs = copy.copy(self.funcargs)

        # Result tuple
        self.resulttuple = []

        self.declared_vars = {}
        self.local_var_list = []

        # Return the original return value by default
        if self.funcargs[0] != None:
            self.appendResult(self.funcargs[0].name)

        for trans in self.transformers:
            trans.prepareWrapper(self)
Exemple #10
0
    def __init__(self, decl, transformers):

        self.decl = decl
        self.transformers = transformers

        # The original function name
        self.funcname = decl.name

        # Create the arg list of the original function (including the
        # return type)
        argnames = map(lambda a: a.name, decl.arguments)
        if str(decl.return_type) == "void":
            ret = None
            argnames = [None] + argnames
        else:
            resname = self._makeNameUnique("res", argnames)
            ret = declarations.argument_t(resname, decl.return_type, None)
            argnames = [resname] + argnames
        self.funcargs = [ret] + decl.arguments
        # Initialize the argument strings used for invoking the original
        # function
        self.callargs = argnames

        # The name of the wrapper function
        self.wrappername = "%s_wrapper" % decl.name
        # The arguments of the wrapper function
        self.wrapperargs = copy.copy(self.funcargs)

        # Result tuple
        self.resulttuple = []

        self.declared_vars = {}
        self.local_var_list = []

        # Return the original return value by default
        if self.funcargs[0] != None:
            self.appendResult(self.funcargs[0].name)

        for trans in self.transformers:
            trans.prepareWrapper(self)
    def test_calldef_member_functions(self):
        struct_calldefs = self.global_ns.class_('calldefs_t')

        member_inline_call = struct_calldefs.member_function(
            'member_inline_call')
        self._test_calldef_args(
            member_inline_call, [
                declarations.argument_t(
                    name='i', type=declarations.int_t())])

        member_const_call = struct_calldefs.member_function(
            'member_const_call')
        self.failUnless(
            member_const_call.has_const,
            "function 'member_const_call' should have const qualifier")
        self.failUnless(
            member_const_call.virtuality ==
            declarations.VIRTUALITY_TYPES.NOT_VIRTUAL,
            "function 'member_const_call' should be non virtual function")

        member_virtual_call = struct_calldefs.member_function(
            name='member_virtual_call')
        self.failUnless(
            member_virtual_call.virtuality ==
            declarations.VIRTUALITY_TYPES.VIRTUAL,
            "function 'member_virtual_call' should be virtual function")

        member_pure_virtual_call = struct_calldefs.member_function(
            'member_pure_virtual_call')
        self.failUnless(
            member_pure_virtual_call.virtuality ==
            declarations.VIRTUALITY_TYPES.PURE_VIRTUAL,
            ("function 'member_pure_virtual_call' should be pure virtual " +
                "function"))

        static_call = struct_calldefs.member_function('static_call')
        self.failUnless(
            static_call.has_static,
            "function 'static_call' should have static qualifier")
Exemple #12
0
    def test_calldef_member_functions(self):
        struct_calldefs = self.global_ns.class_('calldefs_t')

        member_inline_call = struct_calldefs.member_function(
            'member_inline_call')
        self._test_calldef_args(
            member_inline_call, [
                declarations.argument_t(
                    name='i', decl_type=declarations.int_t())])

        member_const_call = struct_calldefs.member_function(
            'member_const_call')
        self.assertTrue(
            member_const_call.has_const,
            "function 'member_const_call' should have const qualifier")
        self.assertTrue(
            member_const_call.virtuality ==
            declarations.VIRTUALITY_TYPES.NOT_VIRTUAL,
            "function 'member_const_call' should be non virtual function")

        member_virtual_call = struct_calldefs.member_function(
            name='member_virtual_call')
        self.assertTrue(
            member_virtual_call.virtuality ==
            declarations.VIRTUALITY_TYPES.VIRTUAL,
            "function 'member_virtual_call' should be virtual function")

        member_pure_virtual_call = struct_calldefs.member_function(
            'member_pure_virtual_call')
        self.assertTrue(
            member_pure_virtual_call.virtuality ==
            declarations.VIRTUALITY_TYPES.PURE_VIRTUAL,
            ("function 'member_pure_virtual_call' should be pure virtual " +
                "function"))

        static_call = struct_calldefs.member_function('static_call')
        self.assertTrue(
            static_call.has_static,
            "function 'static_call' should have static qualifier")
Exemple #13
0
    def prepareWrapper(self, wm):
        # Remove the original argument...
        arg = wm.removeArg(self.idx)
        if not (isinstance(arg.type, declarations.pointer_t)
                or isinstance(arg.type, declarations.array_t)):
            raise ValueError, "Argument %d (%s) must be a pointer." % (
                self.idx, arg.name)

        # ...and replace it with a Python object.
        newarg = declarations.argument_t(arg.name, "boost::python::object")
        wm.insertArg(self.idx, newarg)

        self.argname = arg.name
        self.basetype = str(arg.type.base).replace("const", "").strip()

        # Declare a variable that will hold the C array...
        self.carray = wm.declareLocal("c_" + arg.name,
                                      self.basetype,
                                      size=self.size)
        # and a int which is used for the loop
        self.ivar = wm.declareLocal("i", "int")

        wm.replaceCallArg(self.idx, self.carray)
    def test_calldef_free_functions(self):
        ns = self.global_ns.namespace('calldef')

        no_return_no_args = ns.free_function('no_return_no_args')

        self._test_calldef_return_type(no_return_no_args, declarations.void_t)

        # TODO: gccxml reported no_return_no_args as having an extern
        # qualifier, which is wrong; Keep the test like this for gccxml as
        # gccxml will be dropped one day. With castxml check if function has
        # no extern qualifier.
        if 'GCC-XML' in utils.xml_generator:
            self.failUnless(
                no_return_no_args.has_extern,
                "function 'no_return_no_args' should have an extern qualifier")
        else:
            self.failUnless(
                not no_return_no_args.has_extern,
                "function 'no_return_no_args' should have an extern qualifier")

        # Static_call is explicetely defined as extern, this works with gccxml
        # and castxml.
        static_call = ns.free_function('static_call')
        self.failUnless(
            static_call,
            "function 'no_return_no_args' should have an extern qualifier")

        return_no_args = ns.free_function('return_no_args')
        self._test_calldef_return_type(return_no_args, declarations.int_t)
        # from now there is no need to check return type.
        no_return_1_arg = ns.free_function(name='no_return_1_arg')
        self.failUnless(
            no_return_1_arg,
            "unable to find 'no_return_1_arg' function")
        self.failUnless(no_return_1_arg.arguments[0].name in ['arg', 'arg0'])
        self._test_calldef_args(
            no_return_1_arg,
            [declarations.argument_t(
                name=no_return_1_arg.arguments[0].name,
                type=declarations.int_t())])

        return_default_args = ns.free_function('return_default_args')
        self.failUnless(
            return_default_args.arguments[0].name in ['arg', 'arg0'])
        self.failUnless(
            return_default_args.arguments[1].name in ['arg1', 'flag'])
        self._test_calldef_args(
            return_default_args,
            [declarations.argument_t(
                name=return_default_args.arguments[0].name,
                type=declarations.int_t(),
                default_value='1'),
                declarations.argument_t(
                    name=return_default_args.arguments[1].name,
                    type=declarations.bool_t(),
                    default_value='false')])
        self._test_calldef_exceptions(return_default_args, [])

        calldef_with_throw = ns.free_function('calldef_with_throw')
        self.failUnless(
            calldef_with_throw,
            "unable to find 'calldef_with_throw' function")
        self._test_calldef_exceptions(
            calldef_with_throw, [
                'some_exception_t', 'other_exception_t'])
Exemple #15
0
 def __read_ellipsis(self, attrs):
     if isinstance(self.__inst, declarations.calldef_type_t):
         self.__inst.arguments_types.append('...')
     else:
         argument = declarations.argument_t(type='...')
         self.__inst.arguments.append(argument)
Exemple #16
0
 def __read_ellipsis(self, attrs):
     if isinstance(self.__inst, declarations.calldef_type_t):
         self.__inst.arguments_types.append('...')
     else:
         argument = declarations.argument_t(type='...')
         self.__inst.arguments.append(argument)