metadata

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

Metadata Package

This package provides functionality for generating metadata from Go source code, including function calls, assignments, and type information.

Features

  • Function Analysis: Extract function signatures, calls, and assignments
  • Type Information: Analyze structs, interfaces, and generic types
  • Call Graph: Build dependency graphs between functions
  • Package Analysis: Process multiple packages and their relationships

Usage

import "github.com/ehabterra/apispec/internal/metadata"

// Generate metadata from Go packages
meta := metadata.GenerateMetadata(pkgsMetadata, fileToInfo, importPaths, fset)

// Write metadata to YAML file
err := metadata.WriteMetadata(meta, "output.yaml")

Architecture

The package consists of several key components:

  • Generator: Main entry point for metadata generation
  • Analyzer: Core analysis logic for Go AST nodes
  • IO: YAML serialization and file operations
  • Types: Data structures for metadata representation

Testing

Tests use the packagestest package to create temporary Go modules for testing various scenarios:

  • Simple functions with variables and imports
  • Struct types with methods and interfaces
  • Generic functions and types
  • Constants and variables
  • Complex call graphs with method chains
  • Multi-package dependencies

Each test validates the generated metadata against expected results without generating persistent files.

Documentation

Index

Constants

View Source
const (
	KindIdent           = "ident"
	KindLiteral         = "literal"
	KindSelector        = "selector"
	KindCall            = "call"
	KindTypeConversion  = "type_conversion"
	KindRaw             = "raw"
	KindString          = "string"
	KindInt             = "int"
	KindFloat64         = "float64"
	KindRune            = "rune"
	KindComplex128      = "complex128"
	KindFuncLit         = "func_lit"
	KindUnary           = "unary"
	KindBinary          = "binary"
	KindIndex           = "index"
	KindIndexList       = "index_list"
	KindStar            = "star"
	KindParen           = "paren"
	KindArrayType       = "array_type"
	KindSlice           = "slice"
	KindCompositeLit    = "composite_lit"
	KindKeyValue        = "key_value"
	KindTypeAssert      = "type_assert"
	KindChanType        = "chan_type"
	KindMapType         = "map_type"
	KindStructType      = "struct_type"
	KindInterfaceType   = "interface_type"
	KindInterfaceMethod = "interface_method"
	KindEmbed           = "embed"
	KindField           = "field"
	KindEllipsis        = "ellipsis"
	KindFuncType        = "func_type"
	KindFuncResults     = "func_results"
)
View Source
const MainFunc = "main"
View Source
const MaxSelfCallingDepth = 50

Variables

This section is empty.

Functions

func BuildFuncMap

func BuildFuncMap(pkgs map[string]map[string]*ast.File) map[string]*ast.FuncDecl

BuildFuncMap creates a map of function names to their declarations.

func CallArgToString

func CallArgToString(arg CallArgument) string

CallArgToString converts a CallArgument to its string representation

func DefaultImportName

func DefaultImportName(importPath string) string

DefaultImportName returns the default import name for an import path (last non-version segment)

func ExprToString

func ExprToString(expr ast.Expr) string

ExprToString returns a string representation of an expression.

func ExtractGenericTypes

func ExtractGenericTypes(input string) []string

ExtractGenericTypes extracts the values from generic type parameters in a string Supports two formats: 1. "path.Function[TParam1=Value1,TParam2=Value2]" -> extracts values after '=' 2. "path.Function[Type1,Type2,Type3]" -> extracts all comma-separated types Returns: []string containing the extracted types

func IsSubset

func IsSubset(a, b []string) bool

IsSubset checks if array 'a' is a subset of array 'b' Returns true if all elements in 'a' exist in 'b'

func LoadYAML

func LoadYAML(filename string, data interface{}) error

LoadYAML loads data from a YAML file

func WriteMetadata

func WriteMetadata(metadata *Metadata, filename string) error

WriteMetadata writes metadata to a YAML file

func WriteSplitMetadata

func WriteSplitMetadata(metadata *Metadata, baseFilename string) error

WriteSplitMetadata writes metadata split into 3 separate files

func WriteYAML

func WriteYAML(data interface{}, filename string) error

WriteYAML writes any data to a YAML file

Types

type ArgumentProcessor

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

ArgumentProcessor handles argument processing and classification

type ArgumentType

type ArgumentType int

ArgumentType represents the classification of an argument

const (
	ArgTypeDirectCallee ArgumentType = iota // Direct function call (existing callee)
	ArgTypeFunctionCall                     // Function call as argument
	ArgTypeVariable                         // Variable reference
	ArgTypeLiteral                          // Literal value
	ArgTypeSelector                         // Field/method selector
	ArgTypeComplex                          // Complex expression
	ArgTypeUnary                            // Unary expression (*ptr, &val)
	ArgTypeBinary                           // Binary expression (a + b)
	ArgTypeIndex                            // Index expression (arr[i])
	ArgTypeComposite                        // Composite literal (struct{})
	ArgTypeTypeAssert                       // Type assertion (val.(type))
)

type Assignment

type Assignment struct {
	VariableName int          `yaml:"variable_name,omitempty"`
	Pkg          int          `yaml:"pkg,omitempty"`
	ConcreteType int          `yaml:"concrete_type,omitempty"`
	Position     int          `yaml:"position,omitempty"`
	Scope        int          `yaml:"scope,omitempty"`
	Value        CallArgument `yaml:"value,omitempty"`
	Lhs          CallArgument `yaml:"lhs,omitempty"`
	Func         int          `yaml:"func,omitempty"`

	// For assignments from function calls
	CalleeFunc  string `yaml:"callee_func,omitempty"`
	CalleePkg   string `yaml:"callee_pkg,omitempty"`
	ReturnIndex int    `yaml:"return_index,omitempty"`
}

Assignment represents a variable assignment

type AssignmentKey

type AssignmentKey struct {
	Name      string
	Pkg       string
	Type      string
	Container string
}

AssignmentKey represents a key for assignment relationships

func (AssignmentKey) String

func (k AssignmentKey) String() string
type AssignmentLink struct {
	AssignmentKey AssignmentKey
	Assignment    *Assignment
	Edge          *CallGraphEdge
}

AssignmentLink represents a link between an assignment and a call graph edge

type Call

type Call struct {
	Meta *Metadata      `yaml:"-"`
	Edge *CallGraphEdge `yaml:"-"`

	// Keep existing fields for serialization
	Name     int `yaml:"name,omitempty"`
	Pkg      int `yaml:"pkg,omitempty"`
	Position int `yaml:"position,omitempty"`
	RecvType int `yaml:"recv_type,omitempty"`
	// contains filtered or unexported fields
}

func (*Call) BaseID

func (c *Call) BaseID() string

BaseID returns the base identifier without position or generics

func (*Call) GenericID

func (c *Call) GenericID() string

GenericID returns the identifier with generic type parameters but no position

func (*Call) ID

func (c *Call) ID() string

ID returns different types of identifiers based on context

func (*Call) InstanceID

func (c *Call) InstanceID() string

InstanceID returns the full instance identifier with position and generics

type CallArgument

type CallArgument struct {
	Kind     int                    `yaml:"kind"`            // ident, literal, selector, call, raw
	Name     int                    `yaml:"name,omitempty"`  // for ident
	Value    int                    `yaml:"value,omitempty"` // for literal
	X        *CallArgument          `yaml:"x,omitempty"`     // for selector/call
	Sel      *CallArgument          `yaml:"sel,omitempty"`   // for selector
	Fun      *CallArgument          `yaml:"fun,omitempty"`   // for call
	Args     []CallArgument         `yaml:"args,omitempty"`  // for call
	Raw      int                    `yaml:"raw,omitempty"`   // fallback
	Extra    map[string]interface{} `yaml:"extra,omitempty"` // extensibility
	Pkg      int                    `yaml:"pkg,omitempty"`   // for ident
	Type     int                    `yaml:"type,omitempty"`  // for ident
	Position int                    `yaml:"position,omitempty"`

	// Callee edge for the same call if it's kind is call
	Edge *CallGraphEdge `yaml:"-"`

	// fields for argument-to-parameter and type parameter mapping
	ParamArgMap  map[string]CallArgument `yaml:"-"` // parameter name -> argument
	TypeParamMap map[string]string       `yaml:"-"` // type parameter name -> concrete type

	// Type parameter resolution information
	ResolvedType    int  `yaml:"resolved_type,omitempty"`     // The concrete type after type parameter resolution
	IsGenericType   bool `yaml:"is_generic_type,omitempty"`   // Whether this argument represents a generic type
	GenericTypeName int  `yaml:"generic_type_name,omitempty"` // The generic type parameter name (e.g., "TRequest", "TData")

	// Reference to metadata for StringPool access
	Meta *Metadata `yaml:"-"`
	// contains filtered or unexported fields
}

