From 4165372ec8fd142475a4e35fd0cf4f8042132208 Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Wed, 22 Feb 2023 22:16:50 +0100 Subject: dependencies: update set go min requirements to 1.19 update dependencies update vendor --- .../go-ruleguard/internal/xtypes/xtypes.go | 16 +- .../quasilyte/go-ruleguard/ruleguard/engine.go | 1 + .../quasilyte/go-ruleguard/ruleguard/filters.go | 99 ++++--- .../go-ruleguard/ruleguard/ir/filter_op.gen.go | 224 +++++++-------- .../go-ruleguard/ruleguard/ir/gen_filter_op.go | 1 + .../quasilyte/go-ruleguard/ruleguard/ir_loader.go | 2 + .../go-ruleguard/ruleguard/irconv/irconv.go | 2 + .../quasilyte/go-ruleguard/ruleguard/match_data.go | 35 +-- .../quasilyte/go-ruleguard/ruleguard/nodepath.go | 10 +- .../quasilyte/go-ruleguard/ruleguard/ruleguard.go | 32 +++ .../quasilyte/go-ruleguard/ruleguard/runner.go | 68 +++-- .../go-ruleguard/ruleguard/typematch/typematch.go | 11 +- .../quasilyte/go-ruleguard/ruleguard/utils.go | 7 + vendor/github.com/quasilyte/gogrep/Makefile | 4 +- vendor/github.com/quasilyte/gogrep/README.md | 2 +- vendor/github.com/quasilyte/gogrep/compile.go | 148 ++++++++-- .../github.com/quasilyte/gogrep/gen_operations.go | 11 +- vendor/github.com/quasilyte/gogrep/go.mod | 8 - vendor/github.com/quasilyte/gogrep/go.sum | 8 - vendor/github.com/quasilyte/gogrep/gogrep.go | 63 +++-- vendor/github.com/quasilyte/gogrep/match.go | 211 +++++++++----- .../github.com/quasilyte/gogrep/nodetag/nodetag.go | 7 + .../quasilyte/gogrep/operation_string.go | 216 +++++++------- .../github.com/quasilyte/gogrep/operations.gen.go | 309 ++++++++++++++------- vendor/github.com/quasilyte/gogrep/parse.go | 22 +- vendor/github.com/quasilyte/gogrep/slices.go | 180 +++++++++--- vendor/github.com/quasilyte/regex/syntax/go.mod | 3 - vendor/github.com/quasilyte/regex/syntax/parser.go | 4 +- vendor/github.com/quasilyte/stdinfo/go.mod | 3 - 29 files changed, 1099 insertions(+), 608 deletions(-) delete mode 100644 vendor/github.com/quasilyte/gogrep/go.mod delete mode 100644 vendor/github.com/quasilyte/gogrep/go.sum delete mode 100644 vendor/github.com/quasilyte/regex/syntax/go.mod delete mode 100644 vendor/github.com/quasilyte/stdinfo/go.mod (limited to 'vendor/github.com/quasilyte') diff --git a/vendor/github.com/quasilyte/go-ruleguard/internal/xtypes/xtypes.go b/vendor/github.com/quasilyte/go-ruleguard/internal/xtypes/xtypes.go index 028a5f141..4c5c2a2ab 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/internal/xtypes/xtypes.go +++ b/vendor/github.com/quasilyte/go-ruleguard/internal/xtypes/xtypes.go @@ -2,6 +2,8 @@ package xtypes import ( "go/types" + + "golang.org/x/exp/typeparams" ) // Implements reports whether type v implements iface. @@ -63,9 +65,6 @@ func typeIdentical(x, y types.Type, p *ifacePair) bool { } switch x := x.(type) { - case nil: - return false - case *types.Basic: // Basic types are singletons except for the rune and byte // aliases, thus we cannot solely rely on the x == y check @@ -142,6 +141,11 @@ func typeIdentical(x, y types.Type, p *ifacePair) bool { typeIdentical(x.Results(), y.Results(), p) } + case *typeparams.Union: + // TODO(quasilyte): do we want to match generic union types too? + // It would require copying a lot of code from the go/types. + return false + case *types.Interface: // Two interface types are identical if they have the same set of methods with // the same names and identical function types. Lower-case method names from @@ -214,6 +218,12 @@ func typeIdentical(x, y types.Type, p *ifacePair) bool { } return sameID(x.Obj(), y.Obj().Pkg(), y.Obj().Name()) + case *typeparams.TypeParam: + // nothing to do (x and y being equal is caught in the very beginning of this function) + + case nil: + // avoid a crash in case of nil type + default: panic("unreachable") } diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/engine.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/engine.go index a5e6ca4d6..88feef92d 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/engine.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/engine.go @@ -131,6 +131,7 @@ func (e *engine) Run(ctx *RunContext, buildContext *build.Context, f *ast.File) } // engineState is a shared state inside the engine. +// Its access is synchronized, unlike the RunnerState which should be thread-local. type engineState struct { env *quasigo.Env diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/filters.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/filters.go index 604ae4a18..7320ab7fb 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/filters.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/filters.go @@ -23,9 +23,16 @@ func filterFailure(reason string) matchFilterResult { return matchFilterResult(reason) } -func exprListFilterApply(src string, list gogrep.ExprSlice, fn func(ast.Expr) bool) matchFilterResult { - for i := 0; i < list.Len(); i++ { - if !fn(list.At(i).(ast.Expr)) { +func asExprSlice(x ast.Node) *gogrep.NodeSlice { + if x, ok := x.(*gogrep.NodeSlice); ok && x.Kind == gogrep.ExprNodeSlice { + return x + } + return nil +} + +func exprListFilterApply(src string, list []ast.Expr, fn func(ast.Expr) bool) matchFilterResult { + for _, e := range list { + if !fn(e) { return filterFailure(src) } } @@ -99,12 +106,11 @@ func makeFileNameMatchesFilter(src string, re textmatch.Pattern) filterFunc { func makePureFilter(src, varname string) filterFunc { return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { return isPure(params.ctx.Types, x) }) } - n := params.subExpr(varname) if isPure(params.ctx.Types, n) { return filterSuccess @@ -115,8 +121,8 @@ func makePureFilter(src, varname string) filterFunc { func makeConstFilter(src, varname string) filterFunc { return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { return isConstant(params.ctx.Types, x) }) } @@ -131,8 +137,8 @@ func makeConstFilter(src, varname string) filterFunc { func makeConstSliceFilter(src, varname string) filterFunc { return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { return isConstantSlice(params.ctx.Types, x) }) } @@ -147,8 +153,8 @@ func makeConstSliceFilter(src, varname string) filterFunc { func makeAddressableFilter(src, varname string) filterFunc { return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { return isAddressable(params.ctx.Types, x) }) } @@ -163,8 +169,8 @@ func makeAddressableFilter(src, varname string) filterFunc { func makeComparableFilter(src, varname string) filterFunc { return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { return types.Comparable(params.typeofNode(x)) }) } @@ -212,8 +218,8 @@ func makeCustomVarFilter(src, varname string, fn *quasigo.Func) filterFunc { func makeTypeImplementsFilter(src, varname string, iface *types.Interface) filterFunc { return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { return xtypes.Implements(params.typeofNode(x), iface) }) } @@ -322,8 +328,8 @@ func makeRootSinkTypeIsFilter(src string, pat *typematch.Pattern) filterFunc { func makeTypeIsFilter(src, varname string, underlying bool, pat *typematch.Pattern) filterFunc { if underlying { return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { return pat.MatchIdentical(params.typematchState, params.typeofNode(x).Underlying()) }) } @@ -336,8 +342,8 @@ func makeTypeIsFilter(src, varname string, underlying bool, pat *typematch.Patte } return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { return pat.MatchIdentical(params.typematchState, params.typeofNode(x)) }) } @@ -351,8 +357,8 @@ func makeTypeIsFilter(src, varname string, underlying bool, pat *typematch.Patte func makeTypeConvertibleToFilter(src, varname string, dstType types.Type) filterFunc { return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { return types.ConvertibleTo(params.typeofNode(x), dstType) }) } @@ -367,8 +373,8 @@ func makeTypeConvertibleToFilter(src, varname string, dstType types.Type) filter func makeTypeAssignableToFilter(src, varname string, dstType types.Type) filterFunc { return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { return types.AssignableTo(params.typeofNode(x), dstType) }) } @@ -395,6 +401,28 @@ func makeLineFilter(src, varname string, op token.Token, rhsVarname string) filt } } +func makeObjectIsVariadicParamFilter(src, varname string) filterFunc { + return func(params *filterParams) matchFilterResult { + if params.currentFunc == nil { + return filterFailure(src) + } + funcObj, ok := params.ctx.Types.ObjectOf(params.currentFunc.Name).(*types.Func) + if !ok { + return filterFailure(src) + } + funcSig := funcObj.Type().(*types.Signature) + if !funcSig.Variadic() { + return filterFailure(src) + } + paramObj := funcSig.Params().At(funcSig.Params().Len() - 1) + obj := params.ctx.Types.ObjectOf(identOf(params.subExpr(varname))) + if paramObj != obj { + return filterFailure(src) + } + return filterSuccess + } +} + func makeObjectIsGlobalFilter(src, varname string) filterFunc { return func(params *filterParams) matchFilterResult { obj := params.ctx.Types.ObjectOf(identOf(params.subExpr(varname))) @@ -433,15 +461,21 @@ func makeLineConstFilter(src, varname string, op token.Token, rhsValue constant. func makeTypeSizeConstFilter(src, varname string, op token.Token, rhsValue constant.Value) filterFunc { return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { typ := params.typeofNode(x) + if isTypeParam(typ) { + return false + } lhsValue := constant.MakeInt64(params.ctx.Sizes.Sizeof(typ)) return constant.Compare(lhsValue, op, rhsValue) }) } typ := params.typeofNode(params.subExpr(varname)) + if isTypeParam(typ) { + return filterFailure(src) + } lhsValue := constant.MakeInt64(params.ctx.Sizes.Sizeof(typ)) if constant.Compare(lhsValue, op, rhsValue) { return filterSuccess @@ -453,8 +487,11 @@ func makeTypeSizeConstFilter(src, varname string, op token.Token, rhsValue const func makeTypeSizeFilter(src, varname string, op token.Token, rhsVarname string) filterFunc { return func(params *filterParams) matchFilterResult { lhsTyp := params.typeofNode(params.subExpr(varname)) - lhsValue := constant.MakeInt64(params.ctx.Sizes.Sizeof(lhsTyp)) rhsTyp := params.typeofNode(params.subExpr(rhsVarname)) + if isTypeParam(lhsTyp) || isTypeParam(rhsTyp) { + return filterFailure(src) + } + lhsValue := constant.MakeInt64(params.ctx.Sizes.Sizeof(lhsTyp)) rhsValue := constant.MakeInt64(params.ctx.Sizes.Sizeof(rhsTyp)) if constant.Compare(lhsValue, op, rhsValue) { return filterSuccess @@ -465,8 +502,8 @@ func makeTypeSizeFilter(src, varname string, op token.Token, rhsVarname string) func makeValueIntConstFilter(src, varname string, op token.Token, rhsValue constant.Value) filterFunc { return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { lhsValue := intValueOf(params.ctx.Types, x) return lhsValue != nil && constant.Compare(lhsValue, op, rhsValue) }) @@ -606,8 +643,8 @@ func makeObjectIsFilter(src, varname, objectName string) filterFunc { } return func(params *filterParams) matchFilterResult { - if list, ok := params.subNode(varname).(gogrep.ExprSlice); ok { - return exprListFilterApply(src, list, func(x ast.Expr) bool { + if list := asExprSlice(params.subNode(varname)); list != nil { + return exprListFilterApply(src, list.GetExprSlice(), func(x ast.Expr) bool { ident := identOf(x) return ident != nil && predicate(params.ctx.Types.ObjectOf(ident)) }) diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir/filter_op.gen.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir/filter_op.gen.go index c9401c020..bc2a5ee5b 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir/filter_op.gen.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir/filter_op.gen.go @@ -88,189 +88,195 @@ const ( // $Value type: string FilterVarObjectIsGlobalOp FilterOp = 23 + // m[$Value].Object.IsVariadicParam() + // $Value type: string + FilterVarObjectIsVariadicParamOp FilterOp = 24 + // m[$Value].Type.Is($Args[0]) // $Value type: string - FilterVarTypeIsOp FilterOp = 24 + FilterVarTypeIsOp FilterOp = 25 // m[$Value].Type.IdenticalTo($Args[0]) // $Value type: string - FilterVarTypeIdenticalToOp FilterOp = 25 + FilterVarTypeIdenticalToOp FilterOp = 26 // m[$Value].Type.Underlying().Is($Args[0]) // $Value type: string - FilterVarTypeUnderlyingIsOp FilterOp = 26 + FilterVarTypeUnderlyingIsOp FilterOp = 27 // m[$Value].Type.OfKind($Args[0]) // $Value type: string - FilterVarTypeOfKindOp FilterOp = 27 + FilterVarTypeOfKindOp FilterOp = 28 // m[$Value].Type.Underlying().OfKind($Args[0]) // $Value type: string - FilterVarTypeUnderlyingOfKindOp FilterOp = 28 + FilterVarTypeUnderlyingOfKindOp FilterOp = 29 // m[$Value].Type.ConvertibleTo($Args[0]) // $Value type: string - FilterVarTypeConvertibleToOp FilterOp = 29 + FilterVarTypeConvertibleToOp FilterOp = 30 // m[$Value].Type.AssignableTo($Args[0]) // $Value type: string - FilterVarTypeAssignableToOp FilterOp = 30 + FilterVarTypeAssignableToOp FilterOp = 31 // m[$Value].Type.Implements($Args[0]) // $Value type: string - FilterVarTypeImplementsOp FilterOp = 31 + FilterVarTypeImplementsOp FilterOp = 32 // m[$Value].Type.HasMethod($Args[0]) // $Value type: string - FilterVarTypeHasMethodOp FilterOp = 32 + FilterVarTypeHasMethodOp FilterOp = 33 // m[$Value].Text.Matches($Args[0]) // $Value type: string - FilterVarTextMatchesOp FilterOp = 33 + FilterVarTextMatchesOp FilterOp = 34 // m[$Value].Contains($Args[0]) // $Value type: string - FilterVarContainsOp FilterOp = 34 + FilterVarContainsOp FilterOp = 35 // m.Deadcode() - FilterDeadcodeOp FilterOp = 35 + FilterDeadcodeOp FilterOp = 36 // m.GoVersion().Eq($Value) // $Value type: string - FilterGoVersionEqOp FilterOp = 36 + FilterGoVersionEqOp FilterOp = 37 // m.GoVersion().LessThan($Value) // $Value type: string - FilterGoVersionLessThanOp FilterOp = 37 + FilterGoVersionLessThanOp FilterOp = 38 // m.GoVersion().GreaterThan($Value) // $Value type: string - FilterGoVersionGreaterThanOp FilterOp = 38 + FilterGoVersionGreaterThanOp FilterOp = 39 // m.GoVersion().LessEqThan($Value) // $Value type: string - FilterGoVersionLessEqThanOp FilterOp = 39 + FilterGoVersionLessEqThanOp FilterOp = 40 // m.GoVersion().GreaterEqThan($Value) // $Value type: string - FilterGoVersionGreaterEqThanOp FilterOp = 40 + FilterGoVersionGreaterEqThanOp FilterOp = 41 // m.File.Imports($Value) // $Value type: string - FilterFileImportsOp FilterOp = 41 + FilterFileImportsOp FilterOp = 42 // m.File.PkgPath.Matches($Value) // $Value type: string - FilterFilePkgPathMatchesOp FilterOp = 42 + FilterFilePkgPathMatchesOp FilterOp = 43 // m.File.Name.Matches($Value) // $Value type: string - FilterFileNameMatchesOp FilterOp = 43 + FilterFileNameMatchesOp FilterOp = 44 // $Value holds a function name // $Value type: string - FilterFilterFuncRefOp FilterOp = 44 + FilterFilterFuncRefOp FilterOp = 45 // $Value holds a string constant // $Value type: string - FilterStringOp FilterOp = 45 + FilterStringOp FilterOp = 46 // $Value holds an int64 constant // $Value type: int64 - FilterIntOp FilterOp = 46 + FilterIntOp FilterOp = 47 // m[`$$`].Node.Parent().Is($Args[0]) - FilterRootNodeParentIsOp FilterOp = 47 + FilterRootNodeParentIsOp FilterOp = 48 // m[`$$`].SinkType.Is($Args[0]) - FilterRootSinkTypeIsOp FilterOp = 48 + FilterRootSinkTypeIsOp FilterOp = 49 ) var filterOpNames = map[FilterOp]string{ - FilterInvalidOp: `Invalid`, - FilterNotOp: `Not`, - FilterAndOp: `And`, - FilterOrOp: `Or`, - FilterEqOp: `Eq`, - FilterNeqOp: `Neq`, - FilterGtOp: `Gt`, - FilterLtOp: `Lt`, - FilterGtEqOp: `GtEq`, - FilterLtEqOp: `LtEq`, - FilterVarAddressableOp: `VarAddressable`, - FilterVarComparableOp: `VarComparable`, - FilterVarPureOp: `VarPure`, - FilterVarConstOp: `VarConst`, - FilterVarConstSliceOp: `VarConstSlice`, - FilterVarTextOp: `VarText`, - FilterVarLineOp: `VarLine`, - FilterVarValueIntOp: `VarValueInt`, - FilterVarTypeSizeOp: `VarTypeSize`, - FilterVarTypeHasPointersOp: `VarTypeHasPointers`, - FilterVarFilterOp: `VarFilter`, - FilterVarNodeIsOp: `VarNodeIs`, - FilterVarObjectIsOp: `VarObjectIs`, - FilterVarObjectIsGlobalOp: `VarObjectIsGlobal`, - FilterVarTypeIsOp: `VarTypeIs`, - FilterVarTypeIdenticalToOp: `VarTypeIdenticalTo`, - FilterVarTypeUnderlyingIsOp: `VarTypeUnderlyingIs`, - FilterVarTypeOfKindOp: `VarTypeOfKind`, - FilterVarTypeUnderlyingOfKindOp: `VarTypeUnderlyingOfKind`, - FilterVarTypeConvertibleToOp: `VarTypeConvertibleTo`, - FilterVarTypeAssignableToOp: `VarTypeAssignableTo`, - FilterVarTypeImplementsOp: `VarTypeImplements`, - FilterVarTypeHasMethodOp: `VarTypeHasMethod`, - FilterVarTextMatchesOp: `VarTextMatches`, - FilterVarContainsOp: `VarContains`, - FilterDeadcodeOp: `Deadcode`, - FilterGoVersionEqOp: `GoVersionEq`, - FilterGoVersionLessThanOp: `GoVersionLessThan`, - FilterGoVersionGreaterThanOp: `GoVersionGreaterThan`, - FilterGoVersionLessEqThanOp: `GoVersionLessEqThan`, - FilterGoVersionGreaterEqThanOp: `GoVersionGreaterEqThan`, - FilterFileImportsOp: `FileImports`, - FilterFilePkgPathMatchesOp: `FilePkgPathMatches`, - FilterFileNameMatchesOp: `FileNameMatches`, - FilterFilterFuncRefOp: `FilterFuncRef`, - FilterStringOp: `String`, - FilterIntOp: `Int`, - FilterRootNodeParentIsOp: `RootNodeParentIs`, - FilterRootSinkTypeIsOp: `RootSinkTypeIs`, + FilterInvalidOp: `Invalid`, + FilterNotOp: `Not`, + FilterAndOp: `And`, + FilterOrOp: `Or`, + FilterEqOp: `Eq`, + FilterNeqOp: `Neq`, + FilterGtOp: `Gt`, + FilterLtOp: `Lt`, + FilterGtEqOp: `GtEq`, + FilterLtEqOp: `LtEq`, + FilterVarAddressableOp: `VarAddressable`, + FilterVarComparableOp: `VarComparable`, + FilterVarPureOp: `VarPure`, + FilterVarConstOp: `VarConst`, + FilterVarConstSliceOp: `VarConstSlice`, + FilterVarTextOp: `VarText`, + FilterVarLineOp: `VarLine`, + FilterVarValueIntOp: `VarValueInt`, + FilterVarTypeSizeOp: `VarTypeSize`, + FilterVarTypeHasPointersOp: `VarTypeHasPointers`, + FilterVarFilterOp: `VarFilter`, + FilterVarNodeIsOp: `VarNodeIs`, + FilterVarObjectIsOp: `VarObjectIs`, + FilterVarObjectIsGlobalOp: `VarObjectIsGlobal`, + FilterVarObjectIsVariadicParamOp: `VarObjectIsVariadicParam`, + FilterVarTypeIsOp: `VarTypeIs`, + FilterVarTypeIdenticalToOp: `VarTypeIdenticalTo`, + FilterVarTypeUnderlyingIsOp: `VarTypeUnderlyingIs`, + FilterVarTypeOfKindOp: `VarTypeOfKind`, + FilterVarTypeUnderlyingOfKindOp: `VarTypeUnderlyingOfKind`, + FilterVarTypeConvertibleToOp: `VarTypeConvertibleTo`, + FilterVarTypeAssignableToOp: `VarTypeAssignableTo`, + FilterVarTypeImplementsOp: `VarTypeImplements`, + FilterVarTypeHasMethodOp: `VarTypeHasMethod`, + FilterVarTextMatchesOp: `VarTextMatches`, + FilterVarContainsOp: `VarContains`, + FilterDeadcodeOp: `Deadcode`, + FilterGoVersionEqOp: `GoVersionEq`, + FilterGoVersionLessThanOp: `GoVersionLessThan`, + FilterGoVersionGreaterThanOp: `GoVersionGreaterThan`, + FilterGoVersionLessEqThanOp: `GoVersionLessEqThan`, + FilterGoVersionGreaterEqThanOp: `GoVersionGreaterEqThan`, + FilterFileImportsOp: `FileImports`, + FilterFilePkgPathMatchesOp: `FilePkgPathMatches`, + FilterFileNameMatchesOp: `FileNameMatches`, + FilterFilterFuncRefOp: `FilterFuncRef`, + FilterStringOp: `String`, + FilterIntOp: `Int`, + FilterRootNodeParentIsOp: `RootNodeParentIs`, + FilterRootSinkTypeIsOp: `RootSinkTypeIs`, } var filterOpFlags = map[FilterOp]uint64{ - FilterAndOp: flagIsBinaryExpr, - FilterOrOp: flagIsBinaryExpr, - FilterEqOp: flagIsBinaryExpr, - FilterNeqOp: flagIsBinaryExpr, - FilterGtOp: flagIsBinaryExpr, - FilterLtOp: flagIsBinaryExpr, - FilterGtEqOp: flagIsBinaryExpr, - FilterLtEqOp: flagIsBinaryExpr, - FilterVarAddressableOp: flagHasVar, - FilterVarComparableOp: flagHasVar, - FilterVarPureOp: flagHasVar, - FilterVarConstOp: flagHasVar, - FilterVarConstSliceOp: flagHasVar, - FilterVarTextOp: flagHasVar, - FilterVarLineOp: flagHasVar, - FilterVarValueIntOp: flagHasVar, - FilterVarTypeSizeOp: flagHasVar, - FilterVarTypeHasPointersOp: flagHasVar, - FilterVarFilterOp: flagHasVar, - FilterVarNodeIsOp: flagHasVar, - FilterVarObjectIsOp: flagHasVar, - FilterVarObjectIsGlobalOp: flagHasVar, - FilterVarTypeIsOp: flagHasVar, - FilterVarTypeIdenticalToOp: flagHasVar, - FilterVarTypeUnderlyingIsOp: flagHasVar, - FilterVarTypeOfKindOp: flagHasVar, - FilterVarTypeUnderlyingOfKindOp: flagHasVar, - FilterVarTypeConvertibleToOp: flagHasVar, - FilterVarTypeAssignableToOp: flagHasVar, - FilterVarTypeImplementsOp: flagHasVar, - FilterVarTypeHasMethodOp: flagHasVar, - FilterVarTextMatchesOp: flagHasVar, - FilterVarContainsOp: flagHasVar, - FilterStringOp: flagIsBasicLit, - FilterIntOp: flagIsBasicLit, + FilterAndOp: flagIsBinaryExpr, + FilterOrOp: flagIsBinaryExpr, + FilterEqOp: flagIsBinaryExpr, + FilterNeqOp: flagIsBinaryExpr, + FilterGtOp: flagIsBinaryExpr, + FilterLtOp: flagIsBinaryExpr, + FilterGtEqOp: flagIsBinaryExpr, + FilterLtEqOp: flagIsBinaryExpr, + FilterVarAddressableOp: flagHasVar, + FilterVarComparableOp: flagHasVar, + FilterVarPureOp: flagHasVar, + FilterVarConstOp: flagHasVar, + FilterVarConstSliceOp: flagHasVar, + FilterVarTextOp: flagHasVar, + FilterVarLineOp: flagHasVar, + FilterVarValueIntOp: flagHasVar, + FilterVarTypeSizeOp: flagHasVar, + FilterVarTypeHasPointersOp: flagHasVar, + FilterVarFilterOp: flagHasVar, + FilterVarNodeIsOp: flagHasVar, + FilterVarObjectIsOp: flagHasVar, + FilterVarObjectIsGlobalOp: flagHasVar, + FilterVarObjectIsVariadicParamOp: flagHasVar, + FilterVarTypeIsOp: flagHasVar, + FilterVarTypeIdenticalToOp: flagHasVar, + FilterVarTypeUnderlyingIsOp: flagHasVar, + FilterVarTypeOfKindOp: flagHasVar, + FilterVarTypeUnderlyingOfKindOp: flagHasVar, + FilterVarTypeConvertibleToOp: flagHasVar, + FilterVarTypeAssignableToOp: flagHasVar, + FilterVarTypeImplementsOp: flagHasVar, + FilterVarTypeHasMethodOp: flagHasVar, + FilterVarTextMatchesOp: flagHasVar, + FilterVarContainsOp: flagHasVar, + FilterStringOp: flagIsBasicLit, + FilterIntOp: flagIsBasicLit, } diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir/gen_filter_op.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir/gen_filter_op.go index d3b740905..aecb975d8 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir/gen_filter_op.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir/gen_filter_op.go @@ -55,6 +55,7 @@ func main() { {name: "VarNodeIs", comment: "m[$Value].Node.Is($Args[0])", valueType: "string", flags: flagHasVar}, {name: "VarObjectIs", comment: "m[$Value].Object.Is($Args[0])", valueType: "string", flags: flagHasVar}, {name: "VarObjectIsGlobal", comment: "m[$Value].Object.IsGlobal()", valueType: "string", flags: flagHasVar}, + {name: "VarObjectIsVariadicParam", comment: "m[$Value].Object.IsVariadicParam()", valueType: "string", flags: flagHasVar}, {name: "VarTypeIs", comment: "m[$Value].Type.Is($Args[0])", valueType: "string", flags: flagHasVar}, {name: "VarTypeIdenticalTo", comment: "m[$Value].Type.IdenticalTo($Args[0])", valueType: "string", flags: flagHasVar}, {name: "VarTypeUnderlyingIs", comment: "m[$Value].Type.Underlying().Is($Args[0])", valueType: "string", flags: flagHasVar}, diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir_loader.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir_loader.go index c07a19f54..d71668914 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir_loader.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ir_loader.go @@ -699,6 +699,8 @@ func (l *irLoader) newFilter(filter ir.FilterExpr, info *filterInfo) (matchFilte result.fn = makeConstFilter(result.src, filter.Value.(string)) case ir.FilterVarObjectIsGlobalOp: result.fn = makeObjectIsGlobalFilter(result.src, filter.Value.(string)) + case ir.FilterVarObjectIsVariadicParamOp: + result.fn = makeObjectIsVariadicParamFilter(result.src, filter.Value.(string)) case ir.FilterVarConstSliceOp: result.fn = makeConstSliceFilter(result.src, filter.Value.(string)) case ir.FilterVarAddressableOp: diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/irconv/irconv.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/irconv/irconv.go index 646091fed..4eb90d51b 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/irconv/irconv.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/irconv/irconv.go @@ -746,6 +746,8 @@ func (conv *converter) convertFilterExprImpl(e ast.Expr) ir.FilterExpr { return ir.FilterExpr{Op: ir.FilterVarObjectIsOp, Value: op.varName, Args: args} case "Object.IsGlobal": return ir.FilterExpr{Op: ir.FilterVarObjectIsGlobalOp, Value: op.varName} + case "Object.IsVariadicParam": + return ir.FilterExpr{Op: ir.FilterVarObjectIsVariadicParamOp, Value: op.varName} case "SinkType.Is": if op.varName != "$$" { // TODO: remove this restriction. diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/match_data.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/match_data.go index 3bf3bf5a8..b0909f75f 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/match_data.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/match_data.go @@ -6,41 +6,14 @@ import ( "github.com/quasilyte/gogrep" ) -// matchData is used to handle both regexp and AST match sets in the same way. -type matchData interface { - // TODO: don't use gogrep.CapturedNode type here. - - Node() ast.Node - CaptureList() []gogrep.CapturedNode - CapturedByName(name string) (ast.Node, bool) -} - -type commentMatchData struct { - node ast.Node - capture []gogrep.CapturedNode -} - -func (m commentMatchData) Node() ast.Node { return m.node } - -func (m commentMatchData) CaptureList() []gogrep.CapturedNode { return m.capture } - -func (m commentMatchData) CapturedByName(name string) (ast.Node, bool) { - for _, c := range m.capture { - if c.Name == name { - return c.Node, true - } - } - return nil, false -} - -type astMatchData struct { +type matchData struct { match gogrep.MatchData } -func (m astMatchData) Node() ast.Node { return m.match.Node } +func (m matchData) Node() ast.Node { return m.match.Node } -func (m astMatchData) CaptureList() []gogrep.CapturedNode { return m.match.Capture } +func (m matchData) CaptureList() []gogrep.CapturedNode { return m.match.Capture } -func (m astMatchData) CapturedByName(name string) (ast.Node, bool) { +func (m matchData) CapturedByName(name string) (ast.Node, bool) { return m.match.CapturedByName(name) } diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/nodepath.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/nodepath.go index b0f02f0aa..4ba741ee2 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/nodepath.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/nodepath.go @@ -10,8 +10,8 @@ type nodePath struct { stack []ast.Node } -func newNodePath() nodePath { - return nodePath{stack: make([]ast.Node, 0, 32)} +func newNodePath() *nodePath { + return &nodePath{stack: make([]ast.Node, 0, 32)} } func (p nodePath) String() string { @@ -22,15 +22,15 @@ func (p nodePath) String() string { return strings.Join(parts, "/") } -func (p nodePath) Parent() ast.Node { +func (p *nodePath) Parent() ast.Node { return p.NthParent(1) } -func (p nodePath) Current() ast.Node { +func (p *nodePath) Current() ast.Node { return p.NthParent(0) } -func (p nodePath) NthParent(n int) ast.Node { +func (p *nodePath) NthParent(n int) ast.Node { index := uint(len(p.stack) - n - 1) if index < uint(len(p.stack)) { return p.stack[index] diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ruleguard.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ruleguard.go index 1a2e2f05f..41fbc8995 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ruleguard.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/ruleguard.go @@ -8,6 +8,9 @@ import ( "io" "github.com/quasilyte/go-ruleguard/ruleguard/ir" + "github.com/quasilyte/go-ruleguard/ruleguard/quasigo" + "github.com/quasilyte/go-ruleguard/ruleguard/typematch" + "github.com/quasilyte/gogrep" ) // Engine is the main ruleguard package API object. @@ -88,6 +91,21 @@ type LoadContext struct { Fset *token.FileSet } +type RunnerState struct { + gogrepState gogrep.MatcherState + gogrepSubState gogrep.MatcherState + nodePath *nodePath + evalEnv *quasigo.EvalEnv + typematchState *typematch.MatcherState + + object *rulesRunner +} + +// NewRunnerState creates a state object that can be used with RunContext. +func NewRunnerState(e *Engine) *RunnerState { + return newRunnerState(e.impl.state) +} + type RunContext struct { Debug string DebugImports bool @@ -115,6 +133,20 @@ type RunContext struct { // Note that this value is ignored for Suggest templates. // Ruleguard doesn't truncate suggested replacement candidates. TruncateLen int + + // State is an object that contains reusable resources needed for the rules to be executed. + // + // If nil, a new state will be allocated. + // + // The State object access is not synchronized. + // State should not be shared between multiple goroutines. + // There are 3 patterns that are safe: + // 1. For single-threaded programs, you can use a single state. + // 2. For controlled concurrency with workers, you can use a per-worker state. + // 3. For uncontrolled concurrency you can use a sync.Pool of states. + // + // Reusing the state properly can increase the performance significantly. + State *RunnerState } type ReportData struct { diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/runner.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/runner.go index 92f6cc34b..c76b6db33 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/runner.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/runner.go @@ -56,47 +56,77 @@ type rulesRunner struct { // For named submatches we can't use it as the node can be located // deeper into the tree than the current node. // In those cases we need a more complicated algorithm. - nodePath nodePath + nodePath *nodePath filterParams filterParams } +func newRunnerState(es *engineState) *RunnerState { + gogrepState := gogrep.NewMatcherState() + gogrepSubState := gogrep.NewMatcherState() + state := &RunnerState{ + gogrepState: gogrepState, + gogrepSubState: gogrepSubState, + nodePath: newNodePath(), + evalEnv: es.env.GetEvalEnv(), + typematchState: typematch.NewMatcherState(), + object: &rulesRunner{}, + } + return state +} + +func (state *RunnerState) Reset() { + state.nodePath.stack = state.nodePath.stack[:0] + state.evalEnv.Stack.Reset() +} + func newRulesRunner(ctx *RunContext, buildContext *build.Context, state *engineState, rules *goRuleSet) *rulesRunner { + runnerState := ctx.State + if runnerState == nil { + runnerState = newRunnerState(state) + } else { + runnerState.Reset() + } + importer := newGoImporter(state, goImporterConfig{ fset: ctx.Fset, debugImports: ctx.DebugImports, debugPrint: ctx.DebugPrint, buildContext: buildContext, }) - gogrepState := gogrep.NewMatcherState() + gogrepState := runnerState.gogrepState gogrepState.Types = ctx.Types - gogrepSubState := gogrep.NewMatcherState() + gogrepSubState := runnerState.gogrepSubState gogrepSubState.Types = ctx.Types - evalEnv := state.env.GetEvalEnv() - rr := &rulesRunner{ + evalEnv := runnerState.evalEnv + + rr := runnerState.object + *rr = rulesRunner{ bgContext: context.Background(), ctx: ctx, importer: importer, rules: rules, gogrepState: gogrepState, gogrepSubState: gogrepSubState, - nodePath: newNodePath(), + nodePath: runnerState.nodePath, truncateLen: ctx.TruncateLen, filterParams: filterParams{ - typematchState: typematch.NewMatcherState(), + typematchState: runnerState.typematchState, env: evalEnv, importer: importer, ctx: ctx, }, } + evalEnv.Stack.Push(&rr.filterParams) if ctx.TruncateLen == 0 { rr.truncateLen = 60 } rr.filterParams.nodeText = rr.nodeText rr.filterParams.nodeString = rr.nodeString - rr.filterParams.nodePath = &rr.nodePath + rr.filterParams.nodePath = rr.nodePath rr.filterParams.gogrepSubState = &rr.gogrepSubState + return rr } @@ -160,7 +190,7 @@ func (rr *rulesRunner) run(f *ast.File) error { if rr.rules.universal.categorizedNum != 0 { var inspector astWalker - inspector.nodePath = &rr.nodePath + inspector.nodePath = rr.nodePath inspector.filterParams = &rr.filterParams inspector.Walk(f, func(n ast.Node, tag nodetag.Value) { rr.runRules(n, tag) @@ -183,7 +213,7 @@ func (rr *rulesRunner) runCommentRules(comment *ast.Comment) { file := rr.ctx.Fset.File(comment.Pos()) for _, rule := range rr.rules.universal.commentRules { - var m commentMatchData + var m matchData if rule.captureGroups { result := rule.pat.FindStringSubmatchIndex(comment.Text) if result == nil { @@ -200,13 +230,13 @@ func (rr *rulesRunner) runCommentRules(comment *ast.Comment) { // Consider this pattern: `(?Pfoo)|(bar)`. // If we have `bar` input string, will remain empty. if beginPos < 0 || endPos < 0 { - m.capture = append(m.capture, gogrep.CapturedNode{ + m.match.Capture = append(m.match.Capture, gogrep.CapturedNode{ Name: name, Node: &ast.Comment{Slash: comment.Pos()}, }) continue } - m.capture = append(m.capture, gogrep.CapturedNode{ + m.match.Capture = append(m.match.Capture, gogrep.CapturedNode{ Name: name, Node: &ast.Comment{ Slash: file.Pos(beginPos + file.Offset(comment.Pos())), @@ -214,7 +244,7 @@ func (rr *rulesRunner) runCommentRules(comment *ast.Comment) { }, }) } - m.node = &ast.Comment{ + m.match.Node = &ast.Comment{ Slash: file.Pos(result[0] + file.Offset(comment.Pos())), Text: comment.Text[result[0]:result[1]], } @@ -224,7 +254,7 @@ func (rr *rulesRunner) runCommentRules(comment *ast.Comment) { if result == nil { continue } - m.node = &ast.Comment{ + m.match.Node = &ast.Comment{ Slash: file.Pos(result[0] + file.Offset(comment.Pos())), Text: comment.Text[result[0]:result[1]], } @@ -307,7 +337,7 @@ func (rr *rulesRunner) reject(rule goRule, reason string, m matchData) { } } -func (rr *rulesRunner) handleCommentMatch(rule goCommentRule, m commentMatchData) bool { +func (rr *rulesRunner) handleCommentMatch(rule goCommentRule, m matchData) bool { if rule.base.filter.fn != nil { rr.filterParams.match = m filterResult := rule.base.filter.fn(&rr.filterParams) @@ -345,13 +375,13 @@ func (rr *rulesRunner) handleCommentMatch(rule goCommentRule, m commentMatchData func (rr *rulesRunner) handleMatch(rule goRule, m gogrep.MatchData) bool { if rule.filter.fn != nil || rule.do != nil { - rr.filterParams.match = astMatchData{match: m} + rr.filterParams.match = matchData{match: m} } if rule.filter.fn != nil { filterResult := rule.filter.fn(&rr.filterParams) if !filterResult.Matched() { - rr.reject(rule, filterResult.RejectReason(), astMatchData{match: m}) + rr.reject(rule, filterResult.RejectReason(), matchData{match: m}) return false } } @@ -379,9 +409,9 @@ func (rr *rulesRunner) handleMatch(rule goRule, m gogrep.MatchData) bool { suggestText = rr.filterParams.suggestString } } else { - messageText = rr.renderMessage(rule.msg, astMatchData{match: m}, true) + messageText = rr.renderMessage(rule.msg, matchData{match: m}, true) if rule.suggestion != "" { - suggestText = rr.renderMessage(rule.suggestion, astMatchData{match: m}, false) + suggestText = rr.renderMessage(rule.suggestion, matchData{match: m}, false) } } diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/typematch/typematch.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/typematch/typematch.go index b74740378..4b740b207 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/typematch/typematch.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/typematch/typematch.go @@ -507,9 +507,14 @@ func (p *Pattern) matchIdentical(state *MatcherState, sub *pattern, typ types.Ty } pkgPath := sub.value.([2]string)[0] typeName := sub.value.([2]string)[1] - // obj.Pkg().Path() may be in a vendor directory. - path := strings.SplitAfter(obj.Pkg().Path(), "/vendor/") - return path[len(path)-1] == pkgPath && typeName == obj.Name() + if typeName != obj.Name() { + return false + } + objPath := obj.Pkg().Path() + if vendorPos := strings.Index(objPath, "/vendor/"); vendorPos != -1 { + objPath = objPath[vendorPos+len("/vendor/"):] + } + return objPath == pkgPath case opFuncNoSeq: typ, ok := typ.(*types.Signature) diff --git a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/utils.go b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/utils.go index 962e9da2a..d3226db22 100644 --- a/vendor/github.com/quasilyte/go-ruleguard/ruleguard/utils.go +++ b/vendor/github.com/quasilyte/go-ruleguard/ruleguard/utils.go @@ -9,6 +9,8 @@ import ( "regexp/syntax" "strconv" "strings" + + "golang.org/x/exp/typeparams" ) var invalidType = types.Typ[types.Invalid] @@ -295,3 +297,8 @@ func identOf(e ast.Expr) *ast.Ident { return nil } } + +func isTypeParam(typ types.Type) bool { + _, ok := typ.(*typeparams.TypeParam) + return ok +} diff --git a/vendor/github.com/quasilyte/gogrep/Makefile b/vendor/github.com/quasilyte/gogrep/Makefile index d05331f42..01dd2192e 100644 --- a/vendor/github.com/quasilyte/gogrep/Makefile +++ b/vendor/github.com/quasilyte/gogrep/Makefile @@ -6,9 +6,9 @@ test: @echo "everything is OK" ci-lint: - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH_DIR)/bin v1.43.0 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH_DIR)/bin v1.45.2 $(GOPATH_DIR)/bin/golangci-lint run ./... - go install github.com/quasilyte/go-consistent@latest + go install github.com/quasilyte/go-consistent@master $(GOPATH_DIR)/bin/go-consistent . ./internal/... ./nodetag/... ./filters/... @echo "everything is OK" diff --git a/vendor/github.com/quasilyte/gogrep/README.md b/vendor/github.com/quasilyte/gogrep/README.md index b6c2c47c1..ecf0dc4c7 100644 --- a/vendor/github.com/quasilyte/gogrep/README.md +++ b/vendor/github.com/quasilyte/gogrep/README.md @@ -24,7 +24,7 @@ $ go get github.com/quasilyte/gogrep To get a gogrep command-line tool, install the `cmd/gogrep` Go submodule. ```bash -$ go install github.com/quasilyte/cmd/gogrep +$ go install github.com/quasilyte/gogrep/cmd/gogrep@latest ``` See [docs/gogrep_cli.md](_docs/gogrep_cli.md) to learn how to use it. diff --git a/vendor/github.com/quasilyte/gogrep/compile.go b/vendor/github.com/quasilyte/gogrep/compile.go index cc60c05a6..31b60dfa5 100644 --- a/vendor/github.com/quasilyte/gogrep/compile.go +++ b/vendor/github.com/quasilyte/gogrep/compile.go @@ -6,6 +6,7 @@ import ( "go/token" "github.com/quasilyte/gogrep/internal/stdinfo" + "golang.org/x/exp/typeparams" ) type compileError string @@ -121,16 +122,19 @@ func (c *compiler) compileNode(n ast.Node) { c.compileStmt(n) case *ast.ValueSpec: c.compileValueSpec(n) - case stmtSlice: - c.compileStmtSlice(n) - case declSlice: - c.compileDeclSlice(n) - case ExprSlice: - c.compileExprSlice(n) case *rangeClause: c.compileRangeClause(n) case *rangeHeader: c.compileRangeHeader(n) + case *NodeSlice: + switch n.Kind { + case StmtNodeSlice: + c.compileStmtSlice(n.stmtSlice) + case DeclNodeSlice: + c.compileDeclSlice(n.declSlice) + case ExprNodeSlice: + c.compileExprSlice(n.exprSlice) + } default: panic(c.errorf(n, "compileNode: unexpected %T", n)) } @@ -211,7 +215,7 @@ func (c *compiler) compileField(n *ast.Field) { } c.emitInstOp(opEnd) } - c.compileExpr(n.Type) + c.compileTypeExpr(n.Type) } func (c *compiler) compileValueSpec(spec *ast.ValueSpec) { @@ -234,7 +238,7 @@ func (c *compiler) compileValueSpec(spec *ast.ValueSpec) { } c.emitInstOp(opEnd) if spec.Type != nil { - c.compileOptExpr(spec.Type) + c.compileOptTypeExpr(spec.Type) } if len(spec.Values) != 0 { for _, v := range spec.Values { @@ -245,9 +249,26 @@ func (c *compiler) compileValueSpec(spec *ast.ValueSpec) { } func (c *compiler) compileTypeSpec(spec *ast.TypeSpec) { + // Generic types can't have aliases, so we use that fact here. + typeParams := typeparams.ForTypeSpec(spec) + if !spec.Assign.IsValid() && !isWildName(spec.Name.Name) && typeParams == nil { + c.emitInst(instruction{ + op: opSimpleTypeSpec, + valueIndex: c.internString(spec.Name, spec.Name.Name), + }) + c.compileTypeExpr(spec.Type) + return + } + if typeParams != nil { + c.emitInstOp(opGenericTypeSpec) + c.compileIdent(spec.Name) + c.compileFieldList(typeParams) + c.compileTypeExpr(spec.Type) + return + } c.emitInstOp(pickOp(spec.Assign.IsValid(), opTypeAliasSpec, opTypeSpec)) c.compileIdent(spec.Name) - c.compileExpr(spec.Type) + c.compileTypeExpr(spec.Type) } func (c *compiler) compileFile(n *ast.File) { @@ -274,6 +295,16 @@ func (c *compiler) compileDecl(n ast.Decl) { func (c *compiler) compileFuncDecl(n *ast.FuncDecl) { if n.Recv == nil { + if !isWildName(n.Name.Name) && typeparams.ForFuncType(n.Type) == nil && n.Body != nil { + // Generic functions can't live without body, so there is no generic proto decls. + c.emitInst(instruction{ + op: opSimpleFuncDecl, + valueIndex: c.internString(n.Name, n.Name.Name), + }) + c.compileFuncType(n.Type) + c.compileBlockStmt(n.Body) + return + } c.emitInstOp(pickOp(n.Body == nil, opFuncProtoDecl, opFuncDecl)) } else { c.emitInstOp(pickOp(n.Body == nil, opMethodProtoDecl, opMethodDecl)) @@ -313,6 +344,22 @@ func (c *compiler) compileGenDecl(n *ast.GenDecl) { } } +func (c *compiler) compileTypeExpr(n ast.Expr) { + if ident, ok := n.(*ast.Ident); ok && ident.Name == "any" && !c.config.Strict && typeparams.Enabled() { + c.emitInstOp(opEfaceType) + return + } + c.compileExpr(n) +} + +func (c *compiler) compileOptTypeExpr(n ast.Expr) { + if ident, ok := n.(*ast.Ident); ok && isWildName(ident.Name) { + c.compileWildIdent(ident, true) + return + } + c.compileTypeExpr(n) +} + func (c *compiler) compileExpr(n ast.Expr) { switch n := n.(type) { case *ast.BasicLit: @@ -321,6 +368,8 @@ func (c *compiler) compileExpr(n ast.Expr) { c.compileBinaryExpr(n) case *ast.IndexExpr: c.compileIndexExpr(n) + case *typeparams.IndexListExpr: + c.compileIndexListExpr(n) case *ast.Ident: c.compileIdent(n) case *ast.CallExpr: @@ -408,6 +457,15 @@ func (c *compiler) compileIndexExpr(n *ast.IndexExpr) { c.compileExpr(n.Index) } +func (c *compiler) compileIndexListExpr(n *typeparams.IndexListExpr) { + c.emitInstOp(opIndexListExpr) + c.compileExpr(n.X) + for _, x := range n.Indices { + c.compileExpr(x) + } + c.emitInstOp(opEnd) +} + func (c *compiler) compileWildIdent(n *ast.Ident, optional bool) { info := decodeWildName(n.Name) var inst instruction @@ -467,25 +525,41 @@ func (c *compiler) compileExprMembers(list []ast.Expr) { } func (c *compiler) compileCallExpr(n *ast.CallExpr) { - canBeVariadic := func(n *ast.CallExpr) bool { + variadicOperation := func(n *ast.CallExpr) (operation, uint8) { if len(n.Args) == 0 { - return false + return opNonVariadicCallExpr, 0 } lastArg, ok := n.Args[len(n.Args)-1].(*ast.Ident) if !ok { - return false + return opNonVariadicCallExpr, 0 } - return isWildName(lastArg.Name) && decodeWildName(lastArg.Name).Seq + if !isWildName(lastArg.Name) || !decodeWildName(lastArg.Name).Seq { + return opNonVariadicCallExpr, 0 + } + if len(n.Args) == 1 { + return opCallExpr, 0 + } + // If there is any seq op before the lastArg, we emit opCallExpr too. + for i := 0; i < len(n.Args)-1; i++ { + if decodeWildNode(n.Args[i]).Seq { + return opCallExpr, 0 + } + } + return opMaybeVariadicCallExpr, c.toUint8(n, len(n.Args)-1) } - op := opNonVariadicCallExpr + var value uint8 + var op operation if n.Ellipsis.IsValid() { op = opVariadicCallExpr - } else if canBeVariadic(n) { - op = opCallExpr + } else { + op, value = variadicOperation(n) } - c.emitInstOp(op) + c.prog.insts = append(c.prog.insts, instruction{ + op: op, + value: value, + }) c.compileSymbol(n.Fun) c.compileExprMembers(n.Args) } @@ -592,16 +666,32 @@ func (c *compiler) compileStructType(n *ast.StructType) { } func (c *compiler) compileInterfaceType(n *ast.InterfaceType) { + if len(n.Methods.List) == 0 && !c.config.Strict { + c.emitInstOp(opEfaceType) + return + } c.emitInstOp(opInterfaceType) c.compileOptFieldList(n.Methods) } func (c *compiler) compileFuncType(n *ast.FuncType) { void := n.Results == nil || len(n.Results.List) == 0 + typeParams := typeparams.ForFuncType(n) if void { - c.emitInstOp(opVoidFuncType) + if typeParams == nil { + c.emitInstOp(opVoidFuncType) + } else { + c.emitInstOp(opGenericVoidFuncType) + } } else { - c.emitInstOp(opFuncType) + if typeParams == nil { + c.emitInstOp(opFuncType) + } else { + c.emitInstOp(opGenericFuncType) + } + } + if typeParams != nil { + c.compileOptFieldList(typeParams) } c.compileOptFieldList(n.Params) if !void { @@ -612,18 +702,18 @@ func (c *compiler) compileFuncType(n *ast.FuncType) { func (c *compiler) compileArrayType(n *ast.ArrayType) { if n.Len == nil { c.emitInstOp(opSliceType) - c.compileExpr(n.Elt) + c.compileTypeExpr(n.Elt) } else { c.emitInstOp(opArrayType) c.compileExpr(n.Len) - c.compileExpr(n.Elt) + c.compileTypeExpr(n.Elt) } } func (c *compiler) compileMapType(n *ast.MapType) { c.emitInstOp(opMapType) - c.compileExpr(n.Key) - c.compileExpr(n.Value) + c.compileTypeExpr(n.Key) + c.compileTypeExpr(n.Value) } func (c *compiler) compileChanType(n *ast.ChanType) { @@ -631,7 +721,7 @@ func (c *compiler) compileChanType(n *ast.ChanType) { op: opChanType, value: c.toUint8(n, int(n.Dir)), }) - c.compileExpr(n.Value) + c.compileTypeExpr(n.Value) } func (c *compiler) compileCompositeLit(n *ast.CompositeLit) { @@ -639,7 +729,7 @@ func (c *compiler) compileCompositeLit(n *ast.CompositeLit) { c.emitInstOp(opCompositeLit) } else { c.emitInstOp(opTypedCompositeLit) - c.compileExpr(n.Type) + c.compileTypeExpr(n.Type) } for _, elt := range n.Elts { c.compileExpr(elt) @@ -687,7 +777,7 @@ func (c *compiler) compileTypeAssertExpr(n *ast.TypeAssertExpr) { if n.Type != nil { c.emitInstOp(opTypeAssertExpr) c.compileExpr(n.X) - c.compileExpr(n.Type) + c.compileTypeExpr(n.Type) } else { c.emitInstOp(opTypeSwitchAssertExpr) c.compileExpr(n.X) @@ -1104,7 +1194,7 @@ func (c *compiler) compileSendStmt(n *ast.SendStmt) { c.compileExpr(n.Value) } -func (c *compiler) compileDeclSlice(decls declSlice) { +func (c *compiler) compileDeclSlice(decls []ast.Decl) { c.emitInstOp(opMultiDecl) for _, n := range decls { c.compileDecl(n) @@ -1112,7 +1202,7 @@ func (c *compiler) compileDeclSlice(decls declSlice) { c.emitInstOp(opEnd) } -func (c *compiler) compileStmtSlice(stmts stmtSlice) { +func (c *compiler) compileStmtSlice(stmts []ast.Stmt) { c.emitInstOp(opMultiStmt) insideStmtList := c.insideStmtList c.insideStmtList = true @@ -1123,7 +1213,7 @@ func (c *compiler) compileStmtSlice(stmts stmtSlice) { c.emitInstOp(opEnd) } -func (c *compiler) compileExprSlice(exprs ExprSlice) { +func (c *compiler) compileExprSlice(exprs []ast.Expr) { c.emitInstOp(opMultiExpr) for _, n := range exprs { c.compileExpr(n) diff --git a/vendor/github.com/quasilyte/gogrep/gen_operations.go b/vendor/github.com/quasilyte/gogrep/gen_operations.go index 8de59980b..fd8035774 100644 --- a/vendor/github.com/quasilyte/gogrep/gen_operations.go +++ b/vendor/github.com/quasilyte/gogrep/gen_operations.go @@ -42,6 +42,8 @@ var opPrototypes = []operationProto{ {name: "IndexExpr", tag: "IndexExpr", args: "x expr"}, + {name: "IndexListExpr", tag: "IndexListExpr", args: "x exprs..."}, + {name: "SliceExpr", tag: "SliceExpr", args: "x"}, {name: "SliceFromExpr", tag: "SliceExpr", args: "x from", example: "x[from:]"}, {name: "SliceToExpr", tag: "SliceExpr", args: "x to", example: "x[:to]"}, @@ -60,9 +62,12 @@ var opPrototypes = []operationProto{ {name: "TypeSwitchAssertExpr", tag: "TypeAssertExpr", args: "x"}, {name: "StructType", tag: "StructType", args: "fields"}, - {name: "InterfaceType", tag: "StructType", args: "fields"}, + {name: "InterfaceType", tag: "InterfaceType", args: "fields"}, + {name: "EfaceType", tag: "InterfaceType"}, {name: "VoidFuncType", tag: "FuncType", args: "params"}, + {name: "GenericVoidFuncType", tag: "FuncType", args: "typeparams params"}, {name: "FuncType", tag: "FuncType", args: "params results"}, + {name: "GenericFuncType", tag: "FuncType", args: "typeparams params results"}, {name: "ArrayType", tag: "ArrayType", args: "length elem"}, {name: "SliceType", tag: "ArrayType", args: "elem"}, {name: "MapType", tag: "MapType", args: "key value"}, @@ -92,6 +97,7 @@ var opPrototypes = []operationProto{ {name: "VariadicCallExpr", tag: "CallExpr", args: "fn args", example: "f(1, xs...)"}, {name: "NonVariadicCallExpr", tag: "CallExpr", args: "fn args", example: "f(1, xs)"}, + {name: "MaybeVariadicCallExpr", tag: "CallExpr", args: "fn args", value: "int | can be variadic if len(args)>value", example: "f(1, xs) or f(1, xs...)"}, {name: "CallExpr", tag: "CallExpr", args: "fn args", example: "f(1, xs) or f(1, xs...)"}, {name: "AssignStmt", tag: "AssignStmt", args: "lhs rhs", value: "token.Token | ':=' or '='", example: "lhs := rhs()"}, @@ -167,9 +173,12 @@ var opPrototypes = []operationProto{ {name: "TypedValueInitSpec", tag: "ValueSpec", args: "lhs... type rhs...", example: "lhs typ = rhs"}, {name: "TypedValueSpec", tag: "ValueSpec", args: "lhs... type", example: "lhs typ"}, + {name: "SimpleTypeSpec", tag: "TypeSpec", args: "type", valueIndex: "strings | type name", example: "name type"}, {name: "TypeSpec", tag: "TypeSpec", args: "name type", example: "name type"}, + {name: "GenericTypeSpec", tag: "TypeSpec", args: "name typeparasm type", example: "name[typeparams] type"}, {name: "TypeAliasSpec", tag: "TypeSpec", args: "name type", example: "name = type"}, + {name: "SimpleFuncDecl", tag: "FuncDecl", args: "type block", valueIndex: "strings | field name"}, {name: "FuncDecl", tag: "FuncDecl", args: "name type block"}, {name: "MethodDecl", tag: "FuncDecl", args: "recv name type block"}, {name: "FuncProtoDecl", tag: "FuncDecl", args: "name type"}, diff --git a/vendor/github.com/quasilyte/gogrep/go.mod b/vendor/github.com/quasilyte/gogrep/go.mod deleted file mode 100644 index 3c76dc5e1..000000000 --- a/vendor/github.com/quasilyte/gogrep/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module github.com/quasilyte/gogrep - -go 1.16 - -require ( - github.com/go-toolsmith/astequal v1.0.1 - github.com/google/go-cmp v0.5.6 -) diff --git a/vendor/github.com/quasilyte/gogrep/go.sum b/vendor/github.com/quasilyte/gogrep/go.sum deleted file mode 100644 index 25c3bbb3e..000000000 --- a/vendor/github.com/quasilyte/gogrep/go.sum +++ /dev/null @@ -1,8 +0,0 @@ -github.com/go-toolsmith/astequal v1.0.1 h1:JbSszi42Jiqu36Gnf363HWS9MTEAz67vTQLponh3Moc= -github.com/go-toolsmith/astequal v1.0.1/go.mod h1:4oGA3EZXTVItV/ipGiOx7NWkY5veFfcsOJVS2YxltLw= -github.com/go-toolsmith/strparse v1.0.0 h1:Vcw78DnpCAKlM20kSbAyO4mPfJn/lyYA4BJUDxe2Jb4= -github.com/go-toolsmith/strparse v1.0.0/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/vendor/github.com/quasilyte/gogrep/gogrep.go b/vendor/github.com/quasilyte/gogrep/gogrep.go index 313a9a251..47a03f9b4 100644 --- a/vendor/github.com/quasilyte/gogrep/gogrep.go +++ b/vendor/github.com/quasilyte/gogrep/gogrep.go @@ -11,7 +11,7 @@ import ( ) func IsEmptyNodeSlice(n ast.Node) bool { - if list, ok := n.(NodeSlice); ok { + if list, ok := n.(*NodeSlice); ok { return list.Len() == 0 } return false @@ -62,6 +62,9 @@ type MatcherState struct { // actual matching phase) capture []CapturedNode + nodeSlices []NodeSlice + nodeSlicesUsed int + pc int partial PartialNode @@ -69,7 +72,8 @@ type MatcherState struct { func NewMatcherState() MatcherState { return MatcherState{ - capture: make([]CapturedNode, 0, 8), + capture: make([]CapturedNode, 0, 8), + nodeSlices: make([]NodeSlice, 16), } } @@ -143,34 +147,37 @@ func Compile(config CompileConfig) (*Pattern, PatternInfo, error) { } func Walk(root ast.Node, fn func(n ast.Node) bool) { - switch root := root.(type) { - case ExprSlice: - for _, e := range root { - ast.Inspect(e, fn) - } - case stmtSlice: - for _, e := range root { - ast.Inspect(e, fn) - } - case fieldSlice: - for _, e := range root { - ast.Inspect(e, fn) - } - case identSlice: - for _, e := range root { - ast.Inspect(e, fn) + if root, ok := root.(*NodeSlice); ok { + switch root.Kind { + case ExprNodeSlice: + for _, e := range root.exprSlice { + ast.Inspect(e, fn) + } + case StmtNodeSlice: + for _, e := range root.stmtSlice { + ast.Inspect(e, fn) + } + case FieldNodeSlice: + for _, e := range root.fieldSlice { + ast.Inspect(e, fn) + } + case IdentNodeSlice: + for _, e := range root.identSlice { + ast.Inspect(e, fn) + } + case SpecNodeSlice: + for _, e := range root.specSlice { + ast.Inspect(e, fn) + } + default: + for _, e := range root.declSlice { + ast.Inspect(e, fn) + } } - case specSlice: - for _, e := range root { - ast.Inspect(e, fn) - } - case declSlice: - for _, e := range root { - ast.Inspect(e, fn) - } - default: - ast.Inspect(root, fn) + return } + + ast.Inspect(root, fn) } func newPatternInfo() PatternInfo { diff --git a/vendor/github.com/quasilyte/gogrep/match.go b/vendor/github.com/quasilyte/gogrep/match.go index d927beff3..d4b317b96 100644 --- a/vendor/github.com/quasilyte/gogrep/match.go +++ b/vendor/github.com/quasilyte/gogrep/match.go @@ -8,6 +8,7 @@ import ( "strconv" "github.com/go-toolsmith/astequal" + "golang.org/x/exp/typeparams" ) type matcher struct { @@ -44,8 +45,36 @@ func (m *matcher) resetCapture(state *MatcherState) { } } +func (m *matcher) toStmtSlice(state *MatcherState, nodes ...ast.Node) *NodeSlice { + slice := m.allocNodeSlice(state) + var stmts []ast.Stmt + for _, node := range nodes { + switch x := node.(type) { + case nil: + case ast.Stmt: + stmts = append(stmts, x) + case ast.Expr: + stmts = append(stmts, &ast.ExprStmt{X: x}) + default: + panic(fmt.Sprintf("unexpected node type: %T", x)) + } + } + slice.assignStmtSlice(stmts) + return slice +} + +func (m *matcher) allocNodeSlice(state *MatcherState) *NodeSlice { + if state.nodeSlicesUsed < len(state.nodeSlices) { + i := state.nodeSlicesUsed + state.nodeSlicesUsed++ + return &state.nodeSlices[i] + } + return &NodeSlice{} +} + func (m *matcher) MatchNode(state *MatcherState, n ast.Node, accept func(MatchData)) { state.pc = 0 + state.nodeSlicesUsed = 0 inst := m.nextInst(state) switch inst.op { case opMultiStmt: @@ -90,24 +119,32 @@ func (m *matcher) MatchNode(state *MatcherState, n ast.Node, accept func(MatchDa } func (m *matcher) walkDeclSlice(state *MatcherState, decls []ast.Decl, accept func(MatchData)) { - m.walkNodeSlice(state, declSlice(decls), accept) + slice := m.allocNodeSlice(state) + slice.assignDeclSlice(decls) + m.walkNodeSlice(state, slice, accept) } func (m *matcher) walkExprSlice(state *MatcherState, exprs []ast.Expr, accept func(MatchData)) { - m.walkNodeSlice(state, ExprSlice(exprs), accept) + slice := m.allocNodeSlice(state) + slice.assignExprSlice(exprs) + m.walkNodeSlice(state, slice, accept) } func (m *matcher) walkStmtSlice(state *MatcherState, stmts []ast.Stmt, accept func(MatchData)) { - m.walkNodeSlice(state, stmtSlice(stmts), accept) + slice := m.allocNodeSlice(state) + slice.assignStmtSlice(stmts) + m.walkNodeSlice(state, slice, accept) } -func (m *matcher) walkNodeSlice(state *MatcherState, nodes NodeSlice, accept func(MatchData)) { +func (m *matcher) walkNodeSlice(state *MatcherState, nodes *NodeSlice, accept func(MatchData)) { sliceLen := nodes.Len() from := 0 + tmpSlice := m.allocNodeSlice(state) for { state.pc = 1 // FIXME: this is a kludge m.resetCapture(state) - matched, offset := m.matchNodeList(state, nodes.slice(from, sliceLen), true) + nodes.SliceInto(tmpSlice, from, sliceLen) + matched, offset := m.matchNodeList(state, tmpSlice, true) if matched == nil { break } @@ -232,6 +269,15 @@ func (m *matcher) matchNodeWithInst(state *MatcherState, inst instruction, n ast case opNonVariadicCallExpr: n, ok := n.(*ast.CallExpr) return ok && !n.Ellipsis.IsValid() && m.matchNode(state, n.Fun) && m.matchArgList(state, n.Args) + case opMaybeVariadicCallExpr: + n, ok := n.(*ast.CallExpr) + if !ok { + return false + } + if n.Ellipsis.IsValid() && len(n.Args) <= int(inst.value) { + return false + } + return m.matchNode(state, n.Fun) && m.matchArgList(state, n.Args) case opCallExpr: n, ok := n.(*ast.CallExpr) return ok && m.matchNode(state, n.Fun) && m.matchArgList(state, n.Args) @@ -277,6 +323,10 @@ func (m *matcher) matchNodeWithInst(state *MatcherState, inst instruction, n ast n, ok := n.(*ast.IndexExpr) return ok && m.matchNode(state, n.X) && m.matchNode(state, n.Index) + case opIndexListExpr: + n, ok := n.(*typeparams.IndexListExpr) + return ok && m.matchNode(state, n.X) && m.matchExprSlice(state, n.Indices) + case opKeyValueExpr: n, ok := n.(*ast.KeyValueExpr) return ok && m.matchNode(state, n.Key) && m.matchNode(state, n.Value) @@ -307,15 +357,30 @@ func (m *matcher) matchNodeWithInst(state *MatcherState, inst instruction, n ast case opVoidFuncType: n, ok := n.(*ast.FuncType) return ok && n.Results == nil && m.matchNode(state, n.Params) + case opGenericVoidFuncType: + n, ok := n.(*ast.FuncType) + return ok && n.Results == nil && m.matchNode(state, typeparams.ForFuncType(n)) && m.matchNode(state, n.Params) case opFuncType: n, ok := n.(*ast.FuncType) return ok && m.matchNode(state, n.Params) && m.matchNode(state, n.Results) + case opGenericFuncType: + n, ok := n.(*ast.FuncType) + return ok && m.matchNode(state, typeparams.ForFuncType(n)) && m.matchNode(state, n.Params) && m.matchNode(state, n.Results) case opStructType: n, ok := n.(*ast.StructType) return ok && m.matchNode(state, n.Fields) case opInterfaceType: n, ok := n.(*ast.InterfaceType) return ok && m.matchNode(state, n.Methods) + case opEfaceType: + switch n := n.(type) { + case *ast.InterfaceType: + return len(n.Methods.List) == 0 + case *ast.Ident: + return n.Name == "any" + default: + return false + } case opCompositeLit: n, ok := n.(*ast.CompositeLit) @@ -393,11 +458,11 @@ func (m *matcher) matchNodeWithInst(state *MatcherState, inst instruction, n ast case opIfNamedOptStmt: n, ok := n.(*ast.IfStmt) return ok && n.Else == nil && m.matchNode(state, n.Body) && - m.matchNamed(state, m.stringValue(inst), toStmtSlice(n.Cond, n.Init)) + m.matchNamed(state, m.stringValue(inst), m.toStmtSlice(state, n.Cond, n.Init)) case opIfNamedOptElseStmt: n, ok := n.(*ast.IfStmt) return ok && n.Else != nil && m.matchNode(state, n.Body) && m.matchNode(state, n.Else) && - m.matchNamed(state, m.stringValue(inst), toStmtSlice(n.Cond, n.Init)) + m.matchNamed(state, m.stringValue(inst), m.toStmtSlice(state, n.Cond, n.Init)) case opCaseClause: n, ok := n.(*ast.CaseClause) @@ -511,13 +576,17 @@ func (m *matcher) matchNodeWithInst(state *MatcherState, inst instruction, n ast _, ok := n.(*ast.EmptyStmt) return ok + case opSimpleFuncDecl: + n, ok := n.(*ast.FuncDecl) + return ok && n.Recv == nil && n.Body != nil && typeparams.ForFuncType(n.Type) == nil && + n.Name.Name == m.stringValue(inst) && m.matchNode(state, n.Type) && m.matchNode(state, n.Body) case opFuncDecl: n, ok := n.(*ast.FuncDecl) return ok && n.Recv == nil && n.Body != nil && m.matchNode(state, n.Name) && m.matchNode(state, n.Type) && m.matchNode(state, n.Body) case opFuncProtoDecl: n, ok := n.(*ast.FuncDecl) - return ok && n.Recv == nil && n.Body == nil && + return ok && n.Recv == nil && n.Body == nil && typeparams.ForFuncType(n.Type) == nil && m.matchNode(state, n.Name) && m.matchNode(state, n.Type) case opMethodDecl: n, ok := n.(*ast.FuncDecl) @@ -545,9 +614,15 @@ func (m *matcher) matchNodeWithInst(state *MatcherState, inst instruction, n ast return ok && len(n.Values) != 0 && m.matchIdentSlice(state, n.Names) && m.matchNode(state, n.Type) && m.matchExprSlice(state, n.Values) + case opSimpleTypeSpec: + n, ok := n.(*ast.TypeSpec) + return ok && !n.Assign.IsValid() && typeparams.ForTypeSpec(n) == nil && n.Name.Name == m.stringValue(inst) && m.matchNode(state, n.Type) case opTypeSpec: n, ok := n.(*ast.TypeSpec) return ok && !n.Assign.IsValid() && m.matchNode(state, n.Name) && m.matchNode(state, n.Type) + case opGenericTypeSpec: + n, ok := n.(*ast.TypeSpec) + return ok && !n.Assign.IsValid() && m.matchNode(state, n.Name) && m.matchNode(state, typeparams.ForTypeSpec(n)) && m.matchNode(state, n.Type) case opTypeAliasSpec: n, ok := n.(*ast.TypeSpec) return ok && n.Assign.IsValid() && m.matchNode(state, n.Name) && m.matchNode(state, n.Type) @@ -602,33 +677,43 @@ func (m *matcher) matchArgList(state *MatcherState, exprs []ast.Expr) bool { } func (m *matcher) matchStmtSlice(state *MatcherState, stmts []ast.Stmt) bool { - matched, _ := m.matchNodeList(state, stmtSlice(stmts), false) + slice := m.allocNodeSlice(state) + slice.assignStmtSlice(stmts) + matched, _ := m.matchNodeList(state, slice, false) return matched != nil } func (m *matcher) matchExprSlice(state *MatcherState, exprs []ast.Expr) bool { - matched, _ := m.matchNodeList(state, ExprSlice(exprs), false) + slice := m.allocNodeSlice(state) + slice.assignExprSlice(exprs) + matched, _ := m.matchNodeList(state, slice, false) return matched != nil } func (m *matcher) matchFieldSlice(state *MatcherState, fields []*ast.Field) bool { - matched, _ := m.matchNodeList(state, fieldSlice(fields), false) + slice := m.allocNodeSlice(state) + slice.assignFieldSlice(fields) + matched, _ := m.matchNodeList(state, slice, false) return matched != nil } func (m *matcher) matchIdentSlice(state *MatcherState, idents []*ast.Ident) bool { - matched, _ := m.matchNodeList(state, identSlice(idents), false) + slice := m.allocNodeSlice(state) + slice.assignIdentSlice(idents) + matched, _ := m.matchNodeList(state, slice, false) return matched != nil } func (m *matcher) matchSpecSlice(state *MatcherState, specs []ast.Spec) bool { - matched, _ := m.matchNodeList(state, specSlice(specs), false) + slice := m.allocNodeSlice(state) + slice.assignSpecSlice(specs) + matched, _ := m.matchNodeList(state, slice, false) return matched != nil } // matchNodeList matches two lists of nodes. It uses a common algorithm to match // wildcard patterns with any number of nodes without recursion. -func (m *matcher) matchNodeList(state *MatcherState, nodes NodeSlice, partial bool) (matched ast.Node, offset int) { +func (m *matcher) matchNodeList(state *MatcherState, nodes *NodeSlice, partial bool) (matched ast.Node, offset int) { sliceLen := nodes.Len() inst := m.nextInst(state) if inst.op == opEnd { @@ -688,7 +773,9 @@ func (m *matcher) matchNodeList(state *MatcherState, nodes NodeSlice, partial bo case "", "_": return true } - return m.matchNamed(state, wildName, nodes.slice(wildStart, j)) + slice := m.allocNodeSlice(state) + nodes.SliceInto(slice, wildStart, j) + return m.matchNamed(state, wildName, slice) } for ; inst.op != opEnd || j < sliceLen; inst = m.nextInst(state) { if inst.op != opEnd { @@ -737,7 +824,9 @@ func (m *matcher) matchNodeList(state *MatcherState, nodes NodeSlice, partial bo if !wouldMatch() { return nil, -1 } - return nodes.slice(partialStart, partialEnd), partialEnd + 1 + slice := m.allocNodeSlice(state) + nodes.SliceInto(slice, partialStart, partialEnd) + return slice, partialEnd + 1 } func (m *matcher) matchRangeClause(state *MatcherState, n ast.Node, accept func(MatchData)) { @@ -880,58 +969,56 @@ func equalNodes(x, y ast.Node) bool { if x == nil || y == nil { return x == y } - switch x := x.(type) { - case stmtSlice: - y, ok := y.(stmtSlice) - if !ok || len(x) != len(y) { + if x, ok := x.(*NodeSlice); ok { + y, ok := y.(*NodeSlice) + if !ok || x.Kind != y.Kind || x.Len() != y.Len() { return false } - for i := range x { - if !astequal.Stmt(x[i], y[i]) { - return false + switch x.Kind { + case ExprNodeSlice: + for i, n1 := range x.exprSlice { + n2 := y.exprSlice[i] + if !astequal.Expr(n1, n2) { + return false + } } - } - return true - case ExprSlice: - y, ok := y.(ExprSlice) - if !ok || len(x) != len(y) { - return false - } - for i := range x { - if !astequal.Expr(x[i], y[i]) { - return false + case StmtNodeSlice: + for i, n1 := range x.stmtSlice { + n2 := y.stmtSlice[i] + if !astequal.Stmt(n1, n2) { + return false + } } - } - return true - case declSlice: - y, ok := y.(declSlice) - if !ok || len(x) != len(y) { - return false - } - for i := range x { - if !astequal.Decl(x[i], y[i]) { - return false + case FieldNodeSlice: + for i, n1 := range x.fieldSlice { + n2 := y.fieldSlice[i] + if !astequal.Node(n1, n2) { + return false + } + } + case IdentNodeSlice: + for i, n1 := range x.identSlice { + n2 := y.identSlice[i] + if n1.Name != n2.Name { + return false + } + } + case SpecNodeSlice: + for i, n1 := range x.specSlice { + n2 := y.specSlice[i] + if !astequal.Node(n1, n2) { + return false + } + } + case DeclNodeSlice: + for i, n1 := range x.declSlice { + n2 := y.declSlice[i] + if !astequal.Decl(n1, n2) { + return false + } } } return true - - default: - return astequal.Node(x, y) - } -} - -func toStmtSlice(nodes ...ast.Node) stmtSlice { - var stmts []ast.Stmt - for _, node := range nodes { - switch x := node.(type) { - case nil: - case ast.Stmt: - stmts = append(stmts, x) - case ast.Expr: - stmts = append(stmts, &ast.ExprStmt{X: x}) - default: - panic(fmt.Sprintf("unexpected node type: %T", x)) - } } - return stmtSlice(stmts) + return astequal.Node(x, y) } diff --git a/vendor/github.com/quasilyte/gogrep/nodetag/nodetag.go b/vendor/github.com/quasilyte/gogrep/nodetag/nodetag.go index a4cc2ff85..8060e0ece 100644 --- a/vendor/github.com/quasilyte/gogrep/nodetag/nodetag.go +++ b/vendor/github.com/quasilyte/gogrep/nodetag/nodetag.go @@ -2,6 +2,8 @@ package nodetag import ( "go/ast" + + "golang.org/x/exp/typeparams" ) type Value int @@ -37,6 +39,7 @@ const ( ImportSpec IncDecStmt IndexExpr + IndexListExpr InterfaceType KeyValueExpr LabeledStmt @@ -126,6 +129,8 @@ func FromNode(n ast.Node) Value { return IncDecStmt case *ast.IndexExpr: return IndexExpr + case *typeparams.IndexListExpr: + return IndexListExpr case *ast.InterfaceType: return InterfaceType case *ast.KeyValueExpr: @@ -236,6 +241,8 @@ func FromString(s string) Value { return IncDecStmt case "IndexExpr": return IndexExpr + case "IndexListExpr": + return IndexListExpr case "InterfaceType": return InterfaceType case "KeyValueExpr": diff --git a/vendor/github.com/quasilyte/gogrep/operation_string.go b/vendor/github.com/quasilyte/gogrep/operation_string.go index fa093266e..23eb20062 100644 --- a/vendor/github.com/quasilyte/gogrep/operation_string.go +++ b/vendor/github.com/quasilyte/gogrep/operation_string.go @@ -30,113 +30,121 @@ func _() { _ = x[opIdent-19] _ = x[opPkg-20] _ = x[opIndexExpr-21] - _ = x[opSliceExpr-22] - _ = x[opSliceFromExpr-23] - _ = x[opSliceToExpr-24] - _ = x[opSliceFromToExpr-25] - _ = x[opSliceToCapExpr-26] - _ = x[opSliceFromToCapExpr-27] - _ = x[opFuncLit-28] - _ = x[opCompositeLit-29] - _ = x[opTypedCompositeLit-30] - _ = x[opSimpleSelectorExpr-31] - _ = x[opSelectorExpr-32] - _ = x[opTypeAssertExpr-33] - _ = x[opTypeSwitchAssertExpr-34] - _ = x[opStructType-35] - _ = x[opInterfaceType-36] - _ = x[opVoidFuncType-37] - _ = x[opFuncType-38] - _ = x[opArrayType-39] - _ = x[opSliceType-40] - _ = x[opMapType-41] - _ = x[opChanType-42] - _ = x[opKeyValueExpr-43] - _ = x[opEllipsis-44] - _ = x[opTypedEllipsis-45] - _ = x[opStarExpr-46] - _ = x[opUnaryExpr-47] - _ = x[opBinaryExpr-48] - _ = x[opParenExpr-49] - _ = x[opArgList-50] - _ = x[opSimpleArgList-51] - _ = x[opVariadicCallExpr-52] - _ = x[opNonVariadicCallExpr-53] - _ = x[opCallExpr-54] - _ = x[opAssignStmt-55] - _ = x[opMultiAssignStmt-56] - _ = x[opBranchStmt-57] - _ = x[opSimpleLabeledBranchStmt-58] - _ = x[opLabeledBranchStmt-59] - _ = x[opSimpleLabeledStmt-60] - _ = x[opLabeledStmt-61] - _ = x[opBlockStmt-62] - _ = x[opExprStmt-63] - _ = x[opGoStmt-64] - _ = x[opDeferStmt-65] - _ = x[opSendStmt-66] - _ = x[opEmptyStmt-67] - _ = x[opIncDecStmt-68] - _ = x[opReturnStmt-69] - _ = x[opIfStmt-70] - _ = x[opIfInitStmt-71] - _ = x[opIfElseStmt-72] - _ = x[opIfInitElseStmt-73] - _ = x[opIfNamedOptStmt-74] - _ = x[opIfNamedOptElseStmt-75] - _ = x[opSwitchStmt-76] - _ = x[opSwitchTagStmt-77] - _ = x[opSwitchInitStmt-78] - _ = x[opSwitchInitTagStmt-79] - _ = x[opSelectStmt-80] - _ = x[opTypeSwitchStmt-81] - _ = x[opTypeSwitchInitStmt-82] - _ = x[opCaseClause-83] - _ = x[opDefaultCaseClause-84] - _ = x[opCommClause-85] - _ = x[opDefaultCommClause-86] - _ = x[opForStmt-87] - _ = x[opForPostStmt-88] - _ = x[opForCondStmt-89] - _ = x[opForCondPostStmt-90] - _ = x[opForInitStmt-91] - _ = x[opForInitPostStmt-92] - _ = x[opForInitCondStmt-93] - _ = x[opForInitCondPostStmt-94] - _ = x[opRangeStmt-95] - _ = x[opRangeKeyStmt-96] - _ = x[opRangeKeyValueStmt-97] - _ = x[opRangeClause-98] - _ = x[opRangeHeader-99] - _ = x[opRangeKeyHeader-100] - _ = x[opRangeKeyValueHeader-101] - _ = x[opFieldList-102] - _ = x[opUnnamedField-103] - _ = x[opSimpleField-104] - _ = x[opField-105] - _ = x[opMultiField-106] - _ = x[opValueSpec-107] - _ = x[opValueInitSpec-108] - _ = x[opTypedValueInitSpec-109] - _ = x[opTypedValueSpec-110] - _ = x[opTypeSpec-111] - _ = x[opTypeAliasSpec-112] - _ = x[opFuncDecl-113] - _ = x[opMethodDecl-114] - _ = x[opFuncProtoDecl-115] - _ = x[opMethodProtoDecl-116] - _ = x[opDeclStmt-117] - _ = x[opConstDecl-118] - _ = x[opVarDecl-119] - _ = x[opTypeDecl-120] - _ = x[opAnyImportDecl-121] - _ = x[opImportDecl-122] - _ = x[opEmptyPackage-123] + _ = x[opIndexListExpr-22] + _ = x[opSliceExpr-23] + _ = x[opSliceFromExpr-24] + _ = x[opSliceToExpr-25] + _ = x[opSliceFromToExpr-26] + _ = x[opSliceToCapExpr-27] + _ = x[opSliceFromToCapExpr-28] + _ = x[opFuncLit-29] + _ = x[opCompositeLit-30] + _ = x[opTypedCompositeLit-31] + _ = x[opSimpleSelectorExpr-32] + _ = x[opSelectorExpr-33] + _ = x[opTypeAssertExpr-34] + _ = x[opTypeSwitchAssertExpr-35] + _ = x[opStructType-36] + _ = x[opInterfaceType-37] + _ = x[opEfaceType-38] + _ = x[opVoidFuncType-39] + _ = x[opGenericVoidFuncType-40] + _ = x[opFuncType-41] + _ = x[opGenericFuncType-42] + _ = x[opArrayType-43] + _ = x[opSliceType-44] + _ = x[opMapType-45] + _ = x[opChanType-46] + _ = x[opKeyValueExpr-47] + _ = x[opEllipsis-48] + _ = x[opTypedEllipsis-49] + _ = x[opStarExpr-50] + _ = x[opUnaryExpr-51] + _ = x[opBinaryExpr-52] + _ = x[opParenExpr-53] + _ = x[opArgList-54] + _ = x[opSimpleArgList-55] + _ = x[opVariadicCallExpr-56] + _ = x[opNonVariadicCallExpr-57] + _ = x[opMaybeVariadicCallExpr-58] + _ = x[opCallExpr-59] + _ = x[opAssignStmt-60] + _ = x[opMultiAssignStmt-61] + _ = x[opBranchStmt-62] + _ = x[opSimpleLabeledBranchStmt-63] + _ = x[opLabeledBranchStmt-64] + _ = x[opSimpleLabeledStmt-65] + _ = x[opLabeledStmt-66] + _ = x[opBlockStmt-67] + _ = x[opExprStmt-68] + _ = x[opGoStmt-69] + _ = x[opDeferStmt-70] + _ = x[opSendStmt-71] + _ = x[opEmptyStmt-72] + _ = x[opIncDecStmt-73] + _ = x[opReturnStmt-74] + _ = x[opIfStmt-75] + _ = x[opIfInitStmt-76] + _ = x[opIfElseStmt-77] + _ = x[opIfInitElseStmt-78] + _ = x[opIfNamedOptStmt-79] + _ = x[opIfNamedOptElseStmt-80] + _ = x[opSwitchStmt-81] + _ = x[opSwitchTagStmt-82] + _ = x[opSwitchInitStmt-83] + _ = x[opSwitchInitTagStmt-84] + _ = x[opSelectStmt-85] + _ = x[opTypeSwitchStmt-86] + _ = x[opTypeSwitchInitStmt-87] + _ = x[opCaseClause-88] + _ = x[opDefaultCaseClause-89] + _ = x[opCommClause-90] + _ = x[opDefaultCommClause-91] + _ = x[opForStmt-92] + _ = x[opForPostStmt-93] + _ = x[opForCondStmt-94] + _ = x[opForCondPostStmt-95] + _ = x[opForInitStmt-96] + _ = x[opForInitPostStmt-97] + _ = x[opForInitCondStmt-98] + _ = x[opForInitCondPostStmt-99] + _ = x[opRangeStmt-100] + _ = x[opRangeKeyStmt-101] + _ = x[opRangeKeyValueStmt-102] + _ = x[opRangeClause-103] + _ = x[opRangeHeader-104] + _ = x[opRangeKeyHeader-105] + _ = x[opRangeKeyValueHeader-106] + _ = x[opFieldList-107] + _ = x[opUnnamedField-108] + _ = x[opSimpleField-109] + _ = x[opField-110] + _ = x[opMultiField-111] + _ = x[opValueSpec-112] + _ = x[opValueInitSpec-113] + _ = x[opTypedValueInitSpec-114] + _ = x[opTypedValueSpec-115] + _ = x[opSimpleTypeSpec-116] + _ = x[opTypeSpec-117] + _ = x[opGenericTypeSpec-118] + _ = x[opTypeAliasSpec-119] + _ = x[opSimpleFuncDecl-120] + _ = x[opFuncDecl-121] + _ = x[opMethodDecl-122] + _ = x[opFuncProtoDecl-123] + _ = x[opMethodProtoDecl-124] + _ = x[opDeclStmt-125] + _ = x[opConstDecl-126] + _ = x[opVarDecl-127] + _ = x[opTypeDecl-128] + _ = x[opAnyImportDecl-129] + _ = x[opImportDecl-130] + _ = x[opEmptyPackage-131] } -const _operation_name = "InvalidNodeNamedNodeNodeSeqNamedNodeSeqOptNodeNamedOptNodeFieldNodeNamedFieldNodeMultiStmtMultiExprMultiDeclEndBasicLitStrictIntLitStrictFloatLitStrictCharLitStrictStringLitStrictComplexLitIdentPkgIndexExprSliceExprSliceFromExprSliceToExprSliceFromToExprSliceToCapExprSliceFromToCapExprFuncLitCompositeLitTypedCompositeLitSimpleSelectorExprSelectorExprTypeAssertExprTypeSwitchAssertExprStructTypeInterfaceTypeVoidFuncTypeFuncTypeArrayTypeSliceTypeMapTypeChanTypeKeyValueExprEllipsisTypedEllipsisStarExprUnaryExprBinaryExprParenExprArgListSimpleArgListVariadicCallExprNonVariadicCallExprCallExprAssignStmtMultiAssignStmtBranchStmtSimpleLabeledBranchStmtLabeledBranchStmtSimpleLabeledStmtLabeledStmtBlockStmtExprStmtGoStmtDeferStmtSendStmtEmptyStmtIncDecStmtReturnStmtIfStmtIfInitStmtIfElseStmtIfInitElseStmtIfNamedOptStmtIfNamedOptElseStmtSwitchStmtSwitchTagStmtSwitchInitStmtSwitchInitTagStmtSelectStmtTypeSwitchStmtTypeSwitchInitStmtCaseClauseDefaultCaseClauseCommClauseDefaultCommClauseForStmtForPostStmtForCondStmtForCondPostStmtForInitStmtForInitPostStmtForInitCondStmtForInitCondPostStmtRangeStmtRangeKeyStmtRangeKeyValueStmtRangeClauseRangeHeaderRangeKeyHeaderRangeKeyValueHeaderFieldListUnnamedFieldSimpleFieldFieldMultiFieldValueSpecValueInitSpecTypedValueInitSpecTypedValueSpecTypeSpecTypeAliasSpecFuncDeclMethodDeclFuncProtoDeclMethodProtoDeclDeclStmtConstDeclVarDeclTypeDeclAnyImportDeclImportDeclEmptyPackage" +const _operation_name = "InvalidNodeNamedNodeNodeSeqNamedNodeSeqOptNodeNamedOptNodeFieldNodeNamedFieldNodeMultiStmtMultiExprMultiDeclEndBasicLitStrictIntLitStrictFloatLitStrictCharLitStrictStringLitStrictComplexLitIdentPkgIndexExprIndexListExprSliceExprSliceFromExprSliceToExprSliceFromToExprSliceToCapExprSliceFromToCapExprFuncLitCompositeLitTypedCompositeLitSimpleSelectorExprSelectorExprTypeAssertExprTypeSwitchAssertExprStructTypeInterfaceTypeEfaceTypeVoidFuncTypeGenericVoidFuncTypeFuncTypeGenericFuncTypeArrayTypeSliceTypeMapTypeChanTypeKeyValueExprEllipsisTypedEllipsisStarExprUnaryExprBinaryExprParenExprArgListSimpleArgListVariadicCallExprNonVariadicCallExprMaybeVariadicCallExprCallExprAssignStmtMultiAssignStmtBranchStmtSimpleLabeledBranchStmtLabeledBranchStmtSimpleLabeledStmtLabeledStmtBlockStmtExprStmtGoStmtDeferStmtSendStmtEmptyStmtIncDecStmtReturnStmtIfStmtIfInitStmtIfElseStmtIfInitElseStmtIfNamedOptStmtIfNamedOptElseStmtSwitchStmtSwitchTagStmtSwitchInitStmtSwitchInitTagStmtSelectStmtTypeSwitchStmtTypeSwitchInitStmtCaseClauseDefaultCaseClauseCommClauseDefaultCommClauseForStmtForPostStmtForCondStmtForCondPostStmtForInitStmtForInitPostStmtForInitCondStmtForInitCondPostStmtRangeStmtRangeKeyStmtRangeKeyValueStmtRangeClauseRangeHeaderRangeKeyHeaderRangeKeyValueHeaderFieldListUnnamedFieldSimpleFieldFieldMultiFieldValueSpecValueInitSpecTypedValueInitSpecTypedValueSpecSimpleTypeSpecTypeSpecGenericTypeSpecTypeAliasSpecSimpleFuncDeclFuncDeclMethodDeclFuncProtoDeclMethodProtoDeclDeclStmtConstDeclVarDeclTypeDeclAnyImportDeclImportDeclEmptyPackage" -var _operation_index = [...]uint16{0, 7, 11, 20, 27, 39, 46, 58, 67, 81, 90, 99, 108, 111, 119, 131, 145, 158, 173, 189, 194, 197, 206, 215, 228, 239, 254, 268, 286, 293, 305, 322, 340, 352, 366, 386, 396, 409, 421, 429, 438, 447, 454, 462, 474, 482, 495, 503, 512, 522, 531, 538, 551, 567, 586, 594, 604, 619, 629, 652, 669, 686, 697, 706, 714, 720, 729, 737, 746, 756, 766, 772, 782, 792, 806, 820, 838, 848, 861, 875, 892, 902, 916, 934, 944, 961, 971, 988, 995, 1006, 1017, 1032, 1043, 1058, 1073, 1092, 1101, 1113, 1130, 1141, 1152, 1166, 1185, 1194, 1206, 1217, 1222, 1232, 1241, 1254, 1272, 1286, 1294, 1307, 1315, 1325, 1338, 1353, 1361, 1370, 1377, 1385, 1398, 1408, 1420} +var _operation_index = [...]uint16{0, 7, 11, 20, 27, 39, 46, 58, 67, 81, 90, 99, 108, 111, 119, 131, 145, 158, 173, 189, 194, 197, 206, 219, 228, 241, 252, 267, 281, 299, 306, 318, 335, 353, 365, 379, 399, 409, 422, 431, 443, 462, 470, 485, 494, 503, 510, 518, 530, 538, 551, 559, 568, 578, 587, 594, 607, 623, 642, 663, 671, 681, 696, 706, 729, 746, 763, 774, 783, 791, 797, 806, 814, 823, 833, 843, 849, 859, 869, 883, 897, 915, 925, 938, 952, 969, 979, 993, 1011, 1021, 1038, 1048, 1065, 1072, 1083, 1094, 1109, 1120, 1135, 1150, 1169, 1178, 1190, 1207, 1218, 1229, 1243, 1262, 1271, 1283, 1294, 1299, 1309, 1318, 1331, 1349, 1363, 1377, 1385, 1400, 1413, 1427, 1435, 1445, 1458, 1473, 1481, 1490, 1497, 1505, 1518, 1528, 1540} func (i operation) String() string { if i >= operation(len(_operation_index)-1) { diff --git a/vendor/github.com/quasilyte/gogrep/operations.gen.go b/vendor/github.com/quasilyte/gogrep/operations.gen.go index 8ff1fbeb7..9af838ab8 100644 --- a/vendor/github.com/quasilyte/gogrep/operations.gen.go +++ b/vendor/github.com/quasilyte/gogrep/operations.gen.go @@ -94,481 +94,518 @@ const ( // Args: x expr opIndexExpr operation = 21 + // Tag: IndexListExpr + // Args: x exprs... + opIndexListExpr operation = 22 + // Tag: SliceExpr // Args: x - opSliceExpr operation = 22 + opSliceExpr operation = 23 // Tag: SliceExpr // Args: x from // Example: x[from:] - opSliceFromExpr operation = 23 + opSliceFromExpr operation = 24 // Tag: SliceExpr // Args: x to // Example: x[:to] - opSliceToExpr operation = 24 + opSliceToExpr operation = 25 // Tag: SliceExpr // Args: x from to // Example: x[from:to] - opSliceFromToExpr operation = 25 + opSliceFromToExpr operation = 26 // Tag: SliceExpr // Args: x from cap // Example: x[:from:cap] - opSliceToCapExpr operation = 26 + opSliceToCapExpr operation = 27 // Tag: SliceExpr // Args: x from to cap // Example: x[from:to:cap] - opSliceFromToCapExpr operation = 27 + opSliceFromToCapExpr operation = 28 // Tag: FuncLit // Args: type block - opFuncLit operation = 28 + opFuncLit operation = 29 // Tag: CompositeLit // Args: elts... // Example: {elts...} - opCompositeLit operation = 29 + opCompositeLit operation = 30 // Tag: CompositeLit // Args: typ elts... // Example: typ{elts...} - opTypedCompositeLit operation = 30 + opTypedCompositeLit operation = 31 // Tag: SelectorExpr // Args: x // ValueIndex: strings | selector name - opSimpleSelectorExpr operation = 31 + opSimpleSelectorExpr operation = 32 // Tag: SelectorExpr // Args: x sel - opSelectorExpr operation = 32 + opSelectorExpr operation = 33 // Tag: TypeAssertExpr // Args: x typ - opTypeAssertExpr operation = 33 + opTypeAssertExpr operation = 34 // Tag: TypeAssertExpr // Args: x - opTypeSwitchAssertExpr operation = 34 + opTypeSwitchAssertExpr operation = 35 // Tag: StructType // Args: fields - opStructType operation = 35 + opStructType operation = 36 - // Tag: StructType + // Tag: InterfaceType // Args: fields - opInterfaceType operation = 36 + opInterfaceType operation = 37 + + // Tag: InterfaceType + opEfaceType operation = 38 // Tag: FuncType // Args: params - opVoidFuncType operation = 37 + opVoidFuncType operation = 39 + + // Tag: FuncType + // Args: typeparams params + opGenericVoidFuncType operation = 40 // Tag: FuncType // Args: params results - opFuncType operation = 38 + opFuncType operation = 41 + + // Tag: FuncType + // Args: typeparams params results + opGenericFuncType operation = 42 // Tag: ArrayType // Args: length elem - opArrayType operation = 39 + opArrayType operation = 43 // Tag: ArrayType // Args: elem - opSliceType operation = 40 + opSliceType operation = 44 // Tag: MapType // Args: key value - opMapType operation = 41 + opMapType operation = 45 // Tag: ChanType // Args: value // Value: ast.ChanDir | channel direction - opChanType operation = 42 + opChanType operation = 46 // Tag: KeyValueExpr // Args: key value - opKeyValueExpr operation = 43 + opKeyValueExpr operation = 47 // Tag: Ellipsis - opEllipsis operation = 44 + opEllipsis operation = 48 // Tag: Ellipsis // Args: type - opTypedEllipsis operation = 45 + opTypedEllipsis operation = 49 // Tag: StarExpr // Args: x - opStarExpr operation = 46 + opStarExpr operation = 50 // Tag: UnaryExpr // Args: x // Value: token.Token | unary operator - opUnaryExpr operation = 47 + opUnaryExpr operation = 51 // Tag: BinaryExpr // Args: x y // Value: token.Token | binary operator - opBinaryExpr operation = 48 + opBinaryExpr operation = 52 // Tag: ParenExpr // Args: x - opParenExpr operation = 49 + opParenExpr operation = 53 // Tag: Unknown // Args: exprs... // Example: 1, 2, 3 - opArgList operation = 50 + opArgList operation = 54 // Tag: Unknown // Like ArgList, but pattern contains no $* // Args: exprs[] // Example: 1, 2, 3 // Value: int | slice len - opSimpleArgList operation = 51 + opSimpleArgList operation = 55 // Tag: CallExpr // Args: fn args // Example: f(1, xs...) - opVariadicCallExpr operation = 52 + opVariadicCallExpr operation = 56 // Tag: CallExpr // Args: fn args // Example: f(1, xs) - opNonVariadicCallExpr operation = 53 + opNonVariadicCallExpr operation = 57 // Tag: CallExpr // Args: fn args // Example: f(1, xs) or f(1, xs...) - opCallExpr operation = 54 + // Value: int | can be variadic if len(args)>value + opMaybeVariadicCallExpr operation = 58 + + // Tag: CallExpr + // Args: fn args + // Example: f(1, xs) or f(1, xs...) + opCallExpr operation = 59 // Tag: AssignStmt // Args: lhs rhs // Example: lhs := rhs() // Value: token.Token | ':=' or '=' - opAssignStmt operation = 55 + opAssignStmt operation = 60 // Tag: AssignStmt // Args: lhs... rhs... // Example: lhs1, lhs2 := rhs() // Value: token.Token | ':=' or '=' - opMultiAssignStmt operation = 56 + opMultiAssignStmt operation = 61 // Tag: BranchStmt // Args: x // Value: token.Token | branch kind - opBranchStmt operation = 57 + opBranchStmt operation = 62 // Tag: BranchStmt // Args: x // Value: token.Token | branch kind // ValueIndex: strings | label name - opSimpleLabeledBranchStmt operation = 58 + opSimpleLabeledBranchStmt operation = 63 // Tag: BranchStmt // Args: label x // Value: token.Token | branch kind - opLabeledBranchStmt operation = 59 + opLabeledBranchStmt operation = 64 // Tag: LabeledStmt // Args: x // ValueIndex: strings | label name - opSimpleLabeledStmt operation = 60 + opSimpleLabeledStmt operation = 65 // Tag: LabeledStmt // Args: label x - opLabeledStmt operation = 61 + opLabeledStmt operation = 66 // Tag: BlockStmt // Args: body... - opBlockStmt operation = 62 + opBlockStmt operation = 67 // Tag: ExprStmt // Args: x - opExprStmt operation = 63 + opExprStmt operation = 68 // Tag: GoStmt // Args: x - opGoStmt operation = 64 + opGoStmt operation = 69 // Tag: DeferStmt // Args: x - opDeferStmt operation = 65 + opDeferStmt operation = 70 // Tag: SendStmt // Args: ch value - opSendStmt operation = 66 + opSendStmt operation = 71 // Tag: EmptyStmt - opEmptyStmt operation = 67 + opEmptyStmt operation = 72 // Tag: IncDecStmt // Args: x // Value: token.Token | '++' or '--' - opIncDecStmt operation = 68 + opIncDecStmt operation = 73 // Tag: ReturnStmt // Args: results... - opReturnStmt operation = 69 + opReturnStmt operation = 74 // Tag: IfStmt // Args: cond block // Example: if cond {} - opIfStmt operation = 70 + opIfStmt operation = 75 // Tag: IfStmt // Args: init cond block // Example: if init; cond {} - opIfInitStmt operation = 71 + opIfInitStmt operation = 76 // Tag: IfStmt // Args: cond block else // Example: if cond {} else ... - opIfElseStmt operation = 72 + opIfElseStmt operation = 77 // Tag: IfStmt // Args: init cond block else // Example: if init; cond {} else ... - opIfInitElseStmt operation = 73 + opIfInitElseStmt operation = 78 // Tag: IfStmt // Args: block // Example: if $*x {} // ValueIndex: strings | wildcard name - opIfNamedOptStmt operation = 74 + opIfNamedOptStmt operation = 79 // Tag: IfStmt // Args: block else // Example: if $*x {} else ... // ValueIndex: strings | wildcard name - opIfNamedOptElseStmt operation = 75 + opIfNamedOptElseStmt operation = 80 // Tag: SwitchStmt // Args: body... // Example: switch {} - opSwitchStmt operation = 76 + opSwitchStmt operation = 81 // Tag: SwitchStmt // Args: tag body... // Example: switch tag {} - opSwitchTagStmt operation = 77 + opSwitchTagStmt operation = 82 // Tag: SwitchStmt // Args: init body... // Example: switch init; {} - opSwitchInitStmt operation = 78 + opSwitchInitStmt operation = 83 // Tag: SwitchStmt // Args: init tag body... // Example: switch init; tag {} - opSwitchInitTagStmt operation = 79 + opSwitchInitTagStmt operation = 84 // Tag: SelectStmt // Args: body... - opSelectStmt operation = 80 + opSelectStmt operation = 85 // Tag: TypeSwitchStmt // Args: x block // Example: switch x.(type) {} - opTypeSwitchStmt operation = 81 + opTypeSwitchStmt operation = 86 // Tag: TypeSwitchStmt // Args: init x block // Example: switch init; x.(type) {} - opTypeSwitchInitStmt operation = 82 + opTypeSwitchInitStmt operation = 87 // Tag: CaseClause // Args: values... body... - opCaseClause operation = 83 + opCaseClause operation = 88 // Tag: CaseClause // Args: body... - opDefaultCaseClause operation = 84 + opDefaultCaseClause operation = 89 // Tag: CommClause // Args: comm body... - opCommClause operation = 85 + opCommClause operation = 90 // Tag: CommClause // Args: body... - opDefaultCommClause operation = 86 + opDefaultCommClause operation = 91 // Tag: ForStmt // Args: blocl // Example: for {} - opForStmt operation = 87 + opForStmt operation = 92 // Tag: ForStmt // Args: post block // Example: for ; ; post {} - opForPostStmt operation = 88 + opForPostStmt operation = 93 // Tag: ForStmt // Args: cond block // Example: for ; cond; {} - opForCondStmt operation = 89 + opForCondStmt operation = 94 // Tag: ForStmt // Args: cond post block // Example: for ; cond; post {} - opForCondPostStmt operation = 90 + opForCondPostStmt operation = 95 // Tag: ForStmt // Args: init block // Example: for init; ; {} - opForInitStmt operation = 91 + opForInitStmt operation = 96 // Tag: ForStmt // Args: init post block // Example: for init; ; post {} - opForInitPostStmt operation = 92 + opForInitPostStmt operation = 97 // Tag: ForStmt // Args: init cond block // Example: for init; cond; {} - opForInitCondStmt operation = 93 + opForInitCondStmt operation = 98 // Tag: ForStmt // Args: init cond post block // Example: for init; cond; post {} - opForInitCondPostStmt operation = 94 + opForInitCondPostStmt operation = 99 // Tag: RangeStmt // Args: x block // Example: for range x {} - opRangeStmt operation = 95 + opRangeStmt operation = 100 // Tag: RangeStmt // Args: key x block // Example: for key := range x {} // Value: token.Token | ':=' or '=' - opRangeKeyStmt operation = 96 + opRangeKeyStmt operation = 101 // Tag: RangeStmt // Args: key value x block // Example: for key, value := range x {} // Value: token.Token | ':=' or '=' - opRangeKeyValueStmt operation = 97 + opRangeKeyValueStmt operation = 102 // Tag: RangeStmt // Args: x // Example: range x - opRangeClause operation = 98 + opRangeClause operation = 103 // Tag: RangeStmt // Args: x // Example: for range x - opRangeHeader operation = 99 + opRangeHeader operation = 104 // Tag: RangeStmt // Args: key x // Example: for key := range x // Value: token.Token | ':=' or '=' - opRangeKeyHeader operation = 100 + opRangeKeyHeader operation = 105 // Tag: RangeStmt // Args: key value x // Example: for key, value := range x // Value: token.Token | ':=' or '=' - opRangeKeyValueHeader operation = 101 + opRangeKeyValueHeader operation = 106 // Tag: Unknown // Args: fields... - opFieldList operation = 102 + opFieldList operation = 107 // Tag: Unknown // Args: typ // Example: type - opUnnamedField operation = 103 + opUnnamedField operation = 108 // Tag: Unknown // Args: typ // Example: name type // ValueIndex: strings | field name - opSimpleField operation = 104 + opSimpleField operation = 109 // Tag: Unknown // Args: name typ // Example: $name type - opField operation = 105 + opField operation = 110 // Tag: Unknown // Args: names... typ // Example: name1, name2 type - opMultiField operation = 106 + opMultiField operation = 111 // Tag: ValueSpec // Args: value - opValueSpec operation = 107 + opValueSpec operation = 112 // Tag: ValueSpec // Args: lhs... rhs... // Example: lhs = rhs - opValueInitSpec operation = 108 + opValueInitSpec operation = 113 // Tag: ValueSpec // Args: lhs... type rhs... // Example: lhs typ = rhs - opTypedValueInitSpec operation = 109 + opTypedValueInitSpec operation = 114 // Tag: ValueSpec // Args: lhs... type // Example: lhs typ - opTypedValueSpec operation = 110 + opTypedValueSpec operation = 115 + + // Tag: TypeSpec + // Args: type + // Example: name type + // ValueIndex: strings | type name + opSimpleTypeSpec operation = 116 // Tag: TypeSpec // Args: name type // Example: name type - opTypeSpec operation = 111 + opTypeSpec operation = 117 + + // Tag: TypeSpec + // Args: name typeparasm type + // Example: name[typeparams] type + opGenericTypeSpec operation = 118 // Tag: TypeSpec // Args: name type // Example: name = type - opTypeAliasSpec operation = 112 + opTypeAliasSpec operation = 119 + + // Tag: FuncDecl + // Args: type block + // ValueIndex: strings | field name + opSimpleFuncDecl operation = 120 // Tag: FuncDecl // Args: name type block - opFuncDecl operation = 113 + opFuncDecl operation = 121 // Tag: FuncDecl // Args: recv name type block - opMethodDecl operation = 114 + opMethodDecl operation = 122 // Tag: FuncDecl // Args: name type - opFuncProtoDecl operation = 115 + opFuncProtoDecl operation = 123 // Tag: FuncDecl // Args: recv name type - opMethodProtoDecl operation = 116 + opMethodProtoDecl operation = 124 // Tag: DeclStmt // Args: decl - opDeclStmt operation = 117 + opDeclStmt operation = 125 // Tag: GenDecl // Args: valuespecs... - opConstDecl operation = 118 + opConstDecl operation = 126 // Tag: GenDecl // Args: valuespecs... - opVarDecl operation = 119 + opVarDecl operation = 127 // Tag: GenDecl // Args: typespecs... - opTypeDecl operation = 120 + opTypeDecl operation = 128 // Tag: GenDecl - opAnyImportDecl operation = 121 + opAnyImportDecl operation = 129 // Tag: GenDecl // Args: importspecs... - opImportDecl operation = 122 + opImportDecl operation = 130 // Tag: File // Args: name - opEmptyPackage operation = 123 + opEmptyPackage operation = 131 ) type operationInfo struct { @@ -751,6 +788,14 @@ var operationInfoTable = [256]operationInfo{ VariadicMap: 0, // 0 SliceIndex: -1, }, + opIndexListExpr: { + Tag: nodetag.IndexListExpr, + NumArgs: 2, + ValueKind: emptyValue, + ExtraValueKind: emptyValue, + VariadicMap: 2, // 10 + SliceIndex: -1, + }, opSliceExpr: { Tag: nodetag.SliceExpr, NumArgs: 1, @@ -864,13 +909,21 @@ var operationInfoTable = [256]operationInfo{ SliceIndex: -1, }, opInterfaceType: { - Tag: nodetag.StructType, + Tag: nodetag.InterfaceType, NumArgs: 1, ValueKind: emptyValue, ExtraValueKind: emptyValue, VariadicMap: 0, // 0 SliceIndex: -1, }, + opEfaceType: { + Tag: nodetag.InterfaceType, + NumArgs: 0, + ValueKind: emptyValue, + ExtraValueKind: emptyValue, + VariadicMap: 0, // 0 + SliceIndex: -1, + }, opVoidFuncType: { Tag: nodetag.FuncType, NumArgs: 1, @@ -879,6 +932,14 @@ var operationInfoTable = [256]operationInfo{ VariadicMap: 0, // 0 SliceIndex: -1, }, + opGenericVoidFuncType: { + Tag: nodetag.FuncType, + NumArgs: 2, + ValueKind: emptyValue, + ExtraValueKind: emptyValue, + VariadicMap: 0, // 0 + SliceIndex: -1, + }, opFuncType: { Tag: nodetag.FuncType, NumArgs: 2, @@ -887,6 +948,14 @@ var operationInfoTable = [256]operationInfo{ VariadicMap: 0, // 0 SliceIndex: -1, }, + opGenericFuncType: { + Tag: nodetag.FuncType, + NumArgs: 3, + ValueKind: emptyValue, + ExtraValueKind: emptyValue, + VariadicMap: 0, // 0 + SliceIndex: -1, + }, opArrayType: { Tag: nodetag.ArrayType, NumArgs: 2, @@ -1007,6 +1076,14 @@ var operationInfoTable = [256]operationInfo{ VariadicMap: 0, // 0 SliceIndex: -1, }, + opMaybeVariadicCallExpr: { + Tag: nodetag.CallExpr, + NumArgs: 2, + ValueKind: intValue, + ExtraValueKind: emptyValue, + VariadicMap: 0, // 0 + SliceIndex: -1, + }, opCallExpr: { Tag: nodetag.CallExpr, NumArgs: 2, @@ -1463,6 +1540,14 @@ var operationInfoTable = [256]operationInfo{ VariadicMap: 1, // 1 SliceIndex: -1, }, + opSimpleTypeSpec: { + Tag: nodetag.TypeSpec, + NumArgs: 1, + ValueKind: emptyValue, + ExtraValueKind: stringValue, + VariadicMap: 0, // 0 + SliceIndex: -1, + }, opTypeSpec: { Tag: nodetag.TypeSpec, NumArgs: 2, @@ -1471,6 +1556,14 @@ var operationInfoTable = [256]operationInfo{ VariadicMap: 0, // 0 SliceIndex: -1, }, + opGenericTypeSpec: { + Tag: nodetag.TypeSpec, + NumArgs: 3, + ValueKind: emptyValue, + ExtraValueKind: emptyValue, + VariadicMap: 0, // 0 + SliceIndex: -1, + }, opTypeAliasSpec: { Tag: nodetag.TypeSpec, NumArgs: 2, @@ -1479,6 +1572,14 @@ var operationInfoTable = [256]operationInfo{ VariadicMap: 0, // 0 SliceIndex: -1, }, + opSimpleFuncDecl: { + Tag: nodetag.FuncDecl, + NumArgs: 2, + ValueKind: emptyValue, + ExtraValueKind: stringValue, + VariadicMap: 0, // 0 + SliceIndex: -1, + }, opFuncDecl: { Tag: nodetag.FuncDecl, NumArgs: 3, diff --git a/vendor/github.com/quasilyte/gogrep/parse.go b/vendor/github.com/quasilyte/gogrep/parse.go index f70c4a8f4..3c6854bda 100644 --- a/vendor/github.com/quasilyte/gogrep/parse.go +++ b/vendor/github.com/quasilyte/gogrep/parse.go @@ -146,7 +146,7 @@ func parseDetectingNode(fset *token.FileSet, src string) (ast.Node, error) { } if strings.HasPrefix(src, "for ") && !strings.HasSuffix(src, "}") { asStmts := execTmpl(tmplStmts, src+"{}") - f, err := parser.ParseFile(fset, "", asStmts, 0) + f, err := parser.ParseFile(fset, "", asStmts, parser.SkipObjectResolution) if err == nil && noBadNodes(f) { bl := f.Decls[0].(*ast.FuncDecl).Body if len(bl.List) == 1 { @@ -156,9 +156,9 @@ func parseDetectingNode(fset *token.FileSet, src string) (ast.Node, error) { } // try as a block; otherwise blocks might be mistaken for composite - // literals further below + // literals further below\ asBlock := execTmpl(tmplBlock, src) - if f, err := parser.ParseFile(fset, "", asBlock, 0); err == nil && noBadNodes(f) { + if f, err := parser.ParseFile(fset, "", asBlock, parser.SkipObjectResolution); err == nil && noBadNodes(f) { bl := f.Decls[0].(*ast.FuncDecl).Body if len(bl.List) == 1 { ifs := bl.List[0].(*ast.IfStmt) @@ -168,24 +168,28 @@ func parseDetectingNode(fset *token.FileSet, src string) (ast.Node, error) { // then as value expressions asExprs := execTmpl(tmplExprs, src) - if f, err := parser.ParseFile(fset, "", asExprs, 0); err == nil && noBadNodes(f) { + if f, err := parser.ParseFile(fset, "", asExprs, parser.SkipObjectResolution); err == nil && noBadNodes(f) { vs := f.Decls[0].(*ast.GenDecl).Specs[0].(*ast.ValueSpec) cl := vs.Values[0].(*ast.CompositeLit) if len(cl.Elts) == 1 { return cl.Elts[0], nil } - return ExprSlice(cl.Elts), nil + slice := &NodeSlice{} + slice.assignExprSlice(cl.Elts) + return slice, nil } // then try as statements asStmts := execTmpl(tmplStmts, src) - f, err := parser.ParseFile(fset, "", asStmts, 0) + f, err := parser.ParseFile(fset, "", asStmts, parser.SkipObjectResolution) if err == nil && noBadNodes(f) { bl := f.Decls[0].(*ast.FuncDecl).Body if len(bl.List) == 1 { return bl.List[0], nil } - return stmtSlice(bl.List), nil + slice := &NodeSlice{} + slice.assignStmtSlice(bl.List) + return slice, nil } // Statements is what covers most cases, so it will give // the best overall error message. Show positions @@ -199,7 +203,9 @@ func parseDetectingNode(fset *token.FileSet, src string) (ast.Node, error) { if len(f.Decls) == 1 { return f.Decls[0], nil } - return declSlice(f.Decls), nil + slice := &NodeSlice{} + slice.assignDeclSlice(f.Decls) + return slice, nil } // try as a whole file diff --git a/vendor/github.com/quasilyte/gogrep/slices.go b/vendor/github.com/quasilyte/gogrep/slices.go index 13775a818..fb969b51b 100644 --- a/vendor/github.com/quasilyte/gogrep/slices.go +++ b/vendor/github.com/quasilyte/gogrep/slices.go @@ -5,54 +5,146 @@ import ( "go/token" ) -type NodeSlice interface { - At(i int) ast.Node - Len() int - slice(from, to int) NodeSlice - ast.Node -} +type NodeSliceKind uint32 + +const ( + ExprNodeSlice NodeSliceKind = iota + StmtNodeSlice + FieldNodeSlice + IdentNodeSlice + SpecNodeSlice + DeclNodeSlice +) + +type NodeSlice struct { + Kind NodeSliceKind -type ( - ExprSlice []ast.Expr + exprSlice []ast.Expr stmtSlice []ast.Stmt fieldSlice []*ast.Field identSlice []*ast.Ident specSlice []ast.Spec declSlice []ast.Decl -) +} + +func (s *NodeSlice) GetExprSlice() []ast.Expr { return s.exprSlice } +func (s *NodeSlice) GetStmtSlice() []ast.Stmt { return s.stmtSlice } +func (s *NodeSlice) GetFieldSlice() []*ast.Field { return s.fieldSlice } +func (s *NodeSlice) GetIdentSlice() []*ast.Ident { return s.identSlice } +func (s *NodeSlice) GetSpecSlice() []ast.Spec { return s.specSlice } +func (s *NodeSlice) GetDeclSlice() []ast.Decl { return s.declSlice } + +func (s *NodeSlice) assignExprSlice(xs []ast.Expr) { + s.Kind = ExprNodeSlice + s.exprSlice = xs +} + +func (s *NodeSlice) assignStmtSlice(xs []ast.Stmt) { + s.Kind = StmtNodeSlice + s.stmtSlice = xs +} + +func (s *NodeSlice) assignFieldSlice(xs []*ast.Field) { + s.Kind = FieldNodeSlice + s.fieldSlice = xs +} + +func (s *NodeSlice) assignIdentSlice(xs []*ast.Ident) { + s.Kind = IdentNodeSlice + s.identSlice = xs +} + +func (s *NodeSlice) assignSpecSlice(xs []ast.Spec) { + s.Kind = SpecNodeSlice + s.specSlice = xs +} + +func (s *NodeSlice) assignDeclSlice(xs []ast.Decl) { + s.Kind = DeclNodeSlice + s.declSlice = xs +} + +func (s *NodeSlice) Len() int { + switch s.Kind { + case ExprNodeSlice: + return len(s.exprSlice) + case StmtNodeSlice: + return len(s.stmtSlice) + case FieldNodeSlice: + return len(s.fieldSlice) + case IdentNodeSlice: + return len(s.identSlice) + case SpecNodeSlice: + return len(s.specSlice) + default: + return len(s.declSlice) + } +} -func (l ExprSlice) Len() int { return len(l) } -func (l ExprSlice) At(i int) ast.Node { return l[i] } -func (l ExprSlice) slice(i, j int) NodeSlice { return l[i:j] } -func (l ExprSlice) Pos() token.Pos { return l[0].Pos() } -func (l ExprSlice) End() token.Pos { return l[len(l)-1].End() } - -func (l stmtSlice) Len() int { return len(l) } -func (l stmtSlice) At(i int) ast.Node { return l[i] } -func (l stmtSlice) slice(i, j int) NodeSlice { return l[i:j] } -func (l stmtSlice) Pos() token.Pos { return l[0].Pos() } -func (l stmtSlice) End() token.Pos { return l[len(l)-1].End() } - -func (l fieldSlice) Len() int { return len(l) } -func (l fieldSlice) At(i int) ast.Node { return l[i] } -func (l fieldSlice) slice(i, j int) NodeSlice { return l[i:j] } -func (l fieldSlice) Pos() token.Pos { return l[0].Pos() } -func (l fieldSlice) End() token.Pos { return l[len(l)-1].End() } - -func (l identSlice) Len() int { return len(l) } -func (l identSlice) At(i int) ast.Node { return l[i] } -func (l identSlice) slice(i, j int) NodeSlice { return l[i:j] } -func (l identSlice) Pos() token.Pos { return l[0].Pos() } -func (l identSlice) End() token.Pos { return l[len(l)-1].End() } - -func (l specSlice) Len() int { return len(l) } -func (l specSlice) At(i int) ast.Node { return l[i] } -func (l specSlice) slice(i, j int) NodeSlice { return l[i:j] } -func (l specSlice) Pos() token.Pos { return l[0].Pos() } -func (l specSlice) End() token.Pos { return l[len(l)-1].End() } - -func (l declSlice) Len() int { return len(l) } -func (l declSlice) At(i int) ast.Node { return l[i] } -func (l declSlice) slice(i, j int) NodeSlice { return l[i:j] } -func (l declSlice) Pos() token.Pos { return l[0].Pos() } -func (l declSlice) End() token.Pos { return l[len(l)-1].End() } +func (s *NodeSlice) At(i int) ast.Node { + switch s.Kind { + case ExprNodeSlice: + return s.exprSlice[i] + case StmtNodeSlice: + return s.stmtSlice[i] + case FieldNodeSlice: + return s.fieldSlice[i] + case IdentNodeSlice: + return s.identSlice[i] + case SpecNodeSlice: + return s.specSlice[i] + default: + return s.declSlice[i] + } +} + +func (s *NodeSlice) SliceInto(dst *NodeSlice, i, j int) { + switch s.Kind { + case ExprNodeSlice: + dst.assignExprSlice(s.exprSlice[i:j]) + case StmtNodeSlice: + dst.assignStmtSlice(s.stmtSlice[i:j]) + case FieldNodeSlice: + dst.assignFieldSlice(s.fieldSlice[i:j]) + case IdentNodeSlice: + dst.assignIdentSlice(s.identSlice[i:j]) + case SpecNodeSlice: + dst.assignSpecSlice(s.specSlice[i:j]) + default: + dst.assignDeclSlice(s.declSlice[i:j]) + } +} + +func (s *NodeSlice) Pos() token.Pos { + switch s.Kind { + case ExprNodeSlice: + return s.exprSlice[0].Pos() + case StmtNodeSlice: + return s.stmtSlice[0].Pos() + case FieldNodeSlice: + return s.fieldSlice[0].Pos() + case IdentNodeSlice: + return s.identSlice[0].Pos() + case SpecNodeSlice: + return s.specSlice[0].Pos() + default: + return s.declSlice[0].Pos() + } +} + +func (s *NodeSlice) End() token.Pos { + switch s.Kind { + case ExprNodeSlice: + return s.exprSlice[len(s.exprSlice)-1].End() + case StmtNodeSlice: + return s.stmtSlice[len(s.stmtSlice)-1].End() + case FieldNodeSlice: + return s.fieldSlice[len(s.fieldSlice)-1].End() + case IdentNodeSlice: + return s.identSlice[len(s.identSlice)-1].End() + case SpecNodeSlice: + return s.specSlice[len(s.specSlice)-1].End() + default: + return s.declSlice[len(s.declSlice)-1].End() + } +} diff --git a/vendor/github.com/quasilyte/regex/syntax/go.mod b/vendor/github.com/quasilyte/regex/syntax/go.mod deleted file mode 100644 index 2a4e1f33b..000000000 --- a/vendor/github.com/quasilyte/regex/syntax/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/quasilyte/regex/syntax - -go 1.14 diff --git a/vendor/github.com/quasilyte/regex/syntax/parser.go b/vendor/github.com/quasilyte/regex/syntax/parser.go index c540ac593..f1c154f31 100644 --- a/vendor/github.com/quasilyte/regex/syntax/parser.go +++ b/vendor/github.com/quasilyte/regex/syntax/parser.go @@ -484,10 +484,10 @@ func (p *Parser) newPCRE(source string) (*RegexpPCRE, error) { j += delimLen pcre := &RegexpPCRE{ - Pattern: source[1:j], + Pattern: source[delimLen:j], Source: source, Delim: [2]byte{delim, endDelim}, - Modifiers: source[j+1:], + Modifiers: source[j+delimLen:], } return pcre, nil } diff --git a/vendor/github.com/quasilyte/stdinfo/go.mod b/vendor/github.com/quasilyte/stdinfo/go.mod deleted file mode 100644 index 147e97030..000000000 --- a/vendor/github.com/quasilyte/stdinfo/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/quasilyte/stdinfo - -go 1.17 -- cgit mrf-deployment