mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: bump github.com/onsi/ginkgo/v2
Bumps the github-dependencies group in /e2e with 1 update: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo). Updates `github.com/onsi/ginkgo/v2` from 2.22.2 to 2.23.0 - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/ginkgo/compare/v2.22.2...v2.23.0) --- updated-dependencies: - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
mergify[bot]
parent
5cf650fa3a
commit
e536333e4c
139
e2e/vendor/golang.org/x/tools/go/ast/inspector/inspector.go
generated
vendored
139
e2e/vendor/golang.org/x/tools/go/ast/inspector/inspector.go
generated
vendored
@ -36,6 +36,9 @@ package inspector
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
_ "unsafe"
|
||||
|
||||
"golang.org/x/tools/internal/astutil/edge"
|
||||
)
|
||||
|
||||
// An Inspector provides methods for inspecting
|
||||
@ -44,6 +47,24 @@ type Inspector struct {
|
||||
events []event
|
||||
}
|
||||
|
||||
//go:linkname events
|
||||
func events(in *Inspector) []event { return in.events }
|
||||
|
||||
func packEdgeKindAndIndex(ek edge.Kind, index int) int32 {
|
||||
return int32(uint32(index+1)<<7 | uint32(ek))
|
||||
}
|
||||
|
||||
// unpackEdgeKindAndIndex unpacks the edge kind and edge index (within
|
||||
// an []ast.Node slice) from the parent field of a pop event.
|
||||
//
|
||||
//go:linkname unpackEdgeKindAndIndex
|
||||
func unpackEdgeKindAndIndex(x int32) (edge.Kind, int) {
|
||||
// The "parent" field of a pop node holds the
|
||||
// edge Kind in the lower 7 bits and the index+1
|
||||
// in the upper 25.
|
||||
return edge.Kind(x & 0x7f), int(x>>7) - 1
|
||||
}
|
||||
|
||||
// New returns an Inspector for the specified syntax trees.
|
||||
func New(files []*ast.File) *Inspector {
|
||||
return &Inspector{traverse(files)}
|
||||
@ -52,9 +73,10 @@ func New(files []*ast.File) *Inspector {
|
||||
// An event represents a push or a pop
|
||||
// of an ast.Node during a traversal.
|
||||
type event struct {
|
||||
node ast.Node
|
||||
typ uint64 // typeOf(node) on push event, or union of typ strictly between push and pop events on pop events
|
||||
index int // index of corresponding push or pop event
|
||||
node ast.Node
|
||||
typ uint64 // typeOf(node) on push event, or union of typ strictly between push and pop events on pop events
|
||||
index int32 // index of corresponding push or pop event
|
||||
parent int32 // index of parent's push node (push nodes only), or packed edge kind/index (pop nodes only)
|
||||
}
|
||||
|
||||
// TODO: Experiment with storing only the second word of event.node (unsafe.Pointer).
|
||||
@ -83,7 +105,7 @@ func (in *Inspector) Preorder(types []ast.Node, f func(ast.Node)) {
|
||||
// })
|
||||
|
||||
mask := maskOf(types)
|
||||
for i := 0; i < len(in.events); {
|
||||
for i := int32(0); i < int32(len(in.events)); {
|
||||
ev := in.events[i]
|
||||
if ev.index > i {
|
||||
// push
|
||||
@ -113,7 +135,7 @@ func (in *Inspector) Preorder(types []ast.Node, f func(ast.Node)) {
|
||||
// matches an element of the types slice.
|
||||
func (in *Inspector) Nodes(types []ast.Node, f func(n ast.Node, push bool) (proceed bool)) {
|
||||
mask := maskOf(types)
|
||||
for i := 0; i < len(in.events); {
|
||||
for i := int32(0); i < int32(len(in.events)); {
|
||||
ev := in.events[i]
|
||||
if ev.index > i {
|
||||
// push
|
||||
@ -147,7 +169,7 @@ func (in *Inspector) Nodes(types []ast.Node, f func(n ast.Node, push bool) (proc
|
||||
func (in *Inspector) WithStack(types []ast.Node, f func(n ast.Node, push bool, stack []ast.Node) (proceed bool)) {
|
||||
mask := maskOf(types)
|
||||
var stack []ast.Node
|
||||
for i := 0; i < len(in.events); {
|
||||
for i := int32(0); i < int32(len(in.events)); {
|
||||
ev := in.events[i]
|
||||
if ev.index > i {
|
||||
// push
|
||||
@ -189,43 +211,74 @@ func traverse(files []*ast.File) []event {
|
||||
extent += int(f.End() - f.Pos())
|
||||
}
|
||||
// This estimate is based on the net/http package.
|
||||
capacity := extent * 33 / 100
|
||||
if capacity > 1e6 {
|
||||
capacity = 1e6 // impose some reasonable maximum
|
||||
capacity := min(extent*33/100, 1e6) // impose some reasonable maximum (1M)
|
||||
|
||||
v := &visitor{
|
||||
events: make([]event, 0, capacity),
|
||||
stack: []item{{index: -1}}, // include an extra event so file nodes have a parent
|
||||
}
|
||||
events := make([]event, 0, capacity)
|
||||
|
||||
var stack []event
|
||||
stack = append(stack, event{}) // include an extra event so file nodes have a parent
|
||||
for _, f := range files {
|
||||
ast.Inspect(f, func(n ast.Node) bool {
|
||||
if n != nil {
|
||||
// push
|
||||
ev := event{
|
||||
node: n,
|
||||
typ: 0, // temporarily used to accumulate type bits of subtree
|
||||
index: len(events), // push event temporarily holds own index
|
||||
}
|
||||
stack = append(stack, ev)
|
||||
events = append(events, ev)
|
||||
} else {
|
||||
// pop
|
||||
top := len(stack) - 1
|
||||
ev := stack[top]
|
||||
typ := typeOf(ev.node)
|
||||
push := ev.index
|
||||
parent := top - 1
|
||||
|
||||
events[push].typ = typ // set type of push
|
||||
stack[parent].typ |= typ | ev.typ // parent's typ contains push and pop's typs.
|
||||
events[push].index = len(events) // make push refer to pop
|
||||
|
||||
stack = stack[:top]
|
||||
events = append(events, ev)
|
||||
}
|
||||
return true
|
||||
})
|
||||
for _, file := range files {
|
||||
walk(v, edge.Invalid, -1, file)
|
||||
}
|
||||
|
||||
return events
|
||||
return v.events
|
||||
}
|
||||
|
||||
type visitor struct {
|
||||
events []event
|
||||
stack []item
|
||||
}
|
||||
|
||||
type item struct {
|
||||
index int32 // index of current node's push event
|
||||
parentIndex int32 // index of parent node's push event
|
||||
typAccum uint64 // accumulated type bits of current node's descendents
|
||||
edgeKindAndIndex int32 // edge.Kind and index, bit packed
|
||||
}
|
||||
|
||||
func (v *visitor) push(ek edge.Kind, eindex int, node ast.Node) {
|
||||
var (
|
||||
index = int32(len(v.events))
|
||||
parentIndex = v.stack[len(v.stack)-1].index
|
||||
)
|
||||
v.events = append(v.events, event{
|
||||
node: node,
|
||||
parent: parentIndex,
|
||||
typ: typeOf(node),
|
||||
index: 0, // (pop index is set later by visitor.pop)
|
||||
})
|
||||
v.stack = append(v.stack, item{
|
||||
index: index,
|
||||
parentIndex: parentIndex,
|
||||
edgeKindAndIndex: packEdgeKindAndIndex(ek, eindex),
|
||||
})
|
||||
|
||||
// 2B nodes ought to be enough for anyone!
|
||||
if int32(len(v.events)) < 0 {
|
||||
panic("event index exceeded int32")
|
||||
}
|
||||
|
||||
// 32M elements in an []ast.Node ought to be enough for anyone!
|
||||
if ek2, eindex2 := unpackEdgeKindAndIndex(packEdgeKindAndIndex(ek, eindex)); ek2 != ek || eindex2 != eindex {
|
||||
panic("Node slice index exceeded uint25")
|
||||
}
|
||||
}
|
||||
|
||||
func (v *visitor) pop(node ast.Node) {
|
||||
top := len(v.stack) - 1
|
||||
current := v.stack[top]
|
||||
|
||||
push := &v.events[current.index]
|
||||
parent := &v.stack[top-1]
|
||||
|
||||
push.index = int32(len(v.events)) // make push event refer to pop
|
||||
parent.typAccum |= current.typAccum | push.typ // accumulate type bits into parent
|
||||
|
||||
v.stack = v.stack[:top]
|
||||
|
||||
v.events = append(v.events, event{
|
||||
node: node,
|
||||
typ: current.typAccum,
|
||||
index: current.index,
|
||||
parent: current.edgeKindAndIndex, // see [unpackEdgeKindAndIndex]
|
||||
})
|
||||
}
|
||||
|
4
e2e/vendor/golang.org/x/tools/go/ast/inspector/iter.go
generated
vendored
4
e2e/vendor/golang.org/x/tools/go/ast/inspector/iter.go
generated
vendored
@ -26,7 +26,7 @@ func (in *Inspector) PreorderSeq(types ...ast.Node) iter.Seq[ast.Node] {
|
||||
|
||||
return func(yield func(ast.Node) bool) {
|
||||
mask := maskOf(types)
|
||||
for i := 0; i < len(in.events); {
|
||||
for i := int32(0); i < int32(len(in.events)); {
|
||||
ev := in.events[i]
|
||||
if ev.index > i {
|
||||
// push
|
||||
@ -63,7 +63,7 @@ func All[N interface {
|
||||
|
||||
mask := typeOf((N)(nil))
|
||||
return func(yield func(N) bool) {
|
||||
for i := 0; i < len(in.events); {
|
||||
for i := int32(0); i < int32(len(in.events)); {
|
||||
ev := in.events[i]
|
||||
if ev.index > i {
|
||||
// push
|
||||
|
5
e2e/vendor/golang.org/x/tools/go/ast/inspector/typeof.go
generated
vendored
5
e2e/vendor/golang.org/x/tools/go/ast/inspector/typeof.go
generated
vendored
@ -12,6 +12,8 @@ package inspector
|
||||
import (
|
||||
"go/ast"
|
||||
"math"
|
||||
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -215,8 +217,9 @@ func typeOf(n ast.Node) uint64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
//go:linkname maskOf
|
||||
func maskOf(nodes []ast.Node) uint64 {
|
||||
if nodes == nil {
|
||||
if len(nodes) == 0 {
|
||||
return math.MaxUint64 // match all node types
|
||||
}
|
||||
var mask uint64
|
||||
|
341
e2e/vendor/golang.org/x/tools/go/ast/inspector/walk.go
generated
vendored
Normal file
341
e2e/vendor/golang.org/x/tools/go/ast/inspector/walk.go
generated
vendored
Normal file
@ -0,0 +1,341 @@
|
||||
// Copyright 2025 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package inspector
|
||||
|
||||
// This file is a fork of ast.Inspect to reduce unnecessary dynamic
|
||||
// calls and to gather edge information.
|
||||
//
|
||||
// Consistency with the original is ensured by TestInspectAllNodes.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
|
||||
"golang.org/x/tools/internal/astutil/edge"
|
||||
)
|
||||
|
||||
func walkList[N ast.Node](v *visitor, ek edge.Kind, list []N) {
|
||||
for i, node := range list {
|
||||
walk(v, ek, i, node)
|
||||
}
|
||||
}
|
||||
|
||||
func walk(v *visitor, ek edge.Kind, index int, node ast.Node) {
|
||||
v.push(ek, index, node)
|
||||
|
||||
// walk children
|
||||
// (the order of the cases matches the order
|
||||
// of the corresponding node types in ast.go)
|
||||
switch n := node.(type) {
|
||||
// Comments and fields
|
||||
case *ast.Comment:
|
||||
// nothing to do
|
||||
|
||||
case *ast.CommentGroup:
|
||||
walkList(v, edge.CommentGroup_List, n.List)
|
||||
|
||||
case *ast.Field:
|
||||
if n.Doc != nil {
|
||||
walk(v, edge.Field_Doc, -1, n.Doc)
|
||||
}
|
||||
walkList(v, edge.Field_Names, n.Names)
|
||||
if n.Type != nil {
|
||||
walk(v, edge.Field_Type, -1, n.Type)
|
||||
}
|
||||
if n.Tag != nil {
|
||||
walk(v, edge.Field_Tag, -1, n.Tag)
|
||||
}
|
||||
if n.Comment != nil {
|
||||
walk(v, edge.Field_Comment, -1, n.Comment)
|
||||
}
|
||||
|
||||
case *ast.FieldList:
|
||||
walkList(v, edge.FieldList_List, n.List)
|
||||
|
||||
// Expressions
|
||||
case *ast.BadExpr, *ast.Ident, *ast.BasicLit:
|
||||
// nothing to do
|
||||
|
||||
case *ast.Ellipsis:
|
||||
if n.Elt != nil {
|
||||
walk(v, edge.Ellipsis_Elt, -1, n.Elt)
|
||||
}
|
||||
|
||||
case *ast.FuncLit:
|
||||
walk(v, edge.FuncLit_Type, -1, n.Type)
|
||||
walk(v, edge.FuncLit_Body, -1, n.Body)
|
||||
|
||||
case *ast.CompositeLit:
|
||||
if n.Type != nil {
|
||||
walk(v, edge.CompositeLit_Type, -1, n.Type)
|
||||
}
|
||||
walkList(v, edge.CompositeLit_Elts, n.Elts)
|
||||
|
||||
case *ast.ParenExpr:
|
||||
walk(v, edge.ParenExpr_X, -1, n.X)
|
||||
|
||||
case *ast.SelectorExpr:
|
||||
walk(v, edge.SelectorExpr_X, -1, n.X)
|
||||
walk(v, edge.SelectorExpr_Sel, -1, n.Sel)
|
||||
|
||||
case *ast.IndexExpr:
|
||||
walk(v, edge.IndexExpr_X, -1, n.X)
|
||||
walk(v, edge.IndexExpr_Index, -1, n.Index)
|
||||
|
||||
case *ast.IndexListExpr:
|
||||
walk(v, edge.IndexListExpr_X, -1, n.X)
|
||||
walkList(v, edge.IndexListExpr_Indices, n.Indices)
|
||||
|
||||
case *ast.SliceExpr:
|
||||
walk(v, edge.SliceExpr_X, -1, n.X)
|
||||
if n.Low != nil {
|
||||
walk(v, edge.SliceExpr_Low, -1, n.Low)
|
||||
}
|
||||
if n.High != nil {
|
||||
walk(v, edge.SliceExpr_High, -1, n.High)
|
||||
}
|
||||
if n.Max != nil {
|
||||
walk(v, edge.SliceExpr_Max, -1, n.Max)
|
||||
}
|
||||
|
||||
case *ast.TypeAssertExpr:
|
||||
walk(v, edge.TypeAssertExpr_X, -1, n.X)
|
||||
if n.Type != nil {
|
||||
walk(v, edge.TypeAssertExpr_Type, -1, n.Type)
|
||||
}
|
||||
|
||||
case *ast.CallExpr:
|
||||
walk(v, edge.CallExpr_Fun, -1, n.Fun)
|
||||
walkList(v, edge.CallExpr_Args, n.Args)
|
||||
|
||||
case *ast.StarExpr:
|
||||
walk(v, edge.StarExpr_X, -1, n.X)
|
||||
|
||||
case *ast.UnaryExpr:
|
||||
walk(v, edge.UnaryExpr_X, -1, n.X)
|
||||
|
||||
case *ast.BinaryExpr:
|
||||
walk(v, edge.BinaryExpr_X, -1, n.X)
|
||||
walk(v, edge.BinaryExpr_Y, -1, n.Y)
|
||||
|
||||
case *ast.KeyValueExpr:
|
||||
walk(v, edge.KeyValueExpr_Key, -1, n.Key)
|
||||
walk(v, edge.KeyValueExpr_Value, -1, n.Value)
|
||||
|
||||
// Types
|
||||
case *ast.ArrayType:
|
||||
if n.Len != nil {
|
||||
walk(v, edge.ArrayType_Len, -1, n.Len)
|
||||
}
|
||||
walk(v, edge.ArrayType_Elt, -1, n.Elt)
|
||||
|
||||
case *ast.StructType:
|
||||
walk(v, edge.StructType_Fields, -1, n.Fields)
|
||||
|
||||
case *ast.FuncType:
|
||||
if n.TypeParams != nil {
|
||||
walk(v, edge.FuncType_TypeParams, -1, n.TypeParams)
|
||||
}
|
||||
if n.Params != nil {
|
||||
walk(v, edge.FuncType_Params, -1, n.Params)
|
||||
}
|
||||
if n.Results != nil {
|
||||
walk(v, edge.FuncType_Results, -1, n.Results)
|
||||
}
|
||||
|
||||
case *ast.InterfaceType:
|
||||
walk(v, edge.InterfaceType_Methods, -1, n.Methods)
|
||||
|
||||
case *ast.MapType:
|
||||
walk(v, edge.MapType_Key, -1, n.Key)
|
||||
walk(v, edge.MapType_Value, -1, n.Value)
|
||||
|
||||
case *ast.ChanType:
|
||||
walk(v, edge.ChanType_Value, -1, n.Value)
|
||||
|
||||
// Statements
|
||||
case *ast.BadStmt:
|
||||
// nothing to do
|
||||
|
||||
case *ast.DeclStmt:
|
||||
walk(v, edge.DeclStmt_Decl, -1, n.Decl)
|
||||
|
||||
case *ast.EmptyStmt:
|
||||
// nothing to do
|
||||
|
||||
case *ast.LabeledStmt:
|
||||
walk(v, edge.LabeledStmt_Label, -1, n.Label)
|
||||
walk(v, edge.LabeledStmt_Stmt, -1, n.Stmt)
|
||||
|
||||
case *ast.ExprStmt:
|
||||
walk(v, edge.ExprStmt_X, -1, n.X)
|
||||
|
||||
case *ast.SendStmt:
|
||||
walk(v, edge.SendStmt_Chan, -1, n.Chan)
|
||||
walk(v, edge.SendStmt_Value, -1, n.Value)
|
||||
|
||||
case *ast.IncDecStmt:
|
||||
walk(v, edge.IncDecStmt_X, -1, n.X)
|
||||
|
||||
case *ast.AssignStmt:
|
||||
walkList(v, edge.AssignStmt_Lhs, n.Lhs)
|
||||
walkList(v, edge.AssignStmt_Rhs, n.Rhs)
|
||||
|
||||
case *ast.GoStmt:
|
||||
walk(v, edge.GoStmt_Call, -1, n.Call)
|
||||
|
||||
case *ast.DeferStmt:
|
||||
walk(v, edge.DeferStmt_Call, -1, n.Call)
|
||||
|
||||
case *ast.ReturnStmt:
|
||||
walkList(v, edge.ReturnStmt_Results, n.Results)
|
||||
|
||||
case *ast.BranchStmt:
|
||||
if n.Label != nil {
|
||||
walk(v, edge.BranchStmt_Label, -1, n.Label)
|
||||
}
|
||||
|
||||
case *ast.BlockStmt:
|
||||
walkList(v, edge.BlockStmt_List, n.List)
|
||||
|
||||
case *ast.IfStmt:
|
||||
if n.Init != nil {
|
||||
walk(v, edge.IfStmt_Init, -1, n.Init)
|
||||
}
|
||||
walk(v, edge.IfStmt_Cond, -1, n.Cond)
|
||||
walk(v, edge.IfStmt_Body, -1, n.Body)
|
||||
if n.Else != nil {
|
||||
walk(v, edge.IfStmt_Else, -1, n.Else)
|
||||
}
|
||||
|
||||
case *ast.CaseClause:
|
||||
walkList(v, edge.CaseClause_List, n.List)
|
||||
walkList(v, edge.CaseClause_Body, n.Body)
|
||||
|
||||
case *ast.SwitchStmt:
|
||||
if n.Init != nil {
|
||||
walk(v, edge.SwitchStmt_Init, -1, n.Init)
|
||||
}
|
||||
if n.Tag != nil {
|
||||
walk(v, edge.SwitchStmt_Tag, -1, n.Tag)
|
||||
}
|
||||
walk(v, edge.SwitchStmt_Body, -1, n.Body)
|
||||
|
||||
case *ast.TypeSwitchStmt:
|
||||
if n.Init != nil {
|
||||
walk(v, edge.TypeSwitchStmt_Init, -1, n.Init)
|
||||
}
|
||||
walk(v, edge.TypeSwitchStmt_Assign, -1, n.Assign)
|
||||
walk(v, edge.TypeSwitchStmt_Body, -1, n.Body)
|
||||
|
||||
case *ast.CommClause:
|
||||
if n.Comm != nil {
|
||||
walk(v, edge.CommClause_Comm, -1, n.Comm)
|
||||
}
|
||||
walkList(v, edge.CommClause_Body, n.Body)
|
||||
|
||||
case *ast.SelectStmt:
|
||||
walk(v, edge.SelectStmt_Body, -1, n.Body)
|
||||
|
||||
case *ast.ForStmt:
|
||||
if n.Init != nil {
|
||||
walk(v, edge.ForStmt_Init, -1, n.Init)
|
||||
}
|
||||
if n.Cond != nil {
|
||||
walk(v, edge.ForStmt_Cond, -1, n.Cond)
|
||||
}
|
||||
if n.Post != nil {
|
||||
walk(v, edge.ForStmt_Post, -1, n.Post)
|
||||
}
|
||||
walk(v, edge.ForStmt_Body, -1, n.Body)
|
||||
|
||||
case *ast.RangeStmt:
|
||||
if n.Key != nil {
|
||||
walk(v, edge.RangeStmt_Key, -1, n.Key)
|
||||
}
|
||||
if n.Value != nil {
|
||||
walk(v, edge.RangeStmt_Value, -1, n.Value)
|
||||
}
|
||||
walk(v, edge.RangeStmt_X, -1, n.X)
|
||||
walk(v, edge.RangeStmt_Body, -1, n.Body)
|
||||
|
||||
// Declarations
|
||||
case *ast.ImportSpec:
|
||||
if n.Doc != nil {
|
||||
walk(v, edge.ImportSpec_Doc, -1, n.Doc)
|
||||
}
|
||||
if n.Name != nil {
|
||||
walk(v, edge.ImportSpec_Name, -1, n.Name)
|
||||
}
|
||||
walk(v, edge.ImportSpec_Path, -1, n.Path)
|
||||
if n.Comment != nil {
|
||||
walk(v, edge.ImportSpec_Comment, -1, n.Comment)
|
||||
}
|
||||
|
||||
case *ast.ValueSpec:
|
||||
if n.Doc != nil {
|
||||
walk(v, edge.ValueSpec_Doc, -1, n.Doc)
|
||||
}
|
||||
walkList(v, edge.ValueSpec_Names, n.Names)
|
||||
if n.Type != nil {
|
||||
walk(v, edge.ValueSpec_Type, -1, n.Type)
|
||||
}
|
||||
walkList(v, edge.ValueSpec_Values, n.Values)
|
||||
if n.Comment != nil {
|
||||
walk(v, edge.ValueSpec_Comment, -1, n.Comment)
|
||||
}
|
||||
|
||||
case *ast.TypeSpec:
|
||||
if n.Doc != nil {
|
||||
walk(v, edge.TypeSpec_Doc, -1, n.Doc)
|
||||
}
|
||||
walk(v, edge.TypeSpec_Name, -1, n.Name)
|
||||
if n.TypeParams != nil {
|
||||
walk(v, edge.TypeSpec_TypeParams, -1, n.TypeParams)
|
||||
}
|
||||
walk(v, edge.TypeSpec_Type, -1, n.Type)
|
||||
if n.Comment != nil {
|
||||
walk(v, edge.TypeSpec_Comment, -1, n.Comment)
|
||||
}
|
||||
|
||||
case *ast.BadDecl:
|
||||
// nothing to do
|
||||
|
||||
case *ast.GenDecl:
|
||||
if n.Doc != nil {
|
||||
walk(v, edge.GenDecl_Doc, -1, n.Doc)
|
||||
}
|
||||
walkList(v, edge.GenDecl_Specs, n.Specs)
|
||||
|
||||
case *ast.FuncDecl:
|
||||
if n.Doc != nil {
|
||||
walk(v, edge.FuncDecl_Doc, -1, n.Doc)
|
||||
}
|
||||
if n.Recv != nil {
|
||||
walk(v, edge.FuncDecl_Recv, -1, n.Recv)
|
||||
}
|
||||
walk(v, edge.FuncDecl_Name, -1, n.Name)
|
||||
walk(v, edge.FuncDecl_Type, -1, n.Type)
|
||||
if n.Body != nil {
|
||||
walk(v, edge.FuncDecl_Body, -1, n.Body)
|
||||
}
|
||||
|
||||
case *ast.File:
|
||||
if n.Doc != nil {
|
||||
walk(v, edge.File_Doc, -1, n.Doc)
|
||||
}
|
||||
walk(v, edge.File_Name, -1, n.Name)
|
||||
walkList(v, edge.File_Decls, n.Decls)
|
||||
// don't walk n.Comments - they have been
|
||||
// visited already through the individual
|
||||
// nodes
|
||||
|
||||
default:
|
||||
// (includes *ast.Package)
|
||||
panic(fmt.Sprintf("Walk: unexpected node type %T", n))
|
||||
}
|
||||
|
||||
v.pop(node)
|
||||
}
|
295
e2e/vendor/golang.org/x/tools/internal/astutil/edge/edge.go
generated
vendored
Normal file
295
e2e/vendor/golang.org/x/tools/internal/astutil/edge/edge.go
generated
vendored
Normal file
@ -0,0 +1,295 @@
|
||||
// Copyright 2025 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package edge defines identifiers for each field of an ast.Node
|
||||
// struct type that refers to another Node.
|
||||
package edge
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// A Kind describes a field of an ast.Node struct.
|
||||
type Kind uint8
|
||||
|
||||
// String returns a description of the edge kind.
|
||||
func (k Kind) String() string {
|
||||
if k == Invalid {
|
||||
return "<invalid>"
|
||||
}
|
||||
info := fieldInfos[k]
|
||||
return fmt.Sprintf("%v.%s", info.nodeType.Elem().Name(), info.name)
|
||||
}
|
||||
|
||||
// NodeType returns the pointer-to-struct type of the ast.Node implementation.
|
||||
func (k Kind) NodeType() reflect.Type { return fieldInfos[k].nodeType }
|
||||
|
||||
// FieldName returns the name of the field.
|
||||
func (k Kind) FieldName() string { return fieldInfos[k].name }
|
||||
|
||||
// FieldType returns the declared type of the field.
|
||||
func (k Kind) FieldType() reflect.Type { return fieldInfos[k].fieldType }
|
||||
|
||||
// Get returns the direct child of n identified by (k, idx).
|
||||
// n's type must match k.NodeType().
|
||||
// idx must be a valid slice index, or -1 for a non-slice.
|
||||
func (k Kind) Get(n ast.Node, idx int) ast.Node {
|
||||
if k.NodeType() != reflect.TypeOf(n) {
|
||||
panic(fmt.Sprintf("%v.Get(%T): invalid node type", k, n))
|
||||
}
|
||||
v := reflect.ValueOf(n).Elem().Field(fieldInfos[k].index)
|
||||
if idx != -1 {
|
||||
v = v.Index(idx) // asserts valid index
|
||||
} else {
|
||||
// (The type assertion below asserts that v is not a slice.)
|
||||
}
|
||||
return v.Interface().(ast.Node) // may be nil
|
||||
}
|
||||
|
||||
const (
|
||||
Invalid Kind = iota // for nodes at the root of the traversal
|
||||
|
||||
// Kinds are sorted alphabetically.
|
||||
// Numbering is not stable.
|
||||
// Each is named Type_Field, where Type is the
|
||||
// ast.Node struct type and Field is the name of the field
|
||||
|
||||
ArrayType_Elt
|
||||
ArrayType_Len
|
||||
AssignStmt_Lhs
|
||||
AssignStmt_Rhs
|
||||
BinaryExpr_X
|
||||
BinaryExpr_Y
|
||||
BlockStmt_List
|
||||
BranchStmt_Label
|
||||
CallExpr_Args
|
||||
CallExpr_Fun
|
||||
CaseClause_Body
|
||||
CaseClause_List
|
||||
ChanType_Value
|
||||
CommClause_Body
|
||||
CommClause_Comm
|
||||
CommentGroup_List
|
||||
CompositeLit_Elts
|
||||
CompositeLit_Type
|
||||
DeclStmt_Decl
|
||||
DeferStmt_Call
|
||||
Ellipsis_Elt
|
||||
ExprStmt_X
|
||||
FieldList_List
|
||||
Field_Comment
|
||||
Field_Doc
|
||||
Field_Names
|
||||
Field_Tag
|
||||
Field_Type
|
||||
File_Decls
|
||||
File_Doc
|
||||
File_Name
|
||||
ForStmt_Body
|
||||
ForStmt_Cond
|
||||
ForStmt_Init
|
||||
ForStmt_Post
|
||||
FuncDecl_Body
|
||||
FuncDecl_Doc
|
||||
FuncDecl_Name
|
||||
FuncDecl_Recv
|
||||
FuncDecl_Type
|
||||
FuncLit_Body
|
||||
FuncLit_Type
|
||||
FuncType_Params
|
||||
FuncType_Results
|
||||
FuncType_TypeParams
|
||||
GenDecl_Doc
|
||||
GenDecl_Specs
|
||||
GoStmt_Call
|
||||
IfStmt_Body
|
||||
IfStmt_Cond
|
||||
IfStmt_Else
|
||||
IfStmt_Init
|
||||
ImportSpec_Comment
|
||||
ImportSpec_Doc
|
||||
ImportSpec_Name
|
||||
ImportSpec_Path
|
||||
IncDecStmt_X
|
||||
IndexExpr_Index
|
||||
IndexExpr_X
|
||||
IndexListExpr_Indices
|
||||
IndexListExpr_X
|
||||
InterfaceType_Methods
|
||||
KeyValueExpr_Key
|
||||
KeyValueExpr_Value
|
||||
LabeledStmt_Label
|
||||
LabeledStmt_Stmt
|
||||
MapType_Key
|
||||
MapType_Value
|
||||
ParenExpr_X
|
||||
RangeStmt_Body
|
||||
RangeStmt_Key
|
||||
RangeStmt_Value
|
||||
RangeStmt_X
|
||||
ReturnStmt_Results
|
||||
SelectStmt_Body
|
||||
SelectorExpr_Sel
|
||||
SelectorExpr_X
|
||||
SendStmt_Chan
|
||||
SendStmt_Value
|
||||
SliceExpr_High
|
||||
SliceExpr_Low
|
||||
SliceExpr_Max
|
||||
SliceExpr_X
|
||||
StarExpr_X
|
||||
StructType_Fields
|
||||
SwitchStmt_Body
|
||||
SwitchStmt_Init
|
||||
SwitchStmt_Tag
|
||||
TypeAssertExpr_Type
|
||||
TypeAssertExpr_X
|
||||
TypeSpec_Comment
|
||||
TypeSpec_Doc
|
||||
TypeSpec_Name
|
||||
TypeSpec_Type
|
||||
TypeSpec_TypeParams
|
||||
TypeSwitchStmt_Assign
|
||||
TypeSwitchStmt_Body
|
||||
TypeSwitchStmt_Init
|
||||
UnaryExpr_X
|
||||
ValueSpec_Comment
|
||||
ValueSpec_Doc
|
||||
ValueSpec_Names
|
||||
ValueSpec_Type
|
||||
ValueSpec_Values
|
||||
|
||||
maxKind
|
||||
)
|
||||
|
||||
// Assert that the encoding fits in 7 bits,
|
||||
// as the inspector relies on this.
|
||||
// (We are currently at 104.)
|
||||
var _ = [1 << 7]struct{}{}[maxKind]
|
||||
|
||||
type fieldInfo struct {
|
||||
nodeType reflect.Type // pointer-to-struct type of ast.Node implementation
|
||||
name string
|
||||
index int
|
||||
fieldType reflect.Type
|
||||
}
|
||||
|
||||
func info[N ast.Node](fieldName string) fieldInfo {
|
||||
nodePtrType := reflect.TypeFor[N]()
|
||||
f, ok := nodePtrType.Elem().FieldByName(fieldName)
|
||||
if !ok {
|
||||
panic(fieldName)
|
||||
}
|
||||
return fieldInfo{nodePtrType, fieldName, f.Index[0], f.Type}
|
||||
}
|
||||
|
||||
var fieldInfos = [...]fieldInfo{
|
||||
Invalid: {},
|
||||
ArrayType_Elt: info[*ast.ArrayType]("Elt"),
|
||||
ArrayType_Len: info[*ast.ArrayType]("Len"),
|
||||
AssignStmt_Lhs: info[*ast.AssignStmt]("Lhs"),
|
||||
AssignStmt_Rhs: info[*ast.AssignStmt]("Rhs"),
|
||||
BinaryExpr_X: info[*ast.BinaryExpr]("X"),
|
||||
BinaryExpr_Y: info[*ast.BinaryExpr]("Y"),
|
||||
BlockStmt_List: info[*ast.BlockStmt]("List"),
|
||||
BranchStmt_Label: info[*ast.BranchStmt]("Label"),
|
||||
CallExpr_Args: info[*ast.CallExpr]("Args"),
|
||||
CallExpr_Fun: info[*ast.CallExpr]("Fun"),
|
||||
CaseClause_Body: info[*ast.CaseClause]("Body"),
|
||||
CaseClause_List: info[*ast.CaseClause]("List"),
|
||||
ChanType_Value: info[*ast.ChanType]("Value"),
|
||||
CommClause_Body: info[*ast.CommClause]("Body"),
|
||||
CommClause_Comm: info[*ast.CommClause]("Comm"),
|
||||
CommentGroup_List: info[*ast.CommentGroup]("List"),
|
||||
CompositeLit_Elts: info[*ast.CompositeLit]("Elts"),
|
||||
CompositeLit_Type: info[*ast.CompositeLit]("Type"),
|
||||
DeclStmt_Decl: info[*ast.DeclStmt]("Decl"),
|
||||
DeferStmt_Call: info[*ast.DeferStmt]("Call"),
|
||||
Ellipsis_Elt: info[*ast.Ellipsis]("Elt"),
|
||||
ExprStmt_X: info[*ast.ExprStmt]("X"),
|
||||
FieldList_List: info[*ast.FieldList]("List"),
|
||||
Field_Comment: info[*ast.Field]("Comment"),
|
||||
Field_Doc: info[*ast.Field]("Doc"),
|
||||
Field_Names: info[*ast.Field]("Names"),
|
||||
Field_Tag: info[*ast.Field]("Tag"),
|
||||
Field_Type: info[*ast.Field]("Type"),
|
||||
File_Decls: info[*ast.File]("Decls"),
|
||||
File_Doc: info[*ast.File]("Doc"),
|
||||
File_Name: info[*ast.File]("Name"),
|
||||
ForStmt_Body: info[*ast.ForStmt]("Body"),
|
||||
ForStmt_Cond: info[*ast.ForStmt]("Cond"),
|
||||
ForStmt_Init: info[*ast.ForStmt]("Init"),
|
||||
ForStmt_Post: info[*ast.ForStmt]("Post"),
|
||||
FuncDecl_Body: info[*ast.FuncDecl]("Body"),
|
||||
FuncDecl_Doc: info[*ast.FuncDecl]("Doc"),
|
||||
FuncDecl_Name: info[*ast.FuncDecl]("Name"),
|
||||
FuncDecl_Recv: info[*ast.FuncDecl]("Recv"),
|
||||
FuncDecl_Type: info[*ast.FuncDecl]("Type"),
|
||||
FuncLit_Body: info[*ast.FuncLit]("Body"),
|
||||
FuncLit_Type: info[*ast.FuncLit]("Type"),
|
||||
FuncType_Params: info[*ast.FuncType]("Params"),
|
||||
FuncType_Results: info[*ast.FuncType]("Results"),
|
||||
FuncType_TypeParams: info[*ast.FuncType]("TypeParams"),
|
||||
GenDecl_Doc: info[*ast.GenDecl]("Doc"),
|
||||
GenDecl_Specs: info[*ast.GenDecl]("Specs"),
|
||||
GoStmt_Call: info[*ast.GoStmt]("Call"),
|
||||
IfStmt_Body: info[*ast.IfStmt]("Body"),
|
||||
IfStmt_Cond: info[*ast.IfStmt]("Cond"),
|
||||
IfStmt_Else: info[*ast.IfStmt]("Else"),
|
||||
IfStmt_Init: info[*ast.IfStmt]("Init"),
|
||||
ImportSpec_Comment: info[*ast.ImportSpec]("Comment"),
|
||||
ImportSpec_Doc: info[*ast.ImportSpec]("Doc"),
|
||||
ImportSpec_Name: info[*ast.ImportSpec]("Name"),
|
||||
ImportSpec_Path: info[*ast.ImportSpec]("Path"),
|
||||
IncDecStmt_X: info[*ast.IncDecStmt]("X"),
|
||||
IndexExpr_Index: info[*ast.IndexExpr]("Index"),
|
||||
IndexExpr_X: info[*ast.IndexExpr]("X"),
|
||||
IndexListExpr_Indices: info[*ast.IndexListExpr]("Indices"),
|
||||
IndexListExpr_X: info[*ast.IndexListExpr]("X"),
|
||||
InterfaceType_Methods: info[*ast.InterfaceType]("Methods"),
|
||||
KeyValueExpr_Key: info[*ast.KeyValueExpr]("Key"),
|
||||
KeyValueExpr_Value: info[*ast.KeyValueExpr]("Value"),
|
||||
LabeledStmt_Label: info[*ast.LabeledStmt]("Label"),
|
||||
LabeledStmt_Stmt: info[*ast.LabeledStmt]("Stmt"),
|
||||
MapType_Key: info[*ast.MapType]("Key"),
|
||||
MapType_Value: info[*ast.MapType]("Value"),
|
||||
ParenExpr_X: info[*ast.ParenExpr]("X"),
|
||||
RangeStmt_Body: info[*ast.RangeStmt]("Body"),
|
||||
RangeStmt_Key: info[*ast.RangeStmt]("Key"),
|
||||
RangeStmt_Value: info[*ast.RangeStmt]("Value"),
|
||||
RangeStmt_X: info[*ast.RangeStmt]("X"),
|
||||
ReturnStmt_Results: info[*ast.ReturnStmt]("Results"),
|
||||
SelectStmt_Body: info[*ast.SelectStmt]("Body"),
|
||||
SelectorExpr_Sel: info[*ast.SelectorExpr]("Sel"),
|
||||
SelectorExpr_X: info[*ast.SelectorExpr]("X"),
|
||||
SendStmt_Chan: info[*ast.SendStmt]("Chan"),
|
||||
SendStmt_Value: info[*ast.SendStmt]("Value"),
|
||||
SliceExpr_High: info[*ast.SliceExpr]("High"),
|
||||
SliceExpr_Low: info[*ast.SliceExpr]("Low"),
|
||||
SliceExpr_Max: info[*ast.SliceExpr]("Max"),
|
||||
SliceExpr_X: info[*ast.SliceExpr]("X"),
|
||||
StarExpr_X: info[*ast.StarExpr]("X"),
|
||||
StructType_Fields: info[*ast.StructType]("Fields"),
|
||||
SwitchStmt_Body: info[*ast.SwitchStmt]("Body"),
|
||||
SwitchStmt_Init: info[*ast.SwitchStmt]("Init"),
|
||||
SwitchStmt_Tag: info[*ast.SwitchStmt]("Tag"),
|
||||
TypeAssertExpr_Type: info[*ast.TypeAssertExpr]("Type"),
|
||||
TypeAssertExpr_X: info[*ast.TypeAssertExpr]("X"),
|
||||
TypeSpec_Comment: info[*ast.TypeSpec]("Comment"),
|
||||
TypeSpec_Doc: info[*ast.TypeSpec]("Doc"),
|
||||
TypeSpec_Name: info[*ast.TypeSpec]("Name"),
|
||||
TypeSpec_Type: info[*ast.TypeSpec]("Type"),
|
||||
TypeSpec_TypeParams: info[*ast.TypeSpec]("TypeParams"),
|
||||
TypeSwitchStmt_Assign: info[*ast.TypeSwitchStmt]("Assign"),
|
||||
TypeSwitchStmt_Body: info[*ast.TypeSwitchStmt]("Body"),
|
||||
TypeSwitchStmt_Init: info[*ast.TypeSwitchStmt]("Init"),
|
||||
UnaryExpr_X: info[*ast.UnaryExpr]("X"),
|
||||
ValueSpec_Comment: info[*ast.ValueSpec]("Comment"),
|
||||
ValueSpec_Doc: info[*ast.ValueSpec]("Doc"),
|
||||
ValueSpec_Names: info[*ast.ValueSpec]("Names"),
|
||||
ValueSpec_Type: info[*ast.ValueSpec]("Type"),
|
||||
ValueSpec_Values: info[*ast.ValueSpec]("Values"),
|
||||
}
|
Reference in New Issue
Block a user