Skip to content

Commit

Permalink
more 6g reorg; checkpoint.
Browse files Browse the repository at this point in the history
typecheck.c is now responsible for all type checking
except for assignment and function argument "..."

R=ken
OCL=32661
CL=32667
  • Loading branch information
rsc committed Aug 3, 2009
1 parent 1780890 commit 9dc22b6
Show file tree
Hide file tree
Showing 25 changed files with 1,175 additions and 1,413 deletions.
2 changes: 2 additions & 0 deletions src/cmd/8g/gsubr.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,8 @@ nodarg(Type *t, int fp)
n->class = PPARAM;
break;
}

n->typecheck = 1;
return n;
}

Expand Down
8 changes: 5 additions & 3 deletions src/cmd/gc/const.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ convlit1(Node **np, Type *t, int explicit)
defaultlit(&n, T);
*np = n;
}
yyerror("cannot convert %T constant to %T", n->type, t);
n->diag = 1;
return;
}

Expand Down Expand Up @@ -336,6 +334,9 @@ evconst(Node *n)

switch(n->op) {
case OMAKE:
case OMAKEMAP:
case OMAKESLICE:
case OMAKECHAN:
return;
}

Expand Down Expand Up @@ -557,7 +558,7 @@ evconst(Node *n)
if(cmpslit(nl, nr) > 0)
goto settrue;
goto setfalse;
case TUP(OADD, CTSTR):
case TUP(OADDSTR, CTSTR):
len = v.u.sval->len + nr->val.u.sval->len;
str = mal(sizeof(*str) + len);
str->len = len;
Expand Down Expand Up @@ -605,6 +606,7 @@ evconst(Node *n)
case TUP(OCONV, CTFLT):
case TUP(OCONV, CTSTR):
case TUP(OCONV, CTNIL):
case TUP(OARRAYBYTESTR, CTNIL):
convlit1(&nl, n->type, 1);
break;

Expand Down
28 changes: 21 additions & 7 deletions src/cmd/gc/dcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,9 @@ funclit1(Node *ntype, NodeList *body)
for(l=func->cvars; l; l=l->next) {
a = l->n;
d = oldname(a->sym);
addrescapes(d);
args = list(args, nod(OADDR, d, N));
}
typechecklist(args, Erv);

n = nod(OCALL, clos, N);
n->list = args;
Expand Down Expand Up @@ -1642,7 +1642,7 @@ embedded(Sym *s)
NodeList*
variter(NodeList *vl, Node *nt, NodeList *el)
{
int doexpr;
int doexpr, lno;
Node *v, *e, *a;
Type *tv;
NodeList *r;
Expand All @@ -1663,23 +1663,37 @@ variter(NodeList *vl, Node *nt, NodeList *el)
break;
}
e = el->n;
el = el->next;
} else
e = N;

v = vl->n;
tv = t;
if(t == T) {
if(e) {
lno = lineno;
lineno = v->lineno;
typecheck(&e, Erv);
defaultlit(&e, T);
tv = e->type;
defaultlit(&e, t);
if(t)
e = typecheckconv(nil, e, t, 0);
if(tv == nil)
tv = e->type;
if(tv && tv->etype == TNIL) {
yyerror("cannot initialize %#N to untyped nil", v);
tv = nil;
}
lineno = lno;
}

a = N;
if(e != N || funcdepth > 0)
if((e != N && tv != T) || funcdepth > 0)
a = nod(OAS, v, e);
dodclvar(v, tv, &r);
if(a != N)
r = list(r, a);
if(el) {
el->n = e;
el = el->next;
}
}
if(el != nil)
yyerror("extra expr in var dcl");
Expand Down
34 changes: 19 additions & 15 deletions src/cmd/gc/go.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,36 +328,41 @@ enum
OLITERAL,

// exprs
OADD, OSUB, OOR, OXOR,
OADD, OSUB, OOR, OXOR, OADDSTR,
OADDR,
OANDAND,
OAPPENDSTR,
OARRAY,
OARRAYBYTESTR, OARRAYRUNESTR,
OAS, OAS2, OASOP,
OBAD,
OCALL, OCALLFUNC, OCALLMETH, OCALLINTER,
OCAP,
OCLOSE,
OCLOSED,
OCOMPOS, OCOMPSLICE, OCOMPMAP,
OCONV, OCONVNOP, OCONVRUNE, OCONVSTRB, OCONVSTRI, OCONVA2S,
OCMPIFACE, OCMPSTR,
OCOMPLIT, OMAPLIT, OSTRUCTLIT, OARRAYLIT,
OCOMPSLICE, OCOMPMAP,
OCONV, OCONVNOP, OCONVA2S, OCONVIFACE, OCONVSLICE,
ODCL, ODCLFUNC, ODCLFIELD, ODCLARG,
ODOT, ODOTPTR, ODOTMETH, ODOTINTER,
ODOTTYPE,
OEQ, ONE, OLT, OLE, OGE, OGT,
OFUNC,
OIND,
OINDEX, OINDEXSTR, OINDEXMAP, OINDEXARR,
OINDEX, OINDEXSTR, OINDEXMAP,
OKEY, OPARAM,
OLEN,
OMAKE,
OMAKE, OMAKECHAN, OMAKEMAP, OMAKESLICE,
OMUL, ODIV, OMOD, OLSH, ORSH, OAND, OANDNOT,
ONEW,
ONOT, OCOM, OPLUS, OMINUS,
OOROR,
OPANIC, OPANICN, OPRINT, OPRINTN,
OSEND,
OSLICE, OSLICESTR, OSLICEARR,
OSEND, OSENDNB,
OSLICE, OSLICEARR, OSLICESTR,
ORECV,
ORUNESTR,

