From ef4ddd63f8d98300cf014a5d4a74dcff3f7e4dc3 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 6 Jul 2009 21:39:18 -0700 Subject: [PATCH] another piece for cross-file forward struct declarations. R=ken OCL=31233 CL=31233 --- src/cmd/gc/dcl.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cmd/gc/dcl.c b/src/cmd/gc/dcl.c index 0fe204d463..73cf7786a7 100644 --- a/src/cmd/gc/dcl.c +++ b/src/cmd/gc/dcl.c @@ -67,11 +67,23 @@ dodcltype(Type *n) // if n has been forward declared, // use the Type* created then s = n->sym; - if(s->block == block && s->def != N && s->def->op == OTYPE) { + if((funcdepth == 0 || s->block == block) && s->def != N && s->def->op == OTYPE) { switch(s->def->type->etype) { case TFORWSTRUCT: case TFORWINTER: n = s->def->type; + if(s->block != block) { + // completing forward struct from other file + Dcl *d, *r; + d = dcl(); + d->dsym = s; + d->dtype = n; + d->op = OTYPE; + r = externdcl; + d->back = r->back; + r->back->forw = d; + r->back = d; + } goto found; } } @@ -109,6 +121,7 @@ updatetype(Type *n, Type *t) yyerror("%T forward declared as struct", n); return; } + n->local = 1; break; case TFORWINTER: