cmd/compile: factor out Pkg, Sym, and Type into package types

- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
  file which contains a handful of functions that must be installed
  early by the gc frontend
- to break cycles, for now we need two functions to convert between
  *gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
  functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
  types.NewPtr, types.NewArray, etc.

Passes toolstash-check -all.

Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2017-04-04 17:54:02 -07:00
parent 19bd145d07
commit f68f292820
48 changed files with 2433 additions and 2005 deletions

View file

@ -4,14 +4,17 @@
package gc
import "unicode/utf8"
import (
"cmd/compile/internal/types"
"unicode/utf8"
)
// range
func typecheckrange(n *Node) {
var toomany int
var why string
var t1 *Type
var t2 *Type
var t1 *types.Type
var t2 *types.Type
var v1 *Node
var v2 *Node
var ls []*Node
@ -52,7 +55,7 @@ func typecheckrange(n *Node) {
goto out
case TARRAY, TSLICE:
t1 = Types[TINT]
t1 = types.Types[TINT]
t2 = t.Elem()
case TMAP:
@ -72,8 +75,8 @@ func typecheckrange(n *Node) {
}
case TSTRING:
t1 = Types[TINT]
t2 = runetype
t1 = types.Types[TINT]
t2 = types.Runetype
}
if n.List.Len() > 2 || toomany != 0 {
@ -187,15 +190,15 @@ func walkrange(n *Node) *Node {
// orderstmt arranged for a copy of the array/slice variable if needed.
ha := a
hv1 := temp(Types[TINT])
hn := temp(Types[TINT])
hv1 := temp(types.Types[TINT])
hn := temp(types.Types[TINT])
var hp *Node
init = append(init, nod(OAS, hv1, nil))
init = append(init, nod(OAS, hn, nod(OLEN, ha, nil)))
if v2 != nil {
hp = temp(typPtr(n.Type.Elem()))
hp = temp(types.NewPtr(n.Type.Elem()))
tmp := nod(OINDEX, ha, nodintconst(0))
tmp.SetBounded(true)
init = append(init, nod(OAS, hp, nod(OADDR, tmp, nil)))
@ -229,7 +232,7 @@ func walkrange(n *Node) *Node {
tmp.Type = hp.Type
tmp.Typecheck = 1
tmp.Right.Type = Types[Tptr]
tmp.Right.Type = types.Types[types.Tptr]
tmp.Right.Typecheck = 1
a = nod(OAS, hp, tmp)
a = typecheck(a, Etop)
@ -281,10 +284,10 @@ func walkrange(n *Node) *Node {
hv1 := temp(t.Elem())
hv1.Typecheck = 1
if haspointers(t.Elem()) {
if types.Haspointers(t.Elem()) {
init = append(init, nod(OAS, hv1, nil))
}
hb := temp(Types[TBOOL])
hb := temp(types.Types[TBOOL])
n.Left = nod(ONE, hb, nodbool(false))
a := nod(OAS2RECV, nil, nil)
@ -321,9 +324,9 @@ func walkrange(n *Node) *Node {
// orderstmt arranged for a copy of the string variable.
ha := a
hv1 := temp(Types[TINT])
hv1t := temp(Types[TINT])
hv2 := temp(runetype)
hv1 := temp(types.Types[TINT])
hv1t := temp(types.Types[TINT])
hv2 := temp(types.Runetype)
// hv1 := 0
init = append(init, nod(OAS, hv1, nil))
@ -339,7 +342,7 @@ func walkrange(n *Node) *Node {
// hv2 := rune(ha[hv1])
nind := nod(OINDEX, ha, hv1)
nind.SetBounded(true)
body = append(body, nod(OAS, hv2, conv(nind, runetype)))
body = append(body, nod(OAS, hv2, conv(nind, types.Runetype)))
// if hv2 < utf8.RuneSelf
nif := nod(OIF, nil, nil)
@ -448,25 +451,25 @@ func memclrrange(n, v1, v2, a *Node) bool {
n.Left = nod(ONE, nod(OLEN, a, nil), nodintconst(0))
// hp = &a[0]
hp := temp(Types[TUNSAFEPTR])
hp := temp(types.Types[TUNSAFEPTR])
tmp := nod(OINDEX, a, nodintconst(0))
tmp.SetBounded(true)
tmp = nod(OADDR, tmp, nil)
tmp = nod(OCONVNOP, tmp, nil)
tmp.Type = Types[TUNSAFEPTR]
tmp.Type = types.Types[TUNSAFEPTR]
n.Nbody.Append(nod(OAS, hp, tmp))
// hn = len(a) * sizeof(elem(a))
hn := temp(Types[TUINTPTR])
hn := temp(types.Types[TUINTPTR])
tmp = nod(OLEN, a, nil)
tmp = nod(OMUL, tmp, nodintconst(elemsize))
tmp = conv(tmp, Types[TUINTPTR])
tmp = conv(tmp, types.Types[TUINTPTR])
n.Nbody.Append(nod(OAS, hn, tmp))
var fn *Node
if haspointers(a.Type.Elem()) {
if types.Haspointers(a.Type.Elem()) {
// memclrHasPointers(hp, hn)
fn = mkcall("memclrHasPointers", nil, nil, hp, hn)
} else {