[pygccxml-commit] SF.net SVN: pygccxml: [571] pyplusplus_dev/pyplusplus
Brought to you by:
mbaas,
roman_yakovenko
|
From: <mb...@us...> - 2006-09-21 09:54:49
|
Revision: 571
http://svn.sourceforge.net/pygccxml/?rev=571&view=rev
Author: mbaas
Date: 2006-09-21 02:54:39 -0700 (Thu, 21 Sep 2006)
Log Message:
-----------
1) Renamed gil_state to gil_guard (and moved the class under pyplusplus::threading). 2) The code creator can tell the module creator what header files it requires. As a result, the header file(s) from the code repository (i.e. __gil_guard.pypp.hpp) only gets created when it is really required. 3) Moved the functionality to add/query required headers from the substitution manager to the code manager.
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py
pyplusplus_dev/pyplusplus/function_transformers/code_manager.py
pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py
pyplusplus_dev/pyplusplus/module_creator/creator.py
Modified: pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-09-21 09:51:06 UTC (rev 570)
+++ pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-09-21 09:54:39 UTC (rev 571)
@@ -10,6 +10,7 @@
from pygccxml import declarations
from calldef import calldef_t, calldef_wrapper_t
import pyplusplus.function_transformers as function_transformers
+from pyplusplus import code_repository
######################################################################
@@ -64,6 +65,10 @@
"""
calldef_wrapper_t.__init__( self, function=function )
+ # Create the substitution manager
+ sm = function_transformers.substitution_manager_t(function, transformers=function.function_transformers)
+ self._subst_manager = sm
+
# def is_free_function(self):
# """Return True if the generated function is a free function.
#
@@ -151,10 +156,6 @@
return os.linesep.join( answer )
def _create_impl(self):
- # Create the substitution manager
- decl = self.declaration
- sm = function_transformers.substitution_manager_t(decl, transformers=decl.function_transformers)
- self._subst_manager = sm
answer = self.create_function()
@@ -226,12 +227,17 @@
@type function: calldef_t
"""
calldef_wrapper_t.__init__( self, function=function )
-
+
+ # Create the substitution manager
+ sm = function_transformers.substitution_manager_t(function, transformers=function.function_transformers)
+ self._subst_manager = sm
+
# Stores the name of the variable that holds the override
- self._override_var = None
+ self._override_var = sm.virtual_func.allocate_local(function.alias+"_callable")
# Stores the name of the 'gstate' variable
- self._gstate_var = None
+ self._gstate_var = sm.virtual_func.allocate_local("gstate")
+
def default_name(self):
"""Return the name of the 'default' function.
@@ -323,7 +329,7 @@
if thread_safe:
body = """
-pyplusplus::gil_state_t %(gstate_var)s;
+pyplusplus::threading::gil_state_t %(gstate_var)s;
%(gstate_var)s.ensure();
boost::python::override %(override_var)s = this->get_override( "%(alias)s" );
@@ -478,15 +484,15 @@
answer.append( self.indent( self.create_default_body() ) )
answer.append( '}' )
return os.linesep.join( answer )
-
+ def get_required_headers(self):
+ """Return a list of required header file names."""
+ res = [code_repository.gil_guard.file_name]
+ res += self._subst_manager.virtual_func.get_required_headers()
+ res += self._subst_manager.wrapper_func.get_required_headers()
+ return res
+
def _create_impl(self):
- # Create the substitution manager
- decl = self.declaration
- sm = function_transformers.substitution_manager_t(decl, transformers=decl.function_transformers)
- self._override_var = sm.virtual_func.allocate_local(decl.alias+"_callable")
- self._gstate_var = sm.virtual_func.allocate_local("gstate")
- self._subst_manager = sm
answer = [ self.create_function() ]
answer.append( os.linesep )
Modified: pyplusplus_dev/pyplusplus/function_transformers/code_manager.py
===================================================================
--- pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-09-21 09:51:06 UTC (rev 570)
+++ pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-09-21 09:54:39 UTC (rev 571)
@@ -94,6 +94,39 @@
# A list with variable tuples: (name, type, size, default)
self._local_var_list = []
+ # Required header file names
+ self._required_headers = []
+
+ # require_header
+ def require_header(self, include):
+ """Declare an include file that is required for the code to compile.
+
+ include is the name of the include file which may contain <> or ""
+ characters around the name (which are currently ignored).
+ If an include file is declared twice it will only be added once.
+
+ @param include: The name of the include file (may contain <> or "")
+ @type include: str
+ """
+ if include=="":
+ return
+
+ # Add apostrophes if there aren't any already
+ if include[0] in '"<':
+ include = include[1:-1]
+
+ if include not in self._required_headers:
+ self._required_headers.append(include)
+
+ # get_required_headers
+ def get_required_headers(self, where=None):
+ """Return a list of include files required for the function.
+
+ @return: A list of include file names
+ @rtype: list of str
+ """
+ return self._required_headers
+
# declare_local
def declare_local(self, name, type, size=None, default=None):
"""Declare a local variable and return its final name.
Modified: pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py
===================================================================
--- pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-09-21 09:51:06 UTC (rev 570)
+++ pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-09-21 09:54:39 UTC (rev 571)
@@ -160,8 +160,8 @@
@ivar virtual_func: The L{code manager<code_manager_t>} object that manages the virtual function. This is used by the arg policies to modify the virtual function.
@type virtual_func: L{code_manager_t}
- @group Methods called by the user of the class: append_code_block, subst_wrapper, subst_virtual, get_includes
- @group Methods called by the function transformers: remove_arg, insert_arg, py_result_expr, require_include
+ @group Methods called by the user of the class: append_code_block, subst_wrapper, subst_virtual
+ @group Methods called by the function transformers: remove_arg, insert_arg, py_result_expr
@author: Matthias Baas
"""
@@ -466,66 +466,6 @@
else:
return "%s[%d]"%(pyresult, idx)
- # require_include
- def require_include(self, include, where=None):
- """Declare an include file that is required for the code to compile.
-
- This function is supposed to be called by function transformer
- objects to tell the substitution manager that they create code
- that requires a particular header file.
-
- include is the name of the include file which may contain <> or ""
- characters around the name.
-
- @param include: The name of the include file (may contain <> or "")
- @type include: str
- @param where: "wrapper", "virtual" or None (for both)
- @type where: str
- """
- if where not in ["wrapper", "virtual", None]:
- raise ValueError, "Invalid 'where' argument: %s"%where
-
- if include=="":
- return
-
- # Add apostrophes if there aren't any already
- if include[0] not in '"<':
- include = '"%s"'%include
-
- if where=="wrapper" or where==None:
- if include not in self._wrapper_includes:
- self._wrapper_includes.append(include)
-
- if where=="virtual" or where==None:
- if include not in self._virtual_includes:
- self._virtual_includes.append(include)
-
- # get_includes
- def get_includes(self, where=None):
- """Return a list of include files required for the wrapper and/or the virtual function.
-
- @param where: "wrapper", "virtual" or None (for a combined list)
- @type where: str
- @return: A list of include file names (all names contain <> or "")
- @rtype: list of str
- """
- if where not in ["wrapper", "virtual", None]:
- raise ValueError, "Invalid 'where' argument: %s"%where
-
- if where=="wrapper":
- return self._wrapper_includes[:]
-
- if where=="virtual":
- return self._virtual_includes[:]
-
- # Merge both lists (without duplicating names)
- res = self._virtual_includes[:]
- for inc in self._wrapper_includes:
- if inc not in res:
- res.append(inc)
-
- return res
-
# subst_virtual
def subst_virtual(self, template):
"""Perform a text substitution using the "virtual" variable set.
Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-09-21 09:51:06 UTC (rev 570)
+++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-09-21 09:54:39 UTC (rev 571)
@@ -554,23 +554,30 @@
# Are we dealing with transformed non-virtual member functions?
if maker_cls==code_creators.mem_fun_transformed_t:
# Create the code creator that generates the function source code
- mftw = code_creators.mem_fun_transformed_wrapper_t(self.curr_decl)
+ fwrapper = code_creators.mem_fun_transformed_wrapper_t(self.curr_decl)
# and add it either to the wrapper class or just to the declaration
# area of the cpp file
if self.curr_code_creator.wrapper is None:
- self.curr_code_creator.associated_decl_creators.append(mftw)
+ self.curr_code_creator.associated_decl_creators.append(fwrapper)
else:
- self.curr_code_creator.wrapper.adopt_creator(mftw)
+ self.curr_code_creator.wrapper.adopt_creator(fwrapper)
# Set the wrapper so that the registration code will refer to it
- maker.wrapper = mftw
+ maker.wrapper = fwrapper
- # Include the gil_state header from the code repository.
- if not self.__extmodule.is_system_header(code_repository.gil_state.file_name):
- self.__extmodule.add_system_header( code_repository.gil_state.file_name )
- self.__extmodule.adopt_creator( code_creators.include_t( code_repository.gil_state.file_name )
- , self.__extmodule.first_include_index() + 1)
+ # Make sure all required headers are included...
+ required_headers = getattr(fwrapper, "get_required_headers", lambda : [])()
+ for header in required_headers:
+ # Check whether the header is already included
+ included = filter(lambda cc: isinstance(cc, code_creators.include_t) and cc.header==header, self.__extmodule.creators)
+ if not included:
+ self.__extmodule.add_include( header )
+ # Check if it is a header from the code repository
+ if header in map(lambda mod: mod.file_name, code_repository.all):
+ # Make Py++ write the header
+ self.__extmodule.add_system_header( header )
+
if self.curr_decl.has_static:
#static_method should be created only once.
found = filter( lambda creator: isinstance( creator, code_creators.static_method_t )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|