Commit 833f57ed authored by Alberto Donizetti's avatar Alberto Donizetti Committed by Brad Fitzpatrick

cmd/compile: make Node.Diag a bool

Change-Id: I017c2ef7cc6248d3f4e38a791cd2576e941984ed
Reviewed-on: https://go-review.googlesource.com/32156
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 7b454565
...@@ -359,11 +359,11 @@ func convlit1(n *Node, t *Type, explicit bool, reuse canReuseNode) *Node { ...@@ -359,11 +359,11 @@ func convlit1(n *Node, t *Type, explicit bool, reuse canReuseNode) *Node {
return n return n
bad: bad:
if n.Diag == 0 { if !n.Diag {
if !t.Broke { if !t.Broke {
yyerror("cannot convert %v to type %v", n, t) yyerror("cannot convert %v to type %v", n, t)
} }
n.Diag = 1 n.Diag = true
} }
if n.Type.IsUntyped() { if n.Type.IsUntyped() {
...@@ -692,9 +692,9 @@ func evconst(n *Node) { ...@@ -692,9 +692,9 @@ func evconst(n *Node) {
switch uint32(n.Op)<<16 | uint32(v.Ctype()) { switch uint32(n.Op)<<16 | uint32(v.Ctype()) {
default: default:
if n.Diag == 0 { if !n.Diag {
yyerror("illegal constant expression %v %v", n.Op, nl.Type) yyerror("illegal constant expression %v %v", n.Op, nl.Type)
n.Diag = 1 n.Diag = true
} }
return return
...@@ -953,9 +953,9 @@ func evconst(n *Node) { ...@@ -953,9 +953,9 @@ func evconst(n *Node) {
// The default case above would print 'ideal % ideal', // The default case above would print 'ideal % ideal',
// which is not quite an ideal error. // which is not quite an ideal error.
case OMOD_ | CTFLT_: case OMOD_ | CTFLT_:
if n.Diag == 0 { if !n.Diag {
yyerror("illegal constant expression: floating-point %% operation") yyerror("illegal constant expression: floating-point %% operation")
n.Diag = 1 n.Diag = true
} }
return return
...@@ -1179,9 +1179,9 @@ setfalse: ...@@ -1179,9 +1179,9 @@ setfalse:
return return
illegal: illegal:
if n.Diag == 0 { if !n.Diag {
yyerror("illegal constant expression: %v %v %v", nl.Type, n.Op, nr.Type) yyerror("illegal constant expression: %v %v %v", nl.Type, n.Op, nr.Type)
n.Diag = 1 n.Diag = true
} }
} }
...@@ -1320,9 +1320,9 @@ func defaultlitreuse(n *Node, t *Type, reuse canReuseNode) *Node { ...@@ -1320,9 +1320,9 @@ func defaultlitreuse(n *Node, t *Type, reuse canReuseNode) *Node {
if n.Val().Ctype() == CTNIL { if n.Val().Ctype() == CTNIL {
lineno = lno lineno = lno
if n.Diag == 0 { if !n.Diag {
yyerror("use of untyped nil") yyerror("use of untyped nil")
n.Diag = 1 n.Diag = true
} }
n.Type = nil n.Type = nil
......
...@@ -474,7 +474,7 @@ func colasdefn(left []*Node, defn *Node) { ...@@ -474,7 +474,7 @@ func colasdefn(left []*Node, defn *Node) {
if n.Sym.Flags&SymUniq == 0 { if n.Sym.Flags&SymUniq == 0 {
yyerrorl(defn.Lineno, "%v repeated on left side of :=", n.Sym) yyerrorl(defn.Lineno, "%v repeated on left side of :=", n.Sym)
n.Diag++ n.Diag = true
nerr++ nerr++
continue continue
} }
......
...@@ -971,9 +971,10 @@ func assignconvfn(n *Node, t *Type, context func() string) *Node { ...@@ -971,9 +971,10 @@ func assignconvfn(n *Node, t *Type, context func() string) *Node {
} }
old := n old := n
old.Diag++ // silence errors about n; we'll issue one below od := old.Diag
old.Diag = true // silence errors about n; we'll issue one below
n = defaultlit(n, t) n = defaultlit(n, t)
old.Diag-- old.Diag = od
if t.Etype == TBLANK { if t.Etype == TBLANK {
return n return n
} }
...@@ -1490,7 +1491,9 @@ func dotpath(s *Sym, t *Type, save **Field, ignorecase bool) (path []Dlist, ambi ...@@ -1490,7 +1491,9 @@ func dotpath(s *Sym, t *Type, save **Field, ignorecase bool) (path []Dlist, ambi
// modify the tree with missing type names. // modify the tree with missing type names.
func adddot(n *Node) *Node { func adddot(n *Node) *Node {
n.Left = typecheck(n.Left, Etype|Erv) n.Left = typecheck(n.Left, Etype|Erv)
n.Diag |= n.Left.Diag if n.Left.Diag {
n.Diag = true
}
t := n.Left.Type t := n.Left.Type
if t == nil { if t == nil {
return n return n
......
...@@ -55,7 +55,7 @@ type Node struct { ...@@ -55,7 +55,7 @@ type Node struct {
Class Class // PPARAM, PAUTO, PEXTERN, etc Class Class // PPARAM, PAUTO, PEXTERN, etc
Embedded uint8 // ODCLFIELD embedded type Embedded uint8 // ODCLFIELD embedded type
Colas bool // OAS resulting from := Colas bool // OAS resulting from :=
Diag uint8 // already printed error about this Diag bool // already printed error about this
Noescape bool // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360) Noescape bool // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360)
Walkdef uint8 // tracks state during typecheckdef; 2 == loop detected Walkdef uint8 // tracks state during typecheckdef; 2 == loop detected
Typecheck uint8 // tracks state during typechecking; 2 == loop detected Typecheck uint8 // tracks state during typechecking; 2 == loop detected
......
...@@ -345,8 +345,8 @@ OpSwitch: ...@@ -345,8 +345,8 @@ OpSwitch:
t = typSlice(r.Type) t = typSlice(r.Type)
} else if n.Left.Op == ODDD { } else if n.Left.Op == ODDD {
if top&Ecomplit == 0 { if top&Ecomplit == 0 {
if n.Diag == 0 { if !n.Diag {
n.Diag = 1 n.Diag = true
yyerror("use of [...] array outside of array literal") yyerror("use of [...] array outside of array literal")
} }
n.Type = nil n.Type = nil
...@@ -1184,7 +1184,10 @@ OpSwitch: ...@@ -1184,7 +1184,10 @@ OpSwitch:
// call and call like // call and call like
case OCALL: case OCALL:
n.Left = typecheck(n.Left, Erv|Etype|Ecall) n.Left = typecheck(n.Left, Erv|Etype|Ecall)
n.Diag |= n.Left.Diag if n.Left.Diag {
n.Diag = true
}
l := n.Left l := n.Left
if l.Op == ONAME && l.Etype != 0 { if l.Op == ONAME && l.Etype != 0 {
...@@ -1209,7 +1212,7 @@ OpSwitch: ...@@ -1209,7 +1212,7 @@ OpSwitch:
if !l.Type.Broke { if !l.Type.Broke {
yyerror("invalid use of ... in type conversion to %v", l.Type) yyerror("invalid use of ... in type conversion to %v", l.Type)
} }
n.Diag = 1 n.Diag = true
} }
// pick off before type-checking arguments // pick off before type-checking arguments
...@@ -1685,9 +1688,9 @@ OpSwitch: ...@@ -1685,9 +1688,9 @@ OpSwitch:
var why string var why string
n.Op = convertop(t, n.Type, &why) n.Op = convertop(t, n.Type, &why)
if n.Op == 0 { if n.Op == 0 {
if n.Diag == 0 && !n.Type.Broke { if !n.Diag && !n.Type.Broke {
yyerror("cannot convert %L to type %v%s", n.Left, n.Type, why) yyerror("cannot convert %L to type %v%s", n.Left, n.Type, why)
n.Diag = 1 n.Diag = true
} }
n.Op = OCONV n.Op = OCONV
...@@ -1992,7 +1995,7 @@ OpSwitch: ...@@ -1992,7 +1995,7 @@ OpSwitch:
case ODEFER: case ODEFER:
ok |= Etop ok |= Etop
n.Left = typecheck(n.Left, Etop|Erv) n.Left = typecheck(n.Left, Etop|Erv)
if n.Left.Diag == 0 { if !n.Left.Diag {
checkdefergo(n) checkdefergo(n)
} }
break OpSwitch break OpSwitch
...@@ -2142,9 +2145,9 @@ OpSwitch: ...@@ -2142,9 +2145,9 @@ OpSwitch:
} }
if (top&Etop != 0) && top&(Ecall|Erv|Etype) == 0 && ok&Etop == 0 { if (top&Etop != 0) && top&(Ecall|Erv|Etype) == 0 && ok&Etop == 0 {
if n.Diag == 0 { if !n.Diag {
yyerror("%v evaluated but not used", n) yyerror("%v evaluated but not used", n)
n.Diag = 1 n.Diag = true
} }
n.Type = nil n.Type = nil
...@@ -2241,11 +2244,10 @@ func checkdefergo(n *Node) { ...@@ -2241,11 +2244,10 @@ func checkdefergo(n *Node) {
return return
} }
if n.Diag == 0 { if !n.Diag {
// The syntax made sure it was a call, so this must be // The syntax made sure it was a call, so this must be
// a conversion. // a conversion.
n.Diag = 1 n.Diag = true
yyerror("%s requires function call, not conversion", what) yyerror("%s requires function call, not conversion", what)
} }
} }
...@@ -2686,7 +2688,7 @@ out: ...@@ -2686,7 +2688,7 @@ out:
return return
notenough: notenough:
if n == nil || n.Diag == 0 { if n == nil || !n.Diag {
if call != nil { if call != nil {
// call is the expression being called, not the overall call. // call is the expression being called, not the overall call.
// Method expressions have the form T.M, and the compiler has // Method expressions have the form T.M, and the compiler has
...@@ -2700,7 +2702,7 @@ notenough: ...@@ -2700,7 +2702,7 @@ notenough:
yyerror("not enough arguments to %v\n\thave %s\n\twant %v", op, nl.retsigerr(isddd), tstruct) yyerror("not enough arguments to %v\n\thave %s\n\twant %v", op, nl.retsigerr(isddd), tstruct)
} }
if n != nil { if n != nil {
n.Diag = 1 n.Diag = true
} }
} }
...@@ -2938,9 +2940,9 @@ func typecheckcomplit(n *Node) *Node { ...@@ -2938,9 +2940,9 @@ func typecheckcomplit(n *Node) *Node {
l.Left = typecheck(l.Left, Erv) l.Left = typecheck(l.Left, Erv)
evconst(l.Left) evconst(l.Left)
i = nonnegintconst(l.Left) i = nonnegintconst(l.Left)
if i < 0 && l.Left.Diag == 0 { if i < 0 && !l.Left.Diag {
yyerror("index must be non-negative integer constant") yyerror("index must be non-negative integer constant")
l.Left.Diag = 1 l.Left.Diag = true
i = -(1 << 30) // stay negative for a while i = -(1 << 30) // stay negative for a while
} }
vp = &l.Right vp = &l.Right
...@@ -3565,13 +3567,13 @@ func typecheckdeftype(n *Node) { ...@@ -3565,13 +3567,13 @@ func typecheckdeftype(n *Node) {
n.Name.Param.Ntype = typecheck(n.Name.Param.Ntype, Etype) n.Name.Param.Ntype = typecheck(n.Name.Param.Ntype, Etype)
t := n.Name.Param.Ntype.Type t := n.Name.Param.Ntype.Type
if t == nil { if t == nil {
n.Diag = 1 n.Diag = true
n.Type = nil n.Type = nil
goto ret goto ret
} }
if n.Type == nil { if n.Type == nil {
n.Diag = 1 n.Diag = true
goto ret goto ret
} }
...@@ -3625,8 +3627,8 @@ func typecheckdef(n *Node) *Node { ...@@ -3625,8 +3627,8 @@ func typecheckdef(n *Node) *Node {
setlineno(n) setlineno(n)
if n.Op == ONONAME { if n.Op == ONONAME {
if n.Diag == 0 { if !n.Diag {
n.Diag = 1 n.Diag = true
if n.Lineno != 0 { if n.Lineno != 0 {
lineno = n.Lineno lineno = n.Lineno
} }
...@@ -3674,7 +3676,7 @@ func typecheckdef(n *Node) *Node { ...@@ -3674,7 +3676,7 @@ func typecheckdef(n *Node) *Node {
n.Type = n.Name.Param.Ntype.Type n.Type = n.Name.Param.Ntype.Type
n.Name.Param.Ntype = nil n.Name.Param.Ntype = nil
if n.Type == nil { if n.Type == nil {
n.Diag = 1 n.Diag = true
goto ret goto ret
} }
} }
...@@ -3694,9 +3696,9 @@ func typecheckdef(n *Node) *Node { ...@@ -3694,9 +3696,9 @@ func typecheckdef(n *Node) *Node {
} }
if e.Type != nil && e.Op != OLITERAL || !isgoconst(e) { if e.Type != nil && e.Op != OLITERAL || !isgoconst(e) {
if e.Diag == 0 { if !e.Diag {
yyerror("const initializer %v is not a constant", e) yyerror("const initializer %v is not a constant", e)
e.Diag = 1 e.Diag = true
} }
goto ret goto ret
...@@ -3725,7 +3727,7 @@ func typecheckdef(n *Node) *Node { ...@@ -3725,7 +3727,7 @@ func typecheckdef(n *Node) *Node {
n.Name.Param.Ntype = typecheck(n.Name.Param.Ntype, Etype) n.Name.Param.Ntype = typecheck(n.Name.Param.Ntype, Etype)
n.Type = n.Name.Param.Ntype.Type n.Type = n.Name.Param.Ntype.Type
if n.Type == nil { if n.Type == nil {
n.Diag = 1 n.Diag = true
goto ret goto ret
} }
} }
......
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