[pygccxml-commit] SF.net SVN: pygccxml:[1512] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2008-12-28 20:45:37
|
Revision: 1512 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1512&view=rev Author: roman_yakovenko Date: 2008-12-28 20:45:32 +0000 (Sun, 28 Dec 2008) Log Message: ----------- ctypes - another set of changes Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/class_declaration.py pygccxml_dev/pygccxml/declarations/dependencies.py pyplusplus_dev/pyplusplus/code_creators/__init__.py pyplusplus_dev/pyplusplus/code_creators/function_definition.py pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py pyplusplus_dev/unittests/ctypes_pof_tester.py pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp Added Paths: ----------- pyplusplus_dev/pyplusplus/code_creators/bookmark.py Modified: pygccxml_dev/pygccxml/declarations/class_declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/class_declaration.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pygccxml_dev/pygccxml/declarations/class_declaration.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -537,4 +537,17 @@ , recursive=False , allow_empty=True ) ) + @property + def top_class( self ): + """reference to a parent class, which contains this class and defined + within a namespace + + if this class is defined under a namespace, self will be returned""" + curr = self + parent = self.parent + while isinstance( parent, class_t ): + curr = parent + parent = parent.parent + return curr + class_types = ( class_t, class_declaration_t ) Modified: pygccxml_dev/pygccxml/declarations/dependencies.py =================================================================== --- pygccxml_dev/pygccxml/declarations/dependencies.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pygccxml_dev/pygccxml/declarations/dependencies.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -19,21 +19,21 @@ self._depend_on_it = depend_on_it self._access_type = access_type self._hint = hint - + @property def declaration( self ): return self._declaration #short name decl = declaration - @property + @property def depend_on_it( self ): return self._depend_on_it - + def _get_access_type( self ): return self._access_type def _set_access_type( self, access_type ): - self._access_type = access_type + self._access_type = access_type access_type = property( _get_access_type, _set_access_type ) def __str__( self ): @@ -52,10 +52,27 @@ """ #prevent recursive import from pygccxml import declarations - + if isinstance( self.depend_on_it, declarations.declaration_t ): return self.depend_on_it base_type = declarations.base_type( declarations.remove_alias( self.depend_on_it ) ) if isinstance( base_type, cpptypes.declarated_t ): return base_type.declaration return None + + @staticmethod + def they_depend_on_us( decls ): + """returns set of declarations. every item in the returned set, depends on a + declaration from the input""" + import class_declaration #prevent cyclic imports + to_be_included = set() + for decl in decls: + for dependency_info in decl.i_depend_on_them(): + ddecl = dependency_info.find_out_depend_on_declaration() + if ddecl: + to_be_included.add( ddecl ) + + if isinstance( decl.parent, class_declaration.class_t ): + to_be_included.add( decl.parent ) + return to_be_included + Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -141,6 +141,8 @@ from ctypes_integration_creators import expose_this_t from ctypes_integration_creators import expose_sizeof_t +from bookmark import bookmark_t + #pure ctypes from ctypes_module import ctypes_module_t from import_ import import_t Added: pyplusplus_dev/pyplusplus/code_creators/bookmark.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/bookmark.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_creators/bookmark.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -0,0 +1,18 @@ +# Copyright 2004-2008 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import os +import compound + +class bookmark_t(compound.compound_t): + def __init__( self, comment='' ): + compound.compound_t.__init__(self ) + self.comment = '' + + def _create_impl(self): + return compound.compound_t.create_internal_code( self.creators, indent_code=False ) + + def _get_system_headers_impl( self ): + return [] Modified: pyplusplus_dev/pyplusplus/code_creators/function_definition.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/pyplusplus/code_creators/function_definition.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -38,6 +38,7 @@ def _create_impl(self): result = [] result.append( '#%s' % self.undecorated_decl_name ) + result.append( '#TODO - unable to call C function, if dll was loaded as CPPDLL' ) result.append( '%(alias)s = %(library_var_name)s.%(alias)s' % dict( alias=self.declaration.alias , library_var_name=self.top_parent.library_var_name ) ) Modified: pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py =================================================================== --- pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -32,11 +32,14 @@ self.module = code_creators.ctypes_module_t( global_ns ) self.__dependencies_manager = dependencies_manager.manager_t(self.decl_logger) + self.__class_ccs = code_creators.bookmark_t() + #~ prepared_decls = self.__prepare_decls( global_ns, doc_extractor ) #~ self.__decls = sort_algorithms.sort( prepared_decls ) self.curr_decl = global_ns self.curr_code_creator = self.module self.__class2introduction = {} + self.__namespace2pyclass = {} def __print_readme( self, decl ): readme = decl.readme() @@ -97,14 +100,6 @@ if self.__contains_exported( internal_class ): self.__add_class_introductions( ci_creator, internal_class ) - # - implement better 0(n) algorithm - def __add_namespaces( self, cc, ns ): - ns_creator = code_creators.namespace_as_pyclass_t( ns ) - cc.adopt_creator( ns_creator ) - for internal_ns in ns.namespaces( recursive=False, allow_empty=True): - if self.__contains_exported( ns ): - self.__add_namespaces( ns_creator, internal_ns ) - def create(self ): """Create and return the module for the extension. @@ -119,17 +114,18 @@ ccc.adopt_creator( code_creators.name_mappings_t( self.__exported_symbols ) ) ccc.adopt_creator( code_creators.separator_t() ) #adding namespaces - for ns in self.global_ns.namespaces( recursive=False, allow_empty=True): - if self.__contains_exported( ns ): - self.__add_namespaces( ccc, ns ) - #adding class introductions + global_ns_cc = code_creators.bookmark_t() + ccc.adopt_creator( global_ns_cc ) + ccc.adopt_creator( self.__class_ccs ) + self.__namespace2pyclass[ self.global_ns ] = global_ns_cc + #adding class introductions - special case because of hierarchy f = lambda cls: self.__should_generate_code( cls ) \ and isinstance( cls.parent, declarations.namespace_t ) ns_classes = self.global_ns.classes( f, recursive=True, allow_empty=True) ns_classes = sort_algorithms.sort_classes( ns_classes ) for class_ in ns_classes: - if self.__contains_exported( ns ): - self.__add_class_introductions( ccc, class_ ) + if self.__contains_exported( class_ ): + self.__add_class_introductions( self.__class_ccs, class_ ) ccc.adopt_creator( code_creators.embedded_code_repository_t( code_repository.ctypes_cpp_utils ) ) @@ -174,6 +170,8 @@ def visit_class_declaration(self ): self.__dependencies_manager.add_exported( self.curr_decl ) + ci_creator = code_creators.class_introduction_t( self.curr_decl ) + self.curr_code_creator.adopt_creator( ci_creator ) def visit_class(self): self.__dependencies_manager.add_exported( self.curr_decl ) @@ -197,6 +195,11 @@ self.__dependencies_manager.add_exported( self.curr_decl ) def visit_namespace(self ): + if self.global_ns is not self.curr_decl: + ns_creator = code_creators.namespace_as_pyclass_t( self.curr_decl ) + self.__namespace2pyclass[ self.curr_decl ] = ns_creator + self.__namespace2pyclass[ self.curr_decl.parent ].adopt_creator( ns_creator ) + ns = self.curr_decl for decl in self.curr_decl.decls( recursive=False, allow_empty=True ): if isinstance( decl, declarations.namespace_t) or self.__should_generate_code( decl ): Modified: pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -84,15 +84,18 @@ undecorated = set( b2u.values() ) is_exported = lambda d: msvc.undecorate_decl( d ) in undecorated \ or d.name in b2u and b2u[d.name] == d.name #treatment of C functions - + #include exported declarations included_decls = set() included_decls.update( self.global_ns.calldefs( is_exported, allow_empty=True, recursive=True ) ) included_decls.update( self.global_ns.variables( is_exported, allow_empty=True, recursive=True ) ) - + #include declarations, on which exported declarations depend + they_depend_on_us = decls_package.dependency_info_t.they_depend_on_us + included_decls.update( they_depend_on_us( included_decls ) ) for d in included_decls: + print str(d) d.include() - if isinstance( d.parent, decls_package.class_t ): - d.parent.include() + if isinstance( d, decls_package.class_t ): + d.top_class.include() def build_code_creator( self, library_path, doc_extractor=None ): creator = creators_factory.ctypes_creator_t( self.global_ns Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2008-12-28 20:45:32 UTC (rev 1512) @@ -26,8 +26,8 @@ #mb.code_creator.create() sys.path.append( autoconfig.build_directory ) import ctypes_pof - print ctypes_pof.identity( 23 ) - self.failUnless( ctypes_pof.identity( 23 ) == 23 ) + #the following code fails - difference in the calling conventions + self.failUnless( ctypes_pof.identity( int(111) ) == 111 ) def create_suite(): suite = unittest.TestSuite() Modified: pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp =================================================================== --- pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2008-12-28 13:16:57 UTC (rev 1511) +++ pyplusplus_dev/unittests/data/ctypes_pof/mydll.cpp 2008-12-28 20:45:32 UTC (rev 1512) @@ -47,7 +47,7 @@ void do_smth( number_aptr_t& ){ } -int identity( int i){ return i;} +int identity( int some_data){ return some_data;} BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |