[pygccxml-commit] SF.net SVN: pygccxml: [1132] pygccxml_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2007-11-10 22:30:12
|
Revision: 1132
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1132&view=rev
Author: roman_yakovenko
Date: 2007-11-10 14:29:29 -0800 (Sat, 10 Nov 2007)
Log Message:
-----------
adding is_trivial_constructor functionality
Modified Paths:
--------------
pygccxml_dev/pygccxml/declarations/calldef.py
pygccxml_dev/pygccxml/declarations/type_traits.py
pygccxml_dev/unittests/autoconfig.py
pygccxml_dev/unittests/data/core_cache.hpp
pygccxml_dev/unittests/data/type_traits.hpp
Modified: pygccxml_dev/pygccxml/declarations/calldef.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/calldef.py 2007-11-08 23:28:48 UTC (rev 1131)
+++ pygccxml_dev/pygccxml/declarations/calldef.py 2007-11-10 22:29:29 UTC (rev 1132)
@@ -469,7 +469,9 @@
cls = 'copy ' + cls
return "%s [%s]"%(res, cls)
- def _get_is_copy_constructor(self):
+ @property
+ def is_copy_constructor(self):
+ """returns True if described declaration is copy constructor, otherwise False"""
args = self.arguments
if 1 != len( args ):
return False
@@ -483,8 +485,11 @@
if not isinstance( unaliased.base, cpptypes.declarated_t ):
return False
return id(unaliased.base.declaration) == id(self.parent)
- is_copy_constructor = property(_get_is_copy_constructor
- , doc="returns True if described declaration is copy constructor, otherwise False")
+
+ @property
+ def is_trivial_constructor(self):
+ return not bool( self.arguments )
+
class destructor_t( member_calldef_t ):
"""describes deconstructor declaration"""
Modified: pygccxml_dev/pygccxml/declarations/type_traits.py
===================================================================
--- pygccxml_dev/pygccxml/declarations/type_traits.py 2007-11-08 23:28:48 UTC (rev 1131)
+++ pygccxml_dev/pygccxml/declarations/type_traits.py 2007-11-10 22:29:29 UTC (rev 1132)
@@ -344,22 +344,79 @@
def find_trivial_constructor( type ):
"""returns reference to trivial constructor or None"""
assert isinstance( type, class_declaration.class_t )
- constructors = filter( lambda x: isinstance( x, calldef.constructor_t ) \
- and 0 == len( x.arguments ) \
- , type.public_members )
- if constructors:
- return constructors[0]
+ trivial = type.constructors( lambda x: x.is_trivial_constructor and x.access_type == 'public'
+ , recursive=False
+ , allow_empty=True )
+ if trivial:
+ return trivial[0]
else:
return None
def has_trivial_constructor( type ):
- """returns True, if class has trivial constructor, False otherwise"""
- return None != find_trivial_constructor( type )
+ """returns True, if class has public trivial constructor, False otherwise"""
+ if '0.9' in type.compiler:
+ trivial = type.constructors( lambda x: x.is_trivial_constructor
+ , recursive=False
+ , allow_empty=True )
+ if trivial:
+ if trivial[0].access_type == 'public':
+ return True
+ else:
+ return False
+ else:
+ #there is no trivial constructor, so I should find out whether other constructors exist
+ if type.constructors( recursive=False, allow_empty=True ):
+ return False
+ else:
+ return True
+ else:
+ if None != find_trivial_constructor( type ):
+ return True
+ return False
+"""
+Question: Do I have to define a copy constructor and assignment operator?
+
+Answer:
+ C++ implicitly declares a copy constructor and an assignment operator
+ for every class, struct and union unless the user declared them explicitly.
+ A copy constructor isnot implicitly declared if the class has any user-declared
+ constructor(s). Implicitly defined copy constructor and assignment operator
+ are said to be trivial if:
+
+ * their class has no virtual functions and no virtual base class(es)
+ * all direct base classes and nonstatic data members of their class have trivial constructors
+
+ Otherwise, the copy constructor and the assignment operator are non-trivial.
+ Implicitly-declared non-trivial copy constructor and assignment operator are
+ implicitly-defined.
+
+The assignment operator is called "copy assignment operator" in the standard.
+This verbosity doesnot convey any new or hidden meanings. Perhaps it's meant to
+differentiate between the assignment operator of fundamental types and the
+assignment operator member function of class types. In this series I will stick
+to the term assignment operator.
+"""
+
def has_trivial_copy( type):
- """returns True, if class has copy constructor, False otherwise"""
+ """returns True, if class has public copy constructor, False otherwise"""
assert isinstance( type, class_declaration.class_t )
- constructors = filter( lambda x: isinstance( x, calldef.constructor_t ) \
+ if '0.9' in type.compiler:
+ copy_ = type.constructors( lambda x: x.is_copy_constructor
+ , recursive=False
+ , allow_empty=True )
+ if copy_:
+ if copy_[0].access_type == 'public':
+ return True
+ else:
+ return False
+ else:
+ if type.constructors( recursive=False, allow_empty=True ):
+ return False
+ else:
+ return True
+ else:
+ constructors = filter( lambda x: isinstance( x, calldef.constructor_t ) \
and x.is_copy_constructor
, type.public_members )
return bool( constructors )
@@ -378,7 +435,7 @@
, type=calldef.constructor_t
, recursive=False )
constructors = filter( lambda decl: not decl.is_copy_constructor, decls )
- return bool( constructors )
+ return bool( constructors ) or has_trivial_constructor( type )
def has_public_assign(type):
"""returns True, if class has public assign operator, False otherwise"""
@@ -396,7 +453,6 @@
, type=calldef.destructor_t
, recursive=False ) )
-
def is_base_and_derived( based, derived ):
"""returns True, if there is "base and derived" relationship between classes, False otherwise"""
assert isinstance( based, class_declaration.class_t )
@@ -420,7 +476,7 @@
constructors = filter( lambda x: isinstance( x, calldef.constructor_t ) \
and not x.is_copy_constructor
, type.public_members )
- return bool( constructors )
+ return bool( constructors ) or has_trivial_constructor( type )
def has_public_binary_operator( type, operator_symbol ):
"""returns True, if type has public binary operator, otherwise False"""
@@ -860,6 +916,20 @@
if class_.is_abstract:
return True
+ #~ if '0.9' in class_.compiler:
+ #~ #class will be mark as noncopyable if it has private operator assign and
+ #~ #copy constructor
+ #~ #select all non-public members that are copy constructor and operator assign
+ #~ is_noncopyable_query = \
+ #~ matchers.not_matcher_t( matchers.access_type_matcher_t( 'public' ) )\
+ #~ & \
+ #~ ( matchers.custom_matcher_t( lambda decl: isinstance( decl, calldef.constructor_t ) \
+ #~ and decl.is_copy_constructor )
+ #~ | matchers.operator_matcher_t( symbol='=' ) )
+ #~ result = class_.decls( is_noncopyable_query, recursive=False, allow_empty=True )
+ #~ if result:
+ #~ return True
+ #~ else:
elif not has_trivial_copy( class_ ):
return True
elif not has_public_constructor( class_ ):
Modified: pygccxml_dev/unittests/autoconfig.py
===================================================================
--- pygccxml_dev/unittests/autoconfig.py 2007-11-08 23:28:48 UTC (rev 1131)
+++ pygccxml_dev/unittests/autoconfig.py 2007-11-10 22:29:29 UTC (rev 1132)
@@ -20,8 +20,13 @@
gccxml_09_path = os.path.join( this_module_dir_path, '..', '..', 'gccxml_bin', 'v09', sys.platform, 'bin' )
gccxml_path = gccxml_09_path
-gccxml_version = '__GCCXML_09__'
+gccxml_version = '__GCCXML_07__'
+if '09' in gccxml_path:
+ gccxml_version = '__GCCXML_09__'
+
+print 'compiler: ', gccxml_version
+
if sys.platform == 'win32':
compiler = 'msvc71'
Modified: pygccxml_dev/unittests/data/core_cache.hpp
===================================================================
--- pygccxml_dev/unittests/data/core_cache.hpp 2007-11-08 23:28:48 UTC (rev 1131)
+++ pygccxml_dev/unittests/data/core_cache.hpp 2007-11-10 22:29:29 UTC (rev 1132)
@@ -22,4 +22,4 @@
#endif//__core_cache_hpp__
-//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch
\ No newline at end of file
+//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch//touch
\ No newline at end of file
Modified: pygccxml_dev/unittests/data/type_traits.hpp
===================================================================
--- pygccxml_dev/unittests/data/type_traits.hpp 2007-11-08 23:28:48 UTC (rev 1131)
+++ pygccxml_dev/unittests/data/type_traits.hpp 2007-11-10 22:29:29 UTC (rev 1132)
@@ -79,17 +79,11 @@
}
namespace yes{
- typedef detail::x x;
-#ifdef __GCCXML_09__
- typedef detail::y_type y_type;
-#endif//__GCCXML_09__
-
+ typedef detail::x x;
}
namespace no{
typedef std::string string_type;
-#ifdef __GCCXML_07__
typedef detail::y_type y_type;
-#endif//__GCCXML_07__
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|