]> Cypherpunks repositories - gostls13.git/commitdiff
another piece for cross-file forward struct declarations.
authorRuss Cox <rsc@golang.org>
Tue, 7 Jul 2009 04:39:18 +0000 (21:39 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 7 Jul 2009 04:39:18 +0000 (21:39 -0700)
R=ken
OCL=31233
CL=31233

src/cmd/gc/dcl.c

index 0fe204d463a320d6f0e08c3a109af7020f69944c..73cf7786a72e309f85e863f12e019019115f4bb9 100644 (file)
@@ -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: