astcopy

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2023 License: MIT Imports: 2 Imported by: 18

README

astcopy

build-img pkg-img reportcard-img version-img

Package astcopy implements Go AST reflection-free deep copy operations.

Installation:

Go version 1.16+

go get github.com/go-toolsmith/astcopy

Example

package main

import (
	"fmt"
	"go/ast"
	"go/token"

	"github.com/go-toolsmith/astcopy"
	"github.com/go-toolsmith/astequal"
	"github.com/go-toolsmith/strparse"
)

func main() {
	x := strparse.Expr(`1 + 2`).(*ast.BinaryExpr)
	y := astcopy.BinaryExpr(x)
	fmt.Println(astequal.Expr(x, y)) // => true

	// Now modify x and make sure y is not modified.
	z := astcopy.BinaryExpr(y)
	x.Op = token.SUB
	fmt.Println(astequal.Expr(y, z)) // => true
	fmt.Println(astequal.Expr(x, y)) // => false
}

License

MIT License.

Documentation

Overview

Package astcopy implements Go AST reflection-free deep copy operations.

Example
package main

import (
	"fmt"
	"go/ast"
	"go/token"

	"github.com/go-toolsmith/astcopy"
	"github.com/go-toolsmith/astequal"
	"github.com/go-toolsmith/strparse"
)

func main() {
	x := strparse.Expr(`1 + 2`).(*ast.BinaryExpr)
	y := astcopy.BinaryExpr(x)
	fmt.Println(astequal.Expr(x, y)) // => true

	// Now modify x and make sure y is not modified.
	z := astcopy.BinaryExpr(y)
	x.Op = token.SUB
	fmt.Println(astequal.Expr(y, z)) // => true
	fmt.Println(astequal.Expr(x, y)) // => false

}
Output:

true
true
false

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayType

func ArrayType(x *ast.ArrayType) *ast.ArrayType

ArrayType returns x deep copy. Copy of nil argument is nil.

func AssignStmt

func AssignStmt(x *ast.AssignStmt) *ast.AssignStmt

AssignStmt returns x deep copy. Copy of nil argument is nil.

func BadDecl

func BadDecl(x *ast.BadDecl) *ast.BadDecl

BadDecl returns x deep copy. Copy of nil argument is nil.

func BadExpr

func BadExpr(x *ast.BadExpr) *ast.BadExpr

BadExpr returns x deep copy. Copy of nil argument is nil.

func BadStmt

func BadStmt(x *ast.BadStmt) *ast.BadStmt

BadStmt returns x deep copy. Copy of nil argument is nil.

func BasicLit

func BasicLit(x *ast.BasicLit) *ast.BasicLit

BasicLit returns x deep copy. Copy of nil argument is nil.

func BinaryExpr

func BinaryExpr(x *ast.BinaryExpr) *ast.BinaryExpr

BinaryExpr returns x deep copy. Copy of nil argument is nil.

func BlockStmt

func BlockStmt(x *ast.BlockStmt) *ast.BlockStmt

BlockStmt returns x deep copy. Copy of nil argument is nil.

func BranchStmt

func BranchStmt(x *ast.BranchStmt) *ast.BranchStmt

BranchStmt returns x deep copy. Copy of nil argument is nil.

func CallExpr

func CallExpr(x *ast.CallExpr) *ast.CallExpr

CallExpr returns x deep copy. Copy of nil argument is nil.

func CaseClause

func CaseClause(x *ast.CaseClause) *ast.CaseClause

CaseClause returns x deep copy. Copy of nil argument is nil.

func ChanType

func ChanType(x *ast.ChanType) *ast.ChanType

ChanType returns x deep copy. Copy of nil argument is nil.

func CommClause

func CommClause(x *ast.CommClause) *ast.CommClause

CommClause returns x deep copy. Copy of nil argument is nil.

func Comment

func Comment(x *ast.Comment) *ast.Comment

Comment returns x deep copy. Copy of nil argument is nil.

func CommentGroup

func CommentGroup(x *ast.CommentGroup) *ast.CommentGroup

