Ejemplo n.º 1
0
def ClassTemplate(cur, cxx, errors=None):
    identifier = cur.displayname
    p = []
    for x in cur.get_children():
        if x.kind == CursorKind.TEMPLATE_TYPE_PARAMETER:
            p.append('typename %s' % x.spelling)
        elif x.kind == CursorKind.TEMPLATE_NON_TYPE_PARAMETER:
            p.append('%s %s' % (x.type.spelling, x.spelling))
    # now we need this to distinguish struct/union/class template:
    # damn libclang!! children here should really allow for
    # this by having a STRUCT_DECL, UNION_DECL or CLASS_DECL !
    # Or, if implicit CLASS_DECL due to being a CLASS_TEMPLATE,
    # then there should be a STRUCT_TEMPLATE as well.
    toks = [x.spelling for x in cur.get_tokens()]
    try:
        i = toks.index(cur.spelling)
        k = toks[i - 1]
    except ValueError:
        k = 'struct'
    identifier = "%s %s" % (k, identifier)
    if conf.DEBUG: echo('\t' * g_indent + str(identifier))
    # ok so now proceed with the "class" parsing:
    S = cClass()
    SetStructured(cur, S, errors)
    return identifier, cTemplate(params=p, cClass=S)
Ejemplo n.º 2
0
def cTemplate_C(obj,db,recursive):
    identifier = obj.get_basename()
    template = obj.get_template()
    # get the cxx type object, for namespaces:
    tn = cxx_type(identifier)
    namespace = tn.show_base(kw=False,ns=False)
    #prepare query if recursion is needed:
    if isinstance(recursive,set):
        Q = True
        recursive.update(struct_letters)
        recursive.add(tn.lbase)
        for t in obj['params']:
            if t.startswith('typename '):
                t = t.replace('typename ','')
                recursive.add(t)
    else:
        Q = None
    R = []
    #S holds template output lines:
    S = [u'template%s'%template]
    if 'cClass' in obj:
        from ccrawl.core import cClass
        o = cClass(obj['cClass'])
        o.identifier = identifier
        x = cClass_C(o,db,recursive)
    if 'cFunc' in obj:
        from ccrawl.core import cFunc
        o = cFunc(obj['cFunc'])
        o.identifier = identifier
        x = cFunc_C(o,db,recursive)
    x = x.split('\n\n')
    S.append(x.pop())
    if len(x): R.append(x[0])
    return '\n'.join(R)+'\n'.join(S)
Ejemplo n.º 3
0
def ClassDecl(cur, cxx, errors=None):
    typename = "class %s" % (cur.type.get_canonical().spelling)
    if conf.DEBUG:
        echo("\t" * g_indent + "%s" % typename)
    S = cClass()
    SetStructured(cur, S, errors)
    if conf.VERBOSE:
        secho("  %s: %s" % (S.__class__.__name__, typename))
    return typename, S
Ejemplo n.º 4
0
def UnionDecl(cur, cxx, errors=None):
    typename = cur.type.spelling
    if cxx:
        typename = cur.type.get_canonical().spelling
    if not typename.startswith('union '):
        typename = 'union ' + typename
    typename = get_uniq_typename(typename)
    if conf.DEBUG: echo('\t' * g_indent + 'make unique: %s' % typename)
    S = cClass() if cxx else cUnion()
    SetStructured(cur, S, errors)
    return typename, S
Ejemplo n.º 5
0
def UnionDecl(cur, cxx, errors=None):
    typename = cur.type.spelling
    if cxx:
        typename = cur.type.get_canonical().spelling
    if not typename.startswith("union "):
        typename = "union " + typename
    typename = get_uniq_typename(typename)
    if conf.DEBUG:
        echo("\t" * g_indent + "make unique: %s" % typename)
    S = cClass() if cxx else cUnion()
    SetStructured(cur, S, errors)
    if conf.VERBOSE:
        secho("  %s: %s" % (S.__class__.__name__, typename))
    return typename, S
Ejemplo n.º 6
0
def cTemplate_C(obj, db, recursive):
    identifier = obj.get_basename()
    template = obj.get_template()
    # get the cxx type object, for namespaces:
    tn = cxx_type(identifier)
    # namespace = tn.show_base(kw=False,ns=False)
    # prepare query if recursion is needed:
    if isinstance(recursive, set):
        # Q = True
        recursive.update(struct_letters)
        recursive.add(tn.lbase)
        for t in obj["params"]:
            if t.startswith("typename "):
                t = t.replace("typename ", "")
                recursive.add(t)
    else:
        # Q = None
        pass
    R = []
    # S holds template output lines:
    S = [u"template%s" % template]
    if "cClass" in obj:
        from ccrawl.core import cClass

        o = cClass(obj["cClass"])
        o.identifier = identifier
        x = cClass_C(o, db, recursive)
    if "cFunc" in obj:
        from ccrawl.core import cFunc

        o = cFunc(obj["cFunc"])
        o.identifier = identifier
        x = cFunc_C(o, db, recursive)
    x = x.split("\n\n")
    S.append(x.pop())
    if len(x):
        R.append(x[0])
    return "\n".join(R) + "\n".join(S)
Ejemplo n.º 7
0
def ClassDecl(cur, cxx, errors=None):
    typename = "class %s" % (cur.type.get_canonical().spelling)
    if conf.DEBUG: echo('\t' * g_indent + '%s' % typename)
    S = cClass()
    SetStructured(cur, S, errors)
    return typename, S