예제 #1
0
    def make_signature_for_desc(self,
                                f,
                                is_constructor=False,
                                is_free_function=False):
        """Given a node of a function/methods, it makes the signature for desc file"""

        # first format the arguments
        def cls(t):
            tname = util.decay(t)
            tname = tname.replace(' ', '')
            for ns in self.namespace_to_factor:
                tname = re.sub(ns + '::', '', tname)
            return tname

        if util.use_parameter_class(f):
            r = '**%s' % cls(CL.get_params(f).next().type.spelling)
        else:
            plist = [(cls(p.type.spelling), p.spelling,
                      CL.get_param_default_value(p)) for p in CL.get_params(f)]
            r = ', '.join("%s %s" % (t, n) +
                          (" = %s" % d.replace('"', '\\"') if d else "")
                          for t, n, d in plist)

        if is_constructor:
            return "(%s)" % r
        else:
            f_name = f.spelling if not is_free_function else CL.fully_qualified(
                f)
            return ("%s %s (%s)" %
                    (cls(f.result_type.spelling), f_name, r)).strip()
예제 #2
0
def make_synopsis(m, pdoc, decal):
    #assert not m.tparams, "template functions "
    #try :
    syn = pdoc.elements['synopsis']
    if syn: return [syn]
    s = " {name} ({args}) {qualif}"
    if hasattr(m, 'result_type'):
        s = process_rtype(m.result_type.spelling) + s
    #if not CL.is_constructor(m) :
    #  s = process_rtype(getattr(m, 'result_type', None)) + s
    s = make_synopsis_template_decl(m) + "\n" + decal * ' ' + s

    # filter to remove enable_if dummies from the API
    def no_dummy(t, n):
        return not ('enable_if' in t and 'dummy' in n)

    params = [(p.type.spelling, p.spelling, CL.get_param_default_value(p))
              for p in CL.get_params(m)]
    args = ', '.join([
        "%s %s" % (process_param_type(t), n) + (" = %s" % d if d else "")
        for t, n, d in params if no_dummy(t, n)
    ])
    s = s.format(args=args,
                 name=m.spelling.strip(),
                 qualif=CL.get_method_qualification(m))
    if getattr(m, 'noexcept', False): s += ' noexcept'
    r = [x.strip() for x in s.split('\n')]
    L = [x for x in r if x]
    L_lb = [add_linebreaks(x) for x in L]
    return L_lb
예제 #3
0
파일: synopsis.py 프로젝트: phdum/cpp2py
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()
예제 #4
0
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()
예제 #5
0
파일: cpp2desc.py 프로젝트: TRIQS/triqs
    def make_signature_for_desc(self, f, is_constructor = False, is_free_function = False):
        """Given a node of a function/methods, it makes the signature for desc file"""
        # first format the arguments
        def cls(t) :
            tname = util.decay(t)
            tname = tname.replace(' ','')
            for ns in self.namespace_to_factor : 
                tname = re.sub(ns + '::','',tname)
            return tname
        
        if util.use_parameter_class(f) : 
            r = '**%s'%cls(CL.get_params(f).next().type.spelling)
        else:
            plist = [ (cls(p.type.spelling), p.spelling, CL.get_param_default_value(p)) for p in CL.get_params(f)]
            r = ', '.join("%s %s"%(t, n) + (" = %s"%d.replace('"','\\"') if d else "") for t, n, d  in plist ) 

        if is_constructor:
            return "(%s)"%r
        else :
            f_name = f.spelling if not is_free_function else CL.fully_qualified(f)
            return ("%s %s (%s)"%(cls(f.result_type.spelling), f_name, r)).strip()
예제 #6
0
파일: synopsis.py 프로젝트: TRIQS/triqs
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()