CommentGroup returns x deep copy. Copy of nil argument is nil.

func CompositeLit

func CompositeLit(x *ast.CompositeLit) *ast.CompositeLit

CompositeLit returns x deep copy. Copy of nil argument is nil.

func Decl

func Decl(x ast.Decl) ast.Decl

Decl returns x declaration deep copy. Copy of nil argument is nil.

func DeclList

func DeclList(xs []ast.Decl) []ast.Decl

DeclList returns xs declaration slice deep copy. Copy of nil argument is nil.

func DeclStmt

func DeclStmt(x *ast.DeclStmt) *ast.DeclStmt

DeclStmt returns x deep copy. Copy of nil argument is nil.

func DeferStmt

func DeferStmt(x *ast.DeferStmt) *ast.DeferStmt

DeferStmt returns x deep copy. Copy of nil argument is nil.

func Ellipsis

func Ellipsis(x *ast.Ellipsis) *ast.Ellipsis

Ellipsis returns x deep copy. Copy of nil argument is nil.

func EmptyStmt

func EmptyStmt(x *ast.EmptyStmt) *ast.EmptyStmt

EmptyStmt returns x deep copy. Copy of nil argument is nil.

func Expr

func Expr(x ast.Expr) ast.Expr

Expr returns x expression deep copy. Copy of nil argument is nil.

func ExprList

func ExprList(xs []ast.Expr) []ast.Expr

ExprList returns xs expression slice deep copy. Copy of nil argument is nil.

func ExprStmt

func ExprStmt(x *ast.ExprStmt) *ast.ExprStmt

ExprStmt returns x deep copy. Copy of nil argument is nil.

func Field

func Field(x *ast.Field) *ast.Field

Field returns x deep copy. Copy of nil argument is nil.

func FieldList

func FieldList(x *ast.FieldList) *ast.FieldList

FieldList returns x deep copy. Copy of nil argument is nil.

func File

func File(x *ast.File) *ast.File

File returns x deep copy. Copy of nil argument is nil.

func ForStmt

func ForStmt(x *ast.ForStmt) *ast.ForStmt

ForStmt returns x deep copy. Copy of nil argument is nil.

func FuncDecl

func FuncDecl(x *ast.FuncDecl) *ast.FuncDecl

FuncDecl returns x deep copy. Copy of nil argument is nil.

func FuncLit

func FuncLit(x *ast.FuncLit) *ast.FuncLit

FuncLit returns x deep copy. Copy of nil argument is nil.

func FuncType

func FuncType(x *ast.FuncType) *ast.FuncType

FuncType returns x deep copy. Copy of nil argument is nil.

func GenDecl

func GenDecl(x *ast.GenDecl) *ast.GenDecl

GenDecl returns x deep copy. Copy of nil argument is nil.

func GoStmt

func GoStmt(x *ast.GoStmt) *ast.GoStmt

GoStmt returns x deep copy. Copy of nil argument is nil.

func Ident

func Ident(x *ast.Ident) *ast.Ident

Ident returns x deep copy. Copy of nil argument is nil.

func IdentList

func IdentList(xs []*ast.Ident) []*ast.Ident

IdentList returns xs identifier slice deep copy. Copy of nil argument is nil.

func IfStmt

func IfStmt(x *ast.IfStmt) *ast.IfStmt

IfStmt returns x deep copy. Copy of nil argument is nil.

func ImportSpec

func ImportSpec(x *ast.ImportSpec) *ast.ImportSpec

ImportSpec returns x deep copy. Copy of nil argument is nil.

func IncDecStmt

func IncDecStmt(x *ast.IncDecStmt) *ast.IncDecStmt

IncDecStmt returns x deep copy. Copy of nil argument is nil.

func IndexExpr

func IndexExpr(x *ast.IndexExpr) *ast.IndexExpr

IndexExpr returns x deep copy. Copy of nil argument is nil.

func IndexListExpr added in v1.0.2

IndexListExpr returns x deep copy. Copy of nil argument is nil.

func InterfaceType

func InterfaceType(x *ast.InterfaceType) *ast.InterfaceType

