dcl.c 24.3 KB
Newer Older
1 2 3 4
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Russ Cox's avatar
Russ Cox committed
5 6
#include	<u.h>
#include	<libc.h>
7 8 9
#include	"go.h"
#include	"y.tab.h"

10
static	void	funcargs(Node*);
11
static	void	funcargs2(Type*);
12

Russ Cox's avatar
Russ Cox committed
13
static int
Ken Thompson's avatar
Ken Thompson committed
14 15 16 17 18 19
dflag(void)
{
	if(!debug['d'])
		return 0;
	if(debug['y'])
		return 1;
Russ Cox's avatar
Russ Cox committed
20
	if(incannedimport)
Ken Thompson's avatar
Ken Thompson committed
21 22 23 24
		return 0;
	return 1;
}

25
/*
Russ Cox's avatar
Russ Cox committed
26
 * declaration stack & operations
27
 */
Russ Cox's avatar
Russ Cox committed
28

Russ Cox's avatar
Russ Cox committed
29
static void
Russ Cox's avatar
Russ Cox committed
30
dcopy(Sym *a, Sym *b)
31
{
32
	a->pkg = b->pkg;
Russ Cox's avatar
Russ Cox committed
33 34 35 36 37
	a->name = b->name;
	a->def = b->def;
	a->block = b->block;
	a->lastlineno = b->lastlineno;
}
38

Russ Cox's avatar
Russ Cox committed
39
static Sym*
Russ Cox's avatar
Russ Cox committed
40 41 42
push(void)
{
	Sym *d;
43

Russ Cox's avatar
Russ Cox committed
44
	d = mal(sizeof(*d));
Russ Cox's avatar
Russ Cox committed
45
	d->lastlineno = lineno;
Russ Cox's avatar
Russ Cox committed
46 47 48
	d->link = dclstack;
	dclstack = d;
	return d;
49 50
}

Russ Cox's avatar
Russ Cox committed
51
static Sym*
Russ Cox's avatar
Russ Cox committed
52
pushdcl(Sym *s)
53
{
Russ Cox's avatar
Russ Cox committed
54 55 56 57
	Sym *d;

	d = push();
	dcopy(d, s);
58 59
	if(dflag())
		print("\t%L push %S %p\n", lineno, s, s->def);
Russ Cox's avatar
Russ Cox committed
60
	return d;
61 62
}

Russ Cox's avatar
Russ Cox committed
63 64
void
popdcl(void)
65
{
Russ Cox's avatar
Russ Cox committed
66
	Sym *d, *s;
Russ Cox's avatar
Russ Cox committed
67
	int lno;
68

Russ Cox's avatar
Russ Cox committed
69 70 71 72 73 74
//	if(dflag())
//		print("revert\n");

	for(d=dclstack; d!=S; d=d->link) {
		if(d->name == nil)
			break;
75
		s = pkglookup(d->name, d->pkg);
Russ Cox's avatar
Russ Cox committed
76
		lno = s->lastlineno;
Russ Cox's avatar
Russ Cox committed
77
		dcopy(s, d);
Russ Cox's avatar
Russ Cox committed
78
		d->lastlineno = lno;
Russ Cox's avatar
Russ Cox committed
79
		if(dflag())
80
			print("\t%L pop %S %p\n", lineno, s, s->def);
81
	}
Russ Cox's avatar
Russ Cox committed
82 83 84 85 86
	if(d == S)
		fatal("popdcl: no mark");
	dclstack = d->link;
	block = d->block;
}
87

Russ Cox's avatar
Russ Cox committed
88 89 90
void
poptodcl(void)
{
Russ Cox's avatar
Russ Cox committed
91 92 93 94 95 96
	// pop the old marker and push a new one
	// (cannot reuse the existing one)
	// because we use the markers to identify blocks
	// for the goto restriction checks.
	popdcl();
	markdcl();
97 98 99
}

void
Russ Cox's avatar
Russ Cox committed
100
markdcl(void)
101
{
Russ Cox's avatar
Russ Cox committed
102
	Sym *d;
103

Russ Cox's avatar
Russ Cox committed
104 105 106
	d = push();
	d->name = nil;		// used as a mark in fifo
	d->block = block;
107

Russ Cox's avatar
Russ Cox committed
108 109
	blockgen++;
	block = blockgen;
110

Russ Cox's avatar
Russ Cox committed
111 112 113
//	if(dflag())
//		print("markdcl\n");
}
Russ Cox's avatar
Russ Cox committed
114

Russ Cox's avatar
Russ Cox committed
115 116 117 118 119
void
dumpdcl(char *st)
{
	Sym *s, *d;
	int i;
120

Russ Cox's avatar
Russ Cox committed
121 122
	USED(st);

Russ Cox's avatar
Russ Cox committed
123 124 125 126 127 128 129 130 131
	i = 0;
	for(d=dclstack; d!=S; d=d->link) {
		i++;
		print("    %.2d %p", i, d);
		if(d->name == nil) {
			print("\n");
			continue;
		}
		print(" '%s'", d->name);
132
		s = pkglookup(d->name, d->pkg);
Russ Cox's avatar
Russ Cox committed
133
		print(" %lS\n", s);
134
	}
Russ Cox's avatar
Russ Cox committed
135
}
136

Russ Cox's avatar
Russ Cox committed
137 138 139 140
void
testdclstack(void)
{
	Sym *d;
141

Russ Cox's avatar
Russ Cox committed
142 143 144 145 146
	for(d=dclstack; d!=S; d=d->link) {
		if(d->name == nil) {
			yyerror("mark left on the stack");
			continue;
		}
Russ Cox's avatar
Russ Cox committed
147
	}
148 149
}

150 151 152
void
redeclare(Sym *s, char *where)
{
153 154 155 156 157 158 159 160
	if(s->lastlineno == 0)
		yyerror("%S redeclared %s\n"
			"\tprevious declaration during import",
			s, where);
	else
		yyerror("%S redeclared %s\n"
			"\tprevious declaration at %L",
			s, where, s->lastlineno);
161 162
}

163
/*
Russ Cox's avatar
Russ Cox committed
164
 * declare individual names - var, typ, const
165
 */
Russ Cox's avatar
Russ Cox committed
166
void
Russ Cox's avatar
Russ Cox committed
167
declare(Node *n, int ctxt)
168
{
Russ Cox's avatar
Russ Cox committed
169 170
	Sym *s;
	int gen;
Russ Cox's avatar
Russ Cox committed
171
	static int typegen, vargen;
172

Russ Cox's avatar
Russ Cox committed
173 174 175
	if(isblank(n))
		return;

176
	n->lineno = parserline();
Russ Cox's avatar
Russ Cox committed
177
	s = n->sym;
178 179 180 181 182

	// kludgy: typecheckok means we're past parsing.  Eg genwrapper may declare out of package names later.
	if(importpkg == nil && !typecheckok && s->pkg != localpkg)
		yyerror("cannot declare name %S", s);

Russ Cox's avatar
Russ Cox committed
183 184 185
	gen = 0;
	if(ctxt == PEXTERN) {
		externdcl = list(externdcl, n);
186 187
		if(dflag())
			print("\t%L global decl %S %p\n", lineno, s, n);
Russ Cox's avatar
Russ Cox committed
188
	} else {
189 190 191 192
		if(curfn == nil && ctxt == PAUTO)
			fatal("automatic outside function");
		if(curfn != nil)
			curfn->dcl = list(curfn->dcl, n);
Russ Cox's avatar
Russ Cox committed
193 194 195 196
		if(n->op == OTYPE)
			gen = ++typegen;
		else if(n->op == ONAME)
			gen = ++vargen;
Russ Cox's avatar
Russ Cox committed
197
		pushdcl(s);
198
		n->curfn = curfn;
Russ Cox's avatar
Russ Cox committed
199
	}
200
	if(ctxt == PAUTO)
Russ Cox's avatar
Russ Cox committed
201
		n->xoffset = 0;
202

203 204
	if(s->block == block)
		redeclare(s, "in this block");
205

Russ Cox's avatar
Russ Cox committed
206
	s->block = block;
207
	s->lastlineno = parserline();
Russ Cox's avatar
Russ Cox committed
208
	s->def = n;
Russ Cox's avatar
Russ Cox committed
209
	n->vargen = gen;
Russ Cox's avatar
Russ Cox committed
210
	n->funcdepth = funcdepth;
Russ Cox's avatar
Russ Cox committed
211
	n->class = ctxt;
212

Russ Cox's avatar
Russ Cox committed
213
	autoexport(n, ctxt);
214 215
}

Russ Cox's avatar
Russ Cox committed
216
void
Russ Cox's avatar
Russ Cox committed
217
addvar(Node *n, Type *t, int ctxt)
218
{
Russ Cox's avatar
Russ Cox committed
219 220
	if(n==N || n->sym == S || (n->op != ONAME && n->op != ONONAME) || t == T)
		fatal("addvar: n=%N t=%T nil", n, t);
Russ Cox's avatar
Russ Cox committed
221

Russ Cox's avatar
Russ Cox committed
222 223 224
	n->op = ONAME;
	declare(n, ctxt);
	n->type = t;
225 226 227
}

/*
Russ Cox's avatar
Russ Cox committed
228 229
 * declare variables from grammar
 * new_name_list (type | [type] = expr_list)
230
 */
Russ Cox's avatar
Russ Cox committed
231 232
NodeList*
variter(NodeList *vl, Node *t, NodeList *el)
233
{
Russ Cox's avatar
Russ Cox committed
234
	int doexpr;
235
	Node *v, *e, *as2;
Russ Cox's avatar
Russ Cox committed
236
	NodeList *init;
237

Russ Cox's avatar
Russ Cox committed
238 239
	init = nil;
	doexpr = el != nil;
240 241 242 243 244 245 246 247 248 249 250 251
	
	if(count(el) == 1 && count(vl) > 1) {
		e = el->n;
		as2 = nod(OAS2, N, N);
		as2->list = vl;
		as2->rlist = list1(e);
		for(; vl; vl=vl->next) {
			v = vl->n;
			v->op = ONAME;
			declare(v, dclcontext);
			v->ntype = t;
			v->defn = as2;
Russ Cox's avatar
Russ Cox committed
252 253
			if(funcdepth > 0)
				init = list(init, nod(ODCL, v, N));
254
		}
Russ Cox's avatar
Russ Cox committed
255
		return list(init, as2);
256 257
	}
	
Russ Cox's avatar
Russ Cox committed
258 259 260 261 262 263 264 265 266 267
	for(; vl; vl=vl->next) {
		if(doexpr) {
			if(el == nil) {
				yyerror("missing expr in var dcl");
				break;
			}
			e = el->n;
			el = el->next;
		} else
			e = N;
Russ Cox's avatar
Russ Cox committed
268

Russ Cox's avatar
Russ Cox committed
269
		v = vl->n;
Russ Cox's avatar
Russ Cox committed
270
		v->op = ONAME;
Russ Cox's avatar
Russ Cox committed
271
		declare(v, dclcontext);
Russ Cox's avatar
Russ Cox committed
272
		v->ntype = t;
Russ Cox's avatar
Russ Cox committed
273

274
		if(e != N || funcdepth > 0 || isblank(v)) {
Russ Cox's avatar
Russ Cox committed
275 276 277 278 279 280 281 282 283 284 285
			if(funcdepth > 0)
				init = list(init, nod(ODCL, v, N));
			e = nod(OAS, v, e);
			init = list(init, e);
			if(e->right != N)
				v->defn = e;
		}
	}
	if(el != nil)
		yyerror("extra expr in var dcl");
	return init;
286 287
}

Russ Cox's avatar
Russ Cox committed
288 289 290 291 292 293
/*
 * declare constants from grammar
 * new_name_list [[type] = expr_list]
 */
NodeList*
constiter(NodeList *vl, Node *t, NodeList *cl)
Russ Cox's avatar
Russ Cox committed
294
{
Russ Cox's avatar
Russ Cox committed
295 296
	Node *v, *c;
	NodeList *vv;
297

298
	vv = nil;
Russ Cox's avatar
Russ Cox committed
299 300 301 302 303 304 305 306
	if(cl == nil) {
		if(t != N)
			yyerror("constdcl cannot have type without expr");
		cl = lastconst;
		t = lasttype;
	} else {
		lastconst = cl;
		lasttype = t;
307
	}
Russ Cox's avatar
Russ Cox committed
308
	cl = listtreecopy(cl);
Russ Cox's avatar
Russ Cox committed
309

Russ Cox's avatar
Russ Cox committed
310 311 312 313
	for(; vl; vl=vl->next) {
		if(cl == nil) {
			yyerror("missing expr in const dcl");
			break;
Russ Cox's avatar
Russ Cox committed
314
		}
Russ Cox's avatar
Russ Cox committed
315 316
		c = cl->n;
		cl = cl->next;
Russ Cox's avatar
Russ Cox committed
317

Russ Cox's avatar
Russ Cox committed
318 319
		v = vl->n;
		v->op = OLITERAL;
Russ Cox's avatar
Russ Cox committed
320 321
		declare(v, dclcontext);

Russ Cox's avatar
Russ Cox committed
322 323
		v->ntype = t;
		v->defn = c;
324 325

		vv = list(vv, nod(ODCLCONST, v, N));
Russ Cox's avatar
Russ Cox committed
326
	}
Russ Cox's avatar
Russ Cox committed
327 328 329 330 331
	if(cl != nil)
		yyerror("extra expr in const dcl");
	iota += 1;
	return vv;
}
Russ Cox's avatar
Russ Cox committed
332

Russ Cox's avatar
Russ Cox committed
333
/*
Russ Cox's avatar
Russ Cox committed
334 335
 * this generates a new name node,
 * typically for labels or other one-off names.
Russ Cox's avatar
Russ Cox committed
336 337 338 339 340
 */
Node*
newname(Sym *s)
{
	Node *n;
341

342 343 344
	if(s == S)
		fatal("newname nil");

Russ Cox's avatar
Russ Cox committed
345 346 347 348 349 350 351 352
	n = nod(ONAME, N, N);
	n->sym = s;
	n->type = T;
	n->addable = 1;
	n->ullman = 1;
	n->xoffset = 0;
	return n;
}
Russ Cox's avatar
Russ Cox committed
353

Russ Cox's avatar
Russ Cox committed
354 355
/*
 * this generates a new name node for a name
356
 * being declared.
Russ Cox's avatar
Russ Cox committed
357
 */
Russ Cox's avatar
Russ Cox committed
358 359 360 361
Node*
dclname(Sym *s)
{
	Node *n;
Russ Cox's avatar
Russ Cox committed
362

Russ Cox's avatar
Russ Cox committed
363 364 365 366
	n = newname(s);
	n->op = ONONAME;	// caller will correct it
	return n;
}
Russ Cox's avatar
Russ Cox committed
367

Russ Cox's avatar
Russ Cox committed
368 369 370
Node*
typenod(Type *t)
{
371 372 373 374
	// if we copied another type with *t = *u
	// then t->nod might be out of date, so
	// check t->nod->type too
	if(t->nod == N || t->nod->type != t) {
Russ Cox's avatar
Russ Cox committed
375 376 377
		t->nod = nod(OTYPE, N, N);
		t->nod->type = t;
		t->nod->sym = t->sym;
Russ Cox's avatar
Russ Cox committed
378
	}
Russ Cox's avatar
Russ Cox committed
379
	return t->nod;
Russ Cox's avatar
Russ Cox committed
380 381
}

Russ Cox's avatar
Russ Cox committed
382

383
/*
Russ Cox's avatar
Russ Cox committed
384 385 386 387
 * this will return an old name
 * that has already been pushed on the
 * declaration list. a diagnostic is
 * generated if no name has been defined.
388
 */
Russ Cox's avatar
Russ Cox committed
389 390
Node*
oldname(Sym *s)
391
{
392
	Node *n;
Russ Cox's avatar
Russ Cox committed
393
	Node *c;
394

Russ Cox's avatar
Russ Cox committed
395 396 397 398
	n = s->def;
	if(n == N) {
		// maybe a top-level name will come along
		// to give this a definition later.
399 400
		// walkdef will check s->def again once
		// all the input source has been processed.
Russ Cox's avatar
Russ Cox committed
401 402
		n = newname(s);
		n->op = ONONAME;
403
		n->iota = iota;	// save current iota value in const declarations
Russ Cox's avatar
Russ Cox committed
404
	}
Russ Cox's avatar
Russ Cox committed
405
	if(curfn != nil && n->funcdepth > 0 && n->funcdepth != funcdepth && n->op == ONAME) {
406 407 408 409 410 411
		// inner func is referring to var in outer func.
		//
		// TODO(rsc): If there is an outer variable x and we
		// are parsing x := 5 inside the closure, until we get to
		// the := it looks like a reference to the outer x so we'll
		// make x a closure variable unnecessarily.
Russ Cox's avatar
Russ Cox committed
412 413 414 415 416
		if(n->closure == N || n->closure->funcdepth != funcdepth) {
			// create new closure var.
			c = nod(ONAME, N, N);
			c->sym = s;
			c->class = PPARAMREF;
Russ Cox's avatar
Russ Cox committed
417
			c->isddd = n->isddd;
418
			c->defn = n;
Russ Cox's avatar
Russ Cox committed
419 420 421 422 423
			c->addable = 0;
			c->ullman = 2;
			c->funcdepth = funcdepth;
			c->outer = n->closure;
			n->closure = c;
424
			n->addrtaken = 1;
Russ Cox's avatar
Russ Cox committed
425
			c->closure = n;
426 427
			c->xoffset = 0;
			curfn->cvars = list(curfn->cvars, c);
Russ Cox's avatar
Russ Cox committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
		}
		// return ref to closure var, not original
		return n->closure;
	}
	return n;
}

/*
 * same for types
 */
Type*
newtype(Sym *s)
{
	Type *t;

	t = typ(TFORW);
	t->sym = s;
	t->type = T;
	return t;
}


Russ Cox's avatar
Russ Cox committed
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
/*
 * := declarations
 */

