Пример #1
0
def declare(n):
    #pickle.dumps(n)
    #global Nodes.nodes
    #debug(Nodes.nodes)
    if not isinstance(n, str):
        n = n.value
    debug("decl %s" % pformat(n))
    
    if n not in gcc.tree.nodes.Nodes.nodes:
        gcc.tree.nodes.Nodes.nodes[n]= {
            #'decl_count':1,
                         #'node': Node(n),
                   'nid': n
        }
        
    else:
        # if 'decl_count' in gcc.tree.nodes.Nodes.nodes[n] :
        #     debug(Nodes.nodes[n]['decl_count'])
        #     #raise Exception("Duplicate Decl %s" %n)
        #     gcc.tree.nodes.Nodes.nodes[n]['decl_count'] = n
        # else:
        #     gcc.tree.nodes.Nodes.nodes[n]['decl_count'] = 1
        pass
    n2 = gcc.tree.transform.Resolver.transform(n)
    #testsize(n2)
    #testsize(gcc.tree.nodes.Nodes.nodes)
    
    return n
Пример #2
0
def reference(n, name):
    return NodeRef(n, name)

    # global stack
    # global Nodes.astack
    # global nodes
    debug("ref %s %s" % (n, name))
    # raise Exception('what')
    # pdb.set_trace()
    if isinstance(n, lex.LexToken):
        n = n.value
    if isinstance(name, lex.LexToken):
        name = name.value
    gcc.tree.nodes.Nodes.aobj2[name] = n
    # Nodes.astack.append([name,n])
    # if n not in gcc.tree.nodes.Nodes.nodes:
    #     gcc.tree.nodes.Nodes.nodes[n] = {
    #         # 'count':1,
    #         # 'node' : Node(n),
    #         "nid": n
    #     }
    # else:
    # if 'count' in  gcc.tree.nodes.Nodes.nodes[n]:
    #    gcc.tree.nodes.Nodes.nodes[n]['count'] = gcc.tree.nodes.Nodes.nodes[n]['count'] +1
    # Nodes.nodes[n]['refs'].append(nd)
    # else:
    #    gcc.tree.nodes.Nodes.nodes[n]['count'] = 1

    # if 'node' not in gcc.tree.nodes.Nodes.nodes[n]:
    #    gcc.tree.nodes.Nodes.nodes[n]['node']= Node(n)

    debug(Nodes.nodes)
    return gcc.tree.nodes.Nodes.nodes[n]
Пример #3
0
    def resolve_name(x):

        debug({"phase": "resolve_name", "x": x})
        # if isinstance(x, basestring):
        #    print "\n\nRESOLVESTR '%s'\n\n" % x
        #    return x

        if isinstance(x, dict):
            if "string" in x:
                # print "\n\nRESOLVE: %s\n" % x['string']
                return x["string"]

        raise Exception(x)
Пример #4
0
    def process_stack(name, val, nt, seen):

        if name == "chain" and nt.endswith("_decl"):  # dont chain decls
            return {"name": "chain", "val": val}

        debug({
            "phase": "process_stack",
            "name": name,
            "val": val,
            "nt": nt,
            "seen": seen,
        })
        # v = Resolver.resolve2(val,seen, name, nt)
        v = Resolver.resolve(Resolver.get_node_objs(val), seen, name)
        return {"name": name, "val": v}