InterfaceType returns x deep copy. Copy of nil argument is nil.

func KeyValueExpr

func KeyValueExpr(x *ast.KeyValueExpr) *ast.KeyValueExpr

KeyValueExpr returns x deep copy. Copy of nil argument is nil.

func LabeledStmt

func LabeledStmt(x *ast.LabeledStmt) *ast.LabeledStmt

LabeledStmt returns x deep copy. Copy of nil argument is nil.

func MapType

func MapType(x *ast.MapType) *ast.MapType

MapType returns x deep copy. Copy of nil argument is nil.

func Node

func Node(x ast.Node) ast.Node

Node returns x node deep copy. Copy of nil argument is nil.

func NodeList

func NodeList(xs []ast.Node) []ast.Node

NodeList returns xs node slice deep copy. Copy of nil argument is nil.

func Package

func Package(x *ast.Package) *ast.Package

Package returns x deep copy. Copy of nil argument is nil.

func ParenExpr

func ParenExpr(x *ast.ParenExpr) *ast.ParenExpr

ParenExpr returns x deep copy. Copy of nil argument is nil.

func RangeStmt

func RangeStmt(x *ast.RangeStmt) *ast.RangeStmt

RangeStmt returns x deep copy. Copy of nil argument is nil.

func ReturnStmt

func ReturnStmt(x *ast.ReturnStmt) *ast.ReturnStmt

ReturnStmt returns x deep copy. Copy of nil argument is nil.

func SelectStmt

func SelectStmt(x *ast.SelectStmt) *ast.SelectStmt

SelectStmt returns x deep copy. Copy of nil argument is nil.

func SelectorExpr

func SelectorExpr(x *ast.SelectorExpr) *ast.SelectorExpr

SelectorExpr returns x deep copy. Copy of nil argument is nil.

func SendStmt

func SendStmt(x *ast.SendStmt) *ast.SendStmt

SendStmt returns x deep copy. Copy of nil argument is nil.

func SliceExpr

func SliceExpr(x *ast.SliceExpr) *ast.SliceExpr

SliceExpr returns x deep copy. Copy of nil argument is nil.

func Spec

func Spec(x ast.Spec) ast.Spec

Spec returns x deep copy. Copy of nil argument is nil.

func SpecList

func SpecList(xs []ast.Spec) []ast.Spec

SpecList returns xs spec slice deep copy. Copy of nil argument is nil.

func StarExpr

func StarExpr(x *ast.StarExpr) *ast.StarExpr

StarExpr returns x deep copy. Copy of nil argument is nil.

func Stmt

func Stmt(x ast.Stmt) ast.Stmt

Stmt returns x statement deep copy. Copy of nil argument is nil.

func StmtList

func StmtList(xs []ast.Stmt) []ast.Stmt

StmtList returns xs statement slice deep copy. Copy of nil argument is nil.

func StructType

func StructType(x *ast.StructType) *ast.StructType

StructType returns x deep copy. Copy of nil argument is nil.

func SwitchStmt

func SwitchStmt(x *ast.SwitchStmt) *ast.SwitchStmt

SwitchStmt returns x deep copy. Copy of nil argument is nil.

func TypeAssertExpr

func TypeAssertExpr(x *ast.TypeAssertExpr) *ast.TypeAssertExpr

TypeAssertExpr returns x deep copy. Copy of nil argument is nil.

func TypeSpec

func TypeSpec(x *ast.TypeSpec) *ast.TypeSpec

TypeSpec returns x deep copy. Copy of nil argument is nil.

func TypeSwitchStmt

func TypeSwitchStmt(x *ast.TypeSwitchStmt) *ast.TypeSwitchStmt

TypeSwitchStmt returns x deep copy. Copy of nil argument is nil.

func UnaryExpr

func UnaryExpr(x *ast.UnaryExpr) *ast.UnaryExpr

UnaryExpr returns x deep copy. Copy of nil argument is nil.

func ValueSpec

func ValueSpec(x *ast.ValueSpec) *ast.ValueSpec

ValueSpec returns x deep copy. Copy of nil argument is nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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