def __init__(self, global_ns, library_path, exported_symbols): declarations.decl_visitor_t.__init__(self) self.logger = _logging_.loggers.module_builder self.decl_logger = _logging_.loggers.declarations self.global_ns = global_ns self.__library_path = library_path self.__exported_symbols = exported_symbols self.__exported_decls = set(exported_symbols.itervalues()) self.module = code_creators.ctypes_module_t(global_ns) self.__dependencies_manager = dependencies_manager.manager_t( self.decl_logger) #bookmark for class introductions self.__class_ccs = code_creators.bookmark_t() #bookmark for class deinitions self.__class_defs_ccs = code_creators.bookmark_t() #bookmark for typedef definitions self.__typedefs_ccs = code_creators.bookmark_t() self.curr_decl = global_ns self.curr_code_creator = self.module #mapping between class declaration and class introduction code creator self.__class2introduction = {} #mapping between namespace and its code creator self.__namespace2pyclass = {}
def __init__( self , global_ns , library_path , exported_symbols ): declarations.decl_visitor_t.__init__(self) self.logger = _logging_.loggers.module_builder self.decl_logger = _logging_.loggers.declarations self.global_ns = global_ns self.__library_path = library_path self.__exported_symbols = exported_symbols self.__exported_decls = set( exported_symbols.itervalues() ) self.module = code_creators.ctypes_module_t( global_ns ) self.__dependencies_manager = dependencies_manager.manager_t(self.decl_logger) #bookmark for class introductions self.__class_ccs = code_creators.bookmark_t() #bookmark for class deinitions self.__class_defs_ccs = code_creators.bookmark_t() #bookmark for typedef definitions self.__typedefs_ccs = code_creators.bookmark_t() self.curr_decl = global_ns self.curr_code_creator = self.module #mapping between class declaration and class introduction code creator self.__class2introduction = {} #mapping between namespace and its code creator self.__namespace2pyclass = {}
def create(self): """ create and return the module for the extension - code creators tree root :rtype: :class:`code_creators.module_t` """ # Invoke the appropriate visit_*() method on all decls ccc = self.curr_code_creator ccc.adopt_creator(code_creators.import_t('ctypes')) ccc.adopt_creator( code_creators.import_t(code_repository.ctypes_utils.file_name)) ccc.adopt_creator(code_creators.separator_t()) ccc.adopt_creator( code_creators.library_reference_t(self.__library_path)) ccc.adopt_creator( code_creators.name_mappings_t(self.__exported_symbols)) ccc.adopt_creator(code_creators.separator_t()) #adding namespaces global_ns_cc = code_creators.bookmark_t() ccc.adopt_creator(global_ns_cc) ccc.adopt_creator(self.__class_ccs) self.__namespace2pyclass[self.global_ns] = global_ns_cc #adding class introductions - special case because of hierarchy f = lambda cls: self.__should_generate_code( cls ) \ and isinstance( cls.parent, declarations.namespace_t ) ns_classes = self.global_ns.classes(f, recursive=True, allow_empty=True) ns_classes = sort_algorithms.sort_classes(ns_classes, include_vars=True) for class_ in ns_classes: self.__add_class_introductions(self.__class_ccs, class_) ccc.adopt_creator(self.__class_defs_ccs) ccc.adopt_creator(code_creators.separator_t()) ccc.adopt_creator(self.__typedefs_ccs) declarations.apply_visitor(self, self.curr_decl) self.__dependencies_manager.inform_user() return self.module
def create(self ): """ create and return the module for the extension - code creators tree root :rtype: :class:`code_creators.module_t` """ # Invoke the appropriate visit_*() method on all decls ccc = self.curr_code_creator ccc.adopt_creator( code_creators.import_t( 'ctypes' ) ) ccc.adopt_creator( code_creators.import_t( code_repository.ctypes_utils.file_name ) ) ccc.adopt_creator( code_creators.separator_t() ) ccc.adopt_creator( code_creators.library_reference_t( self.__library_path ) ) ccc.adopt_creator( code_creators.name_mappings_t( self.__exported_symbols ) ) ccc.adopt_creator( code_creators.separator_t() ) #adding namespaces global_ns_cc = code_creators.bookmark_t() ccc.adopt_creator( global_ns_cc ) ccc.adopt_creator( self.__class_ccs ) self.__namespace2pyclass[ self.global_ns ] = global_ns_cc #adding class introductions - special case because of hierarchy f = lambda cls: self.__should_generate_code( cls ) \ and isinstance( cls.parent, declarations.namespace_t ) ns_classes = self.global_ns.classes( f, recursive=True, allow_empty=True) ns_classes = sort_algorithms.sort_classes( ns_classes, include_vars=True ) for class_ in ns_classes: self.__add_class_introductions( self.__class_ccs, class_ ) ccc.adopt_creator( self.__class_defs_ccs ) ccc.adopt_creator( code_creators.separator_t() ) ccc.adopt_creator( self.__typedefs_ccs ) declarations.apply_visitor( self, self.curr_decl ) self.__dependencies_manager.inform_user() return self.module