rewrite

package
v0.4.4-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0, BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyBaseRewrites

func ApplyBaseRewrites(packages []*packages.Package)

ApplyBaseRewrites applies a series of rewrite steps to the packages and all its dependencies. The rewrites are:

- calls to sort.Slice and sort.SliceStable are removed and replaced by calls to the functions used in sorting. - calls to (sync.Once).Do are replaced by a call to the method in the sync.Once object.

func AstFileToBytes

func AstFileToBytes(fset *token.FileSet, file *ast.File) ([]byte, error)

AstFileToBytes pretty prints an AST file to a slice of byte.

func ForEachPackageIncludingDependencies

func ForEachPackageIncludingDependencies(pkgs []*packages.Package, fn func(*packages.Package))

ForEachPackageIncludingDependencies calls fn exactly once for each package that is in pkgs or in the transitive dependencies of pkgs.

func FreshVar

func FreshVar(p *types.Package, scope *types.Scope, base string, t types.Type) *types.Var

FreshVar generates a fresh variable in the given scope, with a base name and a type. If the base name already exists in the scope, then the function attempts to look for names of the form "<base name>_<i>" where i is incremented until the id is not in scope. The function updates the scope when it returns a new `*types.Var`. This ensures that any future calls to FreshVar in the same scope will return a fresh variable again.

func TypeNameForGeneration

func TypeNameForGeneration(t types.Type) string

TypeNameForGeneration recursively decomposes the type to find a type.Named to use for variable name generation. This is a heuristic that could potentially generate names that are easier for debugging purposes.

This shouldn't be relied on as the sole mechanism to generate variable names. The caller is responsible for checking that the name is not already defined in the scope when a fresh variable name is required.

Types

This section is empty.

Jump to

Keyboard shortcuts

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