Commit aacfbb46 authored by Russ Cox's avatar Russ Cox

6g:

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