callgraph

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultOutput       = "./default.png"
	DefaultCache        = "./cachePath.json"
	CallGraphTypeStatic = "static"
	CallGraphTypeCha    = "cha"
	CallGraphTypeRta    = "rta" // 默认使用
	CallGraphTypeVta    = "vta"
)

常量定义

Variables

This section is empty.

Functions

This section is empty.

Types

type DBStore

type DBStore interface {
	// SaveFuncNode 保存函数节点
	SaveFuncNode(node *FuncNode) error

	// SaveFuncEdge 保存函数调用关系
	SaveFuncEdge(edge *FuncEdge) error

	// GetFuncNodeByKey 根据Key获取函数节点
	GetFuncNodeByKey(key string) (*FuncNode, error)

	// GetCallerEdges 获取调用该函数的所有边
	GetCallerEdges(calleeKey string) ([]*FuncNode, error)

	// GetCalleeEdges 获取该函数调用的所有边
	GetCalleeEdges(callerKey string) ([]*FuncNode, error)
}

添加用于存储的方法

type FuncEdge

type FuncEdge struct {
	CallerKey string `json:"caller_key"`
	CalleeKey string `json:"callee_key"`
}

type FuncNode

type FuncNode struct {
	Key      string   `json:"key"`      // 唯一标识
	Pkg      string   `json:"pkg"`      // 包名
	Name     string   `json:"name"`     // 函数名
	Parent   []string `json:"parent"`   // 父节点索引
	Children []string `json:"children"` // 子节点索引
}

FuncNode 表示函数节点

type ProgramAnalysis

type ProgramAnalysis struct {
	Dir string // 项目目录
	// contains filtered or unexported fields
}

ProgramAnalysis 定义程序分析的主要结构

func NewProgramAnalysis

func NewProgramAnalysis(dir string, logger log.Logger, data DBStore, opts ...ProgramOption) *ProgramAnalysis

NewProgramAnalysis 创建新的程序分析实例

func (*ProgramAnalysis) Analysis

func (p *ProgramAnalysis) Analysis() error

Analysis 执行程序分析

func (*ProgramAnalysis) GetMainPackage

func (p *ProgramAnalysis) GetMainPackage(pkgs []*ssa.Package) ([]*ssa.Package, error)

func (*ProgramAnalysis) GetModuleName

func (p *ProgramAnalysis) GetModuleName() (string, error)

GetModuleName 从go.mod文件中获取模块名

func (*ProgramAnalysis) GetNode

func (p *ProgramAnalysis) GetNode(key string) *FuncNode

GetNode 获取节点

func (*ProgramAnalysis) NodeIsExist

func (p *ProgramAnalysis) NodeIsExist(key string) bool

func (*ProgramAnalysis) SaveData

func (p *ProgramAnalysis) SaveData(ctx context.Context) error

SaveData 异步保存数据到数据库

func (*ProgramAnalysis) SetTree

func (p *ProgramAnalysis) SetTree() error

SetTree

@Description: 生成项目整体的语法树
@receiver p
@return error

type ProgramOption

type ProgramOption func(p *ProgramAnalysis)

ProgramOption 定义程序分析的配置选项函数类型

func WithAlgo

func WithAlgo(algo string) ProgramOption

func WithCacheDir

func WithCacheDir(cache string) ProgramOption

func WithCacheFlag

func WithCacheFlag(flag bool) ProgramOption

func WithIgnorePaths

func WithIgnorePaths(ignorePath string) ProgramOption

func WithOnlyPkg

func WithOnlyPkg(onlyPkg string) ProgramOption

func WithOutputDir

func WithOutputDir(output string) ProgramOption

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