Commit 2244ae41 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile/internal/gc: simplify typecheck's Efoo consts

There's no need for Eiota, Eindir, Eaddr, or Eproc; the values are
threaded through to denote various typechecking contexts, but they
don't actually influence typechecking behavior at all.

Also, while here, switch the Efoo const declarations to use iota.

Passes toolstash -cmp.

Change-Id: I5cea869ccd0755c481cf071978f863474bc9c1ed
Reviewed-on: https://go-review.googlesource.com/22271
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 58012ea7
...@@ -12,17 +12,13 @@ import ( ...@@ -12,17 +12,13 @@ import (
) )
const ( const (
Etop = 1 << 1 // evaluated at statement level Etop = 1 << iota // evaluated at statement level
Erv = 1 << 2 // evaluated in value context Erv // evaluated in value context
Etype = 1 << 3 Etype // evaluated in type context
Ecall = 1 << 4 // call-only expressions are ok Ecall // call-only expressions are ok
Efnstruct = 1 << 5 // multivalue function returns are ok Efnstruct // multivalue function returns are ok
Eiota = 1 << 6 // iota is ok Easgn // assigning to expression
Easgn = 1 << 7 // assigning to expression Ecomplit // type in composite literal
Eindir = 1 << 8 // indirecting through expression
Eaddr = 1 << 9 // taking address of expression
Eproc = 1 << 10 // inside a go statement
Ecomplit = 1 << 11 // type in composite literal
) )
// type check the whole tree of an expression. // type check the whole tree of an expression.
...@@ -476,13 +472,7 @@ OpSwitch: ...@@ -476,13 +472,7 @@ OpSwitch:
// type or expr // type or expr
case OIND: case OIND:
ntop := Erv | Etype n.Left = typecheck(n.Left, Erv|Etype|top&Ecomplit)
if top&Eaddr == 0 { // The *x in &*x is not an indirect.
ntop |= Eindir
}
ntop |= top & Ecomplit
n.Left = typecheck(n.Left, ntop)
l := n.Left l := n.Left
t := l.Type t := l.Type
if t == nil { if t == nil {
...@@ -556,8 +546,8 @@ OpSwitch: ...@@ -556,8 +546,8 @@ OpSwitch:
op = Op(n.Etype) op = Op(n.Etype)
} else { } else {
ok |= Erv ok |= Erv
n.Left = typecheck(n.Left, Erv|top&Eiota) n.Left = typecheck(n.Left, Erv)
n.Right = typecheck(n.Right, Erv|top&Eiota) n.Right = typecheck(n.Right, Erv)
l = n.Left l = n.Left
r = n.Right r = n.Right
if l.Type == nil || r.Type == nil { if l.Type == nil || r.Type == nil {
...@@ -775,7 +765,7 @@ OpSwitch: ...@@ -775,7 +765,7 @@ OpSwitch:
case OCOM, OMINUS, ONOT, OPLUS: case OCOM, OMINUS, ONOT, OPLUS:
ok |= Erv ok |= Erv
n.Left = typecheck(n.Left, Erv|top&Eiota) n.Left = typecheck(n.Left, Erv)
l := n.Left l := n.Left
t := l.Type t := l.Type
if t == nil { if t == nil {
...@@ -795,7 +785,7 @@ OpSwitch: ...@@ -795,7 +785,7 @@ OpSwitch:
case OADDR: case OADDR:
ok |= Erv ok |= Erv
n.Left = typecheck(n.Left, Erv|Eaddr) n.Left = typecheck(n.Left, Erv)
if n.Left.Type == nil { if n.Left.Type == nil {
n.Type = nil n.Type = nil
return n return n
...@@ -1262,7 +1252,7 @@ OpSwitch: ...@@ -1262,7 +1252,7 @@ OpSwitch:
} }
} }
n.Left = typecheck(n.Left, Erv|Etype|Ecall|top&Eproc) n.Left = typecheck(n.Left, Erv|Etype|Ecall)
n.Diag |= n.Left.Diag n.Diag |= n.Left.Diag
l = n.Left l = n.Left
if l.Op == ONAME && l.Etype != 0 { if l.Op == ONAME && l.Etype != 0 {
...@@ -1479,8 +1469,8 @@ OpSwitch: ...@@ -1479,8 +1469,8 @@ OpSwitch:
n.Type = nil n.Type = nil
return n return n
} }
n.Left = typecheck(n.Left, Erv|top&Eiota) n.Left = typecheck(n.Left, Erv)
n.Right = typecheck(n.Right, Erv|top&Eiota) n.Right = typecheck(n.Right, Erv)
l = n.Left l = n.Left
r = n.Right r = n.Right
if l.Type == nil || r.Type == nil { if l.Type == nil || r.Type == nil {
...@@ -1738,7 +1728,7 @@ OpSwitch: ...@@ -1738,7 +1728,7 @@ OpSwitch:
case OCONV: case OCONV:
ok |= Erv ok |= Erv
saveorignode(n) saveorignode(n)
n.Left = typecheck(n.Left, Erv|top&(Eindir|Eiota)) n.Left = typecheck(n.Left, Erv)
n.Left = convlit1(n.Left, n.Type, true, noReuse) n.Left = convlit1(n.Left, n.Type, true, noReuse)
t := n.Left.Type t := n.Left.Type
if t == nil || n.Type == nil { if t == nil || n.Type == nil {
...@@ -1926,7 +1916,7 @@ OpSwitch: ...@@ -1926,7 +1916,7 @@ OpSwitch:
case OPRINT, OPRINTN: case OPRINT, OPRINTN:
ok |= Etop ok |= Etop
typecheckslice(n.List.Slice(), Erv|Eindir) // Eindir: address does not escape typecheckslice(n.List.Slice(), Erv)
ls := n.List.Slice() ls := n.List.Slice()
for i1, n1 := range ls { for i1, n1 := range ls {
// Special case for print: int constant is int64, not int. // Special case for print: int constant is int64, not int.
...@@ -2062,7 +2052,7 @@ OpSwitch: ...@@ -2062,7 +2052,7 @@ OpSwitch:
case OPROC: case OPROC:
ok |= Etop ok |= Etop
n.Left = typecheck(n.Left, Etop|Eproc|Erv) n.Left = typecheck(n.Left, Etop|Erv)
checkdefergo(n) checkdefergo(n)
break OpSwitch break OpSwitch
...@@ -3707,7 +3697,7 @@ func typecheckdef(n *Node) *Node { ...@@ -3707,7 +3697,7 @@ func typecheckdef(n *Node) *Node {
Yyerror("xxx") Yyerror("xxx")
} }
e = typecheck(e, Erv|Eiota) e = typecheck(e, Erv)
if Isconst(e, CTNIL) { if Isconst(e, CTNIL) {
Yyerror("const initializer cannot be nil") Yyerror("const initializer cannot be nil")
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