resolve

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 14 Imported by: 0

README

Idea

original:

var SomeVar int

Instrumented:

var SomeVar int

func SomeVar_xgo_get() int {
    __mock_res := SomeVar
    __xgo_runtime.TrapVar("SomeVar",&__mock_res)
    return __mock_res
}

func SomeVar_xgo_get_addr() *int {
    __mock_res := &SomeVar
    __xgo_runtime.TrapVarPtr("SomeVar",&__mock_res)
    return __mock_res
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectDecls

func CollectDecls(pkg *edit.Package)

func Traverse

func Traverse(registry PackageRegistry, packages []*edit.Package, recorder *Recorder) error

Traverse applies variable rewriting, and find possible functions `fn` such that `mock.Patch(fn)` is called.

Types

type Define

type Define struct {
	// is this Def causes a split?
	// if so, should look for parent scope
	Split bool
	Expr  ast.Expr

	// if index==-1, it means exact match
	Index int
}

type FileScope

type FileScope struct {
	File    *edit.File
	Imports Imports
}

type GlobalScope

type GlobalScope struct {
	Packages PackageRegistry
	Recorder *Recorder

	// key is the expr, value is the type info
	ExprInfo map[ast.Expr]types.Info

	NamedTypeToDecl map[PkgName]*edit.Decl
	// contains filtered or unexported fields
}

type Imports

type Imports map[string]string

name -> path

type NameRecorder

type NameRecorder struct {
	HasMockRef      bool
	HasVarTrap      bool
	NamesHavingMock map[string]bool
}

func (*NameRecorder) AddMockName

func (c *NameRecorder) AddMockName(name string)

type PackageRegistry

type PackageRegistry interface {
	Fset() *token.FileSet
	LoadPackage(pkgPath string) (*edit.Package, bool, error)
	GetPackage(pkgPath string) *edit.Package
}

func NewPackagesRegistry

func NewPackagesRegistry(packages *edit.Packages) PackageRegistry

type PackageScope

type PackageScope struct {
	Package *edit.Package
	Decls   PkgScopeNames
}

func (PackageScope) PkgPath

func (c PackageScope) PkgPath() string

type PkgName

type PkgName struct {
	PkgPath string
	Name    string
}

type PkgRecorder

type PkgRecorder struct {
	Names map[string]*NameRecorder
	// Names count of vars
	NumVars int
}

func (*PkgRecorder) Get

func (c *PkgRecorder) Get(name string) *NameRecorder

func (*PkgRecorder) GetOrInit

func (c *PkgRecorder) GetOrInit(name string) *NameRecorder

type PkgScopeNames

type PkgScopeNames map[string]*edit.Decl

imports: key is local name, value is import path

type Recorder

type Recorder struct {
	// has called `trap.AddInterceptor`?
	// if so, we need to enable trapAll mode
	// as mentioned in https://github.com/xhd2015/xgo/issues/308#issuecomment-2800327536
	HasTrapInterceptorRef bool
	Pkgs                  map[string]*PkgRecorder
}

func (*Recorder) GetOrInit

func (c *Recorder) GetOrInit(pkgPath string) *PkgRecorder

type Scope

type Scope struct {
	Global  *GlobalScope
	Package *PackageScope
	File    *FileScope

	Parent *Scope
	Defs   map[string]*Define
	Names  map[string]bool

	PkgDepth int
}

a Scope provides a point where stmts can be prepended or inserted

func (*Scope) Add

func (c *Scope) Add(name string)

func (*Scope) AddDef

func (c *Scope) AddDef(name string, def *Define)

func (*Scope) GetDef

func (c *Scope) GetDef(name string) *Define

func (*Scope) Has

func (c *Scope) Has(name string) bool

Has checks if the name is defined in local scope

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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