static int
colasname(Node *n)
{
	switch(n->op) {
	case ONAME:
	case ONONAME:
	case OPACK:
	case OTYPE:
	case OLITERAL:
		return n->sym != S;
	}
	return 0;
}

468 469
void
colasdefn(NodeList *left, Node *defn)
Russ Cox's avatar
Russ Cox committed
470
{
Russ Cox's avatar
Russ Cox committed
471
	int nnew, nerr;
Russ Cox's avatar
Russ Cox committed
472
	NodeList *l;
473
	Node *n;
Russ Cox's avatar
Russ Cox committed
474 475

	nnew = 0;
Russ Cox's avatar
Russ Cox committed
476
	nerr = 0;
Russ Cox's avatar
Russ Cox committed
477 478
	for(l=left; l; l=l->next) {
		n = l->n;
Russ Cox's avatar
Russ Cox committed
479 480
		if(isblank(n))
			continue;
Russ Cox's avatar
Russ Cox committed
481
		if(!colasname(n)) {
Luuk van Dijk's avatar
Luuk van Dijk committed
482
			yyerror("non-name %N on left side of :=", n);
Russ Cox's avatar
Russ Cox committed
483
			nerr++;
Russ Cox's avatar
Russ Cox committed
484 485 486 487
			continue;
		}
		if(n->sym->block == block)
			continue;
488

Russ Cox's avatar
Russ Cox committed
489 490 491
		nnew++;
		n = newname(n->sym);
		declare(n, dclcontext);
492 493
		n->defn = defn;
		defn->ninit = list(defn->ninit, nod(ODCL, n, N));
Russ Cox's avatar
Russ Cox committed
494 495
		l->n = n;
	}
Russ Cox's avatar
Russ Cox committed
496
	if(nnew == 0 && nerr == 0)
Russ Cox's avatar
Russ Cox committed
497
		yyerror("no new variables on left side of :=");
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
}

Node*
colas(NodeList *left, NodeList *right)
{
	Node *as;

	as = nod(OAS2, N, N);
	as->list = left;
	as->rlist = right;
	as->colas = 1;
	colasdefn(left, as);

	// make the tree prettier; not necessary
	if(count(left) == 1 && count(right) == 1) {
		as->left = as->list->n;
		as->right = as->rlist->n;
		as->list = nil;
		as->rlist = nil;
		as->op = OAS;
	}

Russ Cox's avatar
Russ Cox committed
520 521 522
	return as;
}

523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
/*
 * declare the arguments in an
 * interface field declaration.
 */
void
ifacedcl(Node *n)
{
	if(n->op != ODCLFIELD || n->right == N)
		fatal("ifacedcl");

	dclcontext = PAUTO;
	markdcl();
	funcdepth++;
	n->outer = curfn;
	curfn = n;
	funcargs(n->right);

	// funcbody is normally called after the parser has
	// seen the body of a function but since an interface
	// field declaration does not have a body, we must
	// call it now to pop the current declaration context.
	funcbody(n);
}

547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
/*
 * declare the function proper
 * and declare the arguments.
 * called in extern-declaration context
 * returns in auto-declaration context.
 */
void
funchdr(Node *n)
{
	// change the declaration context from extern to auto
	if(funcdepth == 0 && dclcontext != PEXTERN)
		fatal("funchdr: dclcontext");

	dclcontext = PAUTO;
	markdcl();
	funcdepth++;

	n->outer = curfn;
	curfn = n;
566

567 568
	if(n->nname)
		funcargs(n->nname->ntype);
569
	else if (n->ntype)
570
		funcargs(n->ntype);
571 572
	else
		funcargs2(n->type);
573 574 575 576 577
}

static void
funcargs(Node *nt)
{
578
	Node *n, *nn;
579
	NodeList *l;
Russ Cox's avatar
Russ Cox committed
580
	int gen;
581 582 583 584 585 586

	if(nt->op != OTFUNC)
		fatal("funcargs %O", nt->op);

	// declare the receiver and in arguments.
	// no n->defn because type checking of func header
587
	// will not fill in the types until later
588 589 590
	if(nt->left != N) {
		n = nt->left;
		if(n->op != ODCLFIELD)
591
			fatal("funcargs receiver %O", n->op);
592 593 594 595 596 597 598 599 600
		if(n->left != N) {
			n->left->op = ONAME;
			n->left->ntype = n->right;
			declare(n->left, PPARAM);
		}
	}
	for(l=nt->list; l; l=l->next) {
		n = l->n;
		if(n->op != ODCLFIELD)
601
			fatal("funcargs in %O", n->op);
602 603 604 605 606 607 608 609
		if(n->left != N) {
			n->left->op = ONAME;
			n->left->ntype = n->right;
			declare(n->left, PPARAM);
		}
	}

	// declare the out arguments.
Russ Cox's avatar
Russ Cox committed
610
	gen = 0;
611 612 613
	for(l=nt->rlist; l; l=l->next) {
		n = l->n;
		if(n->op != ODCLFIELD)
614
			fatal("funcargs out %O", n->op);
615 616 617
		if(n->left != N) {
			n->left->op = ONAME;
			n->left->ntype = n->right;
Russ Cox's avatar
Russ Cox committed
618 619
			if(isblank(n->left)) {
				// Give it a name so we can assign to it during return.
620 621 622 623
				// preserve the original in ->orig
				nn = nod(OXXX, N, N);
				*nn = *n->left;
				n->left = nn;
Russ Cox's avatar
Russ Cox committed
624 625 626
				snprint(namebuf, sizeof(namebuf), ".anon%d", gen++);
				n->left->sym = lookup(namebuf);
			}
627 628 629 630 631
			declare(n->left, PPARAMOUT);
		}
	}
}

632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
/*
 * Same as funcargs, except run over an already constructed TFUNC.
 * This happens during import, where the hidden_fndcl rule has
 * used functype directly to parse the function's type.
 */
