cmd/compile: make gc debug flags collector a struct

gc debug flags are currently stored in a 256-long array, that is then
addressed using the ASCII numeric value of the flag itself (a quirk
inherited from the old C compiler). It is also a little wasteful,
since we only define 16 flags, and the other 240 array elements are
always empty.

This change makes Debug a struct, which also provides static checking
that we're not referencing flags that does not exist.

Change-Id: I2f0dfef2529325514b3398cf78635543cdf48fe0
Reviewed-on: https://go-review.googlesource.com/c/go/+/263539
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Alberto Donizetti 2020-10-19 11:31:10 +02:00
parent 4c7a18d74a
commit 3bac5faa4a
17 changed files with 149 additions and 134 deletions

View file

@ -96,7 +96,7 @@ func flusherrors() {
}
func hcrash() {
if Debug['h'] != 0 {
if Debug.h != 0 {
flusherrors()
if outfile != "" {
os.Remove(outfile)
@ -107,7 +107,7 @@ func hcrash() {
}
func linestr(pos src.XPos) string {
return Ctxt.OutermostPos(pos).Format(Debug['C'] == 0, Debug['L'] == 1)
return Ctxt.OutermostPos(pos).Format(Debug.C == 0, Debug.L == 1)
}
// lasterror keeps track of the most recently issued error.
@ -153,7 +153,7 @@ func yyerrorl(pos src.XPos, format string, args ...interface{}) {
hcrash()
nerrors++
if nsavederrors+nerrors >= 10 && Debug['e'] == 0 {
if nsavederrors+nerrors >= 10 && Debug.e == 0 {
flusherrors()
fmt.Printf("%v: too many errors\n", linestr(pos))
errorexit()
@ -175,7 +175,7 @@ func Warn(fmt_ string, args ...interface{}) {
func Warnl(line src.XPos, fmt_ string, args ...interface{}) {
adderr(line, fmt_, args...)
if Debug['m'] != 0 {
if Debug.m != 0 {
flusherrors()
}
}
@ -222,7 +222,7 @@ func hasUniquePos(n *Node) bool {
}
if !n.Pos.IsKnown() {
if Debug['K'] != 0 {
if Debug.K != 0 {
Warn("setlineno: unknown position (line 0)")
}
return false
@ -1506,7 +1506,7 @@ func structargs(tl *types.Type, mustname bool) []*Node {
// method - M func (t T)(), a TFIELD type struct
// newnam - the eventual mangled name of this function
func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym) {
if false && Debug['r'] != 0 {
if false && Debug.r != 0 {
fmt.Printf("genwrapper rcvrtype=%v method=%v newnam=%v\n", rcvr, method, newnam)
}
@ -1579,7 +1579,7 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym) {
fn.Nbody.Append(call)
}
if false && Debug['r'] != 0 {
if false && Debug.r != 0 {
dumplist("genwrapper body", fn.Nbody)
}
@ -1720,7 +1720,7 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool
// the method does not exist for value types.
rcvr := tm.Type.Recv().Type
if rcvr.IsPtr() && !t0.IsPtr() && !followptr && !isifacemethod(tm.Type) {
if false && Debug['r'] != 0 {
if false && Debug.r != 0 {
yyerror("interface pointer mismatch")
}