codegen

package
v1.0.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileGen

type FileGen struct {
	File *ast.File
	// contains filtered or unexported fields
}

FileGen is a utility for generating/patching golang file ASTs.

func NewFileGen

func NewFileGen(file *ast.File, codegenPkgPath string) (*FileGen, error)

NewFileGen creates a new FileGen instance from a file AST with the provided package path.

func (*FileGen) AddOrGetImport

func (g *FileGen) AddOrGetImport(pkgPath string) (importPrefix string)

AddOrGetImport adds a new import for the provided pkgPath (if needed) and returns the unique import prefix for that path.

func (*FileGen) CreateIdent

func (g *FileGen) CreateIdent(namePrefix string) *ast.Ident

CreateIdent creates a new ident that doesn't conflict with reserved symbols, top-level declarations and other defined idents. Idents are unique across the whole file as it is assumed that codegen usually happens on one function per file.

func (*FileGen) PatchFuncDecl

func (g *FileGen) PatchFuncDecl(name string) *FuncGen

PatchFuncDecl returns a FuncGen instance for the function declaration with the given name or returns nil.

func (*FileGen) TypeExpr

func (g *FileGen) TypeExpr(typ reflect.Type) (ast.Expr, error)

TypeExpr generates an ast.Expr to be used in the context of the file for the provided reflect.Type, adding any needed imports.

func (*FileGen) ValueExpr

func (g *FileGen) ValueExpr(value reflect.Value) (ast.Expr, error)

ValueExpr generates an ast.Expr to be used in the context of the file for the provided reflect.Value, adding any needed imports. Values with kind Chan, Func, Interface, Uintptr, and UnsafePointer cannot be generated and only pointers to structs can be generated.

type FuncGen

type FuncGen struct {
	*FileGen
	Func *ast.FuncDecl
}

FuncGen is a utility for generating/patching golang function declaration ASTs.

Jump to

Keyboard shortcuts

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