mirror of
https://github.com/golang/go
synced 2024-09-29 16:24:28 -06:00
cmd/compile: remove ir.CompLitExpr.Ntype field
It's no longer needed, since type expressions are all evaluated by types2. We can just use Node.Type instead. Change-Id: If523bd96f96fc4f2337a26f563f84e4f194e654a Reviewed-on: https://go-review.googlesource.com/c/go/+/403841 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
3ffc230a9f
commit
27b844f767
@ -191,7 +191,6 @@ type ClosureExpr struct {
|
|||||||
type CompLitExpr struct {
|
type CompLitExpr struct {
|
||||||
miniExpr
|
miniExpr
|
||||||
origNode
|
origNode
|
||||||
Ntype Ntype
|
|
||||||
List Nodes // initialized values
|
List Nodes // initialized values
|
||||||
Prealloc *Name
|
Prealloc *Name
|
||||||
// For OSLICELIT, Len is the backing array length.
|
// For OSLICELIT, Len is the backing array length.
|
||||||
@ -205,7 +204,7 @@ func NewCompLitExpr(pos src.XPos, op Op, typ *types.Type, list []Node) *CompLitE
|
|||||||
n.pos = pos
|
n.pos = pos
|
||||||
n.SetOp(op)
|
n.SetOp(op)
|
||||||
if typ != nil {
|
if typ != nil {
|
||||||
n.Ntype = TypeNode(typ)
|
n.SetType(typ)
|
||||||
}
|
}
|
||||||
n.orig = n
|
n.orig = n
|
||||||
return n
|
return n
|
||||||
|
@ -667,15 +667,10 @@ func exprFmt(n Node, s fmt.State, prec int) {
|
|||||||
fmt.Fprintf(s, "%v{%s}", typ, ellipsisIf(len(n.List) != 0))
|
fmt.Fprintf(s, "%v{%s}", typ, ellipsisIf(len(n.List) != 0))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if n.Ntype != nil {
|
|
||||||
fmt.Fprintf(s, "%v{%s}", n.Ntype, ellipsisIf(len(n.List) != 0))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprint(s, "composite literal")
|
fmt.Fprint(s, "composite literal")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Fprintf(s, "(%v{ %.v })", n.Ntype, n.List)
|
fmt.Fprintf(s, "(%v{ %.v })", n.Type(), n.List)
|
||||||
|
|
||||||
case OPTRLIT:
|
case OPTRLIT:
|
||||||
n := n.(*AddrExpr)
|
n := n.(*AddrExpr)
|
||||||
|
@ -346,9 +346,6 @@ func (n *CompLitExpr) doChildren(do func(Node) bool) bool {
|
|||||||
if doNodes(n.init, do) {
|
if doNodes(n.init, do) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if n.Ntype != nil && do(n.Ntype) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if doNodes(n.List, do) {
|
if doNodes(n.List, do) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -359,9 +356,6 @@ func (n *CompLitExpr) doChildren(do func(Node) bool) bool {
|
|||||||
}
|
}
|
||||||
func (n *CompLitExpr) editChildren(edit func(Node) Node) {
|
func (n *CompLitExpr) editChildren(edit func(Node) Node) {
|
||||||
editNodes(n.init, edit)
|
editNodes(n.init, edit)
|
||||||
if n.Ntype != nil {
|
|
||||||
n.Ntype = edit(n.Ntype).(Ntype)
|
|
||||||
}
|
|
||||||
editNodes(n.List, edit)
|
editNodes(n.List, edit)
|
||||||
if n.Prealloc != nil {
|
if n.Prealloc != nil {
|
||||||
n.Prealloc = edit(n.Prealloc).(*Name)
|
n.Prealloc = edit(n.Prealloc).(*Name)
|
||||||
|
@ -207,24 +207,13 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
|
|||||||
base.Pos = lno
|
base.Pos = lno
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if n.Ntype == nil {
|
|
||||||
base.ErrorfAt(n.Pos(), "missing type in composite literal")
|
|
||||||
n.SetType(nil)
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save original node (including n.Right)
|
// Save original node (including n.Right)
|
||||||
n.SetOrig(ir.Copy(n))
|
n.SetOrig(ir.Copy(n))
|
||||||
|
|
||||||
ir.SetPos(n.Ntype)
|
ir.SetPos(n)
|
||||||
|
|
||||||
n.Ntype = typecheckNtype(n.Ntype)
|
t := n.Type()
|
||||||
t := n.Ntype.Type()
|
base.AssertfAt(t != nil, n.Pos(), "missing type in composite literal")
|
||||||
if t == nil {
|
|
||||||
n.SetType(nil)
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
n.SetType(t)
|
|
||||||
|
|
||||||
switch t.Kind() {
|
switch t.Kind() {
|
||||||
default:
|
default:
|
||||||
@ -234,12 +223,10 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
|
|||||||
case types.TARRAY:
|
case types.TARRAY:
|
||||||
typecheckarraylit(t.Elem(), t.NumElem(), n.List, "array literal")
|
typecheckarraylit(t.Elem(), t.NumElem(), n.List, "array literal")
|
||||||
n.SetOp(ir.OARRAYLIT)
|
n.SetOp(ir.OARRAYLIT)
|
||||||
n.Ntype = nil
|
|
||||||
|
|
||||||
case types.TSLICE:
|
case types.TSLICE:
|
||||||
length := typecheckarraylit(t.Elem(), -1, n.List, "slice literal")
|
length := typecheckarraylit(t.Elem(), -1, n.List, "slice literal")
|
||||||
n.SetOp(ir.OSLICELIT)
|
n.SetOp(ir.OSLICELIT)
|
||||||
n.Ntype = nil
|
|
||||||
n.Len = length
|
n.Len = length
|
||||||
|
|
||||||
case types.TMAP:
|
case types.TMAP:
|
||||||
@ -253,18 +240,15 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
|
|||||||
l := l.(*ir.KeyExpr)
|
l := l.(*ir.KeyExpr)
|
||||||
|
|
||||||
r := l.Key
|
r := l.Key
|
||||||
r = pushtype(r, t.Key())
|
|
||||||
r = Expr(r)
|
r = Expr(r)
|
||||||
l.Key = AssignConv(r, t.Key(), "map key")
|
l.Key = AssignConv(r, t.Key(), "map key")
|
||||||
|
|
||||||
r = l.Value
|
r = l.Value
|
||||||
r = pushtype(r, t.Elem())
|
|
||||||
r = Expr(r)
|
r = Expr(r)
|
||||||
l.Value = AssignConv(r, t.Elem(), "map value")
|
l.Value = AssignConv(r, t.Elem(), "map value")
|
||||||
}
|
}
|
||||||
|
|
||||||
n.SetOp(ir.OMAPLIT)
|
n.SetOp(ir.OMAPLIT)
|
||||||
n.Ntype = nil
|
|
||||||
|
|
||||||
case types.TSTRUCT:
|
case types.TSTRUCT:
|
||||||
// Need valid field offsets for Xoffset below.
|
// Need valid field offsets for Xoffset below.
|
||||||
@ -345,7 +329,6 @@ func tcCompLit(n *ir.CompLitExpr) (res ir.Node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
n.SetOp(ir.OSTRUCTLIT)
|
n.SetOp(ir.OSTRUCTLIT)
|
||||||
n.Ntype = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return n
|
return n
|
||||||
|
@ -1410,23 +1410,18 @@ func (r *importReader) node() ir.Node {
|
|||||||
pos := r.pos()
|
pos := r.pos()
|
||||||
typ := r.typ()
|
typ := r.typ()
|
||||||
list := r.fieldList()
|
list := r.fieldList()
|
||||||
n := ir.NewCompLitExpr(pos, ir.OSTRUCTLIT, nil, list)
|
return ir.NewCompLitExpr(pos, ir.OSTRUCTLIT, typ, list)
|
||||||
n.SetType(typ)
|
|
||||||
return n
|
|
||||||
|
|
||||||
case ir.OCOMPLIT:
|
case ir.OCOMPLIT:
|
||||||
pos := r.pos()
|
pos := r.pos()
|
||||||
t := r.typ()
|
t := r.typ()
|
||||||
n := ir.NewCompLitExpr(pos, ir.OCOMPLIT, t, r.exprList())
|
return ir.NewCompLitExpr(pos, ir.OCOMPLIT, t, r.exprList())
|
||||||
n.SetType(t)
|
|
||||||
return n
|
|
||||||
|
|
||||||
case ir.OARRAYLIT, ir.OSLICELIT, ir.OMAPLIT:
|
case ir.OARRAYLIT, ir.OSLICELIT, ir.OMAPLIT:
|
||||||
pos := r.pos()
|
pos := r.pos()
|
||||||
typ := r.typ()
|
typ := r.typ()
|
||||||
list := r.exprList()
|
list := r.exprList()
|
||||||
n := ir.NewCompLitExpr(pos, op, typ, list)
|
n := ir.NewCompLitExpr(pos, op, typ, list)
|
||||||
n.SetType(typ)
|
|
||||||
if op == ir.OSLICELIT {
|
if op == ir.OSLICELIT {
|
||||||
n.Len = int64(r.uint64())
|
n.Len = int64(r.uint64())
|
||||||
}
|
}
|
||||||
|
@ -1451,43 +1451,6 @@ func fielddup(name string, hash map[string]bool) {
|
|||||||
hash[name] = true
|
hash[name] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// iscomptype reports whether type t is a composite literal type.
|
|
||||||
func iscomptype(t *types.Type) bool {
|
|
||||||
switch t.Kind() {
|
|
||||||
case types.TARRAY, types.TSLICE, types.TSTRUCT, types.TMAP:
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// pushtype adds elided type information for composite literals if
|
|
||||||
// appropriate, and returns the resulting expression.
|
|
||||||
func pushtype(nn ir.Node, t *types.Type) ir.Node {
|
|
||||||
if nn == nil || nn.Op() != ir.OCOMPLIT {
|
|
||||||
return nn
|
|
||||||
}
|
|
||||||
n := nn.(*ir.CompLitExpr)
|
|
||||||
if n.Ntype != nil {
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case iscomptype(t):
|
|
||||||
// For T, return T{...}.
|
|
||||||
n.Ntype = ir.TypeNode(t)
|
|
||||||
|
|
||||||
case t.IsPtr() && iscomptype(t.Elem()):
|
|
||||||
// For *T, return &T{...}.
|
|
||||||
n.Ntype = ir.TypeNode(t.Elem())
|
|
||||||
|
|
||||||
addr := NodAddrAt(n.Pos(), n)
|
|
||||||
addr.SetImplicit(true)
|
|
||||||
return addr
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
// typecheckarraylit type-checks a sequence of slice/array literal elements.
|
// typecheckarraylit type-checks a sequence of slice/array literal elements.
|
||||||
func typecheckarraylit(elemType *types.Type, bound int64, elts []ir.Node, ctx string) int64 {
|
func typecheckarraylit(elemType *types.Type, bound int64, elts []ir.Node, ctx string) int64 {
|
||||||
// If there are key/value pairs, create a map to keep seen
|
// If there are key/value pairs, create a map to keep seen
|
||||||
@ -1516,7 +1479,6 @@ func typecheckarraylit(elemType *types.Type, bound int64, elts []ir.Node, ctx st
|
|||||||
r = elt.Value
|
r = elt.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
r = pushtype(r, elemType)
|
|
||||||
r = Expr(r)
|
r = Expr(r)
|
||||||
r = AssignConv(r, elemType, ctx)
|
r = AssignConv(r, elemType, ctx)
|
||||||
if kv != nil {
|
if kv != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user