static void
funcargs2(Type *t)
{
	Type *ft;
	Node *n;

	if(t->etype != TFUNC)
		fatal("funcargs2 %T", t);
	
	if(t->thistuple)
		for(ft=getthisx(t)->type; ft; ft=ft->down) {
			if(!ft->nname || !ft->nname->sym)
				continue;
Russ Cox's avatar
Russ Cox committed
650
			n = ft->nname;  // no need for newname(ft->nname->sym)
651 652 653 654 655 656 657 658
			n->type = ft->type;
			declare(n, PPARAM);
		}

	if(t->intuple)
		for(ft=getinargx(t)->type; ft; ft=ft->down) {
			if(!ft->nname || !ft->nname->sym)
				continue;
Russ Cox's avatar
Russ Cox committed
659
			n = ft->nname;
660 661 662 663 664 665 666 667
			n->type = ft->type;
			declare(n, PPARAM);
		}

	if(t->outtuple)
		for(ft=getoutargx(t)->type; ft; ft=ft->down) {
			if(!ft->nname || !ft->nname->sym)
				continue;
Russ Cox's avatar
Russ Cox committed
668
			n = ft->nname;
669 670 671 672 673
			n->type = ft->type;
			declare(n, PPARAMOUT);
		}
}

674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
/*
 * finish the body.
 * called in auto-declaration context.
 * returns in extern-declaration context.
 */
void
funcbody(Node *n)
{
	// change the declaration context from auto to extern
	if(dclcontext != PAUTO)
		fatal("funcbody: dclcontext");
	popdcl();
	funcdepth--;
	curfn = n->outer;
	n->outer = N;
	if(funcdepth == 0)
		dclcontext = PEXTERN;
}

/*
 * new type being defined with name s.
 */
Node*
typedcl0(Sym *s)
{
699
	Node *n;
700

701
	n = newname(s);
702 703 704 705 706 707 708
	n->op = OTYPE;
	declare(n, dclcontext);
	return n;
}

/*
 * node n, which was returned by typedcl0
709
 * is being declared to have uncompiled type t.
710 711 712 713 714 715 716 717 718 719
 * return the ODCLTYPE node to use.
 */
Node*
typedcl1(Node *n, Node *t, int local)
{
	n->ntype = t;
	n->local = local;
	return nod(ODCLTYPE, n, N);
}

Russ Cox's avatar
Russ Cox committed
720 721 722 723 724
/*
 * structs, functions, and methods.
 * they don't belong here, but where do they belong?
 */

725 726 727 728 729
static void
checkembeddedtype(Type *t)
{
	if (t == T)
		return;
Russ Cox's avatar
Russ Cox committed
730

731 732 733 734 735 736 737 738 739 740 741 742 743
	if(t->sym == S && isptr[t->etype]) {
		t = t->type;
		if(t->etype == TINTER)
			yyerror("embedded type cannot be a pointer to interface");
	}
	if(isptr[t->etype])
		yyerror("embedded type cannot be a pointer");
	else if(t->etype == TFORW && t->embedlineno == 0)
		t->embedlineno = lineno;
}

static Type*
structfield(Node *n)
Russ Cox's avatar
Russ Cox committed
744
{
745
	Type *f;
Russ Cox's avatar
Russ Cox committed
746 747 748
	int lno;

	lno = lineno;
749
	lineno = n->lineno;
Russ Cox's avatar
Russ Cox committed
750

751 752
	if(n->op != ODCLFIELD)
		fatal("structfield: oops %N\n", n);
Russ Cox's avatar
Russ Cox committed
753

754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
	f = typ(TFIELD);
	f->isddd = n->isddd;

	if(n->right != N) {
		typecheck(&n->right, Etype);
		n->type = n->right->type;
		if(n->left != N)
			n->left->type = n->type;
		if(n->embedded)
			checkembeddedtype(n->type);
	}
	n->right = N;
		
	f->type = n->type;
	if(f->type == T)
		f->broke = 1;

	switch(n->val.ctype) {
	case CTSTR:
		f->note = n->val.u.sval;
		break;
	default:
		yyerror("field annotation must be string");
		// fallthrough
	case CTxxx:
		f->note = nil;
		break;
	}

	if(n->left && n->left->op == ONAME) {
		f->nname = n->left;
		f->embedded = n->embedded;
		f->sym = f->nname->sym;
	}

	lineno = lno;
	return f;
}

static void
checkdupfields(Type *t, char* what)
{
	Type* t1;
	int lno;

	lno = lineno;

	for( ; t; t=t->down)
		if(t->sym && t->nname && !isblank(t->nname))
			for(t1=t->down; t1; t1=t1->down)
				if(t1->sym == t->sym) {
					lineno = t->nname->lineno;
					yyerror("duplicate %s %s", what, t->sym->name);
					break;
Russ Cox's avatar
Russ Cox committed
808
				}
809

810 811
	lineno = lno;
}
812

813 814 815 816 817 818 819 820 821 822
/*
 * convert a parsed id/type list into
 * a type for struct/interface/arglist
 */
Type*
tostruct(NodeList *l)
{
	Type *t, *f, **tp;
	t = typ(TSTRUCT);

823 824 825 826 827 828
	for(tp = &t->type; l; l=l->next) {
		f = structfield(l->n);

		*tp = f;
		tp = &f->down;
	}
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851

	for(f=t->type; f && !t->broke; f=f->down)
		if(f->broke)
			t->broke = 1;

	checkdupfields(t->type, "field");

	if (!t->broke)
		checkwidth(t);

	return t;
}

static Type*
tofunargs(NodeList *l)
{
	Type *t, *f, **tp;

	t = typ(TSTRUCT);
	t->funarg = 1;

	for(tp = &t->type; l; l=l->next) {
		f = structfield(l->n);
852
		f->funarg = 1;
Russ Cox's avatar
Russ Cox committed
853

854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
		// esc.c needs to find f given a PPARAM to add the tag.
		if(l->n->left && l->n->left->class == PPARAM)
			l->n->left->paramfld = f;

		*tp = f;
		tp = &f->down;
	}

	for(f=t->type; f && !t->broke; f=f->down)
		if(f->broke)
			t->broke = 1;

	checkdupfields(t->type, "argument");
	return t;
}

static Type*
interfacefield(Node *n)
{
	Type *f;
	int lno;

	lno = lineno;
	lineno = n->lineno;

	if(n->op != ODCLFIELD)
		fatal("interfacefield: oops %N\n", n);

	if (n->val.ctype != CTxxx)
		yyerror("interface method cannot have annotation");

	f = typ(TFIELD);
	f->isddd = n->isddd;
	
	if(n->right != N) {
		if(n->left != N) {
			// queue resolution of method type for later.
			// right now all we need is the name list.
			// avoids cycles for recursive interface types.
			n->type = typ(TINTERMETH);
			n->type->nname = n->right;
			n->left->type = n->type;
			queuemethod(n);

			if(n->left->op == ONAME) {
				f->nname = n->left;
				f->embedded = n->embedded;
				f->sym = f->nname->sym;
				if(importpkg && !exportname(f->sym->name))
					f->sym = pkglookup(f->sym->name, structpkg);
904 905
			}

906 907 908 909
		} else {

			typecheck(&n->right, Etype);
			n->type = n->right->type;
910

911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
			if(n->embedded)
				checkembeddedtype(n->type);

			if(n->type)
				switch(n->type->etype) {
				case TINTER:
					break;
				case TFORW:
					yyerror("interface type loop involving %T", n->type);
					f->broke = 1;
					break;
				default:
					yyerror("interface contains embedded non-interface %T", n->type);
					f->broke = 1;
					break;
Russ Cox's avatar
Russ Cox committed
926
				}
927
		}
928 929
	}

930 931 932 933 934 935
	n->right = N;
	
	f->type = n->type;
	if(f->type == T)
		f->broke = 1;
	
936
	lineno = lno;
937
	return f;
938 939 940
}

Type*
941
tointerface(NodeList *l)
942
{
943
	Type *t, *f, **tp, **otp, *t1;
944

945
	t = typ(TINTER);
946
	t->orig = typ(TINTER);
947

948 949 950 951
	tp = &t->type;
	otp = &t->orig->type;

	for(; l; l=l->next) {
952
		f = interfacefield(l->n);
953 954 955 956
		*otp = typ(TFIELD);
		**otp = *f;
		otp = &(*otp)->down;

957 958 959 960 961 962 963
		if (l->n->left == N && f->type->etype == TINTER) {
			// embedded interface, inline methods
			for(t1=f->type->type; t1; t1=t1->down) {
				f = typ(TFIELD);
				f->type = t1->type;
				f->broke = t1->broke;
				f->sym = t1->sym;
964
				f->embedded = 1;
965 966 967 968 969 970 971 972 973
				if(f->sym)
					f->nname = newname(f->sym);
				*tp = f;
				tp = &f->down;
			}
		} else {
			*tp = f;
			tp = &f->down;
		}
Russ Cox's avatar
Russ Cox committed
974
	}
975 976 977 978 979 980 981 982 983

	for(f=t->type; f && !t->broke; f=f->down)
		if(f->broke)
			t->broke = 1;

	checkdupfields(t->type, "method");
	t = sortinter(t);
	checkwidth(t);

984 985 986
	return t;
}

Russ Cox's avatar
Russ Cox committed
987 988
Node*
embedded(Sym *s)
989
{
Russ Cox's avatar
Russ Cox committed
990 991
	Node *n;
	char *name;
992

Russ Cox's avatar
Russ Cox committed
993 994 995 996 997 998 999 1000 1001
	// Names sometimes have disambiguation junk
	// appended after a center dot.  Discard it when
	// making the name for the embedded struct field.
	enum { CenterDot = 0xB7 };
	name = s->name;
	if(utfrune(s->name, CenterDot)) {
		name = strdup(s->name);
		*utfrune(name, CenterDot) = 0;
	}
1002

1003 1004 1005 1006
	if(exportname(name) || s->pkg == builtinpkg)  // old behaviour, tests pass, but is it correct?
		n = newname(lookup(name));
	else
		n = newname(pkglookup(name, s->pkg));
1007
	n = nod(ODCLFIELD, n, oldname(s));
Russ Cox's avatar
Russ Cox committed
1008 1009
	n->embedded = 1;
	return n;
1010 1011
}

1012 1013 1014 1015
/*
 * check that the list of declarations is either all anonymous or all named
 */

Russ Cox's avatar
Russ Cox committed
1016 1017
static Node*
findtype(NodeList *l)
1018
{
Russ Cox's avatar
Russ Cox committed
1019 1020 1021 1022
	for(; l; l=l->next)
		if(l->n->op == OKEY)
			return l->n->right;
	return N;
1023 1024
}

Russ Cox's avatar
Russ Cox committed
1025
NodeList*
Russ Cox's avatar
Russ Cox committed
1026
checkarglist(NodeList *all, int input)
1027
{
Russ Cox's avatar
Russ Cox committed
1028
	int named;
1029
	Node *n, *t, *nextt;
Russ Cox's avatar
Russ Cox committed
1030
	NodeList *l;
Ken Thompson's avatar
Ken Thompson committed
1031

Russ Cox's avatar
Russ Cox committed
1032 1033 1034 1035 1036
	named = 0;
	for(l=all; l; l=l->next) {
		if(l->n->op == OKEY) {
			named = 1;
			break;
1037 1038
		}
	}
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
	if(named) {
		n = N;
		for(l=all; l; l=l->next) {
			n = l->n;
			if(n->op != OKEY && n->sym == S) {
				yyerror("mixed named and unnamed function parameters");
				break;
			}
		}
		if(l == nil && n != N && n->op != OKEY)
			yyerror("final function parameter must have type");
	}
1051

1052
	nextt = nil;
Russ Cox's avatar
Russ Cox committed
1053
	for(l=all; l; l=l->next) {
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
		// can cache result from findtype to avoid
		// quadratic behavior here, but unlikely to matter.
		n = l->n;
		if(named) {
			if(n->op == OKEY) {
				t = n->right;
				n = n->left;
				nextt = nil;
			} else {
				if(nextt == nil)
					nextt = findtype(l);
				t = nextt;
			}
		} else {
			t = n;
			n = N;
		}
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081

		// during import l->n->op is OKEY, but l->n->left->sym == S
		// means it was a '?', not that it was
		// a lone type This doesn't matter for the exported
		// declarations, which are parsed by rules that don't
		// use checkargs, but can happen for func literals in
		// the inline bodies.
		// TODO(rsc) this can go when typefmt case TFIELD in exportmode fmt.c prints _ instead of ?
		if(importpkg && n->sym == S)
			n = N;

1082 1083 1084
		if(n != N && n->sym == S) {
			t = n;
			n = N;
Russ Cox's avatar
Russ Cox committed
1085
		}
1086
		if(n != N)
1087 1088
			n = newname(n->sym);
		n = nod(ODCLFIELD, n, t);
Russ Cox's avatar
Russ Cox committed
1089
		if(n->right != N && n->right->op == ODDD) {
Russ Cox's avatar
Russ Cox committed
1090 1091 1092 1093
			if(!input)
				yyerror("cannot use ... in output argument list");
			else if(l->next != nil)
				yyerror("can only use ... as final argument in list");
Russ Cox's avatar
Russ Cox committed
1094 1095 1096
			n->right->op = OTARRAY;
			n->right->right = n->right->left;
			n->right->left = N;
Russ Cox's avatar
Russ Cox committed
1097 1098 1099
			n->isddd = 1;
			if(n->left != N)
				n->left->isddd = 1;
Russ Cox's avatar
Russ Cox committed
1100
		}
1101
		l->n = n;
1102
	}
Russ Cox's avatar
Russ Cox committed
1103
	return all;
1104 1105
}

