mirror of https://github.com/golang/go.git
go/ast: rename MultiIndexExpr to IndexListExpr
As discussed in #47781, IndexListExpr is one character shorter and has the advantage of being next to IndexExpr in documentation. Updates #47781 Change-Id: I709d5c1a79b4f9aebcd6445e4ab0cd6dae45bab7 Reviewed-on: https://go-review.googlesource.com/c/go/+/348609 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
65f0d24f73
commit
0406d3a8e5
|
|
@ -344,9 +344,9 @@ type (
|
||||||
Rbrack token.Pos // position of "]"
|
Rbrack token.Pos // position of "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
// A MultiIndexExpr node represents an expression followed by multiple
|
// An IndexListExpr node represents an expression followed by multiple
|
||||||
// indices.
|
// indices.
|
||||||
MultiIndexExpr struct {
|
IndexListExpr struct {
|
||||||
X Expr // expression
|
X Expr // expression
|
||||||
Lbrack token.Pos // position of "["
|
Lbrack token.Pos // position of "["
|
||||||
Indices []Expr // index expressions
|
Indices []Expr // index expressions
|
||||||
|
|
@ -496,7 +496,7 @@ func (x *CompositeLit) Pos() token.Pos {
|
||||||
func (x *ParenExpr) Pos() token.Pos { return x.Lparen }
|
func (x *ParenExpr) Pos() token.Pos { return x.Lparen }
|
||||||
func (x *SelectorExpr) Pos() token.Pos { return x.X.Pos() }
|
func (x *SelectorExpr) Pos() token.Pos { return x.X.Pos() }
|
||||||
func (x *IndexExpr) Pos() token.Pos { return x.X.Pos() }
|
func (x *IndexExpr) Pos() token.Pos { return x.X.Pos() }
|
||||||
func (x *MultiIndexExpr) Pos() token.Pos { return x.X.Pos() }
|
func (x *IndexListExpr) Pos() token.Pos { return x.X.Pos() }
|
||||||
func (x *SliceExpr) Pos() token.Pos { return x.X.Pos() }
|
func (x *SliceExpr) Pos() token.Pos { return x.X.Pos() }
|
||||||
func (x *TypeAssertExpr) Pos() token.Pos { return x.X.Pos() }
|
func (x *TypeAssertExpr) Pos() token.Pos { return x.X.Pos() }
|
||||||
func (x *CallExpr) Pos() token.Pos { return x.Fun.Pos() }
|
func (x *CallExpr) Pos() token.Pos { return x.Fun.Pos() }
|
||||||
|
|
@ -530,7 +530,7 @@ func (x *CompositeLit) End() token.Pos { return x.Rbrace + 1 }
|
||||||
func (x *ParenExpr) End() token.Pos { return x.Rparen + 1 }
|
func (x *ParenExpr) End() token.Pos { return x.Rparen + 1 }
|
||||||
func (x *SelectorExpr) End() token.Pos { return x.Sel.End() }
|
func (x *SelectorExpr) End() token.Pos { return x.Sel.End() }
|
||||||
func (x *IndexExpr) End() token.Pos { return x.Rbrack + 1 }
|
func (x *IndexExpr) End() token.Pos { return x.Rbrack + 1 }
|
||||||
func (x *MultiIndexExpr) End() token.Pos { return x.Rbrack + 1 }
|
func (x *IndexListExpr) End() token.Pos { return x.Rbrack + 1 }
|
||||||
func (x *SliceExpr) End() token.Pos { return x.Rbrack + 1 }
|
func (x *SliceExpr) End() token.Pos { return x.Rbrack + 1 }
|
||||||
func (x *TypeAssertExpr) End() token.Pos { return x.Rparen + 1 }
|
func (x *TypeAssertExpr) End() token.Pos { return x.Rparen + 1 }
|
||||||
func (x *CallExpr) End() token.Pos { return x.Rparen + 1 }
|
func (x *CallExpr) End() token.Pos { return x.Rparen + 1 }
|
||||||
|
|
@ -562,7 +562,7 @@ func (*CompositeLit) exprNode() {}
|
||||||
func (*ParenExpr) exprNode() {}
|
func (*ParenExpr) exprNode() {}
|
||||||
func (*SelectorExpr) exprNode() {}
|
func (*SelectorExpr) exprNode() {}
|
||||||
func (*IndexExpr) exprNode() {}
|
func (*IndexExpr) exprNode() {}
|
||||||
func (*MultiIndexExpr) exprNode() {}
|
func (*IndexListExpr) exprNode() {}
|
||||||
func (*SliceExpr) exprNode() {}
|
func (*SliceExpr) exprNode() {}
|
||||||
func (*TypeAssertExpr) exprNode() {}
|
func (*TypeAssertExpr) exprNode() {}
|
||||||
func (*CallExpr) exprNode() {}
|
func (*CallExpr) exprNode() {}
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ func Walk(v Visitor, node Node) {
|
||||||
Walk(v, n.X)
|
Walk(v, n.X)
|
||||||
Walk(v, n.Index)
|
Walk(v, n.Index)
|
||||||
|
|
||||||
case *MultiIndexExpr:
|
case *IndexListExpr:
|
||||||
Walk(v, n.X)
|
Walk(v, n.X)
|
||||||
for _, index := range n.Indices {
|
for _, index := range n.Indices {
|
||||||
Walk(v, index)
|
Walk(v, index)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ func PackIndexExpr(x ast.Expr, lbrack token.Pos, exprs []ast.Expr, rbrack token.
|
||||||
Rbrack: rbrack,
|
Rbrack: rbrack,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return &ast.MultiIndexExpr{
|
return &ast.IndexListExpr{
|
||||||
X: x,
|
X: x,
|
||||||
Lbrack: lbrack,
|
Lbrack: lbrack,
|
||||||
Indices: exprs,
|
Indices: exprs,
|
||||||
|
|
@ -30,25 +30,24 @@ func PackIndexExpr(x ast.Expr, lbrack token.Pos, exprs []ast.Expr, rbrack token.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IndexExpr wraps an ast.IndexExpr or ast.MultiIndexExpr into the
|
// IndexExpr wraps an ast.IndexExpr or ast.IndexListExpr.
|
||||||
// MultiIndexExpr interface.
|
|
||||||
//
|
//
|
||||||
// Orig holds the original ast.Expr from which this IndexExpr was derived.
|
// Orig holds the original ast.Expr from which this IndexExpr was derived.
|
||||||
type IndexExpr struct {
|
type IndexExpr struct {
|
||||||
Orig ast.Expr // the wrapped expr, which may be distinct from MultiIndexExpr below.
|
Orig ast.Expr // the wrapped expr, which may be distinct from the IndexListExpr below.
|
||||||
*ast.MultiIndexExpr
|
*ast.IndexListExpr
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnpackIndexExpr(n ast.Node) *IndexExpr {
|
func UnpackIndexExpr(n ast.Node) *IndexExpr {
|
||||||
switch e := n.(type) {
|
switch e := n.(type) {
|
||||||
case *ast.IndexExpr:
|
case *ast.IndexExpr:
|
||||||
return &IndexExpr{e, &ast.MultiIndexExpr{
|
return &IndexExpr{e, &ast.IndexListExpr{
|
||||||
X: e.X,
|
X: e.X,
|
||||||
Lbrack: e.Lbrack,
|
Lbrack: e.Lbrack,
|
||||||
Indices: []ast.Expr{e.Index},
|
Indices: []ast.Expr{e.Index},
|
||||||
Rbrack: e.Rbrack,
|
Rbrack: e.Rbrack,
|
||||||
}}
|
}}
|
||||||
case *ast.MultiIndexExpr:
|
case *ast.IndexListExpr:
|
||||||
return &IndexExpr{e, e}
|
return &IndexExpr{e, e}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -1570,7 +1570,7 @@ func (p *parser) checkExpr(x ast.Expr) ast.Expr {
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
case *ast.SelectorExpr:
|
case *ast.SelectorExpr:
|
||||||
case *ast.IndexExpr:
|
case *ast.IndexExpr:
|
||||||
case *ast.MultiIndexExpr:
|
case *ast.IndexListExpr:
|
||||||
case *ast.SliceExpr:
|
case *ast.SliceExpr:
|
||||||
case *ast.TypeAssertExpr:
|
case *ast.TypeAssertExpr:
|
||||||
// If t.Type == nil we have a type assertion of the form
|
// If t.Type == nil we have a type assertion of the form
|
||||||
|
|
@ -1660,7 +1660,7 @@ func (p *parser) parsePrimaryExpr() (x ast.Expr) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// x is possibly a composite literal type
|
// x is possibly a composite literal type
|
||||||
case *ast.IndexExpr, *ast.MultiIndexExpr:
|
case *ast.IndexExpr, *ast.IndexListExpr:
|
||||||
if p.exprLev < 0 {
|
if p.exprLev < 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -873,7 +873,7 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int) {
|
||||||
p.expr0(x.Index, depth+1)
|
p.expr0(x.Index, depth+1)
|
||||||
p.print(x.Rbrack, token.RBRACK)
|
p.print(x.Rbrack, token.RBRACK)
|
||||||
|
|
||||||
case *ast.MultiIndexExpr:
|
case *ast.IndexListExpr:
|
||||||
// TODO(gri): as for IndexExpr, should treat [] like parentheses and undo
|
// TODO(gri): as for IndexExpr, should treat [] like parentheses and undo
|
||||||
// one level of depth
|
// one level of depth
|
||||||
p.expr1(x.X, token.HighestPrec, 1)
|
p.expr1(x.X, token.HighestPrec, 1)
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
|
||||||
if sig.TypeParams().Len() > 0 {
|
if sig.TypeParams().Len() > 0 {
|
||||||
if !check.allowVersion(check.pkg, 1, 18) {
|
if !check.allowVersion(check.pkg, 1, 18) {
|
||||||
switch call.Fun.(type) {
|
switch call.Fun.(type) {
|
||||||
case *ast.IndexExpr, *ast.MultiIndexExpr:
|
case *ast.IndexExpr, *ast.IndexListExpr:
|
||||||
ix := typeparams.UnpackIndexExpr(call.Fun)
|
ix := typeparams.UnpackIndexExpr(call.Fun)
|
||||||
check.softErrorf(inNode(call.Fun, ix.Lbrack), _Todo, "function instantiation requires go1.18 or later")
|
check.softErrorf(inNode(call.Fun, ix.Lbrack), _Todo, "function instantiation requires go1.18 or later")
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -1392,7 +1392,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
||||||
case *ast.SelectorExpr:
|
case *ast.SelectorExpr:
|
||||||
check.selector(x, e)
|
check.selector(x, e)
|
||||||
|
|
||||||
case *ast.IndexExpr, *ast.MultiIndexExpr:
|
case *ast.IndexExpr, *ast.IndexListExpr:
|
||||||
ix := typeparams.UnpackIndexExpr(e)
|
ix := typeparams.UnpackIndexExpr(e)
|
||||||
if check.indexExpr(x, ix) {
|
if check.indexExpr(x, ix) {
|
||||||
check.funcInst(x, ix)
|
check.funcInst(x, ix)
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ func WriteExpr(buf *bytes.Buffer, x ast.Expr) {
|
||||||
buf.WriteByte('.')
|
buf.WriteByte('.')
|
||||||
buf.WriteString(x.Sel.Name)
|
buf.WriteString(x.Sel.Name)
|
||||||
|
|
||||||
case *ast.IndexExpr, *ast.MultiIndexExpr:
|
case *ast.IndexExpr, *ast.IndexListExpr:
|
||||||
ix := typeparams.UnpackIndexExpr(x)
|
ix := typeparams.UnpackIndexExpr(x)
|
||||||
WriteExpr(buf, ix.X)
|
WriteExpr(buf, ix.X)
|
||||||
buf.WriteByte('[')
|
buf.WriteByte('[')
|
||||||
|
|
|
||||||
|
|
@ -513,7 +513,7 @@ L: // unpack receiver type
|
||||||
|
|
||||||
// unpack type parameters, if any
|
// unpack type parameters, if any
|
||||||
switch rtyp.(type) {
|
switch rtyp.(type) {
|
||||||
case *ast.IndexExpr, *ast.MultiIndexExpr:
|
case *ast.IndexExpr, *ast.IndexListExpr:
|
||||||
ix := typeparams.UnpackIndexExpr(rtyp)
|
ix := typeparams.UnpackIndexExpr(rtyp)
|
||||||
rtyp = ix.X
|
rtyp = ix.X
|
||||||
if unpackParams {
|
if unpackParams {
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ func isubst(x ast.Expr, smap map[*ast.Ident]*ast.Ident) ast.Expr {
|
||||||
new.X = X
|
new.X = X
|
||||||
return &new
|
return &new
|
||||||
}
|
}
|
||||||
case *ast.IndexExpr, *ast.MultiIndexExpr:
|
case *ast.IndexExpr, *ast.IndexListExpr:
|
||||||
ix := typeparams.UnpackIndexExpr(x)
|
ix := typeparams.UnpackIndexExpr(x)
|
||||||
var newIndexes []ast.Expr
|
var newIndexes []ast.Expr
|
||||||
for i, index := range ix.Indices {
|
for i, index := range ix.Indices {
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ func embeddedFieldIdent(e ast.Expr) *ast.Ident {
|
||||||
return e.Sel
|
return e.Sel
|
||||||
case *ast.IndexExpr:
|
case *ast.IndexExpr:
|
||||||
return embeddedFieldIdent(e.X)
|
return embeddedFieldIdent(e.X)
|
||||||
case *ast.MultiIndexExpr:
|
case *ast.IndexListExpr:
|
||||||
return embeddedFieldIdent(e.X)
|
return embeddedFieldIdent(e.X)
|
||||||
}
|
}
|
||||||
return nil // invalid embedded field
|
return nil // invalid embedded field
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ func (check *Checker) typInternal(e0 ast.Expr, def *Named) (T Type) {
|
||||||
check.errorf(&x, _NotAType, "%s is not a type", &x)
|
check.errorf(&x, _NotAType, "%s is not a type", &x)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *ast.IndexExpr, *ast.MultiIndexExpr:
|
case *ast.IndexExpr, *ast.IndexListExpr:
|
||||||
ix := typeparams.UnpackIndexExpr(e)
|
ix := typeparams.UnpackIndexExpr(e)
|
||||||
if !check.allowVersion(check.pkg, 1, 18) {
|
if !check.allowVersion(check.pkg, 1, 18) {
|
||||||
check.softErrorf(inNode(e, ix.Lbrack), _Todo, "type instantiation requires go1.18 or later")
|
check.softErrorf(inNode(e, ix.Lbrack), _Todo, "type instantiation requires go1.18 or later")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue