codegen

package
v1.64.2 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: BSD-3-Clause Imports: 13 Imported by: 6

Documentation

Overview

Package codegen contains shared utilities for generating code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertStructUnchanged

func AssertStructUnchanged(t *types.Struct, tname, ctx string, it *ImportTracker) []byte

AssertStructUnchanged generates code that asserts at compile time that type t is unchanged. thisPkg is the package containing t. tname is the named type corresponding to t. ctx is a single-word context for this assertion, such as "Clone". If non-nil, AssertStructUnchanged will add elements to imports for each package path that the caller must import for the returned code to compile.

func ContainsPointers

func ContainsPointers(typ types.Type) bool

ContainsPointers reports whether typ contains any pointers, either explicitly or implicitly. It has special handling for some types that contain pointers that we know are free from memory aliasing/mutation concerns.

func HasNoClone added in v1.26.0

func HasNoClone(structTag string) bool

HasNoClone reports whether the provided tag has `codegen:noclone`.

func IsInvalid added in v1.26.0

func IsInvalid(t types.Type) bool

IsInvalid reports whether the provided type is invalid. It is used to allow codegeneration to run even when the target files have build errors or are missing views.

func IsViewType added in v1.26.0

func IsViewType(typ types.Type) bool

IsViewType reports whether the provided typ is a View.

func LoadTypes added in v1.26.0

func LoadTypes(buildTags string, pkgName string) (*packages.Package, map[string]*types.Named, error)

LoadTypes returns all named types in pkgName, keyed by their type name.

func WritePackageFile added in v1.26.0

func WritePackageFile(tool string, pkg *packages.Package, path string, it *ImportTracker, contents *bytes.Buffer) error

WritePackageFile adds a file with the provided imports and contents to package. The tool param is used to identify the tool that generated package file.

Types

type ImportTracker added in v1.26.0

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

ImportTracker provides a mechanism to track and build import paths.

func NewImportTracker added in v1.26.0

func NewImportTracker(thisPkg *types.Package) *ImportTracker

func (*ImportTracker) Import added in v1.26.0

func (it *ImportTracker) Import(pkg string)

func (*ImportTracker) QualifiedName added in v1.26.0

func (it *ImportTracker) QualifiedName(t types.Type) string

QualifiedName returns the string representation of t in the package.

func (*ImportTracker) Write added in v1.26.0

func (it *ImportTracker) Write(w io.Writer)

Write prints all the tracked imports in a single import block to w.

Jump to

Keyboard shortcuts

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