Commit 9271c640 authored by Russ Cox's avatar Russ Cox

introduce typecheck pass before walkexpr.

not complete but compiler still works.

R=ken
OCL=32424
CL=32426
parent 056940d8
......@@ -257,8 +257,10 @@ typeinit(void)
* initialize okfor
*/
for(i=0; i<NTYPE; i++) {
if(isint[i]) {
if(isint[i] || i == TIDEAL) {
okforeq[i] = 1;
okforcmp[i] = 1;
okforarith[i] = 1;
okforadd[i] = 1;
okforand[i] = 1;
issimple[i] = 1;
......@@ -267,26 +269,76 @@ typeinit(void)
}
if(isfloat[i]) {
okforeq[i] = 1;
okforcmp[i] = 1;
okforadd[i] = 1;
okforarith[i] = 1;
issimple[i] = 1;
minfltval[i] = mal(sizeof(*minfltval[i]));
maxfltval[i] = mal(sizeof(*maxfltval[i]));
}
switch(i) {
case TBOOL:
issimple[i] = 1;
case TPTR32:
case TPTR64:
case TINTER:
case TMAP:
case TCHAN:
case TFUNC:
okforeq[i] = 1;
break;
}
}
issimple[TBOOL] = 1;
okforadd[TSTRING] = 1;
okforbool[TBOOL] = 1;
okforcap[TARRAY] = 1;
//okforcap[TCHAN] = 1;
//okforcap[TMAP] = 1;
okforlen[TARRAY] = 1;
//okforlen[TCHAN] = 1;
okforlen[TMAP] = 1;
okforlen[TSTRING] = 1;
okforeq[TPTR32] = 1;
okforeq[TPTR64] = 1;
okforeq[TINTER] = 1;
okforeq[TMAP] = 1;
okforeq[TCHAN] = 1;
okforeq[TFUNC] = 1;
okforeq[TSTRING] = 1;
okforeq[TBOOL] = 1;
okforeq[TARRAY] = 1; // refined in typecheck
okforcmp[TSTRING] = 1;
for(i=0; i<nelem(okfor); i++)
okfor[i] = okfornone;
// binary
okfor[OADD] = okforadd;
okfor[OAND] = okforand;
okfor[OANDAND] = okforbool;
okfor[OANDNOT] = okforand;
okfor[ODIV] = okforarith;
okfor[OEQ] = okforeq;
okfor[OGE] = okforcmp;
okfor[OGT] = okforcmp;
okfor[OLE] = okforcmp;
okfor[OLT] = okforcmp;
okfor[OMOD] = okforarith;
okfor[OMUL] = okforarith;
okfor[ONE] = okforeq;
okfor[OOR] = okforand;
okfor[OOROR] = okforbool;
okfor[OSUB] = okforarith;
okfor[OXOR] = okforand;
okfor[OLSH] = okforand;
okfor[ORSH] = okforand;
// unary
okfor[OCOM] = okforand;
okfor[OMINUS] = okforarith;
okfor[ONOT] = okforbool;
okfor[OPLUS] = okforadd;
// special
okfor[OCAP] = okforcap;
okfor[OLEN] = okforlen;
mpatofix(maxintval[TINT8], "0x7f");
mpatofix(minintval[TINT8], "-0x80");
mpatofix(maxintval[TINT16], "0x7fff");
......
......@@ -587,6 +587,12 @@ unary:
}
return;
case TUP(OCONV, CTINT):
case TUP(OCONV, CTFLT):
case TUP(OCONV, CTSTR):
convlit1(&nl, n->type, 1);
break;
case TUP(OPLUS, CTINT):
break;
case TUP(OMINUS, CTINT):
......@@ -711,7 +717,7 @@ defaultlit(Node **np, Type *t)
lineno = n->lineno;
switch(n->val.ctype) {
default:
yyerror("defaultlit: unknown literal: %N", n);
yyerror("defaultlit: unknown literal: %#N", n);
break;
case CTINT:
n->type = types[TINT];
......
......@@ -195,6 +195,7 @@ struct Node
uchar funcdepth;
uchar builtin; // built-in name, like len or close
uchar walkdef;
uchar typecheck;
// most nodes
Node* left;
......@@ -435,12 +436,11 @@ enum
enum
{
Exxx,
Eyyy,
Etop, // evaluated at statement level
Elv, // evaluated in lvalue context
Erv, // evaluated in rvalue context
Etype = 1<<8,
Etop = 1<<1, // evaluated at statement level
Elv = 1<<2, // evaluated in lvalue context
Erv = 1<<3, // evaluated in rvalue context
Etype = 1<<4,
Eideal = 1<<5,
};
#define BITS 5
......@@ -574,6 +574,7 @@ EXTERN char* filename; // name to uniqify names
EXTERN Idir* idirs;
EXTERN Type* types[NTYPE];
EXTERN Type* idealstring;
EXTERN uchar simtype[NTYPE];
EXTERN uchar isptr[NTYPE];
EXTERN uchar isforw[NTYPE];
......@@ -581,10 +582,17 @@ EXTERN uchar isint[NTYPE];
EXTERN uchar isfloat[NTYPE];
EXTERN uchar issigned[NTYPE];
EXTERN uchar issimple[NTYPE];
EXTERN uchar okforeq[NTYPE];
EXTERN uchar okforadd[NTYPE];
EXTERN uchar okforand[NTYPE];
EXTERN Type* idealstring;
EXTERN uchar okfornone[NTYPE];
EXTERN uchar okforcmp[NTYPE];
EXTERN uchar okforbool[NTYPE];
EXTERN uchar okforcap[NTYPE];
EXTERN uchar okforlen[NTYPE];
EXTERN uchar okforarith[NTYPE];
EXTERN uchar* okfor[OEND];
EXTERN Mpint* minintval[NTYPE];
EXTERN Mpint* maxintval[NTYPE];
......@@ -977,6 +985,8 @@ void addrescapes(Node*);
void heapmoves(void);
void walkdeflist(NodeList*);
void walkdef(Node*);
void typechecklist(NodeList*, int);
Node* typecheck(Node**, int);
/*
* const.c
......
......@@ -1324,7 +1324,7 @@ Nconv(Fmt *fp)
fmtprint(fp, "<N>");
goto out;
}
if(fp->flags & FmtSharp) {
exprfmt(fp, n, 0);
goto out;
......@@ -2123,7 +2123,6 @@ out:
void
badtype(int o, Type *tl, Type *tr)
{
yyerror("illegal types for operand: %O", o);
if(tl != T)
print(" %T\n", tl);
......@@ -2346,7 +2345,6 @@ tempname(Node *n, Type *t)
n->op = ONAME;
n->sym = s;
n->type = t;
n->etype = t->etype;
n->class = PAUTO;
n->addable = 1;
n->ullman = 1;
......
This diff is collapsed.
......@@ -133,6 +133,7 @@ fixedbugs/bug039.go:6: variable x redeclared in this block
previous declaration at fixedbugs/bug039.go:5
=========== fixedbugs/bug049.go
fixedbugs/bug049.go:6: invalid operation: s == nil
fixedbugs/bug049.go:6: illegal types for operand: EQ
string
nil
......
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