[pygccxml-commit] SF.net SVN: pygccxml: [858] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2007-01-08 07:23:21
|
Revision: 858
http://svn.sourceforge.net/pygccxml/?rev=858&view=rev
Author: roman_yakovenko
Date: 2007-01-07 23:23:19 -0800 (Sun, 07 Jan 2007)
Log Message:
-----------
adding non overridable tester
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_creators/calldef.py
pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py
pyplusplus_dev/pyplusplus/messages/warnings_.py
pyplusplus_dev/unittests/test_all.py
Added Paths:
-----------
pyplusplus_dev/unittests/data/non_overridable_to_be_exported.cpp
pyplusplus_dev/unittests/data/non_overridable_to_be_exported.hpp
pyplusplus_dev/unittests/non_overridable_tester.py
Modified: pyplusplus_dev/pyplusplus/code_creators/calldef.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/calldef.py 2007-01-07 14:32:46 UTC (rev 857)
+++ pyplusplus_dev/pyplusplus/code_creators/calldef.py 2007-01-08 07:23:19 UTC (rev 858)
@@ -153,9 +153,7 @@
return algorithm.create_identifier( self, declarations.full_name( self.declaration.parent ) )
def unoverriden_function_body( self ):
- msg = r'This function could not be overriden in Python!'
- msg = msg + 'Reason: function returns reference to local variable!'
- return 'throw std::logic_error("%s");' % msg
+ return 'throw std::logic_error("%s");' % self.declaration.non_overridable_reason
def throw_specifier_code( self ):
if self.declaration.does_throw:
@@ -256,7 +254,7 @@
}
def create_body( self ):
- if declarations.is_reference( self.declaration.return_type ):
+ if not self.declaration.overridable:
return self.unoverriden_function_body()
template = []
template.append( '%(override)s func_%(alias)s = this->get_override( "%(alias)s" );' )
@@ -665,7 +663,7 @@
}
def create_body( self ):
- if declarations.is_reference( self.declaration.return_type ):
+ if not self.declaration.overridable:
return self.unoverriden_function_body()
template = []
@@ -720,7 +718,7 @@
}
def create_body( self ):
- if declarations.is_reference( self.declaration.return_type ):
+ if not self.declaration.overridable:
return self.unoverriden_function_body()
template = []
Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py
===================================================================
--- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2007-01-07 14:32:46 UTC (rev 857)
+++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2007-01-08 07:23:19 UTC (rev 858)
@@ -33,6 +33,7 @@
self._use_default_arguments = True
self._create_with_signature = False
self._overridable = None
+ self._non_overridable_reason = None
self._transformations = None
def get_call_policies(self):
@@ -90,7 +91,7 @@
and self.virtuality != declarations.VIRTUALITY_TYPES.NOT_VIRTUAL \
and declarations.is_reference( self.return_type ):
self._overridable = False
- self._non_overridable_reason = messages.W1003
+ self._non_overridable_reason = messages.W1049
else:
self._overridable = True
self._non_overridable_reason = ""
@@ -98,10 +99,18 @@
def set_overridable( self, overridable ):
self._overridable = overridable
-
+
overridable = property( get_overridable, set_overridable
, doc = get_overridable.__doc__ )
+ @property
+ def non_overridable_reason( self ):
+ return self._non_overridable_reason
+
+ def mark_as_non_overridable( self, reason ):
+ self.overridable = False
+ self._non_overridable_reason = reason
+
@property
def transformations(self):
"""Get method for property 'function_transformers'.
Modified: pyplusplus_dev/pyplusplus/messages/warnings_.py
===================================================================
--- pyplusplus_dev/pyplusplus/messages/warnings_.py 2007-01-07 14:32:46 UTC (rev 857)
+++ pyplusplus_dev/pyplusplus/messages/warnings_.py 2007-01-08 07:23:19 UTC (rev 858)
@@ -145,7 +145,10 @@
W1048 = 'There are two or more aliases within "pyplusplus::aliases" namespace for ' \
'the class. In order to enjoy from automatic aliasing, the class alias ' \
'should be unique. Other aliases: %s'
-
+
+W1049 = 'This method could not be overriden in Python - method returns reference ' \
+ 'to local variable!'
+
warnings = globals()
for identifier, explanation in warnings.items():
Added: pyplusplus_dev/unittests/data/non_overridable_to_be_exported.cpp
===================================================================
--- pyplusplus_dev/unittests/data/non_overridable_to_be_exported.cpp (rev 0)
+++ pyplusplus_dev/unittests/data/non_overridable_to_be_exported.cpp 2007-01-08 07:23:19 UTC (rev 858)
@@ -0,0 +1,13 @@
+// Copyright 2004 Roman Yakovenko.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "non_overridable_to_be_exported.hpp"
+
+namespace non_overridable{
+
+
+}//non_overridable
+
+
Added: pyplusplus_dev/unittests/data/non_overridable_to_be_exported.hpp
===================================================================
--- pyplusplus_dev/unittests/data/non_overridable_to_be_exported.hpp (rev 0)
+++ pyplusplus_dev/unittests/data/non_overridable_to_be_exported.hpp 2007-01-08 07:23:19 UTC (rev 858)
@@ -0,0 +1,47 @@
+// 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 __non_overridable_to_be_exported_hpp__
+#define __non_overridable_to_be_exported_hpp__
+#include <string>
+
+namespace non_overridables{
+
+struct non_overridable_v_t{
+
+
+ static bool test( const non_overridable_v_t& impl ){
+ return impl.void_ptr() ? true : false;
+ }
+
+
+ virtual const void* void_ptr() const {
+ return this;
+ }
+
+ virtual std::string& string_ref() const {
+ static std::string x( "string_ref" );
+ return x;
+ }
+
+};
+
+struct non_overridable_pv_t{
+
+ static bool test( const non_overridable_pv_t& impl ){
+ return impl.void_ptr() ? true : false;
+ }
+
+ virtual void* void_ptr() const = 0;
+
+ virtual std::string& string_ref() const = 0;
+
+};
+
+
+
+}
+
+#endif//__non_overridable_to_be_exported_hpp__
Added: pyplusplus_dev/unittests/non_overridable_tester.py
===================================================================
--- pyplusplus_dev/unittests/non_overridable_tester.py (rev 0)
+++ pyplusplus_dev/unittests/non_overridable_tester.py 2007-01-08 07:23:19 UTC (rev 858)
@@ -0,0 +1,63 @@
+# 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 ctypes
+import unittest
+import fundamental_tester_base
+from pyplusplus.module_builder import call_policies
+
+class tester_t(fundamental_tester_base.fundamental_tester_base_t):
+ EXTENSION_NAME = 'non_overridable'
+
+ def __init__( self, *args ):
+ fundamental_tester_base.fundamental_tester_base_t.__init__(
+ self
+ , tester_t.EXTENSION_NAME
+ , *args )
+
+ def customize( self, mb ):
+ mb.mem_funs( 'string_ref' ).call_policies \
+ = call_policies.return_value_policy( call_policies.copy_non_const_reference )
+
+ non_overridable_pv_t = mb.class_( 'non_overridable_pv_t' )
+ non_overridable_pv_t.mem_fun( 'void_ptr' ).mark_as_non_overridable( reason='xxx void*' )
+
+ def create_pv_derived(self, module):
+ class py_pv_t( module.non_overridable_pv_t ):
+ def __init__( self ):
+ module.non_overridable_pv_t.__init__( self )
+
+ def void_ptr( self ):
+ return ctypes.c_void_p( id(self) )
+ return py_pv_t()
+
+ def create_v_derived(self, module):
+ class py_v_t( module.non_overridable_v_t ):
+ def __init__( self ):
+ module.non_overridable_v_t.__init__( self )
+
+ def void_ptr( self ):
+ return ctypes.c_void_p( id(self) )
+ return py_v_t()
+
+ def run_tests( self, module):
+ x = self.create_pv_derived(module)
+ self.failUnlessRaises( RuntimeError, module.non_overridable_pv_t.test, x )
+
+ y = self.create_v_derived(module)
+ self.failUnlessRaises( ReferenceError, module.non_overridable_v_t.test, y )
+
+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: pyplusplus_dev/unittests/test_all.py
===================================================================
--- pyplusplus_dev/unittests/test_all.py 2007-01-07 14:32:46 UTC (rev 857)
+++ pyplusplus_dev/unittests/test_all.py 2007-01-08 07:23:19 UTC (rev 858)
@@ -70,6 +70,7 @@
import function_transformations_tester
import throw_tester
import duplicate_aliases_tester
+import non_overridable_tester
def create_suite(times):
testers = [
@@ -136,6 +137,7 @@
, function_transformations_tester
, throw_tester
, duplicate_aliases_tester
+ , non_overridable_tester
]
main_suite = unittest.TestSuite()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|