mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.regabi] cmd/compile: use Ntype where possible
For nodes that are always a type expression, we can use Ntype instead of Node. Passes toolstash -cmp. Change-Id: I28f9fa235015ab48d0da06b78b30c49d74c64e3a Reviewed-on: https://go-review.googlesource.com/c/go/+/280642 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
82ad3083f8
commit
33801cdc62
6 changed files with 26 additions and 26 deletions
|
|
@ -67,7 +67,7 @@ type Func struct {
|
||||||
Dcl []*Name
|
Dcl []*Name
|
||||||
|
|
||||||
ClosureEnter Nodes // list of ONAME nodes (or OADDR-of-ONAME nodes, for output parameters) of captured variables
|
ClosureEnter Nodes // list of ONAME nodes (or OADDR-of-ONAME nodes, for output parameters) of captured variables
|
||||||
ClosureType Node // closure representation type
|
ClosureType Ntype // closure representation type
|
||||||
ClosureVars []*Name // closure params; each has closurevar set
|
ClosureVars []*Name // closure params; each has closurevar set
|
||||||
|
|
||||||
// Parents records the parent scope of each scope within a
|
// Parents records the parent scope of each scope within a
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ func (n *ArrayType) doChildren(do func(Node) error) error {
|
||||||
}
|
}
|
||||||
func (n *ArrayType) editChildren(edit func(Node) Node) {
|
func (n *ArrayType) editChildren(edit func(Node) Node) {
|
||||||
n.Len = maybeEdit(n.Len, edit)
|
n.Len = maybeEdit(n.Len, edit)
|
||||||
n.Elem = maybeEdit(n.Elem, edit)
|
n.Elem = toNtype(maybeEdit(n.Elem, edit))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *AssignListStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
func (n *AssignListStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||||
|
|
@ -241,7 +241,7 @@ func (n *ChanType) doChildren(do func(Node) error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (n *ChanType) editChildren(edit func(Node) Node) {
|
func (n *ChanType) editChildren(edit func(Node) Node) {
|
||||||
n.Elem = maybeEdit(n.Elem, edit)
|
n.Elem = toNtype(maybeEdit(n.Elem, edit))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ClosureExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
func (n *ClosureExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||||
|
|
@ -632,8 +632,8 @@ func (n *MapType) doChildren(do func(Node) error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (n *MapType) editChildren(edit func(Node) Node) {
|
func (n *MapType) editChildren(edit func(Node) Node) {
|
||||||
n.Key = maybeEdit(n.Key, edit)
|
n.Key = toNtype(maybeEdit(n.Key, edit))
|
||||||
n.Elem = maybeEdit(n.Elem, edit)
|
n.Elem = toNtype(maybeEdit(n.Elem, edit))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Name) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
func (n *Name) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||||
|
|
@ -873,7 +873,7 @@ func (n *SliceType) doChildren(do func(Node) error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (n *SliceType) editChildren(edit func(Node) Node) {
|
func (n *SliceType) editChildren(edit func(Node) Node) {
|
||||||
n.Elem = maybeEdit(n.Elem, edit)
|
n.Elem = toNtype(maybeEdit(n.Elem, edit))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *StarExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
func (n *StarExpr) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ func (n *miniType) Type() *types.Type { return n.typ }
|
||||||
// setOTYPE also records t.Nod = self if t.Nod is not already set.
|
// setOTYPE also records t.Nod = self if t.Nod is not already set.
|
||||||
// (Some types are shared by multiple OTYPE nodes, so only
|
// (Some types are shared by multiple OTYPE nodes, so only
|
||||||
// the first such node is used as t.Nod.)
|
// the first such node is used as t.Nod.)
|
||||||
func (n *miniType) setOTYPE(t *types.Type, self Node) {
|
func (n *miniType) setOTYPE(t *types.Type, self Ntype) {
|
||||||
if n.typ != nil {
|
if n.typ != nil {
|
||||||
panic(n.op.String() + " SetType: type already set")
|
panic(n.op.String() + " SetType: type already set")
|
||||||
}
|
}
|
||||||
|
|
@ -61,11 +61,11 @@ func (n *miniType) Implicit() bool { return false } // for Format OTYPE
|
||||||
// A ChanType represents a chan Elem syntax with the direction Dir.
|
// A ChanType represents a chan Elem syntax with the direction Dir.
|
||||||
type ChanType struct {
|
type ChanType struct {
|
||||||
miniType
|
miniType
|
||||||
Elem Node
|
Elem Ntype
|
||||||
Dir types.ChanDir
|
Dir types.ChanDir
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChanType(pos src.XPos, elem Node, dir types.ChanDir) *ChanType {
|
func NewChanType(pos src.XPos, elem Ntype, dir types.ChanDir) *ChanType {
|
||||||
n := &ChanType{Elem: elem, Dir: dir}
|
n := &ChanType{Elem: elem, Dir: dir}
|
||||||
n.op = OTCHAN
|
n.op = OTCHAN
|
||||||
n.pos = pos
|
n.pos = pos
|
||||||
|
|
@ -80,11 +80,11 @@ func (n *ChanType) SetOTYPE(t *types.Type) {
|
||||||
// A MapType represents a map[Key]Value type syntax.
|
// A MapType represents a map[Key]Value type syntax.
|
||||||
type MapType struct {
|
type MapType struct {
|
||||||
miniType
|
miniType
|
||||||
Key Node
|
Key Ntype
|
||||||
Elem Node
|
Elem Ntype
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMapType(pos src.XPos, key, elem Node) *MapType {
|
func NewMapType(pos src.XPos, key, elem Ntype) *MapType {
|
||||||
n := &MapType{Key: key, Elem: elem}
|
n := &MapType{Key: key, Elem: elem}
|
||||||
n.op = OTMAP
|
n.op = OTMAP
|
||||||
n.pos = pos
|
n.pos = pos
|
||||||
|
|
@ -246,11 +246,11 @@ func editFields(list []*Field, edit func(Node) Node) {
|
||||||
// If DDD is true, it's the ...Elem at the end of a function list.
|
// If DDD is true, it's the ...Elem at the end of a function list.
|
||||||
type SliceType struct {
|
type SliceType struct {
|
||||||
miniType
|
miniType
|
||||||
Elem Node
|
Elem Ntype
|
||||||
DDD bool
|
DDD bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSliceType(pos src.XPos, elem Node) *SliceType {
|
func NewSliceType(pos src.XPos, elem Ntype) *SliceType {
|
||||||
n := &SliceType{Elem: elem}
|
n := &SliceType{Elem: elem}
|
||||||
n.op = OTSLICE
|
n.op = OTSLICE
|
||||||
n.pos = pos
|
n.pos = pos
|
||||||
|
|
@ -267,11 +267,11 @@ func (n *SliceType) SetOTYPE(t *types.Type) {
|
||||||
type ArrayType struct {
|
type ArrayType struct {
|
||||||
miniType
|
miniType
|
||||||
Len Node
|
Len Node
|
||||||
Elem Node
|
Elem Ntype
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewArrayType(pos src.XPos, size Node, elem Node) *ArrayType {
|
func NewArrayType(pos src.XPos, len Node, elem Ntype) *ArrayType {
|
||||||
n := &ArrayType{Len: size, Elem: elem}
|
n := &ArrayType{Len: len, Elem: elem}
|
||||||
n.op = OTARRAY
|
n.op = OTARRAY
|
||||||
n.pos = pos
|
n.pos = pos
|
||||||
return n
|
return n
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,7 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
|
||||||
|
|
||||||
// Need to handle [...]T arrays specially.
|
// Need to handle [...]T arrays specially.
|
||||||
if array, ok := n.Ntype.(*ir.ArrayType); ok && array.Elem != nil && array.Len == nil {
|
if array, ok := n.Ntype.(*ir.ArrayType); ok && array.Elem != nil && array.Len == nil {
|
||||||
array.Elem = typecheck(array.Elem, ctxType)
|
array.Elem = typecheckNtype(array.Elem)
|
||||||
elemType := array.Elem.Type()
|
elemType := array.Elem.Type()
|
||||||
if elemType == nil {
|
if elemType == nil {
|
||||||
n.SetType(nil)
|
n.SetType(nil)
|
||||||
|
|
@ -243,7 +243,7 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
n.Ntype = ir.Node(typecheck(n.Ntype, ctxType)).(ir.Ntype)
|
n.Ntype = typecheckNtype(n.Ntype)
|
||||||
t := n.Ntype.Type()
|
t := n.Ntype.Type()
|
||||||
if t == nil {
|
if t == nil {
|
||||||
n.SetType(nil)
|
n.SetType(nil)
|
||||||
|
|
|
||||||
|
|
@ -342,7 +342,7 @@ func tcClosure(clo *ir.ClosureExpr, top int) {
|
||||||
fn.Iota = x
|
fn.Iota = x
|
||||||
}
|
}
|
||||||
|
|
||||||
fn.ClosureType = typecheck(fn.ClosureType, ctxType)
|
fn.ClosureType = typecheckNtype(fn.ClosureType)
|
||||||
clo.SetType(fn.ClosureType.Type())
|
clo.SetType(fn.ClosureType.Type())
|
||||||
fn.SetClosureCalled(top&ctxCallee != 0)
|
fn.SetClosureCalled(top&ctxCallee != 0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
// tcArrayType typechecks an OTARRAY node.
|
// tcArrayType typechecks an OTARRAY node.
|
||||||
func tcArrayType(n *ir.ArrayType) ir.Node {
|
func tcArrayType(n *ir.ArrayType) ir.Node {
|
||||||
n.Elem = typecheck(n.Elem, ctxType)
|
n.Elem = typecheckNtype(n.Elem)
|
||||||
if n.Elem.Type() == nil {
|
if n.Elem.Type() == nil {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
@ -59,7 +59,7 @@ func tcArrayType(n *ir.ArrayType) ir.Node {
|
||||||
|
|
||||||
// tcChanType typechecks an OTCHAN node.
|
// tcChanType typechecks an OTCHAN node.
|
||||||
func tcChanType(n *ir.ChanType) ir.Node {
|
func tcChanType(n *ir.ChanType) ir.Node {
|
||||||
n.Elem = typecheck(n.Elem, ctxType)
|
n.Elem = typecheckNtype(n.Elem)
|
||||||
l := n.Elem
|
l := n.Elem
|
||||||
if l.Type() == nil {
|
if l.Type() == nil {
|
||||||
return n
|
return n
|
||||||
|
|
@ -114,8 +114,8 @@ func tcInterfaceType(n *ir.InterfaceType) ir.Node {
|
||||||
|
|
||||||
// tcMapType typechecks an OTMAP node.
|
// tcMapType typechecks an OTMAP node.
|
||||||
func tcMapType(n *ir.MapType) ir.Node {
|
func tcMapType(n *ir.MapType) ir.Node {
|
||||||
n.Key = typecheck(n.Key, ctxType)
|
n.Key = typecheckNtype(n.Key)
|
||||||
n.Elem = typecheck(n.Elem, ctxType)
|
n.Elem = typecheckNtype(n.Elem)
|
||||||
l := n.Key
|
l := n.Key
|
||||||
r := n.Elem
|
r := n.Elem
|
||||||
if l.Type() == nil || r.Type() == nil {
|
if l.Type() == nil || r.Type() == nil {
|
||||||
|
|
@ -134,7 +134,7 @@ func tcMapType(n *ir.MapType) ir.Node {
|
||||||
|
|
||||||
// tcSliceType typechecks an OTSLICE node.
|
// tcSliceType typechecks an OTSLICE node.
|
||||||
func tcSliceType(n *ir.SliceType) ir.Node {
|
func tcSliceType(n *ir.SliceType) ir.Node {
|
||||||
n.Elem = typecheck(n.Elem, ctxType)
|
n.Elem = typecheckNtype(n.Elem)
|
||||||
if n.Elem.Type() == nil {
|
if n.Elem.Type() == nil {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue