]> Cypherpunks repositories - gostls13.git/commitdiff
6g:
authorRuss Cox <rsc@golang.org>
Tue, 21 Oct 2008 21:34:45 +0000 (14:34 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 21 Oct 2008 21:34:45 +0000 (14:34 -0700)
* print int as int, not P.int
* write type info for non-exported types
   in its own new section.

ar:
skip over rest of line after $$

R=ken
OCL=17568
CL=17568

src/cmd/ar/ar.c
src/cmd/gc/dcl.c
src/cmd/gc/export.c
src/cmd/gc/go.h
src/cmd/gc/lex.c
src/cmd/gc/subr.c
test/golden.out

index aeccc8e57308bd08fcae9a99f50628f3bc25ebaa..7b1db9676dadc2b1f549f80bf9e1325f9db496ec 100644 (file)
@@ -674,8 +674,13 @@ scanpkg(Biobuf *b, long size)
        return;
 
 foundstart:
-       pkg = nil;
+       /* found $$; skip rest of line */
+       while((c = Bgetc(b)) != '\n')
+               if(c == Beof)
+                       goto bad;
+
        /* how big is it? */
+       pkg = nil;
        first = 1;
        start = end = 0;
        for (n=0; n<size; n+=Blinelen(b)) {
@@ -1457,7 +1462,7 @@ ilookup(char *name)
 {
        int h;
        Import *x;
-       
+
        h = hashstr(name) % NIHASH;
        for(x=ihash[h]; x; x=x->hash)
                if(x->name[0] == name[0] && strcmp(x->name, name) == 0)
@@ -1480,7 +1485,7 @@ loadpkgdata(char *data, int len)
        char *p, *ep, *prefix, *name, *def;
        Import *x;
 
-       file = arstrdup(file);  
+       file = arstrdup(file);
        p = data;
        ep = data + len;
        while(parsepkgdata(&p, ep, &export, &prefix, &name, &def) > 0) {
@@ -1503,7 +1508,7 @@ loadpkgdata(char *data, int len)
                                fprint(2, "%s:\t%s %s %s\n", file, prefix, name, def);
                                errors++;
                        }
-                       
+
                        // okay if some .6 say export and others don't.
                        // all it takes is one.
                        if(export)
@@ -1517,7 +1522,7 @@ parsepkgdata(char **pp, char *ep, int *exportp, char **prefixp, char **namep, ch
 {
        char *p, *prefix, *name, *def, *edef, *meth;
        int n;
-       
+
        // skip white space
        p = *pp;
        while(p < ep && (*p == ' ' || *p == '\t'))
@@ -1532,9 +1537,9 @@ parsepkgdata(char **pp, char *ep, int *exportp, char **prefixp, char **namep, ch
                p += 7;
        }
 
-       // prefix: (var|type|func|const)        
+       // prefix: (var|type|func|const)
        prefix = p;
-       
+
        prefix = p;
        if(p + 6 > ep)
                return -1;
@@ -1552,7 +1557,7 @@ parsepkgdata(char **pp, char *ep, int *exportp, char **prefixp, char **namep, ch
                return -1;
        }
        p[-1] = '\0';
-       
+
        // name: a.b followed by space
        name = p;
        while(p < ep && *p != ' ')
@@ -1569,7 +1574,7 @@ parsepkgdata(char **pp, char *ep, int *exportp, char **prefixp, char **namep, ch
                return -1;
        edef = p;
        *p++ = '\0';
-       
+
        // include methods on successive lines in def of named type
        while(parsemethod(&p, ep, &meth) > 0) {
                *edef++ = '\n'; // overwrites '\0'
@@ -1602,7 +1607,7 @@ int
 parsemethod(char **pp, char *ep, char **methp)
 {
        char *p;
-       
+
        // skip white space
        p = *pp;
        while(p < ep && (*p == ' ' || *p == '\t'))
@@ -1613,7 +1618,7 @@ parsemethod(char **pp, char *ep, char **methp)
        // if it says "func (", it's a method
        if(p + 6 >= ep || strncmp(p, "func (", 6) != 0)
                return 0;
-       
+
        // definition to end of line
        *methp = p;
        while(p < ep && *p != '\n')
@@ -1633,10 +1638,10 @@ importcmp(const void *va, const void *vb)
 {
        Import *a, *b;
        int i;
-       
+
        a = *(Import**)va;
        b = *(Import**)vb;
-       
+
        i = strcmp(a->prefix, b->prefix);
        if(i != 0) {
                // rewrite so "type" comes first
@@ -1653,7 +1658,7 @@ char*
 strappend(char *s, char *t)
 {
        int n;
-       
+
        n = strlen(t);
        memmove(s, t, n);
        return s+n;
@@ -1691,7 +1696,7 @@ getpkgdef(char **datap, int *lenp)
 
        // print them into buffer
        data = armalloc(len);
-       
+
        // import\n
        // $$\n
        // pkgstmt\n
index 7eed70e807de89537361819ca52e695eb181a964..bfccdcfd4c9096e041e02e77b0a209a53cd52a13 100644 (file)
@@ -725,6 +725,8 @@ addtyp(Type *n, int ctxt)
 {
        Dcl *r, *d;
        Sym *s;
+       char *p;
+       static int typgen;
 
        if(n==T || n->sym == S)
                fatal("addtyp: n=%T t=%T nil", n);
@@ -736,6 +738,9 @@ addtyp(Type *n, int ctxt)
        else {
                r = autodcl;
                pushdcl(s);
+               p = smprint("%s_%d", s->name, ++typgen);
+               n->xsym = lookup(p);
+               free(p);
        }
 
        if(s->tblock == block)
@@ -750,6 +755,16 @@ addtyp(Type *n, int ctxt)
        d->dtype = n;
        d->op = OTYPE;
 
+       d->back = r->back;
+       r->back->forw = d;
+       r->back = d;
+
+       d = dcl();
+       d->dtype = n;
+       d->op = OTYPE;
+
+       r = typelist;
+       d->back = r->back;
        r->back->forw = d;
        r->back = d;
 
@@ -791,7 +806,7 @@ addconst(Node *n, Node *e, int ctxt)
        d->dsym = s;
        d->dnode = e;
        d->op = OCONST;
-
+       d->back = r->back;
        r->back->forw = d;
        r->back = d;
 
index 4058d857df90bcf2ef18f90a8aa1c5527b0f570e..5067da8707bd0d403c74fc4d6043c6bfaf4c324f 100644 (file)
@@ -42,7 +42,7 @@ dumpprereq(Type *t)
        if(t == T)
                return;
 
-       if(t->printed)
+       if(t->printed || t == types[t->etype] || t == types[TSTRING])
                return;
        t->printed = 1;
 
@@ -133,7 +133,7 @@ dumpexporttype(Sym *s)
                yyerror("export of incomplete type %T", s->otype);
                return;
        }
-       Bprint(bout, "type %lS %l#T\n",  s, s->otype);
+       Bprint(bout, "type %#T %l#T\n",  s->otype, s->otype);
 }
 
 void
@@ -160,7 +160,7 @@ dumpsym(Sym *s)
 
                dumpexporttype(s);
                for(f=s->otype->method; f!=T; f=f->down)
-                       Bprint(bout, "\tfunc (%#T) %hS %#T\n",
+                       Bprint(bout, "\tfunc (%#T) %hS %#hT\n",
                                f->type->type->type, f->sym, f->type);
                break;
        case LNAME:
@@ -172,34 +172,48 @@ dumpsym(Sym *s)
        }
 }
 
+void
+dumptype(Type *t)
+{
+       // no need to re-dump type if already exported
+       if(t->printed)
+               return;
+
+       // no need to dump type if it's not ours (was imported)
+       if(t->sym != S && t->sym->otype == t && !t->sym->local)
+               return;
+
+       Bprint(bout, "type %#T %l#T\n",  t, t);
+}
+
 void
 dumpexport(void)
 {
        Dcl *d;
        int32 lno;
-       char *pkg;
 
-       exporting = 1;
        lno = lineno;
 
        Bprint(bout, "   import\n");
-       Bprint(bout, "   $$\n");
+       Bprint(bout, "   $$  // exports\n");
 
        Bprint(bout, "    package %s\n", package);
-       pkg = package;
-       package = "$nopkg";
 
        for(d=exportlist->forw; d!=D; d=d->forw) {
                lineno = d->lineno;
                dumpsym(d->dsym);
        }
 
-       package = pkg;
+       Bprint(bout, "\n$$  // local types\n");
+
+       for(d=typelist->forw; d!=D; d=d->forw) {
+               lineno = d->lineno;
+               dumptype(d->dtype);
+       }
 
        Bprint(bout, "\n$$\n");
 
        lineno = lno;
-       exporting = 0;
 }
 
 /*
@@ -243,9 +257,9 @@ importsym(Node *ss, int lexical)
                fatal("importsym: oops1 %N", ss);
 
        s = pkgsym(ss->sym->name, ss->psym->name, lexical);
-
        /* TODO botch - need some diagnostic checking for the following assignment */
        s->opackage = ss->osym->name;
+       s->export = 1;
        return s;
 }
 
index c72dbb8c6713508ad4820760226bdda57e0f131f..5e9c36355453294342bcfe47e1dd7317d86e66b7 100644 (file)
@@ -135,6 +135,7 @@ struct      Type
        Type*   method;
 
        Sym*    sym;
+       Sym*    xsym;           // export sym
        int32   vargen;         // unique name for OTYPE/ONAME
 
        Node*   nname;
@@ -442,6 +443,7 @@ EXTERN      Dcl*    paramdcl;
 EXTERN Dcl*    externdcl;
 EXTERN Dcl*    exportlist;
 EXTERN Dcl*    signatlist;
+EXTERN Dcl*    typelist;
 EXTERN int     dclcontext;     // PEXTERN/PAUTO
 EXTERN int     importflag;
 EXTERN int     inimportsys;
index de9700da3d346dd4bf9619e82733d9bee2eda842..239efca67a14505bed0628389be9ea95cd5ef136 100644 (file)
@@ -77,6 +77,9 @@ mainlex(int argc, char *argv[])
        exportlist = mal(sizeof(*exportlist));
        exportlist->back = exportlist;
 
+       typelist = mal(sizeof(*typelist));
+       typelist->back = typelist;
+
        // function field skeleton
        fskel = nod(OLIST, N, nod(OLIST, N, N));
        fskel->left = nod(ODCLFIELD, N, N);
@@ -1112,13 +1115,8 @@ lexinit(void)
                        continue;
                }
                t = typ(etype);
-               switch(etype) {
-               case TSTRING:
-               case TCHAN:
-               case TMAP:
+               if(etype == TSTRING)
                        t = ptrto(t);
-               }
-
                t->sym = s;
 
                dowidth(t);
index 3953ca20c1776df5402bda9547f81d8d38259abd..08e965dead3ca800e67c4c17b73cfc5a0746d22f 100644 (file)
@@ -959,12 +959,25 @@ int
 Tpretty(Fmt *fp, Type *t)
 {
        Type *t1;
+       Sym *s;
 
        if(t->etype != TFIELD
        && t->sym != S
        && t->sym->name[0] != '_'
-       && !(fp->flags&FmtLong))
-               return fmtprint(fp, "%S", t->sym);
+       && !(fp->flags&FmtLong)) {
+               s = t->sym;
+               if(t == types[t->etype] || t == types[TSTRING])
+                       return fmtprint(fp, "%s", s->name);
+               if(exporting) {
+                       if(t->xsym != S)
+                               s = t->xsym;
+                       if(strcmp(s->opackage, package) == 0)
+                       if(s->otype != t || !s->export)
+                               return fmtprint(fp, "%lS_%s", s, filename);
+                       return fmtprint(fp, "%lS", s);
+               }
+               return fmtprint(fp, "%S", s);
+       }
 
        if(t->etype < nelem(basicnames) && basicnames[t->etype] != nil)
                return fmtprint(fp, "%s", basicnames[t->etype]);
@@ -1068,12 +1081,14 @@ Tpretty(Fmt *fp, Type *t)
        return -1;
 }
 
+
+
 int
 Tconv(Fmt *fp)
 {
        char buf[500], buf1[500];
        Type *t, *t1;
-       int et;
+       int et, exp;
 
        t = va_arg(fp->args, Type*);
        if(t == T)
@@ -1085,9 +1100,18 @@ Tconv(Fmt *fp)
                goto out;
        }
 
-       if(!debug['t'] && Tpretty(fp, t) >= 0) {
-               t->trecur--;
-               return 0;
+       if(!debug['t']) {
+               exp = (fp->flags & FmtSharp);
+               if(exp)
+                       exporting++;
+               if(Tpretty(fp, t) >= 0) {
+                       t->trecur--;
+                       if(exp)
+                               exporting--;
+                       return 0;
+               }
+               if(exp)
+                       exporting--;
        }
 
        et = t->etype;
index 9139d49d9e44a469f92258e17e4d0a838f48d210..472e2e670bb4ea62a87fd768c646b33ff14e55c3 100644 (file)
@@ -112,7 +112,7 @@ bugs/bug080.go:12: illegal types for operand: CALL
 BUG: fails incorrectly
 
 =========== bugs/bug083.go
-BUG: succeeds incorrectly
+bugs/bug083.dir/bug1.go:5: syntax error near T0
 
 =========== bugs/bug085.go
 bugs/bug085.go:8: P: undefined
@@ -165,7 +165,7 @@ BUG: should compile
 fixedbugs/bug016.go:7: overflow converting constant to uint32
 
 =========== fixedbugs/bug025.go
-fixedbugs/bug025.go:7: variable exported but not defined: main.Foo
+fixedbugs/bug025.go:7: variable exported but not defined: Foo
 
 =========== fixedbugs/bug027.go
 hi