1
0
mirror of https://github.com/golang/go synced 2024-11-25 16:07:56 -07:00

eqtype(t1, t2, 0) => eqtype(t1, t2)

R=ken
OCL=28559
CL=28562
This commit is contained in:
Russ Cox 2009-05-08 14:40:38 -07:00
parent 1b301bac1a
commit d4fa253837
9 changed files with 47 additions and 34 deletions

View File

@ -191,7 +191,7 @@ cgen(Node *n, Node *res)
goto abop; goto abop;
case OCONV: case OCONV:
if(eqtype(n->type, nl->type, 0)) { if(eqtype(n->type, nl->type)) {
cgen(nl, res); cgen(nl, res);
break; break;
} }
@ -384,7 +384,7 @@ agen(Node *n, Node *res)
break; break;
case OCONV: case OCONV:
if(!eqtype(n->type, nl->type, 0)) if(!eqtype(n->type, nl->type))
fatal("agen: non-trivial OCONV"); fatal("agen: non-trivial OCONV");
agen(nl, res); agen(nl, res);
return; return;

View File

@ -80,7 +80,7 @@ convlit1(Node *n, Type *t, int explicit)
} }
// avoided repeated calculations, errors // avoided repeated calculations, errors
if(eqtype(n->type, t, 0)) { if(eqtype(n->type, t)) {
n->type = t; n->type = t;
return; return;
} }

View File

