1
0
mirror of https://github.com/golang/go synced 2024-11-24 17:30:18 -07:00

cmd/internal/gc: clean up walk conv* and assert*

This is preliminary cleanup for another change.

No functional changes. Passes toolstash -cmp.

Change-Id: I11d562fbd6cba5c48d9636f3149e210e5f5308ad
Reviewed-on: https://go-review.googlesource.com/7696
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2015-03-17 13:56:29 -07:00
parent cadd4f81a8
commit 55b4516fd6
2 changed files with 37 additions and 58 deletions

View File

@ -3573,3 +3573,16 @@ func isdirectiface(t *Type) bool {
return false return false
} }
// type2IET returns "T" if t is a concrete type,
// "I" if t is an interface type, and "E" if t is an empty interface type.
// It is used to build calls to the conv* and assert* runtime routines.
func type2IET(t *Type) string {
if isnilinter(t) {
return "E"
}
if Isinter(t) {
return "I"
}
return "T"
}

View File

@ -678,20 +678,7 @@ func walkexpr(np **Node, init **NodeList) {
n1 := Nod(OADDR, n.Left, nil) n1 := Nod(OADDR, n.Left, nil)
r := n.Right // i.(T) r := n.Right // i.(T)
from := "I" buf := "assert" + type2IET(r.Left.Type) + "2" + type2IET(r.Type)
to := "T"
if isnilinter(r.Left.Type) {
from = "E"
}
if isnilinter(r.Type) {
to = "E"
} else if Isinter(r.Type) {
to = "I"
}
buf := fmt.Sprintf("assert%s2%s", from, to)
fn := syslook(buf, 1) fn := syslook(buf, 1)
substArgTypes(fn, r.Left.Type, r.Type) substArgTypes(fn, r.Left.Type, r.Type)
@ -864,46 +851,37 @@ func walkexpr(np **Node, init **NodeList) {
n = mkcall1(mapfndel("mapdelete", t), nil, init, typename(t), map_, key) n = mkcall1(mapfndel("mapdelete", t), nil, init, typename(t), map_, key)
goto ret goto ret
// a,b = i.(T) // res, ok = i.(T)
// orderstmt made sure a is addressable. // orderstmt made sure a is addressable.
case OAS2DOTTYPE: case OAS2DOTTYPE:
*init = concat(*init, n.Ninit) *init = concat(*init, n.Ninit)
n.Ninit = nil n.Ninit = nil
r := n.Rlist.N
e := n.Rlist.N // i.(T)
walkexprlistsafe(n.List, init) walkexprlistsafe(n.List, init)
walkexpr(&r.Left, init) walkexpr(&e.Left, init)
var n1 *Node t := e.Type // T
if isblank(n.List.N) { from := e.Left // i
n1 = nodnil()
} else {
n1 = Nod(OADDR, n.List.N, nil)
}
n1.Etype = 1 // addr does not escape
from := "I" oktype := Types[TBOOL]
to := "T"
if isnilinter(r.Left.Type) {
from = "E"
}
if isnilinter(r.Type) {
to = "E"
} else if Isinter(r.Type) {
to = "I"
}
buf := fmt.Sprintf("assert%s2%s2", from, to)
fn := syslook(buf, 1)
substArgTypes(fn, r.Left.Type, r.Type)
t := Types[TBOOL]
ok := n.List.Next.N ok := n.List.Next.N
if !isblank(ok) { if !isblank(ok) {
t = ok.Type oktype = ok.Type
} }
r = mkcall1(fn, t, init, typename(r.Type), r.Left, n1)
n = Nod(OAS, ok, r) var resptr *Node // &res
if isblank(n.List.N) {
resptr = nodnil()
} else {
resptr = Nod(OADDR, n.List.N, nil)
}
resptr.Etype = 1 // addr does not escape
buf := "assert" + type2IET(from.Type) + "2" + type2IET(t) + "2"
fn := syslook(buf, 1)
substArgTypes(fn, from.Type, t)
call := mkcall1(fn, oktype, init, typename(t), from, resptr)
n = Nod(OAS, ok, call)
typecheck(&n, Etop) typecheck(&n, Etop)
goto ret goto ret
@ -926,19 +904,7 @@ func walkexpr(np **Node, init **NodeList) {
// Build name of function: convI2E etc. // Build name of function: convI2E etc.
// Not all names are possible // Not all names are possible
// (e.g., we'll never generate convE2E or convE2I). // (e.g., we'll never generate convE2E or convE2I).
from := "T" buf := "conv" + type2IET(n.Left.Type) + "2" + type2IET(n.Type)
to := "I"
if isnilinter(n.Left.Type) {
from = "E"
} else if Isinter(n.Left.Type) {
from = "I"
}
if isnilinter(n.Type) {
to = "E"
}
buf := fmt.Sprintf("conv%s2%s", from, to)
fn := syslook(buf, 1) fn := syslook(buf, 1)
var ll *NodeList var ll *NodeList
if !Isinter(n.Left.Type) { if !Isinter(n.Left.Type) {