astutil

package
v1.19.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: BSD-2-Clause Imports: 9 Imported by: 100

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EndsWithReturn added in v1.17.2

func EndsWithReturn(stmts []ast.Stmt) bool

EndsWithReturn returns true if the last effective statement is a "return".

func FindLoopStmt added in v1.17.2

func FindLoopStmt(stack []ast.Node, branch *ast.BranchStmt, typeInfo *types.Info) ast.Stmt

FindLoopStmt tries to find the loop statement among the AST nodes in the |stack| that corresponds to the break/continue statement represented by branch.

This function is label-aware and assumes the code was successfully type-checked.

func FuncKey added in v1.17.2

func FuncKey(d *ast.FuncDecl) string

FuncKey returns a string, which uniquely identifies a top-level function or method in a package.

func FuncReceiverKey

func FuncReceiverKey(d *ast.FuncDecl) string

FuncReceiverKey returns a string that uniquely identifies the receiver struct of the function or an empty string if there is no receiver. This name will match the name of the struct in the struct's type spec.

func HasDirectivePrefix

func HasDirectivePrefix(file *ast.File, prefix string) bool

HasDirectivePrefix determines if any line in the given file has the given directive prefix in it.

func ImportName

func ImportName(spec *ast.ImportSpec) string

ImportName tries to determine the package name for an import.

If the package name isn't specified then this will make a best make a best guess using the import path. If the import name is dot (`.`), blank (`_`), or there was an issue determining the package name then empty is returned.

func ImportsUnsafe added in v1.17.2

func ImportsUnsafe(file *ast.File) bool

func IsTypeExpr

func IsTypeExpr(expr ast.Expr, info *types.Info) bool

func KeepOriginal

func KeepOriginal(d *ast.FuncDecl) bool

KeepOriginal returns true if gopherjs:keep-original directive is present before a function decl.

`//gopherjs:keep-original` is a GopherJS-specific directive, which can be applied to functions in native overlays and will instruct the augmentation logic to expose the original function such that it can be called. For a function in the original called `foo`, it will be accessible by the name `_gopherjs_original_foo`.

func NewIdent

func NewIdent(name string, t types.Type, info *types.Info, pkg *types.Package) *ast.Ident

func OverrideSignature

func OverrideSignature(d *ast.FuncDecl) bool

OverrideSignature returns true if gopherjs:override-signature directive is present on a function.

`//gopherjs:override-signature` is a GopherJS-specific directive, which can be applied in native overlays and will instruct the augmentation logic to replace the original function signature which has the same FuncKey with the signature defined in the native overlays. This directive can be used to remove generics from a function signature or to replace a receiver of a function with another one. The given native overlay function will be removed, so no method body is needed in the overlay.

The new signature may not contain types which require a new import since the imports will not be automatically added when needed, only removed. Use a type alias in the overlay to deal manage imports.

func Purge

func Purge(d ast.Node) bool

Purge returns true if gopherjs:purge directive is present on a struct, interface, type, variable, constant, or function.

`//gopherjs:purge` is a GopherJS-specific directive, which can be applied in native overlays and will instruct the augmentation logic to delete part of the standard library without a replacement. This directive can be used to remove code that would be invalid in GopherJS, such as code using unsupported features (e.g. generic interfaces before generics were fully supported). It should be used with caution since it may remove needed dependencies. If a type is purged, all methods using that type as a receiver will also be purged.

func RemoveParens

func RemoveParens(e ast.Expr) ast.Expr

func SetType

func SetType(info *types.Info, t types.Type, e ast.Expr) ast.Expr

func Squeeze

func Squeeze[E ast.Node, S ~[]E](s S) S

Squeeze removes all nil nodes from the slice.

The given slice will be modified. This is designed for squeezing declaration, specification, imports, and identifier lists.

Types

This section is empty.

Jump to

Keyboard shortcuts

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