[pygccxml-commit] SF.net SVN: pygccxml:[1583] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2009-01-17 20:24:55
|
Revision: 1583 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1583&view=rev Author: roman_yakovenko Date: 2009-01-17 20:24:45 +0000 (Sat, 17 Jan 2009) Log Message: ----------- adding support for global variables Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/__init__.py pyplusplus_dev/pyplusplus/code_creators/global_variable.py pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py pyplusplus_dev/unittests/ctypes_pof_tester.py pyplusplus_dev/unittests/sconstruct Added Paths: ----------- pyplusplus_dev/unittests/data/ctypes/variables/ pyplusplus_dev/unittests/data/ctypes/variables/sconscript pyplusplus_dev/unittests/data/ctypes/variables/variables.cpp pyplusplus_dev/unittests/data/ctypes/variables/variables.h Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2009-01-17 09:29:36 UTC (rev 1582) +++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2009-01-17 20:24:45 UTC (rev 1583) @@ -167,3 +167,4 @@ from function_definition import mem_fun_definition_t from typedef_as_pyvar import typedef_as_pyvar_t from enum import pyenum_t +from global_variable import global_variable_reference_t Modified: pyplusplus_dev/pyplusplus/code_creators/global_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/global_variable.py 2009-01-17 09:29:36 UTC (rev 1582) +++ pyplusplus_dev/pyplusplus/code_creators/global_variable.py 2009-01-17 20:24:45 UTC (rev 1583) @@ -7,6 +7,7 @@ import pygccxml import algorithm import code_creator +import ctypes_formatter import declaration_based import registration_based from pygccxml import declarations @@ -182,3 +183,18 @@ def _get_system_headers_impl( self ): return [code_repository.ctypes_integration.file_name] + +class global_variable_reference_t( code_creator.code_creator_t, declaration_based.declaration_based_t ): + def __init__( self, var ): + code_creator.code_creator_t.__init__( self ) + declaration_based.declaration_based_t.__init__( self, var ) + + def _create_impl( self ): + return '%(alias)s = %(type)s.in_dll( %(library_var_name)s, "%(name)s" )' \ + % dict( alias=self.alias + , type=ctypes_formatter.as_ctype( self.declaration.type ) + , library_var_name=self.top_parent.library_var_name + , name=self.declaration.name ) + + def _get_system_headers_impl( self ): + return [] Modified: pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py =================================================================== --- pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2009-01-17 09:29:36 UTC (rev 1582) +++ pyplusplus_dev/pyplusplus/creators_factory/ctypes_creator.py 2009-01-17 20:24:45 UTC (rev 1583) @@ -39,8 +39,6 @@ self.__class_defs_ccs = code_creators.bookmark_t() #bookmark for typedef definitions self.__typedefs_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 #mapping between class declaration and class introduction code creator @@ -49,9 +47,6 @@ self.__class2methods_def = {} #mapping between namespace and its code creator self.__namespace2pyclass = {} - #set of all included namespaces - #~ self.__included_nss = set() - #~ for decl in self.global_ns def __print_readme( self, decl ): readme = decl.readme() @@ -71,6 +66,9 @@ return False if isinstance( decl, declarations.calldef_t ): return decl in self.__exported_decls + if isinstance( decl, declarations.variable_t ): + if isinstance( decl.parent, declarations.namespace_t ): + return decl in self.__exported_decls return True #~ def __prepare_decls( self, global_ns, doc_extractor ): @@ -241,6 +239,8 @@ self.__class_defs_ccs.adopt_creator( md_cc ) class_ = self.curr_decl for decl in self.curr_decl.decls( recursive=False, allow_empty=True ): + if isinstance( decl, declarations.variable_t ): + continue #fields_definition_t class treats them if self.__should_generate_code( decl ): self.curr_decl = decl declarations.apply_visitor( self, decl ) @@ -267,7 +267,8 @@ def visit_variable(self): self.__dependencies_manager.add_exported( self.curr_decl ) - + self.curr_code_creator.adopt_creator( code_creators.global_variable_reference_t( self.curr_decl ) ) + def visit_namespace(self ): if not self.__contains_exported( self.curr_decl ): return Modified: pyplusplus_dev/unittests/ctypes_pof_tester.py =================================================================== --- pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-17 09:29:36 UTC (rev 1582) +++ pyplusplus_dev/unittests/ctypes_pof_tester.py 2009-01-17 20:24:45 UTC (rev 1583) @@ -169,6 +169,28 @@ c.r c.val +class variables_tester_t( ctypes_base_tester_t ): + def __init__( self, *args, **keywd ): + ctypes_base_tester_t.__init__( self, 'variables', *args, **keywd ) + + def customize( self, mb ): + pass + + def test(self): + self.module_ref.init() + self.failUnless( self.module_ref.j.value == 87 ) + self.failUnless( self.module_ref.data.i == 1900 ) + self.failUnless( self.module_ref.data_ptr.contents.i == 11 ) + + self.module_ref.j.value = 78 + self.failUnless( self.module_ref.get_value_j() == 78 ) + + self.module_ref.data.i = 987 + self.failUnless( self.module_ref.get_value_data() == 987 ) + + self.module_ref.data_ptr.contents.i = 34 + self.failUnless( self.module_ref.get_value_data_p() == 34 ) + def create_suite(): suite = unittest.TestSuite() if 'win' in sys.platform: @@ -178,6 +200,7 @@ suite.addTest( unittest.makeSuite(opaque_tester_t)) suite.addTest( unittest.makeSuite(include_algorithm_tester_t)) suite.addTest( unittest.makeSuite(anonymous_tester_t)) + suite.addTest( unittest.makeSuite(variables_tester_t)) return suite def run_suite(): Added: pyplusplus_dev/unittests/data/ctypes/variables/sconscript =================================================================== --- pyplusplus_dev/unittests/data/ctypes/variables/sconscript (rev 0) +++ pyplusplus_dev/unittests/data/ctypes/variables/sconscript 2009-01-17 20:24:45 UTC (rev 1583) @@ -0,0 +1,7 @@ +Import('*') + +target_name = 'variables' +shlib = env.SharedLibrary( target=target_name + , source=[ target_name + '.cpp' ] + , CPPPATH=['#data'] ) +env.Alias( target_name, shlib ) Added: pyplusplus_dev/unittests/data/ctypes/variables/variables.cpp =================================================================== --- pyplusplus_dev/unittests/data/ctypes/variables/variables.cpp (rev 0) +++ pyplusplus_dev/unittests/data/ctypes/variables/variables.cpp 2009-01-17 20:24:45 UTC (rev 1583) @@ -0,0 +1,22 @@ +#include "variables.h" + +EXPORT_SYMBOL void init(){ + data.i = 1900; + data_ptr = new data_t(); + data_ptr->i = 11; + j = 87; +} + +EXPORT_SYMBOL int get_value_j(){ + return j; +} + +EXPORT_SYMBOL int get_value_data(){ + return data.i; +} + +EXPORT_SYMBOL int get_value_data_p(){ + return data_ptr->i; +} + + Added: pyplusplus_dev/unittests/data/ctypes/variables/variables.h =================================================================== --- pyplusplus_dev/unittests/data/ctypes/variables/variables.h (rev 0) +++ pyplusplus_dev/unittests/data/ctypes/variables/variables.h 2009-01-17 20:24:45 UTC (rev 1583) @@ -0,0 +1,16 @@ +#include "libconfig.h" + +struct EXPORT_SYMBOL data_t{ + int i; +}; + +EXPORT_SYMBOL int j; +EXPORT_SYMBOL data_t data; +EXPORT_SYMBOL data_t* data_ptr; + +EXPORT_SYMBOL void init(); +EXPORT_SYMBOL int get_value_j(); +EXPORT_SYMBOL int get_value_data(); +EXPORT_SYMBOL int get_value_data_p(); + + Modified: pyplusplus_dev/unittests/sconstruct =================================================================== --- pyplusplus_dev/unittests/sconstruct 2009-01-17 09:29:36 UTC (rev 1582) +++ pyplusplus_dev/unittests/sconstruct 2009-01-17 20:24:45 UTC (rev 1583) @@ -25,7 +25,14 @@ env.AppendUnique( CPPPATH=['#data'] ) -scripts = [ 'pof', 'issues', 'enums', 'opaque', 'include_algorithm', 'anonymous' ] +scripts = [ 'pof' + , 'issues' + , 'enums' + , 'opaque' + , 'include_algorithm' + , 'anonymous' + , 'variables' ] + for s in scripts: SConscript( 'data/ctypes/%s/sconscript' % s , variant_dir='data/ctypes/%s/binaries' % s This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |