[pygccxml-commit] SF.net SVN: pygccxml: [544] pyplusplus_dev/pyplusplus
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2006-09-14 13:02:09
|
Revision: 544
http://svn.sourceforge.net/pygccxml/?rev=544&view=rev
Author: roman_yakovenko
Date: 2006-09-14 06:01:56 -0700 (Thu, 14 Sep 2006)
Log Message:
-----------
small refactoring to clean creator_t class.
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py
pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py
pyplusplus_dev/pyplusplus/module_creator/creator.py
Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py
===================================================================
--- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-09-14 12:02:53 UTC (rev 543)
+++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-09-14 13:01:56 UTC (rev 544)
@@ -90,10 +90,10 @@
if None is self._equality_comparable:
self._equality_comparable = declarations.has_public_equal( self )
return self._equality_comparable
-
+
def _set_equality_comparable( self, value ):
self._equality_comparable = value
-
+
equality_comparable = property( _get_equality_comparable, _set_equality_comparable
, doc="indicates existence of public operator=" \
+"Default value is calculated, based on information presented in the declarations tree" )
@@ -137,7 +137,7 @@
self._null_constructor_body = ''
self._copy_constructor_body = ''
self._exception_translation_code = None
-
+
def _get_redefine_operators( self ):
return self._redefine_operators
def _set_redefine_operators( self, new_value ):
@@ -211,7 +211,7 @@
@property
def exception_argument_name( self ):
"""exception argument name for translate exception function
-
+
If you don't understand what this argument is, please take a look on
Boost.Python documentation: http://www.boost.org/libs/python/doc/v2/exception_translator.html
"""
@@ -221,7 +221,7 @@
return self._exception_translation_code
def _set_exception_translation_code( self, code ):
self._exception_translation_code = code
- exception_translation_code = property( _get_exception_translation_code, _set_exception_translation_code
+ exception_translation_code = property( _get_exception_translation_code, _set_exception_translation_code
, doc="C++ exception to Python exception translation code" \
+"\nExample: PyErr_SetString(PyExc_RuntimeError, exc.what()); " \
+"\nPy++ will generate the rest of the code." \
@@ -229,29 +229,29 @@
def translate_exception_to_string( self, python_exception_type, to_string ):
"""registers exception translation to string
-
+
@param python_exception_type: Python exception type, for example PyExc_RuntimeError
@type python_exception_type: str
-
- @param to_string: C++ expression that extracts information from exception.
+
+ @param to_string: C++ expression that extracts information from exception.
The type of expression should be char*.
@type to_string: str
"""
- #NICE TO HAVE:
+ #NICE TO HAVE:
#1. exception\assert\warning should be raised if python_exception_type
# does not contain valid Python exception
#2. Py++ can validate, that member function returns char*
code = "PyErr_SetString( %(exception_type)s, %(to_string)s ); " \
% { 'exception_type' : python_exception_type, 'to_string' : to_string }
self.exception_translation_code = code
-
+
def add_declaration_code( self, code ):
"""adds the code to the declaration section"""
self.declaration_code.append( user_text.user_text_t( code ) )
def add_registration_code( self, code, works_on_instance=True ):
"""adds the code to the class registration section
-
+
works_on_instance: If true, the custom code can be applied directly to obj inst.
Example: ObjInst."CustomCode"
"""
@@ -278,3 +278,35 @@
if not self in self.parent.public_members:
return 'Py++ can not expose private class.'
return ''
+
+ def get_exportable_members( self, sort=None ):
+ """returns list of internal declarations that should\\could be exported"""
+ #TODO: obviously this function should be shorter. Almost all logic of this class
+ # should be spread between decl_wrapper classes
+ members = filter( lambda mv: mv.ignore == False and mv.exportable, self.public_members )
+ #protected and private virtual functions that not overridable and not pure
+ #virtual should not be exported
+ for member in self.protected_members:
+ if not isinstance( member, declarations.calldef_t ):
+ continue
+ else:
+ members.append( member )
+
+ vfunction_selector = lambda member: isinstance( member, declarations.member_function_t ) \
+ and member.virtuality == declarations.VIRTUALITY_TYPES.PURE_VIRTUAL
+ members.extend( filter( vfunction_selector, self.private_members ) )
+ #now lets filter out none public operators: Py++ does not support them right now
+ members = filter( lambda decl: not isinstance( decl, declarations.member_operator_t )
+ or decl.access_type == declarations.ACCESS_TYPES.PUBLIC
+ , members )
+ #-#if declarations.has_destructor( self ) \
+ #-# and not declarations.has_public_destructor( self ):
+ #remove artificial constructors
+ members = filter( lambda decl: not isinstance( decl, declarations.constructor_t )
+ or not decl.is_artificial
+ , members )
+ members = filter( lambda member: member.ignore == False and member.exportable, members )
+ sorted_members = members
+ if sort:
+ sorted_members = sort( members )
+ return sorted_members
Modified: pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py
===================================================================
--- pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py 2006-09-14 12:02:53 UTC (rev 543)
+++ pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py 2006-09-14 13:01:56 UTC (rev 544)
@@ -97,6 +97,9 @@
self._exportable_reason = 'Py++, by default, does not expose internal compilers declarations. Names of those declarations usually start with "__".'
elif self.location and self.location.file_name == "<internal>":
self._exportable_reason = 'Py++, by default, does not expose internal declarations (those that gccxml say belong to "<internal>" header).'
+ elif self.is_artificial \
+ and not isinstance( self, ( declarations.class_t, declarations.enumeration_t ) ):
+ self._exportable_reason = 'Py++, by default, does not expose compiler generated declarations.'
else:
self._exportable_reason = self._exportable_impl( )
self._exportable = not bool( self._exportable_reason )
Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-09-14 12:02:53 UTC (rev 543)
+++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-09-14 13:01:56 UTC (rev 544)
@@ -45,7 +45,13 @@
INDEXING_SUITE_2_MAIN_HEADER = "boost/python/suite/indexing/container_suite.hpp"
-DO_NOT_REPORT_MSGS = [ "Py++ does not exports compiler generated constructors" ]
+DO_NOT_REPORT_MSGS = [
+ "Py++ does not exports compiler generated constructors"
+ , 'Py++, by default, does not expose internal compilers declarations. Names of those declarations usually start with "__".'
+ , 'Py++, by default, does not expose internal declarations (those that gccxml say belong to "<internal>" header).'
+ , 'Py++, by default, does not expose compiler generated declarations.'
+ , 'Py++ can not expose private class.'
+]
class creator_t( declarations.decl_visitor_t ):
"""Creating code creators.
@@ -117,7 +123,7 @@
self.__extmodule.adopt_creator( self.__module_body )
prepared_decls = self._prepare_decls( decls, doc_extractor )
- self.__decls = self._filter_decls( self._reorder_decls( prepared_decls ) )
+ self.__decls = self._reorder_decls( prepared_decls )
self.curr_code_creator = self.__module_body
self.curr_decl = None
@@ -163,7 +169,6 @@
for msg in readme:
self.decl_logger.warn( "%s;%s" % ( decl, msg ) )
-
#leave only declarations defined under namespace, but remove namespaces
decls = filter( lambda x: not isinstance( x, declarations.namespace_t ) \
and isinstance( x.parent, declarations.namespace_t )
@@ -217,48 +222,6 @@
new_ordered.extend( variables )
return new_ordered #
- def _exportable_class_members( self, class_decl ):
- assert isinstance( class_decl, declarations.class_t )
- members = filter( lambda mv: mv.ignore == False and mv.exportable, class_decl.public_members )
- #protected and private virtual functions that not overridable and not pure
- #virtual should not be exported
- for member in class_decl.protected_members:
- if not isinstance( member, declarations.calldef_t ):
- continue
- else:
- members.append( member )
-
- vfunction_selector = lambda member: isinstance( member, declarations.member_function_t ) \
- and member.virtuality == VIRTUALITY_TYPES.PURE_VIRTUAL
- members.extend( filter( vfunction_selector, class_decl.private_members ) )
- #now lets filter out none public operators: Py++ does not support them right now
- members = filter( lambda decl: not isinstance( decl, declarations.member_operator_t )
- or decl.access_type == ACCESS_TYPES.PUBLIC
- , members )
- #-#if declarations.has_destructor( class_decl ) \
- #-# and not declarations.has_public_destructor( class_decl ):
- #remove artificial constructors
- members = filter( lambda decl: not isinstance( decl, declarations.constructor_t )
- or not decl.is_artificial
- , members )
- members = filter( lambda member: member.ignore == False and member.exportable, members )
- ordered_members = self._reorder_decls( members )
- return ordered_members
-
- def _does_class_have_smth_to_export(self, exportable_members ):
- return bool( self._filter_decls( exportable_members ) )
-
- def _filter_decls( self, decls ):
- # Filter out artificial (compiler created) types unless they are classes
- # See: http://public.kitware.com/pipermail/gccxml/2004-October/000486.html
- decls = filter( lambda x: not (x.is_artificial and
- not (isinstance(x, ( declarations.class_t, declarations.enumeration_t))))
- , decls )
- # Filter out type defs
- decls = filter( lambda x: not isinstance( x, declarations.typedef_t ), decls )
-
- return decls
-
def __is_same_func( self, f1, f2 ):
if not f1.__class__ is f2.__class__:
return False
@@ -602,7 +565,7 @@
self.__module_body.adopt_creator( maker )
cwrapper = None
- exportable_members = self._exportable_class_members(self.curr_code_creator.declaration)
+ exportable_members = self.curr_code_creator.declaration.get_exportable_members()
if self._is_wrapper_needed( self.curr_decl.parent, exportable_members ):
class_wrapper = self.curr_code_creator.wrapper
cwrapper = code_creators.constructor_wrapper_t( constructor=self.curr_decl )
@@ -710,7 +673,7 @@
assert isinstance( self.curr_decl, declarations.class_t )
cls_decl = self.curr_decl
cls_parent_cc = self.curr_code_creator
- exportable_members = self._exportable_class_members(self.curr_decl)
+ exportable_members = self.curr_decl.get_exportable_members(self._reorder_decls)
wrapper = None
cls_cc = code_creators.class_t( class_inst=self.curr_decl )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|