internal

package
v0.0.0-...-5eace61 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveGenFiles

func RemoveGenFiles(workDir string) error

RemoveGenFiles removes previously generated files. During Generate these files can cause issues if they contain syntax or other compilation errors.

func Run

func Run(ctx context.Context, args Args) error

Run runs weld with the given arguments.

func Write

func Write(ctx context.Context, args Args, pkg *packages.Package, result *Result) error

Write writes the weld result to disk. It first removes existing files, and then writes the new files.

func WriteGenFiles

func WriteGenFiles(res *Result, workDir string) error

WriteGenFiles outputs the results from Generate to *_gen.go files.

Types

type Args

type Args struct {
	Dir     string
	Env     []string
	Verbose bool
	Pkgs    []string
	Tags    string
}

type Backends

type Backends struct {
	// Name of the backends interface, usually Backends.
	Name string
	// Type is the actual Backends interface type itself.
	Type types.Type

	// Package of the backends.
	Package *types.Package

	// Deps is the list of dependencies provided by the backends.
	Deps []BackendsDep
}

Backends represents a Backends interface.

type BackendsDep

type BackendsDep struct {
	Getter string
	Type   types.Type
}

type Node

type Node struct {
	// Type of the node.
	Type NodeType

	// Parent of this node in the provider set graph (nil if root).
	Parent *Node

	// Children of this node in the provider set graph.
	Children []*Node

	// Deps is descendents' provided types.
	Deps []types.Type

	// HasDups indicates if this node has duplicate providers.
	HasDups bool

	// VarPkg is the fully qualified package if the provider set is assigned to a variable.
	VarPkg string

	// VarName is the variable name if the provider set is assigned to a variable.
	VarName string

	FuncObj    types.Object
	FuncSig    *types.Signature
	FuncResult types.Type

	BindInterface types.Type
	BindImpl      types.Type
}

Node represents provider in a provider set graph.

func (*Node) AddChild

func (n *Node) AddChild(child *Node)

type NodeSelection

type NodeSelection struct {
	// SelectedNodes is all the functions that need to be called in order
	// to create the weld state
	SelectedNodes []Node
	// TransitiveBackends is the other backends that needed to be satisfied by required nodes
	TransitiveBackends []Backends
	// UnselectedTypes is a list of parameters that could not be satisfied by dependencies
	UnselectedTypes []types.Type
}

type NodeType

type NodeType int
const (
	NodeTypeUnknown NodeType = iota
	NodeTypeSet              // Type=weld.ProviderSet, value=weld.NewSet
	NodeTypeFunc             // Type=func return type, value=func literal
	NodeTypeBind             // Type=weld.Binding,     value=weld.Bind
)

func (NodeType) String

func (i NodeType) String() string

type PkgCache

type PkgCache struct {
	// In is the package path that has the weld spec.
	In string

	// Out is the package that generated files are being written to.
	Out string

	// Pkgs is a map of imported packages by path
	Pkgs map[string]TplImport

	// Names is map of packages paths by import alias/name.
	Names map[string]string
}

PkgCache manages the packages used in code generation providing imports including aliases and type references.

func NewPkgCache

func NewPkgCache(in, out *packages.Package) *PkgCache

func (*PkgCache) Add

func (c *PkgCache) Add(pkg *types.Package)

func (*PkgCache) Name

func (c *PkgCache) Name(pkg *types.Package) string

type Result

type Result struct {
	Root            *Node
	SpecBackends    Backends
	TransBackends   []Backends
	SelectedNodes   []Node
	UnselectedTypes []types.Type
	Errors          []error
	TplData         *TplData
	WeldOutput      []byte
	BackendsOutput  []byte
}

func Generate

func Generate(ctx context.Context, args Args, pkg *packages.Package) (*Result, error)

Generate runs weld on the given package. It returns a Result struct with the generated code.

type SelectResult

type SelectResult struct {
	Node     *Node
	BindImpl types.Type
}

type Selector

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

func NewSelector

func NewSelector(bcks Backends) *Selector

func (*Selector) AddBackends

func (s *Selector) AddBackends(b Backends, add bool)

func (*Selector) AddDep

func (s *Selector) AddDep(dep types.Type)

func (*Selector) Empty

func (s *Selector) Empty() bool

func (*Selector) GetBackends

func (s *Selector) GetBackends() []Backends

func (*Selector) Pop

func (s *Selector) Pop() types.Type

type TplData

type TplData struct {
	// Package is the generated source package name.
	Package string

	// Tags is the build tags string
	Tags string

	BackendsType string // Backends or ops.Backends
	BackendsName string // Backends

	// Imports are the imported packages by package path.
	Imports   map[string]TplImport
	Params    []TplParam
	Deps      []TplDep
	TransBcks []string //  _ email_logical.Backends = (*backendsImpl)(nil)
}

func (TplData) DepsReturnErr

func (t TplData) DepsReturnErr() bool

DepsReturnErr returns true if any dependency returns an error. This determines whether or not `err` should be declared.

func (TplData) ParamsString

func (t TplData) ParamsString() string

type TplDep

type TplDep struct {
	Type        string //  *email_db.EmailDB
	Var         string //  emailDB
	Getter      string //  EmailDB
	IsDuplicate bool
	Provider    TplProvider
}

func (TplDep) FormatVar

func (d TplDep) FormatVar() string

type TplImport

type TplImport struct {
	Name    string
	PkgPath string
	Aliased bool
}

type TplParam

type TplParam struct {
	Name string
	Type string
}

type TplProvider

type TplProvider struct {
	FuncPkg    string //  email_db
	FuncName   string //  Connect
	ReturnsErr bool   //  s.email, err = email_db.Connect()
	Params     []string
	ErrWrapMsg string //  return nil, errors.Wrap(err, "email db connect")
}

func (TplProvider) FormatArgs

func (p TplProvider) FormatArgs() string

func (TplProvider) FormatFunc

func (p TplProvider) FormatFunc() string

type TypeMap

type TypeMap map[string]types.Type

TypeMap provides a map of types.

func (TypeMap) Put

func (m TypeMap) Put(typ types.Type) bool

Put adds the typ to the map and returns true if it already existed.

Jump to

Keyboard shortcuts

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