CallArgument represents a function call argument or expression

func ExprToCallArgument

func ExprToCallArgument(expr ast.Expr, info *types.Info, pkgName string, fset *token.FileSet, meta *Metadata) *CallArgument

ExprToCallArgument returns a structured CallArgument for an expression.

func NewCallArgument

func NewCallArgument(meta *Metadata) *CallArgument

NewCallArgument creates a new CallArgument with metadata reference

func TraceVariableOrigin

func TraceVariableOrigin(
	varName string,
	funcName string,
	pkgName string,
	metadata *Metadata,
) (originVar string, originPkg string, originType *CallArgument, callerFuncName string)

TraceVariableOrigin recursively traces the origin and type of a variable/parameter through the call graph. It supports cross-file and cross-package tracing. Returns: origin variable/parameter name, package, type (if resolvable), and the caller's function name.

func (*CallArgument) GetGenericTypeName

func (a *CallArgument) GetGenericTypeName() string

func (*CallArgument) GetKind

func (a *CallArgument) GetKind() string

Helper methods to get string values from StringPool indices

func (*CallArgument) GetName

func (a *CallArgument) GetName() string

func (*CallArgument) GetPkg

func (a *CallArgument) GetPkg() string

func (*CallArgument) GetPosition

func (a *CallArgument) GetPosition() string

func (*CallArgument) GetRaw

func (a *CallArgument) GetRaw() string

func (*CallArgument) GetResolvedType

func (a *CallArgument) GetResolvedType() string

func (*CallArgument) GetType

func (a *CallArgument) GetType() string

func (*CallArgument) GetValue

func (a *CallArgument) GetValue() string

func (*CallArgument) ID

func (a *CallArgument) ID() string

func (*CallArgument) SetGenericTypeName

func (a *CallArgument) SetGenericTypeName(genericTypeName string)

func (*CallArgument) SetKind

func (a *CallArgument) SetKind(kind string)

SetString methods to set string values using StringPool

func (*CallArgument) SetName

func (a *CallArgument) SetName(name string)

func (*CallArgument) SetPkg

func (a *CallArgument) SetPkg(pkg string)

func (*CallArgument) SetPosition

func (a *CallArgument) SetPosition(position string)

func (*CallArgument) SetRaw

func (a *CallArgument) SetRaw(raw string)

func (*CallArgument) SetResolvedType

func (a *CallArgument) SetResolvedType(resolvedType string)

func (*CallArgument) SetType

func (a *CallArgument) SetType(typeStr string)

func (*CallArgument) SetValue

func (a *CallArgument) SetValue(value string)

func (*CallArgument) TypeParams

func (a *CallArgument) TypeParams() map[string]string

type CallGraphEdge

type CallGraphEdge struct {
	Caller        Call                    `yaml:"caller,omitempty"`
	Callee        Call                    `yaml:"callee,omitempty"`
	Position      int                     `yaml:"position,omitempty"`
	Args          []CallArgument          `yaml:"args,omitempty"`
	AssignmentMap map[string][]Assignment `yaml:"assignments,omitempty"`

	// New fields for argument-to-parameter and type parameter mapping
	ParamArgMap  map[string]CallArgument `yaml:"param_arg_map,omitempty"`  // parameter name -> argument
	TypeParamMap map[string]string       `yaml:"type_param_map,omitempty"` // type parameter name -> concrete type

	CalleeVarName     string `yaml:"callee_var_name,omitempty"`
	CalleeRecvVarName string `yaml:"callee_recv_var_name,omitempty"`

	// Chain tracking for chained method calls like app.Group().Use()
	ChainParent *CallGraphEdge `yaml:"-"`                     // Reference to parent call in chain
	ChainRoot   string         `yaml:"chain_root,omitempty"`  // Root variable name (e.g., "app")
	ChainDepth  int            `yaml:"chain_depth,omitempty"` // Depth in chain (0 = root)

	// NEW: Parent function tracking for function literals
	ParentFunction *Call `yaml:"parent_function,omitempty"` // The function that contains this call (for function literals)
	// contains filtered or unexported fields
}

