1
0
mirror of https://github.com/golang/go synced 2024-11-11 19:51:37 -07:00

[dev.regabi] cmd/compile: rewrite code to use DeclaredBy

Passes buildall w/ toolstash -cmp.

Updates #42990.

[git-generate]
cd src/cmd/compile/internal/gc
rf '
ex {
  import "cmd/compile/internal/ir"
  var x, stmt ir.Node
  x.Name() != nil && x.Name().Defn == stmt ->  ir.DeclaredBy(x, stmt)
  x.Name() == nil || x.Name().Defn != stmt -> !ir.DeclaredBy(x, stmt)
}
'

Change-Id: I222a757296dbcb5d0889d617d221a9d7319f2d74
Reviewed-on: https://go-review.googlesource.com/c/go/+/275306
Reviewed-by: Russ Cox <rsc@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Matthew Dempsky 2020-12-03 16:57:56 -08:00
parent d9cb84c84b
commit 133b03e1c3
2 changed files with 12 additions and 12 deletions

View File

@ -49,7 +49,7 @@ func typecheckrangeExpr(n ir.Node) {
// delicate little dance. see typecheckas2
ls := n.List().Slice()
for i1, n1 := range ls {
if n1.Name() == nil || n1.Name().Defn != n {
if !ir.DeclaredBy(n1, n) {
ls[i1] = typecheck(ls[i1], ctxExpr|ctxAssign)
}
}
@ -115,7 +115,7 @@ func typecheckrangeExpr(n ir.Node) {
}
if v1 != nil {
if v1.Name() != nil && v1.Name().Defn == n {
if ir.DeclaredBy(v1, n) {
v1.SetType(t1)
} else if v1.Type() != nil {
if op, why := assignop(t1, v1.Type()); op == ir.OXXX {
@ -126,7 +126,7 @@ func typecheckrangeExpr(n ir.Node) {
}
if v2 != nil {
if v2.Name() != nil && v2.Name().Defn == n {
if ir.DeclaredBy(v2, n) {
v2.SetType(t2)
} else if v2.Type() != nil {
if op, why := assignop(t2, v2.Type()); op == ir.OXXX {
@ -477,7 +477,7 @@ func isMapClear(n ir.Node) bool {
}
// Require k to be a new variable name.
if k.Name() == nil || k.Name().Defn != n {
if !ir.DeclaredBy(k, n) {
return false
}

View File

@ -3083,7 +3083,7 @@ func checklvalue(n ir.Node, verb string) {
func checkassign(stmt ir.Node, n ir.Node) {
// Variables declared in ORANGE are assigned on every iteration.
if n.Name() == nil || n.Name().Defn != stmt || stmt.Op() == ir.ORANGE {
if !ir.DeclaredBy(n, stmt) || stmt.Op() == ir.ORANGE {
r := outervalue(n)
if r.Op() == ir.ONAME {
r.Name().SetAssigned(true)
@ -3192,7 +3192,7 @@ func typecheckas(n ir.Node) {
// so that the conversion below happens).
n.SetLeft(resolve(n.Left()))
if n.Left().Name() == nil || n.Left().Name().Defn != n || n.Left().Name().Ntype != nil {
if !ir.DeclaredBy(n.Left(), n) || n.Left().Name().Ntype != nil {
n.SetLeft(typecheck(n.Left(), ctxExpr|ctxAssign))
}
@ -3211,7 +3211,7 @@ func typecheckas(n ir.Node) {
}
}
if n.Left().Name() != nil && n.Left().Name().Defn == n && n.Left().Name().Ntype == nil {
if ir.DeclaredBy(n.Left(), n) && n.Left().Name().Ntype == nil {
n.SetRight(defaultlit(n.Right(), nil))
n.Left().SetType(n.Right().Type())
}
@ -3247,7 +3247,7 @@ func typecheckas2(n ir.Node) {
n1 = resolve(n1)
ls[i1] = n1
if n1.Name() == nil || n1.Name().Defn != n || n1.Name().Ntype != nil {
if !ir.DeclaredBy(n1, n) || n1.Name().Ntype != nil {
ls[i1] = typecheck(ls[i1], ctxExpr|ctxAssign)
}
}
@ -3272,7 +3272,7 @@ func typecheckas2(n ir.Node) {
if nl.Type() != nil && nr.Type() != nil {
rs[il] = assignconv(nr, nl.Type(), "assignment")
}
if nl.Name() != nil && nl.Name().Defn == n && nl.Name().Ntype == nil {
if ir.DeclaredBy(nl, n) && nl.Name().Ntype == nil {
rs[il] = defaultlit(rs[il], nil)
nl.SetType(rs[il].Type())
}
@ -3305,7 +3305,7 @@ func typecheckas2(n ir.Node) {
if f.Type != nil && l.Type() != nil {
checkassignto(f.Type, l)
}
if l.Name() != nil && l.Name().Defn == n && l.Name().Ntype == nil {
if ir.DeclaredBy(l, n) && l.Name().Ntype == nil {
l.SetType(f.Type)
}
}
@ -3332,14 +3332,14 @@ func typecheckas2(n ir.Node) {
if l.Type() != nil {
checkassignto(r.Type(), l)
}
if l.Name() != nil && l.Name().Defn == n {
if ir.DeclaredBy(l, n) {
l.SetType(r.Type())
}
l := n.List().Second()
if l.Type() != nil && !l.Type().IsBoolean() {
checkassignto(types.Types[types.TBOOL], l)
}
if l.Name() != nil && l.Name().Defn == n && l.Name().Ntype == nil {
if ir.DeclaredBy(l, n) && l.Name().Ntype == nil {
l.SetType(types.Types[types.TBOOL])
}
goto out