analysis

package
v1.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIfTargetFunction

func CheckIfTargetFunction(_ context.Context, call *ssa.CallCommon, opt *Option) (ssa.Value, bool)

func Walk

func Walk(cg *CallGraph, in *Node, fn func(node *Node) bool)

Types

type AnalyzeMode

type AnalyzeMode int

type CallGraph

type CallGraph struct {
	Nodes map[string]*Node
}

func BuildCallGraph

func BuildCallGraph(pkg *ssa.Package, qrs []*QueryResult) (*CallGraph, error)

func (*CallGraph) AddFuncCallEdge

func (r *CallGraph) AddFuncCallEdge(callerFunc, calleeFunc *ssa.Function)

func (*CallGraph) AddNode

func (r *CallGraph) AddNode(n *Node)

func (*CallGraph) AddQueryEdge

func (r *CallGraph) AddQueryEdge(callerFunc *ssa.Function, calleeTable string, sqlValue *SqlValue)

type Edge

type Edge struct {
	SqlValue *SqlValue
	Caller   string
	Callee   string
}

func (*Edge) IsFuncCall

func (e *Edge) IsFuncCall() bool

func (*Edge) IsQuery

func (e *Edge) IsQuery() bool

type FilterExpr added in v1.1.0

type FilterExpr struct {
	// contains filtered or unexported fields
}

func NewFilterExpr added in v1.1.0

func NewFilterExpr(code string) (*FilterExpr, error)

func (*FilterExpr) Run added in v1.1.0

func (f *FilterExpr) Run(q *sql.Query, pos *ssautil.Posx) (bool, error)

type Node

type Node struct {
	Name string
	In   []*Edge
	Out  []*Edge
	Func *ssa.Function
}

func TopologicalSort

func TopologicalSort(nodes map[string]*Node) []*Node

func (*Node) IsFunc

func (n *Node) IsFunc() bool

func (*Node) IsNotRoot

func (n *Node) IsNotRoot() bool

func (*Node) IsRoot

func (n *Node) IsRoot() bool

func (*Node) IsTable

func (n *Node) IsTable() bool

type NodeWithPackage

type NodeWithPackage struct {
	ast.Node
	Package *types.Package
}

type Option

type Option struct {
	Code            string
	AdditionalFuncs []string
	// contains filtered or unexported fields
}

func NewOption added in v1.1.0

func NewOption(code string, additionalFuncs []string) *Option

func (*Option) AdditionalFuncSlice

func (o *Option) AdditionalFuncSlice() []TargetCall

func (*Option) Filter

func (o *Option) Filter(q *sql.Query, pos *ssautil.Posx) bool

func (*Option) IsCommented

func (o *Option) IsCommented(pkg *types.Package, pos ...token.Pos) bool

type QueryResult

type QueryResult struct {
	*sql.QueryGroup
	Posx        *ssautil.Posx
	FromComment bool
}

func NewQueryResult

func NewQueryResult(pos *ssautil.Posx) *QueryResult

func (*QueryResult) Append

func (qr *QueryResult) Append(qs ...*sql.Query)

func (*QueryResult) Compare

func (qr *QueryResult) Compare(other *QueryResult) int

type QueryResults

type QueryResults []*QueryResult

func Analyze

func Analyze(ctx context.Context, dir, pattern string, opt *Option) (QueryResults, map[string]*CallGraph, error)

func AnalyzeFunc

func AnalyzeFunc(ctx context.Context, fn *ssa.Function, opt *Option) QueryResults

func ExtractQuery

func ExtractQuery(ctx context.Context, ssaProg *buildssa.SSA, files []*ast.File, opt *Option) (QueryResults, error)

ExtractQuery extracts queries from the given package.

func (QueryResults) AllTableNames

func (qrs QueryResults) AllTableNames() []string

func (QueryResults) AllTables

func (qrs QueryResults) AllTables() []*sql.Table

type SqlValue

type SqlValue struct {
	Kind   sql.QueryKind
	RawSQL string
}

type TargetCall added in v1.0.2

type TargetCall struct {
	NamePattern string // function name pattern
	ArgIndex    int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL