pygccxml-commit Mailing List for C++ Python language bindings (Page 87)
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: Roman <rom...@us...> - 2006-03-05 05:51:33
|
Update of /cvsroot/pygccxml/source/pyplusplus/code_creators In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19454/pyplusplus/code_creators Modified Files: calldef.py Log Message: operator[] is now supported Index: calldef.py =================================================================== RCS file: /cvsroot/pygccxml/source/pyplusplus/code_creators/calldef.py,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** calldef.py 2 Mar 2006 13:30:37 -0000 1.46 --- calldef.py 5 Mar 2006 05:51:30 -0000 1.47 *************** *** 176,179 **** --- 176,181 ---- if self._is_call_operator(): self.default_function_name = 'default_call' + elif self._is_index_operator(): + self.default_function_name = 'default_get_item' else: self.default_function_name = 'default_' + self.declaration.name *************** *** 183,186 **** --- 185,192 ---- return isinstance( self.declaration, declarations.member_operator_t ) \ and self.declaration.symbol == '()' + + def _is_index_operator(self): + return isinstance( self.declaration, declarations.member_operator_t ) \ + and self.declaration.symbol == '[]' def _get_default_function_name(self): *************** *** 321,324 **** --- 327,333 ---- name = '__call__' variable_name = 'call' + elif self._is_index_operator(): + name = '__getitem__' + variable_name = 'getitem' else: name = self.declaration.name *************** *** 351,354 **** --- 360,366 ---- name = '__call__' variable_name = 'call' + elif self._is_index_operator(): + name = '__getitem__' + variable_name = 'getitem' else: name = self.declaration.name |
From: Roman <rom...@us...> - 2006-03-05 05:50:28
|
Update of /cvsroot/pygccxml/source/pyplusplus/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18736/pyplusplus/unittests Modified Files: regression3_tester.py Log Message: pyplusplus now wraps hierarchy of abstract classes right. Next code will give you some idea: class base{ public: base(){} virtual ~base(){} virtual int get_value() const = 0; private: base( const base& ); base& operator=( const base& ); }; class middle : public base{ public: virtual void set_value(int) = 0; }; class final : public middle{ public: virtual int get_value() const{ return m_value; } virtual void set_value(int v){ m_value = v; } private: int m_value; }; Index: regression3_tester.py =================================================================== RCS file: /cvsroot/pygccxml/source/pyplusplus/unittests/regression3_tester.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** regression3_tester.py 28 Feb 2006 07:31:33 -0000 1.2 --- regression3_tester.py 5 Mar 2006 05:50:25 -0000 1.3 *************** *** 20,33 **** , *args ) def run_tests(self, module): ! self.fail( "For this test pyplusplus should generate invalid code") ! ! def test( self ): ! try: ! super(tester_t, self).test() ! self.fail( "For this test pyplusplus should generate invalid code" ) ! except RuntimeError: ! pass def create_suite(): suite = unittest.TestSuite() --- 20,52 ---- , *args ) + def create_python_final(self, class_ ): + class tester_impl_t( class_ ): + def __init__(self): + class_.__init__( self ) + self.value = 21 + + def get_value(self): + return self.value + + def set_value( self, i ): + self.value = i + + return tester_impl_t() + def run_tests(self, module): ! final_inst = module.final() ! final_inst.set_value( -2 ) ! self.failUnless( module.get_value( final_inst ) == -2 ) ! self.failUnless( final_inst.get_value() == -2 ) + inst = self.create_python_final( module.middle ) + self.failUnless( module.get_value( inst ) == 21 ) + self.failUnless( inst.get_value() == 21 ) + inst.set_value( -2 ) + self.failUnless( module.get_value( inst ) == -2 ) + self.failUnless( inst.get_value() == -2 ) + + + def create_suite(): suite = unittest.TestSuite() |
From: Roman <rom...@us...> - 2006-03-05 05:50:28
|
Update of /cvsroot/pygccxml/source/pyplusplus/unittests/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18736/pyplusplus/unittests/data Modified Files: regression3_to_be_exported.hpp Log Message: pyplusplus now wraps hierarchy of abstract classes right. Next code will give you some idea: class base{ public: base(){} virtual ~base(){} virtual int get_value() const = 0; private: base( const base& ); base& operator=( const base& ); }; class middle : public base{ public: virtual void set_value(int) = 0; }; class final : public middle{ public: virtual int get_value() const{ return m_value; } virtual void set_value(int v){ m_value = v; } private: int m_value; }; Index: regression3_to_be_exported.hpp =================================================================== RCS file: /cvsroot/pygccxml/source/pyplusplus/unittests/data/regression3_to_be_exported.hpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** regression3_to_be_exported.hpp 9 Feb 2006 05:56:39 -0000 1.1 --- regression3_to_be_exported.hpp 5 Mar 2006 05:50:25 -0000 1.2 *************** *** 32,35 **** --- 32,39 ---- }; + inline int get_value( const base& b ){ return b.get_value(); } + + inline void set_value( middle& m, int value ){ m.set_value( value ); } + } |
From: Roman <rom...@us...> - 2006-03-05 05:50:28
|
Update of /cvsroot/pygccxml/source/pyplusplus/code_creators In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18736/pyplusplus/code_creators Modified Files: class_declaration.py Log Message: pyplusplus now wraps hierarchy of abstract classes right. Next code will give you some idea: class base{ public: base(){} virtual ~base(){} virtual int get_value() const = 0; private: base( const base& ); base& operator=( const base& ); }; class middle : public base{ public: virtual void set_value(int) = 0; }; class final : public middle{ public: virtual int get_value() const{ return m_value; } virtual void set_value(int v){ m_value = v; } private: int m_value; }; Index: class_declaration.py =================================================================== RCS file: /cvsroot/pygccxml/source/pyplusplus/code_creators/class_declaration.py,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** class_declaration.py 28 Feb 2006 07:31:32 -0000 1.36 --- class_declaration.py 5 Mar 2006 05:50:25 -0000 1.37 *************** *** 114,136 **** def _generate_noncopyable(self): ! is_derived_from_noncopyable = False ! for base_desc in self.declaration.bases: ! assert isinstance( base_desc, declarations.hierarchy_info_t ) ! if base_desc.related_class.decl_string in ('::boost::noncopyable', '::boost::noncopyable_::noncopyable' ): ! is_derived_from_noncopyable = True ! break ! if not declarations.has_trivial_copy( base_desc.related_class ): ! is_derived_from_noncopyable = True ! break ! ! if not declarations.has_trivial_copy( self.declaration ) \ ! or not declarations.has_public_constructor( self.declaration )\ ! or self.declaration.is_abstract \ ! or ( declarations.has_destructor( self.declaration ) and ! not declarations.has_public_destructor( self.declaration ) )\ ! or is_derived_from_noncopyable: return algorithm.create_identifier( self, '::boost::noncopyable' ) - else: - return None def _generate_bases(self, base_creators): --- 114,119 ---- def _generate_noncopyable(self): ! if declarations.is_noncopyable( self.declaration ): return algorithm.create_identifier( self, '::boost::noncopyable' ) def _generate_bases(self, base_creators): *************** *** 300,303 **** --- 283,287 ---- , declaration=declaration ) self._class_creator = class_creator + self._base_wrappers = [] def _get_wrapper_alias( self ): *************** *** 307,310 **** --- 291,305 ---- wrapper_alias = property( _get_wrapper_alias, _set_wrapper_alias ) + def _get_base_wrappers( self ): + if self.declaration.is_abstract and not self._base_wrappers: + bases = [ hi.related_class for hi in self.declaration.bases ] + creators_before_me = algorithm.creators_affect_on_me( self ) + self._base_wrappers \ + = filter( lambda creator: isinstance( creator, class_wrapper_t ) + and creator.declaration in bases + , creators_before_me ) + return self._base_wrappers + base_wrappers = property( _get_base_wrappers ) + def _get_exposed_identifier(self): return algorithm.create_identifier( self, self.declaration.decl_string ) *************** *** 339,348 **** def _create_bases(self): ! return ', '.join( [ self.exposed_identifier, self.boost_wrapper_identifier ] ) def _create_impl(self): answer = ['struct %s : %s {' % ( self.wrapper_alias, self._create_bases() )] answer.append( '' ) ! answer.append( self.create_internal_code( self.creators ) ) answer.append( '' ) answer.append( '};' ) --- 334,360 ---- def _create_bases(self): ! return ', '.join( [self.exposed_identifier, self.boost_wrapper_identifier] ) + def _get_pure_virtual_function_creators( self ): + creators = [] + for base_wrapper in self.base_wrappers: + for creator in base_wrapper.creators: + if not isinstance( creator, declaration_based.declaration_based_t ): + continue + if not isinstance( creator.declaration, declarations.member_calldef_t ): + continue + if creator.declaration.virtuality != declarations.VIRTUALITY_TYPES.PURE_VIRTUAL: + continue + creators.append( creator ) + return creators + def _create_impl(self): answer = ['struct %s : %s {' % ( self.wrapper_alias, self._create_bases() )] answer.append( '' ) ! answer.append( self.create_internal_code( self.creators ) ) ! pvcreators = self._get_pure_virtual_function_creators() ! if pvcreators: ! answer.append( '' ) ! answer.append( self.create_internal_code( pvcreators ) ) answer.append( '' ) answer.append( '};' ) |
From: Roman <rom...@us...> - 2006-03-05 05:45:42
|
Update of /cvsroot/pygccxml/source/pygccxml/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15747/pygccxml/unittests Added Files: cache_enums_tester.py Log Message: adding new unit test that should reproduce Matthias problem with different order of enums does not reproduce :-( --- NEW FILE: cache_enums_tester.py --- # 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 autoconfig import parser_test_case import pygccxml from pygccxml import parser from pygccxml import declarations class tester_t( parser_test_case.parser_test_case_t ): COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE def __init__(self, *args ): parser_test_case.parser_test_case_t.__init__( self, *args ) self.header = os.path.join( autoconfig.data_directory, 'declarations_enums.hpp' ) self.cache_file = os.path.join( autoconfig.data_directory, 'pygccxml.cache' ) if os.path.exists( self.cache_file ) and os.path.isfile( self.cache_file ): os.remove(self.cache_file) def test_cache( self ): cache = parser.file_cache_t( self.cache_file ) reader = parser.source_reader_t( self.config, cache ) decls1 = reader.read_file( self.header ) cache.flush() cache = parser.file_cache_t( self.cache_file ) reader = parser.source_reader_t( self.config, cache ) decls2 = reader.read_file( self.header ) enum_matcher = declarations.declaration_matcher_t( name="EColor" , decl_type=declarations.enumeration_t ) color1 = declarations.matcher.get_single( enum_matcher, decls1 ) color2 = declarations.matcher.get_single( enum_matcher, decls2 ) self.failUnless( color1.values == color2.values ) 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() |
From: Roman <rom...@us...> - 2006-03-05 05:44:17
|
Update of /cvsroot/pygccxml/source/pygccxml/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15004/pygccxml/unittests Modified Files: test_all.py Log Message: adding new unit test that should reproduce Matthias problem with different order of enums does not reproduce :-( Index: test_all.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/unittests/test_all.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** test_all.py 2 Mar 2006 05:53:14 -0000 1.16 --- test_all.py 5 Mar 2006 05:44:14 -0000 1.17 *************** *** 30,33 **** --- 30,34 ---- import calldef_matcher_tester import filters_tester + import cache_enums_tester def create_suite(): *************** *** 58,61 **** --- 59,63 ---- , calldef_matcher_tester , filters_tester + , cache_enums_tester ] |
From: Roman <rom...@us...> - 2006-03-05 05:44:17
|
Update of /cvsroot/pygccxml/source/pygccxml/unittests/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15004/pygccxml/unittests/data Modified Files: declarations_enums.hpp Log Message: adding new unit test that should reproduce Matthias problem with different order of enums does not reproduce :-( Index: declarations_enums.hpp =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/unittests/data/declarations_enums.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** declarations_enums.hpp 9 Oct 2005 05:27:05 -0000 1.3 --- declarations_enums.hpp 5 Mar 2006 05:44:14 -0000 1.4 *************** *** 11,14 **** --- 11,19 ---- enum ENumbers{ e0, e1, e2, e3, e4, e5, e6, e7, e8, e9 }; + class data{ + public: + enum EColor{ red, green, blue, black, white }; + }; + } } |
From: Roman <rom...@us...> - 2006-03-05 05:41:15
|
Update of /cvsroot/pygccxml/source/pygccxml/declarations In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12948/pygccxml/declarations Modified Files: __init__.py type_traits.py Log Message: adding is_noncopyable to type_traits Index: type_traits.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/declarations/type_traits.py,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** type_traits.py 1 Feb 2006 07:31:38 -0000 1.22 --- type_traits.py 5 Mar 2006 05:41:11 -0000 1.23 *************** *** 657,661 **** --- 657,675 ---- return __is_convertible_t( source, target ).is_convertible() + def is_noncopyable( class_ ): + for base_desc in class_.recursive_bases: + assert isinstance( base_desc, class_declaration.hierarchy_info_t ) + if base_desc.related_class.decl_string in ('::boost::noncopyable', '::boost::noncopyable_::noncopyable' ): + return True + if not has_trivial_copy( base_desc.related_class ): + return True + + if not has_trivial_copy( class_ ) \ + or not has_public_constructor( class_ )\ + or class_.is_abstract \ + or ( has_destructor( class_ ) and not has_public_destructor( class_ ) ): + return True + return False Index: __init__.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/declarations/__init__.py,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** __init__.py 2 Mar 2006 05:53:14 -0000 1.33 --- __init__.py 5 Mar 2006 05:41:11 -0000 1.34 *************** *** 105,108 **** --- 105,109 ---- from type_traits import is_base_and_derived from type_traits import is_convertible + from type_traits import is_noncopyable from type_traits import is_unary_operator *************** *** 134,137 **** --- 135,139 ---- from decl_factory import decl_factory_t + from filters import declaration_matcher_t from filters import calldef_matcher_t from filters import namespace_matcher_t |
From: Roman <rom...@us...> - 2006-03-05 05:39:13
|
Update of /cvsroot/pygccxml/source/pygccxml/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11726/pygccxml/docs Modified Files: definition.rest pygccxml.rest Log Message: applying John Pallister <jo...@sy...> documentation changes. Index: pygccxml.rest =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/docs/pygccxml.rest,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** pygccxml.rest 31 Jan 2006 08:15:53 -0000 1.3 --- pygccxml.rest 5 Mar 2006 05:39:08 -0000 1.4 *************** *** 22,32 **** First of all let's see a small and simple `example`_. This example prints all ! declarations found in `core_class_hierarchy.hpp`_ file. Also, for instances, that ! describes C++ class, it will print bases and derived class names. This example ! is also interesting because it `shows`_ us how it can be simple to find out all ! bases and derived classes. If someone still is curious "how it can be in the real ! life" he may look at `GCC-XML`_ `generated file`_. ! .. _`generated file` : ./core_class_hierarchy.hpp.xml .. _`core_class_hierarchy.hpp` : ./core_class_hierarchy.hpp .. _`shows` : ./example_output.txt --- 22,32 ---- First of all let's see a small and simple `example`_. This example prints all ! declarations found in the `core_class_hierarchy.hpp`_ file. Also, for instances ! that describe a C++ class it will print base and derived class names. This example ! is also interesting because it `shows`_ us how simple it is to find all base ! and derived classes. If someone is still curious how it looks "in the real ! life" he may look at the `original XML file`_ generated by `GCC-XML`_. ! .. _`original XML file` : ./core_class_hierarchy.hpp.xml .. _`core_class_hierarchy.hpp` : ./core_class_hierarchy.hpp .. _`shows` : ./example_output.txt *************** *** 36,51 **** ----------------------------------------- ! Consider next situation: you have to parse the same set of files every day. ! There are 2 possibilities to complete the task:: ! * Create header file that includes all files you need to parse ! * Parse each file separately and then join the results ! The difference between these approaches is caching algorithm in second case. ! `pygccxml`_ supports both of them. ! That's not all. Do you familiar with `boost::type_traits`_ library? Well, ! `pygccxml`_ has some functionality offered by that library. ------- --- 36,51 ---- ----------------------------------------- ! Consider the following situation: you have to parse the same set of files every ! day. There are 2 possibile ways to complete the task:: ! * create a header file that includes all files you need to parse ! * 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. ------- *************** *** 60,95 **** `UML diagram`_: ! Look at this `UML diagram`_. All classes are defined by `pygccxml`_.declarations ! package. Defined classes are used to describe almost any C++ declaration. ! Few words about convention. Every class name ends with "_t". The are several ! reasons for it: ! * I am used to C++ "std" convention. ( small letters with underscores ) ! * Most of the names are already exists in python and have the different meaning. Types hierarchy --------------- ! Types hierarchy is used to represent arbitrary type in C++. Example ~~~~~~~ ! For variable "ptr" *const int\* ptr=0;* ! `pygccxml`_ will create next type *pointer_t( const_t( int_t() ) )* ! The ability to represent almost any type of C++ comes from "decorator" pattern. ! That's not all! Do you aware of `boost::type_traits`_ library? `boost::type_traits`_ ! library has been developed by John Maddock, Steve Cleary and others. `pygccxml`_ ! reuse names proposed by this library. Also I took few ideas for testing ! `pygccxml`_ type traits implementation. Here are some type traits implemented by ! `pygccxml`_. + *base_type* --- 60,96 ---- `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* *************** *** 156,166 **** --------------------- ! Declaration hierarchy is used to represent arbitrary C++ declaration. ! *"declaration_t"* is a base class of declaration hierarchy. This class has few ! properties. One of them is *"parent"* property. This property keeps reference to ! scope declaration instance in which this declaration is defined. *"scopedef_t"* ! class derives from *"declaration_t"*. This class is used to say - "I may have ! other declarations inside". The pattern that is used here is "composite". ------ --- 157,168 ---- --------------------- ! 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. ------ *************** *** 171,180 **** -------- ! `Parser package`_ ( "`pygccxml`_.parser" ). This is the heart of `pygccxml`_ project. ! Classes in this package implements parsing and binding functionality. There are ! 3 classes and 2 functions that user should know about: ! + *config_t* - class that accumulates all settings of `GCC-XML`_ and `pygccxml`_. ! User can work with relative files paths. In this case files are searched in next order: 1. current directory --- 173,183 ---- -------- ! `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: 1. current directory *************** *** 185,202 **** + *source_reader_t* - the only class that works with `GCC-XML`_. This class has ! only one responsibility: to convert source file declarations and types to ! `pygccxml`_ objects model. You can think about this class as `GCC-XML`_ generated ! file reader only. ! + *project_reader_t* - think about this class as a linker or a binder. Explanation: ! usually you will define base class in one header file and derived in an other one. ! After running *source_reader_t* on base header and on derived header you will ! get 2 definitions of base class. More then one of the definitions will not ! contain information about derived classes. *project_reader_t* was born to solve ! this situation. It implements few algorithms to solve that problem and other ! similar ones. Right now it implements next algorithms: 1. namespace joining. ! 2. join class hierarchies 3. rebinding types to new class hierarchies 4. linking overloaded functions --- 188,206 ---- + *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. ! + *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: 1. namespace joining. ! 2. joining class hierarchies 3. rebinding types to new class hierarchies 4. linking overloaded functions *************** *** 204,220 **** There are 2 ways to solve the problem: ! 1. To compile every file and than to run the algorithms. ! In order to run this mode set *compilation_mode* ( in instance of *config_t* ) ! to *COMPILATION_MODE.FILE_BY_FILE*. ! 2. To create a temporal header file, that will include all headers you want to ! compile. In order to run this mode set *compilation_mode* ( in instance of ! *config_t* ) to *COMPILATION_MODE.ALL_AT_ONCE*. In other words, in this ! mode *project_reader_t* acts like *source_reader_t*, no difference. ! Two modes, why?! The answer is simple - cache. You don't want to pay for ! compilation and processing result for files that has not been changed, right? ! *COMPILATION_MODE.FILE_BY_FILE* gives you the possibility to use cache! For ! further explanation please see `Parser package`_ design. Interface description --- 208,223 ---- There are 2 ways to solve the problem: ! 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*. ! 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 *************** *** 229,256 **** + *read_string(self, content)* - small convenience function. The *content* ! should be valid C++ code. This function will return top level namespaces's list. + *source_reader_t.read_file(self, source_file)* This function will return ! top level namespaces list. ! + *project_reader_t.read_files(self, files)* This function will return ! 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*. In case the item is an instance of class *file_configuration_t* ! then file will be compiled and parsed using it's configuration. Project ! configuration stays unchanged. + *source_reader_t.create_xml_file(self, source_file, destination_file_path=None)* ! This function will return 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 top ! level namespaces list. Right now top level namespaces are: "::" and "std". ! Main purpose of *source_reader_t.create_xml_file* and *source_reader_t.read_xml_file* ! is to make an easy cross-platform development. *pygccxml.parser* --- 232,260 ---- + *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* *************** *** 270,280 **** There are 2 private classes in this package: ! 1. *scanner_t* - this class scans "XML" file, generated by `GCC-XML`_ and creates ! `pygccxml`_ declarations and types classes. After the xml file has been processed ! declarations and types 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\\types class instances. --- 274,284 ---- 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. *************** *** 283,290 **** ----------------- ! `pygccxml`_ comes with comprehensive unit tests. It is running on windows xp and ! `Debian Linux`_. I am using `Python`_ 2.3 and `GCC-XML`_ 0.6.0. Right now I am running ! more then 75 tests. They test almost every piece of code. Also I have performance tests. ! Most of the time I am using "white box" testing strategy. --------- --- 287,295 ---- ----------------- ! `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. --------- *************** *** 292,296 **** --------- ! * My wife Yulia - she helped me to edit initial version of this manuals. All mistakes and bugs are mine. I'd like to believe that I know `Python`_ better then English. --- 297,301 ---- --------- ! * My wife Yulia - she helped me to edit the initial version of this manuals. All mistakes and bugs are mine. I'd like to believe that I know `Python`_ better then English. *************** *** 298,302 **** * Brad King for `GCC-XML`_ ! * Detlev Offenbach for `Eric 3.4`_ * `Docutils`_ - easy to use documentation system --- 303,307 ---- * Brad King for `GCC-XML`_ ! * Detlev Offenbach for `Eric 3.6`_ * `Docutils`_ - easy to use documentation system *************** *** 305,308 **** --- 310,315 ---- `SourceForge`_ + * John Pallister <jo...@sy...> - he helped me to edit\\correct documentation + * Hosted by |SourceForge|__ Index: definition.rest =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/docs/definition.rest,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** definition.rest 16 Jan 2006 05:59:44 -0000 1.2 --- definition.rest 5 Mar 2006 05:39:08 -0000 1.3 *************** *** 6,10 **** -- Introduction to `GCC-XML`_ ! The purpose of `pygccxml`_ is to read a generated file and provide simple framework to navigate C++ declarations using Python classes. --- 6,10 ---- -- Introduction to `GCC-XML`_ ! The purpose of `pygccxml`_ is to read a generated file and provide a simple framework to navigate C++ declarations using Python classes. |
From: Allen B. <al...@us...> - 2006-03-05 00:51:35
|
Update of /cvsroot/pygccxml/source/pyplusplus/experimental/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21247/docs Added Files: generate_all_docs.py Log Message: Added documentation generation script. --- NEW FILE: generate_all_docs.py --- # Generate documentation using epydocs # import os, os.path pj = os.path.join default_format = "restructuredtext" pypp_module_dirs = ["code_creators", "code_repository", "decl_wrappers", "experimental", "file_writers", "gui", "module_builder", "module_creator", "utils", "__init__.py"] pypp_dir = pj("..","..","..","pyplusplus") module_params = [pj(pypp_dir,d) for d in pypp_module_dirs] cmd_line = "epydoc -o html --docformat " + default_format + " " cmd_line += " ".join(module_params) print "Running: ", cmd_line os.system(cmd_line) |
From: Allen B. <al...@us...> - 2006-03-05 00:50:58
|
Update of /cvsroot/pygccxml/source/pyplusplus/experimental In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19921 Modified Files: pypp_api.py Log Message: Started to refactor. - New documentation format - Try to call new pyplusplus API - Stills needs a *lot* of work. I can't figure out how to get the new decl wrapper interface. Index: pypp_api.py =================================================================== RCS file: /cvsroot/pygccxml/source/pyplusplus/experimental/pypp_api.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pypp_api.py 4 Mar 2006 15:48:12 -0000 1.1 --- pypp_api.py 5 Mar 2006 00:50:54 -0000 1.2 *************** *** 1,5 **** ! #!/bin/python ! # import os, os.path, re from pygccxml import parser from pygccxml import declarations --- 1,35 ---- ! # 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) ! ! __docformat__ = "restructuredtext en" ! __doc__ = """ ! pypp api ! ======== ! ! This module provides a simplified high-level API for using ! pygccxml and pyplusplus. It is currently under heavy construction. ! ! Quickstart Usage ! ---------------- ! ! Add quickstart here ! ! Detailed Usage ! -------------- ! ! Add detailed usage here. ! ! :todo: Add quickstart and detailed documentation for API. ! :author: Allen Bierbaum ! :author: Matthias Baas ! :license: Boost Software License, Version 1.0 (see http://www.boost.org/LICENSE_1_0.txt) ! :copyright: 2006 Allen Bierbaum, Matthias Baas ! """ ! import os, os.path, re + + # Bring in everything I need from pyplusplus and pygccxml from pygccxml import parser from pygccxml import declarations *************** *** 9,25 **** from pyplusplus import module_creator from pyplusplus import file_writers # Bring in call policies to use ! from pyplusplus.code_creators import return_self ! from pyplusplus.code_creators import return_internal_reference ! from pyplusplus.code_creators import with_custodian_and_ward ! from pyplusplus.code_creators import copy_const_reference ! from pyplusplus.code_creators import copy_non_const_reference ! from pyplusplus.code_creators import manage_new_object ! from pyplusplus.code_creators import reference_existing_object ! from pyplusplus.code_creators import return_by_value ! from pyplusplus.code_creators import return_opaque_pointer ! from pyplusplus.code_creators import return_value_policy ! def cleanTemplateName(templateName): --- 39,55 ---- from pyplusplus import module_creator from pyplusplus import file_writers + from pyplusplus import decl_wrappers # Bring in call policies to use ! from pyplusplus.decl_wrappers import return_self ! from pyplusplus.decl_wrappers import return_internal_reference ! from pyplusplus.decl_wrappers import with_custodian_and_ward ! from pyplusplus.decl_wrappers import copy_const_reference ! from pyplusplus.decl_wrappers import copy_non_const_reference ! from pyplusplus.decl_wrappers import manage_new_object ! from pyplusplus.decl_wrappers import reference_existing_object ! from pyplusplus.decl_wrappers import return_by_value ! from pyplusplus.decl_wrappers import return_opaque_pointer ! from pyplusplus.decl_wrappers import return_value_policy def cleanTemplateName(templateName): *************** *** 34,39 **** By default all declarations are ignored. ! Todo: ! - ??? """ def __init__(self, headerFiles, workingDir=None, --- 64,69 ---- By default all declarations are ignored. ! :todo: Fix the parsing to work with recent changes ! """ def __init__(self, headerFiles, workingDir=None, *************** *** 41,51 **** defines=[], undefines=[], cacheFile = None, verbose=True): ! """ Initialize module. ! workingDir - directory to start processing. (default: current working dir) ! includePaths - List of paths to tell gccxml to search for header files. ! gccxmlPath - path to gccxml. If not set then attempt to find it in system path. ! (un)defines - set of symbols to add as (un)defined when compiling. ! cacheFile - name of file to use for caching parse data for this module. ! verbose - If true output status and command information as building the module. """ if not isinstance(headerFiles, list): --- 71,83 ---- defines=[], undefines=[], cacheFile = None, verbose=True): ! """ ! Initialize module. ! :Parameters: ! - 'workingDir': directory to start processing. (default: current working dir) ! - 'includePaths': List of paths to tell gccxml to search for header files. ! - 'gccxmlPath': path to gccxml. If not set then attempt to find it in system path. ! - '(un)defines': set of symbols to add as (un)defined when compiling. ! - 'cacheFile': name of file to use for caching parse data for this module. ! - 'verbose': if true output status and command information as building the module. """ if not isinstance(headerFiles, list): *************** *** 79,84 **** This method can be called anytime after initialization and all Template() calls have been made. ! @post: This class can act as a wrapper for namespace("::") ! and all declarations are set to be ignored. """ if self.mVerbose: --- 111,116 ---- This method can be called anytime after initialization and all Template() calls have been made. ! ! :postcondition: This class can act as a wrapper for namespace("::") and all declarations are set to be ignored. """ if self.mVerbose: *************** *** 107,111 **** the_parser = parser.project_reader_t(config=parser_cfg, ! cache=self.mCacheFile) parsed_decls = the_parser.read_files(full_header_list, parser.project_reader.COMPILATION_MODE.FILE_BY_FILE) --- 139,144 ---- the_parser = parser.project_reader_t(config=parser_cfg, ! cache=self.mCacheFile, ! decl_factory=decl_wrappers.dwfactory_t()) parsed_decls = the_parser.read_files(full_header_list, parser.project_reader.COMPILATION_MODE.FILE_BY_FILE) *************** *** 203,211 **** """ Create the module and write it out. Automatically calls createCreators() and filterExposed() if needed. ! moduleName - The name of the module being created. ! filename - The file or directory to create the code. ! useScope - If true the creators all use scope in their code. ! multiFile - If true use the multifile writer. ! multiCreateMain - If true and using multifile then create main reg method. """ if not self.mExtModule: --- 236,244 ---- """ Create the module and write it out. Automatically calls createCreators() and filterExposed() if needed. ! :arg moduleName: The name of the module being created. ! :arg filename: The file or directory to create the code. ! :arg useScope: If true the creators all use scope in their code. ! :arg multiFile: If true use the multifile writer. ! :arg multiCreateMain: If true and using multifile then create main reg method. """ if not self.mExtModule: *************** *** 233,240 **** def Template(self, templateType, typedefName=None): """ Add a template to instantiate. ! templateType - Fully instantiated name. (ex: TemplateClass<float> ) ! typedefName - Name of type def to define to this template type. ! This name can then be used later to look up the real fully ! expanded template type from the typedef map. (see self.mTypeDefMap) """ if not typedefName: --- 266,273 ---- def Template(self, templateType, typedefName=None): """ Add a template to instantiate. ! :param templateType: Fully instantiated name. (ex: TemplateClass<float> ) ! :param typedefName: Name of type def to define to this template type. ! This name can then be used later to look up the real fully ! expanded template type from the typedef map. (see self.mTypeDefMap) """ if not typedefName: *************** *** 312,322 **** class DeclWrapper: """ Class to wrap a single declaration. ! This is the core class for all API exposing. ! Instances of this class are normally created by calling ! one of the creation methods (Namespace, Class, Method, Var, Enum) ! on an existing wrapper or on a module. ! TODO: ! - ??? """ def __init__(self, decl): --- 345,354 ---- class DeclWrapper: """ Class to wrap a single declaration. ! This is the core class for all API exposing. ! Instances of this class are normally created by calling ! one of the creation methods (Namespace, Class, Method, Var, Enum) ! on an existing wrapper or on a module. ! :todo: Rewrite methods to use new wrappers. """ def __init__(self, decl): *************** *** 413,417 **** def setCallPolicy(self, callPolicy): """ Set the callpolicy of the contained method. ! callPolicy - Callpolicy object to use (must be of type code_creators.call_policy_t) """ assert isinstance(callPolicy, code_creators.call_policy_t) --- 445,449 ---- def setCallPolicy(self, callPolicy): """ Set the callpolicy of the contained method. ! :arg callPolicy: Callpolicy object to use (must be of type code_creators.call_policy_t) """ assert isinstance(callPolicy, code_creators.call_policy_t) *************** *** 434,438 **** """ Manually wrap method. Example: setWrapper("method", "ns::new_method") ! @post: ignores any old methods of methodName and defines new method """ self.Method(methodName).ignore() --- 466,470 ---- """ Manually wrap method. Example: setWrapper("method", "ns::new_method") ! :postcondition: ignores any old methods of methodName and defines new method """ self.Method(methodName).ignore() *************** *** 488,499 **** # --------- Internal helpers --------- # def findContainedDecls(self, name=None, declType=None): ! """ Search contained declarations for ones of specific type and or name. ! name: regex to use for matching. (can just be full name) ! Note: To make it more predictable matching we automatically add ! a '$' to the end of the regex to match the end of the name. ! This helps to prevent names with similar prefix's from matching. ! If you need this ability you can still get it by adding '.*' ! declType: a single type or a list of decl types to look for. ! Returns None if not found. Returns 1 or a list if found. """ found = [] --- 520,532 ---- # --------- Internal helpers --------- # def findContainedDecls(self, name=None, declType=None): ! """ ! Search contained declarations for ones of specific type and or name. ! :param name: regex to use for matching. (can just be full name) ! :param declType: a single type or a list of decl types to look for. ! :return: None if not found. Returns 1 or a list if found. ! :note: To make name lookup more predictable matching we automatically add ! a '$' to the end of the regex to match the end of the name. ! This helps to prevent names with similar prefix's from matching. ! If you need this ability you can still get it by adding '.*' """ found = [] *************** *** 511,516 **** def findContained(self, name=None, declType=None): """ Return a new DeclWrapper or MultiDeclWrapper for matching decls. ! name - If set this regex is used. ! declType - If set restrict search to decls based on the given type. """ found = self.findContainedDecls(name, declType) --- 544,549 ---- def findContained(self, name=None, declType=None): """ Return a new DeclWrapper or MultiDeclWrapper for matching decls. ! :arg name: If set this regex is used. ! :arg declType: If set restrict search to decls based on the given type. """ found = self.findContainedDecls(name, declType) *************** *** 789,791 **** curr_level = self.level + 1 print ' ' * curr_level * self.INDENT_SIZE, 'type: %s value: %s'%(self.__inst.type.decl_string, self.__inst.value) ! \ No newline at end of file --- 822,824 ---- curr_level = self.level + 1 print ' ' * curr_level * self.INDENT_SIZE, 'type: %s value: %s'%(self.__inst.type.decl_string, self.__inst.value) ! |
From: Allen B. <al...@us...> - 2006-03-05 00:49:44
|
Update of /cvsroot/pygccxml/source/pyplusplus/experimental/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19677/docs Log Message: Directory /cvsroot/pygccxml/source/pyplusplus/experimental/docs added to the repository |
From: Allen B. <al...@us...> - 2006-03-04 15:48:26
|
Update of /cvsroot/pygccxml/source/pyplusplus/experimental In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27147 Added Files: pypp_api.py Log Message: Initial version of pypp_api. note: this is not ported in any way yet. --- NEW FILE: pypp_api.py --- #!/bin/python # import os, os.path, re from pygccxml import parser from pygccxml import declarations import pygccxml.utils from pyplusplus import code_creators from pyplusplus import module_creator from pyplusplus import file_writers # Bring in call policies to use from pyplusplus.code_creators import return_self from pyplusplus.code_creators import return_internal_reference from pyplusplus.code_creators import with_custodian_and_ward from pyplusplus.code_creators import copy_const_reference from pyplusplus.code_creators import copy_non_const_reference from pyplusplus.code_creators import manage_new_object from pyplusplus.code_creators import reference_existing_object from pyplusplus.code_creators import return_by_value from pyplusplus.code_creators import return_opaque_pointer from pyplusplus.code_creators import return_value_policy def cleanTemplateName(templateName): """ Build a clean template name. """ clean_re = re.compile('[:<>\s,]') return clean_re.sub('_', templateName) class ModuleBuilder: """ Wrapper for a module (or part of a module). Captures handling of parsing and writing out bindings. Note: The pubic namespace '::' is the root decl for the Module. By default all declarations are ignored. Todo: - ??? """ def __init__(self, headerFiles, workingDir=None, includePaths=[], gccxmlPath = '', defines=[], undefines=[], cacheFile = None, verbose=True): """ Initialize module. workingDir - directory to start processing. (default: current working dir) includePaths - List of paths to tell gccxml to search for header files. gccxmlPath - path to gccxml. If not set then attempt to find it in system path. (un)defines - set of symbols to add as (un)defined when compiling. cacheFile - name of file to use for caching parse data for this module. verbose - If true output status and command information as building the module. """ if not isinstance(headerFiles, list): headerFiles = [headerFiles] self.mHeaderFiles = headerFiles self.mWorkingDir = workingDir if not self.mWorkingDir: self.mWorkingDir = os.getcwd() self.mIncludePaths = includePaths # Paths to use for extra includes with gccxml self.mGccXmlPath = gccxmlPath # Path to gccxml executable self.mDefines = defines # Defines for gccxml self.mUndefines = undefines self.mCacheFile = cacheFile # File to use for caching gccxml output self.mVerbose = verbose # Should there be verbose output during processing self.mDeclRoot = None # Root of the parsed decls self.mFinalDecls = None # Final list of decls to export self.mTemplates = [] # List of (templateType, typedefName) to instantiate self.mTypeDefMap = {} # Map from typedef name to expanded type self.mBodyTailCreators = [] # List of creators to add at body tail self.mStartCreators = [] # List of creators to put at beginning of file self.mEndCreators = [] # List of custom creators to add on self.mExtraIncludes = [] # List of extra includes to add self.mLicense = None # License to use self.mExtModule = None # Extension model being built (code creator tree) print "Initialized module." def parse(self): """ Parse the header files and setup the known declarations. Currently this method can only be called once. This method can be called anytime after initialization and all Template() calls have been made. @post: This class can act as a wrapper for namespace("::") and all declarations are set to be ignored. """ if self.mVerbose: print "Parsing headers: ", self.mHeaderFiles parser_cfg = parser.config_t(self.mGccXmlPath, self.mWorkingDir, self.mIncludePaths, define_symbols=self.mDefines, undefine_symbols=self.mUndefines, start_with_declarations=None, verbose=self.mVerbose) full_header_list = self.mHeaderFiles[:] # Handle template instantiation as needed temp_file, temp_filename = (None,None) template_instantiation_text = self.buildTemplateFileContents() if None != template_instantiation_text: temp_filename = pygccxml.utils.create_temp_file_name(suffix=".h") temp_file = file(temp_filename, 'w') temp_file.write(template_instantiation_text) temp_file.close() if self.mVerbose: print " creating template instatiation file: ", temp_filename full_header_list.append(temp_filename) the_parser = parser.project_reader_t(config=parser_cfg, cache=self.mCacheFile) parsed_decls = the_parser.read_files(full_header_list, parser.project_reader.COMPILATION_MODE.FILE_BY_FILE) assert len(parsed_decls) == 1 # assume that we get root of full tree self.mDeclRoot = parsed_decls[0] # Parse the files and add to decl root # - then traverse tree setting everything to ignore self.mDeclRootWrapper = DeclWrapper(self.mDeclRoot) self.mDeclRootWrapper.ignore() # Cleanup if temp_filename: pygccxml.utils.remove_file_no_raise( temp_filename ) typedef_decls = declarations.make_flatten(parsed_decls) typedef_decls = decls = filter( lambda x: (isinstance( x, declarations.typedef_t ) and not x.name.startswith('__') and x.location.file_name != "<internal>") , typedef_decls ) self.mTypeDefMap = {} for d in typedef_decls: type_def_name = d.name full_name = declarations.full_name(d) if full_name.startswith("::"): # Remove the base namespace full_name = full_name[2:] real_type_name = d.type.decl_string if real_type_name.startswith("::"): # Remove base namespace real_type_name = real_type_name[2:] self.mTypeDefMap[full_name] = real_type_name if self.mVerbose: print "completed parsing." def buildCreators(self, moduleName, filename, useScope=False): """ Build creator tree and module from the current declarations. See createModule for parameter documentation. In normal usage the user will not call this directly. Return the base of the creator tree. """ if None == self.mDeclRoot: self.parse() if self.mVerbose: print "Creating module code creator tree...." # Filter the exposed decl list to create a final decl list. def filter(decl): expose = getattr(decl, "_expose_flag", False) return expose if self.mVerbose: print "Filtering module..." self.mFinalDecls = declarations.filtering.user_defined( self.mDeclRoot, filter) # Create creator.module_t for the module # - override the header files in create since we already know what files we used. maker = module_creator.creator_t(self.mFinalDecls, module_name=moduleName, recursive=False) extmodule = maker.create(declHeaders=self.mHeaderFiles) # Handle the extra creators that need added mod_body = extmodule.body for c in self.mBodyTailCreators: mod_body.adopt_creator(c) for c in self.mEndCreators: extmodule.adopt_creator(c) self.mStartCreators.reverse() for c in self.mStartCreators: extmodule.adopt_creator(c, extmodule.last_include_index()+1) for h in self.mExtraIncludes: extmodule.adopt_include(code_creators.include_t(h)) if useScope: class_creators = filter( lambda c: isinstance( c, code_creators.class_t ) , code_creators.make_flatten( extmodule.body.creators ) ) for c in class_creators: c.always_expose_using_scope = True #better error reporting from compiler if self.mLicense: extmodule._set_license(self.mLicense) self.mExtModule = extmodule return self.mExtModule def writeModule(self, moduleName, filename, useScope=False, multiFile=False, multiCreateMain=True): """ Create the module and write it out. Automatically calls createCreators() and filterExposed() if needed. moduleName - The name of the module being created. filename - The file or directory to create the code. useScope - If true the creators all use scope in their code. multiFile - If true use the multifile writer. multiCreateMain - If true and using multifile then create main reg method. """ if not self.mExtModule: self.createCreators(moduleName, filename, useScope) extmodule = self.mExtModule assert extmodule if self.mVerbose: print "Writing out files..." # Write out the file(s) if not multiFile: file_writers.write_file(extmodule, filename) else: mfs = file_writers.multiple_files_t(extmodule, filename) mfs.write(write_main=multiCreateMain) self.split_header_names = mfs.split_header_names self.split_method_names = mfs.split_method_names if self.mVerbose: print "Module generation complete." # ------------- Creator methods -------------- # def Template(self, templateType, typedefName=None): """ Add a template to instantiate. templateType - Fully instantiated name. (ex: TemplateClass<float> ) typedefName - Name of type def to define to this template type. This name can then be used later to look up the real fully expanded template type from the typedef map. (see self.mTypeDefMap) """ if not typedefName: typedefName = cleanTemplateName(templateType) self.mTemplates.append( (templateType, typedefName) ) def addInclude(self, headers): """ Add additional include file(s). These are not parsed but are just added to the generated code. Takes either a single header or a list of headers. """ if not isinstance(headers, list): headers = [headers] self.mExtraIncludes.extend(headers) def __getattr__(self, name): """ Pass through all unfound attributes to the decl wrapper. This allows us to act like a decl wrapper on root. Ex: mod.ignore() """ if hasattr(self.mDeclRootWrapper, name): return getattr(self.mDeclRootWrapper, name) else: raise AttributeError, name # --- Advanced methods of adding creators --- # # This set of methods needs further refinement based upon user needs def addBodyTailText(self, text): self.addBodyTailCreator(code_creators.custom_text_t(text) ) def addStartText(self, text): self.addStartCreator(code_creators.custom_text_t(text) ) def addStartCreator(self, creator): self.mStartCreators.append(creator) def addBodyTailCreator(self, creator): self.mBodyTailCreators.append(creator) def addEndText(self, text): self.addEndCreator(code_creators.custom_text_t(text) ) def addEndCreator(self, creator): self.mEndCreators.append(creator) def setLicense(self, licenseText): """ Set the license header to use. """ self.mLicense = licenseText # ---------- Internal helpers ----------- # def buildTemplateFileContents(self): """ Build up the contents of a file to instantiate the needed templates. headerFiles - List of header files for this module. """ if len(self.mTemplates) == 0: return None content = "/** Autogenerated temporary file for template instantiation. */\n" for h in self.mHeaderFiles: content += '#include<%s>\n'%h for t in self.mTemplates: template_type = t[0] typedef_name = t[1] content += """ typedef %(template_type)s %(typedef_name)s; void __instantiate_%(typedef_name)s() { sizeof(%(typedef_name)s); } """ % vars() return content class DeclWrapper: """ Class to wrap a single declaration. This is the core class for all API exposing. Instances of this class are normally created by calling one of the creation methods (Namespace, Class, Method, Var, Enum) on an existing wrapper or on a module. TODO: - ??? """ def __init__(self, decl): """ Construct declaration wrapper for decl. """ self.mDecl = decl # The declaration we are wrapping if not hasattr(self.mDecl, "declDecorator"): self.mDecl.declDecorator = code_creators.decl_decorator_t() def Namespace(self, name, expose=False): """ Return wrapper for namespace. name: full name or regex to match name. """ res = self.findContained(name, declarations.namespace_t) if res==None: raise RuntimeError, "Namespace '%s' not found"%name if expose: res.expose() return res def Class(self, name, expose=True): """ Returns wrapper for class named name. name: full name or regex to match name. """ res = self.findContained(name, declarations.class_t) if res==None: raise RuntimeError, "Class '%s' not found"%name if expose: res.expose() return res def Method(self, name, retval=None, args=None, expose=True): """ Returns wrapper for method. name: full name or regex to match name. retval: string rep of return value. None=ignore args: list of string rep of arg types. None=ignore """ res = self.findContainedMethod(name, retval, args) if res==None: raise RuntimeError, "Method '%s' {sig: %s } not found"%(name, [retval,args]) if expose: res.expose() return res def Var(self, name, expose=True): """ Returns wrapper around a varibale. name: full name or regex to match the name. """ res = self.findContained(name, declarations.variable_t) if res == None: raise RuntimeError, "Variable '%s' not found"%name if expose: res.expose() return res def Enum(self, name, expose=True): """ Returns wrapper around an Enum. name: full name or regex to match the name. """ res = self.findContained(name, declarations.enumeration_t) if res == None: raise RuntimeError, "Enum '%s' not found"%name if expose: res.expose() return res def ignore(self): """ Ignore this declaration. Ignore always acts recursively hidding all declarations under this one. """ for d in iterdecls(self.mDecl, True): d._expose_flag = False return self def expose(self, recursive=True): """ Expose this declaration. recursive - If True, then expose all under this decl. """ for d in iterdecls(self.mDecl, recursive): d._expose_flag = True return self def rename(self, newName): """ Rename declaration to newName. """ self.mDecl.declDecorator.rename = newName return self def setHeldType(self, heldType): """ Explicitly set the held type. Ex: setHeldType("boost::shared_ptr<Class>") """ self.mDecl.declDecorator.heldType = heldType return self def setCallPolicy(self, callPolicy): """ Set the callpolicy of the contained method. callPolicy - Callpolicy object to use (must be of type code_creators.call_policy_t) """ assert isinstance(callPolicy, code_creators.call_policy_t) self.mDecl.declDecorator.callPolicy = callPolicy return self def finalize(self): """ Ask this system to attempt to finalize this declaration. """ self.mDecl.declDecorator.finalize = True return self def addMethod(self, methodName, methodRef): """ Manually add a method (can be used for wrappers as well). Ex: addMethod("method", "&Class::method") """ self.addCustomText('def("%s", %s)'%(methodName, methodRef)) return self def wrapMethod(self, methodName, wrapperRef): """ Manually wrap method. Example: setWrapper("method", "ns::new_method") @post: ignores any old methods of methodName and defines new method """ self.Method(methodName).ignore() self.addMethod(methodName, wrapperRef) def addCustomText(self, text): """ Add custom text to the declarations creator. """ self.addCreator(code_creators.custom_text_t(text) ) return self def addCreator(self, creator): """ Add a creator that will be automatically added to the creator used to build the code for the wrapped declaration. """ self.mDecl.declDecorator.customCreators.append(creator) return self def printTree(self, detailed=True, recursive=True): """ Print decl tree rooted at this node. """ printDeclTree(self.mDecl, detailed, recursive) def getName(self): return self.mDecl.name def getFullname(self): return self.mDecl.decl_string def getSignature(self): """ Returns function signature: [retval, [arg1, ..., argN]]. """ return getMethodSignature(self.mDecl) def __getitem__(self, name): """ Allow simple name lookup using []'s. Semantically this has nearly the same effect as the creator methods except it does not allow restricting the decl lookup based on type. Ex: class["method"].expose() """ res = self.findContained(name) if res==None: raise RuntimeError, "Declaration '%s' not found"%name res.expose() return res def count(self, name, declType=None): """ Return the number of contained decls with given name and type. """ return len(self.findContainedDecls(name, declType)) def getDeclChildren(self): """ Return a list of all the children of the wrapped decl. """ children = getattr(self.mDecl, "declarations", None) return children # --------- Internal helpers --------- # def findContainedDecls(self, name=None, declType=None): """ Search contained declarations for ones of specific type and or name. name: regex to use for matching. (can just be full name) Note: To make it more predictable matching we automatically add a '$' to the end of the regex to match the end of the name. This helps to prevent names with similar prefix's from matching. If you need this ability you can still get it by adding '.*' declType: a single type or a list of decl types to look for. Returns None if not found. Returns 1 or a list if found. """ found = [] children = self.getDeclChildren() if None != name: if not name.endswith('$'): name = name + '$' name_re = re.compile(name) for c in children: if ((None == name or name_re.match(c.name)) and (None == declType or isinstance(c, declType))): found.append(c) return found def findContained(self, name=None, declType=None): """ Return a new DeclWrapper or MultiDeclWrapper for matching decls. name - If set this regex is used. declType - If set restrict search to decls based on the given type. """ found = self.findContainedDecls(name, declType) if len(found) == 0: return None elif len(found) == 1: return DeclWrapper(found[0]) else: return MultiDeclWrapper([DeclWrapper(d) for d in found]) def findContainedMethod(self, name, retval=None, args=None): """Search for a method with a particular name. name is the method name, retval the type of the return value and args a list of argument types. All types (retval and args) are given as strings treated as regex matches. ex: findContainedMethod("method", retval="bool &", args=["int", "float"]) findContainedMethod(".*", retval="float", args=None) """ found = [] children = getattr(self.mDecl, "declarations", None) if not name.endswith('$'): name = name + '$' name_re = re.compile(name) for c in children: if not isinstance(c, declarations.calldef_t): continue if not name_re.match(c.name): continue if retval!=None: if not retval.endswith('$'): retval = retval + '$' retval_re = re.compile(retval) if c.return_type == None or not retval_re.match(c.return_type.decl_string): continue if args!=None: if len(args) != len(c.arguments): continue cont_flag = False for arg,argument in zip(args, c.arguments): if not arg.endswith('$'): arg = arg + '$' arg_re = re.compile(arg) if not arg_re.match(argument.type.decl_string): cont_flag = True break if cont_flag: continue # Found one found.append(c) if len(found) == 0: return None elif len(found) == 1: return DeclWrapper(found[0]) else: return MultiDeclWrapper([DeclWrapper(d) for d in found]) class MultiDeclWrapper: """ Wrapper for multiple decls at once. Contains a limited subset of DeclWrapper interface. The purpose of having a separate class is to restrict the allowable methods that can be called on a set of decl wrappers. This helps to prevent user errors and minimizes the amount of error checking that is necessary. """ def __init__(self, wrappers): self.mDeclWrappers = wrappers def __getitem__(self, key): """ Lookup a contained item. Ex: methods[3].rename("newMethod") """ return self.mDeclWrappers[key] def __len__(self): """ Return the number of contained decl wrappers. """ return len(self.mDeclWrappers) def ignore(self): """ Call ignore on all contained wrappers. """ for d in self.mDeclWrappers: d.ignore() return self def expose(self, recursive=True): """ Call expose on all contained wrappers. """ for d in self.mDeclWrappers: d.expose(recursive) return self def setCallPolicy(self, callPolicy): """ Set the call policy for all contained wrappers. """ for d in self.mDeclWrappers: d.setCallPolicy(callPolicy) return self def finalize(self): """ Finalize all contained wrappers. """ for d in self.mDeclWrappers: d.finalize() return self # ------ Helper methods and classes --------- # # Internal methods that are not part of the main interface. # iterdecls def iterdecls(rootdecl, recursive=True): """Depth first iteration over one or more declaration trees. rootdecl can be either a single declaration, a list of declarations or None. A declaration must be an object derived from the declaration_t class. """ if rootdecl==None: return if type(rootdecl) is not list: rootdecl = [rootdecl] for root in rootdecl: yield root if recursive: children = getattr(root, "declarations", None) for node in iterdecls(children): yield node def getMethodSignature(decl): """ Returns function signature: [retval, [arg1, ..., argN]]. """ if not isinstance(decl, declarations.member_calldef_t): return None retval = decl.return_type.decl_string args = [] for arg in decl.arguments: args.append(arg.type.decl_string) return [retval, args] def printDeclTree(decls, detailed=True, recursive=True): """ Print decl tree rooted at each of the included nodes. decls - either a single decl or a list of decls. """ prn = DeclPrinter(0, detailed, recursive) if type(decls) is not list: decls = [decls] for d in decls: prn.level = 0 prn.instance = d declarations.apply_visitor(prn, d) class DeclPrinter( declarations.decl_visitor_t ): """ Helper class for printing decl tree. """ JUSTIFY = 20 INDENT_SIZE = 4 def __init__( self, level=0, printDetails=True, recursive=True ): declarations.decl_visitor_t.__init__(self) self.__inst = None self.__level = level self.__printDetails = printDetails self.__recursive = recursive def _get_level(self): return self.__level def _set_level(self, lvl): self.__level = lvl level = property( _get_level, _set_level ) def _get_inst(self): return self.__inst def _set_inst(self, inst): self.__inst = inst instance = property( _get_inst, _set_inst ) def __nice_decl_name( self, inst ): name = inst.__class__.__name__ return name #if name.endswith( '_t' ): # name = name[:-len('_t')] #return name.replace( '_', ' ' ) def __print_decl_header(self): header = self.__nice_decl_name( self.__inst ) + ": '%s'" % self.__inst.name print ' ' * self.level * self.INDENT_SIZE + header.ljust( self.JUSTIFY ) if self.__printDetails: curr_level = self.level + 1 if self.__inst.location: location = 'location: [%s]:%s'%(self.__inst.location.file_name, self.__inst.location.line) print ' ' * curr_level * self.INDENT_SIZE + location expose = getattr(self.__inst, "_expose_flag", False) print ' ' * curr_level * self.INDENT_SIZE + "Expose: ", expose artificial = 'artificial: ' + "'%s'" % str(self.__inst.is_artificial) print ' ' * curr_level * self.INDENT_SIZE + artificial.ljust( self.JUSTIFY ) def visit_member_function( self ): self.__print_decl_header() print ' ' * (self.level+1) * self.INDENT_SIZE + "Signature: ", getMethodSignature(self.__inst) def visit_constructor( self ): self.__print_decl_header() def visit_destructor( self ): self.__print_decl_header() def visit_member_operator( self ): self.__print_decl_header() def visit_casting_operator( self ): self.__print_decl_header() def visit_free_function( self ): self.__print_decl_header() def visit_free_operator( self ): self.__print_decl_header() def visit_class_declaration(self ): self.__print_decl_header() def visit_class(self ): self.__print_decl_header() curr_level = self.level + 1 class_type = 'class type: ' + "'%s'" % str(self.__inst.class_type) print ' ' * curr_level * self.INDENT_SIZE + class_type.ljust( self.JUSTIFY ) def print_hierarchy(hierarchy_type, classes, curr_level): print ' ' * curr_level * self.INDENT_SIZE + hierarchy_type.ljust( self.JUSTIFY ) curr_level += 1 for class_ in classes: class_str = 'class: ' + "'%s'" % str(class_.related_class.decl_string) print ' ' * curr_level * self.INDENT_SIZE + class_str.ljust( self.JUSTIFY ) access = 'access: ' + "'%s'" % str(class_.access) print ' ' * (curr_level + 1)* self.INDENT_SIZE + access.ljust( self.JUSTIFY ) def print_members(members_type, members, curr_level): print ' ' * curr_level * self.INDENT_SIZE + members_type.ljust( self.JUSTIFY ) if self.__recursive: curr_level += 1 for member in members: prn = DeclPrinter( curr_level + 1, self.__printDetails, self.__recursive ) prn.instance = member declarations.apply_visitor( prn, member ) if self.__inst.bases: print_hierarchy( 'base classes: ', self.__inst.bases, curr_level ) if self.__inst.derived: print_hierarchy( 'derived classes: ', self.__inst.derived, curr_level ) print_members( 'public: ', self.__inst.public_members, curr_level ) print_members( 'protected: ', self.__inst.protected_members, curr_level ) print_members( 'private: ', self.__inst.private_members, curr_level ) def visit_enumeration(self): self.__print_decl_header() curr_level = self.level + 1 print ' ' * curr_level * self.INDENT_SIZE + 'values: ['.ljust( self.JUSTIFY ), for name, value in self.__inst.values.items(): print "%s:%s, "% (name, value) def visit_namespace(self ): self.__print_decl_header() if self.__recursive: for decl in self.__inst.declarations: prn = DeclPrinter( self.level + 1, self.__printDetails, self.__recursive ) prn.instance = decl declarations.apply_visitor( prn, decl ) def visit_typedef(self ): self.__print_decl_header() curr_level = self.level + 1 print ' ' * curr_level * self.INDENT_SIZE + 'alias to: ', self.__inst.type.decl_string def visit_variable(self ): self.__print_decl_header() curr_level = self.level + 1 print ' ' * curr_level * self.INDENT_SIZE, 'type: %s value: %s'%(self.__inst.type.decl_string, self.__inst.value) |
From: Roman <rom...@us...> - 2006-03-02 13:30:45
|
Update of /cvsroot/pygccxml/source/pyplusplus/unittests/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4665/pyplusplus/unittests/data Added Files: optional_to_be_exported.hpp Log Message: init< ... , optional< ... > > is now implemented --- NEW FILE: optional_to_be_exported.hpp --- // 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 __optional_to_be_exported_hpp__ #define __optional_to_be_exported_hpp__ namespace optional_args{ struct data { data(int i=0, int j=1) : m_i( i ), m_j( j ) {} int m_i; int m_j; }; struct data2 { data2(int i, int j=1) : m_i( i ), m_j( j ) {} int m_i; int m_j; }; }//optional_args #endif//__optional_to_be_exported_hpp__ |
From: Roman <rom...@us...> - 2006-03-02 13:30:45
|
Update of /cvsroot/pygccxml/source/pyplusplus/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4665/pyplusplus/unittests Modified Files: test_all.py Added Files: optional_tester.py Log Message: init< ... , optional< ... > > is now implemented Index: test_all.py =================================================================== RCS file: /cvsroot/pygccxml/source/pyplusplus/unittests/test_all.py,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** test_all.py 15 Feb 2006 07:45:31 -0000 1.30 --- test_all.py 2 Mar 2006 13:30:37 -0000 1.31 *************** *** 40,43 **** --- 40,44 ---- import regression2_tester import regression3_tester + import optional_tester def create_suite(times): *************** *** 76,79 **** --- 77,81 ---- , class_order3_tester , class_order4_tester + , optional_tester ] --- NEW FILE: optional_tester.py --- # 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 = 'optional' def __init__( self, *args ): fundamental_tester_base.fundamental_tester_base_t.__init__( self , tester_t.EXTENSION_NAME , *args ) def customize( self, mb ): for decl in declarations.make_flatten( mb.declarations ): if isinstance( decl, declarations.calldef_t ): decl.use_default_arguments = False def run_tests(self, module): d = module.data() self.failUnless( d.m_i == 0 ) self.failUnless( d.m_j == 1 ) d2 = module.data(0) self.failUnless( d2.m_i == 0 ) self.failUnless( d2.m_j == 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() |
From: Roman <rom...@us...> - 2006-03-02 13:30:45
|
Update of /cvsroot/pygccxml/source/pyplusplus/code_creators In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4665/pyplusplus/code_creators Modified Files: calldef.py Log Message: init< ... , optional< ... > > is now implemented Index: calldef.py =================================================================== RCS file: /cvsroot/pygccxml/source/pyplusplus/code_creators/calldef.py,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** calldef.py 28 Feb 2006 08:06:02 -0000 1.45 --- calldef.py 2 Mar 2006 13:30:37 -0000 1.46 *************** *** 527,531 **** def _generate_definition_args(self): ! return ', '.join( map( self._create_arg_code, self.declaration.arguments ) ) def create_init_code(self): --- 527,545 ---- def _generate_definition_args(self): ! answer = [] ! optionals = [] ! for arg in self.declaration.arguments: ! if arg.default_value or optionals: ! optionals.append( self._create_arg_code( arg ) ) ! else: ! answer.append( self._create_arg_code( arg ) ) ! ! optionals_str = '' ! if optionals: ! optionals_str = algorithm.create_identifier( self, '::boost::python::optional' ) ! optionals_str = optionals_str + '< ' + ', '.join( optionals ) + ' >' ! answer.append( optionals_str ) ! return ', '.join( answer ) ! def create_init_code(self): |
From: Roman <rom...@us...> - 2006-03-02 07:07:17
|
Update of /cvsroot/pygccxml/source/pyplusplus/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8933/pyplusplus/unittests Modified Files: algorithms_tester.py Log Message: Index: algorithms_tester.py =================================================================== RCS file: /cvsroot/pygccxml/source/pyplusplus/unittests/algorithms_tester.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** algorithms_tester.py 28 Feb 2006 08:06:08 -0000 1.8 --- algorithms_tester.py 2 Mar 2006 07:07:13 -0000 1.9 *************** *** 23,29 **** def test(self): config = parser.config_t( gccxml_path=autoconfig.gccxml_path ) ! mb = module_builder.module_builder_t( 'dummy' ! , ['namespace enums{ enum { OK=1 }; }'] ! , config ) flatten = code_creators.make_flatten(mb.module_creator.creators) self.failUnless( filter( lambda inst: isinstance( inst, code_creators.unnamed_enum_t ), flatten ) ) --- 23,31 ---- def test(self): config = parser.config_t( gccxml_path=autoconfig.gccxml_path ) ! mb = module_builder.module_builder_t( ! 'dummy' ! , [ parser.create_text_fc( 'namespace enums{ enum { OK=1 }; }' )] ! , config ) ! mb.namespace( name='::enums' ).include() flatten = code_creators.make_flatten(mb.module_creator.creators) self.failUnless( filter( lambda inst: isinstance( inst, code_creators.unnamed_enum_t ), flatten ) ) *************** *** 32,50 **** def test_find_by_declaration(self): config = parser.config_t( gccxml_path=autoconfig.gccxml_path ) ! decls = parser.parse_string( 'namespace enums{ enum color{ red = 1}; }', config ) ! extmodule = module_creator.create( decls=decls, module_name='dummy' ) ! enum_matcher = declarations.match_declaration_t( name='color' ) ! enum_found = code_creators.creator_finder.find_by_declaration( enum_matcher ! , extmodule.creators ) self.failUnless( enum_found ) def test_find_by_class_instance(self): config = parser.config_t( gccxml_path=autoconfig.gccxml_path ) ! decls = parser.parse_string( 'namespace enums{ enum color{ red = 1}; }', config ) ! extmodule = module_creator.create( decls=decls, module_name='dummy' ) enum_found = code_creators.creator_finder.find_by_class_instance( code_creators.enum_t ! , extmodule.creators , recursive=True) self.failUnless( enum_found ) --- 34,58 ---- def test_find_by_declaration(self): config = parser.config_t( gccxml_path=autoconfig.gccxml_path ) ! mb = module_builder.module_builder_t( ! 'dummy' ! , [ parser.create_text_fc( 'namespace enums{ enum color{ red = 1}; }' )] ! , config ) ! mb.namespace( name='::enums' ).include() enum_matcher = declarations.match_declaration_t( name='color' ) ! enum_found = code_creators.creator_finder.find_by_declaration( ! enum_matcher ! , mb.module_creator.creators ) self.failUnless( enum_found ) def test_find_by_class_instance(self): config = parser.config_t( gccxml_path=autoconfig.gccxml_path ) ! mb = module_builder.module_builder_t( ! 'dummy' ! , [ parser.create_text_fc( 'namespace enums{ enum color{ red = 1}; }' )] ! , config ) ! mb.namespace( name='::enums' ).include() enum_found = code_creators.creator_finder.find_by_class_instance( code_creators.enum_t ! , mb.module_creator.creators , recursive=True) self.failUnless( enum_found ) |
From: Roman <rom...@us...> - 2006-03-02 05:55:44
|
Update of /cvsroot/pygccxml/source/pygccxml/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25022/pygccxml/unittests Modified Files: declarations_tester.py variable_matcher_tester.py Log Message: 1. adding few classes that will make it easier to find some declaration within declaration tree 2. new unittests has been added Index: variable_matcher_tester.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/unittests/variable_matcher_tester.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** variable_matcher_tester.py 28 Feb 2006 07:11:09 -0000 1.1 --- variable_matcher_tester.py 2 Mar 2006 05:55:41 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- # http://www.boost.org/LICENSE_1_0.txt) + import os import unittest import autoconfig *************** *** 24,31 **** def test( self ): ! criteria = declarations.variable_matcher_t( name='x', type_str='unsigned int' ) x = declarations.matcher.get_single( criteria, self.declarations ) ! criteria.name = '::bit_fields::fields_t::x' x = declarations.matcher.get_single( criteria, self.declarations ) def create_suite(): --- 25,40 ---- def test( self ): ! criteria = declarations.variable_matcher_t( name='x', type='unsigned int' ) x = declarations.matcher.get_single( criteria, self.declarations ) ! ! criteria = declarations.variable_matcher_t( ! name='::bit_fields::fields_t::x' ! , type=declarations.unsigned_int_t() ! , value=x.value ! , header_dir=os.path.dirname(x.location.file_name) ! , header_file=x.location.file_name) ! x = declarations.matcher.get_single( criteria, self.declarations ) + self.failUnless( x, "Variable was not found." ) def create_suite(): Index: declarations_tester.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/unittests/declarations_tester.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** declarations_tester.py 29 Sep 2005 06:09:10 -0000 1.3 --- declarations_tester.py 2 Mar 2006 05:55:41 -0000 1.4 *************** *** 69,73 **** self.failUnless( not m_mutable.type_qualifiers.has_static , "m_mutable must not have static type qualifier" ) ! TODO( "There is bug in GCCXML: doesn't write mutable qualifier." ) #self.failUnless( m_mutable.type_qualifiers.has_mutable # , "static_var must have mutable type qualifier" ) --- 69,73 ---- self.failUnless( not m_mutable.type_qualifiers.has_static , "m_mutable must not have static type qualifier" ) ! ##TODO: "There is bug in GCCXML: doesn't write mutable qualifier." #self.failUnless( m_mutable.type_qualifiers.has_mutable # , "static_var must have mutable type qualifier" ) *************** *** 88,92 **** no_return_1_arg = find_declaration( ns.declarations, type=free_function_t, name='no_return_1_arg' ) self.failUnless( no_return_1_arg, "unable to find 'no_return_1_arg' function" ) - TODO("Find out why GCCXML doesn't preserve argument names, except inline function." ) self._test_calldef_args( no_return_1_arg, [ argument_t( name='arg0', type=int_t() )] ) --- 88,91 ---- |
From: Roman <rom...@us...> - 2006-03-02 05:55:44
|
Update of /cvsroot/pygccxml/source/pygccxml/declarations In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25022/pygccxml/declarations Modified Files: declaration.py namespace.py variable.py Log Message: 1. adding few classes that will make it easier to find some declaration within declaration tree 2. new unittests has been added Index: namespace.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/declarations/namespace.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** namespace.py 28 Feb 2006 07:11:09 -0000 1.8 --- namespace.py 2 Mar 2006 05:55:39 -0000 1.9 *************** *** 49,58 **** #add more comment about this. #if not keep_parent: ! # decl.parent=None ! ! class namespace_matcher_t( declaration.declaration_matcher_t ): ! def __init__( self, name=None ): ! declaration.declaration_matcher_t.__init__( self, decl_type=namespace_t, name=name ) ! ! def does_match( self, decl ): ! return True \ No newline at end of file --- 49,51 ---- #add more comment about this. #if not keep_parent: ! # decl.parent=None \ No newline at end of file Index: variable.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/declarations/variable.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** variable.py 28 Feb 2006 07:11:09 -0000 1.6 --- variable.py 2 Mar 2006 05:55:39 -0000 1.7 *************** *** 54,73 **** self._bits = bits bits = property( _get_bits, _set_bits ) - - class variable_matcher_t( declaration.declaration_matcher_t ): - def __init__( self, name=None, type=None, type_str=None, value=None, location=None ): - declaration.declaration_matcher_t.__init__( self - , decl_type=variable_t - , name=name - , location=location ) - - self.type = type - self.type_str = type_str - self.value = value - - def does_match( self, decl ): - if None != self.type and self.type != decl.type: - return False - if None != self.type_str and self.type_str != decl.type.decl_string: - return False - return True --- 54,55 ---- Index: declaration.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/declarations/declaration.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** declaration.py 28 Feb 2006 07:11:09 -0000 1.17 --- declaration.py 2 Mar 2006 05:55:39 -0000 1.18 *************** *** 15,18 **** --- 15,19 ---- import templates + class location_t(object): *************** *** 166,194 **** return self._create_decl_string() decl_string = property( _decl_string, doc="full name of the declaration" ) - - - class declaration_matcher_t( object ): - def __init__( self, decl_type, name=None, location=None ): - object.__init__( self ) - self.decl_type = decl_type - self.location = location - self.name = name - - def __call__( self, decl ): - if not isinstance( decl, self.decl_type ): - return False - if None != self.location: - if self.location != decl.location: - return False - if None != self.name: - if '::' not in self.name: - if decl.name != self.name: - return False - else: - if self.name != algorithm.full_name( decl ): - return False - return self.does_match(decl) - - def does_match( self, decl ): - raise NotImplementedError() - \ No newline at end of file --- 167,168 ---- |
From: Roman <rom...@us...> - 2006-03-02 05:53:21
|
Update of /cvsroot/pygccxml/source/pygccxml/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23403/pygccxml/utils Modified Files: __init__.py Log Message: Index: __init__.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/utils/__init__.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** __init__.py 2 May 2005 03:31:06 -0000 1.7 --- __init__.py 2 Mar 2006 05:53:15 -0000 1.8 *************** *** 1,40 **** ! # 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 tempfile ! ! __REPOTED_TODOS = [] ! ! def TODO_LAUD( msg, report_once=True ): ! global __REPOTED_TODOS ! if not report_once or msg not in __REPOTED_TODOS: ! print 'TODO: ', msg ! __REPOTED_TODOS.append( msg ) ! ! def TODO_SILENT( msg, report_once=True ): ! __REPOTED_TODOS.append( msg ) ! ! try: ! import pygccxml ! TODO = TODO_SILENT ! except: ! TODO = TODO_LAUD ! ! ! def remove_file_no_raise(file_name ): ! try: ! if os.path.exists(file_name): ! os.remove( file_name ) ! except Exception, error: ! print "error ocured while removing temprorary created file('%s'): %s" % ( file_name, str( error ) ) ! ! def create_temp_file_name(suffix, prefix=None, dir=None): ! if not prefix: ! prefix = tempfile.template ! fd, name = tempfile.mkstemp( suffix=suffix, prefix=prefix, dir=dir ) ! file_obj = os.fdopen( fd ) ! file_obj.close() ! return name --- 1,35 ---- ! # 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 logging ! import tempfile ! ! ! logger = logging.getLogger('pygccxml') ! __handler = logging.StreamHandler(sys.stdout) ! __handler.setFormatter( logging.Formatter('%(asctime)s %(levelname)s %(message)s') ) ! logger.addHandler(__handler) ! logger.setLevel(logging.DEBUG) ! ! def remove_file_no_raise(file_name ): ! try: ! if os.path.exists(file_name): ! os.remove( file_name ) ! except Exception, error: ! logger.debug( "Error ocured while removing temprorary created file('%s'): %s" ! % ( file_name, str( error ) ) ) ! ! def create_temp_file_name(suffix, prefix=None, dir=None): ! if not prefix: ! prefix = tempfile.template ! fd, name = tempfile.mkstemp( suffix=suffix, prefix=prefix, dir=dir ) ! file_obj = os.fdopen( fd ) ! file_obj.close() ! return name ! ! def normalize_path( some_path ): ! return os.path.normpath( os.path.normcase( some_path ) ) |
From: Roman <rom...@us...> - 2006-03-02 05:53:21
|
Update of /cvsroot/pygccxml/source/pygccxml/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23403/pygccxml/unittests Modified Files: test_all.py Added Files: calldef_matcher_tester.py filters_tester.py Log Message: --- NEW FILE: filters_tester.py --- # 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 unittest import autoconfig import parser_test_case from pygccxml import utils from pygccxml import parser from pygccxml import declarations class tester_t( parser_test_case.parser_test_case_t ): COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE def __init__(self, *args ): parser_test_case.parser_test_case_t.__init__( self, *args ) self.header = 'declarations_calldef.hpp' self.declarations = None def setUp(self): if not self.declarations: self.declarations = parser.parse( [self.header], self.config ) def test_regex( self ): criteria = declarations.regex_matcher_t( 'oper.*' , lambda decl: decl.name ) operators = declarations.matcher.find( criteria, self.declarations ) self.failUnless( 6 == len(operators) ) def test_access_type( self ): criteria = declarations.access_type_matcher_t( declarations.ACCESS_TYPES.PUBLIC ) public_members = declarations.matcher.find( criteria, self.declarations ) self.failUnless( 19 == len( public_members ) ) 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() Index: test_all.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/unittests/test_all.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** test_all.py 28 Feb 2006 07:11:09 -0000 1.15 --- test_all.py 2 Mar 2006 05:53:14 -0000 1.16 *************** *** 28,31 **** --- 28,33 ---- import variable_matcher_tester import namespace_matcher_tester + import calldef_matcher_tester + import filters_tester def create_suite(): *************** *** 54,57 **** --- 56,61 ---- , variable_matcher_tester , namespace_matcher_tester + , calldef_matcher_tester + , filters_tester ] --- NEW FILE: calldef_matcher_tester.py --- # 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 unittest import autoconfig import parser_test_case from pygccxml import utils from pygccxml import parser from pygccxml import declarations class tester_t( parser_test_case.parser_test_case_t ): COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE def __init__(self, *args ): parser_test_case.parser_test_case_t.__init__( self, *args ) self.header = 'declarations_calldef.hpp' self.declarations = None def setUp(self): if not self.declarations: self.declarations = parser.parse( [self.header], self.config ) def test( self ): criteria = declarations.calldef_matcher_t( name='return_default_args' , return_type='int' , arg_types=[ None, declarations.bool_t() ] ) rda = declarations.matcher.get_single( criteria, self.declarations ) self.failUnless( rda, "return_default_args function was not found." ) 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() |
From: Roman <rom...@us...> - 2006-03-02 05:53:21
|
Update of /cvsroot/pygccxml/source/pygccxml/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23403/pygccxml/parser Modified Files: __init__.py declarations_cache.py project_reader.py scanner.py source_reader.py Log Message: Index: __init__.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/parser/__init__.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** __init__.py 22 Jan 2006 10:17:17 -0000 1.16 --- __init__.py 2 Mar 2006 05:53:14 -0000 1.17 *************** *** 9,12 **** --- 9,17 ---- from project_reader import project_reader_t from project_reader import file_configuration_t + from project_reader import create_text_fc + from project_reader import create_source_fc + from project_reader import create_gccxml_fc + from project_reader import create_cached_source_fc + from source_reader import source_reader_t from source_reader import gccxml_runtime_error_t *************** *** 17,20 **** --- 22,26 ---- CONTENT_TYPE = file_configuration_t.CONTENT_TYPE + def parse( files , config=None Index: scanner.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/parser/scanner.py,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** scanner.py 28 Feb 2006 07:11:09 -0000 1.20 --- scanner.py 2 Mar 2006 05:53:14 -0000 1.21 *************** *** 10,13 **** --- 10,14 ---- import xml.sax.handler from pygccxml.declarations import * + from pygccxml.utils import logger ##convention *************** *** 192,196 **** self.__files[ attrs[XML_AN_ID] ] = obj else: ! print 'unknown object types.' def endElement(self, name): --- 193,198 ---- self.__files[ attrs[XML_AN_ID] ] = obj else: ! logger.debug( 'Unknown object type has been found.' ! + ' Please report this bug to pygccxml development team.' ) def endElement(self, name): Index: declarations_cache.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/parser/declarations_cache.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** declarations_cache.py 28 Feb 2006 07:11:09 -0000 1.10 --- declarations_cache.py 2 Mar 2006 05:53:14 -0000 1.11 *************** *** 10,14 **** import time import cPickle ! from pygccxml.utils import TODO --- 10,14 ---- import time import cPickle ! from pygccxml.utils import logger *************** *** 152,164 **** cache_file_obj = file( file_name, 'rb' ) try: ! print "Loading cache... ", ! sys.stdout.flush() start_time = time.clock() cache = cPickle.load( cache_file_obj ) ! print " %.1f secs"%(time.clock()-start_time) ! print "Found cache in file: [%s] entries: %s"%(file_name, len(cache.keys())) except Exception, error: cache_file_obj.close() ! print "Invalid cache file: [%s] Regenerating."%file_name file(file_name, 'w+b').close() # Create empty file cache = {} # Empty cache --- 152,164 ---- cache_file_obj = file( file_name, 'rb' ) try: ! logger.debug( "Loading cache file ..." ) start_time = time.clock() cache = cPickle.load( cache_file_obj ) ! logger.debug( "Cache file has been loaded in %.1f secs"%( time.clock() - start_time ) ) ! logger.debug( "Found cache in file: [%s] entries: %s" ! % ( file_name, len( cache.keys() ) ) ) except Exception, error: cache_file_obj.close() ! logger.debug( "Invalid cache file: [%s] Regenerating." % file_name ) file(file_name, 'w+b').close() # Create empty file cache = {} # Empty cache *************** *** 177,181 **** del self.__cache[key] if num_removed > 0: ! print " removed %s entries from cache."%num_removed # Save out the cache to disk cache_file = file( self.__name, 'w+b' ) --- 177,181 ---- del self.__cache[key] if num_removed > 0: ! logger.debug( "There are %s removed entries from cache." % num_removed ) # Save out the cache to disk cache_file = file( self.__name, 'w+b' ) Index: source_reader.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/parser/source_reader.py,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** source_reader.py 28 Feb 2006 07:11:09 -0000 1.24 --- source_reader.py 2 Mar 2006 05:53:14 -0000 1.25 *************** *** 13,16 **** --- 13,17 ---- import patcher from pygccxml.declarations import * + from pygccxml.utils import logger class gccxml_runtime_error_t( RuntimeError ): *************** *** 106,110 **** command_line = self.__create_command_line( ffname, gccxml_file ) if self.__config.verbose: ! print " gccxml: ", command_line input, output = os.popen4( command_line ) input.close() --- 107,111 ---- command_line = self.__create_command_line( ffname, gccxml_file ) if self.__config.verbose: ! logger.debug( " Command line for GCC-XML: %s" % command_line ) input, output = os.popen4( command_line ) input.close() *************** *** 146,154 **** ffname = self.__file_full_name(source_file) if self.__config.verbose: ! print " reading source file: [%s]:"%ffname, declarations = self.__dcache.cached_value( ffname, self.__config ) if not declarations: if self.__config.verbose: ! print " parsing..." gccxml_file = self.create_xml_file( ffname ) declarations, files = self.__parse_gccxml_created_file( gccxml_file ) --- 147,155 ---- ffname = self.__file_full_name(source_file) if self.__config.verbose: ! logger.debug( "Reading source file: [%s]." % ffname ) declarations = self.__dcache.cached_value( ffname, self.__config ) if not declarations: if self.__config.verbose: ! logger.debug( "File has not been found in cache, parsing..." ) gccxml_file = self.create_xml_file( ffname ) declarations, files = self.__parse_gccxml_created_file( gccxml_file ) *************** *** 156,160 **** else: if self.__config.verbose: ! print " cached." except Exception, error: --- 157,161 ---- else: if self.__config.verbose: ! logger.debug( "File has not been changed, reading declarations from cache." ) except Exception, error: *************** *** 168,172 **** def read_xml_file(self, gccxml_created_file): if self.__config.verbose: ! print " reading xml file: [%s]"%gccxml_created_file declarations, files = self.__parse_gccxml_created_file( gccxml_created_file ) --- 169,173 ---- def read_xml_file(self, gccxml_created_file): if self.__config.verbose: ! logger.debug( "Reading xml file: [%s]" % gccxml_created_file ) declarations, files = self.__parse_gccxml_created_file( gccxml_created_file ) Index: project_reader.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/parser/project_reader.py,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** project_reader.py 28 Feb 2006 07:11:09 -0000 1.22 --- project_reader.py 2 Mar 2006 05:53:14 -0000 1.23 *************** *** 11,14 **** --- 11,15 ---- import declarations_cache import pygccxml.declarations + from pygccxml.utils import logger class COMPILATION_MODE: *************** *** 55,58 **** --- 56,76 ---- cached_source_file = property( __get_cached_source_file ) + def create_text_fc( text ): + return file_configuration_t( data=text + , content_type=file_configuration_t.CONTENT_TYPE.TEXT ) + + def create_source_fc( header ): + return file_configuration_t( data=header + , content_type=file_configuration_t.CONTENT_TYPE.STANDARD_SOURCE_FILE ) + + def create_gccxml_fc( xml_file ): + 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 ): + return file_configuration_t( data=header + , cached_source_file=cached_source_file + , content_type=file_configuration_t.CONTENT_TYPE.CACHED_SOURCE_FILE ) + class project_reader_t: def __init__( self, config, cache=None, decl_factory=None): *************** *** 79,83 **** config = self.__config.clone() if config.verbose: ! print "Reading project files: file by file" for prj_file in files: reader = None --- 97,101 ---- config = self.__config.clone() if config.verbose: ! logger.debug( "Reading project files: file by file" ) for prj_file in files: reader = None *************** *** 110,126 **** namespaces.append( decls ) if config.verbose: ! print "Flushing cache... ", ! sys.stdout.flush() start_time = time.clock() self.__dcache.flush() if config.verbose: ! print " %.1f secs"%(time.clock()-start_time) answer = [] if config.verbose: ! print "joining namespaces" for file_nss in namespaces: answer = self._join_top_namespaces( answer, file_nss ) if config.verbose: ! print "joining declarations" for ns in answer: if isinstance( ns, pygccxml.declarations.namespace_t ): --- 128,144 ---- namespaces.append( decls ) if config.verbose: ! logger.debug( "Flushing cache... " ) start_time = time.clock() self.__dcache.flush() if config.verbose: ! logger.debug( "Cache has been fkushed in %.1f secs" ! % ( time.clock() - start_time ) ) answer = [] if config.verbose: ! logger.debug( "Joining namespaces ..." ) for file_nss in namespaces: answer = self._join_top_namespaces( answer, file_nss ) if config.verbose: ! logger.debug( "Joining declarations ..." ) for ns in answer: if isinstance( ns, pygccxml.declarations.namespace_t ): *************** *** 129,133 **** types = self.__declarated_types(answer) if config.verbose: ! print "relinking declared types" self._relink_declarated_types( leaved_classes, types ) return answer --- 147,151 ---- types = self.__declarated_types(answer) if config.verbose: ! logger.debug( "Relinking declared types ..." ) self._relink_declarated_types( leaved_classes, types ) return answer *************** *** 136,140 **** config = self.__config.clone() if config.verbose: ! print "Reading project files: all at once" header_content = [] for header in files: --- 154,158 ---- config = self.__config.clone() if config.verbose: ! logger.debug( "Reading project files: all at once" ) header_content = [] for header in files: |
From: Roman <rom...@us...> - 2006-03-02 05:53:20
|
Update of /cvsroot/pygccxml/source/pygccxml/declarations In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23403/pygccxml/declarations Modified Files: __init__.py algorithm.py Added Files: filters.py Log Message: Index: __init__.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/declarations/__init__.py,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** __init__.py 28 Feb 2006 07:11:09 -0000 1.32 --- __init__.py 2 Mar 2006 05:53:14 -0000 1.33 *************** *** 13,17 **** from enumeration import enumeration_t from namespace import namespace_t - from namespace import namespace_matcher_t from class_declaration import class_t --- 13,16 ---- *************** *** 57,61 **** from variable import variable_t - from variable import variable_matcher_t from algorithm import full_name --- 56,59 ---- *************** *** 136,138 **** --- 134,142 ---- from decl_factory import decl_factory_t + from filters import calldef_matcher_t + from filters import namespace_matcher_t + from filters import variable_matcher_t + from filters import regex_matcher_t + from filters import access_type_matcher_t + from matcher import matcher \ No newline at end of file Index: algorithm.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/declarations/algorithm.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** algorithm.py 21 Dec 2005 07:29:23 -0000 1.17 --- algorithm.py 2 Mar 2006 05:53:14 -0000 1.18 *************** *** 7,11 **** import types - import pygccxml.utils from sets import Set as set --- 7,10 ---- *************** *** 43,47 **** decl_path = declaration_path( decl ) ##Here I have lack of knowledge: ! pygccxml.utils.TODO( "What is the full name of declaration declared in unnamed namespace?" ) result = filter( None, decl_path ) return result[0] + '::'.join( result[1:] ) --- 42,46 ---- decl_path = declaration_path( decl ) ##Here I have lack of knowledge: ! ##TODO: "What is the full name of declaration declared in unnamed namespace?" result = filter( None, decl_path ) return result[0] + '::'.join( result[1:] ) --- NEW FILE: filters.py --- # 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 re import types import algorithm import variable import namespace import calldef import cpptypes import class_declaration from pygccxml import utils class declaration_matcher_t( object ): def __init__( self, decl_type=None, name=None, header_file=None, header_dir=None ): """ header and header dir should be absolute! """ #An other option is that #pygccxml will create absolute path using os.path.abspath function. #But I think this is just wrong, because abspath wbuilds path using #cwd and this behaviour is fragile and not so easy to find the bug. object.__init__( self ) self.decl_type = decl_type self.name = name self.header_dir = header_dir if self.header_dir: self.header_dir = utils.normalize_path( header_dir ) self.header_file = header_file if self.header_file: self.header_file = utils.normalize_path( header_file ) if self.header_dir and not os.path.isabs( self.header_dir ): raise RuntimeError( "Path to header directory should be absolute!" ) if self.header_file and not os.path.isabs( self.header_file ): raise RuntimeError( "Path to header file should be absolute!" ) def __call__( self, decl ): if None != self.decl_type: if not isinstance( decl, self.decl_type ): return False if None != self.name: if '::' not in self.name: if decl.name != self.name: return False else: if self.name != algorithm.full_name( decl ): return False if None != self.header_dir: decl_dir = os.path.abspath( os.path.dirname( decl.location.file_name ) ) decl_dir = utils.normalize_path( decl_dir ) if decl_dir[:len(self.header_dir)] != self.header_dir: return False if None != self.header_file: decl_file = os.path.abspath( decl.location.file_name ) decl_file = utils.normalize_path( decl_file ) if decl_file != self.header_file: return False return True class variable_matcher_t( declaration_matcher_t ): def __init__( self, type=None, value=None, *arguments, **keywords): """ type could be string or instance of class derived from cpptypes.type_t """ declaration_matcher_t.__init__( self, variable.variable_t, *arguments, **keywords ) self.type = type self.value = value def __call__( self, decl ): if not super( variable_matcher_t, self ).__call__( decl ): return False if None != self.type: if isinstance( self.type, cpptypes.type_t ): if self.type != decl.type: return False else: if self.type != decl.type.decl_string: return False return True class namespace_matcher_t( declaration_matcher_t ): def __init__( self, *arguments, **keywords ): declaration_matcher_t.__init__( self, namespace.namespace_t, *arguments, **keywords) def __call__( self, decl ): return super( namespace_matcher_t, self ).__call__( decl ) class calldef_matcher_t( declaration_matcher_t ): def __init__( self, return_type=None, arg_types=None, *arguments, **keywords): """ return_value_type could be string or instance of class derived from cpptypes.type_t arg_types could be a list of strings or cpptypes.type_t. It could be a mix. In this case you should specify all arguments. If you don't want to match some argument you can insert None instead. In future it should be possible to select function by it's default argument value and/or exception .... """ if not keywords.has_key( 'decl_type' ): keywords[ 'decl_type' ] = calldef.calldef_t declaration_matcher_t.__init__( self, *arguments, **keywords ) self.return_type = return_type self.arg_types = arg_types def __call__( self, decl ): if not super( calldef_matcher_t, self ).__call__( decl ): return False if None != self.return_type \ and not self.__compare_types( self.return_type, decl.return_type ): return False if self.arg_types: if isinstance( self.arg_types, (types.ListType, types.TupleType)): if len(self.arg_types) != len( decl.arguments ): return False for type_or_str, arg in zip( self.arg_types, decl.arguments ): if None == type_or_str: continue else: if not self.__compare_types( type_or_str, arg.type ): return False return True def __compare_types( self, type_or_str, type ): assert type_or_str if isinstance( type_or_str, cpptypes.type_t ): if type_or_str != type: return False else: if type_or_str != type.decl_string: return False return True class regex_matcher_t: def __init__( self, regex, function ): self.regex = re.compile( regex ) self.function = function def __call__( self, decl ): text = self.function( decl ) return bool( self.regex.match( text ) ) class access_type_matcher_t: def __init__( self, access_type ): self.access_type = access_type def __call__( self, decl ): if not isinstance( decl.parent, class_declaration.class_t ): return False return self.access_type == decl.parent.find_out_member_access_type( decl ) |
From: Roman <rom...@us...> - 2006-03-02 05:51:44
|
Update of /cvsroot/pygccxml/source/pygccxml/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22365/pygccxml/parser Modified Files: linker.py Log Message: fixing name of casting operator. Now it's name is equal to 'operator ' + return_type.decl_string Index: linker.py =================================================================== RCS file: /cvsroot/pygccxml/source/pygccxml/parser/linker.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** linker.py 19 Jan 2006 05:25:59 -0000 1.11 --- linker.py 2 Mar 2006 05:51:39 -0000 1.12 *************** *** 85,88 **** --- 85,89 ---- def visit_casting_operator( self ): self.__link_calldef() + self.__inst.name = 'operator ' + self.__inst.return_type.decl_string def visit_free_function( self ): |