// stmts
OBLOCK,
Expand Down Expand Up @@ -470,10 +475,9 @@ enum
enum
{
Etop = 1<<1, // evaluated at statement level
Elv = 1<<2, // evaluated in lvalue context
Erv = 1<<3, // evaluated in rvalue context
Etype = 1<<4,
Ecall = 1<<5,
Erv = 1<<2, // evaluated in value context
Etype = 1<<3,
Ecall = 1<<4,
};

#define BITS 5
Expand Down Expand Up @@ -658,6 +662,8 @@ EXTERN ushort blockgen; // max block number
EXTERN ushort block; // current block number
EXTERN int hasdefer; // flag that curfn has defer statetment

EXTERN Node* curfn;

EXTERN int maxround;
EXTERN int widthptr;

Expand Down Expand Up @@ -986,14 +992,12 @@ NodeList* ascompatet(int, NodeList*, Type**, int, NodeList**);
NodeList* ascompatte(int, Type**, NodeList*, int, NodeList**);
int ascompat(Type*, Type*);
Node* newcompat(Node*);
Node* makecompat(Node*);
Node* stringop(Node*, NodeList**);
Type* fixmap(Type*);
Node* mapop(Node*, NodeList**);
Type* fixchan(Type*);
Node* chanop(Node*, NodeList**);
Node* arrayop(Node*);
Node* ifacecvt(Type*, Node*, int);
Node* ifacecvt(Type*, Node*, int, NodeList**);
Node* ifaceop(Node*);
int ifaceas(Type*, Type*, int);
int ifaceas1(Type*, Type*, int);
Expand All @@ -1011,11 +1015,11 @@ Node* arraylit(Node*, Node*, NodeList**);
Node* maplit(Node*, Node*, NodeList**);
Node* selectas(Node*, Node*, NodeList**);
Node* old2new(Node*, Type*, NodeList**);
void addrescapes(Node*);
void heapmoves(void);
void walkdeflist(NodeList*);
void walkdef(Node*);
void typechecklist(NodeList*, int);
Node* typecheckconv(Node*, Node*, Type*, int);
Node* typecheck(Node**, int);

/*
Expand Down
7 changes: 4 additions & 3 deletions src/cmd/gc/go.y
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ file:
{
if(debug['f'])
frame(1);
fninit($4);
if(nerrors == 0)
fninit($4);
if(nsyntaxerrors == 0)
testdclstack();
}
Expand Down Expand Up @@ -882,7 +883,7 @@ pexpr:
| convtype lbrace braced_keyval_list '}'
{
// composite expression
$$ = nod(OCOMPOS, N, $1);
$$ = nod(OCOMPLIT, N, $1);
$$->list = $3;

// If the opening brace was an LBODY,
Expand All @@ -894,7 +895,7 @@ pexpr:
| pexpr '{' braced_keyval_list '}'
{
// composite expression
$$ = nod(OCOMPOS, N, $1);
$$ = nod(OCOMPLIT, N, $1);
$$->list = $3;
}
| fnliteral
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/gc/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,12 @@ exprfmt(Fmt *f, Node *n, int prec)
exprfmt(f, n->left, 0);
break;

case OCOMPOS:
case OCOMPLIT:
fmtprint(f, "<compos>");
break;

case ODOT:
case ODOTPTR:
case ODOTINTER:
case ODOTMETH:
exprfmt(f, n->left, 7);
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/gc/sinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/*
* static initialization
*/

#include "go.h"

static struct
Expand Down
30 changes: 12 additions & 18 deletions src/cmd/gc/subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,14 @@ Nconv(Fmt *fp)
goto out;
}

if(fp->flags & FmtSign) {
if(n->type == T || n->type->etype == TNIL)
fmtprint(fp, "nil");
else
fmtprint(fp, "%#N (type %T)", n, n->type);
goto out;
}

if(fp->flags & FmtSharp) {
exprfmt(fp, n, 0);
goto out;
Expand Down Expand Up @@ -1593,22 +1601,7 @@ eqtype(Type *t1, Type *t2)
int
cvttype(Type *dst, Type *src)
{
Sym *ds, *ss;
int ret;

if(eqtype1(dst, src, 0, 0))
return 1;

// Can convert if assignment compatible when
// top-level names are ignored.
ds = dst->sym;
dst->sym = nil;
ss = src->sym;
src->sym = nil;
ret = ascompat(dst, src);
dst->sym = ds;
src->sym = ss;
return ret == 1;
return eqtype1(dst, src, 0, 0);
}

int
Expand Down Expand Up @@ -1746,6 +1739,7 @@ noconv(Type *t1, Type *t2)
void
argtype(Node *on, Type *t)
{
dowidth(t);
if(!subtype(&on->type, t, 0))
fatal("argtype: failed %N %T\n", on, t);
}
Expand Down Expand Up @@ -2274,7 +2268,7 @@ saferef(Node *n, NodeList **init)
r = nod(OXXX, N, N);
*r = *n;
r->left = l;
typecheck(&r, Elv);
typecheck(&r, Erv);
walkexpr(&r, init);
return r;

Expand All @@ -2288,7 +2282,7 @@ saferef(Node *n, NodeList **init)
walkexpr(&a, init);
*init = list(*init, a);
r = nod(OIND, l, N);
typecheck(&r, Elv);
typecheck(&r, Erv);
walkexpr(&r, init);
return r;
}
Expand Down
Loading

0 comments on commit 9dc22b6

Please sign in to comment.