@ -212,7 +212,7 @@ methcmp(Type *t1, Type *t2)
if(t1->etype != TSTRUCT || t2->etype != TSTRUCT) if(t1->etype != TSTRUCT || t2->etype != TSTRUCT)
return 0; return 0;
if(!eqtype(t1->type, t2->type, 0)) if(!eqtype(t1->type, t2->type))
return 0; return 0;
t1 = t1->down; t1 = t1->down;
@ -327,7 +327,7 @@ addmethod(Node *n, Type *t, int local)
d = f; d = f;
continue; continue;
} }
if(!eqtype(t, f->type, 0)) { if(!eqtype(t, f->type)) {
yyerror("method redeclared: %T.%S", pa, sf); yyerror("method redeclared: %T.%S", pa, sf);
print("\t%T\n\t%T\n", f->type, t); print("\t%T\n\t%T\n", f->type, t);
} }
@ -387,7 +387,7 @@ funchdr(Node *n)
// check for same types // check for same types
if(on != N) { if(on != N) {
if(eqtype(n->type, on->type, 0)) { if(eqtype(n->type, on->type)) {
if(!eqargs(n->type, on->type)) { if(!eqargs(n->type, on->type)) {
yyerror("function arg names changed: %S", s); yyerror("function arg names changed: %S", s);
print("\t%T\n\t%T\n", on->type, n->type); print("\t%T\n\t%T\n", on->type, n->type);

View File

@ -371,7 +371,7 @@ importvar(Node *ss, Type *t, int ctxt)
s = importsym(ss, LNAME); s = importsym(ss, LNAME);
if(s->oname != N) { if(s->oname != N) {
if(eqtype(t, s->oname->type, 0)) if(eqtype(t, s->oname->type))
return; return;
warn("redeclare import var %S from %T to %T", warn("redeclare import var %S from %T to %T",
s, s->oname->type, t); s, s->oname->type, t);
@ -390,7 +390,7 @@ importtype(Node *ss, Type *t)
s = importsym(ss, LATYPE); s = importsym(ss, LATYPE);
if(s->otype != T) { if(s->otype != T) {
if(eqtype(t, s->otype, 0)) if(eqtype(t, s->otype))
return; return;
if(s->otype->etype != TFORW) { if(s->otype->etype != TFORW) {
warn("redeclare import type %S from %T to %T", warn("redeclare import type %S from %T to %T",

View File

@ -726,7 +726,7 @@ int isddd(Type*);
Type* maptype(Type*, Type*); Type* maptype(Type*, Type*);
Type* methtype(Type*); Type* methtype(Type*);
Sym* signame(Type*); Sym* signame(Type*);
int eqtype(Type*, Type*, int); int eqtype(Type*, Type*);
int eqtypenoname(Type*, Type*); int eqtypenoname(Type*, Type*);
void argtype(Node*, Type*); void argtype(Node*, Type*);
int eqargs(Type*, Type*); int eqargs(Type*, Type*);

View File

@ -1088,6 +1088,10 @@ name:
labelname: labelname:
name name
| LATYPE
{
$$ = oldname($1);
}
| keyword | keyword
{ {
$$ = oldname($1); $$ = oldname($1);
@ -2049,6 +2053,9 @@ hidden_pkg_importsym:
* to check whether the rest of the grammar is free of * to check whether the rest of the grammar is free of
* reduce/reduce conflicts, comment this section out by * reduce/reduce conflicts, comment this section out by
* removing the slash on the next line. * removing the slash on the next line.
*
* there should be exactly 1 reduce/reduce conflict
* when this block is commented out.
*/ */
lpack: lpack:
LATYPE LATYPE

View File

@ -230,7 +230,7 @@ dumpsigt(Type *progt, Type *ifacet, Type *rcvrt, Type *methodt, Sym *s)
if(!a->sym->siggen) { if(!a->sym->siggen) {
a->sym->siggen = 1; a->sym->siggen = 1;
if(!eqtype(this, ifacet, 0)) { if(!eqtype(this, ifacet)) {
if(oldlist == nil) if(oldlist == nil)
oldlist = pc; oldlist = pc;

View File

@ -1607,7 +1607,7 @@ bad:
} }
int int
eqtype(Type *t1, Type *t2, int d) eqtype1(Type *t1, Type *t2, int d)
{ {
if(d >= 10) if(d >= 10)
return 1; return 1;
@ -1623,7 +1623,7 @@ eqtype(Type *t1, Type *t2, int d)
t1 = t1->type; t1 = t1->type;
t2 = t2->type; t2 = t2->type;
for(;;) { for(;;) {
if(!eqtype(t1, t2, d+1)) if(!eqtype1(t1, t2, d+1))
return 0; return 0;
if(t1 == T) if(t1 == T)
return 1; return 1;
@ -1659,7 +1659,7 @@ eqtype(Type *t1, Type *t2, int d)
return 0; return 0;
if(ta->etype != TFIELD || tb->etype != TFIELD) if(ta->etype != TFIELD || tb->etype != TFIELD)
return 0; return 0;
if(!eqtype(ta->type, tb->type, d+1)) if(!eqtype1(ta->type, tb->type, d+1))
return 0; return 0;
ta = ta->down; ta = ta->down;
tb = tb->down; tb = tb->down;
@ -1675,20 +1675,26 @@ eqtype(Type *t1, Type *t2, int d)
break; break;
return 0; return 0;
} }
return eqtype(t1->type, t2->type, d+1); return eqtype1(t1->type, t2->type, d+1);
}
int
eqtype(Type *t1, Type *t2)
{
return eqtype1(t1, t2, 0);
} }
int int
eqtypenoname(Type *t1, Type *t2) eqtypenoname(Type *t1, Type *t2)
{ {
if(t1 == T || t2 == T || t1->etype != TSTRUCT || t2->etype != TSTRUCT) if(t1 == T || t2 == T || t1->etype != TSTRUCT || t2->etype != TSTRUCT)
return eqtype(t1, t2, 0); return eqtype(t1, t2);
t1 = t1->type; t1 = t1->type;
t2 = t2->type; t2 = t2->type;
for(;;) { for(;;) {
if(!eqtype(t1, t2, 1)) if(!eqtype(t1, t2))
return 0; return 0;
if(t1 == T) if(t1 == T)
return 1; return 1;
@ -1873,7 +1879,7 @@ eqargs(Type *t1, Type *t2)
for(;;) { for(;;) {
if(t1 == t2) if(t1 == t2)
break; break;
if(!eqtype(t1, t2, 0)) if(!eqtype(t1, t2))
return 0; return 0;
t1 = t1->down; t1 = t1->down;
t2 = t2->down; t2 = t2->down;
@ -2032,7 +2038,7 @@ loop:
} }
if(tl->etype != TFUNC || tr->etype != TFUNC) if(tl->etype != TFUNC || tr->etype != TFUNC)
break; break;
// if(eqtype(t1, t2, 0)) // if(eqtype(t1, t2))
} }
yyerror("illegal types for operand: %O", o); yyerror("illegal types for operand: %O", o);

View File

@ -700,7 +700,7 @@ loop:
defaultlit2(n->left, n->right); defaultlit2(n->left, n->right);
if(n->left->type == T || n->right->type == T) if(n->left->type == T || n->right->type == T)
goto ret; goto ret;
if(!eqtype(n->left->type, n->right->type, 0)) if(!eqtype(n->left->type, n->right->type))
goto badt; goto badt;
switch(n->op) { switch(n->op) {
@ -831,7 +831,7 @@ loop:
defaultlit(n->right, t->down); defaultlit(n->right, t->down);
if(n->right->type == T) if(n->right->type == T)
break; break;
if(!eqtype(n->right->type, t->down, 0)) if(!eqtype(n->right->type, t->down))
goto badt; goto badt;
n->type = t->type; n->type = t->type;
if(top == Erv) if(top == Erv)
@ -1169,7 +1169,7 @@ walkbool(Node *n)
defaultlit(n, T); defaultlit(n, T);
addtotop(n); addtotop(n);
if(n != N && n->type != T) if(n != N && n->type != T)
if(!eqtype(n->type, types[TBOOL], 0)) if(!eqtype(n->type, types[TBOOL]))
yyerror("IF and FOR require a boolean type"); yyerror("IF and FOR require a boolean type");
} }
@ -1210,7 +1210,7 @@ walkconv(Node *n)
return; return;
// nil conversion // nil conversion
if(eqtype(t, l->type, 0)) { if(eqtype(t, l->type)) {
if(l->op != ONAME) { if(l->op != ONAME) {
indir(n, l); indir(n, l);
n->type = t; n->type = t;
@ -1248,7 +1248,7 @@ walkconv(Node *n)
// convert static array to dynamic array // convert static array to dynamic array
if(isslice(t) && isptr[l->type->etype] && isfixedarray(l->type->type)) { if(isslice(t) && isptr[l->type->etype] && isfixedarray(l->type->type)) {
if(eqtype(t->type->type, l->type->type->type->type, 0)) { if(eqtype(t->type->type, l->type->type->type->type)) {
indir(n, arrayop(n, Erv)); indir(n, arrayop(n, Erv));
return; return;
} }
@ -1622,13 +1622,13 @@ lookdot(Node *n, Type *t)
if(f2 != T) { if(f2 != T) {
tt = n->left->type; tt = n->left->type;
rcvr = getthisx(f2->type)->type->type; rcvr = getthisx(f2->type)->type->type;
if(!eqtype(rcvr, tt, 0)) { if(!eqtype(rcvr, tt)) {
if(rcvr->etype == tptr && eqtype(rcvr->type, tt, 0)) { if(rcvr->etype == tptr && eqtype(rcvr->type, tt)) {
walktype(n->left, Elv); walktype(n->left, Elv);
addrescapes(n->left); addrescapes(n->left);
n->left = nod(OADDR, n->left, N); n->left = nod(OADDR, n->left, N);
n->left->type = ptrto(tt); n->left->type = ptrto(tt);
} else if(tt->etype == tptr && eqtype(tt->type, rcvr, 0)) { } else if(tt->etype == tptr && eqtype(tt->type, rcvr)) {
n->left = nod(OIND, n->left, N); n->left = nod(OIND, n->left, N);
n->left->type = tt->type; n->left->type = tt->type;
} else { } else {
@ -2017,7 +2017,7 @@ loop:
int int
ascompat(Type *dst, Type *src) ascompat(Type *dst, Type *src)
{ {
if(eqtype(dst, src, 0)) if(eqtype(dst, src))
return 1; return 1;
if(dst == T || src == T) if(dst == T || src == T)
@ -2026,7 +2026,7 @@ ascompat(Type *dst, Type *src)
if(isslice(dst) if(isslice(dst)
&& isptr[src->etype] && isptr[src->etype]
&& isfixedarray(src->type) && isfixedarray(src->type)
&& eqtype(dst->type, src->type->type, 0)) && eqtype(dst->type, src->type->type))
return 1; return 1;
if(isnilinter(dst) || isnilinter(src)) if(isnilinter(dst) || isnilinter(src))
@ -2120,7 +2120,7 @@ loop:
if(t != nil) if(t != nil)
t = t->type; t = t->type;
if(!eqtype(t, l->type, 0)) { if(!eqtype(t, l->type)) {
l = nod(OCONV, l, N); l = nod(OCONV, l, N);
l->type = t; l->type = t;
} }
@ -2380,7 +2380,7 @@ mapop(Node *n, int top)
convlit(n->right, t->down); convlit(n->right, t->down);
if(!eqtype(n->right->type, t->down, 0)) { if(!eqtype(n->right->type, t->down)) {
badtype(n->op, n->right->type, t->down); badtype(n->op, n->right->type, t->down);
break; break;
} }
@ -2900,7 +2900,7 @@ ifaceas1(Type *dst, Type *src, int explicit)
if(isinter(dst)) { if(isinter(dst)) {
if(isinter(src)) { if(isinter(src)) {
if(eqtype(dst, src, 0)) if(eqtype(dst, src))
return I2Isame; return I2Isame;
if(!isnilinter(dst)) if(!isnilinter(dst))
ifacecheck(dst, src, lineno, explicit); ifacecheck(dst, src, lineno, explicit);
@ -3065,7 +3065,7 @@ convas(Node *n)
goto out; goto out;
} }
if(eqtype(lt, rt, 0)) if(eqtype(lt, rt))
goto out; goto out;
et = ifaceas(lt, rt, 0); et = ifaceas(lt, rt, 0);
@ -3075,7 +3075,7 @@ convas(Node *n)
} }
if(isslice(lt) && isptr[rt->etype] && isfixedarray(rt->type)) { if(isslice(lt) && isptr[rt->etype] && isfixedarray(rt->type)) {
if(!eqtype(lt->type->type, rt->type->type->type, 0)) if(!eqtype(lt->type->type, rt->type->type->type))
goto bad; goto bad;
indir(n, arrayop(n, Etop)); indir(n, arrayop(n, Etop));
goto out; goto out;
@ -3154,7 +3154,7 @@ checkmixed(Node *nl)
if(!colasname(l)) if(!colasname(l))
goto allnew; goto allnew;
if(l->sym->block == block) { if(l->sym->block == block) {
if(!eqtype(l->type, t, 0)) if(!eqtype(l->type, t))
goto allnew; goto allnew;
nred++; nred++;
} }