pygccxml-commit Mailing List for C++ Python language bindings (Page 57)
Brought to you by:
mbaas,
roman_yakovenko
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
(190) |
Apr
(166) |
May
(170) |
Jun
(75) |
Jul
(105) |
Aug
(131) |
Sep
(99) |
Oct
(84) |
Nov
(67) |
Dec
(54) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(66) |
Feb
(49) |
Mar
(25) |
Apr
(62) |
May
(21) |
Jun
(34) |
Jul
(9) |
Aug
(21) |
Sep
(5) |
Oct
|
Nov
(63) |
Dec
(34) |
2008 |
Jan
(10) |
Feb
(42) |
Mar
(26) |
Apr
(25) |
May
(6) |
Jun
(40) |
Jul
(18) |
Aug
(29) |
Sep
(6) |
Oct
(32) |
Nov
(14) |
Dec
(56) |
2009 |
Jan
(127) |
Feb
(52) |
Mar
(2) |
Apr
(10) |
May
(29) |
Jun
(3) |
Jul
|
Aug
(16) |
Sep
(4) |
Oct
(11) |
Nov
(8) |
Dec
(14) |
2010 |
Jan
(31) |
Feb
(1) |
Mar
(7) |
Apr
(9) |
May
(1) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
(8) |
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <rom...@us...> - 2006-08-23 19:28:08
|
Revision: 441 Author: roman_yakovenko Date: 2006-08-23 12:27:57 -0700 (Wed, 23 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=441&view=rev Log Message: ----------- making _[s|g]get_virtuality to be public methods Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/calldef.py Modified: pygccxml_dev/pygccxml/declarations/calldef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/calldef.py 2006-08-23 15:09:21 UTC (rev 440) +++ pygccxml_dev/pygccxml/declarations/calldef.py 2006-08-23 19:27:57 UTC (rev 441) @@ -285,12 +285,12 @@ and self.has_static == other.has_static \ and self.has_const == other.has_const - def _get_virtuality(self): + def get_virtuality(self): return self._virtuality - def _set_virtuality(self, virtuality): + def set_virtuality(self, virtuality): assert virtuality in VIRTUALITY_TYPES.ALL self._virtuality = virtuality - virtuality = property( _get_virtuality, _set_virtuality + virtuality = property( get_virtuality, set_virtuality , doc="""Describes the "virtuality" of the member (as defined by the string constants in the class L{VIRTUALITY_TYPES}). @type: str""") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mb...@us...> - 2006-08-23 15:09:27
|
Revision: 440 Author: mbaas Date: 2006-08-23 08:09:21 -0700 (Wed, 23 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=440&view=rev Log Message: ----------- The 'flag' argument on expose() and ignore() was not taken into account. This is fixed now. Modified Paths: -------------- pyplusplus_dev/contrib/pypp_api/pypp_api/declwrapper.py Modified: pyplusplus_dev/contrib/pypp_api/pypp_api/declwrapper.py =================================================================== --- pyplusplus_dev/contrib/pypp_api/pypp_api/declwrapper.py 2006-08-23 10:05:33 UTC (rev 439) +++ pyplusplus_dev/contrib/pypp_api/pypp_api/declwrapper.py 2006-08-23 15:09:21 UTC (rev 440) @@ -131,6 +131,8 @@ @returns: Returns self @see: L{ignore()} """ + if not flag: + return self.ignore() self._checkLock() for d in self._iterContained(): if decoration_log!=None: @@ -150,6 +152,8 @@ @return: Returns self @see: L{expose()} """ + if not flag: + return self.expose() self._checkLock() for d in self._iterContained(): if decoration_log!=None: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mb...@us...> - 2006-08-23 10:05:51
|
Revision: 439 Author: mbaas Date: 2006-08-23 03:05:33 -0700 (Wed, 23 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=439&view=rev Log Message: ----------- Added a readme Added Paths: ----------- pyplusplus_dev/contrib/pypp_api/readme.txt Added: pyplusplus_dev/contrib/pypp_api/readme.txt =================================================================== --- pyplusplus_dev/contrib/pypp_api/readme.txt (rev 0) +++ pyplusplus_dev/contrib/pypp_api/readme.txt 2006-08-23 10:05:33 UTC (rev 439) @@ -0,0 +1,30 @@ +pypp_api +======== + +pypp_api is an optional high-level API built on top of Py++. It can be +used to control the binding creation process without that you have to +know every detail about the internals of pygccxml and Py++. + +Usage +----- + +In order to use the package set PYTHONPATH to contrib/pypp_api so +that you can import pypp_api. +In your script you will usually import the API as follows: + +from pypp_api import * + + +Documentation +------------- + +A quick start tutorial and a user guide are available on the Py++ wiki at: + + https://realityforge.vrsource.org/view/PyppApi/ + +(see the pages PyppTutorial and PyppUserGuide) + +You can also invoke the script generate_docs.py to generate a reference +manual using epydoc (http://epydoc.sourceforge.net). If you are new to +pypp_api I recommend to have a look at the wiki first. + Property changes on: pyplusplus_dev/contrib/pypp_api/readme.txt ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mb...@us...> - 2006-08-23 09:31:31
|
Revision: 438 Author: mbaas Date: 2006-08-23 02:31:26 -0700 (Wed, 23 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=438&view=rev Log Message: ----------- Added some license information Added Paths: ----------- pyplusplus_dev/contrib/pypp_api/license.txt Added: pyplusplus_dev/contrib/pypp_api/license.txt =================================================================== --- pyplusplus_dev/contrib/pypp_api/license.txt (rev 0) +++ pyplusplus_dev/contrib/pypp_api/license.txt 2006-08-23 09:31:26 UTC (rev 438) @@ -0,0 +1,2 @@ +The pypp_api package is distributed under the same license as the main +pyplusplus package. Property changes on: pyplusplus_dev/contrib/pypp_api/license.txt ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-23 08:56:06
|
Revision: 437 Author: roman_yakovenko Date: 2006-08-23 01:55:55 -0700 (Wed, 23 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=437&view=rev Log Message: ----------- fixing few bugs in topological sort algorithm: 1. Internal classes dependencies are treated as parent class dependencies 2. enums defined in a class, from now add dependencies to the class they used in, from the class they defined in Modified Paths: -------------- pyplusplus_dev/pyplusplus/module_creator/class_organizer.py Modified: pyplusplus_dev/pyplusplus/module_creator/class_organizer.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/class_organizer.py 2006-08-23 05:13:51 UTC (rev 436) +++ pyplusplus_dev/pyplusplus/module_creator/class_organizer.py 2006-08-23 08:55:55 UTC (rev 437) @@ -11,9 +11,9 @@ BLACK = 2 -class class_organizer_t(object): +class class_organizer_t(object): def __init__( self, decls ): - object.__init__( self ) + object.__init__( self ) self.__classes = filter( lambda x: isinstance( x, declarations.class_t ) , decls ) @@ -30,10 +30,10 @@ self.__desired_order = [] self._topological_sort() - + def _build_graph(self): full_name = declarations.full_name - graph = {} # + graph = {} # for class_ in self.__classes: assert isinstance( class_, declarations.class_t ) fname = full_name( class_ ) @@ -50,6 +50,11 @@ , declarations.make_flatten( class_ )) for calldef in calldefs: for arg in calldef.arguments: + if declarations.is_enum( arg.type ): + top_class_inst = self.__get_top_class_inst( declarations.enum_declaration( arg.type ) ) + if top_class_inst: + i_depend_on_them.add( full_name( top_class_inst ) ) + continue if not arg.default_value: continue if declarations.is_pointer( arg.type ) and arg.default_value == 0: @@ -58,8 +63,13 @@ if not isinstance( base_type, declarations.declarated_t ): continue top_class_inst = self.__get_top_class_inst( base_type.declaration ) - i_depend_on_them.add( full_name( top_class_inst ) ) - + if top_class_inst: + i_depend_on_them.add( full_name( top_class_inst ) ) + + for internal_cls in class_.classes(allow_empty=True): + internal_cls_dependencies = self.__find_out_class_dependencies( internal_cls ) + i_depend_on_them.update( internal_cls_dependencies ) + i_depend_on_them = list( i_depend_on_them ) i_depend_on_them.sort() return i_depend_on_them @@ -68,16 +78,17 @@ curr = decl while isinstance( curr.parent, declarations.class_t ): curr = curr.parent - return curr + if isinstance( curr, declarations.class_t ): + return curr def _topological_sort(self): self._dfs() - + def _dfs( self ): for class_ in sorted( self.__dependencies_graph.keys() ): if self.__colors[class_] == COLOR.WHITE: self._dfs_visit(class_) - + def _dfs_visit(self, base): self.__colors[base] = COLOR.GRAY self.__time += 1 @@ -89,13 +100,13 @@ pass #there is usecase where base class defined within some class #but his derives defined out of the class. right now Py++ - #doesn't supports this situation. + #doesn't supports this situation. self.__colors[base] = COLOR.BLACK self.__time += 1 self.__class_treated = self.__time self.__desired_order.append(base) - + def desired_order(self): full_name = declarations.full_name fname2inst = {} @@ -108,4 +119,4 @@ def findout_desired_order( decls ): organizer = class_organizer_t( decls ) - return organizer.desired_order() \ No newline at end of file + return organizer.desired_order() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-23 05:13:57
|
Revision: 436 Author: roman_yakovenko Date: 2006-08-22 22:13:51 -0700 (Tue, 22 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=436&view=rev Log Message: ----------- few comments on goodies Modified Paths: -------------- pyplusplus_dev/contrib/goodies/goodie_utils.py Modified: pyplusplus_dev/contrib/goodies/goodie_utils.py =================================================================== --- pyplusplus_dev/contrib/goodies/goodie_utils.py 2006-08-22 21:57:20 UTC (rev 435) +++ pyplusplus_dev/contrib/goodies/goodie_utils.py 2006-08-23 05:13:51 UTC (rev 436) @@ -1,111 +1,118 @@ -# Copyright 2004 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) -# -# Authors: -# Allen Bierbaum -# -import pygccxml.declarations as pd -from pyplusplus.module_builder.call_policies import * -import pygccxml.declarations.type_traits as tt -import pygccxml.declarations.cpptypes as cpptypes -import pyplusplus.code_creators as code_creators -import pyplusplus.decl_wrappers as decl_wrappers - - -def set_recursive_default(val): - pd.scopedef_t.RECURSIVE_DEFAULT = val - -def finalize(cls): - """ Attempt to finalize a class by not exposing virtual methods. - Still exposes in the case of pure virtuals otherwise the class - could not be instantiated. - """ - members = cls.member_functions(allow_empty=True) - if members: - for m in members: - if m.virtuality == pd.VIRTUALITY_TYPES.VIRTUAL: - m.virtuality = pd.VIRTUALITY_TYPES.NOT_VIRTUAL - - -def add_member_function(cls, methodName, newMethod): - """ Add a member function to the class. """ - cls.add_registration_code('def("%s",%s)'%(methodName, newMethod), True) - -def wrap_method(cls, methodName, newMethod): - """ Wrap a class method with a new method. - ex: c.wrapmethod(c,"doSomething","doSomethingWrapper") - """ - cls[methodName].exclude() - add_member_function(cls, methodName, newMethod) - -def add_method(moduleBuilder, methodName, method): - """ Add a method to the module builder. """ - code_text = 'boost::python::def("%s",%s);'%(methodName, method) - moduleBuilder.code_creator.body.adopt_creator( code_creators.custom_text_t( code_text ), 0 ) - -def is_const_ref(type): - """ Extra trait tester method to check if something is a const reference. """ - is_const = tt.is_const(type) or (hasattr(type,'base') and tt.is_const(type.base)) - is_ref = tt.is_reference(type) or (hasattr(type,'base') and tt.is_reference(type.base)) - return (is_ref and is_const) - -def exclude_protected(cls): - """ Exclude all protected declarations. """ - cls.decls(pd.access_type_matcher_t('protected'),allow_empty=True).exclude() - -def wrap_const_ref_params(cls): - """ Find all member functions of cls and if they take a const& to a class - that does not have a destructor, then create a thin wrapper for them. - This works around an issue with boost.python where it needs a destructor. - """ - calldefs = cls.calldefs() - - if None == calldefs: - return - - for c in calldefs: - # Skip constructors - if isinstance(c, pd.constructor_t): - continue - - # Find arguments that need replacing - args_to_replace = [] # List of indices to args to replace with wrapping - args = c.arguments - for i in range(len(args)): - arg = args[i] - if is_const_ref(arg.type): - naked_arg = tt.remove_cv(tt.remove_reference(arg.type)) - if tt.is_class(naked_arg): - class_type = naked_arg.declaration - if not tt.has_public_destructor(class_type): - print "Found indestructible const& arg: [%s]:[%s] "%(str(c), str(arg)) - args_to_replace.append(i) - - # Now replace arguments - if len(args_to_replace): - if isinstance(c, pd.operator_t) and c.symbol in ["<","==","!=","="]: - c.exclude() - continue - - new_args = copy.copy(args) # Make new copy of args so we don't modify the existing method - for i in args_to_replace: - old_arg_type = args[i].type - if tt.is_reference(old_arg_type) and tt.is_const(old_arg_type.base): - new_args[i].type = cpptypes.reference_t(tt.remove_const(old_arg_type.base)) - elif tt.is_const(old_arg): - new_args[i].type = tt.remove_const(old_arg_type) - - new_name = "%s_const_ref_wrapper"%c.name - args_str = [str(a) for a in new_args] - arg_names_str = [str(a.name) for a in new_args] - new_sig = "static %s %s(%s& self_arg, %s)"%(c.return_type,new_name,cls.name,",".join(args_str)) - new_method = """%s - { return self_arg.%s(%s); } - """%(new_sig,c.name,",".join(arg_names_str)) - - # Add it all - c.exclude() - cls.add_wrapper_code(new_method) - cls.add_code('def("%s", &%s::%s);'%(c.name, cls.wrapper_alias,new_name)) +# Copyright 2004 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) +# +# Authors: +# Allen Bierbaum +# +import pygccxml.declarations as pd +from pyplusplus.module_builder.call_policies import * +import pygccxml.declarations.type_traits as tt +import pygccxml.declarations.cpptypes as cpptypes +import pyplusplus.code_creators as code_creators +import pyplusplus.decl_wrappers as decl_wrappers + + +def set_recursive_default(val): + pd.scopedef_t.RECURSIVE_DEFAULT = val + +#[Roman]The better way is to turn virtuality from virtual to non virtual +def finalize(cls): + """ Attempt to finalize a class by not exposing virtual methods. + Still exposes in the case of pure virtuals otherwise the class + could not be instantiated. + """ + members = cls.member_functions(allow_empty=True) + if members: + for m in members: + if m.virtuality == pd.VIRTUALITY_TYPES.VIRTUAL: + m.virtuality = pd.VIRTUALITY_TYPES.NOT_VIRTUAL + + +def add_member_function(cls, methodName, newMethod): + """ Add a member function to the class. """ + cls.add_registration_code('def("%s",%s)'%(methodName, newMethod), True) + +def wrap_method(cls, methodName, newMethod): + """ Wrap a class method with a new method. + ex: c.wrapmethod(c,"doSomething","doSomethingWrapper") + """ + cls[methodName].exclude() + add_member_function(cls, methodName, newMethod) + +def add_method(moduleBuilder, methodName, method): + """ Add a method to the module builder. """ + code_text = 'boost::python::def("%s",%s);'%(methodName, method) + moduleBuilder.code_creator.body.adopt_creator( code_creators.custom_text_t( code_text ), 0 ) + #[Roman]moduleBuilder.add_registration_code( ... ), see relevant documentation + + +def is_const_ref(type): + """ Extra trait tester method to check if something is a const reference. """ + is_const = tt.is_const(type) or (hasattr(type,'base') and tt.is_const(type.base)) + is_ref = tt.is_reference(type) or (hasattr(type,'base') and tt.is_reference(type.base)) + return (is_ref and is_const) + #[Roman]If you create unit tests for this code, I will add it to type traits module + +def exclude_protected(cls): + """ Exclude all protected declarations. """ + cls.decls(pd.access_type_matcher_t('protected'),allow_empty=True).exclude() + +def wrap_const_ref_params(cls): + """ Find all member functions of cls and if they take a const& to a class + that does not have a destructor, then create a thin wrapper for them. + This works around an issue with boost.python where it needs a destructor. + """ + #[Roman] Obviously, this will only work, if the function does not need other + #wrapper, I think, this is a new use case for Matthias "arguments policies" + #functionality. + calldefs = cls.calldefs() + + if None == calldefs: + return + + for c in calldefs: + # Skip constructors + if isinstance(c, pd.constructor_t): + continue + + # Find arguments that need replacing + args_to_replace = [] # List of indices to args to replace with wrapping + args = c.arguments + for i in range(len(args)): + arg = args[i] + if is_const_ref(arg.type): + naked_arg = tt.remove_cv(tt.remove_reference(arg.type)) + if tt.is_class(naked_arg): + class_type = naked_arg.declaration + if not tt.has_public_destructor(class_type): + print "Found indestructible const& arg: [%s]:[%s] "%(str(c), str(arg)) + args_to_replace.append(i) + + # Now replace arguments + if len(args_to_replace): + if isinstance(c, pd.operator_t) and c.symbol in ["<","==","!=","="]: + c.exclude() + continue + + new_args = copy.copy(args) # Make new copy of args so we don't modify the existing method + for i in args_to_replace: + old_arg_type = args[i].type + if tt.is_reference(old_arg_type) and tt.is_const(old_arg_type.base): + new_args[i].type = cpptypes.reference_t(tt.remove_const(old_arg_type.base)) + elif tt.is_const(old_arg): + new_args[i].type = tt.remove_const(old_arg_type) + + new_name = "%s_const_ref_wrapper"%c.name + args_str = [str(a) for a in new_args] + arg_names_str = [str(a.name) for a in new_args] + new_sig = "static %s %s(%s& self_arg, %s)"%(c.return_type,new_name,cls.name,",".join(args_str)) + new_method = """%s + { return self_arg.%s(%s); } + """%(new_sig,c.name,",".join(arg_names_str)) + + # Add it all + c.exclude() + cls.add_wrapper_code(new_method) + cls.add_code('def("%s", &%s::%s);'%(c.name, cls.wrapper_alias,new_name)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2006-08-22 21:57:25
|
Revision: 435 Author: allenb Date: 2006-08-22 14:57:20 -0700 (Tue, 22 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=435&view=rev Log Message: ----------- Very raw in progress work on goodies. (I needed to commit it so I could work from home on the code) I was hoping to work all day on this but only got about an hour. Added Paths: ----------- pyplusplus_dev/contrib/goodies/ pyplusplus_dev/contrib/goodies/__init__.py pyplusplus_dev/contrib/goodies/dsl_interface.py pyplusplus_dev/contrib/goodies/goodie_utils.py Added: pyplusplus_dev/contrib/goodies/__init__.py =================================================================== --- pyplusplus_dev/contrib/goodies/__init__.py (rev 0) +++ pyplusplus_dev/contrib/goodies/__init__.py 2006-08-22 21:57:20 UTC (rev 435) @@ -0,0 +1,12 @@ +# Copyright 2004 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) +# +# Authors: +# Allen Bierbaum +# +from dsl_interface import * +from goodie_utils import (set_recursive_default, finalize, add_member_function, + wrap_method, add_method, is_const_ref, exclude_protected, + wrap_const_ref_params) Added: pyplusplus_dev/contrib/goodies/dsl_interface.py =================================================================== --- pyplusplus_dev/contrib/goodies/dsl_interface.py (rev 0) +++ pyplusplus_dev/contrib/goodies/dsl_interface.py 2006-08-22 21:57:20 UTC (rev 435) @@ -0,0 +1,33 @@ +# Copyright 2004 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) +# +# Authors: +# Allen Bierbaum +# + +# Dictionary of this module. Useful for adding symbols +mod_dict = globals() + +# Bring in the module builder and alias it +import pyplusplus.module_builder +ModuleBuilder = pyplusplus.module_builder.module_builder_t +set_logger_level = pyplusplus.module_builder.set_logger_level + +# Bring in all call policy symbols +from pyplusplus.module_builder.call_policies import * + +from pyplusplus.decl_wrappers import print_declarations + + +# Type traits + +# Matchers +# - Bring in all matchers but rename then without the '_t' at the end +import pygccxml.declarations.matchers +for n in ["matcher_base_t","or_matcher_t","and_matcher_t","not_matcher_t", + "declaration_matcher_t","calldef_matcher_t","namespace_matcher_t", + "variable_matcher_t","regex_matcher_t","access_type_matcher_t", + "operator_matcher_t","custom_matcher_t","virtuality_type_matcher_t"]: + mod_dict[n[:-2]] = pygccxml.declarations.matchers.__dict__[n] \ No newline at end of file Added: pyplusplus_dev/contrib/goodies/goodie_utils.py =================================================================== --- pyplusplus_dev/contrib/goodies/goodie_utils.py (rev 0) +++ pyplusplus_dev/contrib/goodies/goodie_utils.py 2006-08-22 21:57:20 UTC (rev 435) @@ -0,0 +1,111 @@ +# Copyright 2004 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) +# +# Authors: +# Allen Bierbaum +# +import pygccxml.declarations as pd +from pyplusplus.module_builder.call_policies import * +import pygccxml.declarations.type_traits as tt +import pygccxml.declarations.cpptypes as cpptypes +import pyplusplus.code_creators as code_creators +import pyplusplus.decl_wrappers as decl_wrappers + + +def set_recursive_default(val): + pd.scopedef_t.RECURSIVE_DEFAULT = val + +def finalize(cls): + """ Attempt to finalize a class by not exposing virtual methods. + Still exposes in the case of pure virtuals otherwise the class + could not be instantiated. + """ + members = cls.member_functions(allow_empty=True) + if members: + for m in members: + if m.virtuality == pd.VIRTUALITY_TYPES.VIRTUAL: + m.virtuality = pd.VIRTUALITY_TYPES.NOT_VIRTUAL + + +def add_member_function(cls, methodName, newMethod): + """ Add a member function to the class. """ + cls.add_registration_code('def("%s",%s)'%(methodName, newMethod), True) + +def wrap_method(cls, methodName, newMethod): + """ Wrap a class method with a new method. + ex: c.wrapmethod(c,"doSomething","doSomethingWrapper") + """ + cls[methodName].exclude() + add_member_function(cls, methodName, newMethod) + +def add_method(moduleBuilder, methodName, method): + """ Add a method to the module builder. """ + code_text = 'boost::python::def("%s",%s);'%(methodName, method) + moduleBuilder.code_creator.body.adopt_creator( code_creators.custom_text_t( code_text ), 0 ) + +def is_const_ref(type): + """ Extra trait tester method to check if something is a const reference. """ + is_const = tt.is_const(type) or (hasattr(type,'base') and tt.is_const(type.base)) + is_ref = tt.is_reference(type) or (hasattr(type,'base') and tt.is_reference(type.base)) + return (is_ref and is_const) + +def exclude_protected(cls): + """ Exclude all protected declarations. """ + cls.decls(pd.access_type_matcher_t('protected'),allow_empty=True).exclude() + +def wrap_const_ref_params(cls): + """ Find all member functions of cls and if they take a const& to a class + that does not have a destructor, then create a thin wrapper for them. + This works around an issue with boost.python where it needs a destructor. + """ + calldefs = cls.calldefs() + + if None == calldefs: + return + + for c in calldefs: + # Skip constructors + if isinstance(c, pd.constructor_t): + continue + + # Find arguments that need replacing + args_to_replace = [] # List of indices to args to replace with wrapping + args = c.arguments + for i in range(len(args)): + arg = args[i] + if is_const_ref(arg.type): + naked_arg = tt.remove_cv(tt.remove_reference(arg.type)) + if tt.is_class(naked_arg): + class_type = naked_arg.declaration + if not tt.has_public_destructor(class_type): + print "Found indestructible const& arg: [%s]:[%s] "%(str(c), str(arg)) + args_to_replace.append(i) + + # Now replace arguments + if len(args_to_replace): + if isinstance(c, pd.operator_t) and c.symbol in ["<","==","!=","="]: + c.exclude() + continue + + new_args = copy.copy(args) # Make new copy of args so we don't modify the existing method + for i in args_to_replace: + old_arg_type = args[i].type + if tt.is_reference(old_arg_type) and tt.is_const(old_arg_type.base): + new_args[i].type = cpptypes.reference_t(tt.remove_const(old_arg_type.base)) + elif tt.is_const(old_arg): + new_args[i].type = tt.remove_const(old_arg_type) + + new_name = "%s_const_ref_wrapper"%c.name + args_str = [str(a) for a in new_args] + arg_names_str = [str(a.name) for a in new_args] + new_sig = "static %s %s(%s& self_arg, %s)"%(c.return_type,new_name,cls.name,",".join(args_str)) + new_method = """%s + { return self_arg.%s(%s); } + """%(new_sig,c.name,",".join(arg_names_str)) + + # Add it all + c.exclude() + cls.add_wrapper_code(new_method) + cls.add_code('def("%s", &%s::%s);'%(c.name, cls.wrapper_alias,new_name)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2006-08-22 21:56:43
|
Revision: 434 Author: allenb Date: 2006-08-22 14:56:24 -0700 (Tue, 22 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=434&view=rev Log Message: ----------- Make contrib look a little like a package to python. This will allow a user to just add the contrib directory to their python path and then "import contrib.package_name". This is much easier to deal with then having to add a bunch of paths. Added Paths: ----------- pyplusplus_dev/contrib/__init__.py Added: pyplusplus_dev/contrib/__init__.py =================================================================== --- pyplusplus_dev/contrib/__init__.py (rev 0) +++ pyplusplus_dev/contrib/__init__.py 2006-08-22 21:56:24 UTC (rev 434) @@ -0,0 +1,4 @@ +# Copyright 2004 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) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-22 18:57:55
|
Revision: 433 Author: roman_yakovenko Date: 2006-08-22 11:57:43 -0700 (Tue, 22 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=433&view=rev Log Message: ----------- updating documentation Modified Paths: -------------- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-08-22 13:36:39 UTC (rev 432) +++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-08-22 18:57:43 UTC (rev 433) @@ -10,8 +10,15 @@ from pygccxml import declarations class calldef_t(decl_wrapper.decl_wrapper_t): - """keeps configur global and member variable exposing""" + """base class for all decl_wrappers callable objects classes.""" + BOOST_PYTHON_MAX_ARITY = 10 + """Boost.Python configuration macro value. + + A function has more than BOOST_PYTHON_MAX_ARITY arguments, will not compile. + You should adjust BOOST_PYTHON_MAX_ARITY macro. + For more information see: http://mail.python.org/pipermail/c++-sig/2002-June/001554.html + """ def __init__(self, *arguments, **keywords): decl_wrapper.decl_wrapper_t.__init__( self, *arguments, **keywords ) @@ -26,27 +33,41 @@ return self._call_policies def set_call_policies(self, call_policies): self._call_policies = call_policies - call_policies = property( get_call_policies, set_call_policies ) + call_policies = property( get_call_policies, set_call_policies + , doc="reference to L{call policies<call_policy_t>} class." \ + +"Default value is calculated at runtime, based on return value.") def _get_use_keywords(self): return self._use_keywords and bool( self.arguments ) def _set_use_keywords(self, use_keywords): self._use_keywords = use_keywords - use_keywords = property( _get_use_keywords, _set_use_keywords ) + use_keywords = property( _get_use_keywords, _set_use_keywords + , doc="boolean, if True, allows to call function from Python using keyword arguments." \ + +"Default value is True.") def _get_create_with_signature(self): return self._create_with_signature or bool( self.overloads ) def _set_create_with_signature(self, create_with_signature): self._create_with_signature = create_with_signature - create_with_signature = property( _get_create_with_signature, _set_create_with_signature) + create_with_signature = property( _get_create_with_signature, _set_create_with_signature + , doc="boolean, if True Py++ will generate next code: def( ..., function type( function ref )"\ + +"Thus, the generated code is safe, when a user creates function overloading." \ + +"Default value is computed, based on information from the declarations tree" ) def _get_use_default_arguments(self): return self._use_default_arguments def _set_use_default_arguments(self, use_default_arguments): self._use_default_arguments = use_default_arguments - use_default_arguments = property( _get_use_default_arguments, _set_use_default_arguments ) + use_default_arguments = property( _get_use_default_arguments, _set_use_default_arguments + , doc="boolean, if True Py++ will generate code that will set default arguments" \ + +"Default value is True.") def has_wrapper( self ): + """returns True, if function - wrapper is needed + + The functionality by this function is uncomplete. So please don't + use it in your code. + """ if not isinstance( self, declarations.member_calldef_t ): return False elif self.virtuality == declarations.VIRTUALITY_TYPES.PURE_VIRTUAL: @@ -56,20 +77,18 @@ else: return False - def _finalize_impl( self, error_behavior ): - if not isinstance( self, declarations.member_calldef_t ): - pass - elif self.virtuality == declarations.VIRTUALITY_TYPES.PURE_VIRTUAL: - raise RuntimeError( "In order to expose pure virtual function, you should allow to Py++ to create wrapper." ) - elif self.access_type == declarations.ACCESS_TYPES.PROTECTED: - self.ignore = True - else: - pass + #def _finalize_impl( self, error_behavior ): + #if not isinstance( self, declarations.member_calldef_t ): + #pass + #elif self.virtuality == declarations.VIRTUALITY_TYPES.PURE_VIRTUAL: + #raise RuntimeError( "In order to expose pure virtual function, you should allow to Py++ to create wrapper." ) + #elif self.access_type == declarations.ACCESS_TYPES.PROTECTED: + #self.ignore = True + #else: + #pass def get_overridable( self ): - """ - Check if the method can be overridden. - """ + """Check if the method can be overridden.""" if None is self._overridable: if isinstance( self, declarations.member_calldef_t ) \ and self.virtuality != declarations.VIRTUALITY_TYPES.NOT_VIRTUAL \ @@ -153,11 +172,13 @@ return msgs class member_function_t( declarations.member_function_t, calldef_t ): + """defines a set of properties, that will instruct Py++ how to expose the member function""" def __init__(self, *arguments, **keywords): declarations.member_function_t.__init__( self, *arguments, **keywords ) calldef_t.__init__( self ) class constructor_t( declarations.constructor_t, calldef_t ): + """defines a set of properties, that will instruct Py++ how to expose the constructor""" def __init__(self, *arguments, **keywords): declarations.constructor_t.__init__( self, *arguments, **keywords ) calldef_t.__init__( self ) @@ -167,21 +188,27 @@ return self._body def _set_body(self, body): self._body = body - body = property( _get_body, _set_body ) + body = property( _get_body, _set_body + , doc="string, class-wrapper constructor body" ) def _exportable_impl_derived( self ): if self.is_artificial: return 'Py++ does not exports compiler generated constructors' return '' +class destructor_t( declarations.destructor_t, calldef_t ): + """you may ignore this class for he time being. -class destructor_t( declarations.destructor_t, calldef_t ): + In future it will contain "body" property, that will allow to insert user + code to class-wrapper destructor. + """ + #TODO: add body property def __init__(self, *arguments, **keywords): declarations.destructor_t.__init__( self, *arguments, **keywords ) calldef_t.__init__( self ) class operators_helper: - + """helps Py++ to deal with C++ operators""" inplace = [ '+=', '-=', '*=', '/=', '%=', '>>=', '<<=', '&=', '^=', '|=' ] comparison = [ '==', '!=', '<', '>', '<=', '>=' ] non_member = [ '+', '-', '*', '/', '%', '&', '^', '|' ] #'>>', '<<', not implemented @@ -191,6 +218,7 @@ @staticmethod def is_supported( oper ): + """returns True if Boost.Python support the operator""" if oper.symbol == '*' and len( oper.arguments ) == 0: #dereference does not make sense return False @@ -198,6 +226,7 @@ @staticmethod def exportable( oper ): + """returns True if Boost.Python or Py++ know how to export the operator""" if isinstance( oper, declarations.member_operator_t ) and oper.symbol in ( '()', '[]' ): return '' if not operators_helper.is_supported( oper ): @@ -207,6 +236,7 @@ return '' class member_operator_t( declarations.member_operator_t, calldef_t ): + """defines a set of properties, that will instruct Py++ how to expose the member operator""" def __init__(self, *arguments, **keywords): declarations.member_operator_t.__init__( self, *arguments, **keywords ) calldef_t.__init__( self ) @@ -221,13 +251,15 @@ else: pass return alias - alias = property( _get_alias, decl_wrapper.decl_wrapper_t._set_alias ) + alias = property( _get_alias, decl_wrapper.decl_wrapper_t._set_alias + , doc="Gives right alias for operator()( __call__ ) and operator[]( __getitem__ )" ) def _exportable_impl_derived( self ): return operators_helper.exportable( self ) class casting_operator_t( declarations.casting_operator_t, calldef_t ): + """defines a set of properties, that will instruct Py++ how to expose the casting operator""" def prepare_special_cases(): """ @@ -289,14 +321,18 @@ else: self._alias = 'as_' + self._generate_valid_name(self.return_type.decl_string) return self._alias - alias = property( _get_alias, decl_wrapper.decl_wrapper_t._set_alias ) + alias = property( _get_alias, decl_wrapper.decl_wrapper_t._set_alias + , doc="Gives right alias for casting operators: __int__, __long__, __str__." \ + +"If there is no built-in type, creates as_xxx alias" ) class free_function_t( declarations.free_function_t, calldef_t ): + """defines a set of properties, that will instruct Py++ how to expose the free function""" def __init__(self, *arguments, **keywords): declarations.free_function_t.__init__( self, *arguments, **keywords ) calldef_t.__init__( self ) class free_operator_t( declarations.free_operator_t, calldef_t ): + """defines a set of properties, that will instruct Py++ how to expose the free operator""" def __init__(self, *arguments, **keywords): declarations.free_operator_t.__init__( self, *arguments, **keywords ) calldef_t.__init__( self ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mb...@us...> - 2006-08-22 13:36:44
|
Revision: 432 Author: mbaas Date: 2006-08-22 06:36:39 -0700 (Tue, 22 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=432&view=rev Log Message: ----------- Modified the __iter__() method so it does not iterate over the decls recursively anymore (which is done by iterContained()). The __str__ method now uses str(decl) instead of decl.name to provide more information. Modified Paths: -------------- pyplusplus_dev/contrib/pypp_api/pypp_api/declwrapper.py Modified: pyplusplus_dev/contrib/pypp_api/pypp_api/declwrapper.py =================================================================== --- pyplusplus_dev/contrib/pypp_api/pypp_api/declwrapper.py 2006-08-22 09:53:53 UTC (rev 431) +++ pyplusplus_dev/contrib/pypp_api/pypp_api/declwrapper.py 2006-08-22 13:36:39 UTC (rev 432) @@ -93,14 +93,23 @@ if len(self.decl_handles)==0: return "Decl: <empty>" elif len(self.decl_handles)==1: - ds = getattr(self.decl_handles[0], "name", "?") +# ds = getattr(self.decl_handles[0], "name", "?") + ds = str(self.decl_handles[0]) return 'Decl: "%s"'%(ds) else: return 'Decl: (%d declarations)'%(len(self.decl_handles)) def __iter__(self): - return self.iterContained() + """Iterate over the matched declarations (non-recursively!). + The iterator yields IDecl objects that each contain one declaration. + The number of items is identical to self.decl_handles. + """ + return iter(map(lambda decl: IDecl([decl], modulebuilder=self.modulebuilder), self.decl_handles)) + + def __len__(self): + return len(self.decl_handles) + # iterContained def iterContained(self): """Iterate over all contained nodes. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-22 09:54:10
|
Revision: 431 Author: roman_yakovenko Date: 2006-08-22 02:53:53 -0700 (Tue, 22 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=431&view=rev Log Message: ----------- adding dsl_challenge.rest document Modified Paths: -------------- pyplusplus_dev/docs/peps/peps_index.rest pyplusplus_dev/docs/peps/www_configuration.py Added Paths: ----------- pyplusplus_dev/docs/peps/dsl_challenge.rest pyplusplus_dev/docs/peps/dsl_challenge_introduction.rest Added: pyplusplus_dev/docs/peps/dsl_challenge.rest =================================================================== --- pyplusplus_dev/docs/peps/dsl_challenge.rest (rev 0) +++ pyplusplus_dev/docs/peps/dsl_challenge.rest 2006-08-22 09:53:53 UTC (rev 431) @@ -0,0 +1,214 @@ +============= +DSL challenge +============= + +.. contents:: Table of contents + +------------ +Introduction +------------ + +.. include:: ./dsl_challenge_introduction.rest + +------------------- +Py++ user interface +------------------- + +I will use next C++ code as an example: + +:: + + namespace geometry{ + struct Point{ + Point(); + Point(int x, int y); + Point( const Point& ); + + Point* create_new(){ return *this; } + + int x, y; + int private_data; + }; + } + +In order to export this class, we need: + +1. to set "call policies" to ``create_new`` member function + +2. to exclude ``private_data`` member variable + +3. to rename ``x`` and ``y`` to ``X`` and ``Y`` + +Today, in order to configure this class, the user has to write next code: +:: + + mb = module_builder_t( ... ) + Point = mb.class_( 'Point' ) + Point.member_function( 'create_new' ).call_policies = ... + Point.member_variable( 'private_data' ).exclude() + Point.member_variable( 'x' ).rename( 'X' ) + Point.member_variable( 'Y' ).rename( 'Y' ) + #or + for mvar in Point.member_variables(): + mvar.rename( mvar.name.upper() ) + +If class ``Point`` is not unique, than user will have to write a little bit +different code: +:: + + Point = mb.global_ns.namespace('geometry').class( 'Point' ) + +The current approach is pretty readable and simple. The drawbacks of this approach +are: + +1. before the user starts with `Py++`_ he is forced to read a lot of documentation +2. verbosity - in order to complete the task, the user have to write "a lot" of + code + +--------------------------- +Better user interface (BUI) +--------------------------- +:: + + mb = module_builder_t( ... ) + Point = mb.module.geometry.Point + Point.create_new.call_policies = ... + Point.private_data.exclude() + Point.x.rename( 'X' ) + Point.y.rename( 'Y' ) + +What you see here is DSL! + +---------- +Comparison +---------- + +I don't argue, that the second way is better. I would like to expose you to few +problems it has. + +Rule based approach +------------------- + +BUI does not allow to use "rule based" approach! BUI does not allow you to work +on the whole declarations tree! + +Special syntax +-------------- + +Special syntax should be introduce to support + +* template instantiations + + BUI does not work for template instantiated classes and functions. If we change + class ``Point`` to be template, the special syntax should be introduced: + + :: + + template < class Numeric > + struct Point{ + ... + }; + + :: + + PointTmpl = mb.module.template('Point') + Point = PointTmpl( 'int' ) + + This is a trivial example, that is why it looks grate. Consider next class: + :: + + template< class String, class Allocator > + class regex{ ... } + + The code the user will need to write is: + :: + + regex_tmpl = mb.module.geometry.template( 'regex' ) + #white spaces and scope resolution( :: ) are important + regex_std_string = regex_tmpl( + '::std::basic_string<char,std::char_traits<char>,std::allocator<char> >' + , '::std::allocator<char>' ) + + Using current `Py++`_ interface the user can get reference to the class + instantiation in one line of code: + :: + + regex_std_string = mb.class_( + lambda decl: decl.name.startswith( 'regex' ) and 'wchar_t' not in decl.name ) + +* overloaded functions resolution + + There are use cases, when overloaded functions should be treated differently. + It is not possible to distinguish between different functions, using BUI syntax. + +* C++ operators + + They also require special syntax. + +Readability counts +------------------ + +It is not clear from the script, on how many and on what declarations +configuration is applied. It is possible to introduce a bug. Using current `Py++`_ +API the user always states, whether he expects a declaration to be unique or not +and its type. + +Full name +--------- + +Using BUI the user is forced to write full declaration name, otherwise he faces +next problem: +:: + + Point = mb.module.Point + +Lets analyze what the ``Point`` value: + +1. It could be reference to a declaration, that has name "Point" and it is + defined under global namespace. + +2. It could be a set of declarations that has "Point" as a name from all classes + and namespaces. In our case it will contain at lease reference to class + "Point" declaration and its constructors. + + There are a lot of use cases, when the user has to add some code to the class: + + :: + + Point.add_registration_code( ... ) + + Constructor declaration does not define ``add_registration_code`` method. + According to Python rules: "Errors should never pass silently", exception + should be raised. + +Another Python rule says: "In the face of ambiguity, refuse the temptation to guess". + +----------- +Action item +----------- + +I think, it should be obvious to you, that we cannot drop current `Py++`_ user +interface. The only solution I see, is to build BUI on top of it. The reason +the project does not have BUI is simple. I don't feel comfortable to introduce +it, while I am aware to all these problems. + +The title of this section should be **Your action item** :-). I will be glad +to implement BUI, if we can solve all the problems. Consider to contribute your +experience and knowledge to fix the situation. I am sure together we will build +very powerful and easy to use code generator. + + + +.. _`Py++` : ./../pyplusplus.html +.. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html +.. _`Python`: http://www.python.org +.. _`GCC-XML`: http://www.gccxml.org + +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + End: + Added: pyplusplus_dev/docs/peps/dsl_challenge_introduction.rest =================================================================== --- pyplusplus_dev/docs/peps/dsl_challenge_introduction.rest (rev 0) +++ pyplusplus_dev/docs/peps/dsl_challenge_introduction.rest 2006-08-22 09:53:53 UTC (rev 431) @@ -0,0 +1,11 @@ + +More or less formal definition of DSL could be found `here`__. + +.. __ : http://en.wikipedia.org/wiki/Domain_Specific_Language + +`Py++`_ has been created to solve single and well-defined problem: to create +Python bindings for C++ projects. The good news - `Py++`_ achieved the goal, +the bad news - users are forced to read the documentation. DSL cannot completely +solve the problem, but it can eliminate the need to read documentation in 80% of +the cases. + Modified: pyplusplus_dev/docs/peps/peps_index.rest =================================================================== --- pyplusplus_dev/docs/peps/peps_index.rest 2006-08-21 18:35:11 UTC (rev 430) +++ pyplusplus_dev/docs/peps/peps_index.rest 2006-08-22 09:53:53 UTC (rev 431) @@ -51,7 +51,18 @@ .. __ : ./call_wrapper_policies.html +------------------------------------------ +Domain Specific Language ( DSL ) challenge +------------------------------------------ +.. include:: ./dsl_challenge_introduction.rest + +Please read `DSL challenge`_ document and contribute your ideas, thoughts or just +comments. + +.. _`DSL challenge` : ./dsl_challenge.html + + .. _`Py++` : ./../pyplusplus.html .. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html .. _`Python`: http://www.python.org Modified: pyplusplus_dev/docs/peps/www_configuration.py =================================================================== --- pyplusplus_dev/docs/peps/www_configuration.py 2006-08-21 18:35:11 UTC (rev 430) +++ pyplusplus_dev/docs/peps/www_configuration.py 2006-08-22 09:53:53 UTC (rev 431) @@ -1,4 +1,5 @@ name = 'PEP index' main_html_file = 'peps_index.html' -names = { 'indexing_suite' : 'indexing suite' - , 'call_wrapper_policies' : 'call wrapper policies' } \ No newline at end of file +files_to_skip = ['dsl_challenge_introduction.rest'] +names = { 'call_wrapper_policies' : 'call wrapper policies' + , 'dsl_challenge' : 'DSL challenge' } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-21 18:35:20
|
Revision: 430 Author: roman_yakovenko Date: 2006-08-21 11:35:11 -0700 (Mon, 21 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=430&view=rev Log Message: ----------- updating documentation Modified Paths: -------------- pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py Modified: pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2006-08-21 13:42:15 UTC (rev 429) +++ pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2006-08-21 18:35:11 UTC (rev 430) @@ -57,6 +57,7 @@ return default_t() class compound_policy_t( call_policy_t ): + """base class for all call policies, except default one""" def __init__( self, base=None ): call_policy_t.__init__( self ) self._base = base @@ -67,7 +68,8 @@ return self._base def _set_base_policy( self, new_policy ): self._base = new_policy - base_policy = property( _get_base_policy, _set_base_policy ) + base_policy = property( _get_base_policy, _set_base_policy + , doc="base call policy, by default is reference to L{default_t} call policy") def _get_args(self, function_creator): return [] @@ -88,6 +90,7 @@ return declarations.templates.join( name, args ) class return_argument_t( compound_policy_t ): + """implementation for ::boost::python::return_argument call policies""" def __init__( self, position=1, base=None): compound_policy_t.__init__( self, base ) self._position = position Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-08-21 13:42:15 UTC (rev 429) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-08-21 18:35:11 UTC (rev 430) @@ -18,15 +18,15 @@ """boolean, configures how Py++ should generate code for class. Py can generate code using IDL like syntax: - C{class_< ... >( ... )} - C{.def( ... );} + class_< ... >( ... ) + .def( ... ); Or it can generate code using more complex form: - C{typedef bp::class_< my_class > my_class_exposer_t;} - C{my_class_exposer_t my_class_exposer = my_class_exposer_t( "my_class" );} - C{boost::python::scope my_class_scope( my_class_exposer );} - C{my_class_exposer.def( ... );} + typedef bp::class_< my_class > my_class_exposer_t; + my_class_exposer_t my_class_exposer = my_class_exposer_t( "my_class" ); + boost::python::scope my_class_scope( my_class_exposer ); + my_class_exposer.def( ... ); Also, the second way is much longer, it solves few problems: @@ -72,7 +72,7 @@ break return self._indexing_suite indexing_suite = property( _get_indexing_suite - , doc="returns reference to indexing suite configuration class. " \ + , doc="reference to indexing suite configuration class. " \ +"If the class is not STD container, returns None") def _get_always_expose_using_scope( self ): @@ -84,18 +84,20 @@ def _set_always_expose_using_scope( self, value ): self._always_expose_using_scope = value always_expose_using_scope = property( _get_always_expose_using_scope, _set_always_expose_using_scope - , doc="please see L{always_expose_using_scope_documentation} for documentation." ) + , doc="please see L{class_wrapper.always_expose_using_scope_documentation} variable for documentation." ) def _get_equality_comparable( self ): 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" ) - equality_comparable = property( _get_equality_comparable, _set_equality_comparable ) - def _get_less_than_comparable( self ): if None is self._less_than_comparable: self._less_than_comparable = declarations.has_public_less( self ) @@ -104,9 +106,10 @@ def _set_less_than_comparable( self, value ): self._less_than_comparable = value - less_than_comparable = property( _get_less_than_comparable, _set_less_than_comparable ) + less_than_comparable = property( _get_less_than_comparable, _set_less_than_comparable + , doc="indicates existence of public operator<. " \ + +"Default value is calculated, based on information presented in the declarations tree" ) - #this will only be exported if indexing suite is not None and only when needed class class_declaration_t( class_common_details_t , decl_wrapper.decl_wrapper_t @@ -138,13 +141,16 @@ return self._redefine_operators def _set_redefine_operators( self, new_value ): self._redefine_operators = new_value - redefine_operators = property( _get_redefine_operators, _set_redefine_operators ) + redefine_operators = property( _get_redefine_operators, _set_redefine_operators + , doc="tells Py++ to redefine operators from base class in this class, False by default") def _get_held_type(self): return self._held_type def _set_held_type(self, held_type): self._held_type = held_type - held_type = property( _get_held_type, _set_held_type ) + held_type = property( _get_held_type, _set_held_type + , doc="string, this property tells Py++ what HeldType this class has" \ + +"Default value is calculated, based on information presented in exposed declarations" ) def _get_noncopyable(self): if self._noncopyable is None: @@ -152,24 +158,17 @@ return self._noncopyable def _set_noncopyable(self, noncopyable): self._noncopyable= noncopyable - noncopyable = property( _get_noncopyable, _set_noncopyable) + noncopyable = property( _get_noncopyable, _set_noncopyable + , doc="True if the class is noncopyable, False otherwies" \ + +"Default value is calculated, based on information presented in the declarations tree" ) def _get_wrapper_alias( self ): return self._wrapper_alias def _set_wrapper_alias( self, walias ): self._wrapper_alias = walias - wrapper_alias = property( _get_wrapper_alias, _set_wrapper_alias ) + wrapper_alias = property( _get_wrapper_alias, _set_wrapper_alias + , doc="class-wrapper name") - def has_wrapper( self ): - for decl in self.declarations: - if decl.has_wrapper(): - return True - return False - - def _finalize_impl( self, error_behavior ): - for decl in self.declarations: - decl.finalize( error_behavior ) - @property def declaration_code( self ): """ @@ -198,26 +197,32 @@ return self._null_constructor_body def _set_null_constructor_body(self, body): self._null_constructor_body = body - null_constructor_body = property( _get_null_constructor_body, _set_null_constructor_body ) + null_constructor_body = property( _get_null_constructor_body, _set_null_constructor_body + , doc="null constructor code, that will be added as is to the null constructor of class-wrapper") def _get_copy_constructor_body(self): return self._copy_constructor_body def _set_copy_constructor_body(self, body): self._copy_constructor_body = body - copy_constructor_body = property( _get_copy_constructor_body, _set_copy_constructor_body ) + copy_constructor_body = property( _get_copy_constructor_body, _set_copy_constructor_body + , doc="copy constructor code, that will be added as is to the copy constructor of class-wrapper") 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 ): - """works_on_instance: If true, the custom code can be applied directly to obj inst. - Ex: ObjInst."CustomCode" + """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" """ self.registration_code.append( user_text.class_user_text_t( code, works_on_instance ) ) #preserving backward computability add_code = add_registration_code def add_wrapper_code( self, code ): + """adds code to the class wrapper class definition""" self.wrapper_code.append( user_text.user_text_t( code ) ) def set_constructors_body( self, body ): Modified: pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py 2006-08-21 13:42:15 UTC (rev 429) +++ pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py 2006-08-21 18:35:11 UTC (rev 430) @@ -11,7 +11,7 @@ from pygccxml import declarations class decl_wrapper_printer_t( declarations.decl_printer_t ): - """ Helper class for printing decl tree. """ + """ Helper class for printing declarations tree and Py++ configuration instructions""" JUSTIFY = 20 INDENT_SIZE = 4 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-21 13:42:42
|
Revision: 429 Author: roman_yakovenko Date: 2006-08-21 06:42:15 -0700 (Mon, 21 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=429&view=rev Log Message: ----------- updating documentation strings Modified Paths: -------------- pyplusplus_dev/docs/documentation/best_practices.rest pyplusplus_dev/docs/documentation/how_to.rest pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py pyplusplus_dev/pyplusplus/decl_wrappers/enumeration_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite1.py pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite2.py pyplusplus_dev/pyplusplus/decl_wrappers/namespace_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/scopedef_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/typedef_wrapper.py pyplusplus_dev/pyplusplus/decl_wrappers/user_text.py pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py pyplusplus_dev/setup.py Modified: pyplusplus_dev/docs/documentation/best_practices.rest =================================================================== --- pyplusplus_dev/docs/documentation/best_practices.rest 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/docs/documentation/best_practices.rest 2006-08-21 13:42:15 UTC (rev 429) @@ -9,7 +9,7 @@ ------------ `Py++`_ has reach interface and a lot of functionality. Sometimes reach -interface helps, but sometimes it can confuse. This document will describe how +interface helps, but sometimes it can confuse. This document will describe how effectively to use `Py++`_. ------------ @@ -19,48 +19,47 @@ Definition ---------- -First of all, let me to define "big project". "Big project" is a project with +First of all, let me to define "big project". "Big project" is a project with few hundred of header files. `Py++`_ was born to create `Python`_ bindings -for such projects. If you take a look `here`__ you will find few such projects, -that use `Py++`_. +for such projects. If you take a look `here`__ you will find few such projects. .. __ : ./../../pygccxml/quotes.html Tips ---- -* Create one header file, which will include all project header files. +* Create one header file, which will include all project header files. - Doing it this way makes it so `GCC-XML`_ is only called once and it reduces the + Doing it this way makes it so `GCC-XML`_ is only called once and it reduces the overhead that would occur if you pass `GCC-XML`_ all the files individually. - Namely `GCC-XML`_ would have to run hundreds of times and each call would - actually end up including quite a bit of common code anyway. This way takes a - `GCC-XML`_ processing time from multiple hours with gigabytes of caches to a + Namely `GCC-XML`_ would have to run hundreds of times and each call would + actually end up including quite a bit of common code anyway. This way takes a + `GCC-XML`_ processing time from multiple hours with gigabytes of caches to a couple minutes with a reasonable cache size. - + You can read more about different caches supported by `pygccxml`_ `here`__. ``module_builder_t.__init__`` methods takes reference to an instance of cache class or ``None``: - + :: - from module_builder import * + from module_builder import * mb = module_builder_t( ..., cache=file_cache_t( path to project cache file ), ... ) - + * Single header file, will also improve performance compiling the generated bindings. - When `Py++`_ generated the bindings, you have a lot of .cpp files to + When `Py++`_ generated the bindings, you have a lot of .cpp files to compile. The project you are working on is big. I am sure it takes a lot of - time to compile projects that depend on it. Generated code also depend on it, - more over this code contains a lot of template instantiations. So it could - take a great deal of time to compile it. Allen Bierbaum investigated this - problem. He found out that most of the time is really spent processing all the - headers, templates, macros from the project and from the boost library. So he + time to compile projects that depend on it. Generated code also depend on it, + more over this code contains a lot of template instantiations. So it could + take a great deal of time to compile it. Allen Bierbaum investigated this + problem. He found out that most of the time is really spent processing all the + headers, templates, macros from the project and from the boost library. So he come to conclusion, that in order to improve compilation speed, user should - be able to control( to be able to generate ) precompiled header file. He + be able to control( to be able to generate ) precompiled header file. He implemented an initial version of the functionality. After small discussion, we agreed on next interface: - + :: class module_builder_t( ... ): @@ -68,17 +67,17 @@ def split_module( self, directory_path, huge_classes=None, precompiled_header=None ): ... ... - - ``precompiled_header`` argument could be ``None`` or string, that contains - name of precompiled header file, which will be created in the directory. - `Py++`_ will add to it header files from `Boost.Python`_ library and - your header files. - + + ``precompiled_header`` argument could be ``None`` or string, that contains + name of precompiled header file, which will be created in the directory. + `Py++`_ will add to it header files from `Boost.Python`_ library and + your header files. + What is ``huge_classes`` argument for? ``huge_classes`` could be ``None`` or - list of references to class declarations. It is there to provide a solution to - `this error`_. `Py++`_ will automatically split generated code for the + list of references to class declarations. It is there to provide a solution to + `this error`_. `Py++`_ will automatically split generated code for the huge classes to few files: - + :: mb = module_builder_t( ... ) @@ -89,9 +88,9 @@ .. _`this error` : http://boost.org/libs/python/doc/v2/faq.html#c1204 .. __ : ./../../pygccxml/design.html - - + + .. _`Py++` : ./../pyplusplus.html .. _`pygccxml` : ./../../pygccxml/pygccxml.html .. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html Modified: pyplusplus_dev/docs/documentation/how_to.rest =================================================================== --- pyplusplus_dev/docs/documentation/how_to.rest 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/docs/documentation/how_to.rest 2006-08-21 13:42:15 UTC (rev 429) @@ -20,7 +20,7 @@ :: translate_code = \ - """ + """ void translate(const my_exception &exception){ PyErr_SetString( PyExc_RuntimeError, exception.error().c_str() ); } @@ -48,7 +48,7 @@ mb = module_builder_t( ... ) exception_classes = mb.decls( lambda decl: decl.name.endswith( 'exception' ) ) -Now you can iterate on ``exception_classes``, generate and register translate +Now you can iterate on ``exception_classes``, generate and register translate code for every class. That's all. @@ -64,7 +64,7 @@ ... }; -You can not expose ``get_size`` function as is - ``int`` is immutable type in +You can not expose ``get_size`` function as is - ``int`` is immutable type in Python. So, we need to create a wrapper to the function: :: @@ -81,7 +81,7 @@ ... ; -Now, after you know how this problem is solved. I will show how this solution +Now, after you know how this problem is solved. I will show how this solution could be integrated with `Py++`_. @@ -108,26 +108,25 @@ window.add_wrapper_code( wrapper_code ) window.registration_code( registration_code ) -That's all. +That's all. ------------------------------------------------------------- Fatal error C1204:Compiler limit: internal structure overflow ------------------------------------------------------------- -If you get this error, that the generated file is too big. You will have to split -it to few files. Well, not you but `Py++`_ you will only have to tell that -to it. +If you get this error, than the generated file is too big. You will have to split +it to few files. Well, not you but `Py++`_, you will only have to tell it to do +that. If you are using ``module_builder_t.write_module`` method, consider to switch -to ``module_builder_t.split_module``. +to ``module_builder_t.split_module``. -If you are using ``split_method``, but still generated code for some specific -class could not be compiled because of error, you can ask `Py++`_ to split -class registration code to few cpp files. +If you are using ``split_module``, but still the generated code for some class +could not be compiled, because of the error, you can ask `Py++`_ to split the +code generated for class to be splitted to few cpp files. For more information, please read the documentation. - ------------------------------------------------------ How to automatically export template functions\\class? ------------------------------------------------------ @@ -150,7 +149,7 @@ :: - template <class T> + template <class T> double distance( const point_t<T>& point ){ return sqrt( point.x * point.x + point.y*point.y ); } @@ -167,7 +166,7 @@ * free function invocation causes a compiler to instantiate the function -Lets say that we need to export the class and the function template +Lets say that we need to export the class and the function template instantiations for ``int`` and ``custom_type`` types. There are few ways to do it. Simple and straightforward @@ -191,8 +190,8 @@ } } -Now, you add this file to the list of files you pass as input to -``module_builder_t.__init__`` method and excludes the ``py_details`` namespace +Now, you add this file to the list of files you pass as input to +``module_builder_t.__init__`` method and excludes the ``py_details`` namespace declarations from being exported: :: @@ -203,10 +202,10 @@ "Dynamic" instantiation ----------------------- -Lets say you are less lucky than I, and you have to create ``X`` instantiations +Lets say you are less lucky than I, and you have to create ``X`` instantiations of the class\\function. Obviously, the previous approach will not work for you. -The solution is to build your own code generator, which will generate code similar -to the one, in the previous paragraph. +The solution is to build your own code generator, which will generate code similar +to the one, in the previous paragraph. :: @@ -237,7 +236,7 @@ I understand that the provided solution is not perfect. I understand that something -better and simpler should be done, but a priority of this is low. There are few +better and simpler should be done, but a priority of this is low. There are few tasks, that have much higher priority. Allen Bierbaum wants to fix the situation. He created a `wiki page`_, that discuss possible solutions. Your contribution is welcome too! Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-08-21 13:42:15 UTC (rev 429) @@ -3,14 +3,16 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +"""defines class that configure "callable" declaration exposing""" + import os import decl_wrapper from pygccxml import declarations class calldef_t(decl_wrapper.decl_wrapper_t): - + """keeps configur global and member variable exposing""" BOOST_PYTHON_MAX_ARITY = 10 - + def __init__(self, *arguments, **keywords): decl_wrapper.decl_wrapper_t.__init__( self, *arguments, **keywords ) @@ -92,10 +94,10 @@ overridable = property( get_overridable, set_overridable , doc = get_overridable.__doc__ ) - + def _exportable_impl_derived( self ): return '' - + def _exportable_impl( self ): all_types = [ arg.type for arg in self.arguments ] all_types.append( self.return_type ) @@ -117,7 +119,7 @@ no_ptr = declarations.remove_pointer( no_ref ) no_const = declarations.remove_const( no_ptr ) if declarations.is_array( no_const ): - return "Py++ can not expose function that takes as argument/returns C++ arrays. This will be changed in near future." + return "Py++ can not expose function that takes as argument/returns C++ arrays. This will be changed in near future." return self._exportable_impl_derived() def _readme_impl( self ): @@ -136,7 +138,7 @@ tmp.append( "For more information see: http://mail.python.org/pipermail/c++-sig/2002-June/001554.html" ) tmp = ' '.join( tmp ) msgs.append( tmp % ( calldef_t.BOOST_PYTHON_MAX_ARITY, len( self.arguments ) ) ) - + if suspicious_type( self.return_type ) and None is self.call_policies: msgs.append( 'The function "%s" returns non-const reference to C++ fundamental type - value can not be modified from Python.' % str( self ) ) for index, arg in enumerate( self.arguments ): @@ -193,7 +195,7 @@ #dereference does not make sense return False return oper.symbol in operators_helper.all - + @staticmethod def exportable( oper ): if isinstance( oper, declarations.member_operator_t ) and oper.symbol in ( '()', '[]' ): @@ -203,7 +205,7 @@ msg.append( 'See Boost.Python documentation: http://www.boost.org/libs/python/doc/v2/operators.html#introduction.' ) return ' '.join( msg ) return '' - + class member_operator_t( declarations.member_operator_t, calldef_t ): def __init__(self, *arguments, **keywords): declarations.member_operator_t.__init__( self, *arguments, **keywords ) @@ -300,4 +302,4 @@ calldef_t.__init__( self ) def _exportable_impl_derived( self ): - return operators_helper.exportable( self ) \ No newline at end of file + return operators_helper.exportable( self ) Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-08-21 13:42:15 UTC (rev 429) @@ -3,6 +3,9 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +"""defines class that configure class definition and class declaration exposing""" + +import os import user_text import decl_wrapper import scopedef_wrapper @@ -10,7 +13,36 @@ import indexing_suite1 as isuite1 import indexing_suite2 as isuite2 -class class_common_impl_details_t( object ): + +always_expose_using_scope_documentation = \ +"""boolean, configures how Py++ should generate code for class. +Py can generate code using IDL like syntax: + + C{class_< ... >( ... )} + C{.def( ... );} + +Or it can generate code using more complex form: + + C{typedef bp::class_< my_class > my_class_exposer_t;} + C{my_class_exposer_t my_class_exposer = my_class_exposer_t( "my_class" );} + C{boost::python::scope my_class_scope( my_class_exposer );} + C{my_class_exposer.def( ... );} + +Also, the second way is much longer, it solves few problems: + + - you can not expose enums and internal classes defined within the class using first method + - you will get much better compilation errors + - the code looks like regular C++ code after all :-) + +By default, this property is set to False. Also, Py++ knows pretty well +when it have to ignore this property and generate right code +""" + +class class_common_details_t( object ): + """defines few properties that are common to + L{class declaration<pygccxml.declarations.class_declaration_t>} and + L{definition<pygccxml.declarations.class_t>} classes + """ def __init__(self): object.__init__( self ) self._always_expose_using_scope = False @@ -26,18 +58,9 @@ if self._isuite_version != version: self._isuite_version = version self._indexing_suite = None - indexing_suite_version = property( _get_indexing_suite_version, _set_indexing_suite_version ) + indexing_suite_version = property( _get_indexing_suite_version, _set_indexing_suite_version + , doc="indexing suite version") - def _get_always_expose_using_scope( self ): - #I am almost sure this logic should be moved to code_creators - if isinstance( self.indexing_suite, isuite2.indexing_suite2_t ) \ - and ( self.indexing_suite.disable_methods or self.indexing_suite.disabled_methods_groups ): - return True - return self._always_expose_using_scope - def _set_always_expose_using_scope( self, value ): - self._always_expose_using_scope = value - always_expose_using_scope = property( _get_always_expose_using_scope, _set_always_expose_using_scope ) - def _get_indexing_suite( self ): if self._indexing_suite is None: for container_traits in declarations.all_container_traits: @@ -48,8 +71,21 @@ self._indexing_suite = isuite2.indexing_suite2_t( self, container_traits ) break return self._indexing_suite - indexing_suite = property( _get_indexing_suite ) + indexing_suite = property( _get_indexing_suite + , doc="returns reference to indexing suite configuration class. " \ + +"If the class is not STD container, returns None") + def _get_always_expose_using_scope( self ): + #I am almost sure this logic should be moved to code_creators + if isinstance( self.indexing_suite, isuite2.indexing_suite2_t ) \ + and ( self.indexing_suite.disable_methods or self.indexing_suite.disabled_methods_groups ): + return True + return self._always_expose_using_scope + def _set_always_expose_using_scope( self, value ): + self._always_expose_using_scope = value + always_expose_using_scope = property( _get_always_expose_using_scope, _set_always_expose_using_scope + , doc="please see L{always_expose_using_scope_documentation} for documentation." ) + def _get_equality_comparable( self ): if None is self._equality_comparable: self._equality_comparable = declarations.has_public_equal( self ) @@ -72,19 +108,19 @@ #this will only be exported if indexing suite is not None and only when needed -class class_declaration_t( class_common_impl_details_t +class class_declaration_t( class_common_details_t , decl_wrapper.decl_wrapper_t , declarations.class_declaration_t ): def __init__(self, *arguments, **keywords): - class_common_impl_details_t.__init__( self ) + class_common_details_t.__init__( self ) declarations.class_declaration_t.__init__(self, *arguments, **keywords ) decl_wrapper.decl_wrapper_t.__init__( self ) -class class_t( class_common_impl_details_t +class class_t( class_common_details_t , scopedef_wrapper.scopedef_t , declarations.class_t): def __init__(self, *arguments, **keywords): - class_common_impl_details_t.__init__( self ) + class_common_details_t.__init__( self ) declarations.class_t.__init__(self, *arguments, **keywords ) scopedef_wrapper.scopedef_t.__init__( self ) @@ -198,4 +234,4 @@ return '' if not self in self.parent.public_members: return 'Py++ can not expose private class.' - return '' \ No newline at end of file + return '' Modified: pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper.py 2006-08-21 13:42:15 UTC (rev 429) @@ -3,16 +3,13 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +"""defines base class for all classes, that will keep Py++ code generator engine +instructions.""" + import algorithm from pyplusplus import _logging_ from pygccxml import declarations - - -class ERROR_BEHAVIOR: - PRINT = 'print' - RAISE = 'raise' - class decl_wrapper_t(object): """Declaration interface. @@ -22,7 +19,7 @@ this class are never created by the user, instead they are returned by the API. """ - + def __init__(self): object.__init__(self) self._alias = None @@ -30,28 +27,28 @@ self._exportable = None self._exportable_reason = None self._documentation = None - + @property def logger( self ): + """returns reference to L{_logging_.loggers.declarations}""" return _logging_.loggers.declarations def _get_documentation( self ): return self._documentation - def _set_documentation( self, value ): self._documentation = value documentation = property( _get_documentation, _set_documentation - , doc="Using this property you can set documentatio of exported declaration." ) - + , doc="Using this property you can set documentatio of exported declaration." ) + def _generate_valid_name(self, name=None): if name == None: name = self.name return algorithm.create_valid_name( name ) - + def _get_alias(self): if not self._alias: if declarations.templates.is_instantiation( self.name ): - container_aliases = [ 'value_type', 'key_type' ] + container_aliases = [ 'value_type', 'key_type', 'mapped_type' ] if isinstance( self, declarations.class_t ) \ and 1 == len( set( map( lambda typedef: typedef.name, self.aliases ) ) ) \ and self.aliases[0].name not in container_aliases: @@ -61,32 +58,32 @@ else: self._alias = self.name return self._alias - def _set_alias(self, alias): self._alias = alias alias = property( _get_alias, _set_alias , doc="Using this property you can easily change Python name of declaration" ) - + def rename( self, new_name ): + """renames the declaration name, under which it is exposed""" self.alias = new_name - + def _get_ignore( self ): - return self._ignore - + return self._ignore def _set_ignore( self, value ): self._ignore = value ignore = property( _get_ignore, _set_ignore - ,doc="If you set ignore to True then this declaration will not be exported." ) - + ,doc="If you set ignore to True then this declaration will not be exported." ) + def exclude( self ): """Exclude "self" and child declarations from being exposed.""" self.ignore = True - + def include( self ): """Include "self" and child declarations to be exposed.""" self.ignore = False def why_not_exportable( self ): + """returns strings that explains why this declaration could not be exported or None otherwise""" if None is self._exportable_reason: self.get_exportable() return self._exportable_reason @@ -104,16 +101,15 @@ self._exportable_reason = self._exportable_impl( ) self._exportable = not bool( self._exportable_reason ) return self._exportable - def set_exportable( self, exportable ): self._exportable = exportable - + exportable = property( get_exportable, set_exportable , doc="Returns True if declaration could be exported to Python, otherwise False" ) - + def _readme_impl( self ): return [] - + def readme( self ): """This function will returns some hints/tips/description of problems that applied to the declarations. For example function that has argument @@ -123,5 +119,5 @@ text = [] if not self.exportable: text.append( self.why_not_exportable() ) - text.extend( self._readme_impl() ) - return text \ No newline at end of file + text.extend( self._readme_impl() ) + return text Modified: pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/decl_wrapper_printer.py 2006-08-21 13:42:15 UTC (rev 429) @@ -3,6 +3,9 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +"""defines class that will print in a user friendly format declarations tree and +declarations Py++ configuration instructions""" + import os import sys from pygccxml import declarations @@ -11,7 +14,7 @@ """ Helper class for printing decl tree. """ JUSTIFY = 20 INDENT_SIZE = 4 - + def __init__( self, level=0, print_details=True, recursive=True, writer=None ): declarations.decl_printer_t.__init__(self, level, print_details, recursive, writer) @@ -20,42 +23,42 @@ if increment_level: level += 1 return decl_wrapper_printer_t(level, self.print_details, self.recursive, self.writer) - - def print_decl_header(self): + + def print_decl_header(self): super( decl_wrapper_printer_t, self ).print_decl_header() if not self.print_details: - return - intend_txt = ' ' * (self.level+1) * self.INDENT_SIZE + return + intend_txt = ' ' * (self.level+1) * self.INDENT_SIZE self.writer( intend_txt + "Alias: " + self.instance.alias + os.linesep ) self.writer( intend_txt + "Ignore: " + str( self.instance.ignore ) + os.linesep ) if not self.instance.ignore: msgs = self.instance.readme() if msgs: self.writer( intend_txt + "ReadMe: " + os.linesep ) - more_intend_txt = ' ' * (self.level+2) * self.INDENT_SIZE + more_intend_txt = ' ' * (self.level+2) * self.INDENT_SIZE for msg in msgs: self.writer( more_intend_txt + msg + os.linesep ) - + def print_calldef_wrapper(self): if not self.print_details: - return - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + return + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Call policies: " + str(self.instance.call_policies) + os.linesep ) - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Use keywords: " + str(self.instance.use_keywords) + os.linesep ) - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Use signature: " + str(self.instance.create_with_signature) + os.linesep ) - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Use default arguments: " + str(self.instance.use_default_arguments) + os.linesep ) - + def visit_member_function( self ): super( decl_wrapper_printer_t, self ).visit_member_function() self.print_calldef_wrapper() - + def visit_constructor( self ): super( decl_wrapper_printer_t, self ).visit_constructor() self.print_calldef_wrapper() - + def visit_destructor( self ): super( decl_wrapper_printer_t, self ).visit_destructor() self.print_calldef_wrapper() @@ -80,23 +83,23 @@ super( decl_wrapper_printer_t, self ).visit_class_declaration() def visit_class(self ): - super( decl_wrapper_printer_t, self ).visit_class() - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + super( decl_wrapper_printer_t, self ).visit_class() + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Expose using scope: " + str(self.instance.always_expose_using_scope) + os.linesep ) - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Redefine operators: " + str(self.instance.redefine_operators) + os.linesep ) - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Held type: " + str(self.instance.held_type) + os.linesep ) - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Use noncopyable: " + str(self.instance.noncopyable) + os.linesep ) - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Class wrapper alias: " + str(self.instance.wrapper_alias) + os.linesep ) def visit_enumeration(self): super( decl_wrapper_printer_t, self ).visit_enumeration() - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Enumeration value aliases: " + str(self.instance.value_aliases) + os.linesep ) - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Enumeration export values: " + str(self.instance.export_values) + os.linesep ) def visit_namespace(self ): @@ -104,7 +107,7 @@ def visit_typedef(self ): super( decl_wrapper_printer_t, self ).visit_typedef() - + def visit_variable(self ): super( decl_wrapper_printer_t, self ).visit_variable() Modified: pyplusplus_dev/pyplusplus/decl_wrappers/enumeration_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/enumeration_wrapper.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/enumeration_wrapper.py 2006-08-21 13:42:15 UTC (rev 429) @@ -3,10 +3,16 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -from pygccxml import declarations +"""defines class that configure enumeration declaration exposing""" + +from pygccxml import declarations import decl_wrapper class enumeration_t(decl_wrapper.decl_wrapper_t, declarations.enumeration_t): + """defines a set of properties, that will instruct Py++ how to expose the enumeration + + By default, Py++ will export all enumeration values. + """ def __init__(self, *arguments, **keywords): declarations.enumeration_t.__init__(self, *arguments, **keywords ) decl_wrapper.decl_wrapper_t.__init__( self ) @@ -48,7 +54,7 @@ if name not in export_values: res.append(name) return res - + def _set_no_export_values(self, no_export_values): all_values = map(lambda x: x[0], self.values) export_values = [] @@ -56,11 +62,11 @@ if name not in no_export_values: export_values.append(name) self.export_values = export_values - + no_export_values = property( _get_no_export_values, _set_export_values, doc= """A list of (C++) enumeration names that should not be exported. @type: list""") - + def _readme_impl( self ): msgs = [] if self.name: @@ -68,5 +74,5 @@ if len( set( name2value.keys() ) ) != len( set( name2value.values() ) ): msgs.append( "Boost.Python does not support enums with duplicate values. " "You can read more about this here: http://boost.org/libs/python/todo.html#support-for-enums-with-duplicate-values . " - "The quick work around is to add new class variable to the exported enum, from Python. " ) + "The quick work around is to add new class variable to the exported enum, from Python. " ) return msgs Modified: pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite1.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite1.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite1.py 2006-08-21 13:42:15 UTC (rev 429) @@ -3,10 +3,12 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +"""defines interface for exposing STD containers, using current version of indexing suite""" + from pygccxml import declarations #NoProxy -#By default indexed elements have Python reference semantics and are returned by +#By default indexed elements have Python reference semantics and are returned by #proxy. This can be disabled by supplying true in the NoProxy template parameter. #When we want to disable is: #1. We deal with immutable objects: @@ -21,24 +23,24 @@ This class helps user to export STD containers, using Boost.Python indexing suite V2. """ - + def __init__( self, container_class, container_traits, no_proxy=None, derived_policies=None ): object.__init__( self ) self.__no_proxy = no_proxy self.__derived_policies = derived_policies self.__container_class = container_class self.__container_traits = container_traits - + def _get_container_class( self ): return self.__container_class container_class = property( _get_container_class , doc="Reference to STD container class" ) - + def _get_element_type(self): return self.__container_traits.element_type( self.container_class ) - element_type = property( _get_element_type - , doc="Reference to container value_type( mapped_type ) type" ) - + element_type = property( _get_element_type + , doc="Reference to container value_type( mapped_type ) type" ) + def _get_no_proxy( self ): if self.__no_proxy is None: element_type = self.element_type @@ -51,16 +53,15 @@ else: self.__no_proxy = False return self.__no_proxy - + def _set_no_proxy( self, no_proxy ): self.__no_proxy = no_proxy - no_proxy = property( _get_no_proxy, _set_no_proxy , doc="NoProxy value, the initial value depends on container" +" element_type( mapped_type ) type. In most cases, " +"Py++ is able to guess this value, right. If you are not " +"lucky, you will have to set the property value.") - + def _get_derived_policies( self ): return self.__derived_policies def _set_derived_policies( self, derived_policies ): @@ -68,4 +69,3 @@ derived_policies = property( _get_derived_policies, _set_derived_policies , doc="This proprty contains DerivedPolicies string. " +"It will be added as is to the generated code.") - \ No newline at end of file Modified: pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite2.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite2.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/indexing_suite2.py 2006-08-21 13:42:15 UTC (rev 429) @@ -2,25 +2,28 @@ # 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) + +"""defines interface for exposing STD containers, using next version of indexing suite""" + from pygccxml import declarations """ -method_len -method_iter -method_getitem -method_getitem_slice -method_index -method_contains -method_count -method_has_key -method_setitem -method_setitem_slice -method_delitem -method_delitem_slice -method_reverse -method_append -method_insert -method_extend +method_len +method_iter +method_getitem +method_getitem_slice +method_index +method_contains +method_count +method_has_key +method_setitem +method_setitem_slice +method_delitem +method_delitem_slice +method_reverse +method_append +method_insert +method_extend method_sort slice_methods = method_getitem_slice | method_setitem_slice | method_delitem_slice @@ -35,14 +38,14 @@ This class helps user to export STD containers, using Boost.Python indexing suite V2. """ - + #List of method names. These method could be excluded from being exposed. METHODS = ( 'len', 'iter', 'getitem', 'getitem_slice', 'index', 'contains' , 'count', 'has_key', 'setitem', 'setitem_slice', 'delitem' , 'delitem_slice', 'reverse', 'append', 'insert', 'extend', 'sort' ) - + #Dictionary of method group names. These method groups could be excluded from - #being exposed. Dictionary key is a method group name. Dictionary value is a + #being exposed. Dictionary key is a method group name. Dictionary value is a #list of all methods, which belong to the group. METHOD_GROUPS = { 'slice' : ( 'method_getitem_slice', 'method_setitem_slice', 'method_delitem_slice' ) @@ -50,7 +53,7 @@ , 'reorder' : ( 'method_sort', 'method_reverse' ) , 'insert' : ( 'method_append', 'method_insert', 'method_extend' ) } - + def __init__( self, container_class, container_traits ): object.__init__( self ) self.__call_policies = None @@ -67,15 +70,15 @@ def _get_container_traits( self ): return self._get_container_traits() - container_traits = property( _get_container_traits + container_traits = property( _get_container_traits , doc="Reference to container traits. See " "pygccxml documentation for STD container traits.") - + def _get_element_type(self): return self.__container_traits.element_type( self.container_class ) element_type = property( _get_element_type - , doc="Reference to container value_type( mapped_type ) type" ) - + , doc="Reference to container value_type( mapped_type ) type" ) + def _get_call_policies( self ): #TODO find out call policies return self.__call_policies @@ -86,26 +89,26 @@ def __apply_defaults_if_needed( self ): if self._default_applied: - return + return self._default_applied = True #find out what operators are supported by element_type and #then configure the _disable_[methods|groups] pass - + def disable_method( self, method_name ): """Disable method from being exposed""" assert method_name in self.METHODS self.__apply_defaults_if_needed() self._disabled_methods.add( method_name ) - + def enable_method( self, method_name ): """Enable method to be exposed""" assert method_name in self.METHODS self.__apply_defaults_if_needed() if method_name in self._disabled_methods: self._disabled_methods.remove( method_name ) - - def _get_disabled_methods( self ): + + def _get_disabled_methods( self ): self.__apply_defaults_if_needed() return self._disabled_methods disable_methods = property( _get_disabled_methods @@ -116,16 +119,16 @@ assert group_name in self.METHOD_GROUPS self.__apply_defaults_if_needed() self._disabled_groups.add( group_name ) - + def enable_methods_group( self, group_name ): """Enable methods group to be exposed""" assert group_name in self.METHOD_GROUPS self.__apply_defaults_if_needed() if group_name in self._disabled_groups: self._disabled_groups.remove( group_name ) - - def _get_disabled_methods_groups( self ): + + def _get_disabled_methods_groups( self ): self.__apply_defaults_if_needed() return self._disabled_groups disabled_methods_groups = property( _get_disabled_methods_groups - , doc="list of all disabled methods group") \ No newline at end of file + , doc="list of all disabled methods group") Modified: pyplusplus_dev/pyplusplus/decl_wrappers/namespace_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/namespace_wrapper.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/namespace_wrapper.py 2006-08-21 13:42:15 UTC (rev 429) @@ -3,11 +3,18 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +"""defines class that configure namespace exposing.""" + import scopedef_wrapper from pygccxml import declarations class namespace_t(scopedef_wrapper.scopedef_t, declarations.namespace_t): + """defines a set of properties, that will instruct Py++ how to expose the namespace + + Today, Py++ does not exposes namespaces, but this could be changed in future. + The future direction I see here, is to expose every namespace as sub-module + of the main one. + """ def __init__(self, *arguments, **keywords): scopedef_wrapper.scopedef_t.__init__( self ) declarations.namespace_t.__init__(self, *arguments, **keywords ) - \ No newline at end of file Modified: pyplusplus_dev/pyplusplus/decl_wrappers/scopedef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/scopedef_wrapper.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/scopedef_wrapper.py 2006-08-21 13:42:15 UTC (rev 429) @@ -3,15 +3,17 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +"""defines base class for L{decl_wrappers.class_t} and L{decl_wrappers.namespace_t} classes""" + import decl_wrapper -class scopedef_t(decl_wrapper.decl_wrapper_t): +class scopedef_t(decl_wrapper.decl_wrapper_t): + """base class for L{decl_wrappers.class_t} and L{decl_wrappers.namespace_t} classes + + It provides convinience functionality: include\\exclude all internal declarations + (not) to be exported. """ - In C++ there are 2 declarations that can contain definition of other - declarations: class and namespace. This class is used as a base class for both - of them. - """ - + def __init__(self): decl_wrapper.decl_wrapper_t.__init__( self ) @@ -19,7 +21,7 @@ """Exclude "self" and child declarations from being exposed.""" self.ignore = True map( lambda decl: decl.exclude(), self.declarations ) - + def include( self ): """Include "self" and child declarations to be exposed.""" self.ignore = False Modified: pyplusplus_dev/pyplusplus/decl_wrappers/typedef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/typedef_wrapper.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/typedef_wrapper.py 2006-08-21 13:42:15 UTC (rev 429) @@ -3,10 +3,19 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -from pygccxml import declarations +"""defines class that configure typedef exposing""" + +from pygccxml import declarations import decl_wrapper class typedef_t(decl_wrapper.decl_wrapper_t, declarations.typedef_t): + """defines a set of properties, that will instruct Py++ how to expose the typedef + + Today, Py++ does not exposes typedefs, but this could be changed in future. + In C++, it is a common practises to give an aliases to the class. May be in + future, Py++ will generate code, that will register all those aliases. + """ + def __init__(self, *arguments, **keywords): declarations.typedef_t.__init__(self, *arguments, **keywords ) - decl_wrapper.decl_wrapper_t.__init__( self ) \ No newline at end of file + decl_wrapper.decl_wrapper_t.__init__( self ) Modified: pyplusplus_dev/pyplusplus/decl_wrappers/user_text.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/user_text.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/user_text.py 2006-08-21 13:42:15 UTC (rev 429) @@ -3,15 +3,19 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +"defines few classes, used by L{decl_wrapper.class_t} class to keep user code" + class user_text_t(object): + "keeps reference to user code that belongs to declaration section" def __init__( self, text ): object.__init__( self ) self.text = text class class_user_text_t( user_text_t ): + "keeps reference to user code that belongs to registration section" def __init__( self, text, works_on_instance=True ): """works_on_instance: If true, the custom code can be applied directly to obj inst. Ex: ObjInst."CustomCode" """ user_text_t.__init__( self, text ) - self.works_on_instance = works_on_instance \ No newline at end of file + self.works_on_instance = works_on_instance Modified: pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-08-21 13:42:15 UTC (rev 429) @@ -3,29 +3,29 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -from pygccxml import declarations +"""defines class that configure global and member variable exposing""" + +from pygccxml import declarations import decl_wrapper class variable_t(decl_wrapper.decl_wrapper_t, declarations.variable_t): - - """This class helps user to expose member and global variables.""" - + """defines a set of properties, that will instruct Py++ how to expose the variable""" def __init__(self, *arguments, **keywords): declarations.variable_t.__init__(self, *arguments, **keywords ) decl_wrapper.decl_wrapper_t.__init__( self ) self._getter_call_policies = None self._setter_call_policies = None - + __call_policies_doc__ = \ - """There are usecase, when exporting member variable forces Py++ to + """There are usecase, when exporting member variable forces Py++ to create accessors functions. Sometime, those functions requires call policies. To be more specific: when you export member variable that has reference or - pointer type, you need to tell boost.python library how to manage object - life-time. In all cases, Py++ will give reasonable default value. I am - sure, that there are use cases, when you need to change it. You should use this - property to change it. + pointer type, you need to tell Boost.Python library how to manage object + life-time. In all cases, Py++ will give reasonable default value. I am + sure, that there are use cases, when you will have to change it. You should + use this property to change it. """ - + def get_getter_call_policies( self ): return self._getter_call_policies def set_getter_call_policies( self, call_policies ): @@ -52,7 +52,7 @@ return "Py++ can not expose static pointer member variables. This could be changed in future." if declarations.is_fundamental( type_.base ): return "Py++ can not expose pointer to fundamental member variables. This could be changed in future." - + units = declarations.decompose_type( type_ ) ptr2functions = filter( lambda unit: isinstance( unit, declarations.calldef_type_t ) , units ) @@ -65,4 +65,3 @@ if not cls.name: return "Py++ can not expose variables of with unnamed type." return '' - \ No newline at end of file Modified: pyplusplus_dev/setup.py =================================================================== --- pyplusplus_dev/setup.py 2006-08-21 08:29:47 UTC (rev 428) +++ pyplusplus_dev/setup.py 2006-08-21 13:42:15 UTC (rev 429) @@ -50,7 +50,7 @@ print "Generating epydoc files..." - docindex = build_doc_index(['Py++', 'pygccxml']) + docindex = build_doc_index(['pyplusplus', 'pygccxml']) html_writer = HTMLWriter( docindex , prj_name='Py++' , prj_url='http://www.language-binding.net' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-21 08:30:00
|
Revision: 428 Author: roman_yakovenko Date: 2006-08-21 01:29:47 -0700 (Mon, 21 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=428&view=rev Log Message: ----------- fix for small spell error Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/cpptypes.py Modified: pygccxml_dev/pygccxml/declarations/cpptypes.py =================================================================== --- pygccxml_dev/pygccxml/declarations/cpptypes.py 2006-08-21 08:04:14 UTC (rev 427) +++ pygccxml_dev/pygccxml/declarations/cpptypes.py 2006-08-21 08:29:47 UTC (rev 428) @@ -302,7 +302,7 @@ , '__java_boolean' : jboolean_t() } """ -defines a mapping between funcdamental type name and its synonym to the instance +defines a mapping between fundamental type name and its synonym to the instance of class that describes the type """ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-21 08:04:37
|
Revision: 427 Author: roman_yakovenko Date: 2006-08-21 01:04:14 -0700 (Mon, 21 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=427&view=rev Log Message: ----------- updating documentation strings Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/calldef.py pygccxml_dev/pygccxml/declarations/class_declaration.py pygccxml_dev/pygccxml/declarations/cpptypes.py pygccxml_dev/pygccxml/declarations/decl_factory.py pygccxml_dev/pygccxml/declarations/declaration.py pygccxml_dev/pygccxml/declarations/enumeration.py pygccxml_dev/pygccxml/declarations/filtering.py pygccxml_dev/pygccxml/declarations/mdecl_wrapper.py pygccxml_dev/pygccxml/declarations/namespace.py pygccxml_dev/pygccxml/declarations/pattern_parser.py pygccxml_dev/pygccxml/declarations/scopedef.py pygccxml_dev/pygccxml/declarations/type_traits.py pygccxml_dev/pygccxml/declarations/typedef.py pygccxml_dev/pygccxml/declarations/variable.py pygccxml_dev/pygccxml/utils/__init__.py Modified: pygccxml_dev/pygccxml/declarations/calldef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/calldef.py 2006-08-20 19:53:54 UTC (rev 426) +++ pygccxml_dev/pygccxml/declarations/calldef.py 2006-08-21 08:04:14 UTC (rev 427) @@ -8,18 +8,18 @@ This modules contains definition for next C++ declarations: - operator - - member + - member - free - - function + - function - member - free - constructor - destructor """ -import cpptypes +import cpptypes import algorithm -import declaration +import declaration import type_traits import call_invocation @@ -29,7 +29,7 @@ VIRTUAL = 'virtual' PURE_VIRTUAL = 'pure virtual' ALL = [NOT_VIRTUAL, VIRTUAL, PURE_VIRTUAL] -#preserving backward compatebility +#preserving backward compatebility FUNCTION_VIRTUALITY_TYPES = VIRTUALITY_TYPES #First level in hierarchy of calldef @@ -37,13 +37,13 @@ """ class, that describes argument of "callable" declaration """ - + def __init__( self, name='', type=None, default_value=None ): object.__init__(self) self._name = name self._default_value = default_value self._type = type - + def __str__(self): if self.default_value==None: return "%s %s"%(self.type, self.name) @@ -104,20 +104,20 @@ self._return_type = return_type self._has_extern = has_extern self._demangled_name = None - + def _get__cmp__call_items(self): - """@undocumented _get__cmp__call_items:""" + """implementation details""" raise NotImplementedError() def _get__cmp__items( self ): - """@undocumented _get__cmp__items:""" + """implementation details""" items = [ self._sorted_list( self.arguments ) , self.return_type , self.has_extern , self._sorted_list( self.exceptions ) ] items.extend( self._get__cmp__call_items() ) return items - + def __eq__(self, other): if not declaration.declaration_t.__eq__( self, other ): return False @@ -125,7 +125,7 @@ and self.arguments == other.arguments \ and self.has_extern == other.has_extern \ and self._sorted_list( self.exceptions ) \ - == other._sorted_list( other.exceptions ) + == other._sorted_list( other.exceptions ) def _get_arguments(self): return self._arguments @@ -160,7 +160,7 @@ = algorithm.find_all_declarations( self.parent.declarations , type=calldef_t , name=self.name - , recursive=False ) + , recursive=False ) if not overloaded_funcs: return overloaded_funcs overloaded_funcs_ids = map( id, overloaded_funcs ) @@ -178,30 +178,30 @@ doc="""Was this callable declared as "extern"? @type: bool """) - + def __remove_parent_fname( self, demangled ): - """@undocumented __remove_parent_fname:""" + """implementation details""" demangled = demangled.strip() parent_fname = algorithm.full_name( self.parent ) if parent_fname.startswith( '::' ) and not demangled.startswith( '::' ): parent_fname = parent_fname[2:] demangled = demangled[ len( parent_fname ): ] return demangled - + def _get_demangled_name( self ): if not self.demangled: self._demangled_name = '' - + if self._demangled_name: return self._demangled_name - + if self._demangled_name == '': return self.name - + demangled = self.demangled if self.return_type: return_type = type_traits.remove_alias( self.return_type ).decl_string - + if return_type.startswith( '::' ) and not self.demangled.startswith( '::' ): return_type = return_type[2:] demangled = self.demangled @@ -216,7 +216,7 @@ if demangled_name.startswith( self.name ): self._demangled_name = demangled_name return self._demangled_name - + #well, I am going to try an other strategy fname = algorithm.full_name( self ) found = self.demangled.find( fname ) @@ -238,9 +238,10 @@ #if -1 == found: self._demangled_name = '' return self.name - - demangled_name = property( _get_demangled_name ) - + + demangled_name = property( _get_demangled_name + , doc="returns function demangled name. It can help you to deal with function template instantiations") + #Second level in hierarchy of calldef class member_calldef_t( calldef_t ): """base class for "callable" declarations that defined within C++ class or struct""" @@ -274,9 +275,9 @@ return "%s [%s]"%(res, cls) def _get__cmp__call_items(self): - """@undocumented _get__cmp__call_items:""" + """implementation details""" return [ self.virtuality, self.has_static, self.has_const ] - + def __eq__(self, other): if not calldef_t.__eq__( self, other ): return False @@ -289,7 +290,7 @@ def _set_virtuality(self, virtuality): assert virtuality in VIRTUALITY_TYPES.ALL self._virtuality = virtuality - virtuality = property( _get_virtuality, _set_virtuality + virtuality = property( _get_virtuality, _set_virtuality , doc="""Describes the "virtuality" of the member (as defined by the string constants in the class L{VIRTUALITY_TYPES}). @type: str""") @@ -326,8 +327,8 @@ def _create_decl_string(self): return self.function_type().decl_string - + class free_calldef_t( calldef_t ): """base class for "callable" declarations that defined within C++ namespace""" def __init__( self, *args, **keywords ): @@ -354,7 +355,7 @@ return "%s [%s]"%(res, cls) def _get__cmp__call_items(self): - """@undocumented _get__cmp__call_items:""" + """implementation details""" return [] def function_type(self): @@ -370,12 +371,12 @@ OPERATOR_WORD_LEN = len( 'operator' ) def __init__(self): object.__init__(self) - + def _get_symbol(self): return self.name[operator_t.OPERATOR_WORD_LEN:].strip() symbol = property( _get_symbol, doc="returns symbol of operator. For example: operator+, symbol is equal to '+'") - + #Third level in hierarchy of calldef class member_function_t( member_calldef_t ): """describes member function declaration""" @@ -387,8 +388,8 @@ """describes constructor declaration""" def __init__( self, *args, **keywords ): member_calldef_t.__init__( self, *args, **keywords ) - - def _get_is_copy_constructor(self): + + def _get_is_copy_constructor(self): args = self.arguments if 1 != len( args ): return False @@ -431,4 +432,4 @@ """describes free operator declaration""" def __init__( self, *args, **keywords ): free_calldef_t.__init__( self, *args, **keywords ) - operator_t.__init__( self, *args, **keywords ) \ No newline at end of file + operator_t.__init__( self, *args, **keywords ) Modified: pygccxml_dev/pygccxml/declarations/class_declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-08-20 19:53:54 UTC (rev 426) +++ pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-08-21 08:04:14 UTC (rev 427) @@ -20,7 +20,7 @@ """class that defines "access" constants""" PUBLIC = "public" PRIVATE = "private" - PROTECTED = "protected" + PROTECTED = "protected" ALL = [ PUBLIC, PRIVATE, PROTECTED ] class CLASS_TYPES: @@ -31,10 +31,9 @@ ALL = [ CLASS, STRUCT, UNION ] class hierarchy_info_t( object ): - """ - describes class relationship - """ + """describes class relationship""" def __init__(self, related_class=None, access=None ): + """creates class that contains partial information about class relationship""" if related_class: assert( isinstance( related_class, class_t ) ) self._related_class = related_class @@ -78,17 +77,19 @@ class class_declaration_t( declaration.declaration_t ): """describes class declaration""" def __init__( self, name='' ): + """creates class that describes C++ class declaration( and not definition )""" declaration.declaration_t.__init__( self, name ) - + def _get__cmp__items(self): - """@undocumented _get__cmp__items:""" - return [] + """implementation details""" + return [] class class_t( scopedef.scopedef_t ): """describes class definition""" USE_DEMANGLED_AS_NAME = True def __init__( self, name='', class_type=CLASS_TYPES.CLASS, is_abstract=False ): + """creates class that describes C++ class definition""" scopedef.scopedef_t.__init__( self, name ) if class_type: assert( class_type in CLASS_TYPES.ALL ) @@ -100,7 +101,7 @@ self._private_members = [] self._protected_members = [] self._aliases = [] - + def _get_name_impl( self ): if not self._name: #class with empty name return self._name @@ -111,13 +112,13 @@ if self.demangled.startswith( fname ): tmp = self.demangled[ len( fname ): ] #demangled::name if tmp.startswith( '::' ): - tmp = tmp[2:] + tmp = tmp[2:] return tmp else: return self._name else: return self._name - + def __str__(self): name = algorithm.full_name(self) if name[:2]=="::": @@ -125,15 +126,15 @@ return "%s [%s]"%(name, self.class_type) def _get__cmp__scope_items(self): - """@undocumented _get__cmp__scope_items:""" - return [ self.class_type + """implementation details""" + return [ self.class_type , self._sorted_list( [ algorithm.declaration_path( base.related_class ) for base in self.bases ] ) , self._sorted_list( [ algorithm.declaration_path( derive.related_class ) for derive in self.derived ] ) - , self.is_abstract + , self.is_abstract , self._sorted_list( self.public_members ) , self._sorted_list( self.private_members ) , self._sorted_list( self.protected_members ) ] - + def __eq__(self, other): if not scopedef.scopedef_t.__eq__( self, other ): return False @@ -177,7 +178,7 @@ return all_bases recursive_bases = property( _get_recursive_bases , doc="returns a list of all L{base classes<hierarchy_info_t>}") - + def _get_derived(self): return self._derived def _set_derived( self, new_derived ): @@ -238,12 +239,12 @@ def get_members( self, access=None): """ returns list of members according to access type - + If access equals to None, then returned list will contain all members. - + @param access: describes desired members @type access: L{ACCESS_TYPES} - + @return: [ members ] """ if access == ACCESS_TYPES.PUBLIC: @@ -262,10 +263,10 @@ def set_members( self, access, new_members ): """ set list of members according to access type - + @param access: describes desired members @type access: L{ACCESS_TYPES} - + @param new_members: list of new members @type new_members: [ L{member<declaration_t>} ] """ @@ -278,11 +279,11 @@ self.private_members = new_members for member in new_members: member.parent = self - + def remove_declaration( self, decl ): """ removes decl from members list - + @param decl: declaration to be removed @type decl: L{declaration_t} """ @@ -299,14 +300,14 @@ #add more comment about this. #if not keep_parent: # decl.parent=None - + def find_out_member_access_type( self, member ): """ returns member access type - + @param member: member of the class @type member: L{declaration_t} - + @return: L{ACCESS_TYPES} """ assert member.parent is self @@ -317,4 +318,4 @@ elif member in self.private_members: return ACCESS_TYPES.PRIVATE else: - raise RuntimeError( "Unable to find member within internal members list." ) \ No newline at end of file + raise RuntimeError( "Unable to find member within internal members list." ) Modified: pygccxml_dev/pygccxml/declarations/cpptypes.py =================================================================== --- pygccxml_dev/pygccxml/declarations/cpptypes.py 2006-08-20 19:53:54 UTC (rev 426) +++ pygccxml_dev/pygccxml/declarations/cpptypes.py 2006-08-21 08:04:14 UTC (rev 427) @@ -40,27 +40,30 @@ def _clone_impl( self ): raise NotImplementedError() - + def clone( self ): "returns new instance of the type" answer = self._clone_impl() assert answer return answer - + #There are cases when GCC-XML reports something like this #<Unimplemented id="_9482" tree_code="188" tree_code_name="template_type_parm" node="0xcc4d5b0"/> #In this case I will use this as type class dummy_type_t( type_t ): - #This class is very usefull for code generation + """provides L{type_t} interface for a string, that defines C++ type. + + This class could be very useful in the code generator. + """ def __init__( self, decl_string ): type_t.__init__( self ) self._decl_string = decl_string - + def _create_decl_string(self): return self._decl_string - + def _clone_impl( self ): return dummy_type_t( self._decl_string ) @@ -71,10 +74,10 @@ def _create_decl_string(self): return '?unknown?' - + def _clone_impl( self ): - return self - + return self + ################################################################################ ## Fundamental types: @@ -91,142 +94,168 @@ return self class java_fundamental_t( fundamental_t ): + """base class for all JNI defined fundamental types""" def __init__( self, name ): fundamental_t.__init__( self, name ) class void_t( fundamental_t ): + """represents void type""" CPPNAME = 'void' def __init__( self ): fundamental_t.__init__( self,void_t.CPPNAME ) class char_t( fundamental_t ): + """represents char type""" CPPNAME = 'char' def __init__( self ): fundamental_t.__init__( self, char_t.CPPNAME ) class unsigned_char_t( fundamental_t ): + """represents unsigned char type""" CPPNAME = 'unsigned char' def __init__( self ): fundamental_t.__init__( self, unsigned_char_t.CPPNAME ) class wchar_t( fundamental_t ): + """represents wchar_t type""" CPPNAME = 'wchar_t' def __init__( self ): fundamental_t.__init__( self, wchar_t.CPPNAME ) class short_int_t( fundamental_t ): + """represents short int type""" CPPNAME = 'short int' def __init__( self ): fundamental_t.__init__( self, short_int_t.CPPNAME ) class short_unsigned_int_t( fundamental_t ): + """represents short unsigned int type""" CPPNAME = 'short unsigned int' def __init__( self ): fundamental_t.__init__( self, short_unsigned_int_t.CPPNAME ) class bool_t( fundamental_t ): + """represents bool type""" CPPNAME = 'bool' def __init__( self ): fundamental_t.__init__( self, bool_t.CPPNAME ) class int_t( fundamental_t ): + """represents int type""" CPPNAME = 'int' def __init__( self ): fundamental_t.__init__( self, int_t.CPPNAME ) class unsigned_int_t( fundamental_t ): + """represents unsigned int type""" CPPNAME = 'unsigned int' def __init__( self ): fundamental_t.__init__( self, unsigned_int_t.CPPNAME ) class long_int_t( fundamental_t ): + """represents long int type""" CPPNAME = 'long int' def __init__( self ): fundamental_t.__init__( self, long_int_t.CPPNAME ) class long_unsigned_int_t( fundamental_t ): + """represents long unsigned int type""" CPPNAME = 'long unsigned int' def __init__( self ): fundamental_t.__init__( self, long_unsigned_int_t.CPPNAME ) class long_long_int_t( fundamental_t ): + """represents long long int type""" CPPNAME = 'long long int' def __init__( self ): fundamental_t.__init__( self, long_long_int_t.CPPNAME ) class long_long_unsigned_int_t( fundamental_t ): + """represents long long unsigned int type""" CPPNAME = 'long long unsigned int' def __init__( self ): fundamental_t.__init__( self, long_long_unsigned_int_t.CPPNAME ) class float_t( fundamental_t ): + """represents float type""" CPPNAME = 'float' def __init__( self ): fundamental_t.__init__( self, float_t.CPPNAME ) class double_t( fundamental_t ): + """represents double type""" CPPNAME = 'double' def __init__( self ): fundamental_t.__init__( self, double_t.CPPNAME ) class long_double_t( fundamental_t ): + """represents long double type""" CPPNAME = 'long double' def __init__( self ): fundamental_t.__init__( self, long_double_t.CPPNAME ) class complex_double_t( fundamental_t ): + """represents complex double type""" CPPNAME = 'complex double' def __init__( self ): fundamental_t.__init__( self, complex_double_t.CPPNAME ) class complex_long_double_t( fundamental_t ): + """represents complex long double type""" CPPNAME = 'complex long double' def __init__( self ): fundamental_t.__init__( self, complex_long_double_t.CPPNAME ) class complex_float_t( fundamental_t ): + """represents complex float type""" CPPNAME = 'complex float' def __init__( self ): fundamental_t.__init__( self, complex_float_t.CPPNAME ) class jbyte_t( java_fundamental_t ): + """represents jbyte type""" JNAME = 'jbyte' def __init__( self ): java_fundamental_t.__init__( self, jbyte_t.JNAME ) class jshort_t( java_fundamental_t ): + """represents jshort type""" JNAME = 'jshort' def __init__( self ): java_fundamental_t.__init__( self, jshort_t.JNAME ) class jint_t( java_fundamental_t ): + """represents jint type""" JNAME = 'jint' def __init__( self ): java_fundamental_t.__init__( self, jint_t.JNAME ) class jlong_t( java_fundamental_t ): + """represents jlong type""" JNAME = 'jlong' def __init__( self ): java_fundamental_t.__init__( self, jlong_t.JNAME ) class jfloat_t( java_fundamental_t ): + """represents jfloat type""" JNAME = 'jfloat' def __init__( self ): java_fundamental_t.__init__( self, jfloat_t.JNAME ) - class jdouble_t( java_fundamental_t ): + """represents jdouble type""" JNAME = 'jdouble' def __init__( self ): java_fundamental_t.__init__( self, jdouble_t.JNAME ) - class jchar_t( java_fundamental_t ): + """represents jchar type""" JNAME = 'jchar' def __init__( self ): java_fundamental_t.__init__( self, jchar_t.JNAME ) class jboolean_t( java_fundamental_t ): + """represents jboolean type""" JNAME = 'jboolean' def __init__( self ): java_fundamental_t.__init__( self, jboolean_t.JNAME ) @@ -271,8 +300,11 @@ , '__java_double' : jdouble_t() , '__java_char' : jchar_t() , '__java_boolean' : jboolean_t() - } +""" +defines a mapping between funcdamental type name and its synonym to the instance +of class that describes the type +""" ################################################################################ ## Compaund types: @@ -292,6 +324,7 @@ , doc="reference to internal/base class") class volatile_t( compound_t ): + """represents C{volatile whatever} type""" def __init__( self, base ): compound_t.__init__( self, base) @@ -300,8 +333,9 @@ def _clone_impl( self ): return volatile_t( self.base.clone() ) - + class const_t( compound_t ): + """represents C{whatever const} type""" def __init__( self, base ): compound_t.__init__( self, base ) @@ -312,6 +346,7 @@ return const_t( self.base.clone() ) class pointer_t( compound_t ): + """represents C{whatever*} type""" def __init__( self, base ): compound_t.__init__( self, base ) @@ -322,6 +357,7 @@ return pointer_t( self.base.clone() ) class reference_t( compound_t ): + """represents C{whatever&} type""" def __init__( self, base ): compound_t.__init__( self, base) @@ -332,6 +368,7 @@ return reference_t( self.base.clone() ) class array_t( compound_t ): + """represents C++ array type""" SIZE_UNKNOWN = -1 def __init__( self, base, size ): compound_t.__init__( self, base ) @@ -339,7 +376,7 @@ def _get_size(self): return self._size - size = property( _get_size, + size = property( _get_size, doc="returns array size" ) def _create_decl_string(self): @@ -355,7 +392,7 @@ self._return_type = return_type if arguments_types is None: arguments_types = [] - self._arguments_types = arguments_types + self._arguments_types = arguments_types def _get_return_type(self): return self._return_type @@ -379,45 +416,49 @@ type_t.__init__(self) calldef_type_t.__init__( self, return_type, arguments_types ) - @staticmethod + @staticmethod def create_decl_string( return_type, arguments_types ): """ returns free function type - + @param return_type: function return type @type return_type: L{type_t} - + @param arguments_types: list of argument L{type<type_t>} - + @return: L{free_function_type_t} """ - return free_function_type_t.NAME_TEMPLATE % { + return free_function_type_t.NAME_TEMPLATE % { 'return_type' : return_type.decl_string , 'arguments' : ','.join( map( lambda x: x.decl_string, arguments_types ) ) } - + def _create_decl_string(self): return self.create_decl_string( self.return_type, self.arguments_types ) def _clone_impl( self ): rt_clone = None if self.return_type: - rt_clone = self.return_type.clone() + rt_clone = self.return_type.clone() return free_function_type_t( rt_clone , [ arg.clone() for arg in self.arguments_types ] ) #TODO: create real typedef def create_typedef( self, typedef_name, unused=None): + """returns string, that contains valid C++ code, that defines typedef to function type + + @param name: the desired name of typedef + """ #unused argument simplifies user code - return free_function_type_t.TYPEDEF_NAME_TEMPLATE % { + return free_function_type_t.TYPEDEF_NAME_TEMPLATE % { 'typedef_name' : typedef_name - , 'return_type' : self.return_type.decl_string + , 'return_type' : self.return_type.decl_string , 'arguments' : ','.join( map( lambda x: x.decl_string, self.arguments_types ) ) } - + class member_function_type_t( type_t, calldef_type_t ): """describes member function type""" NAME_TEMPLATE = '%(return_type)s ( %(class)s::* )( %(arguments)s ) %(has_const)s' TYPEDEF_NAME_TEMPLATE = '%(return_type)s ( %(class)s::*%(typedef_name)s )( %(arguments)s ) %(has_const)s' - + def __init__( self, class_inst=None, return_type=None, arguments_types=None, has_const=False): type_t.__init__(self) calldef_type_t.__init__( self, return_type, arguments_types ) @@ -429,7 +470,7 @@ def _set_has_const(self, has_const ): self._has_const = has_const has_const = property( _get_has_const, _set_has_const - , doc="describes, whether function has const modifier") + , doc="describes, whether function has const modifier") def _get_class_inst(self): return self._class_inst @@ -440,9 +481,8 @@ #TODO: create real typedef def create_typedef( self, typedef_name, class_alias=None): - """ - creates typedef to the function type - + """creates typedef to the function type + @param typedef_name: desired type name @return: string """ @@ -451,12 +491,12 @@ has_const_str = 'const' if None is class_alias: class_alias = self.class_inst.decl_string - return member_function_type_t.TYPEDEF_NAME_TEMPLATE % { + return member_function_type_t.TYPEDEF_NAME_TEMPLATE % { 'typedef_name' : typedef_name - , 'return_type' : self.return_type.decl_string + , 'return_type' : self.return_type.decl_string , 'class' : class_alias , 'arguments' : ','.join( map( lambda x: x.decl_string, self.arguments_types ) ) - , 'has_const' : has_const_str } + , 'has_const' : has_const_str } def create(self): return self.create_decl_string( self.return_type @@ -465,7 +505,7 @@ , self.has_const ) - @staticmethod + @staticmethod def create_decl_string(return_type, class_decl_string, arguments_types, has_const): has_const_str = '' if has_const: @@ -473,12 +513,12 @@ return_type_decl_string = '' if return_type: return_type_decl_string = return_type.decl_string - return member_function_type_t.NAME_TEMPLATE % { - 'return_type' : return_type_decl_string + return member_function_type_t.NAME_TEMPLATE % { + 'return_type' : return_type_decl_string , 'class' : class_decl_string , 'arguments' : ','.join( map( lambda x: x.decl_string, arguments_types ) ) - , 'has_const' : has_const_str } - + , 'has_const' : has_const_str } + def _create_decl_string(self): return self.create_decl_string( self.return_type , self.class_inst.decl_string @@ -489,19 +529,19 @@ rt_clone = None if self.return_type: rt_clone = self.return_type.clone() - + return member_function_type_t( self.class_inst , rt_clone , [ arg.clone() for arg in self.arguments_types ] , self.has_const ) - + class member_variable_type_t( compound_t ): """describes member variable type""" NAME_TEMPLATE = '%(type)s ( %(class)s::* )' def __init__( self, class_inst=None, variable_type=None ): compound_t.__init__(self, class_inst) - self._mv_type = variable_type + self._mv_type = variable_type def _get_variable_type(self): return self._mv_type @@ -516,13 +556,13 @@ def _clone_impl( self ): return member_variable_type_t( class_inst=self.base , variable_type=self.variable_type.clone() ) - + ################################################################################ ## declarated types: class declarated_t( type_t ): - """describes type declared by user""" + """class that binds between to hierarchies: L{type_t} and L{declaration_t}""" def __init__( self, declaration ): type_t.__init__( self ) self._declaration = declaration @@ -541,6 +581,7 @@ return declarated_t( self.declaration ) class type_qualifiers_t( object ): + """contains additional information about type: mutable, static, extern""" def __init__(self, has_static=False, has_mutable=False ): self._has_static = has_static self._has_mutable = has_mutable @@ -572,15 +613,3 @@ def _set_has_mutable(self, has_mutable ): self._has_mutable = has_mutable has_mutable = property( _get_has_mutable, _set_has_mutable ) - - #~ def apply_qualifiers( qualifiers, type ): - #~ result = [] - #~ if qualifiers.has_static: - #~ result.append( 'static' ) - #~ if qualifiers.has_mutable: - #~ result.append( 'mutable' ) - #~ if isinstance( type, type_t ): - #~ result.append( type.decl_string ) - #~ else: - #~ result.append( type ) - #~ return ' '.join( result ) Modified: pygccxml_dev/pygccxml/declarations/decl_factory.py =================================================================== --- pygccxml_dev/pygccxml/declarations/decl_factory.py 2006-08-20 19:53:54 UTC (rev 426) +++ pygccxml_dev/pygccxml/declarations/decl_factory.py 2006-08-21 08:04:14 UTC (rev 427) @@ -4,7 +4,7 @@ # http://www.boost.org/LICENSE_1_0.txt) """ -defines declarations factory class +defines default declarations factory class """ from calldef import member_function_t @@ -26,43 +26,57 @@ declarations factory class """ def __init__(self): + """creates declarations factory""" object.__init__(self) - + def create_member_function( self, *arguments, **keywords ): + """creates instance of class that describes member function declaration""" return member_function_t(*arguments, **keywords) - + def create_constructor( self, *arguments, **keywords ): + """creates instance of class that describes constructor declaration""" return constructor_t(*arguments, **keywords) - + def create_destructor( self, *arguments, **keywords ): + """creates instance of class that describes destructor declaration""" return destructor_t(*arguments, **keywords) - + def create_member_operator( self, *arguments, **keywords ): + """creates instance of class that describes member operator declaration""" return member_operator_t(*arguments, **keywords) - + def create_casting_operator( self, *arguments, **keywords ): + """creates instance of class that describes casting operator declaration""" return casting_operator_t(*arguments, **keywords) - + def create_free_function( self, *arguments, **keywords ): + """creates instance of class that describes free function declaration""" return free_function_t(*arguments, **keywords) - + def create_free_operator( self, *arguments, **keywords ): + """creates instance of class that describes free operator declaration""" return free_operator_t(*arguments, **keywords) def create_class_declaration(self, *arguments, **keywords ): + """creates instance of class that describes class declaration""" return class_declaration_t(*arguments, **keywords) - + def create_class( self, *arguments, **keywords ): + """creates instance of class that describes class definition declaration""" return class_t(*arguments, **keywords) - + def create_enumeration( self, *arguments, **keywords ): + """creates instance of class that describes enumeration declaration""" return enumeration_t(*arguments, **keywords) - + def create_namespace( self, *arguments, **keywords ): + """creates instance of class that describes namespace declaration""" return namespace_t(*arguments, **keywords) - + def create_typedef( self, *arguments, **keywords ): + """creates instance of class that describes typedef declaration""" return typedef_t(*arguments, **keywords) - + def create_variable( self, *arguments, **keywords ): + """creates instance of class that describes variable declaration""" return variable_t(*arguments, **keywords) Modified: pygccxml_dev/pygccxml/declarations/declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/declaration.py 2006-08-20 19:53:54 UTC (rev 426) +++ pygccxml_dev/pygccxml/declarations/declaration.py 2006-08-21 08:04:14 UTC (rev 427) @@ -15,8 +15,7 @@ class location_t(object): - - """Provides information about the location of the declaration within the source file. + """provides information about the location of the declaration within the source file. The header file name and the line number of the declaration can be accessed via the attributes C{file_name} and C{line}. @@ -57,7 +56,7 @@ , doc="""The line number where the declaration was found @type: int """) - + def as_tuple( self ): """Return the header file name and the line number. @@ -68,7 +67,7 @@ class declaration_t( object ): """Base class for all classes that represent a C++ declaration. """ - + def __init__( self, name='', location=None, is_artificial=False, mangled=None, demangled=None ): self._name = name self._location = location @@ -94,25 +93,25 @@ # Append the declaration class cls = self.__class__.__name__ if cls[-2:]=="_t": - cls = cls[:-2] + cls = cls[:-2] return "%s [%s]"%(name, cls) - @staticmethod + @staticmethod def _sorted_list( some_list ): - """@undocumented _sorted_list:""" + """implementation details""" some_list.sort() return some_list def _get__cmp__items( self ): - """@undocumented _get__cmp__items:""" - #Every derived class should implement this method. This method should + """implementation details""" + #Every derived class should implement this method. This method should #return a list of items, that should be compared. print '_get__cmp__items not implemented for class ', self.__class__.__name__ raise NotImplemented() def _get__cmp__data(self): - """@undocumented _get__cmp__data:""" + """implementation details""" data = [ algorithm.declaration_path( self.parent ), self.name, self.location ] data.extend( self._get__cmp__items() ) return data @@ -120,8 +119,8 @@ def __eq__(self, other): """ function will return true, if both declarations refers to the same object. - This function could be implemented in terms of _get__cmp__data, but in - this case it will downgrade performance. self.mangled property is not + This function could be implemented in terms of _get__cmp__data, but in + this case it will downgrade performance. self.mangled property is not compared, because it could be chaned from one compilation time to an other. """ @@ -145,13 +144,13 @@ if not isinstance( other, self.__class__ ): return self.__class__.__name__ < other.__class__.__name__ return self._get__cmp__data() < other._get__cmp__data() - + def _get_name_impl( self ): return self._name - + def _get_name( self ): return self._get_name_impl() - + def _set_name( self, new_name ): self._name = new_name name = property( _get_name, _set_name @@ -222,10 +221,10 @@ def _create_decl_string(self): return algorithm.full_name( self ) - + def _decl_string(self): - return self._create_decl_string() + return self._create_decl_string() decl_string = property( _decl_string, doc="""Full name of the declaration @type: str - """ ) \ No newline at end of file + """ ) Modified: pygccxml_dev/pygccxml/declarations/enumeration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/enumeration.py 2006-08-20 19:53:54 UTC (rev 426) +++ pygccxml_dev/pygccxml/declarations/enumeration.py 2006-08-21 08:04:14 UTC (rev 427) @@ -16,11 +16,11 @@ describes C++ enum """ def __init__( self, name='', values=None ): - """Constructor. + """creates class that describes C++ enum declaration The items of the list 'values' may either be strings containing the enumeration value name or tuples (name, numvalue). - + @param name: Enum name @type name: str @param parent: Parent declaration @@ -43,7 +43,7 @@ return self.values == other.values def _get__cmp__items( self ): - """@undocumented _get__cmp__items:""" + """implementation details""" return [self.values] def _get_values(self): @@ -108,7 +108,8 @@ return False def get_name2value_dict( self ): + """returns a dictionary, that maps between enum name( key ) and enum value( value )""" x = {} for val, num in self._values: x[val] = num - return x \ No newline at end of file + return x Modified: pygccxml_dev/pygccxml/declarations/filtering.py =================================================================== --- pygccxml_dev/pygccxml/declarations/filtering.py 2006-08-20 19:53:54 UTC (rev 426) +++ pygccxml_dev/pygccxml/declarations/filtering.py 2006-08-21 08:04:14 UTC (rev 427) @@ -4,41 +4,44 @@ # http://www.boost.org/LICENSE_1_0.txt) """ -defines few algorithms for filtering declarations +deprecated! + +This module defines few algorithms for filtering declarations. """ import os import algorithm class filtering: - """ + """deprecated! + defines few algorithms for filtering declarations """ - - @staticmethod + + @staticmethod def normalize_path( some_path ): """return os.path.normcase( os.path.normpath( some_path ) )""" return os.path.normcase( os.path.normpath( some_path ) ) - - @staticmethod + + @staticmethod def contains_parent_dir( fpath, dirs ): #precondition: dirs and fpath should be normalize_path'ed before calling this function return bool( filter( lambda dir: fpath.startswith( dir ), dirs ) ) - - @staticmethod - def by_location( decls, locations ): + + @staticmethod + def by_location( decls, locations ): """ returns list of declarations that belongs to specified locations. - + This function works recursively. Pay attention: if you remove namespace, then you remove all declarations defined within the namespace. - + @param decls: declaration or list of declarations @type decls: L{declaration<declaration_t>} or list of L{declarations<declaration_t>} - + @param locations: list of directories and/or files names @type locations: list of strings - + @return: list of L{declarations<declaration_t>} """ #precondition: decls is a list of op level namespaces @@ -48,7 +51,7 @@ dirs = filter( lambda location: os.path.isdir( location ), locations ) files = filter( lambda location: os.path.isfile( location ), locations ) result = [] - for decl in temp_decls: + for decl in temp_decls: if not decl.location: result.append( decl ) continue @@ -57,21 +60,20 @@ result.append( decl ) return result - @staticmethod + @staticmethod def user_defined( decls, matcher ): """ returns list of declarations that match user specified criteria. - + This function works recursively. - + @param decls: declaration or list of declarations @type decls: L{declaration<declaration_t>} or list of L{declarations<declaration_t>} - + @param matcher: callable object, that takes 1 argument - declaration and returns True if object should stay, and false otherwise - + @return: list of L{declarations<declaration_t>} - """ + """ #precondition: decls is a list of op level namespaces return filter( matcher, algorithm.make_flatten( decls ) ) - \ No newline at end of file Modified: pygccxml_dev/pygccxml/declarations/mdecl_wrapper.py =================================================================== --- pygccxml_dev/pygccxml/declarations/mdecl_wrapper.py 2006-08-20 19:53:54 UTC (rev 426) +++ pygccxml_dev/pygccxml/declarations/mdecl_wrapper.py 2006-08-21 08:04:14 UTC (rev 427) @@ -3,32 +3,45 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +""" +defines class L{mdecl_wrapper_t} that allows to work on set of declarations, +as it was one declaration. + +The L{class<mdecl_wrapper_t>} allows user to not write "for" loops within the code. +""" + class call_redirector_t( object ): """Internal class used to call some function of objects""" def __init__( self, name, decls ): + """creates call_redirector_t instance. + + @param name: name of method, to be called on every object in C{decls} list + @param decls: list of objects + """ object.__init__( self ) self.name = name self.decls = decls - + def __call__( self, *arguments, **keywords ): + """calls method C{self.name} on every object within C{self.decls} list""" for d in self.decls: callable_ = getattr(d, self.name) callable_( *arguments, **keywords ) class mdecl_wrapper_t( object ): - """Multiple declarations wrapper. - - The main purpose of this class is to allow an user to work on many - declarations, as they were only one single declaration. - - Example: + """Multiple declarations wrapper. + + The main purpose of this class is to allow an user to work on many + declarations, as they were only one single declaration. + + Example: mb = module_builder_t( ... ) #lets say we want to exclude all member functions, that returns reference to int: mb.member_functions( return_type='int &' ).exclude() - + "exclude" function will be called on every function that match the criteria. """ - + def __init__( self, decls ): """@param decls: list of declarations to operate on. @type decls: list of L{declaration wrappers<decl_wrapper_t>} @@ -42,19 +55,19 @@ def __len__( self ): """returns the number of declarations""" return len( self.decls ) - + def __getitem__( self, index ): """provides access to declaration""" return self.decls[index] - + def __iter__( self ): return iter(self.decls) - + def __ensure_attribute( self, name ): invalid_decls = filter( lambda d: not hasattr( d, name ), self.decls ) if invalid_decls: raise RuntimeError( "Not all declarations have '%s' attribute." % name ) - + def __setattr__( self, name, value ): """Updates the value of attribute on all declarations. @param name: name of attribute @@ -63,11 +76,11 @@ self.__ensure_attribute( name ) for d in self.decls: setattr( d, name, value ) - + def __getattr__( self, name ): """@param name: name of method """ return call_redirector_t( name, self.decls ) - + def __contains__( self, item ): - return item in self.decls \ No newline at end of file + return item in self.decls Modified: pygccxml_dev/pygccxml/declarations/namespace.py =================================================================== --- pygccxml_dev/pygccxml/declarations/namespace.py 2006-08-20 19:53:54 UTC (rev 426) +++ pygccxml_dev/pygccxml/declarations/namespace.py 2006-08-21 08:04:14 UTC (rev 427) @@ -3,9 +3,8 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -""" -defines class, that describes C++ namespace -""" +"""defines class, that describes C++ namespace declaration""" + import declaration import scopedef import algorithm @@ -14,8 +13,9 @@ """ describes C++ namespace """ - + def __init__( self, name='', declarations=None ): + """creates class that describes C++ namespace declaration""" scopedef.scopedef_t.__init__( self, name ) if not declarations: declarations = [] @@ -28,15 +28,17 @@ return "%s [namespace]"%name def _get__cmp__scope_items(self): - """@undocumented _get__cmp__scope_items:""" + """implementation details""" return [ self._sorted_list( self.declarations ) ] - + def _get_declarations_impl(self): return self._declarations def _set_declarations(self, declarations): self._declarations = declarations - declarations = property( scopedef.scopedef_t._get_declarations, _set_declarations ) - + declarations = property( scopedef.scopedef_t._get_declarations + , _set_declarations + , doc="list of all declarations, defined in the namespace") + def take_parenting( self, inst ): """Takes parenting from inst and transfers it to self""" if self is inst: @@ -45,11 +47,11 @@ decl.parent = self self.declarations.append( decl ) inst.declarations = [] - + def remove_declaration( self, decl ): """ removes decl from members list - + @param decl: declaration to be removed @type decl: L{declaration_t} """ @@ -59,12 +61,14 @@ # decl.parent=None def namespace( self, name=None, function=None, recursive=None ): + """returns reference to namespace declaration, that is matched defined criterias""" return self._find_single( scopedef.scopedef_t._impl_matchers[ namespace_t.namespace ] , name=name , function=function , recursive=recursive ) def namespaces( self, name=None, function=None, recursive=None, allow_empty=None ): + """returns a set of namespace declarations, that are matched defined criterias""" return self._find_multiple( scopedef.scopedef_t._impl_matchers[ namespace_t.namespace ] , name=name , function=function @@ -72,51 +76,54 @@ , allow_empty=allow_empty) def free_function( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ): + """returns reference to free function declaration, that is matched defined criterias""" return self._find_single( scopedef.scopedef_t._impl_matchers[ namespace_t.free_function ] , name=name , function=function , decl_type=self._impl_decl_types[ namespace_t.free_function ] , return_type=return_type - , arg_types=arg_types + , arg_types=arg_types , header_dir=header_dir - , header_file=header_file + , header_file=header_file , recursive=recursive ) def free_functions( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None, allow_empty=None ): + """returns a set of free function declarations, that are matched defined criterias""" return self._find_multiple( scopedef.scopedef_t._impl_matchers[ namespace_t.free_function ] , name=name , function=function , decl_type=self._impl_decl_types[ namespace_t.free_function ] , return_type=return_type - , arg_types=arg_types + , arg_types=arg_types , header_dir=header_dir , header_file=header_file , recursive=recursive , allow_empty=allow_empty) def free_operator( self, name=None, function=None, symbol=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ): + """returns reference to free operator declaration, that is matched defined criterias""" return self._find_single( scopedef.scopedef_t._impl_matchers[ namespace_t.free_operator ] , name=self._build_operator_name( name, function, symbol ) , symbol=symbol , function=function , decl_type=self._impl_decl_types[ namespace_t.free_operator ] , return_type=return_type - , arg_types=arg_types + , arg_types=arg_types , header_dir=header_dir - , header_file=header_file + , header_file=header_file , recursive=recursive ) def free_operators( self, name=None, function=None, symbol=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None, allow_empty=None ): + """returns a set of free operator declarations, that are matched defined criterias""" return self._find_multiple( scopedef.scopedef_t._impl_matchers[ namespace_t.free_operator ] , name=self._build_operator_name( name, function, symbol ) , symbol=symbol , function=function , decl_type=self._impl_decl_types[ namespace_t.free_operator ] , return_type=return_type - , arg_types=arg_types + , arg_types=arg_types , header_dir=header_dir - , header_file=header_file + , header_file=header_file , recursive=recursive , allow_empty=allow_empty) - - \ No newline at end of file + Modified: pygccxml_dev/pygccxml/declarations/pattern_parser.py =================================================================== --- pygccxml_dev/pygccxml/declarations/pattern_parser.py 2006-08-20 19:53:54 UTC (rev 426) +++ pygccxml_dev/pygccxml/declarations/pattern_parser.py 2006-08-21 08:04:14 UTC (rev 427) @@ -3,13 +3,12 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -""" -implementation details -""" +"""implementation details""" import types class parser_t( object ): + """implementation details""" def __init__( self , pattern_char_begin , pattern_char_end @@ -21,12 +20,14 @@ self.__text_qualifier = '"' self.__char_qualifier = "'" self.__escape = '\\' - - def has_pattern( self, decl_string ): + + def has_pattern( self, decl_string ): + """implementation details""" last_part = decl_string.split( '::' )[-1] return -1 != last_part.find( self.__end ) def name( self, decl_string ): + """implementation details""" assert isinstance( decl_string, types.StringTypes ) if not self.has_pattern( decl_string ): return decl_string @@ -34,6 +35,7 @@ return decl_string[0: args_begin].strip() def __find_args_separator( self, decl_string, start_pos ): + """implementation details""" bracket_depth = 0 for index, ch in enumerate( decl_string[start_pos:] ): if ch not in ( self.__begin, self.__end, self.__separator ): @@ -50,12 +52,13 @@ return -1 def args( self, decl_string ): + """implementation details""" args_begin = decl_string.find( self.__begin ) args_end = decl_string.rfind( self.__end ) if -1 in ( args_begin, args_end ) or args_begin == args_end: raise RuntimeError( "%s doesn't valid template instantiation string" % decl_string ) - - args_only = decl_string[args_begin + 1: args_end ] + + args_only = decl_string[args_begin + 1: args_end ] args = [] previous_found, found = 0, 0 while True: @@ -71,10 +74,13 @@ return [ arg.strip() for arg in args ] NOT_FOUND = ( -1, -1 ) + """implementation details""" + def find_args(self, text, start=None ): + """implementation details""" if start==None: start = 0 - first_occurance = text.find( self.__begin, start ) + first_occurance = text.find( self.__begin, start ) if first_occurance == -1: return self.NOT_FOUND previous_found, found = first_occurance + 1, 0 @@ -88,11 +94,13 @@ previous_found = found + 1 #skip found sep def split( self, decl_string ): + """implementation details""" assert self.has_pattern( decl_string ) return self.name( decl_string ), self.args( decl_string ) - + def split_recursive( self, decl_string ): - assert self.has_pattern( decl_string ) + """implementation details""" + assert self.has_pattern( decl_string ) answer = [] to_go = [ decl_string ] while to_go: @@ -102,8 +110,9 @@ if self.has_pattern( arg ): to_go.append( arg ) return answer - + def join( self, name, args ): + """implementation details""" args = filter( None, args) args_str = '' if not args: @@ -112,5 +121,6 @@ args_str = ' ' + args[0] + ' ' else: args_str = ' ' + ', '.join( args ) + ' ' - - return ''.join( [ name, self.__begin, args_str, self.__end ] ) \ No newline at end of file + + return ''.join( [ name, self.__begin, args_str, self.__end ] ) + Modified: pygccxml_dev/pygccxml/declarations/scopedef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/scopedef.py 2006-08-20 19:53:54 UTC (rev 426) +++ pygccxml_dev/pygccxml/declarations/scopedef.py 2006-08-21 08:04:14 UTC (rev 427) @@ -21,51 +21,51 @@ This is the base class for all declaration classes that may have children nodes. The children can be accessed via the C{declarations} property. - + Also this class provides "get/select/find" interface. Using this class you - can get instance or instances of internal declaration(s). - + can get instance or instances of internal declaration(s). + You can find declaration(s) using next criteria: 1. name - declaration name, could be full qualified name 2. header_dir - directory, to which belongs file, that the declaration was declarated in. - header_dir should be absolute path. + header_dir should be absolute path. 3. header_file - file that the declaration was declarated in. 4. function - user ( your ) custom criteria. The interesting thing is that this function will be joined with other arguments ( criteria ). 5. recursive - the search declaration range, if True will be search in internal declarations too. - + Every "select" API you can invoke and pass as first argument at declaration name or function. This class will find out correctly what argument represents. - + Example:: ns - referrers to global namespace ns.member_function( "do_something ) - will return reference to member function named "do_something". If there is no such function exception will be raised. If there is more then one function exception will be raised too. - + Example 2:: ns - referers to global namespace - do_smths = ns.member_functions( "do_something ) - will return instance + do_smths = ns.member_functions( "do_something ) - will return instance of L{mdecl_wrapper_t} object. This object allows you few things: - + 1. To iterate on selected declarations 2. To set some property to desired value using one line of code only: do_smths.call_policies = x 3. To call some function on every instance using one line of code: do_smths.exclude() - - Pay attention: you can not use "get" functions or properties. + + Pay attention: you can not use "get" functions or properties. """ - RECURSIVE_DEFAULT = True + RECURSIVE_DEFAULT = True ALLOW_EMPTY_MDECL_WRAPPER = False - + _impl_matchers = {} #this class variable is used to prevent recursive imports _impl_decl_types = {} #this class variable is used to prevent recursive imports _impl_all_decl_types = [] #this class variable is used to prevent recursive imports - + def __init__( self, name=''): declaration.declaration_t.__init__( self, name ) @@ -78,18 +78,18 @@ def _get_logger( self ): return utils.loggers.queries_engine - _logger = property( _get_logger ) - + _logger = property( _get_logger, doc="reference to C{queries_engine} logger" ) + def _get__cmp__scope_i... [truncated message content] |
From: <rom...@us...> - 2006-08-20 19:54:09
|
Revision: 426 Author: roman_yakovenko Date: 2006-08-20 12:53:54 -0700 (Sun, 20 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=426&view=rev Log Message: ----------- adding documentation Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/calldef.py pygccxml_dev/pygccxml/declarations/class_declaration.py pygccxml_dev/pygccxml/declarations/declaration.py pygccxml_dev/pygccxml/declarations/enumeration.py pygccxml_dev/pygccxml/declarations/namespace.py pygccxml_dev/pygccxml/declarations/scopedef.py pygccxml_dev/pygccxml/declarations/typedef.py pygccxml_dev/pygccxml/declarations/variable.py pygccxml_dev/pygccxml/utils/__init__.py Modified: pygccxml_dev/pygccxml/declarations/calldef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/calldef.py 2006-08-20 19:15:31 UTC (rev 425) +++ pygccxml_dev/pygccxml/declarations/calldef.py 2006-08-20 19:53:54 UTC (rev 426) @@ -93,12 +93,7 @@ class calldef_t( declaration.declaration_t ): """base class for all "callable" declarations""" - def __init__( self - , name='' - , arguments=None - , exceptions=None - , return_type=None - , has_extern=False ): + def __init__( self, name='', arguments=None, exceptions=None, return_type=None, has_extern=False ): declaration.declaration_t.__init__( self, name ) if not arguments: arguments = [] @@ -111,9 +106,11 @@ self._demangled_name = None def _get__cmp__call_items(self): + """@undocumented _get__cmp__call_items:""" raise NotImplementedError() def _get__cmp__items( self ): + """@undocumented _get__cmp__items:""" items = [ self._sorted_list( self.arguments ) , self.return_type , self.has_extern @@ -183,6 +180,7 @@ """) def __remove_parent_fname( self, demangled ): + """@undocumented __remove_parent_fname:""" demangled = demangled.strip() parent_fname = algorithm.full_name( self.parent ) if parent_fname.startswith( '::' ) and not demangled.startswith( '::' ): @@ -276,6 +274,7 @@ return "%s [%s]"%(res, cls) def _get__cmp__call_items(self): + """@undocumented _get__cmp__call_items:""" return [ self.virtuality, self.has_static, self.has_const ] def __eq__(self, other): @@ -355,6 +354,7 @@ return "%s [%s]"%(res, cls) def _get__cmp__call_items(self): + """@undocumented _get__cmp__call_items:""" return [] def function_type(self): Modified: pygccxml_dev/pygccxml/declarations/class_declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-08-20 19:15:31 UTC (rev 425) +++ pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-08-20 19:53:54 UTC (rev 426) @@ -81,6 +81,7 @@ declaration.declaration_t.__init__( self, name ) def _get__cmp__items(self): + """@undocumented _get__cmp__items:""" return [] class class_t( scopedef.scopedef_t ): @@ -124,6 +125,7 @@ return "%s [%s]"%(name, self.class_type) def _get__cmp__scope_items(self): + """@undocumented _get__cmp__scope_items:""" return [ self.class_type , self._sorted_list( [ algorithm.declaration_path( base.related_class ) for base in self.bases ] ) , self._sorted_list( [ algorithm.declaration_path( derive.related_class ) for derive in self.derived ] ) Modified: pygccxml_dev/pygccxml/declarations/declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/declaration.py 2006-08-20 19:15:31 UTC (rev 425) +++ pygccxml_dev/pygccxml/declarations/declaration.py 2006-08-20 19:53:54 UTC (rev 426) @@ -99,18 +99,20 @@ @staticmethod def _sorted_list( some_list ): + """@undocumented _sorted_list:""" some_list.sort() return some_list def _get__cmp__items( self ): - """ - Every derived class should implement this method. This method should - return a list of items, that should be compared. - """ + """@undocumented _get__cmp__items:""" + #Every derived class should implement this method. This method should + #return a list of items, that should be compared. + print '_get__cmp__items not implemented for class ', self.__class__.__name__ raise NotImplemented() def _get__cmp__data(self): + """@undocumented _get__cmp__data:""" data = [ algorithm.declaration_path( self.parent ), self.name, self.location ] data.extend( self._get__cmp__items() ) return data Modified: pygccxml_dev/pygccxml/declarations/enumeration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/enumeration.py 2006-08-20 19:15:31 UTC (rev 425) +++ pygccxml_dev/pygccxml/declarations/enumeration.py 2006-08-20 19:53:54 UTC (rev 426) @@ -43,6 +43,7 @@ return self.values == other.values def _get__cmp__items( self ): + """@undocumented _get__cmp__items:""" return [self.values] def _get_values(self): Modified: pygccxml_dev/pygccxml/declarations/namespace.py =================================================================== --- pygccxml_dev/pygccxml/declarations/namespace.py 2006-08-20 19:15:31 UTC (rev 425) +++ pygccxml_dev/pygccxml/declarations/namespace.py 2006-08-20 19:53:54 UTC (rev 426) @@ -28,6 +28,7 @@ return "%s [namespace]"%name def _get__cmp__scope_items(self): + """@undocumented _get__cmp__scope_items:""" return [ self._sorted_list( self.declarations ) ] def _get_declarations_impl(self): Modified: pygccxml_dev/pygccxml/declarations/scopedef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/scopedef.py 2006-08-20 19:15:31 UTC (rev 425) +++ pygccxml_dev/pygccxml/declarations/scopedef.py 2006-08-20 19:53:54 UTC (rev 426) @@ -81,9 +81,11 @@ _logger = property( _get_logger ) def _get__cmp__scope_items(self): + """@undocumented _get__cmp__scope_items:""" raise NotImplementedError() def _get__cmp__items(self): + """@undocumented _get__cmp__items:""" items = [ self._sorted_list( self.declarations ) ] items.extend( self._get__cmp__scope_items() ) return items @@ -109,6 +111,7 @@ def __decl_types( self, decl ): + """@undocumented _get__cmp__items:""" types = [] bases = list( decl.__class__.__bases__ ) visited = set() @@ -187,6 +190,7 @@ self._optimized = True def _build_operator_name( self, name, function, symbol ): + """@undocumented _build_operator_name:""" def add_operator( sym ): if 'new' in sym or 'delete' in sym: return 'operator ' + sym @@ -204,24 +208,28 @@ def __normalize_args( self, **keywds ): + """@undocumented __normalize_args:""" if callable( keywds['name'] ) and None is keywds['function']: keywds['function'] = keywds['name'] keywds['name'] = None return keywds def __findout_recursive( self, **keywds ): + """@undocumented __findout_recursive:""" if None is keywds[ 'recursive' ]: return self.RECURSIVE_DEFAULT else: return keywds[ 'recursive' ] def __findout_allow_empty( self, **keywds ): + """@undocumented __findout_allow_empty:""" if None is keywds[ 'allow_empty' ]: return self.ALLOW_EMPTY_MDECL_WRAPPER else: return keywds[ 'allow_empty' ] def __findout_decl_type( self, match_class, **keywds ): + """@undocumented __findout_decl_type:""" if keywds.has_key( 'decl_type' ): return keywds['decl_type'] @@ -238,6 +246,7 @@ return None def __create_matcher( self, match_class, **keywds ): + """@undocumented __create_matcher:""" matcher_args = keywds.copy() del matcher_args['function'] del matcher_args['recursive'] @@ -253,6 +262,7 @@ return matcher def __findout_range( self, name, decl_type, recursive ): + """@undocumented __findout_range:""" if not self._optimized: self._logger.debug( 'running non optimized query - optimization has not been done' ) decls = self.declarations @@ -292,6 +302,7 @@ return self.declarations def _find_single( self, match_class, **keywds ): + """@undocumented _find_single:""" self._logger.debug( 'find single query execution - started' ) start_time = time.clock() norm_keywds = self.__normalize_args( **keywds ) @@ -304,6 +315,7 @@ return found def _find_multiple( self, match_class, **keywds ): + """@undocumented _find_multiple:""" self._logger.debug( 'find all query execution - started' ) start_time = time.clock() norm_keywds = self.__normalize_args( **keywds ) Modified: pygccxml_dev/pygccxml/declarations/typedef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/typedef.py 2006-08-20 19:15:31 UTC (rev 425) +++ pygccxml_dev/pygccxml/declarations/typedef.py 2006-08-20 19:53:54 UTC (rev 426) @@ -17,6 +17,7 @@ self._type = type def _get__cmp__items( self ): + """@undocumented _get__cmp__items:""" return [self.type] def __eq__(self, other): Modified: pygccxml_dev/pygccxml/declarations/variable.py =================================================================== --- pygccxml_dev/pygccxml/declarations/variable.py 2006-08-20 19:15:31 UTC (rev 425) +++ pygccxml_dev/pygccxml/declarations/variable.py 2006-08-20 19:53:54 UTC (rev 426) @@ -13,7 +13,7 @@ """describes C++ global and member variable declaration""" def __init__( self, name='', type=None, type_qualifiers=None, value=None, bits=None): - """@undocumented __init__:""" + """creates class that describes C++ global or member variable""" declaration.declaration_t.__init__( self, name ) self._type = type self._type_qualifiers = type_qualifiers Modified: pygccxml_dev/pygccxml/utils/__init__.py =================================================================== --- pygccxml_dev/pygccxml/utils/__init__.py 2006-08-20 19:15:31 UTC (rev 425) +++ pygccxml_dev/pygccxml/utils/__init__.py 2006-08-20 19:53:54 UTC (rev 426) @@ -3,12 +3,18 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +""" +defines logger classes and few convinience methods, not related to the declarations +tree +""" + import os import sys import logging import tempfile def _create_logger_( name ): + """@undocumented _create_logger:""" logger = logging.getLogger(name) handler = logging.StreamHandler(sys.stdout) handler.setFormatter( logging.Formatter( os.linesep + '%(levelname)s %(message)s' ) ) @@ -17,22 +23,51 @@ return logger class loggers: - gccxml = _create_logger_( 'pygccxml.gccxml' ) + """class-namespace, defines few loggers classes, used in the project""" + + gccxml = _create_logger_( 'pygccxml.gccxml' ) + """logger for gccxml functionality + + If you set this logger level to DEBUG, you will be able to see the exact + command line, used to invoke GCC-XML and errors that occures during XML parsing + """ + queries_engine = _create_logger_( 'pygccxml.queries_engine' ) + """logger for query engine functionality. + + If you set this logger level to DEBUG, you will be able to see what queries + you do against declarations tree, measure performance and may be even to improve it. + Query engine reports queries and whether they are optimized or not. + """ + declarations_cache = _create_logger_( 'pygccxml.declarations_cache' ) - #root logger exists for configuration purpose only + """logger for declarations tree cache functionality + + If you set this logger level to DEBUG, you will be able to see what is exactly + happens, when you read the declarations from cache file. You will be able to + decide, whether it worse for you to use this or that cache strategy. + """ + root = logging.getLogger( 'pygccxml' ) + """root logger exists for your convinience only""" + all = [ root, gccxml, queries_engine, declarations_cache ] + """contains all logger classes, defined by the class""" def remove_file_no_raise(file_name ): + """removes file from disk, if exception is raised, it silently ignores it""" try: if os.path.exists(file_name): os.remove( file_name ) except Exception, error: - logger.error( "Error ocured while removing temprorary created file('%s'): %s" - % ( file_name, str( error ) ) ) + loggers.root.error( "Error ocured while removing temprorary created file('%s'): %s" + % ( file_name, str( error ) ) ) def create_temp_file_name(suffix, prefix=None, dir=None): + """small convinience function that creates temporal file. + + This function is a wrapper aroung Python built-in function - tempfile.mkstemp + """ if not prefix: prefix = tempfile.template fd, name = tempfile.mkstemp( suffix=suffix, prefix=prefix, dir=dir ) @@ -41,4 +76,5 @@ return name def normalize_path( some_path ): + """return os.path.normpath( os.path.normcase( some_path ) )""" return os.path.normpath( os.path.normcase( some_path ) ) \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-20 19:15:45
|
Revision: 425 Author: roman_yakovenko Date: 2006-08-20 12:15:31 -0700 (Sun, 20 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=425&view=rev Log Message: ----------- fixing interface bug: parent should be managed by scopedef_t objects only Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/calldef.py pygccxml_dev/pygccxml/declarations/class_declaration.py pygccxml_dev/pygccxml/declarations/declaration.py pygccxml_dev/pygccxml/declarations/enumeration.py pygccxml_dev/pygccxml/declarations/namespace.py pygccxml_dev/pygccxml/declarations/scopedef.py pygccxml_dev/pygccxml/declarations/typedef.py pygccxml_dev/pygccxml/declarations/variable.py Modified: pygccxml_dev/pygccxml/declarations/calldef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/calldef.py 2006-08-20 14:16:39 UTC (rev 424) +++ pygccxml_dev/pygccxml/declarations/calldef.py 2006-08-20 19:15:31 UTC (rev 425) @@ -95,12 +95,11 @@ """base class for all "callable" declarations""" def __init__( self , name='' - , parent=None , arguments=None , exceptions=None , return_type=None , has_extern=False ): - declaration.declaration_t.__init__( self, name, parent ) + declaration.declaration_t.__init__( self, name ) if not arguments: arguments = [] self._arguments = arguments Modified: pygccxml_dev/pygccxml/declarations/class_declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-08-20 14:16:39 UTC (rev 424) +++ pygccxml_dev/pygccxml/declarations/class_declaration.py 2006-08-20 19:15:31 UTC (rev 425) @@ -77,8 +77,8 @@ class class_declaration_t( declaration.declaration_t ): """describes class declaration""" - def __init__( self, name='', parent='' ): - declaration.declaration_t.__init__( self, name, parent ) + def __init__( self, name='' ): + declaration.declaration_t.__init__( self, name ) def _get__cmp__items(self): return [] @@ -87,8 +87,8 @@ """describes class definition""" USE_DEMANGLED_AS_NAME = True - def __init__( self, name='', parent=None, class_type=CLASS_TYPES.CLASS, is_abstract=False ): - scopedef.scopedef_t.__init__( self, name, parent ) + def __init__( self, name='', class_type=CLASS_TYPES.CLASS, is_abstract=False ): + scopedef.scopedef_t.__init__( self, name ) if class_type: assert( class_type in CLASS_TYPES.ALL ) self._class_type = class_type Modified: pygccxml_dev/pygccxml/declarations/declaration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/declaration.py 2006-08-20 14:16:39 UTC (rev 424) +++ pygccxml_dev/pygccxml/declarations/declaration.py 2006-08-20 19:15:31 UTC (rev 425) @@ -69,15 +69,13 @@ """Base class for all classes that represent a C++ declaration. """ - def __init__( self, name='', parent=None, location=None, is_artificial=False, mangled=None, demangled=None ): + def __init__( self, name='', location=None, is_artificial=False, mangled=None, demangled=None ): self._name = name - if parent: - assert( isinstance( parent, declaration_t ) ) - self._parent = parent self._location = location self._is_artificial = is_artificial self._mangled = mangled self._demangled = demangled + self._parent = None def __str__(self): """Default __str__ method. Modified: pygccxml_dev/pygccxml/declarations/enumeration.py =================================================================== --- pygccxml_dev/pygccxml/declarations/enumeration.py 2006-08-20 14:16:39 UTC (rev 424) +++ pygccxml_dev/pygccxml/declarations/enumeration.py 2006-08-20 19:15:31 UTC (rev 425) @@ -15,7 +15,7 @@ """ describes C++ enum """ - def __init__( self, name='', parent=None, values=None ): + def __init__( self, name='', values=None ): """Constructor. The items of the list 'values' may either be strings containing @@ -28,7 +28,7 @@ @param values: Enumeration values @type values: list """ - declaration.declaration_t.__init__( self, name, parent ) + declaration.declaration_t.__init__( self, name ) # A list of tuples (valname(str), valnum(int)). The order of the list should # be the same as the order in the C/C++ source file. Modified: pygccxml_dev/pygccxml/declarations/namespace.py =================================================================== --- pygccxml_dev/pygccxml/declarations/namespace.py 2006-08-20 14:16:39 UTC (rev 424) +++ pygccxml_dev/pygccxml/declarations/namespace.py 2006-08-20 19:15:31 UTC (rev 425) @@ -15,8 +15,8 @@ describes C++ namespace """ - def __init__( self, name='', parent=None, declarations=None ): - scopedef.scopedef_t.__init__( self, name, parent ) + def __init__( self, name='', declarations=None ): + scopedef.scopedef_t.__init__( self, name ) if not declarations: declarations = [] self._declarations = declarations # list of all declarations belongs to this namespace Modified: pygccxml_dev/pygccxml/declarations/scopedef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/scopedef.py 2006-08-20 14:16:39 UTC (rev 424) +++ pygccxml_dev/pygccxml/declarations/scopedef.py 2006-08-20 19:15:31 UTC (rev 425) @@ -66,8 +66,8 @@ _impl_decl_types = {} #this class variable is used to prevent recursive imports _impl_all_decl_types = [] #this class variable is used to prevent recursive imports - def __init__( self, name='', parent=''): - declaration.declaration_t.__init__( self, name, parent ) + def __init__( self, name=''): + declaration.declaration_t.__init__( self, name ) self._optimized = False self._type2decls = {} Modified: pygccxml_dev/pygccxml/declarations/typedef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/typedef.py 2006-08-20 14:16:39 UTC (rev 424) +++ pygccxml_dev/pygccxml/declarations/typedef.py 2006-08-20 19:15:31 UTC (rev 425) @@ -12,8 +12,8 @@ class typedef_t( declaration.declaration_t ): """describes C++ typedef declaration""" - def __init__( self, name='', parent=None, type=None ): - declaration.declaration_t.__init__( self, name, parent ) + def __init__( self, name='', type=None ): + declaration.declaration_t.__init__( self, name ) self._type = type def _get__cmp__items( self ): Modified: pygccxml_dev/pygccxml/declarations/variable.py =================================================================== --- pygccxml_dev/pygccxml/declarations/variable.py 2006-08-20 14:16:39 UTC (rev 424) +++ pygccxml_dev/pygccxml/declarations/variable.py 2006-08-20 19:15:31 UTC (rev 425) @@ -12,9 +12,9 @@ class variable_t( declaration.declaration_t ): """describes C++ global and member variable declaration""" - def __init__( self, name='', parent=None, type=None, type_qualifiers=None, value=None, bits=None): - """@undocumented:""" - declaration.declaration_t.__init__( self, name, parent ) + def __init__( self, name='', type=None, type_qualifiers=None, value=None, bits=None): + """@undocumented __init__:""" + declaration.declaration_t.__init__( self, name ) self._type = type self._type_qualifiers = type_qualifiers self._value = value @@ -59,4 +59,4 @@ def _set_bits(self, bits): self._bits = bits bits = property( _get_bits, _set_bits - , doc="int, that contains information how many bit takes bit field") + , doc="integer, that contains information about how many bit takes bit field") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-20 14:17:02
|
Revision: 424 Author: roman_yakovenko Date: 2006-08-20 07:16:39 -0700 (Sun, 20 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=424&view=rev Log Message: ----------- adding documentation strings Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/__init__.py pygccxml_dev/pygccxml/declarations/container_traits.py pygccxml_dev/pygccxml/declarations/decl_printer.py pygccxml_dev/pygccxml/declarations/matcher.py pygccxml_dev/pygccxml/declarations/matchers.py pygccxml_dev/pygccxml/declarations/typedef.py pygccxml_dev/pygccxml/declarations/variable.py pygccxml_dev/setup.py pyplusplus_dev/setup.py Modified: pygccxml_dev/pygccxml/declarations/__init__.py =================================================================== --- pygccxml_dev/pygccxml/declarations/__init__.py 2006-08-20 07:45:50 UTC (rev 423) +++ pygccxml_dev/pygccxml/declarations/__init__.py 2006-08-20 14:16:39 UTC (rev 424) @@ -54,7 +54,7 @@ from cpptypes import member_variable_type_t from cpptypes import declarated_t from cpptypes import type_qualifiers_t -#java types +#java types from cpptypes import java_fundamental_t from cpptypes import jbyte_t from cpptypes import jshort_t @@ -160,7 +160,7 @@ from type_traits import smart_pointer_traits -from container_traits import list_traits +from container_traits import list_traits from container_traits import deque_traits from container_traits import queue_traits from container_traits import priority_queue @@ -175,8 +175,9 @@ from container_traits import multiset_traits from container_traits import hash_multiset_traits -all_container_traits = [ - list_traits +all_container_traits = \ +[ + list_traits , deque_traits , queue_traits , priority_queue @@ -189,8 +190,9 @@ , set_traits , hash_set_traits , multiset_traits - , hash_multiset_traits + , hash_multiset_traits ] +"""list, that contains all STD container traits classes""" import templates import call_invocation @@ -220,10 +222,10 @@ from decl_printer import print_declarations -#implementation details: I need this trick in order to prevent recursive imports import scopedef -scopedef.scopedef_t._impl_all_decl_types = [ +scopedef.scopedef_t._impl_all_decl_types = \ +[ scopedef.scopedef_t , enumeration_t , namespace_t @@ -241,53 +243,53 @@ , member_operator_t , casting_operator_t , free_function_t - , free_operator_t + , free_operator_t ] -impl_matchers = scopedef.scopedef_t._impl_matchers -impl_decl_types = scopedef.scopedef_t._impl_decl_types +__impl_matchers = scopedef.scopedef_t._impl_matchers +__impl_decl_types = scopedef.scopedef_t._impl_decl_types -impl_matchers[ scopedef.scopedef_t.decl ] = declaration_matcher_t +__impl_matchers[ scopedef.scopedef_t.decl ] = declaration_matcher_t -impl_matchers[ scopedef.scopedef_t.class_ ] = declaration_matcher_t -impl_decl_types[ scopedef.scopedef_t.class_ ] = class_t +__impl_matchers[ scopedef.scopedef_t.class_ ] = declaration_matcher_t +__impl_decl_types[ scopedef.scopedef_t.class_ ] = class_t -impl_matchers[ scopedef.scopedef_t.variable ] = variable_matcher_t +__impl_matchers[ scopedef.scopedef_t.variable ] = variable_matcher_t -impl_matchers[ scopedef.scopedef_t.calldef ] = calldef_matcher_t -impl_decl_types[ scopedef.scopedef_t.calldef ] = calldef_t +__impl_matchers[ scopedef.scopedef_t.calldef ] = calldef_matcher_t +__impl_decl_types[ scopedef.scopedef_t.calldef ] = calldef_t -impl_matchers[ scopedef.scopedef_t.operator ] = operator_matcher_t -impl_decl_types[ scopedef.scopedef_t.operator ] = operator_t +__impl_matchers[ scopedef.scopedef_t.operator ] = operator_matcher_t +__impl_decl_types[ scopedef.scopedef_t.operator ] = operator_t -impl_matchers[ scopedef.scopedef_t.member_function ] = calldef_matcher_t -impl_decl_types[ scopedef.scopedef_t.member_function ] = member_function_t +__impl_matchers[ scopedef.scopedef_t.member_function ] = calldef_matcher_t +__impl_decl_types[ scopedef.scopedef_t.member_function ] = member_function_t -impl_matchers[ scopedef.scopedef_t.constructor ] = calldef_matcher_t -impl_decl_types[ scopedef.scopedef_t.constructor ] = constructor_t +__impl_matchers[ scopedef.scopedef_t.constructor ] = calldef_matcher_t +__impl_decl_types[ scopedef.scopedef_t.constructor ] = constructor_t -impl_matchers[ scopedef.scopedef_t.member_operator ] = operator_matcher_t -impl_decl_types[ scopedef.scopedef_t.member_operator ] = member_operator_t +__impl_matchers[ scopedef.scopedef_t.member_operator ] = operator_matcher_t +__impl_decl_types[ scopedef.scopedef_t.member_operator ] = member_operator_t -impl_matchers[ scopedef.scopedef_t.member_operator ] = operator_matcher_t -impl_decl_types[ scopedef.scopedef_t.member_operator ] = member_operator_t +__impl_matchers[ scopedef.scopedef_t.member_operator ] = operator_matcher_t +__impl_decl_types[ scopedef.scopedef_t.member_operator ] = member_operator_t -impl_matchers[ scopedef.scopedef_t.casting_operator ] = calldef_matcher_t -impl_decl_types[ scopedef.scopedef_t.casting_operator ] = casting_operator_t +__impl_matchers[ scopedef.scopedef_t.casting_operator ] = calldef_matcher_t +__impl_decl_types[ scopedef.scopedef_t.casting_operator ] = casting_operator_t -impl_matchers[ scopedef.scopedef_t.enumeration ] = declaration_matcher_t -impl_decl_types[ scopedef.scopedef_t.enumeration ] = enumeration_t +__impl_matchers[ scopedef.scopedef_t.enumeration ] = declaration_matcher_t +__impl_decl_types[ scopedef.scopedef_t.enumeration ] = enumeration_t -impl_matchers[ scopedef.scopedef_t.typedef ] = declaration_matcher_t -impl_decl_types[ scopedef.scopedef_t.typedef ] = typedef_t +__impl_matchers[ scopedef.scopedef_t.typedef ] = declaration_matcher_t +__impl_decl_types[ scopedef.scopedef_t.typedef ] = typedef_t -impl_matchers[ namespace_t.namespace ] = namespace_matcher_t +__impl_matchers[ namespace_t.namespace ] = namespace_matcher_t -impl_matchers[ namespace_t.free_function ] = calldef_matcher_t -impl_decl_types[ namespace_t.free_function ] = free_function_t +__impl_matchers[ namespace_t.free_function ] = calldef_matcher_t +__impl_decl_types[ namespace_t.free_function ] = free_function_t -impl_matchers[ namespace_t.free_operator ] = operator_matcher_t -impl_decl_types[ namespace_t.free_operator ] = free_operator_t +__impl_matchers[ namespace_t.free_operator ] = operator_matcher_t +__impl_decl_types[ namespace_t.free_operator ] = free_operator_t Modified: pygccxml_dev/pygccxml/declarations/container_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/container_traits.py 2006-08-20 07:45:50 UTC (rev 423) +++ pygccxml_dev/pygccxml/declarations/container_traits.py 2006-08-20 14:16:39 UTC (rev 424) @@ -9,23 +9,40 @@ import calldef import cpptypes -import namespace +import namespace import templates import class_declaration import type_traits - + class container_traits_impl_t: + """this class implements the functionality needed for convinient work with + STD container classes. + + Implemented functionality: + - find out whether a declaration is STD container or not + - find out container value( mapped ) type + + This class tries to be useful as much, as possible. For example, for class + declaration( and not definition ) it parsers the class name in order to + extract all the information. + """ def __init__( self, container_name, element_type_index, element_type_typedef ): + """ + container_name - std container name + element_type_index - position of value\\mapped type within template + arguments list + element_type_typedef - class typedef to the value\\mapped type + """ self.name = container_name self.element_type_index = element_type_index - self.element_type_typedef = element_type_typedef + self.element_type_typedef = element_type_typedef def get_container_or_none( self, type ): """returns reference to the class declaration or None""" type = type_traits.remove_alias( type ) type = type_traits.remove_cv( type ) - - cls = None + + cls = None if isinstance( type, cpptypes.declarated_t ): cls = type_traits.remove_alias( type.declaration ) elif isinstance( type, class_declaration.class_t ): @@ -34,24 +51,27 @@ cls = type else: return - + if not cls.name.startswith( self.name + '<' ): - return - + return + if not type_traits.impl_details.is_defined_in_xxx( 'std', cls ): return return cls def is_my_case( self, type ): + """checks, whether type is STD container or not""" return bool( self.get_container_or_none( type ) ) - + def class_declaration( self, type ): + """returns reference to the class declaration""" cls = self.get_container_or_none( type ) if not cls: raise TypeError( 'Type "%s" is not instantiation of std::%s' % ( type.decl_string, self.name ) ) return cls - + def element_type( self, type ): + """returns reference to the class value\\mapped type declaration""" cls = self.class_declaration( type ) if isinstance( cls, class_declaration.class_t ): value_type = cls.typedef( self.element_type_typedef, recursive=False ).type @@ -60,26 +80,34 @@ value_type_str = templates.args( cls.name )[self.element_type_index] ref = type_traits.impl_details.find_value_type( cls.top_parent, value_type_str ) if None is ref: - raise RuntimeError( "Unable to find out %s '%s' value type." + raise RuntimeError( "Unable to find out %s '%s' value type." % ( self.name, cls.decl_string ) ) return ref + def create_traits_class( container_name, element_type_index, element_type_typedef ): + """ creates concrete container traits class """ + class xxx_traits: + """extract information from the container""" + impl = container_traits_impl_t( container_name, element_type_index, element_type_typedef ) @staticmethod def is_my_case( type ): + """returns True if type is the container class, otherwise False""" return xxx_traits.impl.is_my_case( type ) - + @staticmethod def class_declaration( type ): + """returns reference to the container class""" return xxx_traits.impl.class_declaration( type ) - + @staticmethod def element_type( type ): + """returns reference to container name value\\mapped type class""" return xxx_traits.impl.element_type( type ) - + return xxx_traits list_traits = create_traits_class( 'list', 0, 'value_type' ) Modified: pygccxml_dev/pygccxml/declarations/decl_printer.py =================================================================== --- pygccxml_dev/pygccxml/declarations/decl_printer.py 2006-08-20 07:45:50 UTC (rev 423) +++ pygccxml_dev/pygccxml/declarations/decl_printer.py 2006-08-20 14:16:39 UTC (rev 424) @@ -3,11 +3,16 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +""" +defines class, decl_printer_t that prints declarations tree in a user friendly format +""" + import os import sys import decl_visitor -import algorithm +import algorithm + class decl_printer_t( decl_visitor.decl_visitor_t ): """Helper class for printing decl tree. @@ -19,7 +24,7 @@ """ JUSTIFY = 20 INDENT_SIZE = 4 - + def __init__( self, level=0, print_details=True, recursive=True, writer=None ): decl_visitor.decl_visitor_t.__init__(self) self.__inst = None @@ -50,7 +55,7 @@ def _set_level(self, lvl): self.__level = lvl level = property( _get_level, _set_level ) - + def _get_print_details(self): return self.__print_details def _set_print_details(self, details): @@ -68,7 +73,7 @@ def _set_inst(self, inst): self.__inst = inst instance = property( _get_inst, _set_inst ) - + def __nice_decl_name( self, inst ): name = inst.__class__.__name__ return name @@ -76,15 +81,15 @@ # name = name[:-len('_t')] #return name.replace( '_', ' ' ) - def print_decl_header(self): + def print_decl_header(self): header = self.__nice_decl_name( self.__inst ) + ": '%s'" % self.__inst.name self.writer( ' ' * self.level * self.INDENT_SIZE + header.ljust( self.JUSTIFY ) + os.linesep ) if self.__print_details: - curr_level = self.level + 1 + curr_level = self.level + 1 if self.__inst.location: location = 'location: [%s]:%s'%(self.__inst.location.file_name, self.__inst.location.line) self.writer( ' ' * curr_level * self.INDENT_SIZE + location + os.linesep ) - artificial = 'artificial: ' + "'%s'" % str(self.__inst.is_artificial) + artificial = 'artificial: ' + "'%s'" % str(self.__inst.is_artificial) self.writer( ' ' * curr_level * self.INDENT_SIZE + artificial.ljust( self.JUSTIFY ) + os.linesep ) def __get_method_signature(self, decl=None): @@ -96,23 +101,23 @@ for arg in decl.arguments: args.append(arg.type.decl_string) return [retval, args] - + def visit_member_function( self ): self.print_decl_header() - self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + self.writer( ' ' * (self.level+1) * self.INDENT_SIZE + "Signature: " + str( self.__get_method_signature() ) + os.linesep ) def visit_constructor( self ): self.print_decl_header() def visit_destructor( self ): - self.print_decl_header() + self.print_decl_header() def visit_member_operator( self ): - self.print_decl_header() + self.print_decl_header() def visit_casting_operator( self ): - self.print_decl_header() + self.print_decl_header() def visit_free_function( self ): self.print_decl_header() @@ -126,23 +131,23 @@ def visit_class(self ): self.print_decl_header() curr_level = self.level + 1 - class_type = 'class type: ' + "'%s'" % str(self.__inst.class_type) + class_type = 'class type: ' + "'%s'" % str(self.__inst.class_type) self.writer( ' ' * curr_level * self.INDENT_SIZE + class_type.ljust( self.JUSTIFY ) + os.linesep ) - + if self.__inst.aliases: aliases = map( lambda typedef: typedef.name, self.__inst.aliases ) msg = 'aliases: ' + `aliases` self.writer( ' ' * curr_level * self.INDENT_SIZE + msg.ljust( self.JUSTIFY ) + os.linesep ) - + def print_hierarchy(hierarchy_type, classes, curr_level): self.writer( ' ' * curr_level * self.INDENT_SIZE + hierarchy_type.ljust( self.JUSTIFY ) + os.linesep ) curr_level += 1 for class_ in classes: - class_str = 'class: ' + "'%s'" % str(class_.related_class.decl_string) + class_str = 'class: ' + "'%s'" % str(class_.related_class.decl_string) self.writer( ' ' * curr_level * self.INDENT_SIZE + class_str.ljust( self.JUSTIFY ) + os.linesep ) - access = 'access: ' + "'%s'" % str(class_.access) + access = 'access: ' + "'%s'" % str(class_.access) self.writer( ' ' * (curr_level + 1)* self.INDENT_SIZE + access.ljust( self.JUSTIFY ) + os.linesep ) - + def print_members(members_type, members, curr_level): self.writer( ' ' * curr_level * self.INDENT_SIZE + members_type.ljust( self.JUSTIFY ) + os.linesep ) if self.__recursive: @@ -151,17 +156,17 @@ prn = self.clone() prn.instance = member algorithm.apply_visitor( prn, member ) - + if self.__inst.bases: print_hierarchy( 'base classes: ', self.__inst.bases, curr_level ) - + if self.__inst.derived: print_hierarchy( 'derived classes: ', self.__inst.derived, curr_level ) print_members( 'public: ', self.__inst.public_members, curr_level ) print_members( 'protected: ', self.__inst.protected_members, curr_level ) print_members( 'private: ', self.__inst.private_members, curr_level ) - + def visit_enumeration(self): self.print_decl_header() curr_level = self.level + 1 @@ -178,7 +183,7 @@ prn = self.clone() prn.instance = decl algorithm.apply_visitor( prn, decl ) - + def visit_typedef(self ): self.print_decl_header() curr_level = self.level + 1 @@ -188,7 +193,7 @@ self.print_decl_header() curr_level = self.level + 1 self.writer( ' ' * curr_level * self.INDENT_SIZE + 'type: %s value: %s'%(self.__inst.type.decl_string, self.__inst.value) + os.linesep) - + def print_declarations( decls, detailed=True, recursive=True, writer=sys.stdout.write ): """ Print decl tree rooted at each of the included nodes. decls - either a single decl or a list of decls. @@ -199,4 +204,4 @@ for d in decls: prn.level = 0 prn.instance = d - algorithm.apply_visitor(prn, d) \ No newline at end of file + algorithm.apply_visitor(prn, d) Modified: pygccxml_dev/pygccxml/declarations/matcher.py =================================================================== --- pygccxml_dev/pygccxml/declarations/matcher.py 2006-08-20 07:45:50 UTC (rev 423) +++ pygccxml_dev/pygccxml/declarations/matcher.py 2006-08-20 14:16:39 UTC (rev 424) @@ -3,29 +3,42 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +"""implements few "find" algorithms on declarations tree""" + import types import algorithm class matcher: - + """class-namespace, contains implementation of few "find" algorithms and + definition of related exception classes""" + class declaration_not_found_t( RuntimeError ): + """exception, that will be raised, if the declaration could not be found""" def __init__( self, matcher ): RuntimeError.__init__( self ) self.matcher = matcher - + def __str__( self ): return "Unable to find declaration. matcher: [%s]"%str(self.matcher) class multiple_declarations_found_t( RuntimeError ): + """exception, that will be raised, if more than one declaration was found""" def __init__( self, matcher ): RuntimeError.__init__( self ) self.matcher = matcher - + def __str__( self ): return "Multiple declarations has been found. matcher: [%s]"%str(self.matcher) - + @staticmethod def find( decl_matcher, decls, recursive=True ): + """returns a list of declarations that match "decl_matcher" defined criretia or None + + @param decl_matcher: Python callable object, that takes one argument - reference to declaration + @param decls: reference to declaration or list of declarations to be searched in + @param recursive: boolean, if True the method will run decl_matcher, on internal declarations too + """ + where = [] if isinstance( decls, types.ListType ): where.extend( decls ) @@ -35,18 +48,34 @@ where = algorithm.make_flatten( where ) return filter( decl_matcher, where ) - @staticmethod + @staticmethod def find_single( decl_matcher, decls, recursive=True ): + """returns a reference to declaration, that match "decl_matcher" defined + criretia, if a unique declaration could not be found the method will return + None. + + @param decl_matcher: Python callable object, that takes one argument - reference to declaration + @param decls: reference to declaration or list of declarations to be searched in + @param recursive: boolean, if True the method will run decl_matcher, on internal declarations too + """ answer = matcher.find( decl_matcher, decls, recursive ) if len(answer) == 1: return answer[0] - @staticmethod + @staticmethod def get_single( decl_matcher, decls, recursive=True ): + """returns a reference to declaration, that match "decl_matcher" defined + criretia, if a unique declaration could not be found, an appropriate + exception will be raised. + + @param decl_matcher: Python callable object, that takes one argument - reference to declaration + @param decls: reference to declaration or list of declarations to be searched in + @param recursive: boolean, if True the method will run decl_matcher, on internal declarations too + """ answer = matcher.find( decl_matcher, decls, recursive ) if len(answer) == 1: return answer[0] elif len(answer) == 0: raise matcher.declaration_not_found_t( decl_matcher ) else: - raise matcher.multiple_declarations_found_t( decl_matcher ) \ No newline at end of file + raise matcher.multiple_declarations_found_t( decl_matcher ) Modified: pygccxml_dev/pygccxml/declarations/matchers.py =================================================================== --- pygccxml_dev/pygccxml/declarations/matchers.py 2006-08-20 07:45:50 UTC (rev 423) +++ pygccxml_dev/pygccxml/declarations/matchers.py 2006-08-20 14:16:39 UTC (rev 424) @@ -3,13 +3,18 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +""" +defines all "built-in" classes that implement declarations compare functionality +according to some criteria +""" + import os import re import types import algorithm import variable -import namespace -import calldef +import namespace +import calldef import cpptypes import templates import class_declaration @@ -21,7 +26,7 @@ """ def __init__( self ): object.__init__( self ) - + def __call__(self, decl): raise NotImplementedError( "matcher must always implement the __call__() method." ) @@ -36,13 +41,13 @@ def __or__(self, other): """or-operator (|)""" return or_matcher_t([self, other]) - + def __str__( self ): return "base class for all matchers" class and_matcher_t(matcher_base_t): - """Combine several other matchers with "&". - + """Combine several other matchers with "&". + For example: find all private functions with name XXX C{ matcher = access_type_matcher_t( 'private' ) & calldef_matcher_t( name='XXX' ) } @@ -63,7 +68,7 @@ class or_matcher_t(matcher_base_t): """Combine several other matchers with "|". - + For example: find all functions and variables with name 'XXX' C{ matcher = variable_matcher_t( name='XXX' ) | calldef_matcher_t( name='XXX' ) } @@ -84,8 +89,8 @@ class not_matcher_t(matcher_base_t): - """Return the inverse result of matcher, using "~" - + """Return the inverse result of matcher, using "~" + For example: find all private and protected declarations C{ matcher = ~access_type_matcher_t( 'private' ) } @@ -104,7 +109,7 @@ class declaration_matcher_t( matcher_base_t ): """ Instance of this class will match declarations by next criteria: - - declaration name, also could be fully qualified name + - declaration name, also could be fully qualified name Example: wstring or ::std::wstring - declaration type Example: L{class_t}, L{namespace_t}, L{enumeration_t} @@ -114,7 +119,7 @@ """ @param decl_type: declaration type to match by. For example L{enumeration_t}. @type decl_type: any class that derives from L{declarations.declaration_t} class - + @param name: declaration name, could be full name. @type name: str @@ -125,10 +130,10 @@ @type header_file: str """ - #An other option is that pygccxml will create absolute path using - #os.path.abspath function. But I think this is just wrong, because abspath - #builds path using current working directory. This behavior is fragile - #and very difficult to find a bug. + #An other option is that pygccxml will create absolute path using + #os.path.abspath function. But I think this is just wrong, because abspath + #builds path using current working directory. This behavior is fragile + #and very difficult to find a bug. matcher_base_t.__init__( self ) self.decl_type = decl_type self.__name = None @@ -136,17 +141,17 @@ self.__opt_tmpl_name = None self.__opt_is_full_name = None self.__decl_name_only = None - + self._set_name( name ) - + self.header_dir = header_dir self.header_file = header_file - + if self.header_dir: self.header_dir = utils.normalize_path( self.header_dir ) if not os.path.isabs( self.header_dir ): raise RuntimeError( "Path to header directory should be absolute!" ) - + if self.header_file: self.header_file = utils.normalize_path( self.header_file ) if not os.path.isabs( self.header_file ): @@ -180,7 +185,7 @@ self.__opt_is_full_name = False self.__decl_name_only = self.__name - + name = property( _get_name, _set_name ) def __str__( self ): @@ -196,7 +201,7 @@ if not msg: msg.append( 'any' ) return ' and '.join( msg ) - + def __call__( self, decl ): if not None is self.decl_type: if not isinstance( decl, self.decl_type ): @@ -218,7 +223,7 @@ def check_name( self, decl ): assert not None is self.name - + if self.__opt_is_tmpl_inst: if not self.__opt_is_full_name: if self.name != decl.name: @@ -234,20 +239,20 @@ if self.name != algorithm.full_name( decl ): return False return True - + def is_full_name(self): return self.__opt_is_full_name - + def _get_decl_name_only(self): return self.__decl_name_only decl_name_only = property( _get_decl_name_only ) - + class variable_matcher_t( declaration_matcher_t ): """ Instance of this class will match variables by next criteria: - L{declaration_matcher_t} criteria - variable type. Example: L{int_t} or 'int' - """ + """ def __init__( self, name=None, type=None, header_dir=None, header_file=None ): """ @param type: variable type @@ -259,7 +264,7 @@ , header_dir=header_dir , header_file=header_file ) self.type = type - + def __call__( self, decl ): if not super( variable_matcher_t, self ).__call__( decl ): return False @@ -288,7 +293,7 @@ def __init__( self, name=None ): declaration_matcher_t.__init__( self, name=name, decl_type=namespace.namespace_t) - + def __call__( self, decl ): if self.name and decl.name == '': #unnamed namespace have same name as thier parent, we should prevent @@ -296,15 +301,15 @@ #directly. return False return super( namespace_matcher_t, self ).__call__( decl ) - + class calldef_matcher_t( declaration_matcher_t ): """ Instance of this class will match callable by next criteria: - L{declaration_matcher_t} criteria - return type. Example: L{int_t} or 'int' - argument types - """ + """ def __init__( self, name=None, return_type=None, arg_types=None, decl_type=None, header_dir=None, header_file=None): """ @@ -312,9 +317,9 @@ @type return_type: string or instance of L{type_t} derived class @param arg_types: list of function argument types. arg_types can contain. - Any item within the list could be string or instance of L{type_t} derived - class. If you don't want some argument to participate in match you can - put None. For example: + Any item within the list could be string or instance of L{type_t} derived + class. If you don't want some argument to participate in match you can + put None. For example: C{ calldef_matcher_t( arg_types=[ 'int &', None ] ) } @@ -332,7 +337,7 @@ self.return_type = return_type self.arg_types = arg_types - + def __call__( self, decl ): if not super( calldef_matcher_t, self ).__call__( decl ): return False @@ -385,7 +390,7 @@ Instance of this class will match operators by next criteria: - L{calldef_matcher_t} criteria - operator symbol: =, !=, (), [] and etc - """ + """ def __init__( self, name=None, symbol=None, return_type=None, arg_types=None, decl_type=None, header_dir=None, header_file=None): """ @param symbol: operator symbol @@ -401,15 +406,15 @@ , header_dir=header_dir , header_file=header_file) self.symbol = symbol - + def __call__( self, decl ): if not super( operator_matcher_t, self ).__call__( decl ): return False - if not None is self.symbol: + if not None is self.symbol: if self.symbol != decl.symbol: return False return True - + def __str__( self ): msg = [ super( operator_matcher_t, self ).__str__() ] if msg == [ 'any' ]: @@ -418,45 +423,45 @@ msg.append( '(symbol==%s)' % str(self.symbol) ) if not msg: msg.append( 'any' ) - return ' and '.join( msg ) - + return ' and '.join( msg ) + class regex_matcher_t( matcher_base_t ): """ Instance of this class will match declaration using regular expression. - User should supply a function that will extract from declaration desired - information as string. Later, this matcher will match that string using + User should supply a function that will extract from declaration desired + information as string. Later, this matcher will match that string using user regular expression. - """ + """ def __init__( self, regex, function=None ): """ @param regex: regular expression @type regex: string, an instance of this class will compile it for you - + @param function: function that will be called to get an information from declaration as string. As input this function takes 1 argument: reference to declaration. Return value should be string. If function is None, then the matcher will use declaration name. - + """ matcher_base_t.__init__(self) self.regex = re.compile( regex ) self.function = function if None is self.function: self.function = lambda decl: decl.name - + def __call__( self, decl ): text = self.function( decl ) return bool( self.regex.match( text ) ) - + def __str__( self ): return '(regex=%s)' % self.regex - + class access_type_matcher_t( matcher_base_t ): """ - Instance of this class will match declaration by its access type: public, + Instance of this class will match declaration by its access type: public, private or protected. If declarations does not have access type, for example free function, then False will be returned. - """ + """ def __init__( self, access_type ): """ @@ -466,21 +471,21 @@ """ matcher_base_t.__init__( self ) self.access_type = access_type - + def __call__( self, decl ): if not isinstance( decl.parent, class_declaration.class_t ): return False return self.access_type == decl.parent.find_out_member_access_type( decl ) - + def __str__( self ): return '(access type=%s)' % self.access_type class virtuality_type_matcher_t( matcher_base_t ): """ - Instance of this class will match declaration by its virtuality type: not virtual, + Instance of this class will match declaration by its virtuality type: not virtual, virtual or pure virtual. If declarations does not have virtuality type, for example free function, then False will be returned. - """ + """ def __init__( self, virtuality_type ): """ @@ -489,12 +494,12 @@ """ matcher_base_t.__init__( self ) self.virtuality_type = virtuality_type - + def __call__( self, decl ): if not isinstance( decl.parent, class_declaration.class_t ): return False return self.virtuality_type == decl.virtuality - + def __str__( self ): return '(virtuality type=%s)' % self.virtuality_type @@ -502,7 +507,7 @@ class custom_matcher_t( matcher_base_t ): """ Instance of this class will match declaration by user custom criteria. - """ + """ def __init__( self, function ): """ @@ -511,10 +516,9 @@ """ matcher_base_t.__init__( self ) self.function = function - + def __call__( self, decl ): return bool( self.function( decl ) ) - + def __str__( self ): return '(user criteria)' - \ No newline at end of file Modified: pygccxml_dev/pygccxml/declarations/typedef.py =================================================================== --- pygccxml_dev/pygccxml/declarations/typedef.py 2006-08-20 07:45:50 UTC (rev 423) +++ pygccxml_dev/pygccxml/declarations/typedef.py 2006-08-20 14:16:39 UTC (rev 424) @@ -3,16 +3,22 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +""" +defines class that describes C++ typedef declaration +""" + import declaration class typedef_t( declaration.declaration_t ): + """describes C++ typedef declaration""" + def __init__( self, name='', parent=None, type=None ): declaration.declaration_t.__init__( self, name, parent ) self._type = type def _get__cmp__items( self ): return [self.type] - + def __eq__(self, other): if not declaration.declaration_t.__eq__( self, other ): return False @@ -22,4 +28,5 @@ return self._type def _set_type(self, type): self._type = type - type = property( _get_type, _set_type ) \ No newline at end of file + type = property( _get_type, _set_type + , doc="reference to the original L{type<type_t>}" ) Modified: pygccxml_dev/pygccxml/declarations/variable.py =================================================================== --- pygccxml_dev/pygccxml/declarations/variable.py 2006-08-20 07:45:50 UTC (rev 423) +++ pygccxml_dev/pygccxml/declarations/variable.py 2006-08-20 14:16:39 UTC (rev 424) @@ -3,16 +3,17 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -import declaration +""" +defines class that describes C++ global and member variable declaration +""" +import declaration + class variable_t( declaration.declaration_t ): - def __init__( self - , name='' - , parent=None - , type=None - , type_qualifiers=None - , value=None - , bits=None): + """describes C++ global and member variable declaration""" + + def __init__( self, name='', parent=None, type=None, type_qualifiers=None, value=None, bits=None): + """@undocumented:""" declaration.declaration_t.__init__( self, name, parent ) self._type = type self._type_qualifiers = type_qualifiers @@ -20,9 +21,11 @@ self._bits = bits def _get__cmp__items( self ): + """@undocumented _get__cmp__items:""" return [ self.type, self.type_qualifiers, self.value ] - + def __eq__(self, other): + """@undocumented __eq__:""" if not declaration.declaration_t.__eq__( self, other ): return False return self.type == other.type \ @@ -34,22 +37,26 @@ return self._type def _set_type(self, type): self._type = type - type = property( _get_type, _set_type ) + type = property( _get_type, _set_type + , doc="reference to the variable L{type<type_t>}" ) def _get_type_qualifiers(self): return self._type_qualifiers def _set_type_qualifiers(self, type_qualifiers): self._type_qualifiers = type_qualifiers - type_qualifiers = property( _get_type_qualifiers, _set_type_qualifiers ) + type_qualifiers = property( _get_type_qualifiers, _set_type_qualifiers + , doc="reference to the L{type_qualifiers_t} instance" ) def _get_value(self): return self._value def _set_value(self, value): self._value = value - value = property( _get_value, _set_value ) + value = property( _get_value, _set_value + , doc="string, that contains the variable value" ) def _get_bits(self): return self._bits def _set_bits(self, bits): self._bits = bits - bits = property( _get_bits, _set_bits ) \ No newline at end of file + bits = property( _get_bits, _set_bits + , doc="int, that contains information how many bit takes bit field") Modified: pygccxml_dev/setup.py =================================================================== --- pygccxml_dev/setup.py 2006-08-20 07:45:50 UTC (rev 423) +++ pygccxml_dev/setup.py 2006-08-20 14:16:39 UTC (rev 424) @@ -13,7 +13,7 @@ """Generate the epydoc reference manual. """ print "Generating epydoc files..." - + from epydoc.docbuilder import build_doc_index from epydoc.docwriter.html import HTMLWriter @@ -21,12 +21,12 @@ html_writer = HTMLWriter( docindex , prj_name='pygccxml' , prj_url='http://www.language-binding.net' - , include_sourcecode=False #This will decrease the size of generated documentation + , include_source_code=False #This will decrease the size of generated documentation , show_private=False , show_frames=False) - + html_writer.write( os.path.join('docs', 'apidocs') ) - + class doc_cmd(Command): """This is a new distutils command 'doc' to build the epydoc manual. """ @@ -37,10 +37,10 @@ def initialize_options (self): self.no_doc = 0 - + def finalize_options (self): pass - + def run(self): if self.no_doc: return @@ -63,4 +63,4 @@ 'pygccxml.parser', 'pygccxml.utils' ], cmdclass = {"doc" : doc_cmd} -) \ No newline at end of file +) Modified: pyplusplus_dev/setup.py =================================================================== --- pyplusplus_dev/setup.py 2006-08-20 07:45:50 UTC (rev 423) +++ pyplusplus_dev/setup.py 2006-08-20 14:16:39 UTC (rev 424) @@ -34,30 +34,30 @@ + environment_var_delimiter \ + pygccxml_path print "Setting PYTHONPATH to", os.environ["PYTHONPATH"] - -def generate_doc(): + +def generate_doc(): """Generate the epydoc reference manual. """ if not pygccxml_available: print "Please install pygccxml before generating the docs." sys.exit() - + add_pygccxml_to_PYTHONPATH() from epydoc.docbuilder import build_doc_index from epydoc.docwriter.html import HTMLWriter - print "Generating epydoc files..." + print "Generating epydoc files..." docindex = build_doc_index(['Py++', 'pygccxml']) html_writer = HTMLWriter( docindex , prj_name='Py++' , prj_url='http://www.language-binding.net' - , include_sourcecode=False #This will decrease the size of generated documentation + , include_source_code=False #This will decrease the size of generated documentation , show_private=False , show_frames=False ) - + html_writer.write( os.path.join('docs', 'documentation', 'apidocs') ) @@ -71,10 +71,10 @@ def initialize_options (self): self.no_doc = 0 - + def finalize_options (self): pass - + def run(self): if self.no_doc: return @@ -105,4 +105,4 @@ 'pyplusplus.utils', 'pyplusplus._logging_'], cmdclass = {"doc" : doc_cmd} -) \ No newline at end of file +) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-20 07:46:03
|
Revision: 423 Author: roman_yakovenko Date: 2006-08-20 00:45:50 -0700 (Sun, 20 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=423&view=rev Log Message: ----------- update autoconfig.py to use new pydsc API Modified Paths: -------------- pygccxml_dev/unittests/autoconfig.py pyplusplus_dev/unittests/autoconfig.py Modified: pygccxml_dev/unittests/autoconfig.py =================================================================== --- pygccxml_dev/unittests/autoconfig.py 2006-08-20 07:24:03 UTC (rev 422) +++ pygccxml_dev/unittests/autoconfig.py 2006-08-20 07:45:50 UTC (rev 423) @@ -30,47 +30,44 @@ pygccxml.declarations.class_t.USE_DEMANGLED_AS_NAME = True -#try: - #import pydsc - ##test only pygccxml - #pydsc.doc_checker.filter.append( package_directory ) - #pydsc.doc_checker.filter_type = pydsc.FILTER_TYPE.INCLUDE - ## - #map( pydsc.doc_checker.speller.ignore_always - #, [ 'Yakovenko' - #, 'Bierbaum' - #, 'org' - #, 'http' - #, 'bool' - #, 'str' - #, 'www' - #, 'param' - #, 'txt' - #, 'decl' - #, 'decls' - #, 'namespace' - #, 'namespaces' - #, 'enum' - #, 'const' - #, 'GCC' - #, 'xcc' - #, 'TODO' - #, 'typedef' - #, 'os' - #, 'normcase' - #, 'normpath' - #, 'scopedef' - #, 'ira'#part of Matthias mail address - #, 'uka'#part of Matthias mail address - #, 'de'#part of Matthias mail address - #, 'dat'#file extension of directory cache - #, 'config'#parameter description - #, 'gccxml'#parameter description - #, 'Py++' - #, 'pygccxml' - #, 'calldef' - #, 'XXX' - #, 'wstring' - #] ) -#except ImportError: - #pass \ No newline at end of file +#~ try: + #~ import pydsc + #~ pydsc.include( r'D:\pygccxml_sources\sources\pygccxml_dev' ) + #~ pydsc.ignore( [ 'Yakovenko' + #~ , 'Bierbaum' + #~ , 'org' + #~ , 'http' + #~ , 'bool' + #~ , 'str' + #~ , 'www' + #~ , 'param' + #~ , 'txt' + #~ , 'decl' + #~ , 'decls' + #~ , 'namespace' + #~ , 'namespaces' + #~ , 'enum' + #~ , 'const' + #~ , 'GCC' + #~ , 'xcc' + #~ , 'TODO' + #~ , 'typedef' + #~ , 'os' + #~ , 'normcase' + #~ , 'normpath' + #~ , 'scopedef' + #~ , 'ira'#part of Matthias mail address + #~ , 'uka'#part of Matthias mail address + #~ , 'de'#part of Matthias mail address + #~ , 'dat'#file extension of directory cache + #~ , 'config'#parameter description + #~ , 'gccxml'#parameter description + #~ , 'Py++' + #~ , 'pygccxml' + #~ , 'calldef' + #~ , 'XXX' + #~ , 'wstring' + #~ , 'py' + #~ ] ) +#~ except ImportError: + #~ pass Modified: pyplusplus_dev/unittests/autoconfig.py =================================================================== --- pyplusplus_dev/unittests/autoconfig.py 2006-08-20 07:24:03 UTC (rev 422) +++ pyplusplus_dev/unittests/autoconfig.py 2006-08-20 07:45:50 UTC (rev 423) @@ -21,9 +21,9 @@ class scons_config: libs = ['boost_python'] libpath = [ boost.libs, python.libs ] - cpppath = [ boost.include, python.include ] + cpppath = [ boost.include, python.include ] include_dirs = cpppath + [data_directory] - + @staticmethod def create_sconstruct(): code = [ @@ -37,19 +37,62 @@ , " , SHLIBSUFFIX='%s'" % scons.suffix #explicit better then implicit , ")" ] return os.linesep.join( code ) - -#I need this in order to allow Python to load just compiled modules + +#I need this in order to allow Python to load just compiled modules sys.path.append( build_dir ) os.chdir( build_dir ) -if sys.platform == 'linux2': +if sys.platform == 'linux2': LD_LIBRARY_PATH = 'LD_LIBRARY_PATH' if not os.environ.has_key( LD_LIBRARY_PATH ) \ or not set( scons_config.libpath ).issubset( set( os.environ[LD_LIBRARY_PATH].split(':') ) ): #see http://hathawaymix.org/Weblog/2004-12-30 print 'error: LD_LIBRARY_PATH has not been set' -else: +else: PATH = os.environ.get( 'PATH', '' ) PATH=PATH + ';' + ';'.join( scons_config.libpath ) - os.environ['PATH'] = PATH \ No newline at end of file + os.environ['PATH'] = PATH + + +#~ try: + #~ import pydsc + #~ pydsc.include( r'D:\pygccxml_sources\sources\pyplusplus_dev' ) + #~ pydsc.ignore( [ 'Yakovenko' + #~ , 'Bierbaum' + #~ , 'org' + #~ , 'http' + #~ , 'bool' + #~ , 'str' + #~ , 'www' + #~ , 'param' + #~ , 'txt' + #~ , 'decl' + #~ , 'decls' + #~ , 'namespace' + #~ , 'namespaces' + #~ , 'enum' + #~ , 'const' + #~ , 'GCC' + #~ , 'xcc' + #~ , 'TODO' + #~ , 'typedef' + #~ , 'os' + #~ , 'normcase' + #~ , 'normpath' + #~ , 'scopedef' + #~ , 'ira'#part of Matthias mail address + #~ , 'uka'#part of Matthias mail address + #~ , 'de'#part of Matthias mail address + #~ , 'dat'#file extension of directory cache + #~ , 'config'#parameter description + #~ , 'gccxml'#parameter description + #~ , 'Py++' + #~ , 'pygccxml' + #~ , 'calldef' + #~ , 'XXX' + #~ , 'wstring' + #~ , 'py' + #~ ] ) +#~ except ImportError: + #~ pass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-20 07:24:11
|
Revision: 422 Author: roman_yakovenko Date: 2006-08-20 00:24:03 -0700 (Sun, 20 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=422&view=rev Log Message: ----------- fixing bug: value traits should be declared only once Modified Paths: -------------- pyplusplus_dev/pyplusplus/module_creator/creator.py Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-08-20 06:31:37 UTC (rev 421) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-08-20 07:24:03 UTC (rev 422) @@ -5,7 +5,7 @@ import types_database import class_organizer -import call_policies_resolver +import call_policies_resolver from pygccxml import declarations from pyplusplus import decl_wrappers from pyplusplus import code_creators @@ -26,9 +26,9 @@ # }; #}; -INDEXING_SUITE_1_CONTAINERS = { - 'vector<' : "boost/python/suite/indexing/vector_indexing_suite.hpp" - , 'map<' : "boost/python/suite/indexing/map_indexing_suite.hpp" +INDEXING_SUITE_1_CONTAINERS = { + 'vector<' : "boost/python/suite/indexing/vector_indexing_suite.hpp" + , 'map<' : "boost/python/suite/indexing/map_indexing_suite.hpp" } INDEXING_SUITE_2_CONTAINERS = { @@ -59,7 +59,7 @@ creator tree whose root node is a L{module_t<code_creators.module_t>} object representing the source code for the entire extension module. """ - + def __init__( self , decls , module_name @@ -89,10 +89,10 @@ @type target_configuration: L{target_configuration_t<code_creators.target_configuration_t>} @type doc_extractor: callable """ - declarations.decl_visitor_t.__init__(self) + declarations.decl_visitor_t.__init__(self) self.logger = _logging_.loggers.module_builder self.decl_logger = _logging_.loggers.declarations - + self.__enable_indexing_suite = enable_indexing_suite self.__target_configuration = target_configuration if not self.__target_configuration: @@ -106,28 +106,28 @@ self.__types_db = types_db if not self.__types_db: self.__types_db = types_database.types_database_t() - - self.__extmodule = code_creators.module_t() + + self.__extmodule = code_creators.module_t() self.__extmodule.add_system_header( "boost/python.hpp" ) self.__extmodule.adopt_creator( code_creators.include_t( header="boost/python.hpp" ) ) self.__create_castinig_constructor = create_castinig_constructor if boost_python_ns_name: bp_ns_alias = code_creators.namespace_alias_t( alias=boost_python_ns_name - , full_namespace_name='::boost::python' ) + , full_namespace_name='::boost::python' ) self.__extmodule.adopt_creator( bp_ns_alias ) - + self.__module_body = code_creators.module_body_t( name=module_name ) - self.__extmodule.adopt_creator( self.__module_body ) - + 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.curr_code_creator = self.__module_body self.curr_decl = None self.__cr_array_1_included = False self.__array_1_registered = set() #(type.decl_string,size) self.__free_operators = [] - + def _prepare_decls( self, decls, doc_extractor ): global DO_NOT_REPORT_MSGS @@ -136,37 +136,37 @@ for decl in decls: if decl.ignore: continue - + if doc_extractor and decl.exportable: decl.documentation = doc_extractor( decl ) readme = decl.readme() if not readme: continue - + if not decl.exportable: reason = readme[0] if reason in DO_NOT_REPORT_MSGS: continue readme = readme[1:] self.decl_logger.warn( "%s;%s" % ( decl, reason ) ) - + 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 ) , decls ) #leave only decls that user wants to export and that could be exported decls = filter( lambda x: x.ignore == False and x.exportable == True, decls ) - + return decls def _reorder_decls(self, decls ): classes = filter( lambda x: isinstance( x, declarations.class_t ) , decls ) - + ordered = class_organizer.findout_desired_order( classes ) ids = set( [ id( inst ) for inst in ordered ] ) for decl in decls: @@ -191,14 +191,14 @@ else: others.append( inst ) #this will prevent from py++ to change the order of generated code - cmp_by_name = lambda d1, d2: cmp( d1.name, d2.name ) - cmp_by_line = lambda d1, d2: cmp( d1.location.line, d2.location.line ) + cmp_by_name = lambda d1, d2: cmp( d1.name, d2.name ) + cmp_by_line = lambda d1, d2: cmp( d1.location.line, d2.location.line ) enums.sort( cmp=cmp_by_name ) others.sort( cmp=cmp_by_name ) variables.sort( cmp=cmp_by_name ) constructors.sort( cmp=cmp_by_line ) - + new_ordered = [] new_ordered.extend( enums ) new_ordered.extend( classes ) @@ -206,7 +206,7 @@ new_ordered.extend( others ) 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 ) @@ -217,13 +217,13 @@ continue else: members.append( member ) - + vfunction_selector = lambda member: isinstance( member, declarations.member_function_t ) \ - and member.virtuality == VIRTUALITY_TYPES.PURE_VIRTUAL + 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 + or decl.access_type == ACCESS_TYPES.PUBLIC , members ) #-#if declarations.has_destructor( class_decl ) \ #-# and not declarations.has_public_destructor( class_decl ): @@ -234,18 +234,18 @@ 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 _is_constructor_of_abstract_class( self, decl ): assert isinstance( decl, declarations.constructor_t ) return decl.parent.is_abstract - + 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 + decls = filter( lambda x: not (x.is_artificial and not (isinstance(x, ( declarations.class_t, declarations.enumeration_t)))) , decls ) # Filter out type defs @@ -268,18 +268,18 @@ if f1_arg.type != f2_arg.type: return False return True - + def redefined_funcs( self, cls ): all_included = declarations.custom_matcher_t( lambda decl: decl.ignore == False and decl.exportable ) all_protected = declarations.access_type_matcher_t( 'protected' ) & all_included all_pure_virtual = declarations.virtuality_type_matcher_t( VIRTUALITY_TYPES.PURE_VIRTUAL ) all_not_pure_virtual = ~all_pure_virtual - + query = all_protected | all_pure_virtual - + funcs = set() defined_funcs = set() - + for base in cls.recursive_bases: if base.access == ACCESS_TYPES.PRIVATE: continue @@ -290,7 +290,7 @@ defined_funcs.update( base_cls.member_functions( all_not_pure_virtual, allow_empty=True ) ) defined_funcs.update( base_cls.member_operators( all_not_pure_virtual, allow_empty=True ) ) - not_reimplemented_funcs = set() + not_reimplemented_funcs = set() for f in funcs: cls_fs = cls.calldefs( name=f.name, recursive=False, allow_empty=True ) for cls_f in cls_fs: @@ -315,7 +315,7 @@ functions.sort( cmp=lambda f1, f2: cmp( ( f1.name, f1.location.as_tuple() ) , ( f2.name, f2.location.as_tuple() ) ) ) return functions - + def _is_wrapper_needed(self, class_inst, exportable_members): if isinstance( self.curr_decl, declarations.class_t ) \ and self.curr_decl.wrapper_code: @@ -325,7 +325,7 @@ return True else: pass - + for member in exportable_members: if isinstance( member, declarations.destructor_t ): continue @@ -346,12 +346,12 @@ if member.access_type in ( ACCESS_TYPES.PROTECTED, ACCESS_TYPES.PRIVATE ): return True #we already decided that those functions should be exposed, so I need wrapper for them return bool( self.redefined_funcs(class_inst) ) - + def _adopt_free_operator( self, operator ): def adopt_operator_impl( operator, found_creators ): creator = filter( lambda creator: isinstance( creator, code_creators.class_t ) , found_creators ) - if len(creator) == 1: + if len(creator) == 1: creator = creator[0] #I think I don't need this condition any more if not find( lambda creator: isinstance( creator, code_creators.declaration_based_t ) @@ -392,7 +392,7 @@ return True else: assert not "unknown instace of registrator: " % str( registered ) - + def _treat_smart_pointers( self ): """ Go to all class creators and apply held_type and creator registrators as needed. @@ -411,7 +411,7 @@ if not self._is_registered_smart_pointer_creator( r, registrators_db ): creator.adopt_creator(r) registrators_db.append(r) - + def _append_user_code( self ): find_classes = code_creators.creator_finder.find_by_class_instance class_creators = find_classes( what=code_creators.class_t @@ -422,29 +422,29 @@ for cls_creator in class_creators: cls_decl = cls_creator.declaration #uc = user code - uc_creators = map( lambda uc: ctext_t( uc.text, uc.works_on_instance ) + uc_creators = map( lambda uc: ctext_t( uc.text, uc.works_on_instance ) , cls_decl.registration_code ) cls_creator.adopt_creators( uc_creators ) - + uc_creators = map( lambda uc: ctext_t( uc.text ), cls_decl.wrapper_code ) if uc_creators: cls_creator.wrapper.adopt_creators( uc_creators ) - + uc_creators = map( lambda uc: ctext_t( uc.text ), cls_decl.declaration_code ) insert_pos = self.__extmodule.creators.index( self.__module_body ) self.__extmodule.adopt_creators( uc_creators, insert_pos ) cls_creator.user_declarations.extend( uc_creators ) - + def _treat_indexing_suite( self ): global INDEXING_SUITE_1_CONTAINERS global INDEXING_SUITE_2_CONTAINERS global INDEXING_SUITE_2_MAIN_HEADER - + def create_explanation(cls): msg = '//WARNING: the next line of code will not compile, because "%s" does not have operator== !' msg = msg % cls.indexing_suite.element_type.decl_string return code_creators.custom_text_t( msg, False ) - + def create_cls_cc( cls ): if isinstance( cls, declarations.class_t ): return code_creators.class_t( class_inst=cls ) @@ -452,12 +452,13 @@ return code_creators.class_declaration_t( class_inst=cls ) if not self.__types_db.used_containers: - return - + return + used_headers = set() creators = [] - + created_value_traits = set() + cmp_by_name = lambda cls1, cls2: cmp( cls1.decl_string, cls2.decl_string ) used_containers = list( self.__types_db.used_containers ) used_containers.sort( cmp_by_name ) @@ -471,9 +472,9 @@ if not isuite.has_key( container_name ): continue #not supported - + if isuite is INDEXING_SUITE_2_CONTAINERS: - used_headers.add( INDEXING_SUITE_2_MAIN_HEADER ) + used_headers.add( INDEXING_SUITE_2_MAIN_HEADER ) used_headers.add( isuite[ container_name ] ) @@ -487,15 +488,16 @@ if not ( None is element_type ) \ and declarations.is_class( element_type ) \ and not declarations.has_public_equal( element_type ): - cls_creator.adopt_creator( create_explanation( cls ) ) + cls_creator.adopt_creator( create_explanation( cls ) ) cls_creator.adopt_creator( code_creators.indexing_suite1_t(cls) ) else: class_traits = declarations.class_traits - if not ( None is element_type ) \ - and class_traits.is_my_case( element_type ): + if not ( None is element_type ) and class_traits.is_my_case( element_type ): value_cls = class_traits.get_declaration( element_type ) - element_type_cc = code_creators.value_traits_t( value_cls ) - self.__extmodule.adopt_declaration_creator( element_type_cc ) + if value_cls not in created_value_traits: + created_value_traits.add( value_cls ) + element_type_cc = code_creators.value_traits_t( value_cls ) + self.__extmodule.adopt_declaration_creator( element_type_cc ) cls_creator.adopt_creator( code_creators.indexing_suite2_t(cls) ) if INDEXING_SUITE_2_MAIN_HEADER in used_headers: @@ -503,11 +505,11 @@ used_headers.remove( INDEXING_SUITE_2_MAIN_HEADER ) self.__extmodule.add_system_header( INDEXING_SUITE_2_MAIN_HEADER ) self.__extmodule.add_include( INDEXING_SUITE_2_MAIN_HEADER ) - + for header in used_headers: self.__extmodule.add_system_header( header ) self.__extmodule.add_include( header ) - + #I am going tp find last class registration and to add all container creators #after it. last_cls_index = -1 @@ -519,10 +521,10 @@ creators.reverse() for creator in creators: self.__module_body.adopt_creator( creator, insert_position ) - + def create(self, decl_headers=None): """Create and return the module for the extension. - + @param decl_headers: If None the headers for the wrapped decls are automatically found. But you can pass a list of headers here to override that search. @returns: Returns the root of the code creators tree @@ -592,42 +594,42 @@ fwrapper_cls = code_creators.mem_fun_v_wrapper_t maker_cls = code_creators.mem_fun_v_t return ( maker_cls, fwrapper_cls ) - + def visit_member_function( self ): fwrapper = None self.__types_db.update( self.curr_decl ) if None is self.curr_decl.call_policies: self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl ) - + maker_cls, fwrapper_cls = self.guess_functions_code_creators() - + maker = None fwrapper = None if fwrapper_cls: fwrapper = fwrapper_cls( function=self.curr_decl ) class_wrapper = self.curr_code_creator.wrapper class_wrapper.adopt_creator( fwrapper ) - + if maker_cls: if fwrapper: maker = maker_cls( function=self.curr_decl, wrapper=fwrapper ) else: maker = maker_cls( function=self.curr_decl ) - self.curr_code_creator.adopt_creator( maker ) - + self.curr_code_creator.adopt_creator( maker ) + if self.curr_decl.has_static: #static_method should be created only once. - found = filter( lambda creator: isinstance( creator, code_creators.static_method_t ) + found = filter( lambda creator: isinstance( creator, code_creators.static_method_t ) and creator.declaration.name == self.curr_decl.name , self.curr_code_creator.creators ) if not found: static_method = code_creators.static_method_t( function=self.curr_decl , function_code_creator=maker ) self.curr_code_creator.adopt_creator( static_method ) - + def visit_constructor( self ): if self.curr_decl.is_copy_constructor: - return + return self.__types_db.update( self.curr_decl ) if not self._is_constructor_of_abstract_class( self.curr_decl ) \ and 1 == len( self.curr_decl.arguments ) \ @@ -646,10 +648,10 @@ if None is self.curr_decl.call_policies: self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl ) self.curr_code_creator.adopt_creator( maker ) - + def visit_destructor( self ): pass - + def visit_member_operator( self ): if self.curr_decl.symbol in ( '()', '[]' ): self.visit_member_function() @@ -657,32 +659,32 @@ self.__types_db.update( self.curr_decl ) maker = code_creators.operator_t( operator=self.curr_decl ) self.curr_code_creator.adopt_creator( maker ) - + def visit_casting_operator( self ): if not declarations.is_fundamental( self.curr_decl.return_type ) \ and not self.curr_decl.has_const: return #only const casting operators can generate implicitly_convertible - + if None is self.curr_decl.call_policies: self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl ) - + self.__types_db.update( self.curr_decl ) if not self.curr_decl.parent.is_abstract \ and not declarations.is_reference( self.curr_decl.return_type ): maker = code_creators.casting_operator_t( operator=self.curr_decl ) - self.__module_body.adopt_creator( maker ) + self.__module_body.adopt_creator( maker ) #what to do if class is abstract if self.curr_decl.access_type == ACCESS_TYPES.PUBLIC: maker = code_creators.casting_member_operator_t( operator=self.curr_decl ) self.curr_code_creator.adopt_creator( maker ) - + def visit_free_function( self ): self.__types_db.update( self.curr_decl ) maker = code_creators.free_function_t( function=self.curr_decl ) if None is self.curr_decl.call_policies: - self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl ) + self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl ) self.curr_code_creator.adopt_creator( maker ) - + def visit_free_operator( self ): self.__types_db.update( self.curr_decl ) self.__free_operators.append( self.curr_decl ) @@ -692,8 +694,8 @@ def visit_class(self ): assert isinstance( self.curr_decl, declarations.class_t ) - temp_curr_decl = self.curr_decl - temp_curr_parent = self.curr_code_creator + temp_curr_decl = self.curr_decl + temp_curr_parent = self.curr_code_creator exportable_members = self._exportable_class_members(self.curr_decl) wrapper = None @@ -703,7 +705,7 @@ wrapper = code_creators.class_wrapper_t( declaration=self.curr_decl , class_creator=class_inst ) class_inst.wrapper = wrapper - #insert wrapper before module body + #insert wrapper before module body if isinstance( self.curr_decl.parent, declarations.class_t ): #we deal with internal class self.curr_code_creator.wrapper.adopt_creator( wrapper ) @@ -714,13 +716,13 @@ #to construct wrapper from wrapped classe if not self.curr_decl.noncopyable: copy_constr = code_creators.copy_constructor_wrapper_t( class_inst=self.curr_decl ) - wrapper.adopt_creator( copy_constr ) + wrapper.adopt_creator( copy_constr ) null_constr = declarations.find_trivial_constructor(self.curr_decl) if null_constr and null_constr.is_artificial: #this constructor is not going to be exposed tcons = code_creators.null_constructor_wrapper_t( class_inst=self.curr_decl ) - wrapper.adopt_creator( tcons ) - + wrapper.adopt_creator( tcons ) + self.curr_code_creator.adopt_creator( class_inst ) self.curr_code_creator = class_inst for decl in exportable_members: @@ -740,10 +742,10 @@ for static_method in static_methods: class_inst.remove_creator( static_method ) class_inst.adopt_creator( static_method ) - - self.curr_decl = temp_curr_decl + + self.curr_decl = temp_curr_decl self.curr_code_creator = temp_curr_parent - + def visit_enumeration(self): assert isinstance( self.curr_decl, declarations.enumeration_t ) maker = None @@ -752,7 +754,7 @@ else: maker = code_creators.unnamed_enum_t( unnamed_enum=self.curr_decl ) self.curr_code_creator.adopt_creator( maker ) - + def visit_namespace(self): pass @@ -765,11 +767,11 @@ return False else: self.__array_1_registered.add( data ) - return True - + return True + def visit_variable(self): self.__types_db.update( self.curr_decl ) - + if declarations.is_array( self.curr_decl.type ): if not self.__cr_array_1_included: self.__extmodule.add_system_header( code_repository.array_1.file_name ) @@ -779,7 +781,7 @@ if self._register_array_1( self.curr_decl.type ): array_1_registrator = code_creators.array_1_registrator_t( array_type=self.curr_decl.type ) self.curr_code_creator.adopt_creator( array_1_registrator ) - + if isinstance( self.curr_decl.parent, declarations.namespace_t ): maker = None wrapper = None @@ -808,9 +810,9 @@ if None is self.curr_decl.setter_call_policies: self.curr_decl.setter_call_policies = self.__call_policies_resolver( self.curr_decl, 'set' ) wrapper = code_creators.mem_var_ref_wrapper_t( variable=self.curr_decl ) - maker = code_creators.mem_var_ref_t( variable=self.curr_decl, wrapper=wrapper ) + maker = code_creators.mem_var_ref_t( variable=self.curr_decl, wrapper=wrapper ) else: - maker = code_creators.member_variable_t( variable=self.curr_decl ) + maker = code_creators.member_variable_t( variable=self.curr_decl ) if wrapper: self.curr_code_creator.wrapper.adopt_creator( wrapper ) - self.curr_code_creator.adopt_creator( maker ) \ No newline at end of file + self.curr_code_creator.adopt_creator( maker ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-20 06:31:43
|
Revision: 421 Author: roman_yakovenko Date: 2006-08-19 23:31:37 -0700 (Sat, 19 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=421&view=rev Log Message: ----------- removing enums work around. This work around caused some API to be non-callable. Next version will contain better work around for Boost.Python dependency problem Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/calldef.py Modified: pyplusplus_dev/pyplusplus/code_creators/calldef.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/calldef.py 2006-08-20 06:29:43 UTC (rev 420) +++ pyplusplus_dev/pyplusplus/code_creators/calldef.py 2006-08-20 06:31:37 UTC (rev 421) @@ -10,8 +10,8 @@ from pygccxml import declarations #virtual functions that returns const reference to something -#could not be overriden by Python. The reason is simple: -#in boost::python::override::operator(...) result of marshaling +#could not be overriden by Python. The reason is simple: +#in boost::python::override::operator(...) result of marshaling #(Python 2 C++) is saved on stack, after functions returns the result #will be reference to no where - access violetion. #For example see temporal variable tester @@ -21,19 +21,19 @@ #Add to docs: #public memebr functions - call, override, call base implementation #protected member functions - call, override -#private - override +#private - override class calldef_t( declaration_based.declaration_based_t): def __init__(self, function, wrapper=None ): declaration_based.declaration_based_t.__init__( self, declaration=function ) - self._wrapper = wrapper - + self._wrapper = wrapper + def _get_wrapper( self ): return self._wrapper def _set_wrapper( self, new_wrapper ): self._wrapper = new_wrapper wrapper = property( _get_wrapper, _set_wrapper ) - + def def_identifier( self ): return algorithm.create_identifier( self, '::boost::python::def' ) @@ -59,26 +59,22 @@ and declarations.is_integral( arg_type_no_alias ) \ and not arg.default_value.startswith( arg_type_no_alias.decl_string ): result.append( '=(%s)(%s)' % ( arg_type_no_alias.decl_string, arg.default_value ) ) - elif declarations.is_enum( arg.type ): - #Work around for bug/missing functionality in boost.python. - #registration order - result.append( '=(long)(%s)' % arg.default_value ) else: result.append( '=%s' % arg.default_value ) else: result.append( '=%s()' % boost_obj ) result.append( ' )' ) return ''.join( result ) - + def create_def_code( self ): if not self.works_on_instance: return '%s.def' % self.parent.class_var_name else: return 'def' - + def create_doc(self): return self.documentation - + def create_function_ref_code( self, use_function_alias=False ): raise NotImplementedError() @@ -92,10 +88,10 @@ def create_function_type_alias_code( self, exported_class_alias=None ): raise NotImplementedError() - - def _create_impl( self ): + + def _create_impl( self ): result = [] - + if not self.works_on_instance: exported_class_alias = None if declarations.templates.is_instantiation( self.declaration.parent.name ): @@ -104,7 +100,7 @@ result.append( os.linesep ) result.append( self.create_function_type_alias_code(exported_class_alias) ) result.append( os.linesep * 2 ) - + result.append( self.create_def_code() + '( ' ) result.append( os.linesep + self.indent( '"%s"' % self.alias ) ) @@ -112,24 +108,24 @@ result.append( self.create_function_ref_code( not self.works_on_instance ) ) if self.declaration.use_keywords: - result.append( self.param_sep() ) + result.append( self.param_sep() ) result.append( self.keywords_args() ) if self.declaration.call_policies: - result.append( self.param_sep() ) + result.append( self.param_sep() ) result.append( self.declaration.call_policies.create( self ) ) else: - result.append( os.linesep + self.indent( '/* undefined call policies */', 2 ) ) + result.append( os.linesep + self.indent( '/* undefined call policies */', 2 ) ) doc = self.create_doc() if doc: result.append( self.param_sep() ) result.append( doc ) - + result.append( ' )' ) if not self.works_on_instance: result.append( ';' ) - + if not self.works_on_instance: #indenting and adding scope code = ''.join( result ) @@ -138,11 +134,11 @@ result.append( self.indent( code ) ) result.append( os.linesep * 2 ) result.append( '}' ) - + return ''.join( result ) -class calldef_wrapper_t( declaration_based.declaration_based_t): +class calldef_wrapper_t( declaration_based.declaration_based_t): def __init__(self, function ): declaration_based.declaration_based_t.__init__( self, declaration=function ) @@ -163,7 +159,7 @@ if len( args ) == 1: return args[ 0 ] return ', '.join( args ) - + def override_identifier(self): return algorithm.create_identifier( self, '::boost::python::override' ) @@ -186,10 +182,10 @@ else: params.append( self.argument_name( index ) ) return ', '.join( params ) - + def wrapped_class_identifier( self ): return algorithm.create_identifier( self, declarations.full_name( self.declaration.parent ) ) - + def unoverriden_function_body( self ): msg = r'This function could not be overriden in Python!' msg = msg + 'Reason: function returns reference to local variable!' @@ -198,16 +194,16 @@ def throw_specifier_code( self ): if not self.declaration.exceptions: return '' - exceptions = map( lambda exception: + exceptions = map( lambda exception: algorithm.create_identifier( self, declarations.full_name( exception ) ) , self.declaration.exceptions ) return ' throw( ' + self.PARAM_SEPARATOR.join( exceptions ) + ' )' - -class free_function_t( calldef_t ): + +class free_function_t( calldef_t ): def __init__( self, function ): calldef_t.__init__( self, function=function ) self.works_on_instance = False - + def create_def_code( self ): return self.def_identifier() @@ -225,13 +221,13 @@ else: return '&%s' % declarations.full_name( self.declaration ) -class mem_fun_t( calldef_t ): +class mem_fun_t( calldef_t ): def __init__( self, function ): calldef_t.__init__( self, function=function ) - + def create_function_type_alias_code( self, exported_class_alias=None ): ftype = self.declaration.function_type() - return 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias ) + return 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias ) def create_function_ref_code(self, use_function_alias=False): if use_function_alias: @@ -245,13 +241,13 @@ return '&%s' % declarations.full_name( self.declaration ) -class mem_fun_pv_t( calldef_t ): +class mem_fun_pv_t( calldef_t ): def __init__( self, function, wrapper ): calldef_t.__init__( self, function=function, wrapper=wrapper ) - + def create_function_type_alias_code( self, exported_class_alias=None ): ftype = self.declaration.function_type() - return 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias ) + return 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias ) def create_function_ref_code(self, use_function_alias=False): if use_function_alias: @@ -273,20 +269,20 @@ def __init__( self, function ): calldef_wrapper_t.__init__( self, function=function ) - def create_declaration(self): + def create_declaration(self): template = 'virtual %(return_type)s %(name)s( %(args)s )%(constness)s%(throw)s' - + constness = '' if self.declaration.has_const: constness = ' const ' - + return template % { 'return_type' : self.declaration.return_type.decl_string , 'name' : self.declaration.name , 'args' : self.args_declaration() , 'constness' : constness , 'throw' : self.throw_specifier_code() - } + } def create_body( self ): if declarations.is_reference( self.declaration.return_type ): @@ -295,7 +291,7 @@ template.append( '%(override)s func_%(alias)s = this->get_override( "%(alias)s" );' ) template.append( '%(return_)sfunc_%(alias)s( %(args)s );') template = os.linesep.join( template ) - + return_ = '' if not declarations.is_void( self.declaration.return_type ): return_ = 'return ' @@ -306,21 +302,21 @@ , 'return_' : return_ , 'args' : self.function_call_args() } - + def _create_impl(self): answer = [ self.create_declaration() + '{' ] answer.append( self.indent( self.create_body() ) ) answer.append( '}' ) return os.linesep.join( answer ) -class mem_fun_v_t( calldef_t ): +class mem_fun_v_t( calldef_t ): def __init__( self, function, wrapper=None ): calldef_t.__init__( self, function=function, wrapper=wrapper ) self.default_function_type_alias = 'default_' + self.function_type_alias - + def create_function_type_alias_code( self, exported_class_alias=None ): result = [] - + ftype = self.declaration.function_type() result.append( 'typedef %s;' % ftype.create_typedef( self.function_type_alias, exported_class_alias ) ) if self.wrapper: @@ -331,7 +327,7 @@ def create_doc(self): return None - + def create_function_ref_code(self, use_function_alias=False): result = [] if use_function_alias: @@ -339,7 +335,7 @@ % ( self.function_type_alias, declarations.full_name( self.declaration ) ) ) if self.wrapper: result.append( self.param_sep() ) - result.append( '%s(&%s)' + result.append( '%s(&%s)' % ( self.default_function_type_alias, self.wrapper.default_full_name() ) ) elif self.declaration.create_with_signature: result.append( '(%s)(&%s)' @@ -347,7 +343,7 @@ , declarations.full_name( self.declaration ) ) ) if self.wrapper: result.append( self.param_sep() ) - result.append( '(%s)(&%s)' + result.append( '(%s)(&%s)' % ( self.wrapper.function_type().decl_string, self.wrapper.default_full_name() ) ) else: result.append( '&%s'% declarations.full_name( self.declaration ) ) @@ -362,25 +358,25 @@ def default_full_name(self): return self.parent.full_name + '::default_' + self.declaration.alias - - def function_type(self): + + def function_type(self): return declarations.member_function_type_t( return_type=self.declaration.return_type , class_inst=declarations.dummy_type_t( self.parent.full_name ) , arguments_types=map( lambda arg: arg.type, self.declaration.arguments ) , has_const=self.declaration.has_const ) - - def create_declaration(self, name, has_virtual=True): + + def create_declaration(self, name, has_virtual=True): template = '%(virtual)s%(return_type)s %(name)s( %(args)s )%(constness)s %(throw)s' virtual = 'virtual ' if not has_virtual: virtual = '' - + constness = '' if self.declaration.has_const: constness = ' const ' - + return template % { 'virtual' : virtual , 'return_type' : self.declaration.return_type.decl_string @@ -388,7 +384,7 @@ , 'args' : self.args_declaration() , 'constness' : constness , 'throw' : self.throw_specifier_code() - } + } def create_virtual_body(self): template = [] @@ -397,11 +393,11 @@ template.append( 'else' ) template.append( self.indent('%(return_)s%(wrapped_class)s::%(name)s( %(args)s );') ) template = os.linesep.join( template ) - + return_ = '' if not declarations.is_void( self.declaration.return_type ): return_ = 'return ' - + return template % { 'override' : self.override_identifier() , 'name' : self.declaration.name @@ -410,7 +406,7 @@ , 'args' : self.function_call_args() , 'wrapped_class' : self.wrapped_class_identifier() } - + def create_default_body(self): function_call = declarations.call_invocation.join( self.declaration.name , [ self.function_call_args() ] ) @@ -424,13 +420,13 @@ answer.append( self.indent( self.create_virtual_body() ) ) answer.append( '}' ) return os.linesep.join( answer ) - + def create_default_function( self ): answer = [ self.create_declaration('default_' + self.declaration.alias, False) + '{' ] answer.append( self.indent( self.create_default_body() ) ) answer.append( '}' ) - return os.linesep.join( answer ) - + return os.linesep.join( answer ) + def _create_impl(self): answer = [ self.create_function() ] answer.append( os.linesep ) @@ -438,10 +434,10 @@ return os.linesep.join( answer ) -class mem_fun_protected_t( calldef_t ): +class mem_fun_protected_t( calldef_t ): def __init__( self, function, wrapper ): calldef_t.__init__( self, function=function, wrapper=wrapper ) - + def create_function_type_alias_code( self, exported_class_alias=None ): ftype = self.wrapper.function_type() return 'typedef ' + ftype.create_typedef( self.function_type_alias ) + ';' @@ -462,28 +458,28 @@ def full_name(self): return '::'.join( [self.parent.full_name, self.declaration.name] ) - + def function_type(self): return declarations.member_function_type_t( return_type=self.declaration.return_type , class_inst=declarations.dummy_type_t( self.parent.full_name ) , arguments_types=map( lambda arg: arg.type, self.declaration.arguments ) , has_const=self.declaration.has_const ) - - def create_declaration(self, name): + + def create_declaration(self, name): template = '%(return_type)s %(name)s( %(args)s )%(constness)s%(throw)s' - + constness = '' if self.declaration.has_const: constness = ' const ' - + return template % { 'return_type' : self.declaration.return_type.decl_string , 'name' : name , 'args' : self.args_declaration() , 'constness' : constness , 'throw' : self.throw_specifier_code() - } + } def create_body(self): tmpl = '%(return_)s%(wrapped_class)s::%(name)s( %(args)s );' @@ -491,7 +487,7 @@ return_ = '' if not declarations.is_void( self.declaration.return_type ): return_ = 'return ' - + return tmpl % { 'name' : self.declaration.name , 'return_' : return_ @@ -503,14 +499,14 @@ answer = [ self.create_declaration(self.declaration.name) + '{' ] answer.append( self.indent( self.create_body() ) ) answer.append( '}' ) - return os.linesep.join( answer ) - + return os.linesep.join( answer ) + def _create_impl(self): return self.create_function() -class mem_fun_protected_s_t( calldef_t ): +class mem_fun_protected_s_t( calldef_t ): def __init__( self, function, wrapper ): calldef_t.__init__( self, function=function, wrapper=wrapper ) @@ -534,21 +530,21 @@ def full_name(self): return '::'.join( [self.parent.full_name, self.declaration.name] ) - + def function_type(self): return declarations.free_function_type_t( return_type=self.declaration.return_type , arguments_types=map( lambda arg: arg.type, self.declaration.arguments ) ) - - def create_declaration(self, name): + + def create_declaration(self, name): template = 'static %(return_type)s %(name)s( %(args)s )%(throw)s' - + return template % { 'return_type' : self.declaration.return_type.decl_string , 'name' : name , 'args' : self.args_declaration() , 'throw' : self.throw_specifier_code() - } + } def create_body(self): tmpl = '%(return_)s%(wrapped_class)s::%(name)s( %(args)s );' @@ -556,7 +552,7 @@ return_ = '' if not declarations.is_void( self.declaration.return_type ): return_ = 'return ' - + return tmpl % { 'name' : self.declaration.name , 'return_' : return_ @@ -568,12 +564,12 @@ answer = [ self.create_declaration(self.declaration.name) + '{' ] answer.append( self.indent( self.create_body() ) ) answer.append( '}' ) - return os.linesep.join( answer ) - + return os.linesep.join( answer ) + def _create_impl(self): return self.create_function() -class mem_fun_protected_v_t( calldef_t ): +class mem_fun_protected_v_t( calldef_t ): def __init__( self, function, wrapper ): calldef_t.__init__( self, function=function, wrapper=wrapper ) @@ -597,28 +593,28 @@ def full_name(self): return self.parent.full_name + '::' + self.declaration.name - - def function_type(self): + + def function_type(self): return declarations.member_function_type_t( return_type=self.declaration.return_type , class_inst=declarations.dummy_type_t( self.parent.full_name ) , arguments_types=map( lambda arg: arg.type, self.declaration.arguments ) , has_const=self.declaration.has_const ) - - def create_declaration(self, name): + + def create_declaration(self, name): template = 'virtual %(return_type)s %(name)s( %(args)s )%(constness)s%(throw)s' - + constness = '' if self.declaration.has_const: constness = ' const ' - + return template % { 'return_type' : self.declaration.return_type.decl_string , 'name' : name , 'args' : self.args_declaration() , 'constness' : constness , 'throw' : self.throw_specifier_code() - } + } def create_virtual_body(self): template = [] @@ -627,11 +623,11 @@ template.append( 'else' ) template.append( self.indent('%(return_)s%(wrapped_class)s::%(name)s( %(args)s );') ) template = os.linesep.join( template ) - + return_ = '' if not declarations.is_void( self.declaration.return_type ): return_ = 'return ' - + return template % { 'override' : self.override_identifier() , 'name' : self.declaration.name @@ -640,24 +636,24 @@ , 'args' : self.function_call_args() , 'wrapped_class' : self.wrapped_class_identifier() } - + def create_function(self): answer = [ self.create_declaration(self.declaration.name) + '{' ] answer.append( self.indent( self.create_virtual_body() ) ) answer.append( '}' ) return os.linesep.join( answer ) - + def _create_impl(self): return self.create_function() -class mem_fun_protected_pv_t( calldef_t ): +class mem_fun_protected_pv_t( calldef_t ): def __init__( self, function, wrapper ): calldef_t.__init__( self, function=function, wrapper=wrapper ) def create_function_type_alias_code( self, exported_class_alias=None ): ftype = self.wrapper.function_type() return 'typedef %s;' % ftype.create_typedef( self.function_type_alias ) - + def create_function_ref_code(self, use_function_alias=False): if use_function_alias: return '%s( &%s )' \ @@ -674,28 +670,28 @@ def full_name(self): return self.parent.full_name + '::' + self.declaration.name - - def function_type(self): + + def function_type(self): return declarations.member_function_type_t( return_type=self.declaration.return_type , class_inst=declarations.dummy_type_t( self.parent.full_name ) , arguments_types=map( lambda arg: arg.type, self.declaration.arguments ) , has_const=self.declaration.has_const ) - def create_declaration(self): + def create_declaration(self): template = 'virtual %(return_type)s %(name)s( %(args)s )%(constness)s%(throw)s' - + constness = '' if self.declaration.has_const: constness = ' const ' - + return template % { 'return_type' : self.declaration.return_type.decl_string , 'name' : self.declaration.name , 'args' : self.args_declaration() , 'constness' : constness , 'throw' : self.throw_specifier_code() - } + } def create_body( self ): if declarations.is_reference( self.declaration.return_type ): @@ -705,7 +701,7 @@ template.append( '%(override)s func_%(alias)s = this->get_override( "%(alias)s" );' ) template.append( '%(return_)sfunc_%(alias)s( %(args)s );') template = os.linesep.join( template ) - + return_ = '' if not declarations.is_void( self.declaration.return_type ): return_ = 'return ' @@ -716,7 +712,7 @@ , 'return_' : return_ , 'args' : self.function_call_args() } - + def _create_impl(self): answer = [ self.create_declaration() + '{' ] answer.append( self.indent( self.create_body() ) ) @@ -729,28 +725,28 @@ def full_name(self): return self.parent.full_name + '::' + self.declaration.name - - def function_type(self): + + def function_type(self): return declarations.member_function_type_t( return_type=self.declaration.return_type , class_inst=declarations.dummy_type_t( self.parent.full_name ) , arguments_types=map( lambda arg: arg.type, self.declaration.arguments ) , has_const=self.declaration.has_const ) - def create_declaration(self): + def create_declaration(self): template = 'virtual %(return_type)s %(name)s( %(args)s )%(constness)s%(throw)s' - + constness = '' if self.declaration.has_const: constness = ' const ' - + return template % { 'return_type' : self.declaration.return_type.decl_string , 'name' : self.declaration.name , 'args' : self.args_declaration() , 'constness' : constness , 'throw' : self.throw_specifier_code() - } + } def create_body( self ): if declarations.is_reference( self.declaration.return_type ): @@ -760,7 +756,7 @@ template.append( '%(override)s func_%(alias)s = this->get_override( "%(alias)s" );' ) template.append( '%(return_)sfunc_%(alias)s( %(args)s );') template = os.linesep.join( template ) - + return_ = '' if not declarations.is_void( self.declaration.return_type ): return_ = 'return ' @@ -771,7 +767,7 @@ , 'return_' : return_ , 'args' : self.function_call_args() } - + def _create_impl(self): answer = [ self.create_declaration() + '{' ] answer.append( self.indent( self.create_body() ) ) @@ -802,7 +798,7 @@ """ def __init__(self, constructor, wrapper=None ): calldef_t.__init__( self, function=constructor, wrapper=wrapper ) - + def _create_arg_code( self, arg ): temp = arg.type if declarations.is_const( temp ): @@ -811,7 +807,7 @@ #except for the purpose of function definitions temp = declarations.remove_const( temp ) return algorithm.create_identifier( self, temp.decl_string ) - + def _generate_definition_args(self): answer = [] optionals = [] @@ -820,7 +816,7 @@ optionals.append( self._create_arg_code( arg ) ) else: answer.append( self._create_arg_code( arg ) ) - + optionals_str = '' if optionals: optionals_str = algorithm.create_identifier( self, '::boost::python::optional' ) @@ -848,7 +844,7 @@ #else: # answer.append( '/*[ undefined call policies ]*/' ) return ''.join( answer ) - + def _create_impl( self ): code = 'def( %s )' % self.create_init_code() if not self.works_on_instance: @@ -863,16 +859,16 @@ declaration_based.declaration_based_t.__init__( self, declaration=function ) self._function_code_creator = function_code_creator - + def _get_function_code_creator(self): return self._function_code_creator def _set_function_code_creator(self, new_function_code_creator ): self._function_code_creator = new_function_code_creator function_code_creator = property( _get_function_code_creator, _set_function_code_creator ) - + def _create_impl( self ): return 'staticmethod( "%s" )' % self.function_code_creator.alias - + class constructor_wrapper_t( calldef_wrapper_t ): """ Creates C++ code that builds wrapper arround exposed constructor. @@ -880,7 +876,7 @@ def __init__( self, constructor ): calldef_wrapper_t.__init__( self, function=constructor ) - + def _create_declaration(self): result = [] result.append( self.parent.wrapper_alias ) @@ -894,7 +890,7 @@ result.append( ', '.join( args ) ) result.append( ' )' ) return ''.join( result ) - + def _create_constructor_call( self ): answer = [ algorithm.create_identifier( self, self.parent.declaration.decl_string ) ] answer.append( '( ' ) @@ -906,7 +902,7 @@ answer.append(' ') answer.append( ')' ) return ''.join( answer ) - + def _create_impl(self): answer = [ self._create_declaration() ] answer.append( ': ' + self._create_constructor_call() ) @@ -940,12 +936,12 @@ result.append( identifier + ' arg' ) result.append( ' )' ) return ''.join( result ) - + def _create_constructor_call( self ): answer = [ algorithm.create_identifier( self, self.parent.declaration.decl_string ) ] answer.append( '( arg )' ) return ''.join( answer ) - + def _create_impl(self): answer = [ self._create_declaration() ] answer.append( ': ' + self._create_constructor_call() ) @@ -959,13 +955,13 @@ class null_constructor_wrapper_t( declaration_based.declaration_based_t ): """ Creates wrapper for compiler generated null constructor. - """ + """ def __init__( self, class_inst ): declaration_based.declaration_based_t.__init__( self, declaration=class_inst ) def _create_constructor_call( self ): return algorithm.create_identifier( self, self.parent.declaration.decl_string ) + '()' - + def _create_impl(self): answer = [ self.parent.wrapper_alias + '(' ] if self.parent.held_type and not self.target_configuration.boost_python_has_wrapper_held_type: @@ -980,7 +976,7 @@ #in python all operators are members of class, while in C++ #you can define operators that are not. -class operator_t( declaration_based.declaration_based_t ): +class operator_t( declaration_based.declaration_based_t ): """ Creates boost.python code needed to expose supported subset of C++ operators. """ @@ -988,12 +984,12 @@ FIRST = 'first' SECOND = 'second' BOTH = 'both' - + def __init__(self, operator ): declaration_based.declaration_based_t.__init__( self , declaration=operator ) - + def _call_type_constructor( self, type ): x = declarations.remove_reference( type ) x = declarations.remove_cv( x ) @@ -1005,7 +1001,7 @@ assert not declarations.is_unary_operator( self.declaration ) decompose_type = declarations.decompose_type parent_decl_string = self.parent.declaration.decl_string - arg0 = decompose_type( self.declaration.arguments[0].type )[-1].decl_string + arg0 = decompose_type( self.declaration.arguments[0].type )[-1].decl_string if isinstance( self.declaration, declarations.member_operator_t ): if parent_decl_string == arg0: return self.SELF_POSITION.BOTH @@ -1040,12 +1036,12 @@ answer[2] = self_identifier else: answer[0] = self_identifier - answer[2] = self_identifier + answer[2] = self_identifier return ' '.join( answer ) def _create_unary_operator(self): return self.declaration.symbol + algorithm.create_identifier( self, '::boost::python::self' ) - + def _create_impl( self ): code = None if declarations.is_binary_operator( self.declaration ): @@ -1066,7 +1062,7 @@ implicitly_convertible = algorithm.create_identifier( self, '::boost::python::implicitly_convertible' ) from_arg = algorithm.create_identifier( self , declarations.full_name( self.declaration.parent ) ) - + to_arg = algorithm.create_identifier( self , self.declaration.return_type.decl_string ) return declarations.templates.join(implicitly_convertible @@ -1075,28 +1071,28 @@ class casting_member_operator_t( declaration_based.declaration_based_t ): """ - Creates boost.python code needed to register casting operators. For some + Creates boost.python code needed to register casting operators. For some operators Pythonic name is given: __int__, __long__, __float__, __str__ """ - + def __init__( self, operator ): declaration_based.declaration_based_t.__init__( self, declaration=operator ) self._call_policies = None def _create_impl(self): template = 'def( "%(function_name)s", &%(class_name)s::operator %(destination_type)s %(call_policies)s%(doc)s )' - + class_name = algorithm.create_identifier( self , declarations.full_name( self.declaration.parent ) ) - - policies = '/*, undefined call policies */' + + policies = '/*, undefined call policies */' if self.declaration.call_policies: policies = ',' + self.declaration.call_policies.create( self ) - + doc = '' if self.documentation: - doc = ', %s' % self.documentation - + doc = ', %s' % self.documentation + return template % { 'function_name' : self.declaration.alias , 'class_name' : class_name , 'destination_type' : self.declaration.return_type.decl_string @@ -1117,7 +1113,7 @@ implicitly_convertible = algorithm.create_identifier( self, '::boost::python::implicitly_convertible' ) from_arg = algorithm.create_identifier( self , self.declaration.arguments[0].type.decl_string) - + to_arg = algorithm.create_identifier( self , declarations.full_name( self.declaration.parent ) ) return declarations.templates.join(implicitly_convertible This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-20 06:29:54
|
Revision: 420 Author: roman_yakovenko Date: 2006-08-19 23:29:43 -0700 (Sat, 19 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=420&view=rev Log Message: ----------- adding case sensitive to the "ignore" API Modified Paths: -------------- pydsc_dev/pydsc.py Modified: pydsc_dev/pydsc.py =================================================================== --- pydsc_dev/pydsc.py 2006-08-17 07:05:41 UTC (rev 419) +++ pydsc_dev/pydsc.py 2006-08-20 06:29:43 UTC (rev 420) @@ -289,13 +289,18 @@ """ doc_checker.filter = filter_by_path_t( what, filter_by_path_t.FILTER_TYPE.INCLUDE ) -def ignore( what ): +def ignore( what, case_sensitive=False ): """Adds word or list of words to the ignore list. what - word(string) or list of words(strings) to be ignored. """ if isinstance( what, str ): + if not case_sensitive: + what = what.lower() doc_checker.ignored_words.add( what ) else: - map( doc_checker.ignored_words.add, what ) + for word in what: + if case_sensitive: + word = what.lower() + doc_checker.ignored_words.add( word ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-17 07:05:47
|
Revision: 419 Author: roman_yakovenko Date: 2006-08-17 00:05:41 -0700 (Thu, 17 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=419&view=rev Log Message: ----------- adding few log messages. they should explain to the user what he is waiting for Modified Paths: -------------- pygccxml_dev/pygccxml/parser/project_reader.py Modified: pygccxml_dev/pygccxml/parser/project_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/project_reader.py 2006-08-17 05:07:08 UTC (rev 418) +++ pygccxml_dev/pygccxml/parser/project_reader.py 2006-08-17 07:05:41 UTC (rev 419) @@ -6,10 +6,10 @@ import os import time import types -import source_reader +import source_reader import declarations_cache import pygccxml.declarations -from pygccxml import utils +from pygccxml import utils class COMPILATION_MODE: ALL_AT_ONCE = 'all at once' @@ -21,40 +21,40 @@ file_configuration_t - a class, that contains some data and description how to treat the data. file_configuration_t can contain reference to the next types of data: - + 1) path to C++ source file - + 2) path to `GCC-XML`_ generated XML file - + 3) path to C++ source file and path to `GCC-XML`_ generated XML file - + In this case, if XML file does not exists, it will be created. Next time you will ask to parse the source file, the XML file will be used instead. - + Small tip: you can setup your makefile to delete XML files every time, the relevant source file has changed. - + 4) Python string, that contains valid C++ code - - + + There are few functions, that will help you to construct file_configuration_t object: * L{create_source_fc} - + * L{create_gccxml_fc} - + * L{create_cached_source_fc} * L{create_text_fc} - + """ class CONTENT_TYPE: STANDARD_SOURCE_FILE = 'standard source file' CACHED_SOURCE_FILE = 'cached source file' GCCXML_GENERATED_FILE = 'gccxml generated file' TEXT = 'text' - + def __init__( self , data , start_with_declarations=None @@ -78,7 +78,7 @@ def __get_start_with_declarations(self): return self.__start_with_declarations start_with_declarations = property( __get_start_with_declarations ) - + def __get_content_type(self): return self.__content_type content_type = property( __get_content_type ) @@ -86,15 +86,15 @@ def __get_cached_source_file(self): return self.__cached_source_file cached_source_file = property( __get_cached_source_file ) - + def create_text_fc( text ): """ Creates L{file_configuration_t} instance, configured to contain Python string, that contains valid C++ code - + @param text: C++ code @type text: str - + @return: L{file_configuration_t} """ return file_configuration_t( data=text @@ -104,12 +104,12 @@ """ Creates L{file_configuration_t} instance, configured to contain path to C++ source file - + @param header: path to C++ source file @type header: str - + @return: L{file_configuration_t} - """ + """ return file_configuration_t( data=header , content_type=file_configuration_t.CONTENT_TYPE.STANDARD_SOURCE_FILE ) @@ -117,12 +117,12 @@ """ Creates L{file_configuration_t} instance, configured to contain path to GCC-XML generated XML file. - + @param xml_file: path to GCC-XML generated XML file @type xml_file: str - + @return: L{file_configuration_t} - """ + """ return file_configuration_t( data=xml_file , content_type=file_configuration_t.CONTENT_TYPE.GCCXML_GENERATED_FILE ) @@ -138,9 +138,9 @@ @param cached_source_file: path to GCC-XML generated XML file @type cached_source_file: str - + @return: L{file_configuration_t} - """ + """ return file_configuration_t( data=header , cached_source_file=cached_source_file , content_type=file_configuration_t.CONTENT_TYPE.CACHED_SOURCE_FILE ) @@ -179,14 +179,14 @@ self.__decl_factory = decl_factory if not decl_factory: self.__decl_factory = pygccxml.declarations.decl_factory_t() - + self.logger = utils.loggers.gccxml - + @staticmethod def get_os_file_names( files ): """Returns a list of OS file names - @param files: list of strings or L{file_configuration_t} instances. + @param files: list of strings or L{file_configuration_t} instances. files could contain a mix of them @type files: list """ @@ -205,7 +205,7 @@ def read_files( self, files, compilation_mode=COMPILATION_MODE.FILE_BY_FILE): """Parse header files. - @param files: list of strings or L{file_configuration_t} instances. + @param files: list of strings or L{file_configuration_t} instances. files could contain a mix of them @type files: list @param compilation_mode: Determines whether the files are parsed individually or as one single chunk @@ -218,13 +218,13 @@ else: if compilation_mode == COMPILATION_MODE.ALL_AT_ONCE: msg = ''.join([ - "Unable to parse files using ALL_AT_ONCE mode. " + "Unable to parse files using ALL_AT_ONCE mode. " , "There is some file configuration that is not file. " , "pygccxml.parser.project_reader_t switches to FILE_BY_FILE mode." ]) self.logger.warning( msg ) return self.__parse_file_by_file(files) - def __parse_file_by_file(self, files): + def __parse_file_by_file(self, files): namespaces = [] config = self.__config.clone() self.logger.debug( "Reading project files: file by file" ) @@ -232,7 +232,7 @@ reader = None header = None content_type = None - if isinstance( prj_file, file_configuration_t ): + if isinstance( prj_file, file_configuration_t ): del config.start_with_declarations[:] config.start_with_declarations.extend( prj_file.start_with_declarations ) header = prj_file.data @@ -246,8 +246,10 @@ , self.__decl_factory ) decls = None if content_type == file_configuration_t.CONTENT_TYPE.STANDARD_SOURCE_FILE: + self.logger.info( 'Parsing source file "%s" ... ' % header ) decls = reader.read_file( header ) elif content_type == file_configuration_t.CONTENT_TYPE.GCCXML_GENERATED_FILE: + self.logger.info( 'Parsing xml file "%s" ... ' % header ) decls = reader.read_xml_file( header ) elif content_type == file_configuration_t.CONTENT_TYPE.CACHED_SOURCE_FILE: #TODO: raise error when header file does not exist @@ -255,36 +257,39 @@ dir_ = os.path.split( prj_file.cached_source_file )[0] if dir_ and not os.path.exists( dir_ ): os.makedirs( dir_ ) + self.logger.info( 'Creating xml file "%s" from source file "%s" ... ' + % ( prj_file.cached_source_file, header ) ) reader.create_xml_file( header, prj_file.cached_source_file ) + self.logger.info( 'Parsing xml file "%s" ... ' % prj_file.cached_source_file ) decls = reader.read_xml_file( prj_file.cached_source_file ) else: decls = reader.read_string( header ) namespaces.append( decls ) self.logger.debug( "Flushing cache... " ) - start_time = time.clock() + start_time = time.clock() self.__dcache.flush() self.logger.debug( "Cache has been flushed in %.1f secs" % ( time.clock() - start_time ) ) answer = [] - self.logger.debug( "Joining namespaces ..." ) + self.logger.debug( "Joining namespaces ..." ) for file_nss in namespaces: answer = self._join_top_namespaces( answer, file_nss ) self.logger.debug( "Joining declarations ..." ) for ns in answer: if isinstance( ns, pygccxml.declarations.namespace_t ): - self._join_declarations( ns ) + self._join_declarations( ns ) leaved_classes = self._join_class_hierarchy( answer ) types = self.__declarated_types(answer) self.logger.debug( "Relinking declared types ..." ) self._relink_declarated_types( leaved_classes, types ) source_reader.bind_aliases( pygccxml.declarations.make_flatten( answer ) ) return answer - + def __parse_all_at_once(self, files): config = self.__config.clone() self.logger.debug( "Reading project files: all at once" ) header_content = [] for header in files: - if isinstance( header, file_configuration_t ): + if isinstance( header, file_configuration_t ): del config.start_with_declarations[:] config.start_with_declarations.extend( header.start_with_declarations ) header_content.append( '#include "%s" %s' % ( header.data, os.linesep ) ) @@ -319,7 +324,7 @@ assert isinstance( nsref, pygccxml.declarations.namespace_t ) ddhash = {} # decl.__class__ : { decl.name : [decls] } double declaration hash decls = [] - + for decl in nsref.declarations: if not ddhash.has_key( decl.__class__ ): ddhash[ decl.__class__ ] = { decl._name : [ decl ] } @@ -346,7 +351,7 @@ decls.append( decl ) joined_decls[decl._name].append( decl ) else: - assert 1 == len( joined_decls[ decl._name ] ) + assert 1 == len( joined_decls[ decl._name ] ) if isinstance( decl, pygccxml.declarations.namespace_t ): joined_decls[ decl._name ][0].take_parenting( decl ) nsref.declarations = decls @@ -369,7 +374,7 @@ for base_info in class_.bases: leaved_base = leaved_classes[ create_key( base_info.related_class ) ] #treating base class hierarchy of leaved_class - leaved_base_info = pygccxml.declarations.hierarchy_info_t( + leaved_base_info = pygccxml.declarations.hierarchy_info_t( related_class=leaved_base , access=base_info.access ) if leaved_base_info not in leaved_class.bases: @@ -378,7 +383,7 @@ index = leaved_class.bases.index( leaved_base_info ) leaved_class.bases[index].related_class = leaved_base_info.related_class #treating derived class hierarchy of leaved_base - leaved_derived_for_base_info = pygccxml.declarations.hierarchy_info_t( + leaved_derived_for_base_info = pygccxml.declarations.hierarchy_info_t( related_class=leaved_class , access=base_info.access ) if leaved_derived_for_base_info not in leaved_base.derived: @@ -389,13 +394,13 @@ for derived_info in class_.derived: leaved_derived = leaved_classes[ create_key( derived_info.related_class ) ] #treating derived class hierarchy of leaved_class - leaved_derived_info = pygccxml.declarations.hierarchy_info_t( + leaved_derived_info = pygccxml.declarations.hierarchy_info_t( related_class=leaved_derived , access=derived_info.access ) if leaved_derived_info not in leaved_class.derived: leaved_class.derived.append( leaved_derived_info ) #treating base class hierarchy of leaved_derived - leaved_base_for_derived_info = pygccxml.declarations.hierarchy_info_t( + leaved_base_for_derived_info = pygccxml.declarations.hierarchy_info_t( related_class=leaved_class , access=derived_info.access ) if leaved_base_for_derived_info not in leaved_derived.bases: @@ -432,7 +437,7 @@ msg.append( "Class definition has been changed from one compilation to an other." ) msg.append( "Why did it happen to me? Here is a short list of reasons: " ) msg.append( " 1. There are different preprocessor definitions applied on same file during compilation" ) - msg.append( " 2. Bug in pygccxml." ) + msg.append( " 2. Bug in pygccxml." ) self.logger.error( os.linesep.join(msg) ) def _join_declarations( self, declref ): @@ -440,7 +445,7 @@ for ns in declref.declarations: if isinstance( ns, pygccxml.declarations.namespace_t ): self._join_declarations( ns ) - + def __declarated_types(self, namespaces): def get_from_type(cpptype): if not cpptype: @@ -456,7 +461,7 @@ for arg in cpptype.arguments_types: types.extend( get_from_type( arg ) ) return types - else: + else: assert isinstance( cpptype, pygccxml.declarations.unknown_t ) return [] types = [] @@ -465,4 +470,4 @@ types.extend( get_from_type( decl.function_type() ) ) elif isinstance( decl, (pygccxml.declarations.typedef_t, pygccxml.declarations.variable_t) ): types.extend( get_from_type( decl.type ) ) - return types \ No newline at end of file + return types This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-17 05:07:24
|
Revision: 418 Author: roman_yakovenko Date: 2006-08-16 22:07:08 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=418&view=rev Log Message: ----------- Updating pydsc, docs and new test cases has been added Modified Paths: -------------- pydsc_dev/docs/pydsc.rest pydsc_dev/pydsc.py pydsc_dev/setup.py pydsc_dev/unittests/tester.py pydsc_dev/unittests/to_be_tested.py Added Paths: ----------- pydsc_dev/unittests/do_not_check/ pydsc_dev/unittests/do_not_check/__init__.py Modified: pydsc_dev/docs/pydsc.rest =================================================================== --- pydsc_dev/docs/pydsc.rest 2006-08-17 03:44:31 UTC (rev 417) +++ pydsc_dev/docs/pydsc.rest 2006-08-17 05:07:08 UTC (rev 418) @@ -7,21 +7,21 @@ .. meta:: :description: Python documentation string spell checker :keywords: Python, docstring, documentation, spell, check - , документация, спеллер, орфографическая коррекция, - + , документация, спеллер, орфографическая коррекция, + -------------- What is pydsc? -------------- -.. include:: ./definition.rest +.. include:: ./definition.rest ---------------------- What it is useful for? ---------------------- Well, this project was born to solve real problem - I made a lot of mistakes, -when I write source code documentation for my projects. I needed some way to -check all the documentation strings. My goal was simplicity + easy customization. +when I write source code documentation for my projects. I needed some way to +check all the documentation strings. My goal was simplicity + easy customization. I achieved it. Here is example of usage of pydsc: | ``import pydsc`` @@ -33,8 +33,8 @@ Spell checking -------------- -I did not reinvent the wheel. I use external spell checking engine. I checked -around and found few spell check engines available from Python. I decided to use +I did not reinvent the wheel. I use external spell checking engine. I checked +around and found few spell check engines available from Python. I decided to use `PyEnchant`_. It is cross platform, has clean interface and responsive author. ------------- @@ -47,12 +47,12 @@ * exclude(include) files from(to) spell checking process by file location ( very useful option in multi-project environment ) -More complex example: +"More complex" example: | ``import pydsc`` -| ``pydsc.doc_checker.filter.append( "/home/roman/pygccxml" )`` -| ``pydsc.doc_checker.filter_type = pydsc.FILTER_TYPE.INCLUDE`` -| ``map( pydsc.doc_checker.speller.ignore_always, [ 'normcase', 'normpath' ] )`` +| #check for spell errors only in files under "/home/roman/pygccxml" directory +| ``pydsc.include( "/home/roman/pygccxml" )`` +| ``pydsc.ignore( [ 'normcase', 'normpath' ] )`` | ``import readline`` -------- Modified: pydsc_dev/pydsc.py =================================================================== --- pydsc_dev/pydsc.py 2006-08-17 03:44:31 UTC (rev 417) +++ pydsc_dev/pydsc.py 2006-08-17 05:07:08 UTC (rev 418) @@ -62,10 +62,10 @@ """ -__version__ = '0.1' -__author__ = 'Roman Yakovenko <rom...@gm...>' -__url__ = 'http://sourceforge.net/projects/pygccxml/' -__license__ = 'Boost Software License <http://boost.org/more/license_info.html>' +__version__ = '0.2' #current version +__author__ = 'Roman Yakovenko <rom...@gm...>' #Don't you want to know who is guilty? +__url__ = 'http://www.language-binding.net' #project home +__license__ = 'Boost Software License <http://boost.org/more/license_info.html>' #license import os import sys @@ -84,12 +84,18 @@ return os.path.normcase( os.path.normpath( some_path ) ) class filter_by_path_t: + """The instance of this class will help user to define filter, that will + exclude modules from being checked""" class FILTER_TYPE: """defines few filter constants""" INCLUDE = 'include' EXCLUDE = 'exclude' def __init__( self, what, ftype ): + """ + what - list of paths, could contain file and directory names + ftype - FILTER_TYPE constant + """ self.what = what if None is self.what: self.what = [] @@ -116,19 +122,13 @@ return bool( filter( lambda dir: path.startswith( dir ), dirs ) ) def check( self, source_file ): + """returns True if source_file should be checked, False otherwise""" source_file = normalize_path( source_file ) if source_file in self.what or self.contains_parent_dir( source_file, self.what ): return self.ftype == self.FILTER_TYPE.INCLUDE else: return self.ftype == self.FILTER_TYPE.EXCLUDE -def exclude( what ): - return filter_by_path_t( what, filter_t.FILTER_TYPE.EXCLUDE ) - -def include( what ): - return filter_by_path_t( what, filter_t.FILTER_TYPE.INCLUDE ) - - class checker_t( object ): """ applies spell check process on every imported module @@ -181,10 +181,12 @@ if self.writer is None: self.writer = sys.stdout self.filter = filter - self.identifiers = set() + self.ignored_words = set() self.ignore_identifiers = ignore_identifiers def should_be_checked( self, obj, module=None ): + """returns True, if obj should be checked, False otherwise""" + if id(obj) in self.__checked: return False if inspect.isbuiltin( obj ): @@ -215,24 +217,22 @@ return False def import_( self, name, globals=None, locals=None, fromlist=None ): + """Hook to import functionality""" pymodule = self.__orig_import( name, globals, locals, fromlist ) if self.should_be_checked(pymodule): - #write = self.writer.write - #write( 'inspecting %s%s' % ( inspect.getsourcefile( pymodule ), os.linesep ) ) self.__already_imported.add( name ) - self.check( pymodule ) - #write( 'inspecting %s done%s' % ( inspect.getsourcefile( pymodule ), os.linesep ) ) + self.__check( pymodule ) return pymodule def __check_text_impl( self, obj, text, text_type ): if not text: return if self.ignore_identifiers and hasattr( obj, '__name__' ) and obj.__name__: - self.identifiers.add( obj.__name__ ) + self.ignored_words.add( obj.__name__ ) errors = {} self.speller.set_text( text ) for error in self.speller: - if error.word in self.identifiers: + if error.word in self.ignored_words: continue if not errors.has_key( error.word ): errors[ error.word ] = [] @@ -252,21 +252,50 @@ write( ' misspelled word: %s%s' % ( word, os.linesep ) ) write( ' suggestions : %s%s' % ( `suggestions`, os.linesep ) ) - def check_text( self, obj): + def __check_text( self, obj): self.__check_text_impl( obj, inspect.getdoc( obj ), 'documentation string' ) if inspect.getsourcefile( obj ): self.__check_text_impl( obj, inspect.getcomments( obj ), 'comment' ) - def check( self, module ): - self.check_text( module ) + def __check( self, module ): + self.__check_text( module ) to_be_checked = map( lambda x: x[1], inspect.getmembers( module ) ) while to_be_checked: member = to_be_checked.pop(0) if not self.should_be_checked( member, module ): continue - self.check_text( member ) + self.__check_text( member ) to_be_checked.extend( map( lambda x: x[1], inspect.getmembers( member ) ) ) self.__checked.add( id(member) ) """documentation spell checker instance""" doc_checker = checker_t( checker.SpellChecker( "en_US" ) ) + +def exclude( what ): + """ + Convenience function. It will exclude all modules, that their source file or + parent directory belongs to "what". + + what - list of paths, could contain file and directory names + """ + doc_checker.filter = filter_by_path_t( what, filter_by_path_t.FILTER_TYPE.EXCLUDE ) + +def include( what ): + """ + Convenience function. It will include only modules, that their source file + or parent directory belongs to "what". + + what - list of paths, could contain file and directory names + """ + doc_checker.filter = filter_by_path_t( what, filter_by_path_t.FILTER_TYPE.INCLUDE ) + +def ignore( what ): + """Adds word or list of words to the ignore list. + + what - word(string) or list of words(strings) to be ignored. + """ + if isinstance( what, str ): + doc_checker.ignored_words.add( what ) + else: + map( doc_checker.ignored_words.add, what ) + Modified: pydsc_dev/setup.py =================================================================== --- pydsc_dev/setup.py 2006-08-17 03:44:31 UTC (rev 417) +++ pydsc_dev/setup.py 2006-08-17 05:07:08 UTC (rev 418) @@ -4,13 +4,59 @@ # http://www.boost.org/LICENSE_1_0.txt) import os -from distutils import sysconfig +import sys + from distutils.core import setup +from distutils.cmd import Command +def generate_doc(): + """Generate the epydoc reference manual. + """ + print "Generating epydoc files..." + + from epydoc.docbuilder import build_doc_index + from epydoc.docwriter.html import HTMLWriter + + docindex = build_doc_index(['pydsc']) + html_writer = HTMLWriter( docindex + , prj_name='pydsc' + , prj_url='http://www.language-binding.net' + , include_sourcecode=False #This will decrease the size of generated documentation + , show_private=False + , show_frames=False) + + html_writer.write( os.path.join('docs', 'apidocs') ) + +class doc_cmd(Command): + """This is a new distutils command 'doc' to build the epydoc manual. + """ + + description = 'build the API reference using epydoc' + user_options = [('no-doc', None, "don't run epydoc")] + boolean_options = ['no-doc'] + + def initialize_options (self): + self.no_doc = 0 + + def finalize_options (self): + pass + + def run(self): + if self.no_doc: + return + generate_doc() + + +# Generate the doc when a source distribution is created +if sys.argv[-1]=="sdist": + generate_doc() + setup( name="pydsc" + , version = "0.2" , description="Python documentation and comments spell checker" , author="Roman Yakovenko" , author_email="rom...@gm..." - , url='http://pygccxml.sourceforge.net' + , url='http://www.language-binding.net' , py_modules=[ 'pydsc' ] -) \ No newline at end of file + , cmdclass = {"doc" : doc_cmd} +) Added: pydsc_dev/unittests/do_not_check/__init__.py =================================================================== --- pydsc_dev/unittests/do_not_check/__init__.py (rev 0) +++ pydsc_dev/unittests/do_not_check/__init__.py 2006-08-17 05:07:08 UTC (rev 418) @@ -0,0 +1,11 @@ +# Copyright 2004 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 types + +def test(): + "qwoeithawytrqwueryqweytrqweytrqweytroqweytrqoweytroqwueytrqowutroqweytroqw" + pass Modified: pydsc_dev/unittests/tester.py =================================================================== --- pydsc_dev/unittests/tester.py 2006-08-17 03:44:31 UTC (rev 417) +++ pydsc_dev/unittests/tester.py 2006-08-17 05:07:08 UTC (rev 418) @@ -3,5 +3,14 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +import os +import sys +sys.path.append( '..' ) + import pydsc -import to_be_tested \ No newline at end of file + +pydsc.exclude( os.path.abspath( os.path.join( os.curdir, 'do_not_check' ) ) ) +pydsc.ignore( 'abracadabra' ) + +import to_be_tested +import do_not_check Modified: pydsc_dev/unittests/to_be_tested.py =================================================================== --- pydsc_dev/unittests/to_be_tested.py 2006-08-17 03:44:31 UTC (rev 417) +++ pydsc_dev/unittests/to_be_tested.py 2006-08-17 05:07:08 UTC (rev 418) @@ -8,8 +8,8 @@ class code_creator_t(object): """ - code_creator_t is the base class for all code creators. - This class defines interface that every code creator should implement. + code_creator_t is the base class for all code creators. + This class defines interface that every code creator should implement. Also it provides few convinience functions. """ PYPLUSPLUS_NS_NAME = 'pyplusplus' @@ -21,23 +21,23 @@ assert isinstance( parent, code_creator_t ) self._parent = parent self._target_configuration = None - + 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 ) self._parent = new_parent """parent - reference to parent code creator""" parent = property( _get_parent, _set_parent ) - + def _get_target_configuration( self ): return self._target_configuration def _set_target_configuration( self, config ): self._target_configuration = config """target_configuration - reference to target_configuration_t class instance""" target_configuration = property( _get_target_configuration, _set_target_configuration ) - + def _get_top_parent(self): parent = self.parent me = self @@ -52,15 +52,15 @@ 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. """ 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. """ code = self._create_impl() @@ -73,21 +73,21 @@ """ assert isinstance( code, types.StringTypes ) return code.strip() - + @staticmethod def indent( code, size=1 ): """ - function that implements code indent algorithm. + function that implements code indent algorithm. """ assert isinstance( code, types.StringTypes ) return code_creator_t.__INDENTATION * size\ + code.replace( os.linesep , os.linesep + code_creator_t.__INDENTATION * size ) - - @staticmethod + + @staticmethod def unindent( code ): """ - function that implements code unindent algorithm. + function that implements code unindent algorithm. """ assert isinstance( code, types.StringTypes ) if code.startswith(code_creator_t.__INDENTATION): @@ -95,7 +95,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 @@ -104,4 +104,10 @@ assert isinstance( line, types.StringTypes ) l = line.lstrip() #1q2w3e4r-------------- - return l.startswith( '//' ) or l.startswith( '/*' ) \ No newline at end of file + return l.startswith( '//' ) or l.startswith( '/*' ) + + + def do_nothing( self ): + """abracadabra""" + pass + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-08-17 03:44:41
|
Revision: 417 Author: roman_yakovenko Date: 2006-08-16 20:44:31 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=417&view=rev Log Message: ----------- moving pydsc.py one directory up, for setup.py script Added Paths: ----------- pydsc_dev/pydsc.py Removed Paths: ------------- pydsc_dev/pydsc/ Copied: pydsc_dev/pydsc.py (from rev 415, pydsc_dev/pydsc/pydsc.py) =================================================================== --- pydsc_dev/pydsc.py (rev 0) +++ pydsc_dev/pydsc.py 2006-08-17 03:44:31 UTC (rev 417) @@ -0,0 +1,272 @@ +# Copyright 2004 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) + +""" +Python Documentation Spell Checker. + +The pydsc module contains functionality needed to check documentation strings +and comments for spelling errors, within Python code. The pydsc module depends +on PyEnchant spell checker. PyEnchant provides interface for different spell +engines: + * ispell + * aspell + * OpenOffice + +The use of the pydsc module is very simple - just import pydsc and all modules +that will be imported after it will be checked. By default all spelling errors +will be printed to sys.stdout. The pydsc checker could be customized in many +different ways: + * you can define set of files/directories that should be included/excluded + from check process + * you can redefine error messages destination + * you can redefine and/or re-configurate spell checker + +Install: +python setup.py install + +Usage example: + +import pydsc +import readline #errors will be printed to standart output + +more complex example ( taken from pygccxml project ): + +import pydsc +#test only pygccxml +#package_directory defined earlier +pydsc.doc_checker.filter.append( package_directory ) +pydsc.doc_checker.filter_type = pydsc.FILTER_TYPE.INCLUDE +# +map( pydsc.doc_checker.speller.ignore_always + , [ 'org' + , 'http' + , 'bool' + , 'str' + , 'www' + , 'param' + , 'txt' + , 'decl' + , 'decls' + , 'namespace' + , 'enum' + , 'const' + , 'GCC' + , 'xcc' + , 'TODO' + , 'typedef' + , 'os' + , 'normcase' + , 'normpath' ] ) + +""" + +__version__ = '0.1' +__author__ = 'Roman Yakovenko <rom...@gm...>' +__url__ = 'http://sourceforge.net/projects/pygccxml/' +__license__ = 'Boost Software License <http://boost.org/more/license_info.html>' + +import os +import sys +import pprint +import inspect +import __builtin__ +from enchant import checker + + +#TODO: source code encoding +# -*- coding: encoding -*- +# -*- coding: iso-8859-15 -*- + +def normalize_path( some_path ): + """return os.path.normcase( os.path.normpath( some_path ) )""" + return os.path.normcase( os.path.normpath( some_path ) ) + +class filter_by_path_t: + class FILTER_TYPE: + """defines few filter constants""" + INCLUDE = 'include' + EXCLUDE = 'exclude' + + def __init__( self, what, ftype ): + self.what = what + if None is self.what: + self.what = [] + elif isinstance( self.what, str ): + self.what = [self.what] + self.what = map( normalize_path, self.what ) + self.ftype = ftype + + @staticmethod + def contains_parent_dir( path, dirs ): + """ + returns true if one of the directories is root directory for the path, + false otherwise + + @param path: path + @type path: str + + @param dirs: list of directories and\\or files + @type dirs: [ str ] + + @return: bool + """ + #precondition: dirs and fpath should be normalize_path'ed before calling this function + return bool( filter( lambda dir: path.startswith( dir ), dirs ) ) + + def check( self, source_file ): + source_file = normalize_path( source_file ) + if source_file in self.what or self.contains_parent_dir( source_file, self.what ): + return self.ftype == self.FILTER_TYPE.INCLUDE + else: + return self.ftype == self.FILTER_TYPE.EXCLUDE + +def exclude( what ): + return filter_by_path_t( what, filter_t.FILTER_TYPE.EXCLUDE ) + +def include( what ): + return filter_by_path_t( what, filter_t.FILTER_TYPE.INCLUDE ) + + +class checker_t( object ): + """ + applies spell check process on every imported module + + This is the main class of this module. This class applies spell check + process on every imported module. Every documentation string within the + module will be checked. Some comments will be checked too. You should read + inspect module documentation, in order to find out which comments will be + checked. + """ + + def __init__( self + , speller + , writer=None + , filter=None + , ignore_identifiers=True ): + """ + initialization method + + During this method, reference to __builtin__.__import__ function is + saved in one of the members of the class, and replaced with import_ + member function. + + @param speller: reference to enchant.checker.SpellChecker object + @type speller: enchant.checker.SpellChecker + + @param writer: reference to instance of class that has write method. + By default sys.stdout will be used. + + @param filter: list of files or directories + @type filter: [ str ] + + @param filter_type: provides interpretation for content of filter parameter + @type filter_type: L{FILTER_TYPE} + + @param ignore_identifiers: often comments/documentation strings contains + class\\method\\function names. Those names, + usually introduce spell error. If ignore_identifiers + set to True, those names will be ignored. + @type ignore_identifiers: bool + """ + object.__init__( self ) + self.__checked = set() + self.__orig_import = __builtin__.__import__ + __builtin__.__import__ = self.import_ + self.__already_imported = set( sys.modules.keys() ) + self.__checked = set() + self.speller = speller + self.writer = writer + if self.writer is None: + self.writer = sys.stdout + self.filter = filter + self.identifiers = set() + self.ignore_identifiers = ignore_identifiers + + def should_be_checked( self, obj, module=None ): + if id(obj) in self.__checked: + return False + if inspect.isbuiltin( obj ): + return False + if inspect.ismodule( obj ): + if obj.__name__ in self.__already_imported: + return False #do not check already imported modules + if self.filter: + try: + source_file = inspect.getsourcefile(obj) + if source_file is None: + source_file = inspect.getfile( obj ) + return self.filter.check( source_file ) + except TypeError: + return False #built in module + else: + return True + obj_module = inspect.getmodule( obj ) + if not obj_module is module: + return False + if inspect.isclass( obj ) \ + or inspect.ismethod( obj ) \ + or inspect.isfunction( obj ) \ + or inspect.isroutine( obj ) \ + or inspect.ismethoddescriptor( obj ) \ + or inspect.isdatadescriptor( obj ): + return True + return False + + def import_( self, name, globals=None, locals=None, fromlist=None ): + pymodule = self.__orig_import( name, globals, locals, fromlist ) + if self.should_be_checked(pymodule): + #write = self.writer.write + #write( 'inspecting %s%s' % ( inspect.getsourcefile( pymodule ), os.linesep ) ) + self.__already_imported.add( name ) + self.check( pymodule ) + #write( 'inspecting %s done%s' % ( inspect.getsourcefile( pymodule ), os.linesep ) ) + return pymodule + + def __check_text_impl( self, obj, text, text_type ): + if not text: + return + if self.ignore_identifiers and hasattr( obj, '__name__' ) and obj.__name__: + self.identifiers.add( obj.__name__ ) + errors = {} + self.speller.set_text( text ) + for error in self.speller: + if error.word in self.identifiers: + continue + if not errors.has_key( error.word ): + errors[ error.word ] = [] + errors[ error.word ] = self.speller.suggest() + if not errors: + return + write = self.writer.write + if inspect.getsourcefile( inspect.getmodule( obj ) ): + write( ' error details: %s' % os.linesep ) + write( ' file : %s%s' % ( inspect.getsourcefile( inspect.getmodule( obj ) ), os.linesep ) ) + write( ' line : %d%s' % ( inspect.getsourcelines( obj )[1], os.linesep ) ) + write( ' text type : %s%s' % ( text_type, os.linesep ) ) + else: + write( ' error details: %s' % os.linesep ) + write( ' text type : %s%s' % ( text_type, os.linesep ) ) + for word, suggestions in errors.items(): + write( ' misspelled word: %s%s' % ( word, os.linesep ) ) + write( ' suggestions : %s%s' % ( `suggestions`, os.linesep ) ) + + def check_text( self, obj): + self.__check_text_impl( obj, inspect.getdoc( obj ), 'documentation string' ) + if inspect.getsourcefile( obj ): + self.__check_text_impl( obj, inspect.getcomments( obj ), 'comment' ) + + def check( self, module ): + self.check_text( module ) + to_be_checked = map( lambda x: x[1], inspect.getmembers( module ) ) + while to_be_checked: + member = to_be_checked.pop(0) + if not self.should_be_checked( member, module ): + continue + self.check_text( member ) + to_be_checked.extend( map( lambda x: x[1], inspect.getmembers( member ) ) ) + self.__checked.add( id(member) ) + +"""documentation spell checker instance""" +doc_checker = checker_t( checker.SpellChecker( "en_US" ) ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |