def test(self): criteria = declarations.calldef_matcher_t( name='return_default_args', return_type='int', arg_types=[None, declarations.bool_t()]) rda = declarations.matcher.get_single(criteria, self.declarations) self.assertTrue(rda, "return_default_args function was not found.")
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 prepare_special_cases(): """ Creates a map of special cases ( aliases ) for casting operator. """ special_cases = {} const_t = declarations.const_t pointer_t = declarations.pointer_t for type_ in declarations.FUNDAMENTAL_TYPES.values(): alias = None if declarations.is_same(type_, declarations.bool_t()): alias = "__int__" elif declarations.is_integral(type_): if "long" in type_.decl_string: alias = "__long__" else: alias = "__int__" elif declarations.is_floating_point(type_): alias = "__float__" else: continue # void if alias: special_cases[type_] = alias special_cases[const_t(type_)] = alias special_cases[pointer_t(const_t(declarations.char_t()))] = "__str__" std_string = "::std::basic_string<char,std::char_traits<char>,std::allocator<char> >" std_wstring1 = "::std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >" std_wstring2 = "::std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >" special_cases[std_string] = "__str__" special_cases[std_wstring1] = "__str__" special_cases[std_wstring2] = "__str__" special_cases["::std::string"] = "__str__" special_cases["::std::wstring"] = "__str__" # TODO: add # std::complex<SomeType> some type should be converted to double return special_cases
def prepare_special_cases(): """ Creates a map of special cases ( aliases ) for casting operator. """ special_cases = {} const_t = declarations.const_t pointer_t = declarations.pointer_t for type_ in declarations.FUNDAMENTAL_TYPES.values(): alias = None if declarations.is_same( type_, declarations.bool_t() ): alias = '__int__' elif declarations.is_integral( type_ ): if 'long' in type_.decl_string: alias = '__long__' else: alias = '__int__' elif declarations.is_floating_point( type_ ): alias = '__float__' else: continue #void if alias: special_cases[ type_ ] = alias special_cases[ const_t( type_ ) ] = alias special_cases[ pointer_t( const_t( declarations.char_t() ) ) ] = '__str__' std_string = '::std::basic_string<char,std::char_traits<char>,std::allocator<char> >' std_wstring1 = '::std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >' std_wstring2 = '::std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >' special_cases[ std_string ] = '__str__' special_cases[ std_wstring1 ] = '__str__' special_cases[ std_wstring2 ] = '__str__' special_cases[ '::std::string' ] = '__str__' special_cases[ '::std::wstring' ] = '__str__' #TODO: add # std::complex<SomeType> some type should be converted to double return special_cases
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'])