CallGraphEdge represents an edge in the call graph

func TypeEdges

func TypeEdges(id string, callerEdges []*CallGraphEdge) []*CallGraphEdge

func (*CallGraphEdge) NewCall

func (edge *CallGraphEdge) NewCall(name, pkg, position, recvType int) *Call

type CallIdentifier

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

CallIdentifier manages different identifier formats for calls

func NewCallIdentifier

func NewCallIdentifier(pkg, name, recvType, position string, generics map[string]string) *CallIdentifier

func (*CallIdentifier) ID

func (ci *CallIdentifier) ID(idType CallIdentifierType) string

ID returns the identifier based on the specified type

type CallIdentifierType

type CallIdentifierType int

CallIdentifierType represents different types of identifiers used in the call graph

const (
	// BaseID - Function/method name with package, no position or generics
	BaseID CallIdentifierType = iota
	// GenericID - Includes generic type parameters but no position
	GenericID
	// InstanceID - Includes position and generic type parameters for specific call instances
	InstanceID
)

type Field

type Field struct {
	Name     int `yaml:"name,omitempty"`
	Type     int `yaml:"type,omitempty"`
	Tag      int `yaml:"tag,omitempty"`
	Scope    int `yaml:"scope,omitempty"`
	Comments int `yaml:"comments,omitempty"`

	// For nested struct types, store the nested type definition
	NestedType *Type `yaml:"nested_type,omitempty"`
}

Field represents a struct field

type File

type File struct {
	Types           map[string]*Type     `yaml:"types,omitempty"`
	Functions       map[string]*Function `yaml:"functions,omitempty"`
	Variables       map[string]*Variable `yaml:"variables,omitempty"`
	StructInstances []StructInstance     `yaml:"struct_instances,omitempty"`
	// Selectors       []Selector           `yaml:"selectors"`
	Imports map[int]int `yaml:"imports"` // alias -> path
}

File represents a Go source file

type Function

type Function struct {
	Name      int          `yaml:"name,omitempty"`
	Pkg       int          `yaml:"pkg,omitempty"`
	Signature CallArgument `yaml:"signature,omitempty"`
	Position  int          `yaml:"position,omitempty"`
	Scope     int          `yaml:"scope,omitempty"`
	Comments  int          `yaml:"comments,omitempty"`
	Tags      []int        `yaml:"tags,omitempty"`

	// Type parameter names for generics
	TypeParams []string `yaml:"type_params,omitempty"`

	// Return value origins for tracing through return values
	ReturnVars []CallArgument `yaml:"return_vars,omitempty"`

	// map of variable name to all assignments (for alias/reassignment tracking)
	AssignmentMap map[string][]Assignment `yaml:"assignments,omitempty"`
}

Function represents a function

type GenericTypeResolver

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

GenericTypeResolver handles generic type parameter resolution

func (*GenericTypeResolver) IsCompatible

func (r *GenericTypeResolver) IsCompatible(callerTypes, calleeTypes []string) bool

IsCompatible checks if caller types are compatible with callee types

func (*GenericTypeResolver) ResolveTypeParameters

func (r *GenericTypeResolver) ResolveTypeParameters(edge *CallGraphEdge) map[string]string

ResolveTypeParameters resolves type parameters for a call graph edge

type GlobalAssignment

type GlobalAssignment struct {
	ConcreteType string `yaml:"-"`
	PkgName      string `yaml:"-"`
}

GlobalAssignment represents a global variable assignment

type InterfaceResolution

type InterfaceResolution struct {
	InterfaceType string `yaml:"interface_type,omitempty"`
	StructType    string `yaml:"struct_type,omitempty"`
	Pkg           string `yaml:"pkg,omitempty"`
	ConcreteType  string `yaml:"concrete_type,omitempty"`
	Position      string `yaml:"position,omitempty"`
}

InterfaceResolution represents a mapping from an interface type to its concrete implementation

