def __merge_user_code(self): for code in self.module_code_tail: self.code_creator.adopt_creator(code_creators.custom_text_t(code)) for code in self.module_code_head: self.code_creator.adopt_creator(code_creators.custom_text_t(code), 0)
def customize_module( mb ): extmodule = mb.code_creator extmodule.license = customization_data.license # Insert a custom init call extmodule.adopt_creator( code_creators.custom_text_t('extern void InitialiseTnFOXPython();\n\n'), len(extmodule.creators)-1) extmodule.body.adopt_creator( code_creators.custom_text_t(' InitialiseTnFOXPython();\n\n'), 0) # Remove all standard headers in favour of precompiled header includes = filter( lambda creator: isinstance( creator, code_creators.include_t ) , extmodule.creators ) map( lambda creator: extmodule.remove_creator( creator ), includes ) position = extmodule.last_include_index() + 1 extmodule.adopt_creator( code_creators.namespace_using_t('::FX'), position ) extmodule.user_defined_directories.append( settings.generated_files_dir ) extmodule.adopt_include( code_creators.include_t( header='../common.h' ) ) extmodule.precompiled_header = '../common.h' extmodule.adopt_include( code_creators.include_t( header='../patches.cpp.h' ) ) # Fix bug in gccxml where default args with function as value gain an extra () try: constr = mb.constructor( 'FXPrimaryButton', arg_types=[None]*15 ) constr.arguments[10].default_value = '(FX::FXWindow::defaultPadding() * 4)' constr.arguments[11].default_value = '(FX::FXWindow::defaultPadding() * 4)' except: pass # Patch default args with enums to be number (to avoid undeclared enum problem) def args_declaration_wa( self ): args = [] for index, arg in enumerate( self.declaration.arguments ): result = arg.type.decl_string + ' ' + self.argument_name(index) if arg.default_value: result += '=%s' % arg.wrapper_default_value args.append( result ) if len( args ) == 1: return args[ 0 ] return ', '.join( args ) code_creators.calldef.calldef_wrapper_t.args_declaration = args_declaration_wa allfuncs = mb.calldefs() for func in allfuncs: #print type(func), type(func.parent), func for arg in func.arguments: if not arg.default_value: continue arg.wrapper_default_value = arg.default_value if not declarations.is_enum( arg.type ): continue enum_ = declarations.enum_declaration( arg.type ) if isinstance( enum_.parent, declarations.namespace_t ): continue #global enum # Be lazy, and just lookup the last part value = arg.default_value[ arg.default_value.rfind('::')+2: ] arg.default_value = arg.type.declaration.values[ value ] + '/*' + arg.default_value + '*/'
def __merge_user_code( self ): for code in self.__declarations_code_tail: self.code_creator.add_declaration_code( code, -1 ) for code in self.__declarations_code_head: self.code_creator.add_declaration_code( code, 0 ) body = self.code_creator.body for code in self.__registrations_code_tail: body.adopt_creator( code_creators.custom_text_t( code ), -1 ) for code in self.__registrations_code_head: body.adopt_creator( code_creators.custom_text_t( code ), 0 )
def split_creators( self, creators, pattern, function_name, registrator_pos ): """Write non-class creators into a particular .h/.cpp file. :param creators: The code creators that should be written :type creators: list of :class:`code_creators.code_creator_t` :param pattern: Name pattern that is used for constructing the final output file name :type pattern: str :param function_name: "register" function name :type function_name: str :param registrator_pos: The position of the code creator that creates the code to invoke the "register" function. :type registrator_pos: int """ if not creators: return file_pattern = self.extmodule.body.name + pattern file_path = os.path.join( self.directory_path, file_pattern ) header_name = file_path + self.HEADER_EXT self.write_file( header_name , self.create_header( file_pattern, self.create_function_code( function_name ) ) ) self.write_file( file_path + self.SOURCE_EXT , self.create_source( file_pattern, function_name, creators )) for creator in creators: creator.create = lambda: '' self.extmodule.body.adopt_creator( code_creators.custom_text_t( function_name + '();' ) , registrator_pos) self.include_creators.append( code_creators.include_t( header_name ) ) self.split_header_names.append(header_name) self.split_method_names.append(function_name)
def addEndText(self, text): """Add C++ source code to the end of the main source file. @param text: A string containing valid C++ source code. @type text: str """ self.addEndCreator(code_creators.custom_text_t(text) )
def addBodyTailText(self, text): """Add C++ source code to the module initialization function. @param text: A string containing valid C++ source code. @type text: str """ self.addBodyTailCreator(code_creators.custom_text_t(text) )
def split_creators( self, creators, pattern, function_name, registrator_pos ): """Write non-class creators into a particular .h/.cpp file. @param creators: The code creators that should be written @type creators: list of code_creator_t @param pattern: Name pattern that is used for constructing the final output file name @type pattern: str @param function_name: The name of the register_xyz() function @type function_name: str @param registrator_pos: The position of the code creator that creates the code to invoke the register_xyz() function. @type registrator_pos: int """ if not creators: return file_pattern = self.extmodule.body.name + pattern file_path = os.path.join( self.directory_path, file_pattern ) header_name = file_path + self.HEADER_EXT self.write_file( header_name , self.create_header( file_pattern, self.create_function_code( function_name ) ) ) self.write_file( file_path + self.SOURCE_EXT , self.create_source( file_pattern, function_name, creators )) for creator in creators: creator.create = lambda: '' self.extmodule.body.adopt_creator( code_creators.custom_text_t( function_name + '();' ) , registrator_pos) self.include_creators.append( code_creators.include_t( header_name ) ) self.split_header_names.append(header_name) self.split_method_names.append(function_name)
def addEndText(self, text): """Add C++ source code to the end of the main source file. @param text: A string containing valid C++ source code. @type text: str """ self.addEndCreator(code_creators.custom_text_t(text))
def addBodyTailText(self, text): """Add C++ source code to the module initialization function. @param text: A string containing valid C++ source code. @type text: str """ self.addBodyTailCreator(code_creators.custom_text_t(text))
def create_explanation(cls): msg = '//WARNING: the next line of code will not compile, because "%s" does not have operator== !' msg = msg % cls.indexing_suite.element_type.decl_string return code_creators.custom_text_t( msg, False )
def __merge_user_code( self ): for code in self.module_code_tail: self.code_creator.adopt_creator( code_creators.custom_text_t( code ) ) for code in self.module_code_head: self.code_creator.adopt_creator( code_creators.custom_text_t( code ), 0 )