예제 #1
0
파일: parse.py 프로젝트: icelinker/smop3
def p_field_expr(p):
    """
    expr : expr FIELD 
    """
    p[0] = node.expr(op=".",
                     args=node.expr_list([p[1],
                                          node.ident(name=p[2],
                                                     lineno=p.lineno(2),
                                                     lexpos=p.lexpos(2))]))
예제 #2
0
파일: parse.py 프로젝트: icelinker/smop3
def p_expr_ident(p):
    "ident : IDENT"
    global use_nargin,use_varargin
    if p[1] == "varargin":
        use_varargin = 1
    if p[1] == "nargin":
        use_nargin = 1
    #import pdb; pdb.set_trace()
    p[0] = node.ident(name=p[1],
                      lineno=p.lineno(1),
                      lexpos=p.lexpos(1),
                      column=p.lexpos(1) - p.lexer.lexdata.rfind("\n",0,p.lexpos(1)))
예제 #3
0
파일: parse.py 프로젝트: icelinker/smop3
def p_funcall_expr(p):
    """expr : expr LPAREN expr_list RPAREN 
            | expr LPAREN RPAREN
    """
    if (0 and len(p)==5 and
        len(p[3])==1 and 
        p[3][0].__class__ is node.expr and
        p[3][0].op == ":" and not p[3][0].args):
        # foo(:) => ravel(foo)
        p[0] = node.funcall(func_expr=node.ident("ravel"),
                            args=node.expr_list([p[1]]))
    else:
        args = node.expr_list() if len(p) == 4 else p[3]
        assert isinstance(args,node.expr_list)
        p[0] = node.funcall(func_expr=p[1],args=args)
예제 #4
0
파일: parse.py 프로젝트: icelinker/smop3
def p_expr(p):
    """expr : ident
            | end
            | number
            | string
            | colon
            | NEG
            | matrix
            | cellarray
            | expr2
            | expr1
            | lambda_expr
            | expr PLUSPLUS
            | expr MINUSMINUS
    """
    #        | PLUSPLUS ident
    #        | MINUSMINUS ident
    if p[1]=="~":
        p[0] = node.ident(name="__")
    else:
        p[0] = p[1]
예제 #5
0
파일: resolve.py 프로젝트: icelinker/smop3
def resolve(t, symtab=None, fp=None, func_name=None):
    if symtab is None:
        symtab = {}
    do_resolve(t, symtab)
    G = as_networkx(t)
    #import pdb;pdb.set_trace()
    for n in G.nodes():
        u = G.node[n]["ident"]
        if u.props:
            pass
        elif G.out_edges(n) and G.in_edges(n):
            u.props = "U"  # upd
            #print u.name, u.lineno, u.column
        elif G.in_edges(n):
            u.props = "D"  # def
        elif G.out_edges(n):
            u.props = "R"  # ref
        else:
            u.props = "F"  # ???
        G.node[n]["label"] = "%s\\n%s" % (n, u.props)

    for u in node.postorder(t):
        #if u.__class__ is node.func_decl:
        #    u.ident.name += "_"
        if u.__class__ is node.funcall:
            try:
                if u.func_expr.props in "UR":  # upd,ref
                    u.__class__ = node.arrayref
                #else:
                #    u.func_expr.name += "_"
            except:
                pass

    for u in node.postorder(t):
        if u.__class__ in (node.arrayref, node.cellarrayref):
            for i, v in enumerate(u.args):
                if v.__class__ is node.expr and v.op == ":":
                    v.op = "::"


#                for w in node.postorder(v):
#                    if w.__class__ is node.expr and w.op == "end":
#                        w.args[0] = u.func_expr
#                        w.args[1] = node.number(i)

    for u in node.postorder(t):
        if u.__class__ is node.let:
            if (u.ret.__class__ is node.ident
                    and u.args.__class__ is node.matrix):
                u.args = node.funcall(func_expr=node.ident("matlabarray"),
                                      args=node.expr_list([u.args]))

    H = nx.connected_components(G.to_undirected())
    for i, component in enumerate(H):
        for nodename in component:
            if G.node[nodename]["ident"].props == "R":
                has_update = 1
                break
        else:
            has_update = 0
        if has_update:
            for nodename in component:
                G.node[nodename]["ident"].props += "S"  # sparse
        #S = G.subgraph(nbunch)
        #print S.edges()
    return G