internal/typeparams: use alias rather than indirection for IndexListExpr

Using aliases make it easier to translate code using the new APIs.

Change-Id: I9887569a3ba1d5b1434ac6cc185485433aca7090
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352898
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Robert Findley 2021-09-29 11:36:49 -04:00
Родитель 13c407cf48
Коммит 942994fc75
2 изменённых файлов: 9 добавлений и 7 удалений

Просмотреть файл

@ -253,6 +253,10 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.
a.apply(n, "X", nil, n.X)
a.apply(n, "Index", nil, n.Index)
case *typeparams.IndexListExpr:
a.apply(n, "X", nil, n.X)
a.applyList(n, "Indices")
case *ast.SliceExpr:
a.apply(n, "X", nil, n.X)
a.apply(n, "Low", nil, n.Low)
@ -439,13 +443,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.
}
default:
if ix := typeparams.GetIndexExprData(n); ix != nil {
a.apply(n, "X", nil, ix.X)
// *ast.IndexExpr was handled above, so n must be an *ast.MultiIndexExpr.
a.applyList(n, "Indices")
} else {
panic(fmt.Sprintf("Apply: unexpected node type %T", n))
}
panic(fmt.Sprintf("Apply: unexpected node type %T", n))
}
if a.post != nil && !a.post(&a.cursor) {

Просмотреть файл

@ -53,6 +53,10 @@ func PackIndexExpr(x ast.Expr, lbrack token.Pos, indices []ast.Expr, rbrack toke
// this Go version. Its methods panic on use.
type IndexListExpr struct {
ast.Expr
X ast.Expr // expression
Lbrack token.Pos // position of "["
Indices []ast.Expr // index expressions
Rbrack token.Pos // position of "]"
}
// ForTypeSpec returns an empty field list, as type parameters on not supported