1106

1107 1108 1109 1110 1111
Node*
fakethis(void)
{
	Node *n;

1112
	n = nod(ODCLFIELD, N, typenod(ptrto(typ(TSTRUCT))));
1113 1114 1115
	return n;
}

1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
/*
 * Is this field a method on an interface?
 * Those methods have an anonymous
 * *struct{} as the receiver.
 * (See fakethis above.)
 */
int
isifacemethod(Type *f)
{
	Type *rcvr;
	Type *t;

1128
	rcvr = getthisx(f)->type;
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
	if(rcvr->sym != S)
		return 0;
	t = rcvr->type;
	if(!isptr[t->etype])
		return 0;
	t = t->type;
	if(t->sym != S || t->etype != TSTRUCT || t->type != T)
		return 0;
	return 1;
}

1140
/*
Russ Cox's avatar
Russ Cox committed
1141 1142
 * turn a parsed function declaration
 * into a type
1143
 */
Russ Cox's avatar
Russ Cox committed
1144 1145
Type*
functype(Node *this, NodeList *in, NodeList *out)
1146
{
Russ Cox's avatar
Russ Cox committed
1147 1148
	Type *t;
	NodeList *rcvr;
1149

Russ Cox's avatar
Russ Cox committed
1150
	t = typ(TFUNC);
1151

Russ Cox's avatar
Russ Cox committed
1152 1153 1154
	rcvr = nil;
	if(this)
		rcvr = list1(this);
1155 1156 1157 1158 1159 1160
	t->type = tofunargs(rcvr);
	t->type->down = tofunargs(out);
	t->type->down->down = tofunargs(in);

	if (t->type->broke || t->type->down->broke || t->type->down->down->broke)
		t->broke = 1;
1161

Russ Cox's avatar
Russ Cox committed
1162 1163 1164 1165
	if(this)
		t->thistuple = 1;
	t->outtuple = count(out);
	t->intuple = count(in);
1166
	t->outnamed = t->outtuple > 0 && out->n->left != N;
1167

Russ Cox's avatar
Russ Cox committed
1168
	return t;
1169 1170
}

Russ Cox's avatar
Russ Cox committed
1171
Sym*
1172
methodsym(Sym *nsym, Type *t0, int iface)
1173
{
Russ Cox's avatar
Russ Cox committed
1174
	Sym *s;
Russ Cox's avatar
Russ Cox committed
1175
	char *p;
1176
	Type *t;
1177
	char *suffix;
1178

Russ Cox's avatar
Russ Cox committed
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
	t = t0;
	if(t == T)
		goto bad;
	s = t->sym;
	if(s == S) {
		if(!isptr[t->etype])
			goto bad;
		t = t->type;
		if(t == T)
			goto bad;
		s = t->sym;
		if(s == S)
			goto bad;
	}
1193

Russ Cox's avatar
Russ Cox committed
1194 1195 1196 1197
	// if t0 == *t and t0 has a sym,
	// we want to see *t, not t0, in the method name.
	if(t != t0 && t0->sym)
		t0 = ptrto(t);
1198

1199 1200 1201 1202 1203 1204
	suffix = "";
	if(iface) {
		dowidth(t0);
		if(t0->width < types[tptr]->width)
			suffix = "·i";
	}
1205
	if(t0->sym == S && isptr[t0->etype])
Luuk van Dijk's avatar
Luuk van Dijk committed
1206
		p = smprint("(%-hT).%s%s", t0, nsym->name, suffix);
1207
	else
Luuk van Dijk's avatar
Luuk van Dijk committed
1208
		p = smprint("%-hT.%s%s", t0, nsym->name, suffix);
Russ Cox's avatar
Russ Cox committed
1209 1210 1211
	s = pkglookup(p, s->pkg);
	free(p);
	return s;
Russ Cox's avatar
Russ Cox committed
1212

Russ Cox's avatar
Russ Cox committed
1213
bad:
1214
	yyerror("illegal receiver type: %T", t0);
Russ Cox's avatar
Russ Cox committed
1215
	return S;
1216 1217
}

1218
Node*
Russ Cox's avatar
Russ Cox committed
1219
methodname(Node *n, Type *t)
1220
{
Russ Cox's avatar
Russ Cox committed
1221 1222
	Sym *s;

1223
	s = methodsym(n->sym, t, 0);
Russ Cox's avatar
Russ Cox committed
1224 1225 1226
	if(s == S)
		return n;
	return newname(s);
1227 1228
}

1229 1230 1231 1232
Node*
methodname1(Node *n, Node *t)
{
	char *star;
Russ Cox's avatar
Russ Cox committed
1233
	char *p;
1234

1235
	star = nil;
1236 1237 1238 1239
	if(t->op == OIND) {
		star = "*";
		t = t->left;
	}
Russ Cox's avatar
Russ Cox committed
1240 1241
	if(t->sym == S || isblank(n))
		return newname(n->sym);
Russ Cox's avatar
Russ Cox committed
1242

1243 1244 1245 1246
	if(star)
		p = smprint("(%s%S).%S", star, t->sym, n->sym);
	else
		p = smprint("%S.%S", t->sym, n->sym);
1247 1248 1249 1250 1251

	if(exportname(t->sym->name))
		n = newname(lookup(p));
	else
		n = newname(pkglookup(p, t->sym->pkg));
Russ Cox's avatar
Russ Cox committed
1252 1253
	free(p);
	return n;
1254 1255
}

1256
/*
Russ Cox's avatar
Russ Cox committed
1257 1258
 * add a method, declared as a function,
 * n is fieldname, pa is base type, t is function type
1259
 */
Russ Cox's avatar
Russ Cox committed
1260
void
1261
addmethod(Sym *sf, Type *t, int local)
1262
{
Russ Cox's avatar
Russ Cox committed
1263
	Type *f, *d, *pa;
1264
	Node *n;
1265

Russ Cox's avatar
Russ Cox committed
1266 1267
	// get field sym
	if(sf == S)
1268
		fatal("no method symbol");
Russ Cox's avatar
Russ Cox committed
1269

Russ Cox's avatar
Russ Cox committed
1270
	// get parent type sym
1271 1272 1273 1274 1275
	pa = getthisx(t)->type;	// ptr to this structure
	if(pa == T) {
		yyerror("missing receiver");
		return;
	}
Russ Cox's avatar
Russ Cox committed
1276

1277
	pa = pa->type;
Russ Cox's avatar
Russ Cox committed
1278
	f = methtype(pa);
1279
	if(f == T) {
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289
		t = pa;
		if(t != T) {
			if(isptr[t->etype]) {
				if(t->sym != S) {
					yyerror("invalid receiver type %T (%T is a pointer type)", pa, t);
					return;
				}
				t = t->type;
			}
		}
1290 1291
		if(t->broke) // rely on typecheck having complained before
			return;
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
		if(t != T) {
			if(t->sym == S) {
				yyerror("invalid receiver type %T (%T is an unnamed type)", pa, t);
				return;
			}
			if(isptr[t->etype]) {
				yyerror("invalid receiver type %T (%T is a pointer type)", pa, t);
				return;
			}
			if(t->etype == TINTER) {
				yyerror("invalid receiver type %T (%T is an interface type)", pa, t);
				return;
			}
		}
		// Should have picked off all the reasons above,
		// but just in case, fall back to generic error.
1308 1309 1310
		yyerror("invalid receiver type %T", pa);
		return;
	}
Russ Cox's avatar
Russ Cox committed
1311

Russ Cox's avatar
Russ Cox committed
1312
	pa = f;
Russ Cox's avatar
Russ Cox committed
1313

Russ Cox's avatar
Russ Cox committed
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
	n = nod(ODCLFIELD, newname(sf), N);
	n->type = t;

	d = T;	// last found
	for(f=pa->method; f!=T; f=f->down) {
		d = f;
		if(f->etype != TFIELD)
			fatal("addmethod: not TFIELD: %N", f);
		if(strcmp(sf->name, f->sym->name) != 0)
			continue;
Russ Cox's avatar
Russ Cox committed
1324 1325
		if(!eqtype(t, f->type))
			yyerror("method redeclared: %T.%S\n\t%T\n\t%T", pa, sf, f->type, t);
Russ Cox's avatar
Russ Cox committed
1326
		return;
Russ Cox's avatar
Russ Cox committed
1327
	}
Russ Cox's avatar
Russ Cox committed
1328 1329 1330 1331 1332

	if(local && !pa->local) {
		// defining method on non-local type.
		yyerror("cannot define new methods on non-local type %T", pa);
		return;
Russ Cox's avatar
Russ Cox committed
1333
	}
Russ Cox's avatar
Russ Cox committed
1334

1335 1336 1337 1338 1339 1340
	f = structfield(n);

	// during import unexported method names should be in the type's package
	if(importpkg && f->sym && !exportname(f->sym->name) && f->sym->pkg != structpkg)
		fatal("imported method name %+S in wrong package %s\n", f->sym, structpkg->name);

Russ Cox's avatar
Russ Cox committed
1341
	if(d == T)
1342
		pa->method = f;
Russ Cox's avatar
Russ Cox committed
1343
	else
1344
		d->down = f;
Russ Cox's avatar
Russ Cox committed
1345
	return;
Russ Cox's avatar
Russ Cox committed
1346 1347
}

Russ Cox's avatar
Russ Cox committed
1348
void
Russ Cox's avatar
Russ Cox committed
1349
funccompile(Node *n, int isclosure)
Russ Cox's avatar
Russ Cox committed
1350
{
1351 1352
	stksize = BADWIDTH;
	maxarg = 0;
Russ Cox's avatar
Russ Cox committed
1353

1354 1355 1356 1357
	if(n->type == T) {
		if(nerrors == 0)
			fatal("funccompile missing type");
		return;
1358
	}
1359

1360 1361
	// assign parameter offsets
	checkwidth(n->type);
Russ Cox's avatar
Russ Cox committed
1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
	
	// record offset to actual frame pointer.
	// for closure, have to skip over leading pointers and PC slot.
	nodfp->xoffset = 0;
	if(isclosure) {
		NodeList *l;
		for(l=n->nname->ntype->list; l; l=l->next) {
			nodfp->xoffset += widthptr;
			if(l->n->left == N)	// found slot for PC
				break;
		}
	}
1374

1375 1376
	if(curfn)
		fatal("funccompile %S inside %S", n->nname->sym, curfn->nname->sym);
Ken Thompson's avatar
Ken Thompson committed
1377

1378
	stksize = 0;
Russ Cox's avatar
Russ Cox committed
1379
	dclcontext = PAUTO;
1380
	funcdepth = n->funcdepth + 1;
Russ Cox's avatar
Russ Cox committed
1381
	compile(n);
1382 1383 1384
	curfn = nil;
	funcdepth = 0;
	dclcontext = PEXTERN;
1385
}