type InterfaceResolutionKey

type InterfaceResolutionKey struct {
	InterfaceType string
	StructType    string
	Pkg           string
}

InterfaceResolutionKey represents a key for interface resolution

func (InterfaceResolutionKey) String

func (k InterfaceResolutionKey) String() string

type Metadata

type Metadata struct {
	StringPool *StringPool         `yaml:"string_pool,omitempty"`
	Packages   map[string]*Package `yaml:"packages,omitempty"`
	CallGraph  []CallGraphEdge     `yaml:"call_graph,omitempty"`

	Callers         map[string][]*CallGraphEdge `yaml:"-"`
	ParentFunctions map[string][]*CallGraphEdge `yaml:"-"`
	Callees         map[string][]*CallGraphEdge `yaml:"-"`
	Args            map[string][]*CallGraphEdge `yaml:"-"`
	// contains filtered or unexported fields
}

Metadata represents the complete metadata for a Go codebase

func GenerateMetadata

func GenerateMetadata(pkgs map[string]map[string]*ast.File, fileToInfo map[*ast.File]*types.Info, importPaths map[string]string, fset *token.FileSet) *Metadata

GenerateMetadata extracts all metadata and call graph info

func LoadMetadata

func LoadMetadata(filename string) (*Metadata, error)

LoadMetadata loads metadata from a YAML file

func LoadSplitMetadata

func LoadSplitMetadata(baseFilename string) (*Metadata, error)

LoadSplitMetadata loads metadata from 3 separate files

func (*Metadata) BuildAssignmentRelationships

func (m *Metadata) BuildAssignmentRelationships() map[AssignmentKey]*AssignmentLink

BuildAssignmentRelationships builds assignment relationships for all call graph edges

func (*Metadata) BuildCallGraphMaps

func (m *Metadata) BuildCallGraphMaps()

BuildCallGraphMaps builds the various lookup maps

func (*Metadata) BuildVariableRelationships

func (m *Metadata) BuildVariableRelationships() map[ParamKey]*VariableLink

BuildVariableRelationships builds variable relationships for all call graph edges

func (*Metadata) CallGraphRoots

func (m *Metadata) CallGraphRoots() []*CallGraphEdge

CallGraphRoots finds root functions using base IDs

func (*Metadata) ClassifyArgument

func (m *Metadata) ClassifyArgument(arg CallArgument) ArgumentType

ClassifyArgument determines the type of an argument for enhanced processing

func (*Metadata) FindRelatedAssignments

func (m *Metadata) FindRelatedAssignments(varName, pkg, container string) []*AssignmentLink

FindRelatedAssignments finds assignments related to a variable

func (*Metadata) FindRelatedVariables

func (m *Metadata) FindRelatedVariables(varName, pkg, container string) []*VariableLink

FindRelatedVariables finds variables related to a parameter

func (*Metadata) GetAllInterfaceResolutions

func (m *Metadata) GetAllInterfaceResolutions() map[InterfaceResolutionKey]*InterfaceResolution

GetAllInterfaceResolutions returns all interface resolutions for debugging purposes

func (*Metadata) GetArgumentProcessor

func (m *Metadata) GetArgumentProcessor() *ArgumentProcessor

GetArgumentProcessor returns the argument processor instance

func (*Metadata) GetAssignmentRelationships

func (m *Metadata) GetAssignmentRelationships() map[AssignmentKey]*AssignmentLink

GetAssignmentRelationships returns the cached assignment relationships

func (*Metadata) GetCallDepth

func (m *Metadata) GetCallDepth(funcID string) int

GetCallDepth returns the call depth for a function

func (*Metadata) GetCallPath

func (m *Metadata) GetCallPath(fromFunc, toFunc string) []*CallGraphEdge

GetCallPath returns the call path from one function to another

func (*Metadata) GetCalleesOfFunction

func (m *Metadata) GetCalleesOfFunction(pkg, funcName string) []*CallGraphEdge

GetCalleesOfFunction returns all edges where the given function is called

func (*Metadata) GetCalleesOfMethod

func (m *Metadata) GetCalleesOfMethod(pkg, recvType, methodName string) []*CallGraphEdge

GetCalleesOfMethod returns all edges where the given method is called

