Commit 50110c9f authored by Luuk van Dijk's avatar Luuk van Dijk

gc: clean up printing.

Got rid of all the magic mystery globals. Now
for %N, %T, and %S, the flags +,- and # set a sticky
debug, sym and export mode, only visible in the new fmt.c.
Default is error mode. Handle h and l flags consistently with
the least side effects, so we can now change
things without worrying about unrelated things
breaking.

fixes #2361

R=rsc
CC=golang-dev
https://golang.org/cl/5316043
parent 58423360
......@@ -24,6 +24,7 @@ OFILES=\
dcl.$O\
esc.$O\
export.$O\
fmt.$O\
gen.$O\
init.$O\
lex.$O\
......@@ -32,7 +33,6 @@ OFILES=\
mparith2.$O\
mparith3.$O\
obj.$O\
print.$O\
range.$O\
reflect.$O\
select.$O\
......@@ -62,7 +62,7 @@ subr.$O: yerr.h
builtin.c: builtin.c.boot
cp builtin.c.boot builtin.c
subr.$O: opnames.h
fmt.$O: opnames.h
opnames.h: mkopnames go.h
./mkopnames go.h >opnames.h
......
......@@ -108,7 +108,7 @@ convlit1(Node **np, Type *t, int explicit)
if(t != T && t->etype == TIDEAL && n->val.ctype != CTINT)
n->val = toint(n->val);
if(t != T && !isint[t->etype]) {
yyerror("invalid operation: %#N (shift of type %T)", n, t);
yyerror("invalid operation: %N (shift of type %T)", n, t);
t = T;
}
n->type = t;
......@@ -224,7 +224,7 @@ convlit1(Node **np, Type *t, int explicit)
bad:
if(!n->diag) {
yyerror("cannot convert %#N to type %T", n, t);
yyerror("cannot convert %N to type %T", n, t);
n->diag = 1;
}
if(isideal(n->type)) {
......@@ -939,7 +939,7 @@ defaultlit(Node **np, Type *t)
defaultlit(&n->left, t);
t = n->left->type;
if(t != T && !isint[t->etype]) {
yyerror("invalid operation: %#N (shift of type %T)", n, t);
yyerror("invalid operation: %N (shift of type %T)", n, t);
t = T;
}
n->type = t;
......@@ -991,7 +991,7 @@ defaultlit(Node **np, Type *t)
n->type = types[TSTRING];
break;
}
yyerror("defaultlit: unknown literal: %#N", n);
yyerror("defaultlit: unknown literal: %N", n);
break;
case CTBOOL:
n->type = types[TBOOL];
......
......@@ -473,7 +473,7 @@ colasdefn(NodeList *left, Node *defn)
if(isblank(n))
continue;
if(!colasname(n)) {
yyerror("non-name %#N on left side of :=", n);
yyerror("non-name %N on left side of :=", n);
nerr++;
continue;
}
......@@ -1086,10 +1086,11 @@ methodsym(Sym *nsym, Type *t0, int iface)
suffix = "·i";
}
if(t0->sym == S && isptr[t0->etype])
p = smprint("(%#hT).%s%s", t0, nsym->name, suffix);
p = smprint("(%-hT).%s%s", t0, nsym->name, suffix);
else
p = smprint("%#hT.%s%s", t0, nsym->name, suffix);
p = smprint("%-hT.%s%s", t0, nsym->name, suffix);
s = pkglookup(p, s->pkg);
//print("methodsym:%s -> %+S\n", p, s);
free(p);
return s;
......
......@@ -88,7 +88,7 @@ escapes(void)
if(debug['m']) {
for(l=noesc; l; l=l->next)
if(l->n->esc == EscNone)
warnl(l->n->lineno, "%S %#hN does not escape",
warnl(l->n->lineno, "%S %hN does not escape",
(l->n->curfn && l->n->curfn->nname) ? l->n->curfn->nname->sym : S,
l->n);
}
......@@ -178,7 +178,7 @@ esc(Node *n)
loopdepth--;
if(debug['m'] > 1)
print("%L:[%d] %#S esc: %#N\n", lineno, loopdepth,
print("%L:[%d] %S esc: %N\n", lineno, loopdepth,
(curfn && curfn->nname) ? curfn->nname->sym : S, n);
switch(n->op) {
......@@ -331,7 +331,7 @@ escassign(Node *dst, Node *src)
return;
if(debug['m'] > 1)
print("%L:[%d] %#S escassign: %hN = %hN\n", lineno, loopdepth,
print("%L:[%d] %S escassign: %hN = %hN\n", lineno, loopdepth,
(curfn && curfn->nname) ? curfn->nname->sym : S, dst, src);
setlineno(dst);
......@@ -609,7 +609,7 @@ escflood(Node *dst)
}
if(debug['m']>1)
print("\nescflood:%d: dst %hN scope:%#S[%d]\n", walkgen, dst,
print("\nescflood:%d: dst %hN scope:%S[%d]\n", walkgen, dst,
(dst->curfn && dst->curfn->nname) ? dst->curfn->nname->sym : S,
dst->escloopdepth);
......@@ -630,7 +630,7 @@ escwalk(int level, Node *dst, Node *src)
src->walkgen = walkgen;
if(debug['m']>1)
print("escwalk: level:%d depth:%d %.*s %hN scope:%#S[%d]\n",
print("escwalk: level:%d depth:%d %.*s %hN scope:%S[%d]\n",
level, pdepth, pdepth, "\t\t\t\t\t\t\t\t\t\t", src,
(src->curfn && src->curfn->nname) ? src->curfn->nname->sym : S, src->escloopdepth);
......@@ -643,7 +643,7 @@ escwalk(int level, Node *dst, Node *src)
if(src->class == PPARAM && leaks && src->esc == EscNone) {
src->esc = EscScope;
if(debug['m'])
warnl(src->lineno, "leaking param: %#hN", src);
warnl(src->lineno, "leaking param: %hN", src);
}
break;
......@@ -652,7 +652,7 @@ escwalk(int level, Node *dst, Node *src)
src->esc = EscHeap;
addrescapes(src->left);
if(debug['m'])
warnl(src->lineno, "%#hN escapes to heap", src);
warnl(src->lineno, "%hN escapes to heap", src);
}
escwalk(level-1, dst, src->left);
break;
......@@ -671,7 +671,7 @@ escwalk(int level, Node *dst, Node *src)
if(leaks) {
src->esc = EscHeap;
if(debug['m'])
warnl(src->lineno, "%#hN escapes to heap", src);
warnl(src->lineno, "%hN escapes to heap", src);
}
break;
......
......@@ -8,7 +8,7 @@
#include "y.tab.h"
static void dumpsym(Sym*);
static void dumpexporttype(Sym*);
static void dumpexporttype(Type*);
static void dumpexportvar(Sym*);
static void dumpexportconst(Sym*);
......@@ -89,25 +89,7 @@ dumppkg(Pkg *p)
}
static void
dumpprereq(Type *t)
{
if(t == T)
return;
if(t->printed || t == types[t->etype] || t == bytetype || t == runetype)
return;
t->printed = 1;
if(t->sym != S) {
dumppkg(t->sym->pkg);
if(t->etype != TFIELD)
dumpsym(t->sym);
}
dumpprereq(t->type);
dumpprereq(t->down);
}
static void
dumpexportconst(Sym *s)
{
Node *n;
......@@ -119,37 +101,12 @@ dumpexportconst(Sym *s)
fatal("dumpexportconst: oconst nil: %S", s);
t = n->type; // may or may not be specified
if(t != T)
dumpprereq(t);
dumpexporttype(t);
Bprint(bout, "\t");
Bprint(bout, "const %#S", s);
if(t != T && !isideal(t))
Bprint(bout, " %#T", t);
Bprint(bout, " = ");
switch(n->val.ctype) {
default:
fatal("dumpexportconst: unknown ctype: %S %d", s, n->val.ctype);
case CTINT:
Bprint(bout, "%B\n", n->val.u.xval);
break;
case CTBOOL:
if(n->val.u.bval)
Bprint(bout, "true\n");
else
Bprint(bout, "false\n");
break;
case CTFLT:
Bprint(bout, "%F\n", n->val.u.fval);
break;
case CTCPLX:
Bprint(bout, "(%F+%F)\n", &n->val.u.cval->real, &n->val.u.cval->imag);
break;
case CTSTR:
Bprint(bout, "\"%Z\"\n", n->val.u.sval);
break;
}
Bprint(bout, "\tconst %#S %#T = %#V\n", s, t, &n->val);
else
Bprint(bout, "\tconst %#S = %#V\n", s, &n->val);
}
static void
......@@ -166,31 +123,12 @@ dumpexportvar(Sym *s)
}
t = n->type;
dumpprereq(t);
dumpexporttype(t);
Bprint(bout, "\t");
if(t->etype == TFUNC && n->class == PFUNC)
Bprint(bout, "func %#S %#hhT", s, t);
Bprint(bout, "\tfunc %#S%#hT\n", s, t);
else
Bprint(bout, "var %#S %#T", s, t);
Bprint(bout, "\n");
}
static void
dumpexporttype(Sym *s)
{
Type *t;
t = s->def->type;
dumpprereq(t);
Bprint(bout, "\t");
switch (t->etype) {
case TFORW:
yyerror("export of incomplete type %T", t);
return;
}
if(Bprint(bout, "type %#T %l#T\n", t, t) < 0)
fatal("Bprint failed for %T", t);
Bprint(bout, "\tvar %#S %#T\n", s, t);
}
static int
......@@ -204,12 +142,50 @@ methcmp(const void *va, const void *vb)
}
static void
dumpsym(Sym *s)
dumpexporttype(Type *t)
{
Type *f, *t;
Type *f;
Type **m;
int i, n;
if(t == T)
return;
if(t->printed || t == types[t->etype] || t == bytetype || t == runetype)
return;
t->printed = 1;
if(t->sym != S && t->etype != TFIELD)
dumppkg(t->sym->pkg);
dumpexporttype(t->type);
dumpexporttype(t->down);
if (t->sym == S || t->etype == TFIELD)
return;
n = 0;
for(f=t->method; f!=T; f=f->down) {
dumpexporttype(f);
n++;
}
m = mal(n*sizeof m[0]);
i = 0;
for(f=t->method; f!=T; f=f->down)
m[i++] = f;
qsort(m, n, sizeof m[0], methcmp);
Bprint(bout, "\ttype %#S %#lT\n", t->sym, t);
for(i=0; i<n; i++) {
f = m[i];
Bprint(bout, "\tfunc (%#T) %#hS%#hT\n", getthisx(f->type)->type, f->sym, f->type);
}
}
static void
dumpsym(Sym *s)
{
if(s->flags & SymExported)
return;
s->flags |= SymExported;
......@@ -229,24 +205,10 @@ dumpsym(Sym *s)
dumpexportconst(s);
break;
case OTYPE:
t = s->def->type;
n = 0;
for(f=t->method; f!=T; f=f->down) {
dumpprereq(f);
n++;
}
m = mal(n*sizeof m[0]);
i = 0;
for(f=t->method; f!=T; f=f->down)
m[i++] = f;
qsort(m, n, sizeof m[0], methcmp);
dumpexporttype(s);
for(i=0; i<n; i++) {
f = m[i];
Bprint(bout, "\tfunc (%#T) %hS %#hhT\n",
f->type->type->type, f->sym, f->type);
}
if(s->def->type->etype == TFORW)
yyerror("export of incomplete type %S", s);
else
dumpexporttype(s->def->type);
break;
case ONAME:
dumpexportvar(s);
......@@ -254,20 +216,6 @@ dumpsym(Sym *s)
}
}
static 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->def == typenod(t) && !t->local)
return;
Bprint(bout, "type %#T %l#T\n", t, t);
}
void
dumpexport(void)
{
......@@ -277,10 +225,7 @@ dumpexport(void)
lno = lineno;
packagequotes = 1;
Bprint(bout, "\n$$ // exports\n");
Bprint(bout, " package %s", localpkg->name);
Bprint(bout, "\n$$ // exports\n package %s", localpkg->name);
if(safemode)
Bprint(bout, " safe");
Bprint(bout, "\n");
......@@ -295,15 +240,7 @@ dumpexport(void)
dumpsym(l->n->sym);
}
Bprint(bout, "\n$$ // local types\n");
for(l=typelist; l; l=l->next) {
lineno = l->n->lineno;
dumptype(l->n->type);
}
Bprint(bout, "\n$$\n");
packagequotes = 0;
Bprint(bout, "\n$$ // local types\n\n$$\n"); // 6l expects this. (see ld/go.c)
lineno = lno;
}
......@@ -346,7 +283,7 @@ pkgtype(Sym *s)
s->def = typenod(t);
}
if(s->def->type == T)
yyerror("pkgtype %lS", s);
yyerror("pkgtype %S", s);
return s->def->type;
}
......@@ -400,8 +337,7 @@ importvar(Sym *s, Type *t, int ctxt)
if(s->def != N && s->def->op == ONAME) {
if(eqtype(t, s->def->type))
return;
yyerror("inconsistent definition for var %S during import\n\t%T\n\t%T",
s, s->def->type, t);
yyerror("inconsistent definition for var %S during import\n\t%T\n\t%T", s, s->def->type, t);
}
n = newname(s);
n->type = t;
......
This diff is collapsed.
......@@ -94,7 +94,7 @@ addrescapes(Node *n)
if(!debug['s'])
n->esc = EscHeap;
if(debug['m'])
print("%L: moved to heap: %#hN\n", n->lineno, n);
print("%L: moved to heap: %N\n", n->lineno, n);
curfn = oldfn;
break;
}
......
......@@ -846,14 +846,8 @@ EXTERN char* hunk;
EXTERN int32 nhunk;
EXTERN int32 thunk;
EXTERN int exporting;
EXTERN int erroring;
EXTERN int noargnames;
EXTERN int funcdepth;
EXTERN int typecheckok;
EXTERN int packagequotes;
EXTERN int longsymnames;
EXTERN int compiling_runtime;
EXTERN int rune32;
......@@ -986,6 +980,13 @@ void importtype(Type *pt, Type *t);
void importvar(Sym *s, Type *t, int ctxt);
Type* pkgtype(Sym *s);
/*
* fmt.c
*/
void fmtinstallgo(void);
void dump(char *s, Node *n);
void dumplist(char *s, NodeList *l);
/*
* gen.c
*/
......@@ -1095,12 +1096,6 @@ void dumpobj(void);
void ieeedtod(uint64 *ieee, double native);
Sym* stringsym(char*, int);
/*
* print.c
*/
void exprfmt(Fmt *f, Node *n, int prec);
void exprlistfmt(Fmt *f, NodeList *l);
/*
* range.c
*/
......@@ -1134,15 +1129,6 @@ int stataddr(Node *nam, Node *n);
/*
* subr.c
*/
int Econv(Fmt *fp);
int Jconv(Fmt *fp);
int Lconv(Fmt *fp);
int Nconv(Fmt *fp);
int Oconv(Fmt *fp);
int Sconv(Fmt *fp);
int Tconv(Fmt *fp);
int Vconv(Fmt *fp);
int Zconv(Fmt *fp);
Node* adddot(Node *n);
int adddot1(Sym *s, Type *t, int d, Type **save, int ignorecase);
Type* aindex(Node *b, Type *t);
......@@ -1157,8 +1143,6 @@ NodeList* concat(NodeList *a, NodeList *b);
int convertop(Type *src, Type *dst, char **why);
int count(NodeList *l);
int cplxsubtype(int et);
void dump(char *s, Node *n);
void dumplist(char *s, NodeList *l);
int eqtype(Type *t1, Type *t2);
int eqtypenoname(Type *t1, Type *t2);
void errorexit(void);
......@@ -1347,6 +1331,7 @@ void zname(Biobuf *b, Sym *s, int t);
#pragma varargck type "lD" Addr*
#pragma varargck type "E" int
#pragma varargck type "F" Mpflt*
#pragma varargck type "H" NodeList*
#pragma varargck type "J" Node*
#pragma varargck type "L" int
#pragma varargck type "L" uint
......
......@@ -426,7 +426,7 @@ simple_stmt:
if($1->next != nil)
yyerror("argument count mismatch: %d = %d", count($1), 1);
else if($1->n->op != ONAME && $1->n->op != OTYPE && $1->n->op != ONONAME)
yyerror("invalid variable name %#N in type switch", $1->n);
yyerror("invalid variable name %N in type switch", $1->n);
else
n = $1->n;
$$ = nod(OTYPESW, n, $3->n->right);
......
......@@ -253,18 +253,7 @@ main(int argc, char *argv[])
*p = '/';
}
fmtinstall('O', Oconv); // node opcodes
fmtinstall('E', Econv); // etype opcodes
fmtinstall('J', Jconv); // all the node flags
fmtinstall('S', Sconv); // sym pointer
fmtinstall('T', Tconv); // type pointer
fmtinstall('V', Vconv); // Val pointer
fmtinstall('N', Nconv); // node pointer
fmtinstall('Z', Zconv); // escaped string
fmtinstall('L', Lconv); // line number
fmtinstall('B', Bconv); // big numbers
fmtinstall('F', Fconv); // big float numbers
fmtinstallgo();
betypeinit();
if(widthptr == 0)
fatal("betypeinit failed");
......
......@@ -52,7 +52,7 @@ dumpglobls(void)
continue;
if(n->type == T)
fatal("external %#N nil type\n", n);
fatal("external %N nil type\n", n);
if(n->class == PFUNC)
continue;
if(n->sym->pkg != localpkg)
......
This diff is collapsed.
......@@ -32,7 +32,7 @@ typecheckrange(Node *n)
switch(t->etype) {
default:
yyerror("cannot range over %+N", n->right);
yyerror("cannot range over %lN", n->right);
goto out;
case TARRAY:
......@@ -71,12 +71,12 @@ typecheckrange(Node *n)
if(v1->defn == n)
v1->type = t1;
else if(v1->type != T && assignop(t1, v1->type, &why) == 0)
yyerror("cannot assign type %T to %+N in range%s", t1, v1, why);
yyerror("cannot assign type %T to %lN in range%s", t1, v1, why);
if(v2) {
if(v2->defn == n)
v2->type = t2;
else if(v2->type != T && assignop(t2, v2->type, &why) == 0)
yyerror("cannot assign type %T to %+N in range%s", t2, v2, why);
yyerror("cannot assign type %T to %lN in range%s", t2, v2, why);
}
out:
......
......@@ -592,9 +592,8 @@ dcommontype(Sym *s, int ot, Type *t)
if(!haspointers(t))
i |= KindNoPointers;
ot = duint8(s, ot, i); // kind
longsymnames = 1;
p = smprint("%-T", t);
longsymnames = 0;
p = smprint("%-uT", t);
//print("dcommontype: %s\n", p);
ot = dgostringptr(s, ot, p); // string
free(p);
......@@ -614,8 +613,9 @@ typesym(Type *t)
char *p;
Sym *s;
p = smprint("%#-T", t);
p = smprint("%-T", t);
s = pkglookup(p, typepkg);
//print("typesym: %s -> %+S\n", p, s);
free(p);
return s;
}
......@@ -662,8 +662,9 @@ weaktypesym(Type *t)
weak->prefix = "weak.type"; // not weak%2etype
}
p = smprint("%#-T", t);
p = smprint("%-T", t);
s = pkglookup(p, weak);
//print("weaktypesym: %s -> %+S\n", p, s);
free(p);
return s;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -80,7 +80,7 @@ no:
return N;
bad:
yyerror("invalid expression %#N", nn);
yyerror("invalid expression %N", nn);
v = 0;
goto ret;
......
......@@ -284,7 +284,7 @@ walkstmt(Node **np)
// OAS2FUNC in disguise
f = n->list->n;
if(f->op != OCALLFUNC && f->op != OCALLMETH && f->op != OCALLINTER)
fatal("expected return of call, have %#N", f);
fatal("expected return of call, have %N", f);
n->list = concat(list1(f), ascompatet(n->op, rl, &f->type, 0, &n->ninit));
break;
}
......@@ -2189,7 +2189,7 @@ vmkcall(Node *fn, Type *t, NodeList **init, va_list va)
NodeList *args;
if(fn->type == T || fn->type->etype != TFUNC)
fatal("mkcall %#N %T", fn, fn->type);
fatal("mkcall %N %T", fn, fn->type);
args = nil;
n = fn->type->intuple;
......
......@@ -356,7 +356,7 @@ var fmttests = []struct {
{"%#v", map[string]int{"a": 1}, `map[string] int{"a":1}`},
{"%#v", map[string]B{"a": {1, 2}}, `map[string] fmt_test.B{"a":fmt_test.B{I:1, j:2}}`},
{"%#v", []string{"a", "b"}, `[]string{"a", "b"}`},
{"%#v", SI{}, `fmt_test.SI{I:interface { }(nil)}`},
{"%#v", SI{}, `fmt_test.SI{I:interface {}(nil)}`},
// slices with other formats
{"%#x", []int{1, 2, 15}, `[0x1 0x2 0xf]`},
......
......@@ -434,7 +434,7 @@ func TestInterfaceGet(t *testing.T) {
inter.E = 123.456
v1 := ValueOf(&inter)
v2 := v1.Elem().Field(0)
assert(t, v2.Type().String(), "interface { }")
assert(t, v2.Type().String(), "interface {}")
i2 := v2.Interface()
v3 := ValueOf(i2)
assert(t, v3.Type().String(), "float64")
......@@ -447,7 +447,7 @@ func TestInterfaceValue(t *testing.T) {
inter.E = 123.456
v1 := ValueOf(&inter)
v2 := v1.Elem().Field(0)
assert(t, v2.Type().String(), "interface { }")
assert(t, v2.Type().String(), "interface {}")
v3 := v2.Elem()
assert(t, v3.Type().String(), "float64")
......
......@@ -15,7 +15,7 @@ var (
_ = sum()
_ = sum(1.0, 2.0)
_ = sum(1.5) // ERROR "integer"
_ = sum("hello") // ERROR ".hello. .type string. as type int|incompatible"
_ = sum("hello") // ERROR ".hello. .type ideal string. as type int|incompatible"
_ = sum([]int{1}) // ERROR "\[\]int literal.*as type int|incompatible"
)
......
......@@ -12,6 +12,6 @@ func main() {
var x interface{}
switch t := x.(type) { // GC_ERROR "0 is not a type"
case 0: // GCCGO_ERROR "expected type"
t.x = 1 // ERROR "type interface \{ \}|reference to undefined field or method"
t.x = 1 // ERROR "type interface \{\}|reference to undefined field or method"
}
}
......@@ -37,7 +37,7 @@ func main() {
asBool(true)
asBool(*&b)
asBool(Bool(true))
asBool(1 != 2) // ERROR "cannot use.*type bool.*as type Bool"
asBool(1 != 2) // ERROR "cannot use.*type ideal bool.*as type Bool"
asBool(i < j) // ERROR "cannot use.*type bool.*as type Bool"
_, b = m[2] // ERROR "cannot .* bool.*type Bool"
......
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