def keep_using(c): #if not c.raw_comment : return False if namespace: qualified_ns = CL.get_namespace(c) if qualified_ns != namespace: return False return (c.location.file.name == self.filename) if self.target_file_only else True
def make_synopsis_one_function(f, number): """ Given the AST node for a function f, returns the synopsis number : the number of the function (in a list of overloads) """ ns = CL.get_namespace( f) + '::' # to remove the myclass:: from the types of arg and rtype is_not_constructor = not getattr(f, 'is_constructor', False) template = make_synopsis_template_decl(f) result_type = (process_type_name(f.result_type) + ' ') if is_not_constructor else '' name = " %s " % f.spelling.strip( ) if is_not_constructor else f.spelling.split( '<', 1)[0] # eliminate the <> in the constructor name qualif = CL.get_method_qualification(f) + (' noexcept' if getattr( f, 'noexcept', False) else '') params1 = [(p.type, p.spelling, CL.get_param_default_value(p)) for p in CL.get_params(f)] params = [ "%s %s" % (process_type_name(t), ":param:`%s`" % n if n else '') + (" = %s" % d if d else "") for t, n, d in params1 ] # same with no rst decoration params_no_role = [ "%s %s" % (t.spelling, n) + (" = %s" % d if d else "") for t, n, d in params1 ] # first attempt : one line, else multiple line nspace = 8 if number >= 10 else 7 sep = nspace * ' ' + '| ' sep2 = ',\n' + sep + ' ' * len(name) res1 = sep + result_type + ":red:`%s` " % name.strip() + '(' # First compute the result without any rst decoroation to compute the lengths res_no_role = res1 + ', '.join(x for x in params_no_role) if len(res_no_role ) > global_vars.synopsis_maxlen_function: # not good, need to split res = res1 + sep2.join( x for x in params ) # DEBUG + "%s %s"%(len(res_no_role) , global_vars.synopsis_maxlen_function) else: res = res1 + ', '.join(x for x in params) # brief = f.processed_doc.brief_doc #r = ('%s:cppbrief:`%s`\n'%(sep,brief) if brief else '') + ('%s:green:`%s`\n'%(sep,template) if template else '') + res + ') ' + qualif r = ('%s:green:`%s`\n' % (sep, template) if template else '') + res + ') ' + qualif return r.strip()
def keep_cls(self, 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_cls(self, c): """ The filter to keep a class/struct or an enum : if we a namespace list, it must be in it. if we have an explicit self.classes : c must be into it if target_file_only it has to be in the file given to c++2py """ if CL.is_template(c) or ("ignore_in_python" in CL.get_annotations(c)): 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 if self.classes: return c.spelling in self.classes or CL.fully_qualified(c) in self.classes return (c.location.file.name == self.filename) if self.target_file_only else True
def keep_cls(self, c): """ The filter to keep a class/struct or an enum : if we a namespace list, it must be in it. if we have an explicit self.classes : c must be into it else it has to be in the file given to c++2py """ if CL.is_template(c) or ("ignore_in_python" in CL.get_annotations(c)): return False if self.namespaces: ns = CL.get_namespace(c) if not any((x in ns) for x in self.namespaces): return False if self.classes: return c.spelling in self.classes or CL.fully_qualified( c) in self.classes return c.location.file.name == self.filename
def make_synopsis_one_function(f, number): """ Given the AST node for a function f, returns the synopsis """ # If @synopsis was given manually #syn = f.processed_doc.elements.pop('synopsis', '') #if syn : return [syn] ns = CL.get_namespace( f) + '::' # to remove the myclass:: from the types of arg and rtype is_not_constructor = not getattr(f, 'is_constructor', False) template = make_synopsis_template_decl(f) result_type = (process_rtype(f.result_type.spelling, remove=ns) + ' ') if is_not_constructor else '' name = " %s " % f.spelling.strip( ) if is_not_constructor else f.spelling.split( '<', 1)[0] # eliminate the <> in the constructor name qualif = CL.get_method_qualification(f) + (' noexcept' if getattr( f, 'noexcept', False) else '') #for p in CL.get_params(f): # print p.type.get_canonical().spelling params1 = [(p.type.spelling, p.spelling, CL.get_param_default_value(p)) for p in CL.get_params(f)] params = [ "%s %s" % (process_param_type(t, remove=ns), ":param:`%s`" % n if n else '') + (" = %s" % d if d else "") for t, n, d in params1 ] # first attempt : one line nspace = 8 if number >= 10 else 7 sep = nspace * ' ' + '| ' sep2 = ',\n' + sep + ' ' res1 = sep + result_type + ":red:`%s` " % name.strip() + '(' res = res1 + ', '.join(x for x in params) if len(res) > maxlen: # not good, need to split res = res1 + sep2.join(x for x in params) brief = f.processed_doc.brief_doc r = ('%s:cppbrief:`%s`\n' % (sep, brief) if brief else '') + ('%s:green:`%s`\n' % (sep, template) if template else '') + res + ') ' + qualif return r.strip()
def keep_cls(c): """ Given a class node, shall we keep it ? Reject if no raw_comment. Keeps if its namespace is EXACTLY in self.namespaces e.g. A::B::cls will be kept iif A::B is in self.namespaces, not it A is. 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 c.spelling.startswith('_') : return False if not c.raw_comment : return False if namespace: qualified_ns = CL.get_namespace(c) if qualified_ns != namespace : return False return (c.location.file.name == self.filename) if self.target_file_only else True
def keep_cls(c): """ Given a class node, shall we keep it ? Reject if no raw_comment. Keeps if its namespace is EXACTLY in self.namespaces e.g. A::B::cls will be kept iif A::B is in self.namespaces, not it A is. 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 c.spelling.startswith('_') : return False # FIXME : Commented for debug if not c.raw_comment : return False if namespace: qualified_ns = CL.get_namespace(c) if qualified_ns != namespace : return False return (c.location.file.name == self.filename) if self.target_file_only else True
def make_synopsis_one_function(f, number): """ Given the AST node for a function f, returns the synopsis number : the number of the function (in a list of overloads) """ ns = CL.get_namespace(f) + '::' # to remove the myclass:: from the types of arg and rtype is_not_constructor = not getattr(f, 'is_constructor', False) template = make_synopsis_template_decl(f) result_type = (process_type_name(f.result_type) + ' ') if is_not_constructor else '' name = " %s "%f.spelling.strip() if is_not_constructor else f.spelling.split('<',1)[0] # eliminate the <> in the constructor name qualif = CL.get_method_qualification(f) + (' noexcept' if getattr(f,'noexcept',False) else '') params1 = [(p.type, p.spelling, CL.get_param_default_value(p)) for p in CL.get_params(f)] params = ["%s %s"%(process_type_name(t), ":param:`%s`"%n if n else '') + (" = %s"%d if d else "") for t,n,d in params1] # same with no rst decoration params_no_role = ["%s %s"%(t.spelling, n) + (" = %s"%d if d else "") for t,n,d in params1] # first attempt : one line, else multiple line nspace = 8 if number>=10 else 7 sep = nspace*' ' + '| ' sep2 = ',\n' + sep + ' ' res1 = sep + result_type + ":red:`%s` "%name.strip() + '(' # First compute the result without any rst decoroation to compute the lengths res_no_role = res1 + ', '.join(x for x in params_no_role) if len(res_no_role) > global_vars.synopsis_maxlen_function: # not good, need to split res = res1 + sep2.join(x for x in params) # DEBUG + "%s %s"%(len(res_no_role) , global_vars.synopsis_maxlen_function) else: res = res1 + ', '.join(x for x in params) brief = f.processed_doc.brief_doc r = ('%s:cppbrief:`%s`\n'%(sep,brief) if brief else '') + ('%s:green:`%s`\n'%(sep,template) if template else '') + res + ') ' + qualif return r.strip()
def analyse_one_ns(self, namespace): print "*** Namespace %s ***" % namespace # ---------------------- # Filters # ---------------------- def keep_ns(n): """Given a namespace node n, shall we keep it ?""" ns = CL.fully_qualified(n) return ns in namespace def keep_cls(c): """ Given a class node, shall we keep it ? Reject if no raw_comment. Keeps if its namespace is EXACTLY in self.namespaces e.g. A::B::cls will be kept iif A::B is in self.namespaces, not it A is. 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 c.spelling.startswith('_'): return False # FIXME : Commented for debug if not c.raw_comment: return False if namespace: qualified_ns = CL.get_namespace(c) if qualified_ns != namespace: return False return (c.location.file.name == self.filename) if self.target_file_only else True def keep_fnt(f): #print "RAW", f.spelling, f.raw_comment if not f.raw_comment: return False if f.spelling.startswith('operator') or f.spelling in [ 'begin', 'end' ]: return False return keep_cls(f) def keep_using(c): #if not c.raw_comment : return False if namespace: qualified_ns = CL.get_namespace(c) if qualified_ns != namespace: return False return (c.location.file.name == self.filename) if self.target_file_only else True # ---------------------- # 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) # make a list to avoid exhaustion of the generator D = OrderedDict() for cls in classes: cls.namespace = CL.get_namespace(cls) cls.name = CL.get_name_with_template_specialization( cls) or cls.spelling cls.fully_qualified_name = '::'.join([cls.namespace, cls.name]) cls.name_for_label = synopsis.make_label(cls.fully_qualified_name) D[cls.fully_qualified_name] = cls # print "CLASS", cls.name # print "CLASS", cls.fully_qualified_name # print "CLASS", cls.name_for_label # print "CLASS", "----------------------" print " ... class : %s" % cls.fully_qualified_name, cls.location #assert ',' not in cls.fully_qualified_name, "Not implemented" # process the doc of the class and add it to the node cls.processed_doc = ProcessedDoc(cls) # all methods and constructors # we build a OrderedDict of the constructors (first) and the methods, in order of declaration constructors = list(CL.get_constructors(cls)) for f in constructors: f.is_constructor = True # tag them for later use methods = OrderedDict() if constructors: methods['constructor'] = constructors methods.update( self.regroup_func_by_names(CL.get_methods( cls, True))) # True : with inherited #methods.update(self.regroup_func_by_names(CL.get_methods(cls, True, keep = keep_fnt))) # True : with inherited # all non member functions friend_functions = self.regroup_func_by_names( CL.get_friend_functions(cls)) #friend_functions = self.regroup_func_by_names(CL.get_friend_functions(cls, keep = keep_fnt)) # Analyse the doc string for all methods and functions, and store the result in the node itself for (n, f_list) in (methods.items() + friend_functions.items()): for f in f_list: f.processed_doc = ProcessedDoc(f) # attach to the node cls.methods, cls.friend_functions = methods, friend_functions # members cls.members = list(CL.get_members(cls, True)) # using cls.usings = list(CL.get_usings(cls)) # , keep_using)) # Eliminate doublons, like forward declarations classes = D.values() # A list of AST nodes for the methods and functions functions = CL.get_functions(self.root, keep_fnt, traverse_namespaces=True, keep_ns=keep_ns) functions = list( functions) # make a to avoid exhaustion of the generator # Analyse the doc strings for f in functions: f.processed_doc = ProcessedDoc(f) # Find the using of this namespace, and make the list unique based on the fully_qualified_name usings = list( CL.get_usings(self.root, keep_using, traverse_namespaces=True, keep_ns=keep_ns)) D = OrderedDict() for c in usings: c.namespace = CL.get_namespace(c) c.fully_qualified_name = '::'.join([c.namespace, c.spelling]) D[c.fully_qualified_name] = c usings = D.values() return classes, functions, usings
def keep_using(c): #if not c.raw_comment : return False if namespace: qualified_ns = CL.get_namespace(c) if qualified_ns != namespace : return False return (c.location.file.name == self.filename) if self.target_file_only else True
def analyse_one_ns(self, namespace): print "*** Namespace %s ***"%namespace # ---------------------- # Filters # ---------------------- def keep_ns(n): """Given a namespace node n, shall we keep it ?""" ns = CL.fully_qualified(n) return ns in namespace def keep_cls(c): """ Given a class node, shall we keep it ? Reject if no raw_comment. Keeps if its namespace is EXACTLY in self.namespaces e.g. A::B::cls will be kept iif A::B is in self.namespaces, not it A is. 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 c.spelling.startswith('_') : return False # FIXME : Commented for debug if not c.raw_comment : return False if namespace: qualified_ns = CL.get_namespace(c) if qualified_ns != namespace : return False return (c.location.file.name == self.filename) if self.target_file_only else True def keep_fnt(f): #print "RAW", f.spelling, f.raw_comment if not f.raw_comment : return False if f.spelling.startswith('operator') or f.spelling in ['begin','end'] : return False return keep_cls(f) def keep_using(c): #if not c.raw_comment : return False if namespace: qualified_ns = CL.get_namespace(c) if qualified_ns != namespace : return False return (c.location.file.name == self.filename) if self.target_file_only else True # ---------------------- # 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) # make a list to avoid exhaustion of the generator D = OrderedDict() for cls in classes: cls.namespace = CL.get_namespace(cls) cls.name = CL.get_name_with_template_specialization(cls) or cls.spelling cls.fully_qualified_name = '::'.join([cls.namespace, cls.name]) cls.name_for_label = synopsis.make_label(cls.fully_qualified_name) D[cls.fully_qualified_name] = cls # print "CLASS", cls.name # print "CLASS", cls.fully_qualified_name # print "CLASS", cls.name_for_label # print "CLASS", "----------------------" print " ... class : %s"%cls.fully_qualified_name, cls.location #assert ',' not in cls.fully_qualified_name, "Not implemented" # process the doc of the class and add it to the node cls.processed_doc = ProcessedDoc(cls) # all methods and constructors # we build a OrderedDict of the constructors (first) and the methods, in order of declaration constructors = list(CL.get_constructors(cls)) for f in constructors : f.is_constructor = True # tag them for later use methods = OrderedDict() if constructors: methods['constructor'] = constructors methods.update(self.regroup_func_by_names(CL.get_methods(cls, True))) # True : with inherited #methods.update(self.regroup_func_by_names(CL.get_methods(cls, True, keep = keep_fnt))) # True : with inherited # all non member functions friend_functions = self.regroup_func_by_names(CL.get_friend_functions(cls)) #friend_functions = self.regroup_func_by_names(CL.get_friend_functions(cls, keep = keep_fnt)) # Analyse the doc string for all methods and functions, and store the result in the node itself for (n,f_list) in (methods.items() + friend_functions.items()): for f in f_list: f.processed_doc = ProcessedDoc(f) # attach to the node cls.methods, cls.friend_functions = methods, friend_functions # members cls.members = list(CL.get_members(cls, True)) # using cls.usings = list(CL.get_usings(cls)) # , keep_using)) # Eliminate doublons, like forward declarations classes = D.values() # A list of AST nodes for the methods and functions functions = CL.get_functions(self.root, keep_fnt, traverse_namespaces = True, keep_ns = keep_ns) functions = list(functions) # make a to avoid exhaustion of the generator # Analyse the doc strings for f in functions: f.processed_doc = ProcessedDoc(f) # Find the using of this namespace, and make the list unique based on the fully_qualified_name usings = list(CL.get_usings(self.root, keep_using, traverse_namespaces = True, keep_ns = keep_ns)) D = OrderedDict() for c in usings: c.namespace = CL.get_namespace(c) c.fully_qualified_name = '::'.join([c.namespace, c.spelling]) D[c.fully_qualified_name] = c usings = D.values() return classes, functions, usings