func (*Metadata) GetCallersOfFunction

func (m *Metadata) GetCallersOfFunction(pkg, funcName string) []*CallGraphEdge

GetCallersOfFunction returns all edges where the given function is the caller

func (*Metadata) GetCallersOfMethod

func (m *Metadata) GetCallersOfMethod(pkg, recvType, methodName string) []*CallGraphEdge

GetCallersOfMethod returns all edges where the given method is the caller

func (*Metadata) GetFunctionsAtDepth

func (m *Metadata) GetFunctionsAtDepth(targetDepth int) []*CallGraphEdge

GetFunctionsAtDepth returns all functions at a specific call depth

func (*Metadata) GetGenericTypeResolver

func (m *Metadata) GetGenericTypeResolver() *GenericTypeResolver

GetGenericTypeResolver returns the generic type resolver instance

func (*Metadata) GetInterfaceResolution

func (m *Metadata) GetInterfaceResolution(interfaceType, structType, pkg string) (string, bool)

GetInterfaceResolution retrieves the concrete type for an interface in a specific context

func (*Metadata) GetVariableRelationships

func (m *Metadata) GetVariableRelationships() map[ParamKey]*VariableLink

GetVariableRelationships returns the cached variable relationships

func (*Metadata) IsGenericTypeCompatible

func (m *Metadata) IsGenericTypeCompatible(callerTypes, calleeTypes []string) bool

IsGenericTypeCompatible checks if generic types are compatible

func (*Metadata) IsReachableFrom

func (m *Metadata) IsReachableFrom(fromFunc, toFunc string) bool

IsReachableFrom checks if a function is reachable from another function

func (*Metadata) ProcessArguments

func (m *Metadata) ProcessArguments(edge *CallGraphEdge, limits TrackerLimits) []*ProcessedArgument

ProcessArguments processes arguments with enhanced classification and tracking

func (*Metadata) ProcessFunctionReturnTypes

func (m *Metadata) ProcessFunctionReturnTypes()

ProcessFunctionReturnTypes processes all functions and methods in the metadata to fill their ResolvedType based on their ReturnVars, assuming the first return value is the target type

func (*Metadata) RegisterInterfaceResolution

func (m *Metadata) RegisterInterfaceResolution(interfaceType, structType, pkg, concreteType, position string)

RegisterInterfaceResolution registers a mapping from an interface type to its concrete implementation

func (*Metadata) ResolveTypeParameters

func (m *Metadata) ResolveTypeParameters(edge *CallGraphEdge) map[string]string

ResolveTypeParameters resolves type parameters for a call graph edge

func (*Metadata) TraverseCallGraph

func (m *Metadata) TraverseCallGraph(startFrom string, visitor func(*CallGraphEdge, int) bool)

TraverseCallGraph traverses the call graph with a visitor function

func (*Metadata) TraverseCallerChildren

func (m *Metadata) TraverseCallerChildren(edge *CallGraphEdge, action func(parent, child *CallGraphEdge))

TraverseCallerChildren traverses the call graph using base IDs

type Method

type Method struct {
	Name         int          `yaml:"name,omitempty"`
	Receiver     int          `yaml:"receiver,omitempty"`
	Signature    CallArgument `yaml:"signature,omitempty"`
	SignatureStr int          `yaml:"signature_str,omitempty"`
	Position     int          `yaml:"position,omitempty"`
	Scope        int          `yaml:"scope,omitempty"`
	Comments     int          `yaml:"comments,omitempty"`
	Tags         []int        `yaml:"tags,omitempty"`
	Filename     int          `yaml:"filename,omitempty"`

	// Type parameter names for generics
	TypeParams []string `yaml:"type_params,omitempty"`

	// Return value origins for tracing through return values
	ReturnVars []CallArgument `yaml:"return_vars,omitempty"`

	// map of variable name to all assignments (for alias/reassignment tracking)
	AssignmentMap map[string][]Assignment `yaml:"assignments,omitempty"`
}

Method represents a method

type Package

type Package struct {
	Files map[string]*File `yaml:"files,omitempty"`
	Types map[string]*Type `yaml:"types,omitempty"`
}

Package represents a Go package

type ParamKey

