Skip to content

Commit

Permalink
go/ast: rename MultiIndexExpr to IndexListExpr
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
findleyr committed Sep 8, 2021
1 parent 65f0d24 commit 0406d3a
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/go/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ type (
Rbrack token.Pos // position of "]"
}

// A MultiIndexExpr node represents an expression followed by multiple
// An IndexListExpr node represents an expression followed by multiple
// indices.
MultiIndexExpr struct {
IndexListExpr struct {
X Expr // expression
Lbrack token.Pos // position of "["
Indices []Expr // index expressions
Expand Down Expand Up @@ -496,7 +496,7 @@ func (x *CompositeLit) Pos() token.Pos {
func (x *ParenExpr) Pos() token.Pos { return x.Lparen }
func (x *SelectorExpr) 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 *TypeAssertExpr) Pos() token.Pos { return x.X.Pos() }
func (x *CallExpr) Pos() token.Pos { return x.Fun.Pos() }
Expand Down Expand Up @@ -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 *SelectorExpr) End() token.Pos { return x.Sel.End() }
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 *TypeAssertExpr) End() token.Pos { return x.Rparen + 1 }
func (x *CallExpr) End() token.Pos { return x.Rparen + 1 }
Expand Down Expand Up @@ -562,7 +562,7 @@ func (*CompositeLit) exprNode() {}
func (*ParenExpr) exprNode() {}
func (*SelectorExpr) exprNode() {}
func (*IndexExpr) exprNode() {}
func (*MultiIndexExpr) exprNode() {}
func (*IndexListExpr) exprNode() {}
func (*SliceExpr) exprNode() {}
func (*TypeAssertExpr) exprNode() {}
func (*CallExpr) exprNode() {}
Expand Down
2 changes: 1 addition & 1 deletion src/go/ast/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func Walk(v Visitor, node Node) {
Walk(v, n.X)
Walk(v, n.Index)

case *MultiIndexExpr:
case *IndexListExpr:
Walk(v, n.X)
for _, index := range n.Indices {
Walk(v, index)
Expand Down
13 changes: 6 additions & 7 deletions src/go/internal/typeparams/typeparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func PackIndexExpr(x ast.Expr, lbrack token.Pos, exprs []ast.Expr, rbrack token.
Rbrack: rbrack,
}
default:
return &ast.MultiIndexExpr{
return &ast.IndexListExpr{
X: x,
Lbrack: lbrack,
Indices: exprs,
Expand All @@ -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
// MultiIndexExpr interface.
// IndexExpr wraps an ast.IndexExpr or ast.IndexListExpr.
//
// Orig holds the original ast.Expr from which this IndexExpr was derived.
type IndexExpr struct {
Orig ast.Expr // the wrapped expr, which may be distinct from MultiIndexExpr below.
*ast.MultiIndexExpr
Orig ast.Expr // the wrapped expr, which may be distinct from the IndexListExpr below.
*ast.IndexListExpr
}

func UnpackIndexExpr(n ast.Node) *IndexExpr {
switch e := n.(type) {
case *ast.IndexExpr:
return &IndexExpr{e, &ast.MultiIndexExpr{
return &IndexExpr{e, &ast.IndexListExpr{
X: e.X,
Lbrack: e.Lbrack,
Indices: []ast.Expr{e.Index},
Rbrack: e.Rbrack,
}}
case *ast.MultiIndexExpr:
case *ast.IndexListExpr:
return &IndexExpr{e, e}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions src/go/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ func (p *parser) checkExpr(x ast.Expr) ast.Expr {
panic("unreachable")
case *ast.SelectorExpr:
case *ast.IndexExpr:
case *ast.MultiIndexExpr:
case *ast.IndexListExpr:
case *ast.SliceExpr:
case *ast.TypeAssertExpr:
// If t.Type == nil we have a type assertion of the form
Expand Down Expand Up @@ -1660,7 +1660,7 @@ func (p *parser) parsePrimaryExpr() (x ast.Expr) {
return
}
// x is possibly a composite literal type
case *ast.IndexExpr, *ast.MultiIndexExpr:
case *ast.IndexExpr, *ast.IndexListExpr:
if p.exprLev < 0 {
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/go/printer/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int) {
p.expr0(x.Index, depth+1)
p.print(x.Rbrack, token.RBRACK)

case *ast.MultiIndexExpr:
case *ast.IndexListExpr:
// TODO(gri): as for IndexExpr, should treat [] like parentheses and undo
// one level of depth
p.expr1(x.X, token.HighestPrec, 1)
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
if sig.TypeParams().Len() > 0 {
if !check.allowVersion(check.pkg, 1, 18) {
switch call.Fun.(type) {
case *ast.IndexExpr, *ast.MultiIndexExpr:
case *ast.IndexExpr, *ast.IndexListExpr:
ix := typeparams.UnpackIndexExpr(call.Fun)
check.softErrorf(inNode(call.Fun, ix.Lbrack), _Todo, "function instantiation requires go1.18 or later")
default:
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
case *ast.SelectorExpr:
check.selector(x, e)

case *ast.IndexExpr, *ast.MultiIndexExpr:
case *ast.IndexExpr, *ast.IndexListExpr:
ix := typeparams.UnpackIndexExpr(e)
if check.indexExpr(x, ix) {
check.funcInst(x, ix)
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/exprstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func WriteExpr(buf *bytes.Buffer, x ast.Expr) {
buf.WriteByte('.')
buf.WriteString(x.Sel.Name)

case *ast.IndexExpr, *ast.MultiIndexExpr:
case *ast.IndexExpr, *ast.IndexListExpr:
ix := typeparams.UnpackIndexExpr(x)
WriteExpr(buf, ix.X)
buf.WriteByte('[')
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ L: // unpack receiver type

// unpack type parameters, if any
switch rtyp.(type) {
case *ast.IndexExpr, *ast.MultiIndexExpr:
case *ast.IndexExpr, *ast.IndexListExpr:
ix := typeparams.UnpackIndexExpr(rtyp)
rtyp = ix.X
if unpackParams {
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func isubst(x ast.Expr, smap map[*ast.Ident]*ast.Ident) ast.Expr {
new.X = X
return &new
}
case *ast.IndexExpr, *ast.MultiIndexExpr:
case *ast.IndexExpr, *ast.IndexListExpr:
ix := typeparams.UnpackIndexExpr(x)
var newIndexes []ast.Expr
for i, index := range ix.Indices {
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func embeddedFieldIdent(e ast.Expr) *ast.Ident {
return e.Sel
case *ast.IndexExpr:
return embeddedFieldIdent(e.X)
case *ast.MultiIndexExpr:
case *ast.IndexListExpr:
return embeddedFieldIdent(e.X)
}
return nil // invalid embedded field
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/typexpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

case *ast.IndexExpr, *ast.MultiIndexExpr:
case *ast.IndexExpr, *ast.IndexListExpr:
ix := typeparams.UnpackIndexExpr(e)
if !check.allowVersion(check.pkg, 1, 18) {
check.softErrorf(inNode(e, ix.Lbrack), _Todo, "type instantiation requires go1.18 or later")
Expand Down

0 comments on commit 0406d3a

Please sign in to comment.