def test(self): """ Check the is_copy_constructor method. This fails when using CastXML, see issue #27. """ tclass = self.global_ns.class_("test") ctors = [] for decl in tclass.declarations: if isinstance(decl, declarations.constructor_t): ctors.append(decl) # test::test(test const & t0) [copy constructor] self.assertTrue(declarations.is_copy_constructor(ctors[0])) # test::test(float const & t0) [constructor] self.assertFalse(declarations.is_copy_constructor(ctors[1])) # test::test(myvar t0) [constructor] self.assertFalse(declarations.is_copy_constructor(ctors[2])) t2class = self.global_ns.class_("test2") ctors = [] for decl in t2class.declarations: if isinstance(decl, declarations.constructor_t): ctors.append(decl) # test2::test2() [constructor] self.assertFalse(declarations.is_copy_constructor(ctors[0])) # test2::test2(test2 const & arg0) [copy constructor] self.assertTrue(declarations.is_copy_constructor(ctors[1]))
def exclusion_critera(self): # Check for exclusions exclusion_args = self.class_info.hierarchy_attribute_gather( 'calldef_excludes') ctor_arg_exludes = self.class_info.hierarchy_attribute_gather( 'constructor_arg_type_excludes') for eachArg in self.ctor_decl.argument_types: if eachArg.decl_string.replace(" ", "") in exclusion_args: return True for eachExclude in ctor_arg_exludes: if eachExclude in eachArg.decl_string: return True for eachArg in self.ctor_decl.argument_types: if "iterator" in eachArg.decl_string.lower(): return True if self.ctor_decl.parent != self.class_decl: return True if self.ctor_decl.is_artificial and declarations.is_copy_constructor( self.ctor_decl): return True if self.class_decl.is_abstract and len( self.class_decl.recursive_bases) > 0: if any(t.related_class.is_abstract for t in self.class_decl.recursive_bases): return True return False
def _get_no_init( self ): if None is self._no_init and False == bool( self.indexing_suite ): #select all public constructors and exclude copy constructor cs = self.constructors( lambda c: not declarations.is_copy_constructor(c) and c.access_type == 'public' , recursive=False, allow_empty=True ) has_suitable_constructor = bool( cs ) if cs and len(cs) == 1 and declarations.is_trivial_constructor(cs[0]) and declarations.find_noncopyable_vars(self): has_suitable_constructor = False has_nonpublic_destructor = declarations.has_destructor( self ) \ and not declarations.has_public_destructor( self ) trivial_constructor = declarations.find_trivial_constructor(self) if has_nonpublic_destructor \ or ( self.is_abstract and not self.is_wrapper_needed() ) \ or not has_suitable_constructor: self._no_init = True elif not trivial_constructor or trivial_constructor.access_type != 'public': exportable_cs = [c for c in cs if c.exportable and c.ignore == False] if not exportable_cs: self._no_init = True else: pass if None is self._no_init: self._no_init = False return self._no_init
def test(self): """ Check the is_copy_constructor method. This fails when using CastXML, see issue #27. """ tclass = self.global_ns.class_("test") ctors = [] for decl in tclass.declarations: if isinstance(decl, declarations.constructor_t): ctors.append(decl) # test::test(test const & t0) [copy constructor] self.assertTrue(declarations.is_copy_constructor(ctors[0])) # test::test(float const & t0) [constructor] self.assertFalse(declarations.is_copy_constructor(ctors[1])) # test::test(myvar t0) [constructor] self.assertFalse(declarations.is_copy_constructor(ctors[2])) t2class = self.global_ns.class_("test2") ctors = [] for decl in t2class.declarations: if isinstance(decl, declarations.constructor_t): ctors.append(decl) # GCCXML and CastXML return the constructors in a different order. # I hope this index inversion will cover the two cases. If different # compilers give other orders, we will need to find a nicer solution. if "CastXML" in utils.xml_generator: positions = [0, 1] elif "GCC" in utils.xml_generator: positions = [1, 0] # test2::test2() [constructor] self.assertFalse(declarations.is_copy_constructor(ctors[positions[0]])) # test2::test2(test2 const & arg0) [copy constructor] self.assertTrue(declarations.is_copy_constructor(ctors[positions[1]]))
def test(self): """ Check the is_copy_constructor method. This fails when using CastXML, see issue #27. """ tclass = self.global_ns.class_("test") ctors = [] for decl in tclass.declarations: if isinstance(decl, declarations.constructor_t): ctors.append(decl) # test::test(test const & t0) [copy constructor] self.assertTrue(declarations.is_copy_constructor(ctors[0])) # test::test(float const & t0) [constructor] self.assertFalse(declarations.is_copy_constructor(ctors[1])) # test::test(myvar t0) [constructor] self.assertFalse(declarations.is_copy_constructor(ctors[2])) t2class = self.global_ns.class_("test2") ctors = [] for decl in t2class.declarations: if isinstance(decl, declarations.constructor_t): ctors.append(decl) # GCCXML and CastXML return the constructors in a different order. # I hope this index inversion will cover the two cases. If different # compilers give other orders, we will need to find a nicer solution. if self.xml_generator_from_xml_file.is_castxml: positions = [0, 1] elif self.xml_generator_from_xml_file.is_gccxml: positions = [1, 0] # test2::test2() [constructor] self.assertFalse(declarations.is_copy_constructor(ctors[positions[0]])) # test2::test2(test2 const & arg0) [copy constructor] self.assertTrue(declarations.is_copy_constructor(ctors[positions[1]]))
def does_define_implicit_conversion( self ): """ returns true if the constructor can take part in implicit conversions. For more information see: * http://boost.org/libs/python/doc/v2/implicit.html#implicitly_convertible-spec * http://msdn2.microsoft.com/en-us/library/h1y7x448.aspx * http://msdn.microsoft.com/en-us/library/s2ff0fz8%28VS.100%29.aspx """ if self.parent.is_abstract: #user is not able to create an instance of the class return False if declarations.is_copy_constructor(self): return False if not( len( self.arguments) and len( self.required_args ) < 2 ): return False if self.parent.find_out_member_access_type( self ) != declarations.ACCESS_TYPES.PUBLIC: return False return True
def test_constructors_destructors(self): struct_calldefs = self.global_ns.class_('calldefs_t') destructor = struct_calldefs.calldef('~calldefs_t') self._test_calldef_args(destructor, []) self._test_calldef_return_type(destructor, None.__class__) # well, now we have a few functions ( constructors ) with the same # name, there is no easy way to find the desired one. Well in my case # I have only 4 constructors # 1. from char # 2. from (int,double) # 3. default # 4. copy constructor constructor_found = struct_calldefs.constructors('calldefs_t') self.assertTrue( len(constructor_found) == 5, ("struct 'calldefs_t' has 5 constructors, pygccxml parser " + "reports only about %d.") % len(constructor_found)) error_text = "copy constructor has not been found" self.assertTrue( 1 == len([ constructor for constructor in constructor_found if declarations.is_copy_constructor(constructor) ]), error_text) # there is nothing to check about constructors - I know the # implementation of parser. # In this case it doesn't different from any other function c = struct_calldefs.constructor('calldefs_t', arg_types=['char']) self.assertTrue( c.explicit, ("calldef_t constructor defined with 'explicit' keyword, " + "for some reason the value is False ")) arg_type = declarations.declarated_t( self.global_ns.class_('some_exception_t')) c = struct_calldefs.constructor('calldefs_t', arg_types=[arg_type]) self.assertTrue( c.explicit is False, ("calldef_t constructor defined without 'explicit' keyword, " + "for some reason the value is True "))
def create_module_builder(self): date_time_xml_file = self._create_xml_file() mb = module_builder.module_builder_t( [parser.create_gccxml_fc(date_time_xml_file)], gccxml_path=date_time_settings.gccxml.executable, include_paths=[date_time_settings.boost.include], define_symbols=date_time_settings.defined_symbols, undefine_symbols=date_time_settings.undefined_symbols, optimize_queries=False, indexing_suite_version=2) if sys.platform == 'win32': linux_name = "time_duration<boost::posix_time::time_duration, boost::date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, (boost::date_time::time_resolutions)5, (long long)1000000, 6, int> >" win_name = "time_duration<boost::posix_time::time_duration, boost::date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, (boost::date_time::time_resolutions)5, (long long)1000000, 6, long> >" time_duration_impl = mb.class_(linux_name) #small price for generating code from xml and not from sources time_duration_impl.name = win_name time_duration_impl.demangled = None for f_decl in mb.free_functions(): f_decl.alias = f_decl.name f_decl.name = f_decl.demangled_name #f_decl.create_with_signature = True local_date_time = mb.class_( lambda decl: decl.name.startswith('local_date_time_base<')) for c in local_date_time.constructors(): if not declarations.is_copy_constructor(c): local_date_time.remove_declaration(c) mb.run_query_optimizer() for name, alias in customization_data.name2alias.items(): decl = mb.class_(name) decl.alias = alias if isinstance(decl, declarations.class_t): decl.wrapper_alias = alias + '_wrapper' return mb