]> Cypherpunks repositories - gostls13.git/commitdiff
gc: minor changes for inlining
authorRuss Cox <rsc@golang.org>
Fri, 9 Dec 2011 13:03:51 +0000 (08:03 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 9 Dec 2011 13:03:51 +0000 (08:03 -0500)
Copied from 5400043 since they stand alone from inlining.

R=lvd
CC=golang-dev
https://golang.org/cl/5479046

src/cmd/gc/dcl.c
src/cmd/gc/typecheck.c
src/cmd/gc/walk.c
src/pkg/exp/types/gcimporter.go

index c61306ad4c8d57ce330fb7bc1e366586daa6b73d..235e2ceff4fb43e453a7728d1f17083fdf5ca9f9 100644 (file)
@@ -642,7 +642,7 @@ funcargs2(Type *t)
                for(ft=getthisx(t)->type; ft; ft=ft->down) {
                        if(!ft->nname || !ft->nname->sym)
                                continue;
-                       n = newname(ft->nname->sym);
+                       n = ft->nname;  // no need for newname(ft->nname->sym)
                        n->type = ft->type;
                        declare(n, PPARAM);
                }
@@ -651,7 +651,7 @@ funcargs2(Type *t)
                for(ft=getinargx(t)->type; ft; ft=ft->down) {
                        if(!ft->nname || !ft->nname->sym)
                                continue;
-                       n = newname(ft->nname->sym);
+                       n = ft->nname;
                        n->type = ft->type;
                        declare(n, PPARAM);
                }
@@ -660,7 +660,7 @@ funcargs2(Type *t)
                for(ft=getoutargx(t)->type; ft; ft=ft->down) {
                        if(!ft->nname || !ft->nname->sym)
                                continue;
-                       n = newname(ft->nname->sym);
+                       n = ft->nname;
                        n->type = ft->type;
                        declare(n, PPARAMOUT);
                }
@@ -845,6 +845,7 @@ tofunargs(NodeList *l)
        for(tp = &t->type; l; l=l->next) {
                f = structfield(l->n);
                f->funarg = 1;
+
                // esc.c needs to find f given a PPARAM to add the tag.
                if(l->n->left && l->n->left->class == PPARAM)
                        l->n->left->paramfld = f;
@@ -1224,6 +1225,7 @@ methodname1(Node *n, Node *t)
        }
        if(t->sym == S || isblank(n))
                return newname(n->sym);
+
        if(star)
                p = smprint("(%s%S).%S", star, t->sym, n->sym);
        else
index edf32fe2fa392bc98d0943056a38dba769b2936e..5527bc342cf24cd289911b6b4c7c3bcae5a5dd53 100644 (file)
@@ -1685,6 +1685,7 @@ lookdot(Node *n, Type *t, int dostrcmp)
                n->right = methodname(n->right, n->left->type);
                n->xoffset = f2->width;
                n->type = f2->type;
+//             print("lookdot found [%p] %T\n", f2->type, f2->type);
                n->op = ODOTMETH;
                return 1;
        }
@@ -2441,7 +2442,7 @@ typecheckfunc(Node *n)
        if((t = n->nname->type) == T)
                return;
        n->type = t;
-
+       t->nname = n->nname;
        rcvr = getthisx(t)->type;
        if(rcvr != nil && n->shortname != N && !isblank(n->shortname))
                addmethod(n->shortname->sym, t, 1);
index 93bcd423f47fea27f5c783f46efcbef49939c744..3e2160a94f693646901b61a2796290fb8e357f10 100644 (file)
@@ -167,6 +167,8 @@ walkstmt(Node **np)
 
        setlineno(n);
 
+       walkstmtlist(n->ninit);
+
        switch(n->op) {
        default:
                if(n->op == ONAME)
@@ -243,7 +245,6 @@ walkstmt(Node **np)
                break;
 
        case OFOR:
-               walkstmtlist(n->ninit);
                if(n->ntest != N) {
                        walkstmtlist(n->ntest->ninit);
                        init = n->ntest->ninit;
@@ -256,7 +257,6 @@ walkstmt(Node **np)
                break;
 
        case OIF:
-               walkstmtlist(n->ninit);
                walkexpr(&n->ntest, &n->ninit);
                walkstmtlist(n->nbody);
                walkstmtlist(n->nelse);
@@ -384,6 +384,12 @@ walkexpr(Node **np, NodeList **init)
                fatal("walkexpr init == &n->ninit");
        }
 
+       if(n->ninit != nil) {
+               walkstmtlist(n->ninit);
+               *init = concat(*init, n->ninit);
+               n->ninit = nil;
+       }
+
        // annoying case - not typechecked
        if(n->op == OKEY) {
                walkexpr(&n->left, init);
@@ -1229,7 +1235,7 @@ ascompatee(int op, NodeList *nl, NodeList *nr, NodeList **init)
 
        // cannot happen: caller checked that lists had same length
        if(ll || lr)
-               yyerror("error in shape across %O", op);
+               yyerror("error in shape across %+H %O %+H", nl, op, nr);
        return nn;
 }
 
index 0b10e5fb3fc2d4b7573827199023a66900342a3c..10c56db21ff0d78fe2e1a0d850d6a72e5be51a32 100644 (file)
@@ -145,18 +145,14 @@ func GcImporter(imports map[string]*ast.Object, path string) (pkg *ast.Object, e
 
 // Declare inserts a named object of the given kind in scope.
 func (p *gcParser) declare(scope *ast.Scope, kind ast.ObjKind, name string) *ast.Object {
-       // a type may have been declared before - if it exists
-       // already in the respective package scope, return that
-       // type
-       if kind == ast.Typ {
-               if obj := scope.Lookup(name); obj != nil {
-                       assert(obj.Kind == ast.Typ)
-                       return obj
-               }
+       // the object may have been imported before - if it exists
+       // already in the respective package scope, return that object
+       if obj := scope.Lookup(name); obj != nil {
+               assert(obj.Kind == kind)
+               return obj
        }
 
-       // any other object must be a newly declared object -
-       // create it and insert it into the package scope
+       // otherwise create a new object and insert it into the package scope
        obj := ast.NewObj(kind, name)
        if scope.Insert(obj) != nil {
                p.errorf("already declared: %v %s", kind, obj.Name)