Revision: 1501
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1501&view=rev
Author: roman_yakovenko
Date: 2008-12-26 07:58:38 +0000 (Fri, 26 Dec 2008)
Log Message:
-----------
small refactoring before introducing ctypes code generator
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_creators/__init__.py
pyplusplus_dev/pyplusplus/code_creators/name_mappings.py
Added Paths:
-----------
pyplusplus_dev/pyplusplus/code_creators/bpmodule.py
Removed Paths:
-------------
pyplusplus_dev/pyplusplus/code_creators/module.py
Modified: pyplusplus_dev/pyplusplus/code_creators/__init__.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-26 07:53:03 UTC (rev 1500)
+++ pyplusplus_dev/pyplusplus/code_creators/__init__.py 2008-12-26 07:58:38 UTC (rev 1501)
@@ -116,7 +116,7 @@
from license import license_t
-from module import bpmodule_t
+from bpmodule import bpmodule_t
from smart_pointers import held_type_t
from smart_pointers import smart_pointers_converter_t
@@ -143,4 +143,4 @@
#pure ctypes
from import_ import import_t
from library_reference import library_reference_t
-from name_mapping import name_mapping_t
+from name_mappings import name_mapping_t
Copied: pyplusplus_dev/pyplusplus/code_creators/bpmodule.py (from rev 1500, pyplusplus_dev/pyplusplus/code_creators/module.py)
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/bpmodule.py (rev 0)
+++ pyplusplus_dev/pyplusplus/code_creators/bpmodule.py 2008-12-26 07:58:38 UTC (rev 1501)
@@ -0,0 +1,173 @@
+# Copyright 2004-2008 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 custom
+import module
+import include
+import namespace
+import compound
+import algorithm
+import module_body
+import declaration_based
+import include_directories
+from pygccxml import utils
+
+class bpmodule_t(module.module_t):
+ """This class represents the source code for the entire extension module.
+
+ The root of the code creator tree is always a module_t object.
+ """
+ def __init__(self, global_ns):
+ """Constructor.
+ """
+ module.module_t.__init__(self, global_ns)
+ self.__body = None
+
+ def _get_include_dirs(self):
+ include_dirs = algorithm.creator_finder.find_by_class_instance(
+ what=include_directories.include_directories_t
+ , where=self.creators
+ , recursive=False)
+ if 0 == len( include_dirs ):
+ include_dirs = include_directories.include_directories_t()
+ if self.license:
+ self.adopt_creator( include_dirs, 1 )
+ else:
+ self.adopt_creator( include_dirs, 0 )
+ return include_dirs
+ elif 1 == len( include_dirs ):
+ return include_dirs[0]
+ else:
+ assert not "only single instance of include_directories_t should exist"
+
+ def _get_std_directories(self):
+ include_dirs = self._get_include_dirs()
+ return include_dirs.std
+ std_directories = property( _get_std_directories )
+
+ def _get_user_defined_directories(self):
+ include_dirs = self._get_include_dirs()
+ return include_dirs.user_defined
+ user_defined_directories = property( _get_user_defined_directories )
+
+ @property
+ def body(self):
+ """Return reference to L{module_body_t} code creator"""
+ if None is self.__body:
+ found = algorithm.creator_finder.find_by_class_instance( what=module_body.module_body_t
+ , where=self.creators
+ , recursive=False )
+ if found:
+ self.__body = found[0]
+ return self.__body
+
+ def last_include_index(self):
+ """Return the children index of the last L{include_t} object.
+
+ An exception is raised when there is no include_t object among
+ the children creators.
+
+ @returns: Children index
+ @rtype: int
+ """
+ for i in range( len(self.creators) - 1, -1, -1 ):
+ if isinstance( self.creators[i], include.include_t ):
+ return i
+ else:
+ return 0
+
+ def replace_included_headers( self, headers, leave_system_headers=True ):
+ to_be_removed = []
+ for creator in self.creators:
+ if isinstance( creator, include.include_t ):
+ to_be_removed.append( creator )
+ elif isinstance( creator, module_body.module_body_t ):
+ break
+
+ for creator in to_be_removed:
+ if creator.is_system:
+ if not leave_system_headers:
+ self.remove_creator( creator )
+ elif creator.is_user_defined:
+ pass
+ else:
+ self.remove_creator( creator )
+ map( lambda header: self.adopt_include( include.include_t( header=header ) )
+ , headers )
+
+ def adopt_include(self, include_creator):
+ """Insert an L{include_t} object.
+
+ The include creator is inserted right after the last include file.
+
+ @param include_creator: Include creator object
+ @type include_creator: L{include_t}
+ """
+ lii = self.last_include_index()
+ if lii == 0:
+ if not self.creators:
+ lii = -1
+ elif not isinstance( self.creators[0], include.include_t ):
+ lii = -1
+ else:
+ pass
+ self.adopt_creator( include_creator, lii + 1 )
+
+ def do_include_dirs_optimization(self):
+ include_dirs = self._get_include_dirs()
+ includes = filter( lambda creator: isinstance( creator, include.include_t )
+ , self.creators )
+ for include_creator in includes:
+ include_creator.include_dirs_optimization = include_dirs
+
+ def _create_impl(self):
+ self.do_include_dirs_optimization()
+ index = 0
+ includes = []
+ for index in range( len( self.creators ) ):
+ if not isinstance( self.creators[index], include.include_t ):
+ break
+ else:
+ includes.append( self.creators[index].create() )
+ code = compound.compound_t.create_internal_code( self.creators[index:] )
+ code = self.unindent(code)
+ return os.linesep.join( includes ) + 2 * os.linesep + code + os.linesep
+
+ def add_include( self, header, user_defined=True, system=False ):
+ creator = include.include_t( header=header, user_defined=user_defined, system=system )
+ self.adopt_include( creator )
+
+ def add_namespace_usage( self, namespace_name ):
+ self.adopt_creator( namespace.namespace_using_t( namespace_name )
+ , self.last_include_index() + 1 )
+
+ def add_namespace_alias( self, alias, full_namespace_name ):
+ self.adopt_creator( namespace.namespace_alias_t(
+ alias=alias
+ , full_namespace_name=full_namespace_name )
+ , self.last_include_index() + 1 )
+
+ def adopt_declaration_creator( self, creator ):
+ self.adopt_creator( creator, self.creators.index( self.body ) )
+
+ def add_declaration_code( self, code, position ):
+ self.adopt_declaration_creator( custom.custom_text_t( code ) )
+
+ @utils.cached
+ def specially_exposed_decls(self):
+ """list of exposed declarations, which were not ``included``, but still
+ were exposed. For example, std containers.
+ """
+ decls = set()
+ #select all declaration based code creators
+ ccs = filter( lambda cc: isinstance( cc, declaration_based.declaration_based_t )
+ , algorithm.make_flatten_list( self ) )
+ #leave only "ignored"
+ ccs = filter( lambda cc: cc.declaration.ignore == True, ccs )
+
+ decls = map( lambda cc: cc.declaration, ccs )
+
+ return set( decls )
Deleted: pyplusplus_dev/pyplusplus/code_creators/module.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/module.py 2008-12-26 07:53:03 UTC (rev 1500)
+++ pyplusplus_dev/pyplusplus/code_creators/module.py 2008-12-26 07:58:38 UTC (rev 1501)
@@ -1,174 +0,0 @@
-# Copyright 2004-2008 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 custom
-import license
-import include
-import namespace
-import compound
-import algorithm
-import base_module
-import module_body
-import declaration_based
-import include_directories
-from pygccxml import utils
-
-class bpmodule_t(base_module.base_module_t):
- """This class represents the source code for the entire extension module.
-
- The root of the code creator tree is always a module_t object.
- """
- def __init__(self, global_ns):
- """Constructor.
- """
- base_module.base_module_t.__init__(self, global_ns)
- self.__body = None
-
- def _get_include_dirs(self):
- include_dirs = algorithm.creator_finder.find_by_class_instance(
- what=include_directories.include_directories_t
- , where=self.creators
- , recursive=False)
- if 0 == len( include_dirs ):
- include_dirs = include_directories.include_directories_t()
- if self.license:
- self.adopt_creator( include_dirs, 1 )
- else:
- self.adopt_creator( include_dirs, 0 )
- return include_dirs
- elif 1 == len( include_dirs ):
- return include_dirs[0]
- else:
- assert not "only single instance of include_directories_t should exist"
-
- def _get_std_directories(self):
- include_dirs = self._get_include_dirs()
- return include_dirs.std
- std_directories = property( _get_std_directories )
-
- def _get_user_defined_directories(self):
- include_dirs = self._get_include_dirs()
- return include_dirs.user_defined
- user_defined_directories = property( _get_user_defined_directories )
-
- @property
- def body(self):
- """Return reference to L{module_body_t} code creator"""
- if None is self.__body:
- found = algorithm.creator_finder.find_by_class_instance( what=module_body.module_body_t
- , where=self.creators
- , recursive=False )
- if found:
- self.__body = found[0]
- return self.__body
-
- def last_include_index(self):
- """Return the children index of the last L{include_t} object.
-
- An exception is raised when there is no include_t object among
- the children creators.
-
- @returns: Children index
- @rtype: int
- """
- for i in range( len(self.creators) - 1, -1, -1 ):
- if isinstance( self.creators[i], include.include_t ):
- return i
- else:
- return 0
-
- def replace_included_headers( self, headers, leave_system_headers=True ):
- to_be_removed = []
- for creator in self.creators:
- if isinstance( creator, include.include_t ):
- to_be_removed.append( creator )
- elif isinstance( creator, module_body.module_body_t ):
- break
-
- for creator in to_be_removed:
- if creator.is_system:
- if not leave_system_headers:
- self.remove_creator( creator )
- elif creator.is_user_defined:
- pass
- else:
- self.remove_creator( creator )
- map( lambda header: self.adopt_include( include.include_t( header=header ) )
- , headers )
-
- def adopt_include(self, include_creator):
- """Insert an L{include_t} object.
-
- The include creator is inserted right after the last include file.
-
- @param include_creator: Include creator object
- @type include_creator: L{include_t}
- """
- lii = self.last_include_index()
- if lii == 0:
- if not self.creators:
- lii = -1
- elif not isinstance( self.creators[0], include.include_t ):
- lii = -1
- else:
- pass
- self.adopt_creator( include_creator, lii + 1 )
-
- def do_include_dirs_optimization(self):
- include_dirs = self._get_include_dirs()
- includes = filter( lambda creator: isinstance( creator, include.include_t )
- , self.creators )
- for include_creator in includes:
- include_creator.include_dirs_optimization = include_dirs
-
- def _create_impl(self):
- self.do_include_dirs_optimization()
- index = 0
- includes = []
- for index in range( len( self.creators ) ):
- if not isinstance( self.creators[index], include.include_t ):
- break
- else:
- includes.append( self.creators[index].create() )
- code = compound.compound_t.create_internal_code( self.creators[index:] )
- code = self.unindent(code)
- return os.linesep.join( includes ) + 2 * os.linesep + code + os.linesep
-
- def add_include( self, header, user_defined=True, system=False ):
- creator = include.include_t( header=header, user_defined=user_defined, system=system )
- self.adopt_include( creator )
-
- def add_namespace_usage( self, namespace_name ):
- self.adopt_creator( namespace.namespace_using_t( namespace_name )
- , self.last_include_index() + 1 )
-
- def add_namespace_alias( self, alias, full_namespace_name ):
- self.adopt_creator( namespace.namespace_alias_t(
- alias=alias
- , full_namespace_name=full_namespace_name )
- , self.last_include_index() + 1 )
-
- def adopt_declaration_creator( self, creator ):
- self.adopt_creator( creator, self.creators.index( self.body ) )
-
- def add_declaration_code( self, code, position ):
- self.adopt_declaration_creator( custom.custom_text_t( code ) )
-
- @utils.cached
- def specially_exposed_decls(self):
- """list of exposed declarations, which were not ``included``, but still
- were exposed. For example, std containers.
- """
- decls = set()
- #select all declaration based code creators
- ccs = filter( lambda cc: isinstance( cc, declaration_based.declaration_based_t )
- , algorithm.make_flatten_list( self ) )
- #leave only "ignored"
- ccs = filter( lambda cc: cc.declaration.ignore == True, ccs )
-
- decls = map( lambda cc: cc.declaration, ccs )
-
- return set( decls )
Modified: pyplusplus_dev/pyplusplus/code_creators/name_mappings.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/name_mappings.py 2008-12-26 07:53:03 UTC (rev 1500)
+++ pyplusplus_dev/pyplusplus/code_creators/name_mappings.py 2008-12-26 07:58:38 UTC (rev 1501)
@@ -24,7 +24,7 @@
items_undecorated.append( tmpl % ( undecorated, blob ) )
result = []
- result.append('%s.undecorated_names = {#mapping between decorated and undecorated names' % self._dictionary_var_name ]
+ result.append('%s.undecorated_names = {#mapping between decorated and undecorated names' % self._dictionary_var_name )
for s in items_undecorated:
result.append( self.indent( s ) )
for s in items_decorated:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|