Пример #5
0
    def resolve(d, seen, role):
        debug({"phase": "resolve", "d": d, "role": role, "seen": seen})
        # nt = seen['node_type']

        if "node" not in d:
            return None

        nid = d["node"].nid()
        nt = d["node"].node_type()

        if nid not in seen["seen"]:
            # print ('new %s %s %s\n' % (nid,role,nt))
            seen["seen"][nid] = 1
            seen["stack"].append([nid, role, nt])
            # return
        else:
            # print( 'seen %s\n' % nid)
            return seen["seen"][nid]

        if len(seen["stack"]) > 100:
            # debug(seen)
            return "overflow"
        t = {"__nid__": nid}
        if "astack" in d:
            for x in d["astack"]:
                v = Resolver.process(x, nt, seen)
                if v:
                    t[v["name"]] = v["val"]

        if "stack" in d:
            for x in d["stack"]:
                name = x[0]
                val = x[1]
                v = Resolver.process_stack(name, val, nt, seen)
                if v:
                    t[v["name"]] = v["val"]

        if role == "name":
            # print ("role is name")
            if "name" in t:
                print(("name role : %s" % t["name"]))
                t = Resolver.resolve_name(t["name"])

        seen["seen"][nid] = t
        # print ( "done seen %s -> %s" % (nid, seen['seen'][nid]))
        return t
Пример #6
0
def reference(n, name):
    debug(Nodes.nodes)
    #global stack
    #global Nodes.astack
    #global nodes
    debug("ref %s %s" % (n, name))
    #raise Exception('what')
    #pdb.set_trace()
    if isinstance(n,lex.LexToken):
        n = n.value
    if isinstance(name,lex.LexToken):
        name = name.value
    gcc.tree.nodes.Nodes.aobj2[name]=n
    #Nodes.astack.append([name,n])
    if n not in gcc.tree.nodes.Nodes.nodes:
        gcc.tree.nodes.Nodes.nodes[n]= {
            #'count':1,
                         #'node' : Node(n),
                         'nid': n }
    #else:
        #if 'count' in  gcc.tree.nodes.Nodes.nodes[n]:
        #    gcc.tree.nodes.Nodes.nodes[n]['count'] = gcc.tree.nodes.Nodes.nodes[n]['count'] +1
            #Nodes.nodes[n]['refs'].append(nd)
        #else:
        #    gcc.tree.nodes.Nodes.nodes[n]['count'] = 1
            
        #if 'node' not in gcc.tree.nodes.Nodes.nodes[n]:
        #    gcc.tree.nodes.Nodes.nodes[n]['node']= Node(n)
            
    debug(Nodes.nodes)
    return gcc.tree.nodes.Nodes.nodes[n]
Пример #7
0
def statement(x):
    return
    # debug(Nodes.nodes)
    debug("statement %s" % pformat2(x))
    # pickle.dumps(x)
    # pickle.dumps(x)
    # global stack
    # global Nodes.astack
    # global Nodes.nodes
    if x:
        # pprint.pprint(x)
        nid = x._id

        # if nid in gcc.tree.nodes.Nodes.nodes:
        #    gcc.tree.nodes.Nodes.nodes[nid]['decl'] = x
        # else:
        # gcc.tree.nodes.Nodes.nodes[nid]["type"] = x._type

        # gcc.tree.nodes.Nodes.nodes[nid]['stack'] =list(Nodes.stack)

        # gcc.tree.nodes.Nodes.nodes[nid]["attrs"] = Nodes.aobj
        # gcc.tree.nodes.Nodes.nodes[nid]["refs"] = Nodes.aobj2
        Nodes.aobj = {}
        Nodes.aobj2 = {}

        # pprint.pprint(gcc.tree.nodes.Nodes.nodes[nid])
        # pprint.pprint(Nodes.aobj)

        # now each of these items
        # for sp in gcc.tree.nodes.Nodes.stack:
        #    sn = sp[0]
        #    s = sp[1]
        #    gcc.tree.nodes.Nodes.usedby(s,x,sn)
        # gcc.tree.nodes.Nodes.stack=[]
        gcc.tree.nodes.Nodes.aobj = {}
        gcc.tree.nodes.Nodes.aobj2 = {}
        debug(gcc.tree.nodes.Nodes.nodes)
        n2 = gcc.tree.transform.Resolver.transform(nid)
        # testsize(n2)
        if n2 is None:
            debug("expr be null %s" % nid)
    else:
        raise Exception("none")
    debug(gcc.tree.nodes.Nodes.nodes)

    n2 = gcc.tree.transform.Resolver.transform(nid)
    # testsize(n2)
    testsize(gcc.tree.nodes.Nodes.nodes)
Пример #8
0
    def resolve2(x, seen, role, nt):
        debug({
            "phase": "resolve2",
            "x": x,
            "role": role,
            "nt": nt,
            "seen": seen,
        })
        if isinstance(x, str):
            # print ('instance %s' % x)
            return x

        if isinstance(x, dict):
            if "type" in x:
                # print  ('resolving dict %s' % pprint.pformat(x))
                return Resolver.resolve2(x["type"], seen, role, nt)
            else:
                # print('resolving dict %s' % pprint.pformat(x))
                raise Exception()
        skip = ("min", "max", "size", "bpos")
        if role in skip:
            if len(seen["stack"]) > 3:
                return "short"

        if isinstance(x, tuast.Node):
            return Resolver.resolve(Resolver.get_node_objs(x.nid()), seen,
                                    role)
        if isinstance(x, nodes.Node):
            return Resolver.resolve(Resolver.get_node_objs(x.nid()), seen,
                                    role)
        if isinstance(x, attributes.TNode):
            return Resolver.resolve(Resolver.get_node_objs(x.nid()), seen,
                                    role)

        t = type(x)
        print(("trying to resolve %s" % t))
        print(("resolving obj %s" % pprint.pformat(x)))
        raise Exception(x)
Пример #9
0
def statement(x):
    #debug(Nodes.nodes)
    debug("statement %s" % pformat2(x))
    #pickle.dumps(x)
    #pickle.dumps(x)
    #global stack
    #global Nodes.astack
    #global Nodes.nodes
    if x:
        #pprint.pprint(x)
        nid = x['node_decl']
        
        #if nid in gcc.tree.nodes.Nodes.nodes:
        #    gcc.tree.nodes.Nodes.nodes[nid]['decl'] = x
        #else:
        gcc.tree.nodes.Nodes.nodes[nid]['type'] =  x['type']

        #gcc.tree.nodes.Nodes.nodes[nid]['stack'] =list(Nodes.stack)

        gcc.tree.nodes.Nodes.nodes[nid]['attrs'] =Nodes.aobj
        gcc.tree.nodes.Nodes.nodes[nid]['refs'] =Nodes.aobj2
        Nodes.aobj={}
        Nodes.aobj2={}

        #pprint.pprint(gcc.tree.nodes.Nodes.nodes[nid])
        #pprint.pprint(Nodes.aobj)

        # now each of these items
        #for sp in gcc.tree.nodes.Nodes.stack:
        #    sn = sp[0]
        #    s = sp[1]
        #    gcc.tree.nodes.Nodes.usedby(s,x,sn)
        #gcc.tree.nodes.Nodes.stack=[]
        gcc.tree.nodes.Nodes.aobj={}
        gcc.tree.nodes.Nodes.aobj2={}
        debug(gcc.tree.nodes.Nodes.nodes)
        n2 = gcc.tree.transform.Resolver.transform(nid)
        #testsize(n2)
        if n2 is None:
            debug ("expr be null %s" % nid)
    else:
        raise Exception("none")
    debug(gcc.tree.nodes.Nodes.nodes)

    n2 = gcc.tree.transform.Resolver.transform(nid)
    #testsize(n2)
    testsize(gcc.tree.nodes.Nodes.nodes)
