[pygccxml-commit] SF.net SVN: pygccxml: [967] pyplusplus_dev/pyplusplus
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2007-04-04 20:21:23
|
Revision: 967
http://svn.sourceforge.net/pygccxml/?rev=967&view=rev
Author: roman_yakovenko
Date: 2007-04-04 13:21:23 -0700 (Wed, 04 Apr 2007)
Log Message:
-----------
fixing a bug, which could cause duplicated include directives
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_repository/call_policies.py
pyplusplus_dev/pyplusplus/code_repository/return_range.py
pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py
pyplusplus_dev/pyplusplus/module_creator/creator.py
Added Paths:
-----------
pyplusplus_dev/pyplusplus/module_creator/header_files_manager.py
Modified: pyplusplus_dev/pyplusplus/code_repository/call_policies.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_repository/call_policies.py 2007-04-01 20:08:17 UTC (rev 966)
+++ pyplusplus_dev/pyplusplus/code_repository/call_policies.py 2007-04-04 20:21:23 UTC (rev 967)
@@ -7,10 +7,11 @@
This file contains C++ code - custom call policies
"""
+from pyplusplus.decl_wrappers import call_policies
namespace = "pyplusplus::call_policies"
-file_name = "__call_policies.pypp.hpp"
+file_name = call_policies.PYPP_CALL_POLICIES_HEADER_FILE
code = \
"""// Copyright 2004 Roman Yakovenko.
Modified: pyplusplus_dev/pyplusplus/code_repository/return_range.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_repository/return_range.py 2007-04-01 20:08:17 UTC (rev 966)
+++ pyplusplus_dev/pyplusplus/code_repository/return_range.py 2007-04-04 20:21:23 UTC (rev 967)
@@ -7,9 +7,11 @@
This file contains C++ code - "return_range" call policies
"""
+from pyplusplus.decl_wrappers import call_policies
+
namespace = "pyplusplus::call_policies"
-file_name = "__return_range.pypp.hpp"
+file_name = call_policies.return_range_t.HEADER_FILE
code = \
"""// Copyright 2004 Roman Yakovenko.
Modified: pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py
===================================================================
--- pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2007-04-01 20:08:17 UTC (rev 966)
+++ pyplusplus_dev/pyplusplus/decl_wrappers/call_policies.py 2007-04-04 20:21:23 UTC (rev 967)
@@ -15,6 +15,8 @@
import python_traits
from pygccxml import declarations
+PYPP_CALL_POLICIES_HEADER_FILE = "__call_policies.pypp.hpp"
+
class CREATION_POLICY:
"""Implementation details"""
AS_INSTANCE = 'as instance'
@@ -57,6 +59,11 @@
def _create_impl( self, function_creator ):
raise NotImplementedError()
+ @property
+ def header_file(self):
+ """Return name of the header file to be included"""
+ return "boost/python.hpp"
+
class default_call_policies_t(call_policy_t):
"""implementation for ::boost::python::default_call_policies"""
def __init__( self ):
@@ -226,6 +233,13 @@
else:
return True
+ @property
+ def header_file(self):
+ """Return name of the header file to be included"""
+ if self.is_predefined():
+ return super( return_value_policy_t, self ).header_file
+ else:
+ return PYPP_CALL_POLICIES_HEADER_FILE
copy_const_reference = '::boost::python::copy_const_reference'
@@ -246,9 +260,10 @@
class custom_call_policies_t(call_policy_t):
"""implementation for user defined call policies"""
- def __init__( self, call_policies ):
+ def __init__( self, call_policies, header_file=None ):
call_policy_t.__init__( self )
self.__call_policies = call_policies
+ self.__header_file = header_file
def _create_impl(self, function_creator ):
return str( self.__call_policies )
@@ -256,9 +271,16 @@
def __str__(self):
return 'custom call policies'
-def custom_call_policies(call_policies):
+ def get_header_file( self ):
+ return self.__header_file
+ def set_header_file( self, header_file_name ):
+ self.__header_file = header_file_name
+ header_file = property( get_header_file, set_header_file
+ , doc="""Return name of the header file to be included""" )
+
+def custom_call_policies(call_policies, header_file=None):
"""create custom\\user defined call policies"""
- return custom_call_policies_t(call_policies)
+ return custom_call_policies_t(call_policies, header_file)
class memory_managers:
none = 'none'
@@ -282,7 +304,12 @@
def is_predefined( self ):
"""Returns True if call policy is defined in Boost.Python library, False otherwise"""
return False
-
+
+ @property
+ def header_file(self):
+ """Return name of the header file to be included"""
+ return PYPP_CALL_POLICIES_HEADER_FILE
+
def _get_array_size( self ):
return self._array_size
def _set_array_size( self, new_array_size):
@@ -321,6 +348,7 @@
return convert_array_to_tuple_t( array_size, memory_manager, make_object_call_policies, base )
class return_range_t( call_policy_t ):
+ HEADER_FILE = "__return_range.pypp.hpp"
def __init__( self, get_size_class, value_type, value_policies):
call_policy_t.__init__( self )
self._value_type = value_type
@@ -331,6 +359,11 @@
"""Returns True if call policy is defined in Boost.Python library, False otherwise"""
return False
+ @property
+ def header_file(self):
+ """Return name of the header file to be included"""
+ return self.HEADER_FILE
+
def _get_get_size_class( self ):
return self._get_size_class
def _set_get_size_class( self, new_get_size_class):
Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-04-01 20:08:17 UTC (rev 966)
+++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2007-04-04 20:21:23 UTC (rev 967)
@@ -8,7 +8,9 @@
import sort_algorithms
import dependencies_manager
import opaque_types_manager
+import header_files_manager
import call_policies_resolver
+
from pygccxml import declarations
from pyplusplus import decl_wrappers
from pyplusplus import code_creators
@@ -107,8 +109,7 @@
self.__types_db = types_database.types_database_t()
self.__extmodule = code_creators.module_t()
- self.__extmodule.add_system_header( "boost/python.hpp" )
- self.__extmodule.adopt_creator( code_creators.include_t( header="boost/python.hpp" ) )
+ self.__header_files_manager = header_files_manager.manager_t( self.__extmodule )
if boost_python_ns_name:
bp_ns_alias = code_creators.namespace_alias_t( alias=boost_python_ns_name
, full_namespace_name='::boost::python' )
@@ -122,14 +123,10 @@
self.curr_code_creator = self.__module_body
self.curr_decl = None
- self.__cr_array_1_included = False
self.__array_1_registered = set() #(type.decl_string,size)
self.__free_operators = []
self.__exposed_free_fun_overloads = set()
self.__opaque_types_manager = opaque_types_manager.manager_t( self.__extmodule )
- self.__custom_call_policies_included = False
- self.__return_range_call_policies_included = False
-
self.__dependencies_manager = dependencies_manager.manager_t(self.decl_logger)
def _prepare_decls( self, decls, doc_extractor ):
@@ -351,25 +348,6 @@
creators.reverse()
self.__module_body.adopt_creators( creators, 0 )
- def __on_demand_include_call_policies( self, call_policy ):
- if self.__custom_call_policies_included and self.__return_range_call_policies_included:
- return
-
- if not call_policy:
- return
-
- if call_policy.is_predefined():
- return
-
- if isinstance( call_policy, decl_wrappers.call_policies.return_range_t ):
- self.__return_range_call_policies_included = True
- self.__extmodule.add_include( code_repository.return_range.file_name )
- self.__extmodule.add_system_header( code_repository.return_range.file_name )
- else:
- self.__custom_call_policies_included = True
- self.__extmodule.add_include( code_repository.call_policies.file_name )
- self.__extmodule.add_system_header( code_repository.call_policies.file_name )
-
def create(self, decl_headers=None):
"""Create and return the module for the extension.
@@ -379,10 +357,11 @@
@rtype: L{module_t<code_creators.module_t>}
"""
if decl_headers is None:
- self._create_includes()
- else:
- for h in decl_headers:
- self.__extmodule.adopt_include(code_creators.include_t(header=h))
+ decl_headers = declarations.declaration_files( self.__decls )
+
+ map( lambda header: self.__header_files_manager.include( header )
+ , decl_headers )
+
# Invoke the appropriate visit_*() method on all decls
for decl in self.__decls:
self.curr_decl = decl
@@ -399,18 +378,13 @@
self.__dependencies_manager.inform_user()
return self.__extmodule
- def _create_includes(self):
- for fn in declarations.declaration_files( self.__decls ):
- include = code_creators.include_t( header=fn )
- self.__extmodule.adopt_include(include)
-
def visit_member_function( self ):
fwrapper = None
self.__types_db.update( self.curr_decl )
self.__dependencies_manager.add_exported( self.curr_decl )
if None is self.curr_decl.call_policies:
self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl )
- self.__on_demand_include_call_policies( self.curr_decl.call_policies )
+ self.__header_files_manager.include_call_policy( self.curr_decl.call_policies )
maker_cls, fwrapper_cls = creators_wizard.find_out_mem_fun_creator_classes( self.curr_decl )
@@ -437,23 +411,10 @@
self.curr_code_creator.adopt_creator( maker )
self.__opaque_types_manager.register_opaque( maker, self.curr_decl )
- if self.curr_decl.transformations:
+ if self.curr_decl.transformations:
required_headers = self.curr_decl.transformations[0].required_headers()
- 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.adopt_include(
- code_creators.include_t( header=header, user_defined=True ) )
-
- # Check if it is a header from the code repository
- if header in code_repository.headers:
- self.__extmodule.add_system_header( header )
+ self.__header_files_manager.include_ft( required_headers )
- if not self.__extmodule.is_system_header( code_repository.named_tuple.file_name ):
- self.__extmodule.add_system_header( code_repository.named_tuple.file_name )
-
if self.curr_decl.has_static:
#static_method should be created only once.
found = filter( lambda creator: isinstance( creator, code_creators.static_method_t )
@@ -479,7 +440,7 @@
maker = code_creators.constructor_t( constructor=self.curr_decl, wrapper=cwrapper )
if None is self.curr_decl.call_policies:
self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl )
- self.__on_demand_include_call_policies( self.curr_decl.call_policies )
+ self.__header_files_manager.include_call_policy( self.curr_decl.call_policies )
self.curr_code_creator.adopt_creator( maker )
def visit_destructor( self ):
@@ -498,7 +459,7 @@
self.__dependencies_manager.add_exported( self.curr_decl )
if None is self.curr_decl.call_policies:
self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl )
- self.__on_demand_include_call_policies( self.curr_decl.call_policies )
+ self.__header_files_manager.include_call_policy( self.curr_decl.call_policies )
self.__types_db.update( self.curr_decl )
if not self.curr_decl.parent.is_abstract and not declarations.is_reference( self.curr_decl.return_type ):
@@ -530,7 +491,7 @@
self.__dependencies_manager.add_exported( f )
if None is f.call_policies:
f.call_policies = self.__call_policies_resolver( f )
- self.__on_demand_include_call_policies( f.call_policies )
+ self.__header_files_manager.include_call_policy( f.call_policies )
overloads_cls_creator = code_creators.free_fun_overloads_class_t( overloads )
self.__extmodule.adopt_declaration_creator( overloads_cls_creator )
@@ -551,10 +512,13 @@
self.__dependencies_manager.add_exported( self.curr_decl )
if None is self.curr_decl.call_policies:
self.curr_decl.call_policies = self.__call_policies_resolver( self.curr_decl )
- self.__on_demand_include_call_policies( self.curr_decl.call_policies )
+ self.__header_files_manager.include_call_policy( self.curr_decl.call_policies )
maker = None
if self.curr_decl.transformations:
+ required_headers = self.curr_decl.transformations[0].required_headers()
+ self.__header_files_manager.include_ft( required_headers )
+
wrapper = code_creators.free_fun_transformed_wrapper_t( self.curr_decl )
self.__extmodule.adopt_declaration_creator( wrapper )
maker = code_creators.free_fun_transformed_t( self.curr_decl, wrapper )
@@ -595,7 +559,7 @@
self.__dependencies_manager.add_exported( f )
if None is f.call_policies:
f.call_policies = self.__call_policies_resolver( f )
- self.__on_demand_include_call_policies( f.call_policies )
+ self.__header_files_manager.include_call_policy( f.call_policies )
overloads_cls_creator = code_creators.mem_fun_overloads_class_t( overloads )
self.__extmodule.adopt_declaration_creator( overloads_cls_creator )
@@ -707,11 +671,7 @@
self.__dependencies_manager.add_exported( self.curr_decl )
if declarations.is_array( self.curr_decl.type ):
- if not self.__cr_array_1_included:
- self.__extmodule.add_system_header( code_repository.array_1.file_name )
- self.__extmodule.adopt_creator( code_creators.include_t( code_repository.array_1.file_name )
- , self.__extmodule.first_include_index() + 1)
- self.__cr_array_1_included = True
+ self.__header_files_manager.include(code_repository.array_1.file_name, system=True )
if self._register_array_1( self.curr_decl.type ):
array_1_registrator = code_creators.array_1_registrator_t( array_type=self.curr_decl.type )
self.curr_code_creator.adopt_creator( array_1_registrator )
@@ -741,10 +701,10 @@
elif declarations.is_reference( self.curr_decl.type ):
if None is self.curr_decl.getter_call_policies:
self.curr_decl.getter_call_policies = self.__call_policies_resolver( self.curr_decl, 'get' )
- self.__on_demand_include_call_policies( self.curr_decl.getter_call_policies )
+ self.__header_files_manager.include_call_policy( self.curr_decl.getter_call_policies )
if None is self.curr_decl.setter_call_policies:
self.curr_decl.setter_call_policies = self.__call_policies_resolver( self.curr_decl, 'set' )
- self.__on_demand_include_call_policies( self.curr_decl.setter_call_policies )
+ self.__header_files_manager.include_call_policy( self.curr_decl.setter_call_policies )
wrapper = code_creators.mem_var_ref_wrapper_t( variable=self.curr_decl )
maker = code_creators.mem_var_ref_t( variable=self.curr_decl, wrapper=wrapper )
self.__opaque_types_manager.register_opaque( maker, self.curr_decl )
Added: pyplusplus_dev/pyplusplus/module_creator/header_files_manager.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/header_files_manager.py (rev 0)
+++ pyplusplus_dev/pyplusplus/module_creator/header_files_manager.py 2007-04-04 20:21:23 UTC (rev 967)
@@ -0,0 +1,53 @@
+# 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)
+
+from pygccxml import declarations
+from pyplusplus import code_creators
+from pyplusplus import code_repository
+
+class manager_t( object ):
+ def __init__( self, extmodule ):
+ object.__init__( self )
+ self.__extmodule = extmodule
+ self.__already_included = set()
+ self.normalize = code_creators.include_directories_t.normalize
+
+ self.__extmodule.add_system_header( "boost/python.hpp" )
+ self.__extmodule.adopt_creator( code_creators.include_t( header="boost/python.hpp" ) )
+
+ def include( self, header, system=False, once=True, user_defined=False ):
+ if once:
+ normalized_header = self.normalize( header )
+ if normalized_header in self.__already_included:
+ return
+ self.__extmodule.add_system_header( header )
+ self.__extmodule.adopt_include( code_creators.include_t( header, user_defined=user_defined ) )
+ if system:
+ self.__extmodule.add_system_header( header )
+
+
+ def include_call_policy( self, call_policy ):
+ if not call_policy:
+ return
+ if call_policy.is_predefined():
+ #boost/python.hpp is already included
+ return
+ self.include( call_policy.header_file, system=True )
+
+ def include_ft( self, required_headers ): #include function transformation headers
+ for header in required_headers:
+ # Check whether the header is already included
+ system = bool( header in code_repository.headers )
+ self.include( header, system=system, user_defined=True )
+
+ if not self.__extmodule.is_system_header( code_repository.named_tuple.file_name ):
+ self.__extmodule.add_system_header( code_repository.named_tuple.file_name )
+
+
+
+
+
+
+
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|