Update of /cvsroot/pygccxml/source/pyplusplus/examples/py_date_time
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19111/pyplusplus/examples/py_date_time
Modified Files:
create_date_time.py customization_data.py
Log Message:
porting boost.date_time library to use new api.
Porting process discover few bugs, I fixed them.
Index: customization_data.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pyplusplus/examples/py_date_time/customization_data.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** customization_data.py 14 Feb 2006 11:07:43 -0000 1.13
--- customization_data.py 19 Mar 2006 13:35:39 -0000 1.14
***************
*** 6,9 ****
--- 6,10 ----
import os
+ import sys
from environment import settings
***************
*** 28,36 ****
aliases = {
! "time_duration<boost::posix_time::time_duration,boost::date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, micro, 1000000, 6, int> >"
! : "time_duration_impl" #this will be used on linux
! , "time_duration<boost::posix_time::time_duration,boost::date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, micro, 1000000, 6, long int> >"
! : "time_duration_impl" #and this one will be used on windows
! , "months_duration<boost::gregorian::greg_durations_config>"
: "months"
, 'weeks_duration<boost::date_time::duration_traits_adapted>'
--- 29,33 ----
aliases = {
! "months_duration<boost::gregorian::greg_durations_config>"
: "months"
, 'weeks_duration<boost::date_time::duration_traits_adapted>'
***************
*** 188,193 ****
, "dst_calculator<boost::gregorian::date,boost::posix_time::time_duration>"
: "dst_calculator"
! , "tz_db_base<boost::local_time::custom_time_zone,boost::date_time::day_calc_dst_rule<boost::local_time::nth_kday_rule_spec> >"
! : "tz_database"
, "microsec_clock<boost::local_time::local_date_time_base<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char> > >"
: "local_microsec_clock"
--- 185,190 ----
, "dst_calculator<boost::gregorian::date,boost::posix_time::time_duration>"
: "dst_calculator"
! #, "tz_db_base<boost::local_time::custom_time_zone,boost::date_time::day_calc_dst_rule<boost::local_time::nth_kday_rule_spec> >"
! # : "tz_database"
, "microsec_clock<boost::local_time::local_date_time_base<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char> > >"
: "local_microsec_clock"
***************
*** 206,215 ****
}
#may be those names are uglier, but they are much short
ns_aliases = {
! 'boost::date_time' : 'dt'
! , 'boost::gregorian' : 'gr'
! , 'boost::posix_time' : 'pt'
! , 'boost::local_time' : 'lt'
}
--- 203,219 ----
}
+ if sys.platform == 'win32':
+ aliases[ "time_duration<boost::posix_time::time_duration,boost::date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, micro, 1000000, 6, long int> >" ] \
+ = "time_duration_impl"
+ else:
+ aliases[ "time_duration<boost::posix_time::time_duration,boost::date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, micro, 1000000, 6, int> >" ] \
+ = "time_duration_impl"
+
#may be those names are uglier, but they are much short
ns_aliases = {
! '::boost::date_time' : 'dt'
! , '::boost::gregorian' : 'gr'
! , '::boost::posix_time' : 'pt'
! , '::boost::local_time' : 'lt'
}
Index: create_date_time.py
===================================================================
RCS file: /cvsroot/pygccxml/source/pyplusplus/examples/py_date_time/create_date_time.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** create_date_time.py 28 Feb 2006 07:31:33 -0000 1.30
--- create_date_time.py 19 Mar 2006 13:35:39 -0000 1.31
***************
*** 17,38 ****
from pyplusplus import file_writers
import customization_data
!
! def identify_call_policies( decl ):
! built_in_resolver = module_creator.built_in_resolver_t()
! policy = built_in_resolver( decl )
! if policy:
! return policy
!
! return_by_value = code_creators.return_value_policy( code_creators.return_by_value )
! rbv_types = [
! declarations.pointer_t( declarations.char_t() )
! , declarations.pointer_t( declarations.wchar_t() )
! ]
!
! for type_ in rbv_types:
! if declarations.is_same( type_, decl.return_type ):
! return return_by_value
!
! return None
class exporter_t(object):
--- 17,21 ----
from pyplusplus import file_writers
import customization_data
! from pyplusplus import module_builder
class exporter_t(object):
***************
*** 60,185 ****
return destination
! def read_declarations(self):
date_time_xml_file = self._create_xml_file()
! decls = parser.parse_xml_file( date_time_xml_file, self.__parser_config )
!
! linux_name = "time_duration<boost::posix_time::time_duration,boost::date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, micro, 1000000, 6, int> >"
! win_name = "time_duration<boost::posix_time::time_duration,boost::date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, micro, 1000000, 6, long int> >"
! time_duration_impl = declarations.find_declaration( decls, type=declarations.class_t, name=linux_name )
if sys.platform == 'win32':
#small price for generating code from xml and not from sources
time_duration_impl.name = win_name
! #I don't know why GCCXML reports about this constructor, I think I should find
! #out compilation flags, defines.
! int_adapter_int = declarations.find_declaration( decls, type=declarations.class_t, name='int_adapter<int>' )
! for member in time_duration_impl.get_members():
! if isinstance( member, declarations.constructor_t ):
! if len( member.arguments ) == 1 and member.arguments[0].type.decl_string == int_adapter_int.decl_string:
! member.arguments[0].type = declarations.long_long_int_t()
! break
! return decls
!
! def filter_declarations(self, decls ):
! def should_stay(decl):
! if isinstance( decl, declarations.calldef_t ) \
! and decl.name in [ 'month_str_to_ushort', 'from_stream_type', 'parse_date' ]:
! return False
!
if isinstance( decl, declarations.class_t ):
! full_named = [ 'c_time', 'duration_traits_long', 'duration_traits_adapted' ]
!
! starts_with = [ 'time_resolution_traits<'
! , 'counted_time_rep<'
! , 'date_facet<'
! , 'time_facet<'
! , 'period_formatter<'
! , 'date_generator_formatter<'
! , 'special_values_formatter<' ]
! ends_with = [ '_impl', '_traits', '_config', '_formatter']
! if decl.name in full_named:
! return False
! for txt in starts_with:
! if decl.name.startswith( txt ):
! return False
! for txt in ends_with:
! if decl.name.endswith( txt ):
! return False
!
! if decl.name.startswith( 'constrained_value' ) \
! or decl.name.startswith( 'less_than_comparable' ) \
! or decl.name.startswith( 'equality_comparable' ) \
! or decl.name.startswith( 'addable' ) \
! or decl.name.startswith( 'subtractable' )\
! or decl.name.startswith( 'c_local_adjustor' ):
! return True
!
! fname = declarations.full_name( decl )
! return fname.startswith( '::pyplusplus' ) \
! or fname.startswith( '::boost::posix_time' ) \
! or fname.startswith( '::boost::date_time' ) \
! or fname.startswith( '::boost::gregorian' ) \
! or fname.startswith( '::boost::local_time' )
! return declarations.filtering.user_defined( decls, should_stay )
!
! def create_extmodule(self, decls):
! creator = module_creator.creator_t( decls=decls
! , module_name=settings.module_name
! , create_castinig_constructor=True
! , call_policies_resolver_=identify_call_policies)
! extmodule = creator.create()
! return extmodule
! def _treat_free_functions(self, extmodule):
! creators = code_creators.make_flatten( extmodule )
! template_on_return_type_functions = [ 'parse_iso_time'
! , 'parse_undelimited_time_duration'
! , 'parse_delimited_time'
! , 'parse_delimited_time_duration'
! , 'parse_undelimited_date'
! , 'str_from_delimited_time_duration']
! template_on_2 = [ 'from_simple_string_type' ]
! template_on_char_type = [ 'to_iso_extended_string_type'
! , 'to_iso_string_type'
! , 'to_simple_string_type'
! , 'to_sql_string_type' ]
- matcher = lambda creator: isinstance( creator, code_creators.function_t ) \
- and ( isinstance( creator.declaration, declarations.free_function_t )
- or creator.declaration.has_static )
- functions = filter( matcher, creators )
- for creator in functions:
- #most boost.date_time free functions are templated. Using full signature
- #will forse compiler to generate them, thus allowing generated code to compile
- creator.create_with_signature = True
- if creator.declaration.name in template_on_return_type_functions:
- creator.alias = creator.declaration.name
- creator.declaration.name \
- = declarations.templates.join( creator.declaration.name
- , [ creator.declaration.return_type.decl_string ] )
- if creator.declaration.name in template_on_2:
- decl = creator.declaration
- creator.alias = decl.name
- return_args = declarations.templates.split( decl.return_type.decl_string )[1]
- args = [ return_args[0] ]
- if 'wchar_t' in decl.arguments[0].type.decl_string:
- args.append( 'wchar_t' )
- else:
- args.append( 'char' )
- decl.name = declarations.templates.join( decl.name, args )
- if creator.declaration.name in template_on_char_type:
- decl = creator.declaration
- creator.alias = decl.name
- args = []
- if 'wchar_t' in decl.return_type.decl_string:
- args.append( 'wchar_t' )
- creator.alias = creator.alias + '_w'
- else:
- args.append( 'char' )
- decl.name = declarations.templates.join( decl.name, args )
! def _replace_include_directives( self, extmodule ):
includes = filter( lambda creator: isinstance( creator, code_creators.include_t )
, extmodule.creators )
--- 43,154 ----
return destination
! def create_module_builder(self):
date_time_xml_file = self._create_xml_file()
! mb = module_builder.module_builder_t( settings.module_name
! , [ parser.create_gccxml_fc( date_time_xml_file ) ]
! , self.__parser_config )
if sys.platform == 'win32':
+ linux_name = "time_duration<boost::posix_time::time_duration,boost::date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, micro, 1000000, 6, int> >"
+ win_name = "time_duration<boost::posix_time::time_duration,boost::date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, micro, 1000000, 6, long int> >"
+ time_duration_impl = mb.class_( linux_name )
#small price for generating code from xml and not from sources
time_duration_impl.name = win_name
!
! for name, alias in self.__aliases.items():
! decl = mb.decl( name )
! decl.alias = alias
if isinstance( decl, declarations.class_t ):
! decl.wrapper_alias = alias + '_wrapper'
!
! return mb
!
! def filter_declarations(self, mb ):
! mb.global_ns.exclude()
! mb.namespace( '::pyplusplus' ).include()
! mb.namespace( '::boost::posix_time' ).include()
! mb.namespace( '::boost::date_time' ).include()
! mb.namespace( '::boost::gregorian' ).include()
! mb.namespace( '::boost::local_time' ).include()
! mb.classes( lambda decl: decl.name.startswith( 'constrained_value' ) ).include()
! to_be_removed = [ 'month_str_to_ushort', 'from_stream_type', 'parse_date' ]
! mb.calldefs( lambda decl: decl.name in to_be_removed ).exclude()
!
! to_be_removed = [ 'c_time', 'duration_traits_long', 'duration_traits_adapted' ]
! mb.classes( lambda decl: decl.name in to_be_removed ).exclude()
!
! starts_with = [ 'time_resolution_traits<'
! , 'counted_time_rep<'
! , 'date_facet<'
! , 'time_facet<'
! , 'period_formatter<'
! , 'date_generator_formatter<'
! , 'special_values_formatter<' ]
! for name in starts_with:
! mb.classes( lambda decl: decl.name.startswith( name ) ).exclude()
! ends_with = [ '_impl', '_traits', '_config', '_formatter']
! for name in starts_with:
! mb.classes( lambda decl: decl.name.endswith( name ) ).exclude()
! #boost.date_time has problem to create local_[micro]sec_clock
! #variable, it has nothing to do with pyplusplus
! classes = mb.classes(lambda decl: decl.alias in ['local_microsec_clock', 'local_sec_clock'] )
! classes.exclude()
! classes.ignore = False
! #todo: fix me
! tdi = mb.class_( lambda decl: decl.alias == 'time_duration_impl' )
! tdi_init = tdi.constructor( arg_types=[None, None, None, None], recursive=False)
! tdi_init.ignore=True
! def fix_free_template_functions(self, mb):
! mb.free_functions().create_with_signature = True
!
! #This function fixes some boost.date_time function signatures
! tmpl_on_return_type = [ 'parse_iso_time'
! , 'parse_undelimited_time_duration'
! , 'parse_delimited_time'
! , 'parse_delimited_time_duration'
! , 'parse_undelimited_date'
! , 'str_from_delimited_time_duration']
! functions = mb.free_functions( lambda decl: decl.name in tmpl_on_return_type )
! for function in functions:
! function.alias = function.name
! function.name = declarations.templates.join( function.name
! , [ function.return_type.decl_string ] )
!
! #template on second argument
! functions = mb.free_functions( 'from_simple_string_type' )
! functions.create_with_signature = False
! for function in functions:
! function.alias = function.name
! return_args = declarations.templates.split( function.return_type.decl_string )[1]
! args = [ return_args[0] ]
! if 'wchar_t' in function.arguments[0].type.decl_string:
! args.append( 'wchar_t' )
! else:
! args.append( 'char' )
! function.name = declarations.templates.join( function.name, args )
!
! tmpl_on_char_type = [ 'to_iso_extended_string_type'
! , 'to_iso_string_type'
! , 'to_simple_string_type'
! , 'to_sql_string_type' ]
!
! functions = mb.free_functions( lambda decl: decl.name in tmpl_on_char_type )
! for function in functions:
! function.alias = function.name
! args = []
! if 'wchar_t' in function.return_type.decl_string:
! args.append( 'wchar_t' )
! function.alias = function.alias + '_w'
! else:
! args.append( 'char' )
! function.name = declarations.templates.join( function.name, args )
!
! def replace_include_directives( self, mb ):
! extmodule = mb.module_creator
includes = filter( lambda creator: isinstance( creator, code_creators.include_t )
, extmodule.creators )
***************
*** 189,196 ****
extmodule.adopt_include( code_creators.include_t( header=include_header ) )
! def _customize_classes( self, extmodule ):
! class_creators = filter( lambda creator: isinstance( creator, code_creators.class_t )
! , code_creators.make_flatten( extmodule.body.creators ) )
!
#boost.date_time has a lot of templates, not all functions
#are instantiated during GCCXML scan.
--- 158,162 ----
extmodule.adopt_include( code_creators.include_t( header=include_header ) )
! def add_code( self, mb ):
#boost.date_time has a lot of templates, not all functions
#are instantiated during GCCXML scan.
***************
*** 198,233 ****
max_template = 'def( "max", &%s::max, bp::default_call_policies() )'
as_number_template = 'def( "as_number", &%(class_def)s::operator %(class_def)s::value_type, bp::default_call_policies() )'
! for creator in class_creators:
! creator.always_expose_using_scope = True #better error reporting from compiler
! if creator.alias != 'local_date_time':
! creator.redefine_operators = True #redefine all operators found in base classes
!
! if creator.declaration.name.startswith( 'constrained_value<' ):
! as_number = code_creators.custom_text_t( as_number_template % { 'class_def' : declarations.full_name( creator.declaration ) } )
! creator.adopt_creator( as_number )
!
! min_creator = code_creators.custom_text_t( min_template % declarations.full_name( creator.declaration ) )
! creator.adopt_creator( min_creator )
! creator.adopt_creator( code_creators.custom_text_t( 'staticmethod( "min" )' ) )
! max_creator = code_creators.custom_text_t( max_template % declarations.full_name( creator.declaration ))
! creator.adopt_creator( max_creator )
! creator.adopt_creator( code_creators.custom_text_t( 'staticmethod( "max" )' ) )
! #I need to find better pattern to expose additional operators
! #I may use the fact that boost.date_time uses boost.operators.
! if creator.alias in ( 'date_duration', 'time_duration' ):
! for operator in [ '>', '>=', '<=', '<', '+', '-' ]:
! creator.adopt_creator( code_creators.custom_text_t( 'def( bp::self %s bp::self )' % operator ) )
!
! if creator.alias == 'ptime':
! for operator in [ '>', '>=', '<=', '<', '-' ]:
! creator.adopt_creator( code_creators.custom_text_t( 'def( bp::self %s bp::self )' % operator ) )
! if creator.alias in ['local_microsec_clock', 'local_sec_clock']:
! #boost.date_time has problem to create local_[micro]sec_clock
! #variable, it has nothing to do with pyplusplus
! del creator.creators[:]
! def _beautify_code( self, extmodule ):
position = extmodule.last_include_index() + 1
extmodule.adopt_creator( code_creators.namespace_using_t( 'boost' )
--- 164,188 ----
max_template = 'def( "max", &%s::max, bp::default_call_policies() )'
as_number_template = 'def( "as_number", &%(class_def)s::operator %(class_def)s::value_type, bp::default_call_policies() )'
!
! classes = mb.classes()
! classes.always_expose_using_scope = True #better error reporting from compiler
! classes = mb.classes(lambda decl: decl.alias != 'local_date_time' )
! classes.redefine_operators = True #redefine all operators found in base classes
!
! classes = mb.classes(lambda decl: decl.name.startswith('constrained_value<') )
! for cls in classes:
! cls.add_code( as_number_template % { 'class_def' : declarations.full_name( cls ) } )
! classes = mb.classes(lambda decl: decl.alias in [ 'date_duration', 'time_duration' ] )
! for operator in [ '>', '>=', '<=', '<', '+', '-' ]:
! classes.add_code( 'def( bp::self %s bp::self )' % operator )
!
! ptime = mb.class_( lambda decl: decl.alias == 'ptime' )
! for operator in [ '>', '>=', '<=', '<', '-' ]:
! ptime.add_code( 'def( bp::self %s bp::self )' % operator )
! def beautify_code( self, mb ):
! extmodule = mb.module_creator
position = extmodule.last_include_index() + 1
extmodule.adopt_creator( code_creators.namespace_using_t( 'boost' )
***************
*** 237,240 ****
--- 192,196 ----
, position )
position += 1
+
for full_ns_name, alias in self.__ns_aliases.items():
creator = code_creators.namespace_alias_t( alias=alias
***************
*** 243,255 ****
position += 1
! creators = code_creators.make_flatten( extmodule.creators )
! for creator in creators:
! if isinstance( creator, code_creators.declaration_based_t )\
! and self.__aliases.has_key(creator.declaration.name):
! creator.alias = self.__aliases[ creator.declaration.name ]
! if isinstance( creator, code_creators.class_wrapper_t ):
! creator.alias = creator.alias + '_wrapper'
!
! def customize_extmodule( self, extmodule ):
#beautifying include code generation
extmodule.license = customization_data.license
--- 199,204 ----
position += 1
! def customize_extmodule( self, mb ):
! extmodule = mb.module_creator
#beautifying include code generation
extmodule.license = customization_data.license
***************
*** 259,269 ****
extmodule.license = customization_data.license
extmodule.precompiled_header = 'boost/python.hpp'
! self._replace_include_directives( extmodule )
! self._beautify_code( extmodule )
! self._treat_free_functions( extmodule )
! self._customize_classes( extmodule )
! def write_files( self, extmodule ):
! file_writers.write_multiple_files( extmodule, settings.generated_files_dir )
shutil.copyfile( os.path.join( settings.date_time_pypp_include, 'date_time_wrapper.hpp' )
, os.path.join( settings.generated_files_dir, 'date_time_wrapper.hpp' ) )
--- 208,216 ----
extmodule.license = customization_data.license
extmodule.precompiled_header = 'boost/python.hpp'
! self.replace_include_directives( mb )
! self.beautify_code( mb )
! def write_files( self, mb ):
! mb.write_multiple_files( settings.generated_files_dir )
shutil.copyfile( os.path.join( settings.date_time_pypp_include, 'date_time_wrapper.hpp' )
, os.path.join( settings.generated_files_dir, 'date_time_wrapper.hpp' ) )
***************
*** 271,279 ****
def create(self):
start_time = time.clock()
! decls_all = self.read_declarations()
! decls = self.filter_declarations(decls_all)
! extmodule = self.create_extmodule( decls )
! self.customize_extmodule( extmodule )
! self.write_files( extmodule )
print 'time taken : ', time.clock() - start_time, ' seconds'
--- 218,227 ----
def create(self):
start_time = time.clock()
! mb = self.create_module_builder()
! self.filter_declarations(mb)
! self.fix_free_template_functions( mb )
! self.add_code( mb )
! self.customize_extmodule( mb )
! self.write_files( mb )
print 'time taken : ', time.clock() - start_time, ' seconds'
|