type ParamKey struct {
	Name      string
	Pkg       string
	Container string
}

ParamKey represents a key for parameter relationships

type ProcessedArgument

type ProcessedArgument struct {
	Argument   *CallArgument
	Edge       *CallGraphEdge
	ArgType    ArgumentType
	ArgIndex   int
	ArgContext string
	Children   []*ProcessedArgument
}

ProcessedArgument represents a processed argument with enhanced information

type Selector

type Selector struct {
	Expr     CallArgument `yaml:"expr,omitempty"`
	Kind     int          `yaml:"kind,omitempty"`
	Position int          `yaml:"position,omitempty"`
}

Selector represents a selector expression

type StringPool

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

StringPool for deduplicating strings across metadata

func NewStringPool

func NewStringPool() *StringPool

func (*StringPool) Finalize

func (sp *StringPool) Finalize()

Finalize cleans up the string pool by removing the lookup map

func (*StringPool) Get

func (sp *StringPool) Get(s string) int

func (*StringPool) GetSize

func (sp *StringPool) GetSize() int

GetSize returns the number of unique strings in the pool

func (*StringPool) GetString

func (sp *StringPool) GetString(idx int) string

func (*StringPool) MarshalYAML

func (sp *StringPool) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler interface

func (*StringPool) UnmarshalYAML

func (sp *StringPool) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler interface

type StructInstance

type StructInstance struct {
	Type     int         `yaml:"type,omitempty"`
	Pkg      int         `yaml:"pkg,omitempty"`
	Position int         `yaml:"position,omitempty"`
	Fields   map[int]int `yaml:"fields,omitempty"`
}

StructInstance represents a struct literal instance

type TraceVariableResult added in v0.2.2

type TraceVariableResult struct {
	OriginVar      string
	OriginPkg      string
	OriginType     *CallArgument
	CallerFuncName string
}

TraceVariableResult caches the result of traceVariableOriginHelper

type TrackerLimits

type TrackerLimits struct {
	MaxNodesPerTree    int
	MaxChildrenPerNode int
	MaxArgsPerFunction int
	MaxNestedArgsDepth int
	MaxRecursionDepth  int
}

TrackerLimits holds configuration for tree/graph traversal limits

type Type

type Type struct {
	Name          int      `yaml:"name,omitempty"`
	Pkg           int      `yaml:"pkg,omitempty"`
	Kind          int      `yaml:"kind,omitempty"`
	Target        int      `yaml:"target,omitempty"`
	Implements    []int    `yaml:"implements,omitempty"`
	ImplementedBy []int    `yaml:"implemented_by,omitempty"`
	Embeds        []int    `yaml:"embeds,omitempty"`
	Fields        []Field  `yaml:"fields,omitempty"`
	Scope         int      `yaml:"scope,omitempty"`
	Methods       []Method `yaml:"methods,omitempty"`
	Comments      int      `yaml:"comments,omitempty"`
	Tags          []int    `yaml:"tags,omitempty"`
}

Type represents a Go type

type Variable

type Variable struct {
	Name          int         `yaml:"name,omitempty"`
	Tok           int         `yaml:"tok,omitempty"`
	Pkg           int         `yaml:"pkg,omitempty"`
	Type          int         `yaml:"type,omitempty"`
	ResolvedType  int         `yaml:"resolved_type,omitempty"` // underlying type from types.Info
	Value         int         `yaml:"value,omitempty"`
	ComputedValue interface{} `yaml:"computed_value,omitempty"` // actual value from types.Info (for constants)
	Position      int         `yaml:"position,omitempty"`
	Comments      int         `yaml:"comments,omitempty"`
	GroupIndex    int         `yaml:"group_index,omitempty"` // which const group this belongs to
}

Variable represents a variable

type VariableLink struct {
	ParamKey   ParamKey
	OriginVar  string
	OriginPkg  string
	OriginFunc string
	Edge       *CallGraphEdge
	Argument   *CallArgument
}

VariableLink represents a link between a variable and a call graph edge

type VariableOrigin

type VariableOrigin struct {
	OriginVar  string
	OriginPkg  string
	OriginFunc string
	OriginArg  *CallArgument
}

VariableOrigin represents the origin of a variable

Jump to

Keyboard shortcuts

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