Revision: 1499
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1499&view=rev
Author: roman_yakovenko
Date: 2008-12-25 11:46:00 +0000 (Thu, 25 Dec 2008)
Log Message:
-----------
adding few basic ctypes code creators
Modified Paths:
--------------
pygccxml_dev/unittests/data/core_cache.hpp
pyplusplus_dev/pyplusplus/code_creators/__init__.py
pyplusplus_dev/pyplusplus/code_creators/code_creator.py
pyplusplus_dev/pyplusplus/cpptypes/name_mapping.py
Added Paths:
-----------
pyplusplus_dev/pyplusplus/code_creators/import_.py
pyplusplus_dev/pyplusplus/code_creators/library_reference.py
pyplusplus_dev/pyplusplus/code_creators/name_mappings.py
Modified: pygccxml_dev/unittests/data/core_cache.hpp
===================================================================
--- pygccxml_dev/unittests/data/core_cache.hpp 2008-12-24 21:48:48 UTC (rev 1498)
+++ pygccxml_dev/unittests/data/core_cache.hpp 2008-12-25 11:46:00 UTC (rev 1499)
@@ -22,4 +22,4 @@
#endif//__core_cache_hpp__
-//touch
\ No newline at end of file
+//touch//touch
\ No newline at end of file
Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-24 21:48:48 UTC (rev 1498)
+++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-25 11:46:00 UTC (rev 1499)
@@ -139,3 +139,8 @@
from ctypes_integration_creators import expose_this_t
from ctypes_integration_creators import expose_sizeof_t
+
+#pure ctypes
+from import_ import import_t
+from library_reference import library_reference_t
+from name_mapping import name_mapping_t
Modified: pyplusplus_dev/pyplusplus/code_creators/code_creator.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/code_creator.py 2008-12-24 21:48:48 UTC (rev 1498)
+++ pyplusplus_dev/pyplusplus/code_creators/code_creator.py 2008-12-25 11:46:00 UTC (rev 1499)
@@ -9,8 +9,8 @@
class code_creator_t(object):
"""
code_creator_t is the base class for all code creators.
-
- This class defines the interface that every code creator should implement.
+
+ This class defines the interface that every code creator should implement.
Also it provides few convenience functions.
The purpose of a code creator is the generation of a block of C++
@@ -33,16 +33,16 @@
self._parent = None
self._target_configuration = None
self._works_on_instance = True
-
+
def _get_works_on_instance(self):
return self._works_on_instance
def _set_works_on_instance(self, works_on_instance):
self._works_on_instance = works_on_instance
works_on_instance = property( _get_works_on_instance, _set_works_on_instance )
-
+
def _get_parent( self ):
- return self._parent
+ return self._parent
def _set_parent( self, new_parent ):
if new_parent:
assert isinstance( new_parent, code_creator_t )
@@ -52,7 +52,7 @@
doc="""Parent code creator or None if this is the root node.
@type: L{code_creator_t}
""")
-
+
def _get_target_configuration( self ):
return self._target_configuration
def _set_target_configuration( self, config ):
@@ -62,7 +62,7 @@
doc="""Target configuration.
@type: L{target_configuration_t}
""")
-
+
def _get_top_parent(self):
parent = self.parent
me = self
@@ -80,17 +80,17 @@
def _create_impl(self):
"""
- function that all derived classes should implement. This function
+ function that all derived classes should implement. This function
actually creates code and returns it. Return value of this function is
string.
@rtype: str
"""
raise NotImplementedError()
-
+
def create(self):
"""
- this function should be used in order to get code that should be
+ this function should be used in order to get code that should be
generated.
@returns: Returns a text block of C++ source code.
@@ -109,7 +109,7 @@
used.add( h )
uheaders.append( h )
return uheaders
-
+
def _get_system_headers_impl( self ):
"""Return list of system header files the generated code depends on"""
raise NotImplementedError(self.__class__.__name__)
@@ -132,13 +132,13 @@
"""
assert isinstance( code, types.StringTypes )
return code.strip()
-
+
@staticmethod
def indent( code, size=1 ):
"""
function that implements code indent algorithm.
- @param code: C++ code block.
+ @param code: C++/Python code block.
@type code: str
@param size: The number of indentation levels that the code is shifted
@type size: int
@@ -149,11 +149,11 @@
return code_creator_t.__INDENTATION * size\
+ code.replace( os.linesep
, os.linesep + code_creator_t.__INDENTATION * size )
-
+
@staticmethod
def unindent( code ):
"""
- function that implements code unindent algorithm.
+ function that implements code unindent algorithm.
@param code: C++ code block.
@type code: str
@@ -165,7 +165,7 @@
return code.replace( os.linesep + code_creator_t.__INDENTATION
, os.linesep )
- @staticmethod
+ @staticmethod
def is_comment( line ):
"""
function that returns true if content of the line is comment, otherwise
@@ -178,4 +178,10 @@
assert isinstance( line, types.StringTypes )
l = line.lstrip()
return l.startswith( '//' ) or l.startswith( '/*' )
-
\ No newline at end of file
+
+ @staticmethod
+ def iif( condition, true_, false_ ):
+ if condition:
+ return true_
+ else:
+ return false_
Added: pyplusplus_dev/pyplusplus/code_creators/import_.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/import_.py (rev 0)
+++ pyplusplus_dev/pyplusplus/code_creators/import_.py 2008-12-25 11:46:00 UTC (rev 1499)
@@ -0,0 +1,20 @@
+# 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 code_creator
+import include_directories
+
+
+class import_t(code_creator.code_creator_t):
+ """Creates Python import directive"""
+ def __init__( self, module_name ):
+ code_creator.code_creator_t.__init__(self)
+ self._module_name = module_name
+
+ def _create_impl(self):
+ return 'import %(module)s' % dict( module=self.module_name )
+
+ def _get_system_headers_impl( self ):
+ return []
Added: pyplusplus_dev/pyplusplus/code_creators/library_reference.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/library_reference.py (rev 0)
+++ pyplusplus_dev/pyplusplus/code_creators/library_reference.py 2008-12-25 11:46:00 UTC (rev 1499)
@@ -0,0 +1,32 @@
+# 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 code_creator
+
+
+class library_reference_t(code_creator.code_creator_t):
+ """Creates reference to a library"""
+
+ def __init__( self, library_var_name, library_path, is_cpp_library ):
+ code_creator.code_creator_t.__init__(self)
+ self._library_path = library_path
+ self._is_cpp_library = is_cpp_library
+ self._library_var_name = library_var_name
+
+ def _create_impl(self):
+ return '%(var)s = ctypes.%(loader)s( r"%(path)s" )' \
+ % dict( var=self._library_var_name
+ , loader=self.iif( self._is_cpp_library, 'CPPDLL', 'CDLL' )
+ , path=self._library_path )
+
+
+ def _get_system_headers_impl( self ):
+ return []
+
+if __name__ == '__main__':
+ lr = library_reference_t( 'library', r'c:\temp\x1.dll', False )
+ print lr.create()
+ lr = library_reference_t( 'library', r'c:\temp\x1.dll', True )
+ print lr.create()
Added: pyplusplus_dev/pyplusplus/code_creators/name_mappings.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/name_mappings.py (rev 0)
+++ pyplusplus_dev/pyplusplus/code_creators/name_mappings.py 2008-12-25 11:46:00 UTC (rev 1499)
@@ -0,0 +1,43 @@
+# 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 code_creator
+
+
+class name_mapping_t(code_creator.code_creator_t):
+ """creates dictionery { [un]decorated name : [un]decorated name }"""
+
+ def __init__( self, exported_symbols ):
+ code_creator.code_creator_t.__init__(self)
+ self._exported_symbols = exported_symbols
+
+
+ def _create_impl(self):
+ tmpl = '"%s" : "%s", '
+ items_decorated = []
+ items_undecorated = []
+ for blob, undecorated in self._exported_symbols.iteritems():
+ items_decorated.append( tmpl % ( blob, undecorated ) )
+ items_undecorated.append( tmpl % ( undecorated, blob ) )
+
+ result = []
+ result.append('%s.undecorated_names = {#mapping between decorated and undecorated names' % self._dictionary_var_name ]
+ for s in items_undecorated:
+ result.append( self.indent( s ) )
+ for s in items_decorated:
+ result.append( self.indent( s ) )
+ result.append( '}' )
+ return os.linesep.join( result )
+
+
+ def _get_system_headers_impl( self ):
+ return []
+
+
+if __name__ == '__main__':
+ data = { 'a' : 'AA', 'b' : 'BB' }
+ nm = name_mapping_t( 'name_mapping', data )
+ print nm.create()
Modified: pyplusplus_dev/pyplusplus/cpptypes/name_mapping.py
===================================================================
--- pyplusplus_dev/pyplusplus/cpptypes/name_mapping.py 2008-12-24 21:48:48 UTC (rev 1498)
+++ pyplusplus_dev/pyplusplus/cpptypes/name_mapping.py 2008-12-25 11:46:00 UTC (rev 1499)
@@ -25,8 +25,7 @@
Obviously the result is too big and some additional work should be done.
"""
-data = \
-{u'??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z': u'std::basic_ostream<char,std::char_traits<char> > & std::operator<<<std::char_traits<char> >(std::basic_ostream<char,std::char_traits<char> > &,char const *)',
+data = {u'??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z': u'std::basic_ostream<char,std::char_traits<char> > & std::operator<<<std::char_traits<char> >(std::basic_ostream<char,std::char_traits<char> > &,char const *)',
u'??0?$auto_ptr@Vnumber_t@@@std@@QAE@AAV01@@Z': u'std::auto_ptr<number_t>::auto_ptr<number_t>(std::auto_ptr<number_t> &)',
u'??0?$auto_ptr@Vnumber_t@@@std@@QAE@PAVnumber_t@@@Z': u'std::auto_ptr<number_t>::auto_ptr<number_t>(number_t *)',
u'??0?$auto_ptr@Vnumber_t@@@std@@QAE@U?$auto_ptr_ref@Vnumber_t@@@1@@Z': u'std::auto_ptr<number_t>::auto_ptr<number_t>(std::auto_ptr_ref<number_t>)',
@@ -91,4 +90,9 @@
u'void operator delete[](void *)': u'??_V@YAXPAX@Z',
u"void std::auto_ptr<number_t>::`default constructor closure'(void)": u'??_F?$auto_ptr@Vnumber_t@@@std@@QAEXXZ',
u'void std::auto_ptr<number_t>::reset(number_t *)': u'?reset@?$auto_ptr@Vnumber_t@@@std@@QAEXPAVnumber_t@@@Z',
- u'void terminate(void)': u'?terminate@@YAXXZ'}
+ u'void terminate(void)': u'?terminate@@YAXXZ'
+}
+
+
+ddd
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|