[pygccxml-commit] SF.net SVN: pygccxml: [1052] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2007-06-13 05:42:41
|
Revision: 1052
http://svn.sourceforge.net/pygccxml/?rev=1052&view=rev
Author: roman_yakovenko
Date: 2007-06-12 22:42:40 -0700 (Tue, 12 Jun 2007)
Log Message:
-----------
adding new functionality to free operators - now they are able to report class types, they work on
Modified Paths:
--------------
pygccxml_dev/pygccxml/declarations/calldef.py
pygccxml_dev/unittests/test_all.py
Added Paths:
-----------
pygccxml_dev/unittests/data/free_operators.hpp
pygccxml_dev/unittests/free_operators_tester.py
Modified: pygccxml_dev/pygccxml/declarations/calldef.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/calldef.py 2007-06-10 19:30:09 UTC (rev 1051)
+++ pygccxml_dev/pygccxml/declarations/calldef.py 2007-06-13 05:42:40 UTC (rev 1052)
@@ -427,10 +427,10 @@
def __init__(self):
object.__init__(self)
- def _get_symbol(self):
+ @property
+ def symbol(self):
+ "operator's symbol. For example: operator+, symbol is equal to '+'"
return self.name[operator_t.OPERATOR_WORD_LEN:].strip()
- symbol = property( _get_symbol,
- doc="returns symbol of operator. For example: operator+, symbol is equal to '+'")
#Third level in hierarchy of calldef
class member_function_t( member_calldef_t ):
@@ -438,7 +438,6 @@
def __init__( self, *args, **keywords ):
member_calldef_t.__init__( self, *args, **keywords )
-
class constructor_t( member_calldef_t ):
"""describes constructor declaration"""
def __init__( self, *args, **keywords ):
@@ -485,6 +484,7 @@
def __init__( self, *args, **keywords ):
member_calldef_t.__init__( self, *args, **keywords )
operator_t.__init__( self, *args, **keywords )
+ self.__class_types = None
class casting_operator_t( member_calldef_t, operator_t ):
"""describes casting operator declaration"""
@@ -502,3 +502,22 @@
def __init__( self, *args, **keywords ):
free_calldef_t.__init__( self, *args, **keywords )
operator_t.__init__( self, *args, **keywords )
+ self.__class_types = None
+
+ @property
+ def class_types( self ):
+ """list of class/class declaration types, extracted from the operator arguments"""
+ if None is self.__class_types:
+ self.__class_types = []
+ for type_ in self.argument_types:
+ decl = None
+ type_ = type_traits.remove_reference( type_ )
+ if type_traits.is_class( type_ ):
+ decl = type_traits.class_traits.get_declaration( type_ )
+ elif type_traits.is_class_declaration( type_ ):
+ decl = type_traits.class_declaration_traits.get_declaration( type_ )
+ else:
+ pass
+ if decl:
+ self.__class_types.append( decl )
+ return self.__class_types
Added: pygccxml_dev/unittests/data/free_operators.hpp
===================================================================
--- pygccxml_dev/unittests/data/free_operators.hpp (rev 0)
+++ pygccxml_dev/unittests/data/free_operators.hpp 2007-06-13 05:42:40 UTC (rev 1052)
@@ -0,0 +1,57 @@
+// 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 __free_operators_to_be_exported_hpp__
+#define __free_operators_to_be_exported_hpp__
+
+namespace free_operators{
+
+struct number{
+ int i;
+
+ number operator*( int ii ) const {
+ number n2 = { i * ii };
+ return n2;
+ }
+};
+
+struct rational{
+ int x, y;
+};
+
+number operator+( const number& x, int y ){
+ number z;
+ z.i = x.i + y;
+ return z;
+}
+
+bool operator!( const number& x ){
+ return !x.i;
+}
+
+number operator*( const number& n, double i ){
+ number n2 = { n.i * i };
+ return n2;
+}
+
+number operator*( double i, const number& n ){
+ number n2 = { n.i * i };
+ return n2;
+}
+
+rational operator*( int i, const rational& r ){
+ rational rr = { r.x * i, r.y };
+ return rr;
+}
+
+bool operator!( const rational& x ){
+ return !x.x;
+}
+
+
+}
+
+
+#endif//__free_operators_to_be_exported_hpp__
Added: pygccxml_dev/unittests/free_operators_tester.py
===================================================================
--- pygccxml_dev/unittests/free_operators_tester.py (rev 0)
+++ pygccxml_dev/unittests/free_operators_tester.py 2007-06-13 05:42:40 UTC (rev 1052)
@@ -0,0 +1,46 @@
+# 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 ):
+ def __init__(self, *args ):
+ parser_test_case.parser_test_case_t.__init__( self, *args )
+ self.header = 'free_operators.hpp'
+ self.global_ns = None
+
+ def setUp(self):
+ reader = parser.source_reader_t( self.config )
+ decls = reader.read_file( self.header )
+ self.global_ns = declarations.get_global_namespace( decls )
+
+ def test( self ):
+ fo = self.global_ns.namespace( 'free_operators' )
+ number = fo.class_( 'number' )
+ rational = fo.class_( 'rational' )
+ for oper in fo.free_operators():
+ if number.name in str( oper ):
+ self.failUnless( number in oper.class_types )
+ if rational.name in str( oper ):
+ self.failUnless( rational in oper.class_types )
+
+
+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()
Modified: pygccxml_dev/unittests/test_all.py
===================================================================
--- pygccxml_dev/unittests/test_all.py 2007-06-10 19:30:09 UTC (rev 1051)
+++ pygccxml_dev/unittests/test_all.py 2007-06-13 05:42:40 UTC (rev 1052)
@@ -40,6 +40,7 @@
import has_binary_operator_traits_tester
import algorithms_cache_tester
import dependencies_tester
+import free_operators_tester
def create_suite():
testers = [
@@ -79,6 +80,7 @@
, has_binary_operator_traits_tester
, algorithms_cache_tester
, dependencies_tester
+ , free_operators_tester
]
main_suite = unittest.TestSuite()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|