Revision: 562
http://svn.sourceforge.net/pygccxml/?rev=562&view=rev
Author: mbaas
Date: 2006-09-20 09:46:04 -0700 (Wed, 20 Sep 2006)
Log Message:
-----------
Added a new method code_manager_t.allocate_local() and two new variables CLEANUP and EXCEPTION_HANDLER_EXIT.
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/function_transformers/code_manager.py
pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py
Modified: pyplusplus_dev/pyplusplus/function_transformers/code_manager.py
===================================================================
--- pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-09-20 07:43:39 UTC (rev 561)
+++ pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-09-20 16:46:04 UTC (rev 562)
@@ -44,6 +44,8 @@
@type result_type: str
@ivar result_expr: A string containing the expression that will be put after the "return" statement. This expression is used for the variable RETURN_STMT.
@type result_expr: str
+ @ivar exception_handler_exit: The C++ code that is executed at the end of the main exception handler (default: "throw;").
+ @type exception_handler_exit: str
@author: Matthias Baas
"""
@@ -53,7 +55,8 @@
"""
subst_t.__init__(self, blockvars=["DECLARATIONS",
"PRE_CALL",
- "POST_CALL"])
+ "POST_CALL",
+ "EXCEPTION_HANDLER_EXIT"])
# The name of the class of which the generated function is a member
# (pass None or an empty string if the function is a free function)
@@ -80,6 +83,12 @@
# the "return" statement.
self.result_expr = None
+ # The C++ code that is executed at the end of the main
+ # exception handler.
+ self.exception_handler_exit = "throw;"
+
+ # Key:Variable name / Value:1
+ self._allocated_vars = {}
# Key:Variable name / Value:(type,size,default)
self._declared_vars = {}
# A list with variable tuples: (name, type, size, default)
@@ -100,11 +109,30 @@
@return: The assigned variable name (which is guaranteed to be unique)
@rtype: str
"""
- name = self._make_name_unique(name)
+ name = self.allocate_local(name)
self._declared_vars[name] = (type,size,default)
self._local_var_list.append((name, type, size, default))
return name
+ # allocate_local
+ def allocate_local(self, name):
+ """Allocate a local variable name and return the final name.
+
+ Allocate a variable name that is unique to the entire
+ function. The variable will not appear in the DECLARATIONS
+ block. Instead, the caller has to generate the declaration
+ code himself at an appropriate place.
+
+ @param name: The desired variable name
+ @type name: str
+ @return: The assigned variable name (which is guaranteed to be unique)
+ @rtype: str
+ """
+ name = self._make_name_unique(name)
+ self._allocated_vars[name] = 1
+ return name
+
+ # is_defined
def is_defined(self, name):
"""Check if a variable name is already in use.
@@ -113,7 +141,7 @@
@rtype: bool
"""
- if name in self._declared_vars:
+ if name in self._allocated_vars:
return True
if filter(lambda a: a.name==name, self.arg_list):
return True
@@ -127,6 +155,8 @@
@return: Returns the type of the specified local variable.
@rtype: str
"""
+ if name in self._allocated_vars:
+ raise ValueError, 'The type of local variable "%s" is unknown.'%name
if name not in self._declared_vars:
raise ValueError, 'Local variable "%s" not found.'%name
@@ -202,6 +232,12 @@
else:
self.RETURN_STMT = ""
+ # EXCEPTION_HANDLER_EXIT
+ if self.exception_handler_exit!=None:
+ self.EXCEPTION_HANDLER_EXIT = self.exception_handler_exit
+ else:
+ self.EXCEPTION_HANDLER_EXIT = ""
+
# _make_name_unique
def _make_name_unique(self, name):
"""Make a variable name unique so that there's no clash with other names.
Modified: pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py
===================================================================
--- pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-09-20 07:43:39 UTC (rev 561)
+++ pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-09-20 16:46:04 UTC (rev 562)
@@ -148,7 +148,11 @@
| [} catch(...) {...}] |
+--------------------------+
+ - CLEANUP: The cleanup code blocks of all function transformers.
+
- RETURN_STMT: "return <varname>" or "return boost::python::make_tuple(...)"
+
+ - EXCEPTION_HANDLER_EXIT: The C++ code that is executed at the end of the main exception handler (default: "throw;")
@ivar wrapper_func: The L{code manager<code_manager_t>} object that manages the wrapper function. This is used by the arg policies to modify the wrapper function.
@@ -297,6 +301,12 @@
postcall = "\n\n".join(src)
self.wrapper_func.POST_CALL = postcall
+ # Create the wrapper function cleanup block...
+ src = map(lambda cb: getattr(cb, "wrapper_cleanup", defmeth)(self), transformers)
+ src = filter(lambda x: x!=None, src)
+ cleanup = "\n\n".join(src)
+ self.wrapper_func.CLEANUP = cleanup
+
# Create the virtual function pre-call block...
src = map(lambda cb: getattr(cb, "virtual_pre_call", defmeth)(self), transformers)
src = filter(lambda x: x!=None, src)
@@ -309,8 +319,14 @@
src.reverse()
postcall = "\n\n".join(src)
self.virtual_func.POST_CALL = postcall
-
+ # Create the virtual function cleanup block...
+ src = map(lambda cb: getattr(cb, "virtual_cleanup", defmeth)(self), transformers)
+ src = filter(lambda x: x!=None, src)
+ cleanup = "\n\n".join(src)
+ self.virtual_func.CLEANUP = cleanup
+
+
# remove_arg
def remove_arg(self, idx):
"""Remove an argument from the wrapper function.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|