Commit 3443656b authored by Russ Cox's avatar Russ Cox

clean up ideal handling; reject attempts

to write type descriptors for ideal types

R=ken
OCL=33958
CL=33958
parent 2156961b
...@@ -66,18 +66,13 @@ convlit(Node **np, Type *t) ...@@ -66,18 +66,13 @@ convlit(Node **np, Type *t)
void void
convlit1(Node **np, Type *t, int explicit) convlit1(Node **np, Type *t, int explicit)
{ {
int et, ct; int ct, et;
Node *n, *nn; Node *n, *nn;
n = *np; n = *np;
if(n == N || t == T || n->type == T) if(n == N || t == T || n->type == T || isideal(t) || eqtype(t, n->type))
return; return;
et = t->etype; if(!explicit && !isideal(n->type))
if(et == TIDEAL || et == TNIL)
return;
if(eqtype(t, n->type))
return;
if(!explicit && n->type->etype != TIDEAL && n->type != idealstring && n->type->etype != TNIL)
return; return;
//dump("convlit1", n); //dump("convlit1", n);
...@@ -120,6 +115,7 @@ convlit1(Node **np, Type *t, int explicit) ...@@ -120,6 +115,7 @@ convlit1(Node **np, Type *t, int explicit)
if(ct < 0) if(ct < 0)
goto bad; goto bad;
et = t->etype;
if(et == TINTER) { if(et == TINTER) {
if(ct == CTNIL && n->type == types[TNIL]) { if(ct == CTNIL && n->type == types[TNIL]) {
n->type = t; n->type = t;
...@@ -129,21 +125,6 @@ convlit1(Node **np, Type *t, int explicit) ...@@ -129,21 +125,6 @@ convlit1(Node **np, Type *t, int explicit)
return; return;
} }
// if already has non-ideal type, cannot change implicitly
if(!explicit) {
switch(n->type->etype) {
case TIDEAL:
case TNIL:
break;
case TSTRING:
if(n->type == idealstring)
break;
// fall through
default:
goto bad;
}
}
switch(ct) { switch(ct) {
default: default:
goto bad; goto bad;
...@@ -203,7 +184,7 @@ convlit1(Node **np, Type *t, int explicit) ...@@ -203,7 +184,7 @@ convlit1(Node **np, Type *t, int explicit)
return; return;
bad: bad:
if(n->type->etype == TIDEAL) { if(isideal(n->type)) {
defaultlit(&n, T); defaultlit(&n, T);
*np = n; *np = n;
} }
...@@ -720,9 +701,7 @@ defaultlit(Node **np, Type *t) ...@@ -720,9 +701,7 @@ defaultlit(Node **np, Type *t)
Node *n, *nn; Node *n, *nn;
n = *np; n = *np;
if(n == N) if(n == N || !isideal(n->type))
return;
if(n->type == T || (n->type->etype != TIDEAL && n->type->etype != TNIL))
return; return;
switch(n->op) { switch(n->op) {
...@@ -749,8 +728,7 @@ defaultlit(Node **np, Type *t) ...@@ -749,8 +728,7 @@ defaultlit(Node **np, Type *t)
return; return;
} }
lno = lineno; lno = setlineno(n);
lineno = n->lineno;
switch(n->val.ctype) { switch(n->val.ctype) {
default: default:
if(t != T) { if(t != T) {
...@@ -763,6 +741,10 @@ defaultlit(Node **np, Type *t) ...@@ -763,6 +741,10 @@ defaultlit(Node **np, Type *t)
n->type = T; n->type = T;
break; break;
} }
if(n->val.ctype == CTSTR) {
n->type = types[TSTRING];
break;
}
yyerror("defaultlit: unknown literal: %#N", n); yyerror("defaultlit: unknown literal: %#N", n);
break; break;
case CTINT: case CTINT:
......
...@@ -805,6 +805,7 @@ int isslice(Type*); ...@@ -805,6 +805,7 @@ int isslice(Type*);
int isinter(Type*); int isinter(Type*);
int isnilinter(Type*); int isnilinter(Type*);
int isddd(Type*); int isddd(Type*);
int isideal(Type*);
Type* maptype(Type*, Type*); Type* maptype(Type*, Type*);
Type* methtype(Type*); Type* methtype(Type*);
Node* typename(Type*); Node* typename(Type*);
......
...@@ -320,7 +320,7 @@ dextratype(Type *t) ...@@ -320,7 +320,7 @@ dextratype(Type *t)
else else
ot = duintptr(s, ot, 0); ot = duintptr(s, ot, 0);
} }
ggloblsym(s, ot, 1); ggloblsym(s, ot, 0);
return s; return s;
} }
...@@ -480,6 +480,10 @@ dtypesym(Type *t) ...@@ -480,6 +480,10 @@ dtypesym(Type *t)
Sym *s, *s1, *s2; Sym *s, *s1, *s2;
Sig *a, *m; Sig *a, *m;
Type *t1; Type *t1;
Sym *tsym;
if(t->etype == TNIL || t->etype == TIDEAL || t == idealstring)
fatal("dtypesym ideal %T", t);
s = typesym(t); s = typesym(t);
if(s->flags & SymSiggen) if(s->flags & SymSiggen)
...@@ -492,6 +496,11 @@ dtypesym(Type *t) ...@@ -492,6 +496,11 @@ dtypesym(Type *t)
t1 = T; t1 = T;
if(isptr[t->etype]) if(isptr[t->etype])
t1 = t->type; t1 = t->type;
tsym = S;
if(t1)
tsym = t1->sym;
else
tsym = t->sym;
if(strcmp(package, "runtime") == 0) { if(strcmp(package, "runtime") == 0) {
if(t == types[t->etype]) if(t == types[t->etype])
...@@ -639,7 +648,7 @@ ok: ...@@ -639,7 +648,7 @@ ok:
break; break;
} }
ggloblsym(s, ot, 1); ggloblsym(s, ot, tsym == nil);
return s; return s;
} }
......
...@@ -1468,6 +1468,16 @@ isddd(Type *t) ...@@ -1468,6 +1468,16 @@ isddd(Type *t)
return 0; return 0;
} }
int
isideal(Type *t)
{
if(t == T)
return 0;
if(t == idealstring)
return 1;
return t->etype == TNIL || t->etype == TIDEAL;
}
/* /*
* given receiver of type t (t == r or t == *r) * given receiver of type t (t == r or t == *r)
* return type to hang methods off (r). * return type to hang methods off (r).
......
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