def parse_l(l, rundebug, error_file, f):
    """
    preprocessing of the line
    """

    pval = None
    ptype = None

    # if the line is empty
    if not l:
        raise Exception()
    # or does not start with @
    if l[0] != "@":
        raise Exception()

    stack = []

    # array element 0
    x = re.search(ERE, l)
    while x:
        n = x.group(1)
        # print ("Find %s in %s" % (n,l))
        l = re.sub(r"\s%s\s+:\s\@" % n, " E%s :@" % n, l)
        x = re.search(ERE, l)

    # replace op 0
    x = re.search(OPRE, l)
    while x:
        n = x.group(1)
        # print ("Find %s in %s" % (n,l))
        l = re.sub(r"op\s%s\s*:\s\@" % n, " OP%s :@" % n, l)
        x = re.search(OPRE, l)

    # now try and parse the input
    try:
        x = parser.parse(l, debug=rundebug)

        # memprofile(l)

        if not x:
            error_file.write(l + "\n")
            # print "Error on Line:%s" % l
            # print "Stack:%s" % stack
            # print "parser %s" % pprint2.pformat(parser.__dict__)
            # if not debug:
            #    x = parser.parse(l, debug=True)
        else:
            report(x, l)
            if rundebug:
                debug(("Results1 %s" % x))
            else:
                s = str(x)
                # if not s in seen:
                #     seen[s]=1
                #     if debug:
                #         print("Results2 '%s'" % s)

        if rundebug:
            #debug("Stack:%s" % stack)
            print(("parser %s" % parser))

        return x

    # except QueryBadFormed as e:
    #    raise e
    except Exception as exp:
        print(("parse error : " + l + "\n"))
        error_file.write(l + "\n")
        # traceback.print_exc()
        print(("Exp", exp))
        print(("EXP Line:%s" % l))
        f.write(l + "\n")
        print(("EXP Stack:%s" % stack))
        raise exp

    # print "Stack:%s" % stack
    return None
Пример #11
0
def parse_l(l, rundebug, error_file, f):
    '''
    preprocessing of the line
    '''

    pval = None
    ptype = None

    # if the line is empty
    if not l:
        raise Exception()
    # or does not start with @ 
    if l[0] != '@':
        raise Exception()

    stack = []

    # array element 0
    x = re.search(ERE, l)
    while x:
        n = x.group(1)
        # print ("Find %s in %s" % (n,l))
        l = re.sub(r'\s%s\s+:\s\@' % n, " E%s :@" % n, l)
        x = re.search(ERE, l)

    # replace op 0
    x = re.search(OPRE, l)
    while x:
        n = x.group(1)
        # print ("Find %s in %s" % (n,l))
        l = re.sub(r'op\s%s\s*:\s\@' % n, " OP%s :@" % n, l)
        x = re.search(OPRE, l)

    # now try and parse the input
    try:
        x = parser.parse(l, debug=rundebug)

        #memprofile(l)

        if not x:
            error_file.write(l + "\n")
            #print "Error on Line:%s" % l
            #print "Stack:%s" % stack
            #print "parser %s" % pprint2.pformat(parser.__dict__)
            #if not debug:
            #    x = parser.parse(l, debug=True)
        else:
            report(x,l)
            if rundebug:
                debug(("Results1 %s" % x))
            else:
                s = str(x)
                # if not s in seen:
                #     seen[s]=1
                #     if debug:
                #         print("Results2 '%s'" % s)

        if rundebug :
            debug("Stack:%s" % stack)
            print("parser %s" % parser)

        return x
    
    #except QueryBadFormed as e:
    #    raise e
    except Exception as exp:
        print("parse error : "+ l + "\n")
        error_file.write(l + "\n")
        #traceback.print_exc()
        print("Exp",exp)
        print("EXP Line:%s" % l)
        f.write(l + "\n")
        print("EXP Stack:%s" % stack)
        raise exp
    
    #print "Stack:%s" % stack
    return None
Пример #12
0
def report():
    debug("report")
    debug(pformat2(types))
Пример #13
0
 def get_node_objs(x):
     if x in gcc.tree.nodes.Nodes.nodes:
         return gcc.tree.nodes.Nodes.nodes[x]
     else:
         debug({'cannot find':x, 'nodes': gcc.tree.nodes.Nodes.nodes })
         raise Exception(x)