[pygccxml-commit] SF.net SVN: pygccxml:[1537] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2009-01-05 22:58:45
|
Revision: 1537
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1537&view=rev
Author: roman_yakovenko
Date: 2009-01-05 22:58:43 +0000 (Mon, 05 Jan 2009)
Log Message:
-----------
fix bug "pygccxml parses const volatile variable args as just const"
Modified Paths:
--------------
pygccxml_dev/pygccxml/declarations/type_traits.py
pygccxml_dev/pygccxml/parser/linker.py
pygccxml_dev/pygccxml/parser/scanner.py
pygccxml_dev/unittests/autoconfig.py
pygccxml_dev/unittests/test_all.py
pygccxml_dev/unittests/type_traits_tester.py
Added Paths:
-----------
pygccxml_dev/unittests/const_volatile_arg_tester.py
pygccxml_dev/unittests/data/const_volatile_arg.hpp
Modified: pygccxml_dev/pygccxml/declarations/type_traits.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/type_traits.py 2009-01-05 22:06:06 UTC (rev 1536)
+++ pygccxml_dev/pygccxml/declarations/type_traits.py 2009-01-05 22:58:43 UTC (rev 1537)
@@ -104,7 +104,14 @@
elif 3 <= len( types ):
classes = set( [tp.__class__ for tp in types[:3]] )
desired = set( [main] + list( secondary ) )
- return classes == desired
+ diff = classes.symmetric_difference( desired )
+ if not diff:
+ return True
+ if len( diff ) == 2:
+ items = list( diff )
+ return issubclass( items[0], items[1] ) or issubclass( items[1], items[0] )
+ else:
+ return False
else:
return False
@@ -152,17 +159,16 @@
def is_pointer(type):
"""returns True, if type represents C++ pointer type, False otherwise"""
- return does_match_definition( type
- , cpptypes.pointer_t
- , (cpptypes.const_t, cpptypes.volatile_t) )
+ return does_match_definition( type, cpptypes.pointer_t, (cpptypes.const_t, cpptypes.volatile_t) ) \
+ or does_match_definition( type, cpptypes.pointer_t, (cpptypes.volatile_t, cpptypes.const_t) )
+
def is_calldef_pointer(type):
"""returns True, if type represents pointer to free/member function, False otherwise"""
if not is_pointer(type):
return False
nake_type = remove_alias( type )
- nake_type = remove_const( nake_type )
- nake_type = remove_volatile( nake_type )
+ nake_type = remove_cv( nake_type )
return isinstance( nake_type, cpptypes.compound_t ) \
and isinstance( nake_type.base, cpptypes.calldef_type_t )
@@ -178,6 +184,10 @@
return cpptypes.volatile_t( nake_type.base.base )
elif isinstance( nake_type, cpptypes.const_t ) and isinstance( nake_type.base, cpptypes.pointer_t ):
return cpptypes.const_t( nake_type.base.base )
+ elif isinstance( nake_type, cpptypes.volatile_t ) \
+ and isinstance( nake_type.base, cpptypes.const_t ) \
+ and isinstance( nake_type.base.base, cpptypes.pointer_t ):
+ return cpptypes.volatile_t( ctypes.const_t( nake_type.base.base.base ) )
elif isinstance( nake_type.base, cpptypes.calldef_type_t ):
return type
else:
@@ -285,13 +295,14 @@
result = nake_type.base
if is_volatile( result ):
result = result.base
+ if is_const( result ):
+ result = result.base
return result
def is_fundamental(type):
"""returns True, if type represents C++ fundamental type"""
- return does_match_definition( type
- , cpptypes.fundamental_t
- , (cpptypes.const_t, cpptypes.volatile_t) )
+ return does_match_definition( type, cpptypes.fundamental_t, (cpptypes.const_t, cpptypes.volatile_t) ) \
+ or does_match_definition( type, cpptypes.fundamental_t, (cpptypes.volatile_t, cpptypes.const_t) ) \
class declaration_xxx_traits:
"""this class implements the functionality needed for convinient work with
Modified: pygccxml_dev/pygccxml/parser/linker.py
===================================================================
--- pygccxml_dev/pygccxml/parser/linker.py 2009-01-05 22:06:06 UTC (rev 1536)
+++ pygccxml_dev/pygccxml/parser/linker.py 2009-01-05 22:58:43 UTC (rev 1537)
@@ -18,13 +18,13 @@
self.__membership = membership
self.__files = files
self.__inst = None
-
- self.__compiler = None
+
+ self.__compiler = None
if self.__decls:
for d in self.__decls.itervalues():
self.__compiler = d.compiler
break
-
+
def _get_inst(self):
return self.__inst
def _set_inst(self, inst):
@@ -48,12 +48,12 @@
else:
return unknown_t()
- def __link_compound_type(self):
+ def __link_compound_type(self):
self.__inst.base = self.__link_type( self.__inst.base )
def __link_members(self):
if not self.__membership.has_key( id(self.__inst) ):
- return
+ return
for member in self.__membership[ id(self.__inst) ]:
if not self.__access.has_key( member ):
continue
@@ -85,7 +85,7 @@
def visit_constructor( self ):
self.__link_calldef()
-
+
def visit_destructor( self ):
self.__link_calldef()
@@ -109,13 +109,13 @@
def visit_class(self ):
self.__link_members()
#GCC-XML sometimes generates constructors with names that does not match
- #class name. I think this is because those constructors are compiler
- #generated. I need to find out more about this and to talk with Brad
+ #class name. I think this is because those constructors are compiler
+ #generated. I need to find out more about this and to talk with Brad
new_name = self.__inst._name
if templates.is_instantiation( new_name ):
new_name = templates.name( new_name )
-
+
for decl in self.__inst.declarations:
if not isinstance( decl, constructor_t ):
continue
@@ -133,7 +133,7 @@
access = data[0]
self.__inst.bases.append( hierarchy_info_t( base_decl, access ) )
base_decl.derived.append( hierarchy_info_t( self.__inst, access ) )
-
+
def visit_enumeration(self ):
pass
@@ -208,30 +208,34 @@
def visit_jbyte(self):
pass
-
+
def visit_jshort(self):
pass
-
+
def visit_jint(self):
pass
-
+
def visit_jlong(self):
pass
-
+
def visit_jfloat(self):
pass
-
+
def visit_jdouble(self):
pass
-
+
def visit_jchar(self):
pass
-
+
def visit_jboolean(self):
pass
def visit_volatile( self ):
- self.__link_compound_type()
+ if isinstance( self.__inst.base, const_t ):
+ const_type_inst = self.__inst.base
+ const_type_inst.base = self.__link_type( const_type_inst.base )
+ else:
+ self.__link_compound_type()
def visit_const( self ):
self.__link_compound_type()
@@ -239,7 +243,7 @@
def visit_pointer( self ):
if '0.9' in self.__compiler and isinstance( self.__inst.base, member_variable_type_t ):
original_inst = self.__inst
- self.__inst = self.__inst.base
+ self.__inst = self.__inst.base
self.visit_member_variable_type()
self.__inst = original_inst
else:
Modified: pygccxml_dev/pygccxml/parser/scanner.py
===================================================================
--- pygccxml_dev/pygccxml/parser/scanner.py 2009-01-05 22:06:06 UTC (rev 1536)
+++ pygccxml_dev/pygccxml/parser/scanner.py 2009-01-05 22:58:43 UTC (rev 1537)
@@ -338,7 +338,9 @@
return array_t( type_, size + 1 )
def __read_cv_qualified_type( self, attrs ):
- if attrs.has_key( XML_AN_CONST ):
+ if attrs.has_key( XML_AN_CONST ) and attrs.has_key( XML_AN_VOLATILE ):
+ return volatile_t( const_t( attrs[XML_AN_TYPE] ) )
+ elif attrs.has_key( XML_AN_CONST ):
return const_t( attrs[XML_AN_TYPE] )
elif attrs.has_key( XML_AN_VOLATILE ):
return volatile_t( attrs[XML_AN_TYPE] )
Modified: pygccxml_dev/unittests/autoconfig.py
===================================================================
--- pygccxml_dev/unittests/autoconfig.py 2009-01-05 22:06:06 UTC (rev 1536)
+++ pygccxml_dev/unittests/autoconfig.py 2009-01-05 22:58:43 UTC (rev 1537)
@@ -28,7 +28,6 @@
print 'unittests will run on DEVELOPMENT version'
compiler = pygccxml.utils.native_compiler.get_gccxml_compiler()
-compiler = 'msvc71'
print 'GCCXML configured to simulate compiler ', compiler
pygccxml.declarations.class_t.USE_DEMANGLED_AS_NAME = True
Added: pygccxml_dev/unittests/const_volatile_arg_tester.py
===================================================================
--- pygccxml_dev/unittests/const_volatile_arg_tester.py (rev 0)
+++ pygccxml_dev/unittests/const_volatile_arg_tester.py 2009-01-05 22:58:43 UTC (rev 1537)
@@ -0,0 +1,46 @@
+# Copyright 2004-2008 Roman Yakovenko.
+# Distributed under the Boost Software License, Version 1.0. (See
+# accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+import unittest
+import autoconfig
+import parser_test_case
+
+from pygccxml import utils
+from pygccxml import parser
+from pygccxml import declarations
+
+class tester_t( parser_test_case.parser_test_case_t ):
+ global_ns = None
+ def __init__(self, *args ):
+ parser_test_case.parser_test_case_t.__init__( self, *args )
+ self.header = 'const_volatile_arg.hpp'
+ self.global_ns = None
+
+ def setUp(self):
+ if not tester_t.global_ns:
+ decls = parser.parse( [self.header], self.config )
+ tester_t.global_ns = declarations.get_global_namespace( decls )
+ tester_t.global_ns.init_optimizer()
+ self.global_ns = tester_t.global_ns
+
+ def test( self ):
+ f = self.global_ns.free_fun( 'pygccxml_bug' )
+ t = f.arguments[0].type
+ self.failUnless( isinstance( t, declarations.pointer_t ) )
+ self.failUnless( isinstance( t.base, declarations.volatile_t ) )
+ self.failUnless( isinstance( t.base.base, declarations.const_t ) )
+ self.failUnless( declarations.is_integral( t.base.base.base ) )
+
+
+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()
Added: pygccxml_dev/unittests/data/const_volatile_arg.hpp
===================================================================
--- pygccxml_dev/unittests/data/const_volatile_arg.hpp (rev 0)
+++ pygccxml_dev/unittests/data/const_volatile_arg.hpp 2009-01-05 22:58:43 UTC (rev 1537)
@@ -0,0 +1,12 @@
+// Copyright 2004-2008 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 __const_volatile_arg_hpp__
+#define __const_volatile_arg_hpp__
+
+void pygccxml_bug(int const volatile* icv);
+
+#endif//__const_volatile_arg_hpp__
+
Modified: pygccxml_dev/unittests/test_all.py
===================================================================
--- pygccxml_dev/unittests/test_all.py 2009-01-05 22:06:06 UTC (rev 1536)
+++ pygccxml_dev/unittests/test_all.py 2009-01-05 22:58:43 UTC (rev 1537)
@@ -54,6 +54,7 @@
import declaration_matcher_tester
import undname_creator_tester
import calling_convention_tester
+import const_volatile_arg_tester
testers = [
decl_string_tester
@@ -104,6 +105,7 @@
, declaration_matcher_tester
, undname_creator_tester
, calling_convention_tester
+ , const_volatile_arg_tester
]
def create_suite():
Modified: pygccxml_dev/unittests/type_traits_tester.py
===================================================================
--- pygccxml_dev/unittests/type_traits_tester.py 2009-01-05 22:06:06 UTC (rev 1536)
+++ pygccxml_dev/unittests/type_traits_tester.py 2009-01-05 22:58:43 UTC (rev 1537)
@@ -12,19 +12,19 @@
from pygccxml import declarations
class tester_t( parser_test_case.parser_test_case_t ):
- COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE
+ COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE
declarations = None
def __init__(self, *args ):
parser_test_case.parser_test_case_t.__init__( self, *args )
self.header = 'type_traits.hpp'
self.declarations = None
-
+
def setUp(self):
if not tester_t.declarations:
tester_t.declarations = parser.parse( [self.header], self.config )
self.declarations = tester_t.declarations
-
- def __test_type_category( self, ns_name, controller ):
+
+ def __test_type_category( self, ns_name, controller ):
ns_control = declarations.find_declaration( self.declarations
, type=declarations.namespace_t
, name=ns_name )
@@ -37,23 +37,26 @@
, type=declarations.namespace_t
, name='no' )
self.failUnless( ns_no, "unable to find 'no' namespace" )
- for decl in ns_yes.declarations:
+ for decl in ns_yes.declarations:
if isinstance( decl, declarations.variable_t ):
self.failUnless( controller( decl.type )
- , 'for type "%s" the answer to the question "%s" should be True'
+ , 'for type "%s" the answer to the question "%s" should be True'
% ( decl.type.decl_string, ns_name ) )
elif isinstance( decl, declarations.calldef_t ) and decl.name.startswith( 'test_' ):
continue
else:
+ #~ if 'mf1_type_const_volatile_t' in decl.name:
+ #~ import pdb
+ #~ pdb.set_trace()
self.failUnless( controller( decl )
- , 'for type "%s" the answer to the question "%s" should be True'
+ , 'for type "%s" the answer to the question "%s" should be True'
% ( decl.decl_string, ns_name ) )
for decl in ns_no.declarations:
if isinstance( decl, declarations.calldef_t ) and decl.name.startswith( 'test_' ):
continue
self.failIf( controller( decl )
- , 'for type "%s" the answer to the question "%s" should be False'
+ , 'for type "%s" the answer to the question "%s" should be False'
% ( decl.decl_string, ns_name ) )
def __test_type_transformation( self, ns_name, transformer ):
@@ -69,8 +72,8 @@
, type=declarations.namespace_t
, name='after' )
self.failUnless( ns_after, "unable to find 'after' namespace" )
-
- for tbefore in ns_before.declarations:
+
+ for tbefore in ns_before.declarations:
tafter = declarations.find_declaration( ns_after, name=tbefore.name )
self.failUnless( tafter, "unable to find transformed type definition for type '%s'" % tbefore.decl_string )
transformed = transformer( tbefore )
@@ -151,14 +154,14 @@
unrelated1 = declarations.find_declaration( ns.declarations
, type=declarations.class_t
, name='unrelated1' )
-
+
unrelated2 = declarations.find_declaration( ns.declarations
, type=declarations.class_t
, name='unrelated2' )
self.failUnless( base and derived and not declarations.is_base_and_derived( unrelated1, unrelated2 ) )
def test_is_same(self):
- self.failUnless( declarations.is_same( declarations.int_t, declarations.int_t ) )
+ self.failUnless( declarations.is_same( declarations.int_t, declarations.int_t ) )
self.failIf( declarations.is_same( declarations.int_t, declarations.float_t ) )
def test_remove_const(self):
@@ -183,21 +186,21 @@
self.failUnless( operator_not, 'operator! was not found' )
self.failUnless( declarations.is_unary_operator( operator_not ), 'operator! should be idenitified as unary operator' )
self.failUnless( not declarations.is_binary_operator( operator_not ), 'operator! should be idenitified as unary operator' )
-
+
operator_class_p = declarations.find_declaration( self.declarations
, type=declarations.operator_t
, fullname='::is_unary_operator::dummy::operator+' )
self.failUnless( operator_class_p, 'operator+ was not found' )
self.failUnless( not declarations.is_unary_operator( operator_class_p ), 'operator+ should be idenitified as binary operator' )
self.failUnless( declarations.is_binary_operator( operator_class_p ), 'operator! should be idenitified as binary operator' )
-
+
operator_class_pp = declarations.find_declaration( self.declarations
, type=declarations.operator_t
, fullname='::is_unary_operator::dummy::operator++' )
self.failUnless( operator_class_pp, 'operator++ was not found' )
self.failUnless( declarations.is_unary_operator( operator_class_pp ), 'operator++ should be idenitified as unary operator' )
self.failUnless( not declarations.is_binary_operator( operator_class_pp ), 'operator++ should be idenitified as unary operator' )
-
+
operator_pp = declarations.find_declaration( self.declarations
, type=declarations.operator_t
, fullname='::is_unary_operator::operator++' )
@@ -229,16 +232,16 @@
expected_value = bool( expected_type.get_name2value_dict()['value'] )
self.failUnless( expected_value == declarations.is_convertible( source_type, target_type )
, 'Check conversion failed for ' + decl.name )
-
+
def test_is_convertible( self ):
ns_is_convertible = declarations.find_declaration( self.declarations
, type=declarations.namespace_t
, name="is_convertible" )
-
+
self.failUnless( ns_is_convertible, "namespace is_convertible was not found" )
for tester in filter( lambda decl: decl.name.startswith( 'x' ), ns_is_convertible.declarations ):
self.__is_convertible_impl( tester )
-
+
class missing_decls_tester_t(unittest.TestCase):
def __init__(self, *args ):
unittest.TestCase.__init__(self, *args)
@@ -249,9 +252,9 @@
ci = global_ns.class_( 'const_item' )
self.failUnless( len( ci.declarations ) == 3 )
#copy constructor, destructor, variable
-
+
def create_suite():
- suite = unittest.TestSuite()
+ suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite(tester_t))
suite.addTest( unittest.makeSuite(missing_decls_tester_t))
return suite
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|