Commit fc128403 authored by Russ Cox's avatar Russ Cox

gc: minor changes for inlining

Copied from 5400043 since they stand alone from inlining.

R=lvd
CC=golang-dev
https://golang.org/cl/5479046
parent ef1c5357
...@@ -642,7 +642,7 @@ funcargs2(Type *t) ...@@ -642,7 +642,7 @@ funcargs2(Type *t)
for(ft=getthisx(t)->type; ft; ft=ft->down) { for(ft=getthisx(t)->type; ft; ft=ft->down) {
if(!ft->nname || !ft->nname->sym) if(!ft->nname || !ft->nname->sym)
continue; continue;
n = newname(ft->nname->sym); n = ft->nname; // no need for newname(ft->nname->sym)
n->type = ft->type; n->type = ft->type;
declare(n, PPARAM); declare(n, PPARAM);
} }
...@@ -651,7 +651,7 @@ funcargs2(Type *t) ...@@ -651,7 +651,7 @@ funcargs2(Type *t)
for(ft=getinargx(t)->type; ft; ft=ft->down) { for(ft=getinargx(t)->type; ft; ft=ft->down) {
if(!ft->nname || !ft->nname->sym) if(!ft->nname || !ft->nname->sym)
continue; continue;
n = newname(ft->nname->sym); n = ft->nname;
n->type = ft->type; n->type = ft->type;
declare(n, PPARAM); declare(n, PPARAM);
} }
...@@ -660,7 +660,7 @@ funcargs2(Type *t) ...@@ -660,7 +660,7 @@ funcargs2(Type *t)
for(ft=getoutargx(t)->type; ft; ft=ft->down) { for(ft=getoutargx(t)->type; ft; ft=ft->down) {
if(!ft->nname || !ft->nname->sym) if(!ft->nname || !ft->nname->sym)
continue; continue;
n = newname(ft->nname->sym); n = ft->nname;
n->type = ft->type; n->type = ft->type;
declare(n, PPARAMOUT); declare(n, PPARAMOUT);
} }
...@@ -845,6 +845,7 @@ tofunargs(NodeList *l) ...@@ -845,6 +845,7 @@ tofunargs(NodeList *l)
for(tp = &t->type; l; l=l->next) { for(tp = &t->type; l; l=l->next) {
f = structfield(l->n); f = structfield(l->n);
f->funarg = 1; f->funarg = 1;
// esc.c needs to find f given a PPARAM to add the tag. // esc.c needs to find f given a PPARAM to add the tag.
if(l->n->left && l->n->left->class == PPARAM) if(l->n->left && l->n->left->class == PPARAM)
l->n->left->paramfld = f; l->n->left->paramfld = f;
...@@ -1224,6 +1225,7 @@ methodname1(Node *n, Node *t) ...@@ -1224,6 +1225,7 @@ methodname1(Node *n, Node *t)
} }
if(t->sym == S || isblank(n)) if(t->sym == S || isblank(n))
return newname(n->sym); return newname(n->sym);
if(star) if(star)
p = smprint("(%s%S).%S", star, t->sym, n->sym); p = smprint("(%s%S).%S", star, t->sym, n->sym);
else else
......
...@@ -1685,6 +1685,7 @@ lookdot(Node *n, Type *t, int dostrcmp) ...@@ -1685,6 +1685,7 @@ lookdot(Node *n, Type *t, int dostrcmp)
n->right = methodname(n->right, n->left->type); n->right = methodname(n->right, n->left->type);
n->xoffset = f2->width; n->xoffset = f2->width;
n->type = f2->type; n->type = f2->type;
// print("lookdot found [%p] %T\n", f2->type, f2->type);
n->op = ODOTMETH; n->op = ODOTMETH;
return 1; return 1;
} }
...@@ -2441,7 +2442,7 @@ typecheckfunc(Node *n) ...@@ -2441,7 +2442,7 @@ typecheckfunc(Node *n)
if((t = n->nname->type) == T) if((t = n->nname->type) == T)
return; return;
n->type = t; n->type = t;
t->nname = n->nname;
rcvr = getthisx(t)->type; rcvr = getthisx(t)->type;
if(rcvr != nil && n->shortname != N && !isblank(n->shortname)) if(rcvr != nil && n->shortname != N && !isblank(n->shortname))
addmethod(n->shortname->sym, t, 1); addmethod(n->shortname->sym, t, 1);
......
...@@ -167,6 +167,8 @@ walkstmt(Node **np) ...@@ -167,6 +167,8 @@ walkstmt(Node **np)
setlineno(n); setlineno(n);
walkstmtlist(n->ninit);
switch(n->op) { switch(n->op) {
default: default:
if(n->op == ONAME) if(n->op == ONAME)
...@@ -243,7 +245,6 @@ walkstmt(Node **np) ...@@ -243,7 +245,6 @@ walkstmt(Node **np)
break; break;
case OFOR: case OFOR:
walkstmtlist(n->ninit);
if(n->ntest != N) { if(n->ntest != N) {
walkstmtlist(n->ntest->ninit); walkstmtlist(n->ntest->ninit);
init = n->ntest->ninit; init = n->ntest->ninit;
...@@ -256,7 +257,6 @@ walkstmt(Node **np) ...@@ -256,7 +257,6 @@ walkstmt(Node **np)
break; break;
case OIF: case OIF:
walkstmtlist(n->ninit);
walkexpr(&n->ntest, &n->ninit); walkexpr(&n->ntest, &n->ninit);
walkstmtlist(n->nbody); walkstmtlist(n->nbody);
walkstmtlist(n->nelse); walkstmtlist(n->nelse);
...@@ -384,6 +384,12 @@ walkexpr(Node **np, NodeList **init) ...@@ -384,6 +384,12 @@ walkexpr(Node **np, NodeList **init)
fatal("walkexpr init == &n->ninit"); fatal("walkexpr init == &n->ninit");
} }
if(n->ninit != nil) {
walkstmtlist(n->ninit);
*init = concat(*init, n->ninit);
n->ninit = nil;
}
// annoying case - not typechecked // annoying case - not typechecked
if(n->op == OKEY) { if(n->op == OKEY) {
walkexpr(&n->left, init); walkexpr(&n->left, init);
...@@ -1229,7 +1235,7 @@ ascompatee(int op, NodeList *nl, NodeList *nr, NodeList **init) ...@@ -1229,7 +1235,7 @@ ascompatee(int op, NodeList *nl, NodeList *nr, NodeList **init)
// cannot happen: caller checked that lists had same length // cannot happen: caller checked that lists had same length
if(ll || lr) if(ll || lr)
yyerror("error in shape across %O", op); yyerror("error in shape across %+H %O %+H", nl, op, nr);
return nn; return nn;
} }
......
...@@ -145,18 +145,14 @@ func GcImporter(imports map[string]*ast.Object, path string) (pkg *ast.Object, e ...@@ -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. // 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 { func (p *gcParser) declare(scope *ast.Scope, kind ast.ObjKind, name string) *ast.Object {
// a type may have been declared before - if it exists // the object may have been imported before - if it exists
// already in the respective package scope, return that // already in the respective package scope, return that object
// type
if kind == ast.Typ {
if obj := scope.Lookup(name); obj != nil { if obj := scope.Lookup(name); obj != nil {
assert(obj.Kind == ast.Typ) assert(obj.Kind == kind)
return obj return obj
} }
}
// any other object must be a newly declared object - // otherwise create a new object and insert it into the package scope
// create it and insert it into the package scope
obj := ast.NewObj(kind, name) obj := ast.NewObj(kind, name)
if scope.Insert(obj) != nil { if scope.Insert(obj) != nil {
p.errorf("already declared: %v %s", kind, obj.Name) p.errorf("already declared: %v %s", kind, obj.Name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment