pygccxml-commit Mailing List for C++ Python language bindings (Page 68)
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-05-27 18:46:47
|
Revision: 166 Author: roman_yakovenko Date: 2006-05-27 11:46:37 -0700 (Sat, 27 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=166&view=rev Log Message: ----------- Fixing bug in variable_wrapper, where variables holds pointer to function Modified Paths: -------------- pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py Modified: pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-05-27 11:28:07 UTC (rev 165) +++ pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-05-27 18:46:37 UTC (rev 166) @@ -42,11 +42,19 @@ return '' if self.bits == 0 and self.name == "": return "pyplusplus can not expose alignement bit." - type_ = declarations.remove_const( self.type ) + type_ = declarations.remove_alias( self.type ) + type_ = declarations.remove_const( type_ ) if declarations.is_pointer( type_ ): if self.type_qualifiers.has_static: return "pyplusplus, right now, can not expose static pointer member variables. This could be changed in future." if declarations.is_fundamental( type_.base ): return "pyplusplus, right now, 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 ) + if ptr2functions: + return "boost.python can not expose variables, which are pointer to function." \ + + " See http://www.boost.org/libs/python/doc/v2/faq.html#funcptr for more information." return '' \ 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-05-27 11:28:21
|
Revision: 165 Author: roman_yakovenko Date: 2006-05-27 04:28:07 -0700 (Sat, 27 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=165&view=rev Log Message: ----------- improving documentation Modified Paths: -------------- pygccxml_dev/docs/query_interface.rest pygccxml_dev/docs/www_configuration.py pygccxml_dev/pygccxml/declarations/mdecl_wrapper.py Modified: pygccxml_dev/docs/query_interface.rest =================================================================== --- pygccxml_dev/docs/query_interface.rest 2006-05-25 08:05:00 UTC (rev 164) +++ pygccxml_dev/docs/query_interface.rest 2006-05-27 11:28:07 UTC (rev 165) @@ -9,7 +9,7 @@ ------------ You parsed the source files. Now you have to do some real work with the extracted information, right? `pygccxml`_ provides very powerful and simple interface to -query about extracted declrations. +query about extracted declarations. Just an example. I want to select all member functions, that have 2 arguments. I don't care about first argument type, but I do want second argument type to be @@ -23,7 +23,7 @@ query = query & ~declarations.access_type_matcher_t( 'public' ) global_ns.member_functions( function=query, arg_types=[None, 'int &'] ) -As for me, the example I gave was too complex. In many cases you will find your +The example is complex, but still readable. In many cases you will find your self looking for one or many declarations using one or two properties of that declaration(s). For example: :: @@ -34,141 +34,243 @@ -------------- User interface --------------- - -As you already know, ``pygccxml.declarations`` packages defines next classes: +-------------- +As you already know, ``pygccxml.declarations`` package defines next classes: + * ``scopedef_t`` - base class for all classes, that can contain other declarations * ``namespace_t`` - derives from ``scopedef_t`` class, represents C++ namespace -* ``class_t`` - derives from ``scopedef_t`` class, represents C++ class/struct. +* ``class_t`` - derives from ``scopedef_t`` class, represents C++ class/struct/union. -So, the query methods defined on ``scopedef_t`` class could be used on instances -of ``class_t`` and ``namespace_t`` classes. - -I will explain the usage of ``member_function`` and ``member_functions`` methods. -The usage of other methods is very similar to them. Here is definition of those -methods: -:: - - def member_function( self, - name=None, - function=None, - return_type=None, - arg_types=None, - header_dir=None, - header_file=None, - recursive=None ) - - - def member_functions( self, - name=None, - function=None, - return_type=None, - arg_types=None, - header_dir=None, - header_file=None, - recursive=None, - allow_empty=None ) - -As you can see, from the methods arguments you can search for member function -by: - - * ``name`` - - Python string, that contains member function name or full name. - - ``do_smth = my_class.member_function( 'do_smth' )`` - ``do_smth = my_class.member_function( 'my_namespace::my_class::do_smth' )`` - - * ``function`` - - Python callable object. You would use this functionality, if you need to - build custom query. This object will be called with one argument - declaration, - and it should return ``True`` or ``False``. - - ``impls = my_class.member_functions( lambda decl: decl.name.endswith( 'impl' ) )`` - - ``impls`` will contain all member functions, that thier name ends with "impl". - - * ``return_type`` - - Function return type. This argument can be Python string or an object that - describes C++ type. - - ``mem_funcs = my_class.member_functions( return_type='int' )`` - - ``i = declarations.int_t()`` - ``ref_i = declarations.reference_t( i )`` - ``const_ref_i = declarations.const_t( ref_i )`` - ``mem_funcs = my_class.member_functions( return_type=const_ref_int )`` - - * ``arg_types`` - - Python list that contains description of member function argument types. - This list could be a mix of Python strings and objects that describes C++ - type. Size of list says how many arguments function should have. If you want - to skip some argument type from within comparison, you put ``None``, into - relevant position within the list. - - ``mem_funcs = my_class.member_functions( arg_types=[ None, 'int'] )`` - - ``mem_funcs`` will contain all member functions, that have two arguments - and type of second argument is ``int``. - - * ``header_dir`` - - Python string, that contains full path to directory, which contains file, - which contains the function declaration - - ``mem_funcs = my_namespace.member_functions( header_dir='/home/roman/xyz' )`` - - * ``header_file`` - - Python string, that contains full path to file, which contains the function - declaration. - - ``mem_funcs = my_namespace.member_functions( header_dir='/home/roman/xyz/xyz.hpp' )`` - - * ``recursive`` - - Python boolean object. - - If ``recursive`` is ``True``, then member function will be also searched - within internal declarations. - - If ``recursive`` is ``False``, then member function will be searched only - within current scope. - - What happen if ``recursive`` is ``None``? Well. ``scopedef_t`` class defines - ``RECURSIVE_DEFAULT`` variable. It's initial value is ``True``. So, if you - don't pass ``recursive`` argument, the value of ``RECURSIVE_DEFAULT`` variable - will be used. This "yet another level of indirection" allows you to configure - `pygccxml`_ "select" functions in one place for all project. - - * ``allow_empty`` - - Python boolean object, it says `pygccxml`_ what to do if query returns empty. - - If ``allow_empty`` is ``False``, then exception - ``RuntimeError( "Multi declaration query returned 0 declarations." )`` - will be raised - - ``allow_empty`` uses same tehnique as ``recursive``, to allow you to customize - the behaviour project-wise. The relevant class variable name is - ``ALLOW_EMPTY_MDECL_WRAPPER``. It's initial value is ``False``. - -Now, when you understand, how to call those functions, I will explain what they -return. - -``member_function`` will always return reference to desired declaration. If -declaration could not be found or there are more then one declaration that -match query ``RuntimeError`` exception will be raised. - - - +So, the query methods defined on ``scopedef_t`` class could be used on instances +of ``class_t`` and ``namespace_t`` classes. I am sure you knew that. + +Usage examples +-------------- + +I will explain the usage of ``member_function`` and ``member_functions`` methods. +The usage of other methods is very similar to them. Here is definition of those +methods: +:: + + def member_function( self, + name=None, + function=None, + return_type=None, + arg_types=None, + header_dir=None, + header_file=None, + recursive=None ) + + + def member_functions( self, + name=None, + function=None, + return_type=None, + arg_types=None, + header_dir=None, + header_file=None, + recursive=None, + allow_empty=None ) + +As you can see, from the methods arguments you can search for member function +by: + + * ``name`` + + Python string, that contains member function name or full name. + :: + + do_smth = my_class.member_function( 'do_smth' ) + do_smth = my_class.member_function( 'my_namespace::my_class::do_smth' ) + + * ``function`` + + Python callable object. You would use this functionality, if you need to + build custom query. This object will be called with one argument - declaration, + and it should return ``True`` or ``False``. + :: + + impls = my_class.member_functions( lambda decl: decl.name.endswith( 'impl' ) ) + + ``impls`` will contain all member functions, that their name ends with "impl". + + * ``return_type`` + + Function return type. This argument can be Python string or an object that + describes C++ type. + :: + + mem_funcs = my_class.member_functions( return_type='int' ) + + i = declarations.int_t()`` + ref_i = declarations.reference_t( i ) + const_ref_i = declarations.const_t( ref_i ) + mem_funcs = my_class.member_functions( return_type=const_ref_int ) + + * ``arg_types`` + + Python list that contains description of member function argument types. + This list could be a mix of Python strings and objects that describes C++ + type. Size of list says how many arguments function should have. If you want + to skip some argument type from within comparison, you put ``None``, into + relevant position within the list. + :: + + mem_funcs = my_class.member_functions( arg_types=[ None, 'int'] ) + + ``mem_funcs`` will contain all member functions, that have two arguments + and type of second argument is ``int``. + + * ``header_dir`` + + Python string, that contains full path to directory, which contains file, + which contains the function declaration + + ``mem_funcs = my_namespace.member_functions( header_dir='/home/roman/xyz' )`` + + * ``header_file`` + + Python string, that contains full path to file, which contains the function + declaration. + + ``mem_funcs = my_namespace.member_functions( header_dir='/home/roman/xyz/xyz.hpp' )`` + + * ``recursive`` + + Python boolean object. + + If ``recursive`` is ``True``, then member function will be also searched + within internal declarations. + + If ``recursive`` is ``False``, then member function will be searched only + within current scope. + + What happen if ``recursive`` is ``None``? Well. ``scopedef_t`` class defines + ``RECURSIVE_DEFAULT`` variable. It's initial value is ``True``. So, if you + don't pass ``recursive`` argument, the value of ``RECURSIVE_DEFAULT`` variable + will be used. This "yet another level of indirection" allows you to configure + `pygccxml`_ "select" functions in one place for all project. + + * ``allow_empty`` + + Python boolean object, it says `pygccxml`_ what to do if query returns empty. + + If ``allow_empty`` is ``False``, then exception + ``RuntimeError( "Multi declaration query returned 0 declarations." )`` + will be raised + + ``allow_empty`` uses same technique as ``recursive``, to allow you to customize + the behaviour project-wise. The relevant class variable name is + ``ALLOW_EMPTY_MDECL_WRAPPER``. It's initial value is ``False``. + +Now, when you understand, how to call those functions, I will explain what they +return. + +``member_function`` will always return reference to desired declaration. If +declaration could not be found or there are more then one declaration that +match query ``RuntimeError`` exception will be raised. + +Return value of ``member_functions`` is not Python list or set, but instance +of ``mdecl_wrapper_t`` class. This class allows you to work on all selected +objects at once. I will give an example from another project - `pyplusplus`_. +In order to help `boost.python`_ to manage objects life time, all functions +should have `call policies`_. For example: +:: + + struct A{ + A* clone() const { return new A(); } + ... + }; + + struct B{ + B* clone() const { return new B(); } + ... + }; + +`Call policies`_ of the member function ``clone`` is ``return_value_policy<manage_new_object>()``. +Next code applies `call policies`_ on all ``clone`` member functions within the +project. +:: + + #global_ns - instance of namespace_t class, that contains reference to global namespace + clone = global_ns.member_functions( 'clone' ) + clone.call_policies = return_value_policy( manage_new_object ) + + +Another example, from `pyplusplus`_ project. Sometimes it is desirable to +exclude declaration, from being exported to Python. Next code will exclude +``clone`` member function from being exported: + + ``global_ns.member_functions( 'clone' ).exclude()`` + +As you can see this class allows you to write less code. Basically using this +class you don't have to write loops. If will do it for you. Also if you insist to +write loops, ``mdecl_wrapper_t`` class implements ``__len__``, ``__getitem__`` +and ``__iter__`` methods. So you can write next code: +:: + + for clone in global_ns.member_functions( 'clone' ): + print clone.parent.name + + +---------------------- +Implementation details +---------------------- + +Performance +----------- + +For big projects, performace is critical. When you finished to build/change +declarations tree, then you can call ``scopedef_t.init_optimizer`` method. +This method will initialize few data structures, that will help to minimize the +number of compared declarations. The price you are going to pay is memory usage. + +Data structures +~~~~~~~~~~~~~~~ +Here is a short explanation of what data structures is initialized. + +* ``scopedef_t._type2decls``, ``scopedef_t._type2decls_nr`` + + Python dictionary, that contains mapping between declaration type and + declarations in the current scope. + + ``scopedef_t.type2decls_nr`` contains only declaration from the current scope. + ``scopedef_t.type2decls`` contains declarations from the current scope and its children + +* ``scopedef_t._type2name2decls``, ``scopedef_t._type2name2decls_nr`` + + Python dictionary, that contains mapping between declaration type and + another dictionary. This second dictionary contains mapping between + a declaration name and declaration. + + ``scopedef_t.type2name2decls_nr`` contains only declaration from the current scope. + ``scopedef_t.type2name2decls`` contains declarations from the current scope and its children + +* ``scopedef_t._all_decls`` + + A flat list of all declarations, including declarations from the children scopes. + +Except ``scopedef_t.decl`` and ``scopedef_t.decls`` methods, all other queries +have information about declaration type. + +If you include ``name`` into your query, you will get the best performance. + +---------------- +More information +---------------- + +I think, I gave you all important information. If you need definition of some +query method, you can take a look on API documentation or into source code. + + +.. _`boost.python`: http://boost.org/libs/python/doc/tutorial/doc/html/index.html +.. _`call policies`: http://boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies +.. _`Call policies`: http://boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies .. _`pygccxml`: ./pygccxml.html +.. _`pyplusplus`: ./../pyplusplus/pyplusplus.html .. _`SourceForge`: http://sourceforge.net/index.php .. _`Python`: http://www.python.org .. _`GCC-XML`: http://www.gccxml.org Modified: pygccxml_dev/docs/www_configuration.py =================================================================== --- pygccxml_dev/docs/www_configuration.py 2006-05-25 08:05:00 UTC (rev 164) +++ pygccxml_dev/docs/www_configuration.py 2006-05-27 11:28:07 UTC (rev 165) @@ -1,3 +1,3 @@ name = 'pygccxml' files_to_skip = ['definition.rest'] -names = { 'query_api' : 'query interface' } \ No newline at end of file +names = { 'query_interface' : 'query interface' } \ No newline at end of file Modified: pygccxml_dev/pygccxml/declarations/mdecl_wrapper.py =================================================================== --- pygccxml_dev/pygccxml/declarations/mdecl_wrapper.py 2006-05-25 08:05:00 UTC (rev 164) +++ pygccxml_dev/pygccxml/declarations/mdecl_wrapper.py 2006-05-27 11:28:07 UTC (rev 165) @@ -46,6 +46,9 @@ 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 ) @@ -64,4 +67,7 @@ def __getattr__( self, name ): """@param name: name of method """ - return call_redirector_t( name, self.decls ) \ No newline at end of file + return call_redirector_t( name, self.decls ) + + def __contains__( self, item ): + return item in self.decls This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-25 08:05:21
|
Revision: 164 Author: roman_yakovenko Date: 2006-05-25 01:05:00 -0700 (Thu, 25 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=164&view=rev Log Message: ----------- fixing critical bug with unnamed enums. If you have 2 unnamed enums within same scope, only one enum is reported Modified Paths: -------------- pygccxml_dev/pygccxml/parser/project_reader.py pygccxml_dev/unittests/data/core_cache.hpp pygccxml_dev/unittests/test_all.py Added Paths: ----------- pygccxml_dev/unittests/data/unnamed_enums_bug1.hpp pygccxml_dev/unittests/data/unnamed_enums_bug2.hpp pygccxml_dev/unittests/unnamed_enums_bug_tester.py Modified: pygccxml_dev/pygccxml/parser/project_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/project_reader.py 2006-05-25 06:54:11 UTC (rev 163) +++ pygccxml_dev/pygccxml/parser/project_reader.py 2006-05-25 08:05:00 UTC (rev 164) @@ -324,7 +324,8 @@ def _join_namespaces( self, nsref ): assert isinstance( nsref, pygccxml.declarations.namespace_t ) ddhash = {} # decl.__class__ : { decl.name : [decls] } double declaration hash - decls = [] + decls = [] + for decl in nsref.declarations: if not ddhash.has_key( decl.__class__ ): ddhash[ decl.__class__ ] = { decl._name : [ decl ] } @@ -339,7 +340,12 @@ if decl not in joined_decls[decl._name]: #functions has overloading decls.append( decl ) - joined_decls[decl._name].append( decl ) + joined_decls[decl._name].append( decl ) + elif isinstance( decl, pygccxml.declarations.enumeration_t ): + #unnamed enums + if not decl.name and decl not in joined_decls[decl._name]: + decls.append( decl ) + joined_decls[decl._name].append( decl ) else: assert 1 == len( joined_decls[ decl._name ] ) if isinstance( decl, pygccxml.declarations.namespace_t ): Modified: pygccxml_dev/unittests/data/core_cache.hpp =================================================================== --- pygccxml_dev/unittests/data/core_cache.hpp 2006-05-25 06:54:11 UTC (rev 163) +++ pygccxml_dev/unittests/data/core_cache.hpp 2006-05-25 08:05:00 UTC (rev 164) @@ -22,3 +22,4 @@ #endif//__core_cache_hpp__ +//touch \ No newline at end of file Added: pygccxml_dev/unittests/data/unnamed_enums_bug1.hpp =================================================================== --- pygccxml_dev/unittests/data/unnamed_enums_bug1.hpp (rev 0) +++ pygccxml_dev/unittests/data/unnamed_enums_bug1.hpp 2006-05-25 08:05:00 UTC (rev 164) @@ -0,0 +1,13 @@ +// 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) + +#ifndef __unnamed_enums_bug1_hpp__ +#define __unnamed_enums_bug1_hpp__ + +enum{ x1, x2 }; +enum{ y1, y2 }; + + +#endif//__unnamed_enums_bug1_hpp__ Added: pygccxml_dev/unittests/data/unnamed_enums_bug2.hpp =================================================================== --- pygccxml_dev/unittests/data/unnamed_enums_bug2.hpp (rev 0) +++ pygccxml_dev/unittests/data/unnamed_enums_bug2.hpp 2006-05-25 08:05:00 UTC (rev 164) @@ -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) + +#ifndef __unnamed_enums_bug2_hpp__ +#define __unnamed_enums_bug2_hpp__ + +enum{ z1, z2 }; + +#endif//__unnamed_enums_bug2_hpp__ \ No newline at end of file Modified: pygccxml_dev/unittests/test_all.py =================================================================== --- pygccxml_dev/unittests/test_all.py 2006-05-25 06:54:11 UTC (rev 163) +++ pygccxml_dev/unittests/test_all.py 2006-05-25 08:05:00 UTC (rev 164) @@ -32,7 +32,8 @@ import cache_enums_tester import decl_printer_tester import typedefs_tester -import demangled_tester +import demangled_tester +import unnamed_enums_bug_tester def create_suite(): testers = [ @@ -64,7 +65,8 @@ , cache_enums_tester , decl_printer_tester , typedefs_tester - , demangled_tester + , demangled_tester + , unnamed_enums_bug_tester ] main_suite = unittest.TestSuite() Added: pygccxml_dev/unittests/unnamed_enums_bug_tester.py =================================================================== --- pygccxml_dev/unittests/unnamed_enums_bug_tester.py (rev 0) +++ pygccxml_dev/unittests/unnamed_enums_bug_tester.py 2006-05-25 08:05:00 UTC (rev 164) @@ -0,0 +1,95 @@ +# 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 unittest +import autoconfig +import parser_test_case + +from pygccxml import utils +from pygccxml import parser +from pygccxml import declarations + +class source_reader_tester_t( parser_test_case.parser_test_case_t ): + def __init__(self, *args ): + parser_test_case.parser_test_case_t.__init__( self, *args ) + self.header = 'unnamed_enums_bug1.hpp' + self.global_ns = None + + def setUp(self): + if not self.global_ns: + reader = parser.source_reader_t( self.config ) + decls = reader.read_file( self.header ) + self.global_ns = declarations.get_global_namespace( decls ) + self.global_ns.init_optimizer() + + def test( self ): + names = [] + enums = self.global_ns.enums() + map( lambda enum: names.extend( enum.values.keys() ), enums ) + self.failUnless( len( names ) == 4 ) + self.failUnless( 'x1' in names ) + self.failUnless( 'x2' in names ) + self.failUnless( 'y1' in names ) + self.failUnless( 'y2' in names ) + +class project_reader_1_tester_t( parser_test_case.parser_test_case_t ): + def __init__(self, *args ): + parser_test_case.parser_test_case_t.__init__( self, *args ) + self.header = 'unnamed_enums_bug1.hpp' + self.global_ns = None + + def setUp(self): + if not self.global_ns: + decls = parser.parse( [self.header], self.config ) + self.global_ns = declarations.get_global_namespace( decls ) + self.global_ns.init_optimizer() + + def test( self ): + names = [] + enums = self.global_ns.enums() + map( lambda enum: names.extend( enum.values.keys() ), enums ) + self.failUnless( len( names ) == 4 ) + self.failUnless( 'x1' in names ) + self.failUnless( 'x2' in names ) + self.failUnless( 'y1' in names ) + self.failUnless( 'y2' in names ) + +class project_reader_3_tester_t( parser_test_case.parser_test_case_t ): + def __init__(self, *args ): + parser_test_case.parser_test_case_t.__init__( self, *args ) + self.headers = ['unnamed_enums_bug1.hpp', 'unnamed_enums_bug2.hpp', 'unnamed_enums_bug1.hpp' ] + self.global_ns = None + + def setUp(self): + if not self.global_ns: + decls = parser.parse( self.headers, self.config ) + self.global_ns = declarations.get_global_namespace( decls ) + self.global_ns.init_optimizer() + + def test( self ): + names = [] + enums = self.global_ns.enums() + map( lambda enum: names.extend( enum.values.keys() ), enums ) + self.failUnless( len( names ) == 6 ) + self.failUnless( 'x1' in names ) + self.failUnless( 'x2' in names ) + self.failUnless( 'y1' in names ) + self.failUnless( 'y2' in names ) + self.failUnless( 'z1' in names ) + self.failUnless( 'z2' in names ) + + +def create_suite(): + suite = unittest.TestSuite() + suite.addTest( unittest.makeSuite(source_reader_tester_t)) + suite.addTest( unittest.makeSuite(project_reader_1_tester_t)) + suite.addTest( unittest.makeSuite(project_reader_3_tester_t)) + return suite + +def run_suite(): + unittest.TextTestRunner(verbosity=2).run( create_suite() ) + +if __name__ == "__main__": + run_suite() \ 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-05-25 06:54:22
|
Revision: 163 Author: roman_yakovenko Date: 2006-05-24 23:54:11 -0700 (Wed, 24 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=163&view=rev Log Message: ----------- updating docs Modified Paths: -------------- pygccxml_dev/docs/www_configuration.py Added Paths: ----------- pygccxml_dev/docs/query_interface.rest Removed Paths: ------------- pygccxml_dev/docs/query_api.rest Deleted: pygccxml_dev/docs/query_api.rest =================================================================== --- pygccxml_dev/docs/query_api.rest 2006-05-24 20:36:00 UTC (rev 162) +++ pygccxml_dev/docs/query_api.rest 2006-05-25 06:54:11 UTC (rev 163) @@ -1,91 +0,0 @@ -=============================== -pygccxml.declarations query API -=============================== - -.. contents:: Table of contents - ------------- -Introduction ------------- -You parsed the source files. Now you have to do some real work with the extracted -information, right? `pygccxml`_ provides very powerful and simple interface to -query about extracted declrations. - -Just an example. I want to select all member functions, that have 2 arguments. -I don't care about first argument type, but I do want second argument type to be -a reference to an integer. More over, I want those functions names to end with -"impl" string and they should be protected or private. -:: - - #global_ns is the reference to an instance of namespace_t object, that - #represents global namespace - query = declarations.custom_matcher_t( lambda mem_fun: mem_fun.name.endswith( 'impl' ) - query = query & ~declarations.access_type_matcher_t( 'public' ) - global_ns.member_functions( function=query, arg_types=[None, 'int &'] ) - -As for me, the example I gave was too complex. In many cases you will find your -self looking for one or many declarations using one or two properties of that -declaration(s). For example: -:: - - global_ns.namespaces( 'details' ) - -This call will return all namespaces with name 'details'. - --------------- -User interface --------------- - -As you already know, ``pygccxml.declarations`` packages defines next classes: - -* ``scopedef_t`` - base class for all classes, that can contain other declarations - -* ``namespace_t`` - derives from ``scopedef_t`` class, represents C++ namespace - -* ``class_t`` - derives from ``scopedef_t`` class, represents C++ class/struct. - -So, the query methods defined on ``scopedef_t`` class could be used on instances -of ``class_t`` and ``namespace_t`` classes. - -I will explain the usage of ``member_function`` and ``member_functions`` methods. -The usage of other methods is very similar to them. Here is definition of those -methods: -:: - - def member_function( self, - name=None, - function=None, - return_type=None, - arg_types=None, - header_dir=None, - header_file=None, - recursive=None ) - - def member_functions( self, - name=None, - function=None, - return_type=None, - arg_types=None, - header_dir=None, - header_file=None, - recursive=None, - allow_empty=None ) - - - - -.. _`pygccxml`: ./pygccxml.html -.. _`SourceForge`: http://sourceforge.net/index.php -.. _`Python`: http://www.python.org -.. _`GCC-XML`: http://www.gccxml.org -.. _`UML diagram` : ./declarations_uml.png -.. _`parser package UML diagram` : ./parser_uml.png -.. _`ReleaseForge` : http://releaseforge.sourceforge.net -.. _`boost::type_traits` : http://www.boost.org/libs/type_traits/index.html -.. - Local Variables: - mode: indented-text - indent-tabs-mode: nil - sentence-end-double-space: t - fill-column: 70 - End: \ No newline at end of file Copied: pygccxml_dev/docs/query_interface.rest (from rev 162, pygccxml_dev/docs/query_api.rest) =================================================================== --- pygccxml_dev/docs/query_interface.rest (rev 0) +++ pygccxml_dev/docs/query_interface.rest 2006-05-25 06:54:11 UTC (rev 163) @@ -0,0 +1,185 @@ +=============================== +pygccxml.declarations query API +=============================== + +.. contents:: Table of contents + +------------ +Introduction +------------ +You parsed the source files. Now you have to do some real work with the extracted +information, right? `pygccxml`_ provides very powerful and simple interface to +query about extracted declrations. + +Just an example. I want to select all member functions, that have 2 arguments. +I don't care about first argument type, but I do want second argument type to be +a reference to an integer. More over, I want those functions names to end with +"impl" string and they should be protected or private. +:: + + #global_ns is the reference to an instance of namespace_t object, that + #represents global namespace + query = declarations.custom_matcher_t( lambda mem_fun: mem_fun.name.endswith( 'impl' ) + query = query & ~declarations.access_type_matcher_t( 'public' ) + global_ns.member_functions( function=query, arg_types=[None, 'int &'] ) + +As for me, the example I gave was too complex. In many cases you will find your +self looking for one or many declarations using one or two properties of that +declaration(s). For example: +:: + + global_ns.namespaces( 'details' ) + +This call will return all namespaces with name 'details'. + +-------------- +User interface +-------------- + +As you already know, ``pygccxml.declarations`` packages defines next classes: + +* ``scopedef_t`` - base class for all classes, that can contain other declarations + +* ``namespace_t`` - derives from ``scopedef_t`` class, represents C++ namespace + +* ``class_t`` - derives from ``scopedef_t`` class, represents C++ class/struct. + +So, the query methods defined on ``scopedef_t`` class could be used on instances +of ``class_t`` and ``namespace_t`` classes. + +I will explain the usage of ``member_function`` and ``member_functions`` methods. +The usage of other methods is very similar to them. Here is definition of those +methods: +:: + + def member_function( self, + name=None, + function=None, + return_type=None, + arg_types=None, + header_dir=None, + header_file=None, + recursive=None ) + + + def member_functions( self, + name=None, + function=None, + return_type=None, + arg_types=None, + header_dir=None, + header_file=None, + recursive=None, + allow_empty=None ) + +As you can see, from the methods arguments you can search for member function +by: + + * ``name`` + + Python string, that contains member function name or full name. + + ``do_smth = my_class.member_function( 'do_smth' )`` + ``do_smth = my_class.member_function( 'my_namespace::my_class::do_smth' )`` + + * ``function`` + + Python callable object. You would use this functionality, if you need to + build custom query. This object will be called with one argument - declaration, + and it should return ``True`` or ``False``. + + ``impls = my_class.member_functions( lambda decl: decl.name.endswith( 'impl' ) )`` + + ``impls`` will contain all member functions, that thier name ends with "impl". + + * ``return_type`` + + Function return type. This argument can be Python string or an object that + describes C++ type. + + ``mem_funcs = my_class.member_functions( return_type='int' )`` + + ``i = declarations.int_t()`` + ``ref_i = declarations.reference_t( i )`` + ``const_ref_i = declarations.const_t( ref_i )`` + ``mem_funcs = my_class.member_functions( return_type=const_ref_int )`` + + * ``arg_types`` + + Python list that contains description of member function argument types. + This list could be a mix of Python strings and objects that describes C++ + type. Size of list says how many arguments function should have. If you want + to skip some argument type from within comparison, you put ``None``, into + relevant position within the list. + + ``mem_funcs = my_class.member_functions( arg_types=[ None, 'int'] )`` + + ``mem_funcs`` will contain all member functions, that have two arguments + and type of second argument is ``int``. + + * ``header_dir`` + + Python string, that contains full path to directory, which contains file, + which contains the function declaration + + ``mem_funcs = my_namespace.member_functions( header_dir='/home/roman/xyz' )`` + + * ``header_file`` + + Python string, that contains full path to file, which contains the function + declaration. + + ``mem_funcs = my_namespace.member_functions( header_dir='/home/roman/xyz/xyz.hpp' )`` + + * ``recursive`` + + Python boolean object. + + If ``recursive`` is ``True``, then member function will be also searched + within internal declarations. + + If ``recursive`` is ``False``, then member function will be searched only + within current scope. + + What happen if ``recursive`` is ``None``? Well. ``scopedef_t`` class defines + ``RECURSIVE_DEFAULT`` variable. It's initial value is ``True``. So, if you + don't pass ``recursive`` argument, the value of ``RECURSIVE_DEFAULT`` variable + will be used. This "yet another level of indirection" allows you to configure + `pygccxml`_ "select" functions in one place for all project. + + * ``allow_empty`` + + Python boolean object, it says `pygccxml`_ what to do if query returns empty. + + If ``allow_empty`` is ``False``, then exception + ``RuntimeError( "Multi declaration query returned 0 declarations." )`` + will be raised + + ``allow_empty`` uses same tehnique as ``recursive``, to allow you to customize + the behaviour project-wise. The relevant class variable name is + ``ALLOW_EMPTY_MDECL_WRAPPER``. It's initial value is ``False``. + +Now, when you understand, how to call those functions, I will explain what they +return. + +``member_function`` will always return reference to desired declaration. If +declaration could not be found or there are more then one declaration that +match query ``RuntimeError`` exception will be raised. + + + +.. _`pygccxml`: ./pygccxml.html +.. _`SourceForge`: http://sourceforge.net/index.php +.. _`Python`: http://www.python.org +.. _`GCC-XML`: http://www.gccxml.org +.. _`UML diagram` : ./declarations_uml.png +.. _`parser package UML diagram` : ./parser_uml.png +.. _`ReleaseForge` : http://releaseforge.sourceforge.net +.. _`boost::type_traits` : http://www.boost.org/libs/type_traits/index.html +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + End: \ No newline at end of file Modified: pygccxml_dev/docs/www_configuration.py =================================================================== --- pygccxml_dev/docs/www_configuration.py 2006-05-24 20:36:00 UTC (rev 162) +++ pygccxml_dev/docs/www_configuration.py 2006-05-25 06:54:11 UTC (rev 163) @@ -1,2 +1,3 @@ name = 'pygccxml' -files_to_skip = ['definition.rest'] \ No newline at end of file +files_to_skip = ['definition.rest'] +names = { 'query_api' : 'query interface' } \ 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-05-24 20:36:15
|
Revision: 162 Author: roman_yakovenko Date: 2006-05-24 13:36:00 -0700 (Wed, 24 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=162&view=rev Log Message: ----------- commiting full implementation ( no unittests ) for member variable references - small bg fixes Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/member_variable.py pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp Modified: pyplusplus_dev/pyplusplus/code_creators/member_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-05-24 20:19:26 UTC (rev 161) +++ pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-05-24 20:36:00 UTC (rev 162) @@ -510,7 +510,7 @@ def _get_getter_type(self): return declarations.free_function_type_t( return_type=self._get_exported_var_type() - , arguments_types=[ self._get_class_inst_type() ] ) + , arguments_types=[ declarations.reference_t( self._get_class_inst_type() ) ] ) getter_type = property( _get_getter_type ) def _get_setter_full_name(self): @@ -520,7 +520,8 @@ def _get_setter_type(self): return declarations.free_function_type_t( return_type=declarations.void_t() - , arguments_types=[ self._get_class_inst_type(), self._get_exported_var_type() ] ) + , arguments_types=[ declarations.reference_t( self._get_class_inst_type() ) + , self._get_exported_var_type() ] ) setter_type = property( _get_setter_type ) def _get_has_setter( self ): Modified: pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp 2006-05-24 20:19:26 UTC (rev 161) +++ pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp 2006-05-24 20:36:00 UTC (rev 162) @@ -118,6 +118,18 @@ const int& m_i; }; +struct A{}; + + +struct B { + B( A& a_ ): a( a_ ){} + A& a; +}; + +struct C { + C( A& a_ ): a( a_ ){} + const A& a; +}; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-24 20:19:44
|
Revision: 161 Author: roman_yakovenko Date: 2006-05-24 13:19:26 -0700 (Wed, 24 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=161&view=rev Log Message: ----------- commiting full implementation ( no unittests ) for member variable references Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/class_declaration.py pyplusplus_dev/pyplusplus/code_creators/member_variable.py pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py pyplusplus_dev/pyplusplus/module_builder/builder.py pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py pyplusplus_dev/pyplusplus/module_creator/creator.py Modified: pyplusplus_dev/pyplusplus/code_creators/class_declaration.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/class_declaration.py 2006-05-24 12:36:11 UTC (rev 160) +++ pyplusplus_dev/pyplusplus/code_creators/class_declaration.py 2006-05-24 20:19:26 UTC (rev 161) @@ -13,6 +13,7 @@ import declaration_based import array_1_registrator import indexing_suites +import member_variable from pygccxml import declarations class class_t( scoped.scoped_t ): @@ -189,6 +190,9 @@ if isinstance( inst, indexing_suites.indexing_suite_t ): return True + if isinstance( inst, member_variable.mem_var_ref_t ): + return True + return False def _get_class_var_name(self): Modified: pyplusplus_dev/pyplusplus/code_creators/member_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-05-24 12:36:11 UTC (rev 160) +++ pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-05-24 20:19:26 UTC (rev 161) @@ -416,10 +416,6 @@ return os.linesep.join( answer ) - - - - class mem_var_ref_t( member_variable_base_t ): """ Creates C++ code that creates accessor for class member variable, that has type reference. @@ -429,34 +425,48 @@ , variable=variable , wrapper=wrapper , parent=parent) + self.param_sep = os.linesep + self.indent( self.PARAM_SEPARATOR, 2 ) - def _create_impl( self ): - if self.declaration.type_qualifiers.has_static: - add_property = 'add_static_property' + def _create_getter( self ): + answer = ['def'] + answer.append( '( ' ) + answer.append( '"get_%s"' % self.alias) + answer.append( self.param_sep ) + answer.append( '(%s)(&%s)' + % ( self.wrapper.getter_type.decl_string, self.wrapper.getter_full_name ) ) + if self.declaration.getter_call_policies: + answer.append( self.param_sep ) + answer.append( self.declaration.getter_call_policies.create( self ) ) else: - add_property = 'add_property' - answer = [ add_property ] + answer.append( os.linesep + self.indent( '/* undefined call policies */', 2 ) ) + answer.append( ' )' ) + return ''.join( answer ) + + def _create_setter( self ): + answer = ['def'] answer.append( '( ' ) - answer.append('"%s"' % self.alias) - answer.append( self.PARAM_SEPARATOR ) + answer.append( '"set_%s"' % self.alias) + answer.append( self.param_sep ) answer.append( '(%s)(&%s)' - % ( self.wrapper.getter_type.decl_string, self.wrapper.getter_full_name ) ) - + % ( self.wrapper.setter_type.decl_string, self.wrapper.setter_full_name ) ) + if self.declaration.setter_call_policies: + answer.append( self.param_sep ) + answer.append( self.declaration.setter_call_policies.create( self ) ) + else: + answer.append( os.linesep + self.indent( '/* undefined call policies */', 2 ) ) + answer.append( ' )' ) + return ''.join( answer ) + + def _create_impl( self ): + #TODO: fix me, should not force class scope usage + answer = [] + class_var_name = self.parent.class_var_name + answer.append( "%s.%s;" % (class_var_name, self._create_getter() ) ) if self.wrapper.has_setter: - answer.append( self.PARAM_SEPARATOR ) - answer.append( '(%s)(&%s)' - % ( self.wrapper.setter_type.decl_string, self.wrapper.setter_full_name ) ) - answer.append( ' ) ' ) - - code = ''.join( answer ) - if len( code ) <= self.LINE_LENGTH: - return code - else: - for i in range( len( answer ) ): - if answer[i] == self.PARAM_SEPARATOR: - answer[i] = os.linesep + self.indent( self.indent( self.indent( answer[i] ) ) ) - return ''.join( answer ) - + answer.append( os.linesep ) + answer.append( "%s.%s;" % (class_var_name, self._create_setter() ) ) + return ''.join( answer ) + class mem_var_ref_wrapper_t( declaration_based.declaration_based_t ): """ Creates C++ code that creates accessor for class member variable, that has type reference. @@ -514,14 +524,28 @@ setter_type = property( _get_setter_type ) def _get_has_setter( self ): - if declarations.is_fundamental( self._get_exported_var_type() ): + if declarations.is_const( declarations.remove_reference( self.declaration.type ) ): + return False + elif declarations.is_fundamental( self._get_exported_var_type() ): return True elif declarations.is_enum( self._get_exported_var_type() ): return True - elif declarations.is_const( declarations.remove_reference( self.declaration.type ) ): - return False else: - return True + pass + + no_ref = declarations.remove_reference( self.declaration.type ) + no_const = declarations.remove_const( no_ref ) + base_type = declarations.remove_alias( no_const ) + if not isinstance( base_type, declarations.declarated_t ): + return True #TODO ???? + decl = base_type.declaration + if decl.is_abstract: + return False + if declarations.has_destructor( decl ) and not declarations.has_public_destructor( decl ): + return False + if not declarations.has_trivial_copy(decl): + return False + return True has_setter = property( _get_has_setter ) def _create_impl(self): Modified: pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-05-24 12:36:11 UTC (rev 160) +++ pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-05-24 20:19:26 UTC (rev 161) @@ -10,25 +10,33 @@ def __init__(self, *arguments, **keywords): declarations.variable_t.__init__(self, *arguments, **keywords ) decl_wrapper.decl_wrapper_t.__init__( self ) - self._call_policies = None - - def _get_call_policies( self ): - return self._call_policies - def _set_call_policies( self, call_policies ): - self._call_policies = call_policies + self._getter_call_policies = None + self._setter_call_policies = None + + __call_policies_doc__ = \ + """There are usecase, when exporting member variable forces pyplusplus 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, pyplusplus 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. + """ - __call_policies_doc__ = \ - """There are usecase, when exporting member variable forces pyplusplus 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, pyplusplus 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. - """ - call_policies = property( _get_call_policies, _set_call_policies - , doc=__call_policies_doc__ ) + def get_getter_call_policies( self ): + return self._getter_call_policies + def set_getter_call_policies( self, call_policies ): + self._getter_call_policies = call_policies + getter_call_policies = property( get_getter_call_policies, set_getter_call_policies + , doc=__call_policies_doc__ ) + def get_setter_call_policies( self ): + return self._setter_call_policies + def set_setter_call_policies( self, call_policies ): + self._setter_call_policies = call_policies + setter_call_policies = property( get_setter_call_policies, set_setter_call_policies + , doc=__call_policies_doc__ ) + def _exportable_impl( self ): if not isinstance( self.parent, declarations.class_t ): return '' Modified: pyplusplus_dev/pyplusplus/module_builder/builder.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-05-24 12:36:11 UTC (rev 160) +++ pyplusplus_dev/pyplusplus/module_builder/builder.py 2006-05-24 20:19:26 UTC (rev 161) @@ -135,6 +135,13 @@ , flatten_decls ) map( lambda calldef: calldef.set_call_policies( call_policies_resolver( calldef ) ) , calldefs ) + mem_vars = filter( lambda decl: isinstance( decl, decls_package.variable_t ) + and isinstance( decl.parent, decls_package.class_t ) + , flatten_decls ) + map( lambda mem_var: mem_var.set_getter_call_policies( call_policies_resolver( mem_var, 'get' ) ) + , mem_vars ) + map( lambda mem_var: mem_var.set_setter_call_policies( call_policies_resolver( mem_var, 'set' ) ) + , mem_vars ) def print_declarations(self, decl=None, detailed=True, recursive=True, writer=sys.stdout.write): """ Modified: pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py 2006-05-24 12:36:11 UTC (rev 160) +++ pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py 2006-05-24 20:19:26 UTC (rev 161) @@ -11,7 +11,7 @@ def __init__( self ): object.__init__( self ) - def __call__(self, decl): + def __call__(self, decl, hint=None): raise NotImplementedError() class default_policy_resolver_t(resolver_t): @@ -30,7 +30,7 @@ return decl_wrappers.default_call_policies() return None - def __call__(self, calldef): + def __call__(self, calldef, hint=None): if not isinstance( calldef, declarations.calldef_t ): return None @@ -46,7 +46,7 @@ def __init__( self ): resolver_t.__init__( self ) - def __call__( self, calldef ): + def __call__( self, calldef, hint=None ): if not isinstance( calldef, declarations.calldef_t ): return None @@ -66,7 +66,7 @@ self.__const_wchar_pointer \ = declarations.pointer_t( declarations.const_t( declarations.wchar_t() ) ) - def __call__(self, calldef): + def __call__(self, calldef, hint=None): if not isinstance( calldef, declarations.calldef_t ): return None @@ -87,7 +87,7 @@ def __init__( self ): resolver_t.__init__( self ) - def __call__(self, calldef): + def __call__(self, calldef, hint=None): if not isinstance( calldef, declarations.calldef_t ): return None @@ -112,23 +112,43 @@ def __init__( self ): resolver_t.__init__( self ) - def __init__( self, variable ): + def __call__( self, variable, hint=None ): if not isinstance( variable, declarations.variable_t ): return None + + assert hint in ( 'get', 'set' ) if not declarations.is_reference( variable.type ): return None - no_ref = declarations.remove_reference( self.declaration.type ) + no_ref = declarations.remove_reference( variable.type ) base_type = declarations.remove_const( no_ref ) if declarations.is_fundamental( base_type ) or declarations.is_enum( base_type ): #the relevant code creator will generate code, that will return this member variable #by value - return decl_wrappers.default_call_policies() - - - return self.declaration.type - + return decl_wrappers.default_call_policies() + + if not isinstance( base_type, declarations.declarated_t ): + return None + + base_type = declarations.remove_alias( base_type ) + decl = base_type.declaration + + if decl.is_abstract: + return None + if declarations.has_destructor( decl ) and not declarations.has_public_destructor( decl ): + return None + if not declarations.has_trivial_copy(decl): + return None + if hint == 'get': + #if we rich this line, it means that we are able to create an obect using + #copy constructor. + if declarations.is_const( no_ref ): + return decl_wrappers.return_value_policy( decl_wrappers.copy_const_reference ) + else: + return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference ) + else: + return decl_wrappers.default_call_policies() class built_in_resolver_t(resolver_t): def __init__( self, config=None): @@ -139,10 +159,11 @@ if not config or config.boost_python_supports_void_ptr: self.__resolvers.append( void_pointer_resolver_t() ) self.__resolvers.append( return_internal_reference_resolver_t() ) + self.__resolvers.append( variable_accessors_resolver_t() ) - def __call__( self, calldef ): + def __call__( self, calldef, hint=None ): for resolver in self.__resolvers: - resolved = resolver( calldef ) + resolved = resolver( calldef, hint ) if resolved: return resolved return None Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-05-24 12:36:11 UTC (rev 160) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-05-24 20:19:26 UTC (rev 161) @@ -664,6 +664,10 @@ wrapper = code_creators.member_variable_wrapper_t( variable=self.curr_decl ) maker = code_creators.member_variable_t( variable=self.curr_decl, wrapper=wrapper ) elif declarations.is_reference( self.curr_decl.type ): + if None is self.curr_decl.getter_call_policies: + self.curr_decl.getter_call_policies = self.__call_policies_resolver( self.curr_decl, 'get' ) + 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 ) else: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-24 12:36:37
|
Revision: 160 Author: roman_yakovenko Date: 2006-05-24 05:36:11 -0700 (Wed, 24 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=160&view=rev Log Message: ----------- implementing first draft of member variable references Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/member_variable.py pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/unittests/member_variables_tester.py Modified: pyplusplus_dev/pyplusplus/code_creators/member_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-05-23 21:11:16 UTC (rev 159) +++ pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-05-24 12:36:11 UTC (rev 160) @@ -464,7 +464,7 @@ indent = declaration_based.declaration_based_t.indent GET_TEMPLATE = os.linesep.join([ - 'static %(type)s get_%(name)s(%(class_type)s& inst) {' + 'static %(type)s get_%(name)s( %(class_type)s& inst ) {' , indent( 'return inst.%(name)s;' ) , '}' , '' @@ -488,10 +488,18 @@ def _get_class_inst_type( self ): return declarations.declarated_t( self.declaration.parent ) + + def _get_exported_var_type( self ): + type_ = declarations.remove_reference( self.declaration.type ) + type_ = declarations.remove_const( type_ ) + if declarations.is_fundamental( type_ ) or declarations.is_enum( type_ ): + return type_ + else: + return self.declaration.type def _get_getter_type(self): return declarations.free_function_type_t( - return_type=self.declaration.type + return_type=self._get_exported_var_type() , arguments_types=[ self._get_class_inst_type() ] ) getter_type = property( _get_getter_type ) @@ -501,19 +509,26 @@ def _get_setter_type(self): return declarations.free_function_type_t( - return_type=self.declaration.type - , arguments_types=[ self._get_class_inst_type(), self.declaration.type ] ) + return_type=declarations.void_t() + , arguments_types=[ self._get_class_inst_type(), self._get_exported_var_type() ] ) setter_type = property( _get_setter_type ) - def _get_has_setter( self ): - return not declarations.is_const( self.declaration.type ) + def _get_has_setter( self ): + if declarations.is_fundamental( self._get_exported_var_type() ): + return True + elif declarations.is_enum( self._get_exported_var_type() ): + return True + elif declarations.is_const( declarations.remove_reference( self.declaration.type ) ): + return False + else: + return True has_setter = property( _get_has_setter ) def _create_impl(self): answer = [] cls_type = algorithm.create_identifier( self, self.declaration.parent.decl_string ) - substitutions = dict( type=self.declaration.type.decl_string + substitutions = dict( type=self._get_exported_var_type().decl_string , class_type=cls_type , name=self.declaration.name ) answer.append( self.GET_TEMPLATE % substitutions ) Modified: pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-05-23 21:11:16 UTC (rev 159) +++ pyplusplus_dev/pyplusplus/decl_wrappers/variable_wrapper.py 2006-05-24 12:36:11 UTC (rev 160) @@ -9,8 +9,26 @@ class variable_t(decl_wrapper.decl_wrapper_t, declarations.variable_t): def __init__(self, *arguments, **keywords): declarations.variable_t.__init__(self, *arguments, **keywords ) - decl_wrapper.decl_wrapper_t.__init__( self ) - + decl_wrapper.decl_wrapper_t.__init__( self ) + self._call_policies = None + + def _get_call_policies( self ): + return self._call_policies + def _set_call_policies( self, call_policies ): + self._call_policies = call_policies + + __call_policies_doc__ = \ + """There are usecase, when exporting member variable forces pyplusplus 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, pyplusplus 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. + """ + call_policies = property( _get_call_policies, _set_call_policies + , doc=__call_policies_doc__ ) + def _exportable_impl( self ): if not isinstance( self.parent, declarations.class_t ): return '' Modified: pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py 2006-05-23 21:11:16 UTC (rev 159) +++ pyplusplus_dev/pyplusplus/module_creator/call_policies_resolver.py 2006-05-24 12:36:11 UTC (rev 160) @@ -11,7 +11,7 @@ def __init__( self ): object.__init__( self ) - def __call__(self, calldef): + def __call__(self, decl): raise NotImplementedError() class default_policy_resolver_t(resolver_t): @@ -31,7 +31,9 @@ return None def __call__(self, calldef): - assert isinstance( calldef, declarations.calldef_t ) + if not isinstance( calldef, declarations.calldef_t ): + return None + if not isinstance( calldef, declarations.constructor_t ): return self._resolve_by_type( calldef.return_type ) else: @@ -45,7 +47,9 @@ resolver_t.__init__( self ) def __call__( self, calldef ): - assert isinstance( calldef, declarations.calldef_t ) + if not isinstance( calldef, declarations.calldef_t ): + return None + if isinstance( calldef, declarations.constructor_t ): return None return_type = declarations.remove_alias( calldef.return_type ) @@ -63,7 +67,9 @@ = declarations.pointer_t( declarations.const_t( declarations.wchar_t() ) ) def __call__(self, calldef): - assert isinstance( calldef, declarations.calldef_t ) + if not isinstance( calldef, declarations.calldef_t ): + return None + if isinstance( calldef, declarations.constructor_t ): return None @@ -82,6 +88,9 @@ resolver_t.__init__( self ) def __call__(self, calldef): + if not isinstance( calldef, declarations.calldef_t ): + return None + if not isinstance( calldef, declarations.member_operator_t ): return None @@ -98,7 +107,29 @@ return decl_wrappers.return_value_policy( decl_wrappers.copy_non_const_reference ) else: return decl_wrappers.return_internal_reference() - + +class variable_accessors_resolver_t( resolver_t ): + def __init__( self ): + resolver_t.__init__( self ) + + def __init__( self, variable ): + if not isinstance( variable, declarations.variable_t ): + return None + + if not declarations.is_reference( variable.type ): + return None + + no_ref = declarations.remove_reference( self.declaration.type ) + base_type = declarations.remove_const( no_ref ) + if declarations.is_fundamental( base_type ) or declarations.is_enum( base_type ): + #the relevant code creator will generate code, that will return this member variable + #by value + return decl_wrappers.default_call_policies() + + + return self.declaration.type + + class built_in_resolver_t(resolver_t): def __init__( self, config=None): resolver_t.__init__( self ) Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-05-23 21:11:16 UTC (rev 159) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-05-24 12:36:11 UTC (rev 160) @@ -251,8 +251,8 @@ return True if declarations.is_pointer( member.type ): return True - #if declarations.is_reference( member.type ): - #return True + if declarations.is_reference( member.type ): + return True if declarations.is_array( member.type ): return True if isinstance( member, declarations.class_t ): @@ -663,9 +663,9 @@ elif declarations.is_pointer( self.curr_decl.type ): wrapper = code_creators.member_variable_wrapper_t( variable=self.curr_decl ) maker = code_creators.member_variable_t( variable=self.curr_decl, wrapper=wrapper ) - #elif declarations.is_reference( self.curr_decl.type ): - #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 ) + elif declarations.is_reference( self.curr_decl.type ): + 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 ) else: maker = code_creators.member_variable_t( variable=self.curr_decl ) if wrapper: Modified: pyplusplus_dev/unittests/member_variables_tester.py =================================================================== --- pyplusplus_dev/unittests/member_variables_tester.py 2006-05-23 21:11:16 UTC (rev 159) +++ pyplusplus_dev/unittests/member_variables_tester.py 2006-05-24 12:36:11 UTC (rev 160) @@ -18,7 +18,8 @@ , *args ) def customize(self, mb ): - mb.variable( 'prefered_color' ).alias = 'PreferedColor' + mb.variable( 'prefered_color' ).alias = 'PreferedColor' + mb.classes().always_expose_using_scope = True def change_default_color( self, module ): module.point.default_color = module.point.color.blue This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-23 21:11:28
|
Revision: 159 Author: roman_yakovenko Date: 2006-05-23 14:11:16 -0700 (Tue, 23 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=159&view=rev Log Message: ----------- commiting partial implementation for member variable references Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/__init__.py pyplusplus_dev/pyplusplus/code_creators/global_variable.py pyplusplus_dev/pyplusplus/code_creators/member_variable.py pyplusplus_dev/pyplusplus/module_creator/creator.py pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2006-05-23 20:19:51 UTC (rev 158) +++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2006-05-23 21:11:16 UTC (rev 159) @@ -83,6 +83,8 @@ from member_variable import bit_field_wrapper_t from member_variable import array_mv_t from member_variable import array_mv_wrapper_t +from member_variable import mem_var_ref_t +from member_variable import mem_var_ref_wrapper_t from class_declaration import class_t from class_declaration import class_wrapper_t Modified: pyplusplus_dev/pyplusplus/code_creators/global_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/global_variable.py 2006-05-23 20:19:51 UTC (rev 158) +++ pyplusplus_dev/pyplusplus/code_creators/global_variable.py 2006-05-23 21:11:16 UTC (rev 159) @@ -11,6 +11,7 @@ from pyplusplus import code_repository from pyplusplus.decl_wrappers import call_policies +#TODO: if variable is not const, then export it using boost::python::ptr class global_variable_base_t( declaration_based.declaration_based_t ): """ Base class for all global variables code creators. Mainly exists to Modified: pyplusplus_dev/pyplusplus/code_creators/member_variable.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-05-23 20:19:51 UTC (rev 158) +++ pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2006-05-23 21:11:16 UTC (rev 159) @@ -415,3 +415,108 @@ answer.append('}') return os.linesep.join( answer ) + + + + + +class mem_var_ref_t( member_variable_base_t ): + """ + Creates C++ code that creates accessor for class member variable, that has type reference. + """ + def __init__(self, variable, wrapper, parent=None ): + member_variable_base_t.__init__( self + , variable=variable + , wrapper=wrapper + , parent=parent) + + def _create_impl( self ): + if self.declaration.type_qualifiers.has_static: + add_property = 'add_static_property' + else: + add_property = 'add_property' + answer = [ add_property ] + answer.append( '( ' ) + answer.append('"%s"' % self.alias) + answer.append( self.PARAM_SEPARATOR ) + answer.append( '(%s)(&%s)' + % ( self.wrapper.getter_type.decl_string, self.wrapper.getter_full_name ) ) + + if self.wrapper.has_setter: + answer.append( self.PARAM_SEPARATOR ) + answer.append( '(%s)(&%s)' + % ( self.wrapper.setter_type.decl_string, self.wrapper.setter_full_name ) ) + answer.append( ' ) ' ) + + code = ''.join( answer ) + if len( code ) <= self.LINE_LENGTH: + return code + else: + for i in range( len( answer ) ): + if answer[i] == self.PARAM_SEPARATOR: + answer[i] = os.linesep + self.indent( self.indent( self.indent( answer[i] ) ) ) + return ''.join( answer ) + +class mem_var_ref_wrapper_t( declaration_based.declaration_based_t ): + """ + Creates C++ code that creates accessor for class member variable, that has type reference. + """ + + indent = declaration_based.declaration_based_t.indent + GET_TEMPLATE = os.linesep.join([ + 'static %(type)s get_%(name)s(%(class_type)s& inst) {' + , indent( 'return inst.%(name)s;' ) + , '}' + , '' + ]) + + SET_TEMPLATE = os.linesep.join([ + 'static void set_%(name)s( %(class_type)s& inst, %(type)s new_value ){ ' + , indent( 'inst.%(name)s = new_value;' ) + , '}' + , '' + ]) + + def __init__(self, variable, parent=None ): + declaration_based.declaration_based_t.__init__( self + , parent=parent + , declaration=variable) + + def _get_getter_full_name(self): + return self.parent.full_name + '::' + 'get_' + self.declaration.name + getter_full_name = property( _get_getter_full_name ) + + def _get_class_inst_type( self ): + return declarations.declarated_t( self.declaration.parent ) + + def _get_getter_type(self): + return declarations.free_function_type_t( + return_type=self.declaration.type + , arguments_types=[ self._get_class_inst_type() ] ) + getter_type = property( _get_getter_type ) + + def _get_setter_full_name(self): + return self.parent.full_name + '::' + 'set_' + self.declaration.name + setter_full_name = property(_get_setter_full_name) + + def _get_setter_type(self): + return declarations.free_function_type_t( + return_type=self.declaration.type + , arguments_types=[ self._get_class_inst_type(), self.declaration.type ] ) + setter_type = property( _get_setter_type ) + + def _get_has_setter( self ): + return not declarations.is_const( self.declaration.type ) + has_setter = property( _get_has_setter ) + + def _create_impl(self): + answer = [] + cls_type = algorithm.create_identifier( self, self.declaration.parent.decl_string ) + + substitutions = dict( type=self.declaration.type.decl_string + , class_type=cls_type + , name=self.declaration.name ) + answer.append( self.GET_TEMPLATE % substitutions ) + if self.has_setter: + answer.append( self.SET_TEMPLATE % substitutions ) + return os.linesep.join( answer ) Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-05-23 20:19:51 UTC (rev 158) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-05-23 21:11:16 UTC (rev 159) @@ -251,6 +251,8 @@ return True if declarations.is_pointer( member.type ): return True + #if declarations.is_reference( member.type ): + #return True if declarations.is_array( member.type ): return True if isinstance( member, declarations.class_t ): Modified: pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp 2006-05-23 20:19:51 UTC (rev 158) +++ pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp 2006-05-23 21:11:16 UTC (rev 159) @@ -105,6 +105,20 @@ } +namespace reference{ + +enum EFruit{ apple, orange }; + +struct fundamental_t{ + fundamental_t( EFruit& fruit, const int& i ) + : m_fruit( fruit ), m_i( i ) + {} + + EFruit& m_fruit; + const int& m_i; +}; + } +} #endif//__member_variables_to_be_exported_hpp__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-23 20:19:58
|
Revision: 158 Author: roman_yakovenko Date: 2006-05-23 13:19:51 -0700 (Tue, 23 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=158&view=rev Log Message: ----------- fixing bug with hierarchy level 3 - updating change history Modified Paths: -------------- pyplusplus_dev/docs/history/history.rest Modified: pyplusplus_dev/docs/history/history.rest =================================================================== --- pyplusplus_dev/docs/history/history.rest 2006-05-23 20:19:16 UTC (rev 157) +++ pyplusplus_dev/docs/history/history.rest 2006-05-23 20:19:51 UTC (rev 158) @@ -25,7 +25,9 @@ 5. Member variables, that are pointers exported correctly. -6. Adding experimental support for ``vector_indexing_suite``. +6. Adding experimental support for ``vector_indexing_suite``. + +7. Bug fixes. ------------- Version 0.7.0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-23 20:19:26
|
Revision: 157 Author: roman_yakovenko Date: 2006-05-23 13:19:16 -0700 (Tue, 23 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=157&view=rev Log Message: ----------- fixing bug with hierarchy level 3 - adding unit tests Modified Paths: -------------- pyplusplus_dev/unittests/test_all.py Added Paths: ----------- pyplusplus_dev/unittests/data/hierarchy3_to_be_exported.hpp pyplusplus_dev/unittests/hierarchy3_tester.py Property Changed: ---------------- pyplusplus_dev/unittests/data/ Property changes on: pyplusplus_dev/unittests/data ___________________________________________________________________ Name: svn:ignore - *.obj + *.obj call_policies_to_be_exported.os Added: pyplusplus_dev/unittests/data/hierarchy3_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/hierarchy3_to_be_exported.hpp (rev 0) +++ pyplusplus_dev/unittests/data/hierarchy3_to_be_exported.hpp 2006-05-23 20:19:16 UTC (rev 157) @@ -0,0 +1,24 @@ +// 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) + +#ifndef __hierarchy3_to_be_exported_hpp__ +#define __hierarchy3_to_be_exported_hpp__ + +namespace hierarchy3{ + +struct grandpa_t{ + virtual int gp_pure(int i) = 0; +}; + +struct father_t : public grandpa_t{ + virtual int gp_pure(int i){ return i; } +}; + +struct son_t : public father_t +{}; + +} + +#endif//__hierarchy3_to_be_exported_hpp__ Added: pyplusplus_dev/unittests/hierarchy3_tester.py =================================================================== --- pyplusplus_dev/unittests/hierarchy3_tester.py (rev 0) +++ pyplusplus_dev/unittests/hierarchy3_tester.py 2006-05-23 20:19:16 UTC (rev 157) @@ -0,0 +1,44 @@ +# 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 sys +import unittest +import fundamental_tester_base +from pygccxml import declarations +from pyplusplus import code_creators + +class tester_t(fundamental_tester_base.fundamental_tester_base_t): + EXTENSION_NAME = 'hierarchy3' + + def __init__( self, *args ): + fundamental_tester_base.fundamental_tester_base_t.__init__( + self + , tester_t.EXTENSION_NAME + , *args ) + + def customize(self, mb ): + mb.build_code_creator( 'hierarchy3' ) + find = code_creators.creator_finder.find_by_declaration_single + matcher = declarations.match_declaration_t( name='son_t' + , type=declarations.class_t) + found = find( matcher, mb.code_creator.body.creators ) + self.failUnless( found ) + self.failUnless( not found.wrapper ) + self.failUnless( 0 == len( found.creators ) ) + + def run_tests(self, module): + pass + +def create_suite(): + suite = unittest.TestSuite() + suite.addTest( unittest.makeSuite(tester_t)) + return suite + +def run_suite(): + unittest.TextTestRunner(verbosity=2).run( create_suite() ) + +if __name__ == "__main__": + run_suite() \ No newline at end of file Modified: pyplusplus_dev/unittests/test_all.py =================================================================== --- pyplusplus_dev/unittests/test_all.py 2006-05-23 19:48:13 UTC (rev 156) +++ pyplusplus_dev/unittests/test_all.py 2006-05-23 20:19:16 UTC (rev 157) @@ -50,7 +50,8 @@ import factory_tester import private_assign_tester import protected_tester -import indexing_suites_tester +import indexing_suites_tester +import hierarchy3_tester def create_suite(times): testers = [ @@ -98,7 +99,8 @@ , factory_tester , private_assign_tester , protected_tester - , indexing_suites_tester + , indexing_suites_tester + , hierarchy3_tester ] main_suite = unittest.TestSuite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-23 20:09:16
|
Revision: 155 Author: roman_yakovenko Date: 2006-05-23 12:46:59 -0700 (Tue, 23 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=155&view=rev Log Message: ----------- adding java fundamental types Modified Paths: -------------- pygccxml_dev/docs/history/history.rest Modified: pygccxml_dev/docs/history/history.rest =================================================================== --- pygccxml_dev/docs/history/history.rest 2006-05-23 18:38:46 UTC (rev 154) +++ pygccxml_dev/docs/history/history.rest 2006-05-23 19:46:59 UTC (rev 155) @@ -41,8 +41,10 @@ 7. Bug fixes. -8. Documentation. +8. Documentation has been updated/written/improved. +9. Native java types has been added to fundamental types. + ------------- Version 0.7.1 ------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-23 20:09:14
|
Revision: 156 Author: roman_yakovenko Date: 2006-05-23 12:48:13 -0700 (Tue, 23 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=156&view=rev Log Message: ----------- fixing bug with hierarchy level 3 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-05-23 19:46:59 UTC (rev 155) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-05-23 19:48:13 UTC (rev 156) @@ -193,17 +193,23 @@ all_included = declarations.custom_matcher_t( lambda decl: decl.ignore == False ) 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 base_cls = base.related_class funcs.update( base_cls.member_functions( query, allow_empty=True ) ) funcs.update( base_cls.member_operators( query, allow_empty=True ) ) - + + 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() for f in funcs: cls_fs = cls.calldefs( name=f.name, recursive=False, allow_empty=True ) @@ -216,7 +222,15 @@ if self.__is_same_func( f, f_impl ): break else: - not_reimplemented_funcs.add( f ) + #should test whether this function is implemented in base class + if f.virtuality != VIRTUALITY_TYPES.PURE_VIRTUAL: + not_reimplemented_funcs.add( f ) + else: + for f_defined in defined_funcs: + if self.__is_same_func( f, f_defined ): + break + else: + not_reimplemented_funcs.add( f ) return not_reimplemented_funcs def _is_wrapper_needed(self, class_inst, exportable_members): @@ -647,6 +661,9 @@ elif declarations.is_pointer( self.curr_decl.type ): wrapper = code_creators.member_variable_wrapper_t( variable=self.curr_decl ) maker = code_creators.member_variable_t( variable=self.curr_decl, wrapper=wrapper ) + #elif declarations.is_reference( self.curr_decl.type ): + #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 ) else: maker = code_creators.member_variable_t( variable=self.curr_decl ) if wrapper: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-23 18:39:31
|
Revision: 154 Author: roman_yakovenko Date: 2006-05-23 11:38:46 -0700 (Tue, 23 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=154&view=rev Log Message: ----------- adding java fundamental types Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/__init__.py pygccxml_dev/pygccxml/declarations/cpptypes.py pygccxml_dev/unittests/core_tester.py Modified: pygccxml_dev/pygccxml/declarations/__init__.py =================================================================== --- pygccxml_dev/pygccxml/declarations/__init__.py 2006-05-23 14:37:46 UTC (rev 153) +++ pygccxml_dev/pygccxml/declarations/__init__.py 2006-05-23 18:38:46 UTC (rev 154) @@ -54,7 +54,19 @@ from cpptypes import member_variable_type_t from cpptypes import declarated_t from cpptypes import type_qualifiers_t +#java types +from cpptypes import java_fundamental_t +from cpptypes import jbyte_t +from cpptypes import jshort_t +from cpptypes import jint_t +from cpptypes import jlong_t +from cpptypes import jfloat_t +from cpptypes import jdouble_t +from cpptypes import jchar_t +from cpptypes import jboolean_t + + from variable import variable_t from algorithm import full_name Modified: pygccxml_dev/pygccxml/declarations/cpptypes.py =================================================================== --- pygccxml_dev/pygccxml/declarations/cpptypes.py 2006-05-23 14:37:46 UTC (rev 153) +++ pygccxml_dev/pygccxml/declarations/cpptypes.py 2006-05-23 18:38:46 UTC (rev 154) @@ -89,7 +89,11 @@ def _clone_impl( self ): return self - + +class java_fundamental_t( fundamental_t ): + def __init__( self, name ): + fundamental_t.__init__( self, name ) + class void_t( fundamental_t ): CPPNAME = 'void' def __init__( self ): @@ -185,6 +189,48 @@ def __init__( self ): fundamental_t.__init__( self, complex_float_t.CPPNAME ) +class jbyte_t( java_fundamental_t ): + JNAME = 'jbyte' + def __init__( self ): + java_fundamental_t.__init__( self, jbyte_t.JNAME ) + +class jshort_t( java_fundamental_t ): + JNAME = 'jshort' + def __init__( self ): + java_fundamental_t.__init__( self, jshort_t.JNAME ) + +class jint_t( java_fundamental_t ): + JNAME = 'jint' + def __init__( self ): + java_fundamental_t.__init__( self, jint_t.JNAME ) + +class jlong_t( java_fundamental_t ): + JNAME = 'jlong' + def __init__( self ): + java_fundamental_t.__init__( self, jlong_t.JNAME ) + +class jfloat_t( java_fundamental_t ): + JNAME = 'jfloat' + def __init__( self ): + java_fundamental_t.__init__( self, jfloat_t.JNAME ) + + +class jdouble_t( java_fundamental_t ): + JNAME = 'jdouble' + def __init__( self ): + java_fundamental_t.__init__( self, jdouble_t.JNAME ) + + +class jchar_t( java_fundamental_t ): + JNAME = 'jchar' + def __init__( self ): + java_fundamental_t.__init__( self, jchar_t.JNAME ) + +class jboolean_t( java_fundamental_t ): + JNAME = 'jboolean' + def __init__( self ): + java_fundamental_t.__init__( self, jboolean_t.JNAME ) + FUNDAMENTAL_TYPES = { void_t.CPPNAME : void_t() , char_t.CPPNAME : char_t() @@ -208,6 +254,24 @@ , complex_long_double_t.CPPNAME : complex_long_double_t() , complex_double_t.CPPNAME : complex_double_t() , complex_float_t.CPPNAME : complex_float_t() + ##adding java types + , jbyte_t.JNAME : jbyte_t() + , jshort_t.JNAME : jshort_t() + , jint_t.JNAME : jint_t() + , jlong_t.JNAME : jlong_t() + , jfloat_t.JNAME : jfloat_t() + , jdouble_t.JNAME : jdouble_t() + , jchar_t.JNAME : jchar_t() + , jboolean_t.JNAME : jboolean_t() + , '__java_byte' : jbyte_t() + , '__java_short' : jshort_t() + , '__java_int' : jint_t() + , '__java_long' : jlong_t() + , '__java_float' : jfloat_t() + , '__java_double' : jdouble_t() + , '__java_char' : jchar_t() + , '__java_boolean' : jboolean_t() + } ################################################################################ Modified: pygccxml_dev/unittests/core_tester.py =================================================================== --- pygccxml_dev/unittests/core_tester.py 2006-05-23 14:37:46 UTC (rev 153) +++ pygccxml_dev/unittests/core_tester.py 2006-05-23 18:38:46 UTC (rev 154) @@ -184,6 +184,8 @@ for fundamental_type_name, fundamental_type in FUNDAMENTAL_TYPES.iteritems(): if 'complex' in fundamental_type_name: continue #I check this in an other tester + if isinstance( fundamental_type, java_fundamental_t ): + continue #I don't check this at all typedef_name = 'typedef_' + fundamental_type_name.replace( ' ', '_' ) typedef = self.global_ns.decl( decl_type=typedef_t, name=typedef_name ) self.failUnless( typedef, "unable to find typedef to build-in type '%s'" % fundamental_type_name ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-23 14:37:56
|
Revision: 153 Author: roman_yakovenko Date: 2006-05-23 07:37:46 -0700 (Tue, 23 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=153&view=rev Log Message: ----------- updating docs Modified Paths: -------------- pygccxml_dev/docs/query_api.rest Modified: pygccxml_dev/docs/query_api.rest =================================================================== --- pygccxml_dev/docs/query_api.rest 2006-05-23 06:55:34 UTC (rev 152) +++ pygccxml_dev/docs/query_api.rest 2006-05-23 14:37:46 UTC (rev 153) @@ -23,19 +23,19 @@ query = query & ~declarations.access_type_matcher_t( 'public' ) global_ns.member_functions( function=query, arg_types=[None, 'int &'] ) -As for me the example I gave was too complex. In many cases you will find your +As for me, the example I gave was too complex. In many cases you will find your self looking for one or many declarations using one or two properties of that declaration(s). For example: :: global_ns.namespaces( 'details' ) -This call will return all namespaces that have 'details' namespace. +This call will return all namespaces with name 'details'. ------------------- -How does it works? ------------------- - +-------------- +User interface +-------------- + As you already know, ``pygccxml.declarations`` packages defines next classes: * ``scopedef_t`` - base class for all classes, that can contain other declarations @@ -44,12 +44,36 @@ * ``class_t`` - derives from ``scopedef_t`` class, represents C++ class/struct. -``scopedef_t`` class defines query interface. Basicaly you can ask it about any -declaration it contains, even about some sub declarations. +So, the query methods defined on ``scopedef_t`` class could be used on instances +of ``class_t`` and ``namespace_t`` classes. + +I will explain the usage of ``member_function`` and ``member_functions`` methods. +The usage of other methods is very similar to them. Here is definition of those +methods: +:: + + def member_function( self, + name=None, + function=None, + return_type=None, + arg_types=None, + header_dir=None, + header_file=None, + recursive=None ) + + def member_functions( self, + name=None, + function=None, + return_type=None, + arg_types=None, + header_dir=None, + header_file=None, + recursive=None, + allow_empty=None ) + + + - - - .. _`pygccxml`: ./pygccxml.html .. _`SourceForge`: http://sourceforge.net/index.php .. _`Python`: http://www.python.org This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-23 06:55:45
|
Revision: 152 Author: roman_yakovenko Date: 2006-05-22 23:55:34 -0700 (Mon, 22 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=152&view=rev Log Message: ----------- adding vector indexing suite support Modified Paths: -------------- pyplusplus_dev/docs/history/history.rest pyplusplus_dev/unittests/test_all.py Modified: pyplusplus_dev/docs/history/history.rest =================================================================== --- pyplusplus_dev/docs/history/history.rest 2006-05-23 06:31:16 UTC (rev 151) +++ pyplusplus_dev/docs/history/history.rest 2006-05-23 06:55:34 UTC (rev 152) @@ -25,6 +25,8 @@ 5. Member variables, that are pointers exported correctly. +6. Adding experimental support for ``vector_indexing_suite``. + ------------- Version 0.7.0 ------------- Modified: pyplusplus_dev/unittests/test_all.py =================================================================== --- pyplusplus_dev/unittests/test_all.py 2006-05-23 06:31:16 UTC (rev 151) +++ pyplusplus_dev/unittests/test_all.py 2006-05-23 06:55:34 UTC (rev 152) @@ -50,6 +50,7 @@ import factory_tester import private_assign_tester import protected_tester +import indexing_suites_tester def create_suite(times): testers = [ @@ -97,6 +98,7 @@ , factory_tester , private_assign_tester , protected_tester + , indexing_suites_tester ] main_suite = unittest.TestSuite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-23 06:31:34
|
Revision: 151 Author: roman_yakovenko Date: 2006-05-22 23:31:16 -0700 (Mon, 22 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=151&view=rev Log Message: ----------- adding vector indexing suite support - unit test Added Paths: ----------- pyplusplus_dev/unittests/data/indexing_suites_to_be_exported.hpp pyplusplus_dev/unittests/indexing_suites_tester.py Property Changed: ---------------- pyplusplus_dev/unittests/temp/ Added: pyplusplus_dev/unittests/data/indexing_suites_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/indexing_suites_to_be_exported.hpp (rev 0) +++ pyplusplus_dev/unittests/data/indexing_suites_to_be_exported.hpp 2006-05-23 06:31:16 UTC (rev 151) @@ -0,0 +1,39 @@ +// 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) + +#ifndef __indexing_suites_to_be_exported_hpp__ +#define __indexing_suites_to_be_exported_hpp__ + +#include <vector> + +namespace indexing_suites { + +struct item_t{ + item_t() : value( -1 ){} + + bool operator==(item_t const& item) const { + return value == item.value; + } + + bool operator!=(item_t const& item) const { + return value != item.value; + } + + int value; +}; + + +inline item_t get_value( const std::vector<item_t>& vec, unsigned int index ){ + return vec.at(index); +} + +inline void set_value( std::vector<item_t>& vec, unsigned int index, item_t value ){ + vec.at(index); + vec[index] = value; +} + +} + +#endif//__indexing_suites_to_be_exported_hpp__ Added: pyplusplus_dev/unittests/indexing_suites_tester.py =================================================================== --- pyplusplus_dev/unittests/indexing_suites_tester.py (rev 0) +++ pyplusplus_dev/unittests/indexing_suites_tester.py 2006-05-23 06:31:16 UTC (rev 151) @@ -0,0 +1,43 @@ +# 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 sys +import unittest +import fundamental_tester_base +from pyplusplus import module_builder + + +class tester_t(fundamental_tester_base.fundamental_tester_base_t): + EXTENSION_NAME = 'indexing_suites' + + def __init__( self, *args ): + fundamental_tester_base.fundamental_tester_base_t.__init__( + self + , tester_t.EXTENSION_NAME + , *args ) + + def customize(self, generator): + item_cls = generator.class_( 'item_t' ) + item_cls.indexing_suites.append( module_builder.vector_indexing_suite_t( 'items_t' ) ) + + def run_tests( self, module): + items = module.items_t() + item = module.item_t() + item.value = 1977 + items.append( item ) + self.failUnless( module.get_value( items, 0 ).value == 1977 ) + self.failUnless( len( items ) == 1 ) + +def create_suite(): + suite = unittest.TestSuite() + suite.addTest( unittest.makeSuite(tester_t)) + return suite + +def run_suite(): + unittest.TextTestRunner(verbosity=2).run( create_suite() ) + +if __name__ == "__main__": + run_suite() Property changes on: pyplusplus_dev/unittests/temp ___________________________________________________________________ Name: svn:ignore - internal_classes.dll member_functions.dll member_variables.dll module_body.dll namespaces.dll noncopyable.dll operators.dll operators_bug.dll optional.dll optional_bug.dll pointer_as_arg.dll pointer_to_function_as_argument.dll private_assign.dll recursive.dll regression1.dll regression2.dll regression3.dll smart_pointers.dll special_operators.dll statics.dll temprorary_variable.dll unnamed_enums.dll user_text.dll abstract.cpp~ call_policies.cpp~ casting.cpp~ class_order2.cpp~ class_order3.cpp~ class_order4.cpp~ class_order.cpp~ classes.cpp~ enums.cpp~ factory.cpp~ finalizables.cpp~ free_functions.cpp~ free_operators.cpp~ global_variables.cpp~ index_operator.cpp~ internal_classes.cpp~ member_functions.cpp~ member_variables.cpp~ noncopyable.cpp~ operators_bug.cpp~ optional.cpp~ optional_bug.cpp~ pointer_as_arg.cpp~ pointer_to_function_as_argument.cpp~ private_assign.cpp~ recursive.cpp~ regression1.cpp~ regression2.cpp~ regression3.cpp~ smart_pointers.cpp~ special_operators.cpp~ statics.cpp~ temprorary_variable.cpp~ unnamed_enums.cpp~ user_text.cpp~ abstract.exp call_policies.exp casting.exp class_order2.exp class_order3.exp class_order4.exp class_order.exp classes.exp enums.exp factory.exp finalizables.exp free_function_ignore_bug.exp free_functions.exp free_operators.exp global_variables.exp index_operator.exp internal_classes.exp member_functions.exp member_variables.exp module_body.exp namespaces.exp noncopyable.exp operators.exp operators_bug.exp optional.exp optional_bug.exp pointer_as_arg.exp pointer_to_function_as_argument.exp private_assign.exp recursive.exp regression1.exp regression2.exp regression3.exp smart_pointers.exp special_operators.exp statics.exp temprorary_variable.exp unnamed_enums.exp user_text.exp abstract.lib call_policies.lib casting.lib class_order2.lib class_order3.lib class_order4.lib class_order.lib classes.lib enums.lib factory.lib finalizables.lib free_function_ignore_bug.lib free_functions.lib free_operators.lib global_variables.lib index_operator.lib internal_classes.lib member_functions.lib member_variables.lib module_body.lib namespaces.lib noncopyable.lib operators.lib operators_bug.lib optional.lib optional_bug.lib pointer_as_arg.lib pointer_to_function_as_argument.lib private_assign.lib recursive.lib regression1.lib regression2.lib regression3.lib smart_pointers.lib special_operators.lib statics.lib temprorary_variable.lib unnamed_enums.lib user_text.lib abstract.obj call_policies.obj casting.obj class_order2.obj class_order3.obj class_order4.obj class_order.obj classes.obj enums.obj factory.obj finalizables.obj free_function_ignore_bug.obj free_functions.obj free_operators.obj global_variables.obj index_operator.obj internal_classes.obj member_functions.obj member_variables.obj module_body.obj namespaces.obj noncopyable.obj operators.obj operators_bug.obj optional.obj optional_bug.obj pointer_as_arg.obj pointer_to_function_as_argument.obj private_assign.obj recursive.obj regression1.obj regression2.obj regression3.obj smart_pointers.obj special_operators.obj statics.obj temprorary_variable.obj unnamed_enums.obj user_text.obj abstract.scons call_policies.scons casting.scons class_order2.scons class_order3.scons class_order4.scons class_order.scons classes.scons enums.scons factory.scons finalizables.scons free_function_ignore_bug.scons free_functions.scons free_operators.scons global_variables.scons index_operator.scons internal_classes.scons member_functions.scons member_variables.scons module_body.scons namespaces.scons noncopyable.scons operators.scons operators_bug.scons optional.scons optional_bug.scons pointer_as_arg.scons pointer_to_function_as_argument.scons private_assign.scons recursive.scons regression1.scons regression2.scons regression3.scons smart_pointers.scons special_operators.scons statics.scons temprorary_variable.scons unnamed_enums.scons user_text.scons abstract.dll call_policies.dll casting.dll class_order2.dll class_order3.dll class_order4.dll class_order.dll classes.dll enums.dll factory.dll finalizables.dll free_function_ignore_bug.dll free_functions.dll free_operators.dll global_variables.dll index_operator.dll .sconsign.dblite __array_1.pypp.hpp classes.cpp enums.cpp free_functions.cpp module_body.cpp namespaces.cpp unnamed_enums.cpp abstract.cpp call_policies.cpp casting.cpp class_order.cpp class_order2.cpp class_order3.cpp class_order4.cpp factory.cpp finalizables.cpp free_function_ignore_bug.cpp free_operators.cpp global_variables.cpp index_operator.cpp internal_classes.cpp member_functions.cpp member_variables.cpp noncopyable.cpp operators.cpp operators_bug.cpp optional.cpp optional_bug.cpp pointer_as_arg.cpp pointer_to_function_as_argument.cpp private_assign.cpp protected.cpp recursive.cpp regression1.cpp regression2.cpp regression3.cpp smart_pointers.cpp special_operators.cpp statics.cpp temprorary_variable.cpp user_text.cpp protected.dll protected.exp protected.lib protected.obj protected.scons + internal_classes.dll member_functions.dll member_variables.dll module_body.dll namespaces.dll noncopyable.dll operators.dll operators_bug.dll optional.dll optional_bug.dll pointer_as_arg.dll pointer_to_function_as_argument.dll private_assign.dll recursive.dll regression1.dll regression2.dll regression3.dll smart_pointers.dll special_operators.dll statics.dll temprorary_variable.dll unnamed_enums.dll user_text.dll abstract.cpp~ call_policies.cpp~ casting.cpp~ class_order2.cpp~ class_order3.cpp~ class_order4.cpp~ class_order.cpp~ classes.cpp~ enums.cpp~ factory.cpp~ finalizables.cpp~ free_functions.cpp~ free_operators.cpp~ global_variables.cpp~ index_operator.cpp~ internal_classes.cpp~ member_functions.cpp~ member_variables.cpp~ noncopyable.cpp~ operators_bug.cpp~ optional.cpp~ optional_bug.cpp~ pointer_as_arg.cpp~ pointer_to_function_as_argument.cpp~ private_assign.cpp~ recursive.cpp~ regression1.cpp~ regression2.cpp~ regression3.cpp~ smart_pointers.cpp~ special_operators.cpp~ statics.cpp~ temprorary_variable.cpp~ unnamed_enums.cpp~ user_text.cpp~ abstract.exp call_policies.exp casting.exp class_order2.exp class_order3.exp class_order4.exp class_order.exp classes.exp enums.exp factory.exp finalizables.exp free_function_ignore_bug.exp free_functions.exp free_operators.exp global_variables.exp index_operator.exp internal_classes.exp member_functions.exp member_variables.exp module_body.exp namespaces.exp noncopyable.exp operators.exp operators_bug.exp optional.exp optional_bug.exp pointer_as_arg.exp pointer_to_function_as_argument.exp private_assign.exp recursive.exp regression1.exp regression2.exp regression3.exp smart_pointers.exp special_operators.exp statics.exp temprorary_variable.exp unnamed_enums.exp user_text.exp abstract.lib call_policies.lib casting.lib class_order2.lib class_order3.lib class_order4.lib class_order.lib classes.lib enums.lib factory.lib finalizables.lib free_function_ignore_bug.lib free_functions.lib free_operators.lib global_variables.lib index_operator.lib internal_classes.lib member_functions.lib member_variables.lib module_body.lib namespaces.lib noncopyable.lib operators.lib operators_bug.lib optional.lib optional_bug.lib pointer_as_arg.lib pointer_to_function_as_argument.lib private_assign.lib recursive.lib regression1.lib regression2.lib regression3.lib smart_pointers.lib special_operators.lib statics.lib temprorary_variable.lib unnamed_enums.lib user_text.lib abstract.obj call_policies.obj casting.obj class_order2.obj class_order3.obj class_order4.obj class_order.obj classes.obj enums.obj factory.obj finalizables.obj free_function_ignore_bug.obj free_functions.obj free_operators.obj global_variables.obj index_operator.obj internal_classes.obj member_functions.obj member_variables.obj module_body.obj namespaces.obj noncopyable.obj operators.obj operators_bug.obj optional.obj optional_bug.obj pointer_as_arg.obj pointer_to_function_as_argument.obj private_assign.obj recursive.obj regression1.obj regression2.obj regression3.obj smart_pointers.obj special_operators.obj statics.obj temprorary_variable.obj unnamed_enums.obj user_text.obj abstract.scons call_policies.scons casting.scons class_order2.scons class_order3.scons class_order4.scons class_order.scons classes.scons enums.scons factory.scons finalizables.scons free_function_ignore_bug.scons free_functions.scons free_operators.scons global_variables.scons index_operator.scons internal_classes.scons member_functions.scons member_variables.scons module_body.scons namespaces.scons noncopyable.scons operators.scons operators_bug.scons optional.scons optional_bug.scons pointer_as_arg.scons pointer_to_function_as_argument.scons private_assign.scons recursive.scons regression1.scons regression2.scons regression3.scons smart_pointers.scons special_operators.scons statics.scons temprorary_variable.scons unnamed_enums.scons user_text.scons abstract.dll call_policies.dll casting.dll class_order2.dll class_order3.dll class_order4.dll class_order.dll classes.dll enums.dll factory.dll finalizables.dll free_function_ignore_bug.dll free_functions.dll free_operators.dll global_variables.dll index_operator.dll .sconsign.dblite __array_1.pypp.hpp classes.cpp enums.cpp free_functions.cpp module_body.cpp namespaces.cpp unnamed_enums.cpp abstract.cpp call_policies.cpp casting.cpp class_order.cpp class_order2.cpp class_order3.cpp class_order4.cpp factory.cpp finalizables.cpp free_function_ignore_bug.cpp free_operators.cpp global_variables.cpp index_operator.cpp internal_classes.cpp member_functions.cpp member_variables.cpp noncopyable.cpp operators.cpp operators_bug.cpp optional.cpp optional_bug.cpp pointer_as_arg.cpp pointer_to_function_as_argument.cpp private_assign.cpp protected.cpp recursive.cpp regression1.cpp regression2.cpp regression3.cpp smart_pointers.cpp special_operators.cpp statics.cpp temprorary_variable.cpp user_text.cpp protected.dll protected.exp protected.lib protected.obj protected.scons indexing_suites.cpp indexing_suites.cpp~ indexing_suites.dll indexing_suites.exp indexing_suites.lib indexing_suites.obj indexing_suites.scons This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-23 06:29:34
|
Revision: 150 Author: roman_yakovenko Date: 2006-05-22 23:29:14 -0700 (Mon, 22 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=150&view=rev Log Message: ----------- adding vector indexing suite support Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/__init__.py pyplusplus_dev/pyplusplus/code_creators/class_declaration.py pyplusplus_dev/pyplusplus/code_creators/declaration_based.py pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py pyplusplus_dev/pyplusplus/module_builder/__init__.py pyplusplus_dev/pyplusplus/module_creator/creator.py Added Paths: ----------- pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2006-05-22 20:34:23 UTC (rev 149) +++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2006-05-23 06:29:14 UTC (rev 150) @@ -102,3 +102,5 @@ from target_configuration import target_configuration_t from array_1_registrator import array_1_registrator_t + +from indexing_suites import vector_indexing_suite_t \ No newline at end of file Modified: pyplusplus_dev/pyplusplus/code_creators/class_declaration.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/class_declaration.py 2006-05-22 20:34:23 UTC (rev 149) +++ pyplusplus_dev/pyplusplus/code_creators/class_declaration.py 2006-05-23 06:29:14 UTC (rev 150) @@ -12,6 +12,7 @@ import smart_pointers import declaration_based import array_1_registrator +import indexing_suites from pygccxml import declarations class class_t( scoped.scoped_t ): @@ -185,6 +186,9 @@ if isinstance( inst, array_1_registrator.array_1_registrator_t ): return True + if isinstance( inst, indexing_suites.indexing_suite_t ): + return True + return False def _get_class_var_name(self): Modified: pyplusplus_dev/pyplusplus/code_creators/declaration_based.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/declaration_based.py 2006-05-22 20:34:23 UTC (rev 149) +++ pyplusplus_dev/pyplusplus/code_creators/declaration_based.py 2006-05-23 06:29:14 UTC (rev 150) @@ -41,3 +41,7 @@ def _set_alias(self, alias): self.declaration.alias = alias alias = property( _get_alias, _set_alias ) + + def _get_decl_identifier( self ): + return algorithm.create_identifier( self, self.declaration.decl_string ) + decl_identifier = property( _get_decl_identifier ) \ No newline at end of file Added: pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py (rev 0) +++ pyplusplus_dev/pyplusplus/code_creators/indexing_suites.py 2006-05-23 06:29:14 UTC (rev 150) @@ -0,0 +1,71 @@ +# 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 +import scoped +import custom +import calldef +import algorithm +import smart_pointers +import declaration_based +import array_1_registrator +from pygccxml import declarations + +class indexing_suite_t( scoped.scoped_t ): + def __init__(self, class_inst, suite_configuration, parent=None ): + scoped.scoped_t.__init__( self + , parent=parent + , declaration=class_inst ) + self._suite_configuration = suite_configuration + + def _get_suite_configuration( self ): + return self._suite_configuration + suite_configuration = property( _get_suite_configuration ) + +class vector_indexing_suite_t( indexing_suite_t ): + """ + Creates boost.python code that needed to export a vector of some class + """ + #class_< std::vector<X> >("XVec") + # .def(vector_indexing_suite<std::vector<X> >()) + #; + + def __init__(self, class_inst, suite_configuration, parent=None ): + indexing_suite_t.__init__( self + , class_inst=class_inst + , suite_configuration=suite_configuration + , parent=parent ) + + def _create_indexing_suite_declaration( self ): + vector_indexing_suite = algorithm.create_identifier( self, 'boost::python::vector_indexing_suite' ) + container_identifier = algorithm.create_identifier( self, self.suite_configuration.container ) + container = declarations.templates.join( container_identifier, [ self.decl_identifier ] ) + args = [container] + if self.suite_configuration.derived_policies: + if self.suite_configuration.no_proxy: + args.append( 'true' ) + else: + args.append( 'false' ) + args.append( self.suite_configuration.derived_policies ) + else: + if self.suite_configuration.no_proxy: + args.append( 'true' ) + return declarations.templates.join( vector_indexing_suite, args ) + + def _create_class_declaration( self ): + class_ = algorithm.create_identifier( self, 'boost::python::class_' ) + container_identifier = algorithm.create_identifier( self, self.suite_configuration.container ) + container = declarations.templates.join( container_identifier, [ self.decl_identifier ] ) + return declarations.templates.join( class_, [ container ] ) + + def _create_impl(self): + result = [] + result.append( self._create_class_declaration() + '("%s")' % self.suite_configuration.name ) + result.append( self.indent( ".def( %s() )" % self._create_indexing_suite_declaration() ) ) + result.append( ';' ) + return os.linesep.join( result ) + + \ No newline at end of file Modified: pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-05-22 20:34:23 UTC (rev 149) +++ pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-05-23 06:29:14 UTC (rev 150) @@ -44,6 +44,7 @@ from calldef_wrapper import free_function_t from calldef_wrapper import free_operator_t +from class_wrapper import vector_indexing_suite_t from class_wrapper import class_declaration_t from class_wrapper import class_t Modified: pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-05-22 20:34:23 UTC (rev 149) +++ pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py 2006-05-23 06:29:14 UTC (rev 150) @@ -8,6 +8,14 @@ from pygccxml import declarations import user_text +class vector_indexing_suite_t( object ): + def __init__( self, name, container='std::vector', no_proxy=False, derived_policies='' ): + object.__init__( self ) + self.name = name + self.container = container + self.no_proxy = no_proxy + self.derived_policies = derived_policies + class class_declaration_t(decl_wrapper.decl_wrapper_t, declarations.class_declaration_t): def __init__(self, *arguments, **keywords): declarations.class_declaration_t.__init__(self, *arguments, **keywords ) @@ -25,6 +33,7 @@ self._wrapper_alias = self._generate_valid_name() + "_wrapper" self._user_code = [] self._wrapper_user_code = [] + self._indexing_suites = [] def _get_always_expose_using_scope( self ): return self._always_expose_using_scope @@ -77,6 +86,12 @@ def _set_wrapper_user_code( self, value ): self._wrapper_user_code = value wrapper_user_code = property( _get_wrapper_user_code, _set_wrapper_user_code ) + + def _get_indexing_suites( self ): + return self._indexing_suites + def _set_indexing_suites( self, value ): + self._indexing_suites = value + indexing_suites = property( _get_indexing_suites, _set_indexing_suites ) def add_code( self, code, works_on_instance=True ): """works_on_instance: If true, the custom code can be applied directly to obj inst. Modified: pyplusplus_dev/pyplusplus/module_builder/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/__init__.py 2006-05-22 20:34:23 UTC (rev 149) +++ pyplusplus_dev/pyplusplus/module_builder/__init__.py 2006-05-23 06:29:14 UTC (rev 150) @@ -43,6 +43,8 @@ from pyplusplus.decl_wrappers import variable_t from pyplusplus.decl_wrappers import scopedef_t +from pyplusplus.decl_wrappers import vector_indexing_suite_t + from pyplusplus.decl_wrappers import print_declarations import call_policies Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py =================================================================== --- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-05-22 20:34:23 UTC (rev 149) +++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-05-23 06:29:14 UTC (rev 150) @@ -10,6 +10,7 @@ import types_database from pyplusplus import code_repository from sets import Set as set +from pyplusplus import decl_wrappers ACCESS_TYPES = declarations.ACCESS_TYPES VIRTUALITY_TYPES = declarations.VIRTUALITY_TYPES @@ -352,6 +353,13 @@ return self.__extmodule def _create_includes(self): + for cls in self.__decls: + if not isinstance( cls, decl_wrappers.class_t ): + continue + if cls.indexing_suites: + include = code_creators.include_t( header="boost/python/suite/indexing/vector_indexing_suite.hpp" ) + self.__extmodule.adopt_include(include) + break for fn in declarations.declaration_files( self.__decls ): include = code_creators.include_t( header=fn ) self.__extmodule.adopt_include(include) @@ -510,6 +518,13 @@ def visit_class_declaration(self ): pass + def register_indexing_suites(self, class_decl, class_code_creator): + for suite in class_decl.indexing_suites: + assert isinstance( suite, decl_wrappers.vector_indexing_suite_t ) + creator = code_creators.vector_indexing_suite_t( class_inst=class_decl + , suite_configuration=suite ) + class_code_creator.adopt_creator( creator ) + def visit_class(self ): if self.curr_decl.ignore: return @@ -566,6 +581,8 @@ self.curr_decl = temp_curr_decl self.curr_code_creator = temp_curr_parent + self.register_indexing_suites( self.curr_decl, self.curr_code_creator ) + def visit_enumeration(self): if self.curr_decl.ignore: return This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-22 20:34:34
|
Revision: 149 Author: roman_yakovenko Date: 2006-05-22 13:34:23 -0700 (Mon, 22 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=149&view=rev Log Message: ----------- improving documentation Modified Paths: -------------- pygccxml_dev/docs/design.rest pygccxml_dev/docs/example/example.py pygccxml_dev/docs/pygccxml.rest Modified: pygccxml_dev/docs/design.rest =================================================================== --- pygccxml_dev/docs/design.rest 2006-05-22 06:47:04 UTC (rev 148) +++ pygccxml_dev/docs/design.rest 2006-05-22 20:34:23 UTC (rev 149) @@ -248,7 +248,7 @@ Patchers -------- -????. Well, `GCC-XML`_ has few bugs, that could not be fixed from it. For example +Well, `GCC-XML`_ has few bugs, that could not be fixed from it. For example :: namespace ns1{ namespace ns2{ @@ -258,15 +258,19 @@ void fix_enum( ns1::ns2::fruit arg=ns1::ns2::apple ); `GCC-XML`_ will report the default value of ``arg`` as ``apple``. Obviously -this in an error. `pygccxml`_ knows how to fix different bugs. +this in an error. `pygccxml`_ knows how to fix this bug. +This is not the only bug, that could be fixed, there are few of them. `pygccxml`_ +introduces few classes, that knows how to deal with specific bug. More over, those +bugs are fixed, only if I am 101% sure, that this is the right thing to do. + ------- Summary ------- -Thats all. I hope I was clear, at least I tried. Any way we are talking about -open source project. You can take a look on source code. If you need more information -you can take a look on API documentation. +Thats all. I hope I was clear, at least I tried. Any way, `pygccxml`_ is an open +source project. You always can take a look on the source code. If you need more +information please read API documentation. .. _`pygccxml`: ./pygccxml.html .. _`SourceForge`: http://sourceforge.net/index.php Modified: pygccxml_dev/docs/example/example.py =================================================================== --- pygccxml_dev/docs/example/example.py 2006-05-22 06:47:04 UTC (rev 148) +++ pygccxml_dev/docs/example/example.py 2006-05-22 20:34:23 UTC (rev 149) @@ -3,21 +3,24 @@ # accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +import sys +sys.path.append('../..') #adding pygccxml to the path + from pygccxml import parser from pygccxml import declarations #configure GCC-XML parser -config = parser.config_t( gccxml_path=r'/home/roman/gccxml/bin/gccxml' ) +config = parser.config_t( gccxml_path='/home/roman/gccxml-build/bin/gccxml' ) + #parsing source file -global_ns = parser.parse( ['core_class_hierarchy.hpp'], config ) +decls = parser.parse( ['core_class_hierarchy.hpp'], config ) +global_ns = declarations.get_global_namespace( decls ) + #printing all declarations found in file and its includes declarations.print_declarations( global_ns ) -#selecting all classes -all_decls = declarations.make_flatten( global_ns ) -all_classes = filter( lambda decl: isinstance( decl, declarations.class_t ) - , all_decls ) + #print all base and derived class names -for class_ in all_classes: +for class_ in global_ns.classes(): print class_.name print '\tbases: ', `[base.related_class.name for base in class_.bases]` print '\tderived: ', `[derive.related_class.name for derive in class_.derived]` Modified: pygccxml_dev/docs/pygccxml.rest =================================================================== --- pygccxml_dev/docs/pygccxml.rest 2006-05-22 06:47:04 UTC (rev 148) +++ pygccxml_dev/docs/pygccxml.rest 2006-05-22 20:34:23 UTC (rev 149) @@ -36,272 +36,91 @@ Usage example ------------- First of all let's see a small and simple `example`_. This example prints all -declarations found in the global namespace after `GCC-XML`_ has parsed -`core_class_hierarchy.hpp`_ file. Also it prints all clasess, and for every class -it will print it's base and derived classes. It was simple task, right? If you -are still curious how it looks "in the real life", I mean how xml file -is look like, you may look at the `original XML file`_ generated by `GCC-XML`_. +declarations, reported by `GCC-XML`_ after parsing `core_class_hierarchy.hpp`_ +file. Also it prints all clasess, and for every class it will print it's base +and derived classes. It was simple task, right? If you are still curious how it +looks "in the real life", I mean how xml file is look like, you may look at the +`original XML file`_ generated by `GCC-XML`_. .. _`original XML file` : ./example/core_class_hierarchy.hpp.xml .. _`core_class_hierarchy.hpp` : ./example/core_class_hierarchy.hpp .. _`example` : ./example/example.py - -I like it, but what else can you propose? ------------------------------------------ +-------- +Features +-------- + +Caching +------- + Consider the following situation: you have to parse the same set of files every -day. There are 2 possibile ways to complete the task:: +day. There are 2 possibile ways to complete the task: - * create a header file that includes all files you need to parse +* create a header file that includes all files you need to parse - * parse each file separately and then join the results +* parse each file separately and then join the results The difference between these approaches is the caching algorithm used in the second case. `pygccxml`_ supports both of them. -That's not all. Do you familiar with the `boost::type_traits`_ library? Well, -`pygccxml`_ includes some functionality offered by that library. +Type traits +----------- -------- -License -------- +`pygccxml`_ provides a lot of functionality to analize C++ types and relationship +between them. For more information please refer to `design`__ document or API +documentation. Just a few names of algorithms: -`Boost Software License`_. +* ``is_convertible( from, to )`` -------------------------- -Declaration class diagram -------------------------- -`UML diagram`_: - - Look at this `UML diagram`_. All the classes are defined by the - `pygccxml`_.declarations package. Defined classes are used to describe almost - any C++ declaration. - -A few words about the naming convention used. Every class name ends with "_t". -The are several reasons for this: - - * I am used to the C++ "std" convention, i.e. lower-case letters with underscores. - - * Most of the names are already used in Python, and have a different meaning. - -Types hierarchy ---------------- - -Types hierarchy is used to represent an arbitrary type in C++. - -Example -~~~~~~~ - -For a variable "ptr" - - *const int\* ptr=0;* - -`pygccxml`_ will create the type - - *pointer_t( const_t( int_t() ) )* - -The ability to represent almost any type of C++ comes from the use of the -"decorator" pattern. That's not all! Are you aware of `boost::type_traits`_ -library? The `boost::type_traits`_ library has been developed by John Maddock, -Steve Cleary and others. `pygccxml`_ reuses the names proposed by this library. -Also I took few ideas for testing the `pygccxml`_ type traits implementation. -Here are some of the type traits implemented by `pygccxml`_. - - + *base_type* - - + *decompose_type* - - + *decompose_class* - - + *is_same* - - + *is_enum* - - + *is_void* - - + *is_const* - - + *is_array* - - + *is_pointer* - - + *is_volatile* - - + *is_integral* - - + *is_reference* - - + *is_arithmetic* - - + *is_convertible* - - + *is_fundamental* - - + *is_floating_point* - - + *is_base_and_derived* - - + *is_unary_operator* - - + *is_binary_operator* - - + *remove_cv* - - + *remove_const* - - + *remove_alias* - - + *remove_pointer* - - + *remove_volatile* - - + *remove_reference* - - + *has_trivial_copy* - - + *has_trivial_constructor* - - + *find_trivial_constructor* - - + *has_any_non_copyconstructor* - - + *...* - -Declaration hierarchy ---------------------- - -A declaration hierarchy is used to represent an arbitrary C++ declaration. - -*"declaration_t"* is the base class of the declaration hierarchy. This class has -a few properties. One of them is the *"parent"* property. This property keeps a -reference to the scope declaration instance in which this declaration is defined. -The *"scopedef_t"* class derives from *"declaration_t"*. This class is used to -say - "I may have other declarations inside". The "composite" design pattern is -used here. - ------- -Parser ------- - -User API --------- - -`Parser package`_ ( "`pygccxml`_.parser" ). This is the heart of the `pygccxml`_ -project. Classes in this package implement parsing and binding functionality. -There are 3 classes and 2 functions that user should know about: - -+ *config_t* - a class that accumulates all the settings of `GCC-XML`_ and - `pygccxml`_. Users can work with relative files paths. In this case files are - searched in the following order: + returns ``True`` if there is a conversion from type ``from`` to type ``to``, + otherwise ``False`` - 1. current directory - - 2. working directory - - 3. additional include paths specified by the user +* ``is_unary_operator( oper )`` -+ *source_reader_t* - the only class that works with `GCC-XML`_. This class has - only one responsibility: to convert source file declarations and types into the - `pygccxml`_ object model. You can think about this class as simply a reader for - `GCC-XML`_-generated files. + returns ``True`` if ``oper`` describes unary operator -+ *project_reader_t* - think of this class as a linker or a binder. Explanation: - usually you will define a base class in one header file and a derived class in - another. After running *source_reader_t* on the base class header file and on - the derived class header file you will have two definitions of the base class. - All but one of the definitions will not contain information about the derived - classes. *project_reader_t* was born to solve this situation. It implements - several algorithms to solve that problem and other similar ones. Right now it - implements these algorithms: +.. __: ./design.html - 1. namespace joining. - 2. joining class hierarchies - 3. rebinding types to new class hierarchies - 4. linking overloaded functions - There are 2 ways to solve the problem: +Query interface +--------------- - 1. Compile every file to run the algorithms. In order to select this mode - set *compilation_mode* (in the instance of *config_t*) to *COMPILATION_MODE.FILE_BY_FILE*. +`pygccxml`_ provides simple and powerful API to query declarations tree. I will +try to give small example, that will prove my point. If you want to know more +about provided API please read `query api`__ document or API documentation. +Examples: +:: - 2. Create a temporary header file, that will include all headers you want to - compile. In order to select this mode set *compilation_mode* (in the instance - of *config_t* ) to *COMPILATION_MODE.ALL_AT_ONCE*. In other words, in this - mode *project_reader_t* acts like *source_reader_t*, there's no difference. - - Two modes, why?! The answer is simple - the cache. You don't want to pay for - compilation and processing results for files that have not changed, right? - *COMPILATION_MODE.FILE_BY_FILE* gives you the possibility to use the cache! - For further explanation please see `Parser package`_ design. - -Interface description -~~~~~~~~~~~~~~~~~~~~~ - -*project_reader_t* and *source_reader_t* -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -+ *__init__( self, config, declarations_cache )* - *source_reader_t* allows - *declarations_cache* to be or instance of *cache_base_t* or None. *project_reader_t* - allows *declarations_cache* to be also path to cache file. - -+ *read_string(self, content)* - small convenience function. The *content* - should be valid C++ code. This function will return the list of top level - namespaces. - -+ *source_reader_t.read_file(self, source_file)* This function will return - the list of top level namespaces. - -+ *project_reader_t.read_files(self, files)* This function will return the top - level namespaces list. *files* - list of files to be compiled. This list may - contain a file name ( string ) or instance of class *file_configuration_t*. - If the item is an instance of class *file_configuration_t* then the file will - be compiled and parsed using its configuration. The project configuration stays - unchanged. - -+ *source_reader_t.create_xml_file(self, source_file, destination_file_path=None)* - This function will return the file name of the file, created by `GCC-XML`_. If - *destination_file_path* is not *None* then this file path will be used and - returned. - -+ *source_reader_t.read_xml_file(self, xmlfile)* This function will return the - top level namespaces list. - - Right now top level namespaces are: "::" and "std". - - The main purpose of *source_reader_t.create_xml_file* and *source_reader_t.read_xml_file* - is to ease cross-platform development. + #global_ns is the reference to declarations that describes C++ namespace. + #In our case, instance of that declarations describes global ( :: ) namespace. + global_ns.free_functions( "do_smth", return_type='void', arg_types=[None,'int'] ) -*pygccxml.parser* -^^^^^^^^^^^^^^^^^ -There are 2 functions: +Small explanation. Assume that ``None`` means "any type". Now the code is pretty +readable: +:: - 1. *parse(files, config=None, declarations_cache=None)* - 2. *parse_string(content, config=None)* + select all free functions + where + name equal to "do_smth" + return type is void + function has two arguments + second argument type is int -Those are *"shortcuts"* functions for *project_reader_t* class. +.. __: ./query_api.html +------- +License +------- -Implementation notes -~~~~~~~~~~~~~~~~~~~~ +`Boost Software License`_. -There are 2 private classes in this package: - - 1. *scanner_t* - this class scans the "XML" file, generated by `GCC-XML`_ and - creates `pygccxml`_ declarations and types classes. After the xml file has - been processed declarations and type class instances keeps references to - each other using `GCC-XML`_ generated id's. - - 2. *linker_t* - this class contains logic for replacing `GCC-XML`_ generated - ids with references to declarations or type class instances. - - ----------------- Test environments ----------------- `pygccxml`_ comes with comprehensive unit tests. It is running on Windows XP and -`Debian Linux`_. I am using `Python`_ [ 2.3 | 2.4 ] and `GCC-XML`_ [ 0.6.0 | CVS ]. +`Ubuntu`_. I am using `Python`_ 2.4 and `GCC-XML`_ CVS. Right now I am running more then 100 tests. They test almost every piece of code. Also I have performance tests. Most of the time I am using "white box" testing strategy. @@ -314,10 +133,7 @@ .. _`Python`: http://www.python.org .. _`GCC-XML`: http://www.gccxml.org .. _`Boost Software License`: http://boost.org/more/license_info.html -.. _`Debian Linux`: http://www.debian.org -.. _`UML diagram` : ./declarations_uml.png -.. _`Parser package` : ./parser_uml.png -.. _`ReleaseForge` : http://releaseforge.sourceforge.net +.. _`Ubuntu`: http://www.ubuntu.com/ .. _`boost::type_traits` : http://www.boost.org/libs/type_traits/index.html .. Local Variables: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-22 06:47:17
|
Revision: 148 Author: roman_yakovenko Date: 2006-05-21 23:47:04 -0700 (Sun, 21 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=148&view=rev Log Message: ----------- fixing broken links within documentation Modified Paths: -------------- pygccxml_dev/docs/download.rest pyplusplus_dev/docs/download.rest Modified: pygccxml_dev/docs/download.rest =================================================================== --- pygccxml_dev/docs/download.rest 2006-05-22 06:25:35 UTC (rev 147) +++ pygccxml_dev/docs/download.rest 2006-05-22 06:47:04 UTC (rev 148) @@ -21,10 +21,10 @@ https://sourceforge.net/project/showfiles.php?group_id=118209 ---------- -CVS access +SVN access ---------- -https://sourceforge.net/cvs/?group_id=118209 +http://sourceforge.net/svn/?group_id=118209 ------------ Installation @@ -44,8 +44,8 @@ * `GCC-XML`_ .. _`pygccxml` : ./../pygccxml/pygccxml.html -.. _`SourceForge`: http://sourceforge.net/index.php .. _`GCC-XML`: http://www.gccxml.org + .. Local Variables: mode: indented-text Modified: pyplusplus_dev/docs/download.rest =================================================================== --- pyplusplus_dev/docs/download.rest 2006-05-22 06:25:35 UTC (rev 147) +++ pyplusplus_dev/docs/download.rest 2006-05-22 06:47:04 UTC (rev 148) @@ -21,10 +21,10 @@ https://sourceforge.net/project/showfiles.php?group_id=118209 ---------- -CVS access +SVN access ---------- -https://sourceforge.net/cvs/?group_id=118209 +http://sourceforge.net/svn/?group_id=118209 ------------ Installation @@ -46,12 +46,7 @@ .. _`pyplusplus` : ./pyplusplus.html .. _`pygccxml` : ./../pygccxml/pygccxml.html -.. _`boost.python`: http://www.boost.org/libs/python/doc/index.html -.. _`SourceForge`: http://sourceforge.net/index.php -.. _`Docutils`: http://docutils.sourceforge.net -.. _`Python`: http://www.python.org -.. _`GCC-XML`: http://www.gccxml.org -.. _`Debian Linux`: http://www.debian.org + .. Local Variables: mode: indented-text This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-22 06:25:44
|
Revision: 147 Author: roman_yakovenko Date: 2006-05-21 23:25:35 -0700 (Sun, 21 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=147&view=rev Log Message: ----------- fixing broken links within documentation Modified Paths: -------------- pyplusplus_dev/docs/tutorials/module_builder/www_configuration.py pyplusplus_dev/docs/tutorials/tutorials.rest Modified: pyplusplus_dev/docs/tutorials/module_builder/www_configuration.py =================================================================== --- pyplusplus_dev/docs/tutorials/module_builder/www_configuration.py 2006-05-21 20:01:26 UTC (rev 146) +++ pyplusplus_dev/docs/tutorials/module_builder/www_configuration.py 2006-05-22 06:25:35 UTC (rev 147) @@ -1 +1 @@ -name = 'tutorials' \ No newline at end of file +name = 'module builder' \ No newline at end of file Modified: pyplusplus_dev/docs/tutorials/tutorials.rest =================================================================== --- pyplusplus_dev/docs/tutorials/tutorials.rest 2006-05-21 20:01:26 UTC (rev 146) +++ pyplusplus_dev/docs/tutorials/tutorials.rest 2006-05-22 06:25:35 UTC (rev 147) @@ -36,7 +36,7 @@ I suppose you decided to do some coding with `pyplusplus`_. `Module builder`_ tutorials will help you. -.. _`Module builder` : ./module_builder.html +.. _`Module builder` : ./module_builder/module_builder.html -------- Advanced This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-21 20:01:42
|
Revision: 146 Author: roman_yakovenko Date: 2006-05-21 13:01:26 -0700 (Sun, 21 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=146&view=rev Log Message: ----------- updating documentation Modified Paths: -------------- pygccxml_dev/docs/design.rest pygccxml_dev/pygccxml/parser/project_reader.py Added Paths: ----------- pygccxml_dev/docs/query_api.rest Modified: pygccxml_dev/docs/design.rest =================================================================== --- pygccxml_dev/docs/design.rest 2006-05-21 13:54:20 UTC (rev 145) +++ pygccxml_dev/docs/design.rest 2006-05-21 20:01:26 UTC (rev 146) @@ -1,9 +1,9 @@ -=============== +=============== pygccxml design =============== .. contents:: Table of contents - + ------------------------ The view from 10000 fits ------------------------ @@ -12,8 +12,8 @@ * ``declarations`` package defines classes that describe C++ declarations and types -* ``parser`` package defines classes that parse `GCC-XML`_ generared files. Also - it defines few classes that will help you to eliminate unnecessary parsing of +* ``parser`` package defines classes that parse `GCC-XML`_ generared files. Also + it defines few classes that will help you to eliminate unnecessary parsing of C++ source files. * ``utils`` package defines few functions, I found useful in the whole project. @@ -22,105 +22,105 @@ ``declarations`` package ------------------------- -Please take a look on `UML diagram`_. This `UML diagram`_ describes almost all -classes defined in the package and their relationship. ``declarations`` package -defines two hierarchies of class: - -1. types hiearchy - used to represent a C++ type - +Please take a look on `UML diagram`_. This `UML diagram`_ describes almost all +classes defined in the package and their relationship. ``declarations`` package +defines two hierarchies of class: + +1. types hierarchy - used to represent a C++ type + 2. declarations hierarchy - used to represent a C++ declaration. - + Types hierarchy --------------- -Types hierarchy is used to represent an arbitrary type in C++. class ``type_t`` -is the base class. +Types hierarchy is used to represent an arbitrary type in C++. class ``type_t`` +is the base class. ``type_traits`` ~~~~~~~~~~~~~~~ -Are you aware of `boost::type_traits`_ library? The `boost::type_traits`_ -library has been developed by John Maddock, Steve Cleary and others. The -`boost::type_traits`_ library contains a set of very specific traits classes, -each of which encapsulate a single trait from the C++ type system; for example, -is a type a pointer or a reference type? Or does a type have a trivial constructor, +Are you aware of `boost::type_traits`_ library? The `boost::type_traits`_ +library has been developed by John Maddock, Steve Cleary and others. The +`boost::type_traits`_ library contains a set of very specific traits classes, +each of which encapsulate a single trait from the C++ type system; for example, +is a type a pointer or a reference type? Or does a type have a trivial constructor, or a const-qualifier? -`pygccxml`_ implements a lot of functionality from the library: - -* a lot of algorithms has been implemented - - + ``is_same`` - - + ``is_enum`` - - + ``is_void`` - - + ``is_const`` - - + ``is_array`` - - + ``is_pointer`` - - + ``is_volatile`` - - + ``is_integral`` - - + ``is_reference`` - - + ``is_arithmetic`` - - + ``is_convertible`` - - + ``is_fundamental`` - - + ``is_floating_point`` - - + ``is_base_and_derived`` - - + ``is_unary_operator`` - - + ``is_binary_operator`` - - + ``remove_cv`` - - + ``remove_const`` - - + ``remove_alias`` - - + ``remove_pointer`` - - + ``remove_volatile`` - - + ``remove_reference`` - - + ``has_trivial_copy`` - - + ``has_trivial_constructor`` - - + ``has_any_non_copyconstructor`` - - For a full list of implemented algorithms, please consult API documentation. - -* a lot of unit tests has been written base on unit tests from the +`pygccxml`_ implements a lot of functionality from the library: + +* a lot of algorithms has been implemented + + + ``is_same`` + + + ``is_enum`` + + + ``is_void`` + + + ``is_const`` + + + ``is_array`` + + + ``is_pointer`` + + + ``is_volatile`` + + + ``is_integral`` + + + ``is_reference`` + + + ``is_arithmetic`` + + + ``is_convertible`` + + + ``is_fundamental`` + + + ``is_floating_point`` + + + ``is_base_and_derived`` + + + ``is_unary_operator`` + + + ``is_binary_operator`` + + + ``remove_cv`` + + + ``remove_const`` + + + ``remove_alias`` + + + ``remove_pointer`` + + + ``remove_volatile`` + + + ``remove_reference`` + + + ``has_trivial_copy`` + + + ``has_trivial_constructor`` + + + ``has_any_non_copyconstructor`` + + For a full list of implemented algorithms, please consult API documentation. + +* a lot of unit tests has been written base on unit tests from the `boost::type_traits`_ library. - - + + If you are going to build code generator, you will find ``type_traits`` very handy. Declarations hierarchy ---------------------- -A declaration hierarchy is used to represent an arbitrary C++ declaration. +A declaration hierarchy is used to represent an arbitrary C++ declaration. Basically, most of the classes defined in this package are just "set of properties". ``declaration_t`` is the base class of the declaration hierarchy. Every declaration -has ``parent`` property. This property keeps a reference to the scope declaration -instance, in which this declaration is defined. +has ``parent`` property. This property keeps a reference to the scope declaration +instance, in which this declaration is defined. -The ``scopedef_t`` class derives from ``declaration_t``. This class is used to -say - "I may have other declarations inside". The "composite" design pattern is +The ``scopedef_t`` class derives from ``declaration_t``. This class is used to +say - "I may have other declarations inside". The "composite" design pattern is used here. ``class_t`` and ``namespace_t`` declaration classes derive from the ``scopedef_t`` class. @@ -128,8 +128,8 @@ ``parser`` package ------------------ -Please take a look on `parser package UML diagram`_ . Classes defined in this -package implement parsing and linking functionality. There are few kind of +Please take a look on `parser package UML diagram`_ . Classes defined in this +package implement parsing and linking functionality. There are few kind of classes defined by the package: * classes, that implements parsing algorithms of `GCC-XML`_ generated XML file @@ -138,73 +138,136 @@ * cache - classes, those one will help you to eliminate unnecessary parsing -* patchers - classes, that fix `GCC-XML`_ generated declarations. ( Yes, sometimes +* patchers - classes, that fix `GCC-XML`_ generated declarations. ( Yes, sometimes GCC-XML generates wrong description of C++ declaration. ) Parser classes -------------- -``source_reader_t`` - the only class that have an intime knowledge about `GCC-XML`_. +``source_reader_t`` - the only class that have an detailed knowledge about `GCC-XML`_. It has only one responsibility: it calls `GCC-XML`_ with a source file specified by user and creates declarations tree. The implementation of this class is split to 2 classes: - -1. ``scanner_t`` - this class scans the "XML" file, generated by `GCC-XML`_ and - creates `pygccxml`_ declarations and types classes. After the xml file has - been processed declarations and type class instances keeps references to - each other using `GCC-XML`_ generated id's. - -2. ``linker_t`` - this class contains logic for replacing `GCC-XML`_ generated + +1. ``scanner_t`` - this class scans the "XML" file, generated by `GCC-XML`_ and + creates `pygccxml`_ declarations and types classes. After the xml file has + been processed declarations and type class instances keeps references to + each other using `GCC-XML`_ generated id's. + +2. ``linker_t`` - this class contains logic for replacing `GCC-XML`_ generated ids with references to declarations or type class instances. -Both those classes are implementation details and should not be used by user. -Performance note: ``scanner_t`` class uses Python ``xml.sax`` package in order -to parse XML. As a result, ``scanner_t`` class is able to parse even big XML files -pretty quick. - -``project_reader_t`` - think about this class as a linker. In most cases you work +Both those classes are implementation details and should not be used by user. +Performance note: ``scanner_t`` class uses Python ``xml.sax`` package in order +to parse XML. As a result, ``scanner_t`` class is able to parse even big XML files +pretty quick. + +``project_reader_t`` - think about this class as a linker. In most cases you work with few source files. GCC-XML does not supports this mode of work. So, `pygccxml`_ -implements all functionlity needed to parse few source files at once. +implements all functionality needed to parse few source files at once. ``project_reader_t`` implements 2 different algorithms, that solves the problem: -1. ``project_reader_t`` creates temporal source file, that includes all the source - files. +1. ``project_reader_t`` creates temporal source file, that includes all the source + files. -2. ``project_reader_t`` parse separetly every source file, using ``source_reader_t`` +2. ``project_reader_t`` parse separately every source file, using ``source_reader_t`` class and then joins the resulting declarations tree into single declarations tree. - + Both approaches have different trades-off. The first approach does not allow you -to reuse information from already parsed source files. While the second one -allows you to setup cache. - -Parser configuration classes ----------------------------- +to reuse information from already parsed source files. While the second one +allows you to setup cache. -``config_t`` - a class, that accumulates all the settings needed to invoke `GCC-XML`_: - - -``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 - user will ask to parse the source file, the XML file will be used instead. - -(4) Python string, that contains valid C++ code - - -Cache classes -------------- - +Parser configuration classes +---------------------------- +``config_t`` - a class, that accumulates all the settings needed to invoke `GCC-XML`_: + +``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: + +* ``def create_source_fc( header )`` + + ``header`` contains path to C++ source file + +* ``def create_gccxml_fc( xml_file )`` + + ``xml_file`` contains path to `GCC-XML`_ generated XML file + +* ``def create_cached_source_fc( header, cached_source_file )`` + + - ``header`` contains path to C++ source file + - ``xml_file`` contains path to `GCC-XML`_ generated XML file + +* ``def create_text_fc( text )`` + + ``text`` - Python string, that contains valid C++ code + + +Cache classes +------------- + +There are few cache classes, that implements different cache strategies. My +advise - don't use them. Your best choice is ``file_configuration_t``, +configured to C++ source file + `GCC-XML`_ generated file. + +* ``file_cache_t`` class, will save all declarations from all files within single + binary file. + +* ``directory_cache_t`` class will store one index file called "index.dat" which + is always read by the cache when the cache object is created. Each header file + will have its corresponding \*.cache file that stores the declarations found + in the header file. The index file is used to determine whether a \*.cache file + is still valid or not (by checking if one of the dependent files + (i.e. the header file itself and all included files) have been modified since + the last run). + +As you can guess, ``directory_cache_t`` class gives much better performance, than +``file_cache_t``. Many thanks to Matthias Baas for its implemention. + + +Patchers +-------- + +????. Well, `GCC-XML`_ has few bugs, that could not be fixed from it. For example +:: + + namespace ns1{ namespace ns2{ + enum fruit{ apple, orange }; + } } + + void fix_enum( ns1::ns2::fruit arg=ns1::ns2::apple ); + +`GCC-XML`_ will report the default value of ``arg`` as ``apple``. Obviously +this in an error. `pygccxml`_ knows how to fix different bugs. + +------- +Summary +------- + +Thats all. I hope I was clear, at least I tried. Any way we are talking about +open source project. You can take a look on source code. If you need more information +you can take a look on API documentation. + .. _`pygccxml`: ./pygccxml.html .. _`SourceForge`: http://sourceforge.net/index.php .. _`Python`: http://www.python.org Added: pygccxml_dev/docs/query_api.rest =================================================================== --- pygccxml_dev/docs/query_api.rest (rev 0) +++ pygccxml_dev/docs/query_api.rest 2006-05-21 20:01:26 UTC (rev 146) @@ -0,0 +1,67 @@ +=============================== +pygccxml.declarations query API +=============================== + +.. contents:: Table of contents + +------------ +Introduction +------------ +You parsed the source files. Now you have to do some real work with the extracted +information, right? `pygccxml`_ provides very powerful and simple interface to +query about extracted declrations. + +Just an example. I want to select all member functions, that have 2 arguments. +I don't care about first argument type, but I do want second argument type to be +a reference to an integer. More over, I want those functions names to end with +"impl" string and they should be protected or private. +:: + + #global_ns is the reference to an instance of namespace_t object, that + #represents global namespace + query = declarations.custom_matcher_t( lambda mem_fun: mem_fun.name.endswith( 'impl' ) + query = query & ~declarations.access_type_matcher_t( 'public' ) + global_ns.member_functions( function=query, arg_types=[None, 'int &'] ) + +As for me the example I gave was too complex. In many cases you will find your +self looking for one or many declarations using one or two properties of that +declaration(s). For example: +:: + + global_ns.namespaces( 'details' ) + +This call will return all namespaces that have 'details' namespace. + +------------------ +How does it works? +------------------ + +As you already know, ``pygccxml.declarations`` packages defines next classes: + +* ``scopedef_t`` - base class for all classes, that can contain other declarations + +* ``namespace_t`` - derives from ``scopedef_t`` class, represents C++ namespace + +* ``class_t`` - derives from ``scopedef_t`` class, represents C++ class/struct. + +``scopedef_t`` class defines query interface. Basicaly you can ask it about any +declaration it contains, even about some sub declarations. + + + + +.. _`pygccxml`: ./pygccxml.html +.. _`SourceForge`: http://sourceforge.net/index.php +.. _`Python`: http://www.python.org +.. _`GCC-XML`: http://www.gccxml.org +.. _`UML diagram` : ./declarations_uml.png +.. _`parser package UML diagram` : ./parser_uml.png +.. _`ReleaseForge` : http://releaseforge.sourceforge.net +.. _`boost::type_traits` : http://www.boost.org/libs/type_traits/index.html +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + End: \ No newline at end of file Modified: pygccxml_dev/pygccxml/parser/project_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/project_reader.py 2006-05-21 13:54:20 UTC (rev 145) +++ pygccxml_dev/pygccxml/parser/project_reader.py 2006-05-21 20:01:26 UTC (rev 146) @@ -17,51 +17,38 @@ class file_configuration_t( object ): - """ - file_configuration_t class is cool feature. When you want to parse C++ code - from different sources at once, you should use this class. -class instance you should pass list of files. This list can contain string( == file paths ) and/or instances of file_configuration_t class. + """ + 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: -file_configuration_t is class with fat interface. -It has 4 states: - 1. it could contain reference to source file. - Use "create_source_fc" function to create an instance of file_configuration_t + * L{create_source_fc} + + * L{create_gccxml_fc} + + * L{create_cached_source_fc} - 2. it could contain reference to source file and xml file. In this case if xml file - exist, source file will not be parsed by gccxml. If xml file does not exists, source - file will be parsed and xml file will be saved for future use. - See create_cached_source_fc function - - 3. it could contain reference to xml file only - See create_gccxml_fc - - 4. it could contain some text. In this case, parser will create temporal file on - disk and will pass it as an argument to gccxml. - See create_text_fc - -In most cases you don't all those features. If I were you, I would create regular -source file and put all template instantiation there. - -Any way the code: - -tmpl_inst = ''' -===================== - #include "TempClass.h" - - namespace details{ - inline void export_templates(){ - sizeof( TempClass<int> ); - } - } -''' - -import module_builder -mb = module_builder.module_builder_t( - [ module_builder.create_text_fc( tmpl_inst ) ] - , .... ) - -""" - + * L{create_text_fc} + + """ class CONTENT_TYPE: STANDARD_SOURCE_FILE = 'standard source file' CACHED_SOURCE_FILE = 'cached source file' @@ -101,18 +88,59 @@ 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 , content_type=file_configuration_t.CONTENT_TYPE.TEXT ) def create_source_fc( header ): + """ + 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 ) def create_gccxml_fc( xml_file ): + """ + 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 ) def create_cached_source_fc( header, cached_source_file ): + """ + Creates L{file_configuration_t} instance, configured to contain path to + GCC-XML generated XML file and C++ source file. If XML file does not exists, + it will be created and used for parsing. If XML file exists, it will be used + for parsing. + + @param header: path to C++ source file + @type header: str + + @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 ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-21 13:54:28
|
Revision: 145 Author: roman_yakovenko Date: 2006-05-21 06:54:20 -0700 (Sun, 21 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=145&view=rev Log Message: ----------- updating design document Modified Paths: -------------- pygccxml_dev/docs/design.rest Modified: pygccxml_dev/docs/design.rest =================================================================== --- pygccxml_dev/docs/design.rest 2006-05-20 20:28:08 UTC (rev 144) +++ pygccxml_dev/docs/design.rest 2006-05-21 13:54:20 UTC (rev 145) @@ -4,142 +4,120 @@ .. contents:: Table of contents ------------------------ -The view from 1000 fits ------------------------ +------------------------ +The view from 10000 fits +------------------------ `pygccxml`_ has 3 packages: -1. ``declarations`` - This package defines classes that describe C++ declarations and types. +* ``declarations`` package defines classes that describe C++ declarations and types -2. ``parser`` - This package defines classes that parse `GCC-XML`_ generared files and classes - that will help you to eliminate unnecessary parsing of C++ source files. +* ``parser`` package defines classes that parse `GCC-XML`_ generared files. Also + it defines few classes that will help you to eliminate unnecessary parsing of + C++ source files. -3. ``utils`` - This package defines few functions, that I found useful in the previous - packages. +* ``utils`` package defines few functions, I found useful in the whole project. ------------------------- ``declarations`` package ------------------------- -Please take a look on `UML diagram`_. It contains all the classes are defined by -the `pygccxml`_.declarations package. Defined classes are used to describe almost -any C++ declaration. +Please take a look on `UML diagram`_. This `UML diagram`_ describes almost all +classes defined in the package and their relationship. ``declarations`` package +defines two hierarchies of class: + +1. types hiearchy - used to represent a C++ type + +2. declarations hierarchy - used to represent a C++ declaration. + -A few words about the naming convention used. Every class name ends with "_t". -The are several reasons for this: - - * I am used to the C++ "std" convention, i.e. lower-case letters with underscores. - - * Most of the names are already used in Python, and have a different meaning. - Types hierarchy --------------- -Types hierarchy is used to represent an arbitrary type in C++. +Types hierarchy is used to represent an arbitrary type in C++. class ``type_t`` +is the base class. -Example -~~~~~~~ - -For a variable "ptr" - - ``const int\* ptr=0;`` - -`pygccxml`_ will create the type - - ``pointer_t( const_t( int_t() ) )`` - -The ability to represent almost any type of C++ comes from the use of the -"decorator" pattern. - ``type_traits`` ~~~~~~~~~~~~~~~ -Are you aware of `boost::type_traits`_ library? The `boost::type_traits`_ +Are you aware of `boost::type_traits`_ library? The `boost::type_traits`_ library has been developed by John Maddock, Steve Cleary and others. The -`boost::type_traits`_ library contains a set of very specific traits classes, +`boost::type_traits`_ library contains a set of very specific traits classes, each of which encapsulate a single trait from the C++ type system; for example, is a type a pointer or a reference type? Or does a type have a trivial constructor, or a const-qualifier? -`pygccxml`_ implements a lot of algorithm from the library. It also reuses the -names proposed by this library. Also I took few ideas for testing the `pygccxml`_ -type traits implementation. Here are some of the type traits implemented by `pygccxml`_. - - + ``base_type`` - - + ``decompose_type`` - - + ``decompose_class`` - - + ``is_same`` - - + ``is_enum`` - - + ``is_void`` - - + ``is_const`` - - + ``is_array`` - - + ``is_pointer`` - - + ``is_volatile`` - - + ``is_integral`` - - + ``is_reference`` - - + ``is_arithmetic`` - - + ``is_convertible`` - - + ``is_fundamental`` - - + ``is_floating_point`` - - + ``is_base_and_derived`` - - + ``is_unary_operator`` - - + ``is_binary_operator`` - - + ``remove_cv`` - - + ``remove_const`` - - + ``remove_alias`` - - + ``remove_pointer`` - - + ``remove_volatile`` - - + ``remove_reference`` - - + ``has_trivial_copy`` - - + ``has_trivial_constructor`` - - + ``find_trivial_constructor`` - - + ``has_any_non_copyconstructor`` - - + ``...`` - +`pygccxml`_ implements a lot of functionality from the library: + +* a lot of algorithms has been implemented + + + ``is_same`` + + + ``is_enum`` + + + ``is_void`` + + + ``is_const`` + + + ``is_array`` + + + ``is_pointer`` + + + ``is_volatile`` + + + ``is_integral`` + + + ``is_reference`` + + + ``is_arithmetic`` + + + ``is_convertible`` + + + ``is_fundamental`` + + + ``is_floating_point`` + + + ``is_base_and_derived`` + + + ``is_unary_operator`` + + + ``is_binary_operator`` + + + ``remove_cv`` + + + ``remove_const`` + + + ``remove_alias`` + + + ``remove_pointer`` + + + ``remove_volatile`` + + + ``remove_reference`` + + + ``has_trivial_copy`` + + + ``has_trivial_constructor`` + + + ``has_any_non_copyconstructor`` + + For a full list of implemented algorithms, please consult API documentation. + +* a lot of unit tests has been written base on unit tests from the + `boost::type_traits`_ library. + + If you are going to build code generator, you will find ``type_traits`` very handy. Declarations hierarchy ---------------------- +---------------------- A declaration hierarchy is used to represent an arbitrary C++ declaration. Basically, most of the classes defined in this package are just "set of properties". ``declaration_t`` is the base class of the declaration hierarchy. Every declaration has ``parent`` property. This property keeps a reference to the scope declaration -instance in which this declaration is defined. +instance, in which this declaration is defined. The ``scopedef_t`` class derives from ``declaration_t``. This class is used to say - "I may have other declarations inside". The "composite" design pattern is @@ -150,45 +128,44 @@ ``parser`` package ------------------ -User API --------- +Please take a look on `parser package UML diagram`_ . Classes defined in this +package implement parsing and linking functionality. There are few kind of +classes defined by the package: -Please take a look on `parser package`_ ( "`pygccxml`_.parser" ) UML diagram. -This is the heart of the `pygccxml`_ project. Classes in this package implement -parsing and binding/linking functionality. There are few types of classes defined -by the package: +* classes, that implements parsing algorithms of `GCC-XML`_ generated XML file -1. classes, that implements file parsing +* classes, that configure "parser" -2. classes, that configure "parser" +* cache - classes, those one will help you to eliminate unnecessary parsing -3. cache - classes +* patchers - classes, that fix `GCC-XML`_ generated declarations. ( Yes, sometimes + GCC-XML generates wrong description of C++ declaration. ) -4. patchers - classes, that fix `GCC-XML`_ generated declarations - -Next few paragraphs will tell you more about those classes. - Parser classes -------------- ``source_reader_t`` - the only class that have an intime knowledge about `GCC-XML`_. It has only one responsibility: it calls `GCC-XML`_ with a source file specified by user and creates declarations tree. The implementation of this class is split -to 2 classes: -1. ``scanner_t `` - this class scans the "XML" file, generated by `GCC-XML`_ and +to 2 classes: + +1. ``scanner_t`` - this class scans the "XML" file, generated by `GCC-XML`_ and creates `pygccxml`_ declarations and types classes. After the xml file has been processed declarations and type class instances keeps references to - each other using `GCC-XML`_ generated id's. - + each other using `GCC-XML`_ generated id's. + 2. ``linker_t`` - this class contains logic for replacing `GCC-XML`_ generated ids with references to declarations or type class instances. -Both those classes are implementation details and should not be used by user. +Both those classes are implementation details and should not be used by user. +Performance note: ``scanner_t`` class uses Python ``xml.sax`` package in order +to parse XML. As a result, ``scanner_t`` class is able to parse even big XML files +pretty quick. -``project_reader_t`` - think of this class as a linker or a binder. In most cases -you work with few source files. GCC-XML does not supports this mode. So,`pygccxml`_ -implements all functionlity to parse few source files at once. ``project_reader_t`` -implements 2 different algorithms, that solves the problem: +``project_reader_t`` - think about this class as a linker. In most cases you work +with few source files. GCC-XML does not supports this mode of work. So, `pygccxml`_ +implements all functionlity needed to parse few source files at once. +``project_reader_t`` implements 2 different algorithms, that solves the problem: 1. ``project_reader_t`` creates temporal source file, that includes all the source files. @@ -197,92 +174,43 @@ class and then joins the resulting declarations tree into single declarations tree. -Both approaches have different trades-off. The firs approach does not allow you -to reuse already parsed source files. +Both approaches have different trades-off. The first approach does not allow you +to reuse information from already parsed source files. While the second one +allows you to setup cache. + +Parser configuration classes +---------------------------- +``config_t`` - a class, that accumulates all the settings needed to invoke `GCC-XML`_: + + +``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 + user will ask to parse the source file, the XML file will be used instead. + +(4) Python string, that contains valid C++ code + + +Cache classes +------------- + -``config_t`` - a class that accumulates all the settings of `GCC-XML`_ and -`pygccxml`_. Users can work with relative files paths. In this case files are -searched in the following order: -1. current directory - -2. working directory - -3. additional include paths specified by the user - - -Interface description -~~~~~~~~~~~~~~~~~~~~~ - -``project_reader_t`` and ``source_reader_t`` -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -+ ``__init__( self, config, declarations_cache )`` - ``source_reader_t`` allows - ``declarations_cache`` to be or instance of ``cache_base_t`` or None. ``project_reader_t`` - allows ``declarations_cache`` to be also path to cache file. - -+ ``read_string(self, content)`` - small convenience function. The ``content`` - should be valid C++ code. This function will return the list of top level - namespaces. - -+ ``source_reader_t.read_file(self, source_file)`` - this function will return - the list of top level namespaces. - -+ ``project_reader_t.read_files(self, files)`` This function will return the top - level namespaces list. ``files`` - list of files to be compiled. This list may - contain a file name ( string ) or instance of class ``file_configuration_t``. - If the item is an instance of class ``file_configuration_t`` then the file will - be compiled and parsed using its configuration. The project configuration stays - unchanged. - -+ ``source_reader_t.create_xml_file(self, source_file, destination_file_path=None)`` - This function will return the file name of the file, created by `GCC-XML`_. If - ``destination_file_path`` is not ``None`` then this file path will be used and - returned. - -+ ``source_reader_t.read_xml_file(self, xmlfile)`` This function will return the - top level namespaces list. - - Right now top level namespaces are: "::" and "std". - - The main purpose of ``source_reader_t.create_xml_file`` and ``source_reader_t.read_xml_file`` - is to ease cross-platform development. - -``pygccxml.parser`` -^^^^^^^^^^^^^^^^^^^ - -There are 2 functions: - - 1. ``parse(files, config=None, declarations_cache=None)`` - 2. ``parse_string(content, config=None)`` - -Those are ``shortcuts`` functions for ``project_reader_t`` class. - - - - ------------------ -Test environments ------------------ - -`pygccxml`_ comes with comprehensive unit tests. It is running on Windows XP and -`Debian Linux`_. I am using `Python`_ [ 2.3 | 2.4 ] and `GCC-XML`_ [ 0.6.0 | CVS ]. -Right now I am running more then 100 tests. They test almost every piece of code. -Also I have performance tests. Most of the time I am using "white box" testing -strategy. - -.. _`WSDL`: http://www.w3.org/TR/wsdl -.. _`pyplusplus`: ./../pyplusplus/pyplusplus.html .. _`pygccxml`: ./pygccxml.html .. _`SourceForge`: http://sourceforge.net/index.php -.. _`Docutils`: http://docutils.sourceforge.net .. _`Python`: http://www.python.org .. _`GCC-XML`: http://www.gccxml.org -.. _`Boost Software License`: http://boost.org/more/license_info.html -.. _`Debian Linux`: http://www.debian.org .. _`UML diagram` : ./declarations_uml.png -.. _`Parser package` : ./parser_uml.png +.. _`parser package UML diagram` : ./parser_uml.png .. _`ReleaseForge` : http://releaseforge.sourceforge.net .. _`boost::type_traits` : http://www.boost.org/libs/type_traits/index.html .. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-20 20:28:45
|
Revision: 144 Author: roman_yakovenko Date: 2006-05-20 13:28:08 -0700 (Sat, 20 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=144&view=rev Log Message: ----------- optimzing so files for space Modified Paths: -------------- pyplusplus_dev/examples/pyboost_dev/sconstruct Modified: pyplusplus_dev/examples/pyboost_dev/sconstruct =================================================================== --- pyplusplus_dev/examples/pyboost_dev/sconstruct 2006-05-20 20:26:18 UTC (rev 143) +++ pyplusplus_dev/examples/pyboost_dev/sconstruct 2006-05-20 20:28:08 UTC (rev 144) @@ -19,7 +19,7 @@ if sys.platform == 'win32': env.Replace( no_import_lib=1 ) else: - env.Append( CCFLAGS=' -ggdb3 -DNDEBUG -O3' ) + env.Append( CCFLAGS=' -Os -fPIC -fvisibility=hidden' ) Export( 'env' ) env.SConscript( ['dev/date_time/sconscript'] ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rom...@us...> - 2006-05-20 20:26:33
|
Revision: 143 Author: roman_yakovenko Date: 2006-05-20 13:26:18 -0700 (Sat, 20 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=143&view=rev Log Message: ----------- adding design document Added Paths: ----------- pygccxml_dev/docs/design.rest Added: pygccxml_dev/docs/design.rest =================================================================== --- pygccxml_dev/docs/design.rest (rev 0) +++ pygccxml_dev/docs/design.rest 2006-05-20 20:26:18 UTC (rev 143) @@ -0,0 +1,294 @@ +=============== +pygccxml design +=============== + +.. contents:: Table of contents + +----------------------- +The view from 1000 fits +----------------------- + +`pygccxml`_ has 3 packages: + +1. ``declarations`` + This package defines classes that describe C++ declarations and types. + +2. ``parser`` + This package defines classes that parse `GCC-XML`_ generared files and classes + that will help you to eliminate unnecessary parsing of C++ source files. + +3. ``utils`` + This package defines few functions, that I found useful in the previous + packages. + +------------------------- +``declarations`` package +------------------------- + +Please take a look on `UML diagram`_. It contains all the classes are defined by +the `pygccxml`_.declarations package. Defined classes are used to describe almost +any C++ declaration. + +A few words about the naming convention used. Every class name ends with "_t". +The are several reasons for this: + + * I am used to the C++ "std" convention, i.e. lower-case letters with underscores. + + * Most of the names are already used in Python, and have a different meaning. + +Types hierarchy +--------------- + +Types hierarchy is used to represent an arbitrary type in C++. + +Example +~~~~~~~ + +For a variable "ptr" + + ``const int\* ptr=0;`` + +`pygccxml`_ will create the type + + ``pointer_t( const_t( int_t() ) )`` + +The ability to represent almost any type of C++ comes from the use of the +"decorator" pattern. + +``type_traits`` +~~~~~~~~~~~~~~~ + +Are you aware of `boost::type_traits`_ library? The `boost::type_traits`_ +library has been developed by John Maddock, Steve Cleary and others. The +`boost::type_traits`_ library contains a set of very specific traits classes, +each of which encapsulate a single trait from the C++ type system; for example, +is a type a pointer or a reference type? Or does a type have a trivial constructor, +or a const-qualifier? + +`pygccxml`_ implements a lot of algorithm from the library. It also reuses the +names proposed by this library. Also I took few ideas for testing the `pygccxml`_ +type traits implementation. Here are some of the type traits implemented by `pygccxml`_. + + + ``base_type`` + + + ``decompose_type`` + + + ``decompose_class`` + + + ``is_same`` + + + ``is_enum`` + + + ``is_void`` + + + ``is_const`` + + + ``is_array`` + + + ``is_pointer`` + + + ``is_volatile`` + + + ``is_integral`` + + + ``is_reference`` + + + ``is_arithmetic`` + + + ``is_convertible`` + + + ``is_fundamental`` + + + ``is_floating_point`` + + + ``is_base_and_derived`` + + + ``is_unary_operator`` + + + ``is_binary_operator`` + + + ``remove_cv`` + + + ``remove_const`` + + + ``remove_alias`` + + + ``remove_pointer`` + + + ``remove_volatile`` + + + ``remove_reference`` + + + ``has_trivial_copy`` + + + ``has_trivial_constructor`` + + + ``find_trivial_constructor`` + + + ``has_any_non_copyconstructor`` + + + ``...`` + +If you are going to build code generator, you will find ``type_traits`` very handy. + +Declarations hierarchy +--------------------- + +A declaration hierarchy is used to represent an arbitrary C++ declaration. +Basically, most of the classes defined in this package are just "set of properties". + +``declaration_t`` is the base class of the declaration hierarchy. Every declaration +has ``parent`` property. This property keeps a reference to the scope declaration +instance in which this declaration is defined. + +The ``scopedef_t`` class derives from ``declaration_t``. This class is used to +say - "I may have other declarations inside". The "composite" design pattern is +used here. ``class_t`` and ``namespace_t`` declaration classes derive from the +``scopedef_t`` class. + +------------------ +``parser`` package +------------------ + +User API +-------- + +Please take a look on `parser package`_ ( "`pygccxml`_.parser" ) UML diagram. +This is the heart of the `pygccxml`_ project. Classes in this package implement +parsing and binding/linking functionality. There are few types of classes defined +by the package: + +1. classes, that implements file parsing + +2. classes, that configure "parser" + +3. cache - classes + +4. patchers - classes, that fix `GCC-XML`_ generated declarations + +Next few paragraphs will tell you more about those classes. + +Parser classes +-------------- + +``source_reader_t`` - the only class that have an intime knowledge about `GCC-XML`_. +It has only one responsibility: it calls `GCC-XML`_ with a source file specified +by user and creates declarations tree. The implementation of this class is split +to 2 classes: +1. ``scanner_t `` - this class scans the "XML" file, generated by `GCC-XML`_ and + creates `pygccxml`_ declarations and types classes. After the xml file has + been processed declarations and type class instances keeps references to + each other using `GCC-XML`_ generated id's. + +2. ``linker_t`` - this class contains logic for replacing `GCC-XML`_ generated + ids with references to declarations or type class instances. + +Both those classes are implementation details and should not be used by user. + +``project_reader_t`` - think of this class as a linker or a binder. In most cases +you work with few source files. GCC-XML does not supports this mode. So,`pygccxml`_ +implements all functionlity to parse few source files at once. ``project_reader_t`` +implements 2 different algorithms, that solves the problem: + +1. ``project_reader_t`` creates temporal source file, that includes all the source + files. + +2. ``project_reader_t`` parse separetly every source file, using ``source_reader_t`` + class and then joins the resulting declarations tree into single declarations + tree. + +Both approaches have different trades-off. The firs approach does not allow you +to reuse already parsed source files. + + +``config_t`` - a class that accumulates all the settings of `GCC-XML`_ and +`pygccxml`_. Users can work with relative files paths. In this case files are +searched in the following order: + +1. current directory + +2. working directory + +3. additional include paths specified by the user + + +Interface description +~~~~~~~~~~~~~~~~~~~~~ + +``project_reader_t`` and ``source_reader_t`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + ++ ``__init__( self, config, declarations_cache )`` - ``source_reader_t`` allows + ``declarations_cache`` to be or instance of ``cache_base_t`` or None. ``project_reader_t`` + allows ``declarations_cache`` to be also path to cache file. + ++ ``read_string(self, content)`` - small convenience function. The ``content`` + should be valid C++ code. This function will return the list of top level + namespaces. + ++ ``source_reader_t.read_file(self, source_file)`` - this function will return + the list of top level namespaces. + ++ ``project_reader_t.read_files(self, files)`` This function will return the top + level namespaces list. ``files`` - list of files to be compiled. This list may + contain a file name ( string ) or instance of class ``file_configuration_t``. + If the item is an instance of class ``file_configuration_t`` then the file will + be compiled and parsed using its configuration. The project configuration stays + unchanged. + ++ ``source_reader_t.create_xml_file(self, source_file, destination_file_path=None)`` + This function will return the file name of the file, created by `GCC-XML`_. If + ``destination_file_path`` is not ``None`` then this file path will be used and + returned. + ++ ``source_reader_t.read_xml_file(self, xmlfile)`` This function will return the + top level namespaces list. + + Right now top level namespaces are: "::" and "std". + + The main purpose of ``source_reader_t.create_xml_file`` and ``source_reader_t.read_xml_file`` + is to ease cross-platform development. + +``pygccxml.parser`` +^^^^^^^^^^^^^^^^^^^ + +There are 2 functions: + + 1. ``parse(files, config=None, declarations_cache=None)`` + 2. ``parse_string(content, config=None)`` + +Those are ``shortcuts`` functions for ``project_reader_t`` class. + + + + +----------------- +Test environments +----------------- + +`pygccxml`_ comes with comprehensive unit tests. It is running on Windows XP and +`Debian Linux`_. I am using `Python`_ [ 2.3 | 2.4 ] and `GCC-XML`_ [ 0.6.0 | CVS ]. +Right now I am running more then 100 tests. They test almost every piece of code. +Also I have performance tests. Most of the time I am using "white box" testing +strategy. + +.. _`WSDL`: http://www.w3.org/TR/wsdl +.. _`pyplusplus`: ./../pyplusplus/pyplusplus.html +.. _`pygccxml`: ./pygccxml.html +.. _`SourceForge`: http://sourceforge.net/index.php +.. _`Docutils`: http://docutils.sourceforge.net +.. _`Python`: http://www.python.org +.. _`GCC-XML`: http://www.gccxml.org +.. _`Boost Software License`: http://boost.org/more/license_info.html +.. _`Debian Linux`: http://www.debian.org +.. _`UML diagram` : ./declarations_uml.png +.. _`Parser package` : ./parser_uml.png +.. _`ReleaseForge` : http://releaseforge.sourceforge.net +.. _`boost::type_traits` : http://www.boost.org/libs/type_traits/index.html +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + End: \ 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-05-20 20:25:30
|
Revision: 142 Author: roman_yakovenko Date: 2006-05-20 13:25:22 -0700 (Sat, 20 May 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=142&view=rev Log Message: ----------- adding doc strings Modified Paths: -------------- pygccxml_dev/pygccxml/parser/config.py pygccxml_dev/pygccxml/parser/project_reader.py pygccxml_dev/pygccxml/parser/source_reader.py Modified: pygccxml_dev/pygccxml/parser/config.py =================================================================== --- pygccxml_dev/pygccxml/parser/config.py 2006-05-18 15:11:59 UTC (rev 141) +++ pygccxml_dev/pygccxml/parser/config.py 2006-05-20 20:25:22 UTC (rev 142) @@ -10,7 +10,15 @@ """Configuration object to collect parameters for invoking gccxml. This class serves as a container for the parameters that can be used - to customize the call to gccxml. + to customize the call to gccxml. This class also allows users to work with + relative files paths. In this case files are searched in the following order: + + 1. current directory + + 2. working directory + + 3. additional include paths specified by the user + """ def __init__( self , gccxml_path='' Modified: pygccxml_dev/pygccxml/parser/project_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/project_reader.py 2006-05-18 15:11:59 UTC (rev 141) +++ pygccxml_dev/pygccxml/parser/project_reader.py 2006-05-20 20:25:22 UTC (rev 142) @@ -16,9 +16,10 @@ FILE_BY_FILE = 'file by file' -#TODO: rework next explanation to something useful. -""" -file_configuration_t is rather cool feature. When you create module_builder_t +class file_configuration_t( object ): + """ + file_configuration_t class is cool feature. When you want to parse C++ code + from different sources at once, you should use this class. class instance you should pass list of files. This list can contain string( == file paths ) and/or instances of file_configuration_t class. file_configuration_t is class with fat interface. @@ -60,7 +61,7 @@ , .... ) """ -class file_configuration_t( object ): + class CONTENT_TYPE: STANDARD_SOURCE_FILE = 'standard source file' CACHED_SOURCE_FILE = 'cached source file' Modified: pygccxml_dev/pygccxml/parser/source_reader.py =================================================================== --- pygccxml_dev/pygccxml/parser/source_reader.py 2006-05-18 15:11:59 UTC (rev 141) +++ pygccxml_dev/pygccxml/parser/source_reader.py 2006-05-20 20:25:22 UTC (rev 142) @@ -44,7 +44,35 @@ cls_inst.aliases.append( decl ) class source_reader_t: + """ + This class reads C++ source code and returns declarations tree. + + This class is the only class that have an intime knowledge about GCC-XML. + It has only one responsibility: it calls GCC-XML with a source file specified + by user and creates declarations tree. The implementation of this class is split + to 2 classes: + + 1. L{scanner_t} - this class scans the "XML" file, generated by GCC-XML and + creates `pygccxml`_ declarations and types classes. After the xml file has + been processed declarations and type class instances keeps references to + each other using GCC-XML generated id's. + + 2. L{linker_t} - this class contains logic for replacing GCC-XML generated + ids with references to declarations or type class instances. + """ def __init__( self, config, cache=None, decl_factory=None ): + """ + @param config: instance of L{config_t} class, that contains GCC-XML + configuration + @type config: L{config_t} + + @param cache: reference to cache object, that will be updated after + file has been parsed. + @param cache: instance of class, that derives from {cache_base_t} + + @param decl_factory: declarations factory, if not given default + declarations factory L{decl_factory_t} will be used + """ self.__search_directories = [] self.__config = config self.__search_directories.append( config.working_directory ) @@ -118,6 +146,20 @@ return cmd_line def create_xml_file( self, header, destination=None ): + """ + This function will return the file name of the file, created by GCC-XML + for "header" file. If destination_file_path is not None, then this file + path will be used and returned. + + @param header: path to source file, that should be parsed + @type header: str + + @param destination: if given, will be used as target file/path for + GCC-XML generated file. + @type destination: str + + @return: path to GCC-XML generated file + """ gccxml_file = destination # If file specified, remove it to start else create new file name if gccxml_file: @@ -155,6 +197,17 @@ return gccxml_file def create_xml_file_from_string( self, content, destination=None ): + """ + Creates XML file from text. + + @param content: C++ source code + @type content: str + + @param destination: file name for GCC-XML generated file + @type destination: str + + @return: returns file name of GCC-XML generated file + """ header_file = pygccxml.utils.create_temp_file_name( suffix='.h' ) gccxml_file = None try: @@ -167,6 +220,12 @@ return gccxml_file def read_file(self, source_file): + """ + Reads C++ source file and returns declarations tree + + @param source_file: path to C++ source file + @type source_file: str + """ declarations, types = None, None gccxml_file = '' try: @@ -193,6 +252,14 @@ return declarations def read_xml_file(self, gccxml_created_file): + """ + Reads GCC-XML generated XML file. + + @param gccxml_created_file: path to GCC-XML generated file + @type gccxml_created_file: str + + @return: declarations tree + """ if self.__config.verbose: logger.info( "Reading xml file: [%s]" % gccxml_created_file ) @@ -200,6 +267,10 @@ return declarations def read_string(self, content): + """ + Reads Python string, that contains valid C++ code, and returns + declarations tree. + """ header_file = pygccxml.utils.create_temp_file_name( suffix='.h' ) header_file_obj = file(header_file, 'w+') header_file_obj.write( content ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |