def render(message, d): for f_name, f_overloads in d.items(): print " ...... %s [%s]" % (f_name, message) r = renderers.render_fnt(parent_class=c, f_name=f_name, f_overloads=f_overloads) safe_write(f_name, r)
def render(mess, d): for f_name, f_overloads in d.items(): print " ...... %s %s" % (mess, f_name) r = render_fnt(parent_class=c, f_name=f_name, f_overloads=f_overloads) safe_write(f_name, r)
def run_one_ns(self, namespace, classes, functions, usings): # c : AST node of name A::B::C::clsname makes and cd into A/B/C def mkchdir_for_one_node(node): mkchdir(* ( CL.fully_qualified_name(node).split('::')[:-1])) # First treat the class for c in classes: if not c.spelling.strip() : print "Skipping a class with an empty name !" continue # One directory for the class : make it and cd into it cur_dir = os.getcwd() mkchdir_for_one_node(c) # the file for the class r = renderers.render_cls(c, c.methods, c.friend_functions) safe_write(synopsis.replace_ltgt(c.name), r) # create a directory with the class name and cd into it mkchdir(synopsis.replace_ltgt(c.name)) # write a file for each function def render(message, d) : for f_name, f_overloads in d.items(): print " ...... %s [%s]"%(f_name, message) r = renderers.render_fnt(parent_class = c, f_name = f_name, f_overloads = f_overloads) safe_write(f_name, r) render('method', c.methods) render('non member function', c.friend_functions) # Change back to up directory os.chdir(cur_dir) # Now treat the functions functions_by_name = self.regroup_func_by_names(functions) docs = dict ( (n, [ProcessedDoc(f) for f in fs]) for (n,fs) in functions_by_name.items()) for f_name, f_overloads in functions_by_name.items(): print " ... function " + f_name, " [", f_overloads[0].location.file.name, ']' cur_dir = os.getcwd() mkchdir_for_one_node(f_overloads[0]) r = renderers.render_fnt(parent_class = None, f_name = f_name, f_overloads = f_overloads) safe_write(f_name, r) os.chdir(cur_dir) # namespace resume function cur_dir = os.getcwd() mkchdir(*namespace.split('::')[:-1]) r = renderers.render_ns(namespace, functions_by_name, classes, usings) ns = namespace.split('::',1)[-1] safe_write(ns, r) os.chdir(cur_dir)
def run_one_ns(self, namespace, classes, functions, usings): # c : AST node of name A::B::C::clsname makes and cd into A/B/C def mkchdir_for_one_node(node): mkchdir(* ( CL.fully_qualified_name(node).split('::')[:-1])) # First treat the class for c in classes: if not c.spelling.strip() : print "Skipping a class with an empty name !" continue # One directory for the class : make it and cd into it cur_dir = os.getcwd() mkchdir_for_one_node(c) # the file for the class r = renderers.render_cls(c, c.methods, c.friend_functions) safe_write(synopsis.replace_ltgt(c.name), r) # create a directory with the class name and cd into it mkchdir(synopsis.replace_ltgt(c.name)) # write a file for each function def render(message, d) : for f_name, f_overloads in d.items(): print " ...... %s [%s]"%(f_name, message) r = renderers.render_fnt(parent_class = c, f_name = f_name, f_overloads = f_overloads) safe_write(f_name, r) render('method', c.methods) render('non member function', c.friend_functions) # Change back to up directory os.chdir(cur_dir) # Now treat the functions functions_by_name = self.regroup_func_by_names(functions) docs = dict ( (n, [ProcessedDoc(f) for f in fs]) for (n,fs) in functions_by_name.items()) for f_name, f_overloads in functions_by_name.items(): print " ... function " + f_name, " [", f_overloads[0].location.file.name, ']' cur_dir = os.getcwd() mkchdir_for_one_node(f_overloads[0]) r = renderers.render_fnt(parent_class = None, f_name = f_name, f_overloads = f_overloads) safe_write(f_name, r) os.chdir(cur_dir) # namespace resume function cur_dir = os.getcwd() mkchdir(*namespace.split('::')[:-1]) r = renderers.render_ns(namespace, functions_by_name, classes, usings) ns = namespace.split('::',1)[1] safe_write(ns, r) os.chdir(cur_dir)
def render(message, d) : for f_name, f_overloads in d.items(): print " ...... %s [%s]"%(f_name, message) r = renderers.render_fnt(parent_class = c, f_name = f_name, f_overloads = f_overloads) safe_write(f_name, r)
def run(self, output_directory): print "Generating the documentation ..." mkchdir(output_directory) # Filters def keep_ns(n): ns = CL.fully_qualified(n) if 'std' in ns or 'boost' in ns or 'detail' in ns or 'impl' in ns: return False if len(self.namespaces) == 0: return True return any((ns in x) for x in self.namespaces) def keep_cls(c): """ The filter to keep a class/struct or an enum : it must have a raw comment if we a namespace list, it must be in it. if target_file_only it has to be in the file given to c++2py """ if not c.raw_comment: return False if self.namespaces: qualified_ns = CL.get_namespace(c) if not any((x in qualified_ns) for x in self.namespaces): return False return (c.location.file.name == self.filename) if self.target_file_only else True def keep_fnt(f): if not f.raw_comment: return False if f.spelling.startswith('operator') or f.spelling in [ 'begin', 'end' ]: return False return keep_cls(f) # A list of AST nodes for classes classes = CL.get_classes(self.root, keep_cls, traverse_namespaces=True, keep_ns=keep_ns) classes = list(classes) # to avoid exhaustion of the generator # A list of AST nodes for the methods and functions all_functions = CL.get_functions(self.root, keep_fnt, traverse_namespaces=True, keep_ns=keep_ns) all_functions = list( all_functions) # to avoid exhaustion of the generator # Build the doc for all functions for f in all_functions: f.processed_doc = ProcessedDoc(f) # c : AST node of name A::B::C::clsname makes and cd into A/B/C def mkchdir_for_one_node(node): mkchdir(*(CL.fully_qualified_name(node).split('::')[:-1])) # regroup the functions into a list of overloads def regroup_func_by_names(fs): """ Given a list of functions, regroup them by names""" d = OrderedDict() def decay(name): if 'operator' not in name: return name a, ca, c, co = '+ - * /', '+= -= \*= /=', "== !=", r" comparison" d = { '*=': ca, '+=': ca, '/=': ca, '-=': ca, '*': a, '+': a, '/': a, '-': a, '==': c, '!=': c, '<': co, '>': co, '<=': co, '>=': co } n = name.replace('operator', '').strip() return 'operator' + d[n] if n in d else name for f in fs: d.setdefault(decay(f.spelling), []).append(f) return d synopsis.class_list = classes synopsis.class_list_name = [n.spelling for n in classes] for c in classes: if not c.spelling.strip(): print "Skipping a class with an empty name !" continue print " ... class : " + c.spelling, CL.fully_qualified_name( c), c.kind, CL.get_name_with_template_specialization(c) # process the doc of the class and add it to the node c.processed_doc = ProcessedDoc(c) # all methods and constructors constructors = list(CL.get_constructors(c)) for f in constructors: f.is_constructor = True # tag them for later use all_methods = OrderedDict() if constructors: all_methods['constructor'] = constructors all_methods.update(regroup_func_by_names(CL.get_methods( c, True))) # True : with inherited ? # all non member functions all_friend_functions = regroup_func_by_names( CL.get_friend_functions(c)) # process the doc for all methods and functions, and store it in the node. for (n, f_list) in (all_methods.items() + all_friend_functions.items()): for f in f_list: f.processed_doc = ProcessedDoc(f) # One directory for the class cur_dir = os.getcwd() mkchdir_for_one_node(c) # the file for the class r = render_cls(c, all_methods, all_friend_functions) safe_write(c.spelling, r) # create a directory with the class name mkchdir(c.spelling) # write a file for each function def render(mess, d): for f_name, f_overloads in d.items(): print " ...... %s %s" % (mess, f_name) r = render_fnt(parent_class=c, f_name=f_name, f_overloads=f_overloads) safe_write(f_name, r) render('methods', all_methods) render('non member functions', all_friend_functions) # Change back to up directory os.chdir(cur_dir) all_functions = regroup_func_by_names(all_functions) docs = dict((n, [ProcessedDoc(f) for f in fs]) for (n, fs) in all_functions.items()) for f_name, f_overloads in all_functions.items(): print " ... function " + f_name, " [", f_overloads[ 0].location.file.name, ']' cur_dir = os.getcwd() mkchdir_for_one_node(f_overloads[0]) r = render_fnt(parent_class=None, f_name=f_name, f_overloads=f_overloads) safe_write(f_name, r) os.chdir(cur_dir) print "... done"