[pygccxml-commit] SF.net SVN: pygccxml: [707] pyplusplus_dev/pyplusplus
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-11-13 19:55:51
|
Revision: 707 http://svn.sourceforge.net/pygccxml/?rev=707&view=rev Author: roman_yakovenko Date: 2006-11-11 10:12:58 -0800 (Sat, 11 Nov 2006) Log Message: ----------- code_manager_t clean up Modified Paths: -------------- pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py pyplusplus_dev/pyplusplus/code_repository/gil_guard.py pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py pyplusplus_dev/pyplusplus/function_transformers/code_manager.py pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py pyplusplus_dev/pyplusplus/function_transformers/transformers.py Modified: pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py =================================================================== --- pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-11-11 07:14:29 UTC (rev 706) +++ pyplusplus_dev/pyplusplus/code_creators/calldef_transformed.py 2006-11-11 18:12:58 UTC (rev 707) @@ -247,11 +247,12 @@ self._subst_manager = sm # Stores the name of the variable that holds the override - self._override_var = sm.virtual_func.allocate_local(function.alias+"_callable") + self._override_var \ + = sm.virtual_func.declare_variable(function.alias + "_callable", 'boost::python::override') # Stores the name of the 'gstate' variable - self._gstate_var = sm.virtual_func.allocate_local("gstate") + self._gstate_var \ + = sm.virtual_func.declare_variable("gstate", 'pyplusplus::threading ::gil_guard_t' ) - def default_name(self): """Return the name of the 'default' function. @@ -339,7 +340,7 @@ def create_virtual_body(self): - thread_safe = getattr(self.declaration, "thread_safe", False) + thread_safe = self.declaration.transformations[0].thread_safe if thread_safe: body = """ @@ -415,25 +416,16 @@ # Replace the $-variables body = self._subst_manager.subst_virtual(body) -# template = [] -# template.append( 'if( %(override)s func_%(alias)s = this->get_override( "%(alias)s" ) )' ) -# template.append( self.indent('%(return_)sfunc_%(alias)s( %(args)s );') ) -# template.append( 'else' ) -# template.append( self.indent('%(return_)s%(wrapped_class)s::%(name)s( %(args)s );') ) -# template = os.linesep.join( template ) - return body % { -# 'override' : self.override_identifier() 'override_var' : self._override_var , 'gstate_var' : self._gstate_var , 'alias' : self.declaration.alias -# , 'func_var' : "func_"+self.declaration.alias , 'inherited' : self.create_base_body() } def create_default_body(self): cls_wrapper_type = self.parent.full_name - cls_wrapper = self._subst_manager.wrapper_func.declare_local("cls_wrapper", cls_wrapper_type); + cls_wrapper = self._subst_manager.wrapper_func.declare_variable("cls_wrapper", cls_wrapper_type); # The name of the 'self' variable (i.e. first argument) selfname = self._subst_manager.wrapper_func.arg_list[0].name Modified: pyplusplus_dev/pyplusplus/code_repository/gil_guard.py =================================================================== --- pyplusplus_dev/pyplusplus/code_repository/gil_guard.py 2006-11-11 07:14:29 UTC (rev 706) +++ pyplusplus_dev/pyplusplus/code_repository/gil_guard.py 2006-11-11 18:12:58 UTC (rev 707) @@ -59,4 +59,4 @@ #endif//__gil_guard_pyplusplus_hpp__ -""" +""" \ No newline at end of file Modified: pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-11-11 07:14:29 UTC (rev 706) +++ pyplusplus_dev/pyplusplus/decl_wrappers/calldef_wrapper.py 2006-11-11 18:12:58 UTC (rev 707) @@ -118,12 +118,12 @@ self._transformations = [] return self._transformations - def add_transformation(self, *args): + def add_transformation(self, *args, **keywd): """Set method for property 'function_transformers'. args is a list of transformers """ - self.transformations.append( ft.function_transformation_t( args ) ) + self.transformations.append( ft.function_transformation_t( args, **keywd ) ) def _exportable_impl_derived( self ): return '' Modified: pyplusplus_dev/pyplusplus/function_transformers/code_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-11-11 07:14:29 UTC (rev 706) +++ pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-11-11 18:12:58 UTC (rev 707) @@ -19,7 +19,7 @@ manipulate a function and stores the actual substitution variables. Each function has its own code manager instance. - A code block can declare a local variable using L{declare_local()} + A code block can declare a local variable using L{declare_variable()} and it can manipulate one of the attributes that are used to initialize the final variables (see the documentation of the instance variables below). The final variables (such as RET_TYPE, @@ -81,22 +81,15 @@ # 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) - self._local_var_list = [] - # Required header file names - self._required_headers = [] - def substitute( self, template_code ): tmpl = string.Template(template_code) return tmpl.safe_substitute(self.__dict__) - # declare_local - def declare_local(self, name, type, size=None, default=None): + # declare_variable + def declare_variable(self, name, type, size=None, default=None): """Declare a local variable and return its final name. @param name: The desired variable name @@ -110,64 +103,10 @@ @return: The assigned variable name (which is guaranteed to be unique) @rtype: str """ - name = self.allocate_local(name) + name = self._make_name_unique(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. - - The method returns True if name is the name of an argument or of - a local variable. - - @rtype: bool - """ - if name in self._allocated_vars: - return True - if filter(lambda a: a.name==name, self.arg_list): - return True - return False - - def local_type_str(self, name): - """Return the type of a local variable. - - An exception is raised if a variable called name does not exist. - - @return: Returns the type of the specified local variable. - @rtype: str - """ - if name not 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 - - type,size,default = self._declared_vars[name] - - if size==None: - return type - else: - return "*%s"%type - def init_variables(self): """Initialize the substitution variables. @@ -202,7 +141,8 @@ # Create the declaration block -> DECLARATIONS vardecls = [] - for varname,type,size,default in self._local_var_list: + for varname in self._declared_vars.keys(): + type,size,default = self._declared_vars[ varname ] if default==None: vd = "%s %s"%(type, varname) else: @@ -249,17 +189,14 @@ @return: A unique name based on the input name @rtype: str """ - if not self.is_defined(name): - return name - n = 2 + newname = name while 1: - newname = "%s_%d"%(name, n) - if not self.is_defined(newname): + if not self._declared_vars.has_key( newname ): return newname + newname = "%s_%d"%(name, n) n += 1 - # wrapper_code_manager_t class wrapper_code_manager_t(code_manager_t): """The CodeManager class for the wrapper function. Modified: pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py 2006-11-11 07:14:29 UTC (rev 706) +++ pyplusplus_dev/pyplusplus/function_transformers/function_transformation.py 2006-11-11 18:12:58 UTC (rev 707) @@ -9,11 +9,12 @@ class function_transformation_t: - def __init__(self, transformers): + def __init__(self, transformers, **keywd): """Constructor. """ self.__transformers = list(transformers) - + self.__thread_safe = keywd.get( 'thread_safe', False ) + @property def transformers( self ): return self.__transformers @@ -23,3 +24,7 @@ map( lambda transformer: headers.extend( transformer.required_headers() ) , self.transformers ) return headers + + @property + def thread_safe( self ): + return self.__thread_safe \ No newline at end of file Modified: pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-11-11 07:14:29 UTC (rev 706) +++ pyplusplus_dev/pyplusplus/function_transformers/substitution_manager.py 2006-11-11 18:12:58 UTC (rev 707) @@ -217,10 +217,8 @@ ret_type = None else: ret_type = decl.return_type -# self.wrapper_func.result_type = str(ret_type) self.wrapper_func.result_type = str(declarations.type_traits.remove_reference(ret_type)) - self.wrapper_func.result_var = self.wrapper_func.declare_local("result", self.wrapper_func.result_type) -# self.wrapper_func.result_var = self.wrapper_func.allocate_local("result") + self.wrapper_func.result_var = self.wrapper_func.declare_variable("result", self.wrapper_func.result_type) self.wrapper_func.result_exprs = [self.wrapper_func.result_var] self.virtual_func.ret_type = ret_type @@ -283,7 +281,7 @@ # inside the virtual function. if len(self.wrapper_func.result_exprs)>0: self.virtual_func.result_type = "boost::python::object" - self.virtual_func.result_var = self.virtual_func.declare_local("pyresult", self.virtual_func.result_type) + self.virtual_func.result_var = self.virtual_func.declare_variable("pyresult", self.virtual_func.result_type) self.wrapper_func.init_variables() self.virtual_func.init_variables() @@ -509,7 +507,7 @@ # Declare the local variable that will hold the return value # for the virtual function - self.result_var = sm.virtual_func.declare_local("result", sm.virtual_func.ret_type) + self.result_var = sm.virtual_func.declare_variable("result", sm.virtual_func.ret_type) # Replace the result expression if there is still the default # result expression (which will not work anyway) if sm.virtual_func.result_expr==sm.virtual_func.result_var: @@ -528,4 +526,3 @@ res = "// Extract the C++ return value\n" res += "%s = boost::python::extract<%s>(%s);"%(self.result_var, sm.virtual_func.ret_type, resexpr) return res - Modified: pyplusplus_dev/pyplusplus/function_transformers/transformers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2006-11-11 07:14:29 UTC (rev 706) +++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2006-11-11 18:12:58 UTC (rev 707) @@ -57,7 +57,7 @@ raise ValueError, '%s\nOutput variable %d ("%s") must be a reference or a pointer (got %s)'%(sm.decl, self.idx, arg.name, arg.type) # Declare a local variable that will receive the output value - self.local_var = sm.wrapper_func.declare_local(arg.name, str(reftype.base)) + self.local_var = sm.wrapper_func.declare_variable(arg.name, str(reftype.base)) # Append the output to the result tuple sm.wrapper_func.result_exprs.append(self.local_var) @@ -220,7 +220,7 @@ # Declare a variable that will hold the Python list # (this will be the input of the Python call in the virtual function) - self.pylist = sm.virtual_func.declare_local("py_"+arg.name, "boost::python::list") + self.pylist = sm.virtual_func.declare_variable("py_"+arg.name, "boost::python::list") # Replace the removed argument with a Python object. newarg = declarations.argument_t(arg.name, declarations.dummy_type_t("boost::python::object")) @@ -230,7 +230,7 @@ self.basetype = str(arg.type.base).replace("const", "").strip() # Declare a variable that will hold the C array... - self.carray = sm.wrapper_func.declare_local("c_"+arg.name, self.basetype, size=self.size) + self.carray = sm.wrapper_func.declare_variable("c_"+arg.name, self.basetype, size=self.size) # Replace the input parameter with the C array sm.wrapper_func.input_params[self.idx-1] = self.carray @@ -307,9 +307,9 @@ # Wrapper: # Declare a variable that will hold the C array... - self.wrapper_cval = sm.wrapper_func.declare_local("c_"+self.argname, self.basetype, size=self.size) + self.wrapper_cval = sm.wrapper_func.declare_variable("c_"+self.argname, self.basetype, size=self.size) # Declare a Python list which will receive the output... - self.wrapper_pyval = sm.wrapper_func.declare_local(self.argname, "boost::python::list") + self.wrapper_pyval = sm.wrapper_func.declare_variable(self.argname, "boost::python::list") # ...and add it to the result sm.wrapper_func.result_exprs.append(arg.name) @@ -318,7 +318,7 @@ # Virtual: # Declare a variable that will receive the Python list - self.virtual_pyval = sm.virtual_func.declare_local("py_"+self.argname, "boost::python::object") + self.virtual_pyval = sm.virtual_func.declare_variable("py_"+self.argname, "boost::python::object") def wrapper_post_call(self, sm): tmpl = '%(pypp_con)s::copy_container( %(array)s, %(array)s + %(size)d, %(pypp_con)s::list_inserter( %(pylist)s ) );' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |