Revision: 296
Author: roman_yakovenko
Date: 2006-07-11 05:39:43 -0700 (Tue, 11 Jul 2006)
ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=296&view=rev
Log Message:
-----------
improving generated code stability( order of generated code should not change from
one generation to another )
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/file_writers/multiple_files.py
pyplusplus_dev/pyplusplus/module_creator/class_organizer.py
pyplusplus_dev/pyplusplus/module_creator/creator.py
Modified: pyplusplus_dev/pyplusplus/file_writers/multiple_files.py
===================================================================
--- pyplusplus_dev/pyplusplus/file_writers/multiple_files.py 2006-07-11 09:05:55 UTC (rev 295)
+++ pyplusplus_dev/pyplusplus/file_writers/multiple_files.py 2006-07-11 12:39:43 UTC (rev 296)
@@ -293,7 +293,8 @@
self.split_global_variables()
self.split_free_functions()
- if write_main:
+ if write_main:
+ self.__include_creators.sort( cmp=lambda ic1, ic2: cmp( ic1.header, ic2.header ) )
map( lambda creator: self.extmodule.adopt_include( creator )
, self.__include_creators )
main_cpp = os.path.join( self.directory_path, self.extmodule.body.name + '.main.cpp' )
Modified: pyplusplus_dev/pyplusplus/module_creator/class_organizer.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/class_organizer.py 2006-07-11 09:05:55 UTC (rev 295)
+++ pyplusplus_dev/pyplusplus/module_creator/class_organizer.py 2006-07-11 12:39:43 UTC (rev 296)
@@ -10,12 +10,15 @@
WHITE = 0
GRAY = 1
BLACK = 2
+
class class_organizer_t(object):
def __init__( self, decls ):
- object.__init__( self )
+ object.__init__( self )
+
self.__classes = filter( lambda x: isinstance( x, declarations.class_t )
- , decls )
+ , decls )
+ self.__classes.sort( lambda cls1, cls2: cmp( cls1.decl_string, cls2.decl_string ) )
self.__dependencies_graph = self._build_graph()
self.__time = 0
self.__colors = dict( zip( self.__dependencies_graph.keys()
Modified: pyplusplus_dev/pyplusplus/module_creator/creator.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-07-11 09:05:55 UTC (rev 295)
+++ pyplusplus_dev/pyplusplus/module_creator/creator.py 2006-07-11 12:39:43 UTC (rev 296)
@@ -113,7 +113,7 @@
decls = filter( lambda x: not x.ignore, decls )
return decls
- def _reorder_decls(self, decls ):
+ def _reorder_decls(self, decls ):
classes = filter( lambda x: isinstance( x, declarations.class_t )
, decls )
@@ -126,15 +126,33 @@
#type should be exported before it can be used.
variables = []
enums = []
- others = []
+ others = []
+ classes = []
+ constructors = []
for inst in ordered:
if isinstance( inst, declarations.variable_t ):
variables.append( inst )
elif isinstance( inst, declarations.enumeration_t ):
- enums.append( inst )
+ enums.append( inst )
+ elif isinstance( inst, ( declarations.class_t, declarations.class_declaration_t ) ):
+ classes.append( inst )
+ elif isinstance( inst, declarations.constructor_t ):
+ constructors.append( inst )
else:
- others.append( inst )
- new_ordered = enums
+ others.append( inst )
+ #this will prevent from py++ to change the order of generated code
+ cmp_by_name = lambda d1, d2: cmp( d1.name, d2.name )
+ cmp_by_line = lambda d1, d2: cmp( d1.location.line, d2.location.line )
+
+ enums.sort( cmp=cmp_by_name )
+ others.sort( cmp=cmp_by_name )
+ variables.sort( cmp=cmp_by_name )
+ constructors.sort( cmp=cmp_by_line )
+
+ new_ordered = []
+ new_ordered.extend( enums )
+ new_ordered.extend( classes )
+ new_ordered.extend( constructors )
new_ordered.extend( others )
new_ordered.extend( variables )
return new_ordered #
@@ -168,7 +186,7 @@
return ordered_members
def _does_class_have_smth_to_export(self, exportable_members ):
- return bool( self._filter_decls( self._reorder_decls( exportable_members ) ) )
+ return bool( self._filter_decls( exportable_members ) )
def _is_constructor_of_abstract_class( self, decl ):
assert isinstance( decl, declarations.constructor_t )
@@ -242,8 +260,11 @@
if self.__is_same_func( f, f_defined ):
break
else:
- not_reimplemented_funcs.add( f )
- return not_reimplemented_funcs
+ not_reimplemented_funcs.add( f )
+ functions = list( not_reimplemented_funcs )
+ functions.sort( cmp=lambda f1, f2: cmp( ( f1.name, f1.location.as_tuple() )
+ , ( f2.name, f2.location.as_tuple() ) ) )
+ return functions
def _is_wrapper_needed(self, class_inst, exportable_members):
if isinstance( self.curr_decl, declarations.class_t ) \
@@ -657,7 +678,7 @@
self.curr_code_creator.adopt_creator( class_inst )
self.curr_code_creator = class_inst
- for decl in self._filter_decls( self._reorder_decls( exportable_members ) ):
+ for decl in exportable_members:
self.curr_decl = decl
declarations.apply_visitor( self, decl )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|