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/astequal" "github.com/go-toolsmith/strparse" "github.com/vvakame/astcopy" ) func main() { x := strparse.Expr(`1 + 2`).(*ast.BinaryExpr) y := astcopy.BinaryExpr(x, nil) fmt.Println(astequal.Expr(x, y)) // => true // Now modify x and make sure y is not modified. z := astcopy.BinaryExpr(y, nil) x.Op = token.SUB fmt.Println(astequal.Expr(y, z)) // => true fmt.Println(astequal.Expr(x, y)) // => false }
Output: true true false
Index ¶
- func ArrayType(x *ast.ArrayType, nMap CopyNodeMap) *ast.ArrayType
- func AssignStmt(x *ast.AssignStmt, nMap CopyNodeMap) *ast.AssignStmt
- func BadDecl(x *ast.BadDecl, nMap CopyNodeMap) *ast.BadDecl
- func BadExpr(x *ast.BadExpr, nMap CopyNodeMap) *ast.BadExpr
- func BadStmt(x *ast.BadStmt, nMap CopyNodeMap) *ast.BadStmt
- func BasicLit(x *ast.BasicLit, nMap CopyNodeMap) *ast.BasicLit
- func BinaryExpr(x *ast.BinaryExpr, nMap CopyNodeMap) *ast.BinaryExpr
- func BlockStmt(x *ast.BlockStmt, nMap CopyNodeMap) *ast.BlockStmt
- func BranchStmt(x *ast.BranchStmt, nMap CopyNodeMap) *ast.BranchStmt
- func CallExpr(x *ast.CallExpr, nMap CopyNodeMap) *ast.CallExpr
- func CaseClause(x *ast.CaseClause, nMap CopyNodeMap) *ast.CaseClause
- func ChanType(x *ast.ChanType, nMap CopyNodeMap) *ast.ChanType
- func CommClause(x *ast.CommClause, nMap CopyNodeMap) *ast.CommClause
- func Comment(x *ast.Comment, nMap CopyNodeMap) *ast.Comment
- func CommentGroup(x *ast.CommentGroup, nMap CopyNodeMap) *ast.CommentGroup
- func CompositeLit(x *ast.CompositeLit, nMap CopyNodeMap) *ast.CompositeLit
- func Decl(x ast.Decl, nMap CopyNodeMap) ast.Decl
- func DeclList(xs []ast.Decl, nMap CopyNodeMap) []ast.Decl
- func DeclStmt(x *ast.DeclStmt, nMap CopyNodeMap) *ast.DeclStmt
- func DeferStmt(x *ast.DeferStmt, nMap CopyNodeMap) *ast.DeferStmt
- func Ellipsis(x *ast.Ellipsis, nMap CopyNodeMap) *ast.Ellipsis
- func EmptyStmt(x *ast.EmptyStmt, nMap CopyNodeMap) *ast.EmptyStmt
- func Expr(x ast.Expr, nMap CopyNodeMap) ast.Expr
- func ExprList(xs []ast.Expr, nMap CopyNodeMap) []ast.Expr
- func ExprStmt(x *ast.ExprStmt, nMap CopyNodeMap) *ast.ExprStmt
- func Field(x *ast.Field, nMap CopyNodeMap) *ast.Field
- func FieldList(x *ast.FieldList, nMap CopyNodeMap) *ast.FieldList
- func File(x *ast.File, nMap CopyNodeMap) *ast.File
- func ForStmt(x *ast.ForStmt, nMap CopyNodeMap) *ast.ForStmt
- func FuncDecl(x *ast.FuncDecl, nMap CopyNodeMap) *ast.FuncDecl
- func FuncLit(x *ast.FuncLit, nMap CopyNodeMap) *ast.FuncLit
- func FuncType(x *ast.FuncType, nMap CopyNodeMap) *ast.FuncType
- func GenDecl(x *ast.GenDecl, nMap CopyNodeMap) *ast.GenDecl
- func GoStmt(x *ast.GoStmt, nMap CopyNodeMap) *ast.GoStmt
- func Ident(x *ast.Ident, nMap CopyNodeMap) *ast.Ident
- func IdentList(xs []*ast.Ident, nMap CopyNodeMap) []*ast.Ident
- func IfStmt(x *ast.IfStmt, nMap CopyNodeMap) *ast.IfStmt
- func ImportSpec(x *ast.ImportSpec, nMap CopyNodeMap) *ast.ImportSpec
- func IncDecStmt(x *ast.IncDecStmt, nMap CopyNodeMap) *ast.IncDecStmt
- func IndexExpr(x *ast.IndexExpr, nMap CopyNodeMap) *ast.IndexExpr
- func InterfaceType(x *ast.InterfaceType, nMap CopyNodeMap) *ast.InterfaceType
- func KeyValueExpr(x *ast.KeyValueExpr, nMap CopyNodeMap) *ast.KeyValueExpr
- func LabeledStmt(x *ast.LabeledStmt, nMap CopyNodeMap) *ast.LabeledStmt
- func MapType(x *ast.MapType, nMap CopyNodeMap) *ast.MapType
- func Node(x ast.Node, nMap CopyNodeMap) ast.Node
- func NodeList(xs []ast.Node, nMap CopyNodeMap) []ast.Node
- func Package(x *ast.Package, nMap CopyNodeMap) *ast.Package
- func ParenExpr(x *ast.ParenExpr, nMap CopyNodeMap) *ast.ParenExpr
- func RangeStmt(x *ast.RangeStmt, nMap CopyNodeMap) *ast.RangeStmt
- func ReturnStmt(x *ast.ReturnStmt, nMap CopyNodeMap) *ast.ReturnStmt
- func SelectStmt(x *ast.SelectStmt, nMap CopyNodeMap) *ast.SelectStmt
- func SelectorExpr(x *ast.SelectorExpr, nMap CopyNodeMap) *ast.SelectorExpr
- func SendStmt(x *ast.SendStmt, nMap CopyNodeMap) *ast.SendStmt
- func SliceExpr(x *ast.SliceExpr, nMap CopyNodeMap) *ast.SliceExpr
- func Spec(x ast.Spec, nMap CopyNodeMap) ast.Spec
- func SpecList(xs []ast.Spec, nMap CopyNodeMap) []ast.Spec
- func StarExpr(x *ast.StarExpr, nMap CopyNodeMap) *ast.StarExpr
- func Stmt(x ast.Stmt, nMap CopyNodeMap) ast.Stmt
- func StmtList(xs []ast.Stmt, nMap CopyNodeMap) []ast.Stmt
- func StructType(x *ast.StructType, nMap CopyNodeMap) *ast.StructType
- func SwitchStmt(x *ast.SwitchStmt, nMap CopyNodeMap) *ast.SwitchStmt
- func TypeAssertExpr(x *ast.TypeAssertExpr, nMap CopyNodeMap) *ast.TypeAssertExpr
- func TypeSpec(x *ast.TypeSpec, nMap CopyNodeMap) *ast.TypeSpec
- func TypeSwitchStmt(x *ast.TypeSwitchStmt, nMap CopyNodeMap) *ast.TypeSwitchStmt
- func UnaryExpr(x *ast.UnaryExpr, nMap CopyNodeMap) *ast.UnaryExpr
- func ValueSpec(x *ast.ValueSpec, nMap CopyNodeMap) *ast.ValueSpec
- type CopyNodeMap
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArrayType ¶
func ArrayType(x *ast.ArrayType, nMap CopyNodeMap) *ast.ArrayType
ArrayType returns x deep copy. Copy of nil argument is nil.
func AssignStmt ¶
func AssignStmt(x *ast.AssignStmt, nMap CopyNodeMap) *ast.AssignStmt
AssignStmt returns x deep copy. Copy of nil argument is nil.
func BadDecl ¶
func BadDecl(x *ast.BadDecl, nMap CopyNodeMap) *ast.BadDecl
BadDecl returns x deep copy. Copy of nil argument is nil.
func BadExpr ¶
func BadExpr(x *ast.BadExpr, nMap CopyNodeMap) *ast.BadExpr
BadExpr returns x deep copy. Copy of nil argument is nil.
func BadStmt ¶
func BadStmt(x *ast.BadStmt, nMap CopyNodeMap) *ast.BadStmt
BadStmt returns x deep copy. Copy of nil argument is nil.
func BasicLit ¶
func BasicLit(x *ast.BasicLit, nMap CopyNodeMap) *ast.BasicLit
BasicLit returns x deep copy. Copy of nil argument is nil.
func BinaryExpr ¶
func BinaryExpr(x *ast.BinaryExpr, nMap CopyNodeMap) *ast.BinaryExpr
BinaryExpr returns x deep copy. Copy of nil argument is nil.
func BlockStmt ¶
func BlockStmt(x *ast.BlockStmt, nMap CopyNodeMap) *ast.BlockStmt
BlockStmt returns x deep copy. Copy of nil argument is nil.
func BranchStmt ¶
func BranchStmt(x *ast.BranchStmt, nMap CopyNodeMap) *ast.BranchStmt
BranchStmt returns x deep copy. Copy of nil argument is nil.
func CallExpr ¶
func CallExpr(x *ast.CallExpr, nMap CopyNodeMap) *ast.CallExpr
CallExpr returns x deep copy. Copy of nil argument is nil.
func CaseClause ¶
func CaseClause(x *ast.CaseClause, nMap CopyNodeMap) *ast.CaseClause
CaseClause returns x deep copy. Copy of nil argument is nil.
func ChanType ¶
func ChanType(x *ast.ChanType, nMap CopyNodeMap) *ast.ChanType
ChanType returns x deep copy. Copy of nil argument is nil.
func CommClause ¶
func CommClause(x *ast.CommClause, nMap CopyNodeMap) *ast.CommClause
CommClause returns x deep copy. Copy of nil argument is nil.
func Comment ¶
func Comment(x *ast.Comment, nMap CopyNodeMap) *ast.Comment
Comment returns x deep copy. Copy of nil argument is nil.
func CommentGroup ¶
func CommentGroup(x *ast.CommentGroup, nMap CopyNodeMap) *ast.CommentGroup
CommentGroup returns x deep copy. Copy of nil argument is nil.
func CompositeLit ¶
func CompositeLit(x *ast.CompositeLit, nMap CopyNodeMap) *ast.CompositeLit
CompositeLit returns x deep copy. Copy of nil argument is nil.
func Decl ¶
func Decl(x ast.Decl, nMap CopyNodeMap) ast.Decl
Decl returns x declaration deep copy. Copy of nil argument is nil.
func DeclList ¶
func DeclList(xs []ast.Decl, nMap CopyNodeMap) []ast.Decl
DeclList returns xs declaration slice deep copy. Copy of nil argument is nil.
func DeclStmt ¶
func DeclStmt(x *ast.DeclStmt, nMap CopyNodeMap) *ast.DeclStmt
DeclStmt returns x deep copy. Copy of nil argument is nil.
func DeferStmt ¶
func DeferStmt(x *ast.DeferStmt, nMap CopyNodeMap) *ast.DeferStmt
DeferStmt returns x deep copy. Copy of nil argument is nil.
func Ellipsis ¶
func Ellipsis(x *ast.Ellipsis, nMap CopyNodeMap) *ast.Ellipsis
Ellipsis returns x deep copy. Copy of nil argument is nil.
func EmptyStmt ¶
func EmptyStmt(x *ast.EmptyStmt, nMap CopyNodeMap) *ast.EmptyStmt
EmptyStmt returns x deep copy. Copy of nil argument is nil.
func Expr ¶
func Expr(x ast.Expr, nMap CopyNodeMap) ast.Expr
Expr returns x expression deep copy. Copy of nil argument is nil.
func ExprList ¶
func ExprList(xs []ast.Expr, nMap CopyNodeMap) []ast.Expr
ExprList returns xs expression slice deep copy. Copy of nil argument is nil.
func ExprStmt ¶
func ExprStmt(x *ast.ExprStmt, nMap CopyNodeMap) *ast.ExprStmt
ExprStmt returns x deep copy. Copy of nil argument is nil.
func Field ¶
func Field(x *ast.Field, nMap CopyNodeMap) *ast.Field
Field returns x deep copy. Copy of nil argument is nil.
func FieldList ¶
func FieldList(x *ast.FieldList, nMap CopyNodeMap) *ast.FieldList
FieldList returns x deep copy. Copy of nil argument is nil.
func File ¶
func File(x *ast.File, nMap CopyNodeMap) *ast.File
File returns x deep copy. Copy of nil argument is nil.
func ForStmt ¶
func ForStmt(x *ast.ForStmt, nMap CopyNodeMap) *ast.ForStmt
ForStmt returns x deep copy. Copy of nil argument is nil.
func FuncDecl ¶
func FuncDecl(x *ast.FuncDecl, nMap CopyNodeMap) *ast.FuncDecl
FuncDecl returns x deep copy. Copy of nil argument is nil.
func FuncLit ¶
func FuncLit(x *ast.FuncLit, nMap CopyNodeMap) *ast.FuncLit
FuncLit returns x deep copy. Copy of nil argument is nil.
func FuncType ¶
func FuncType(x *ast.FuncType, nMap CopyNodeMap) *ast.FuncType
FuncType returns x deep copy. Copy of nil argument is nil.
func GenDecl ¶
func GenDecl(x *ast.GenDecl, nMap CopyNodeMap) *ast.GenDecl
GenDecl returns x deep copy. Copy of nil argument is nil.
func GoStmt ¶
func GoStmt(x *ast.GoStmt, nMap CopyNodeMap) *ast.GoStmt
GoStmt returns x deep copy. Copy of nil argument is nil.
func Ident ¶
func Ident(x *ast.Ident, nMap CopyNodeMap) *ast.Ident
Ident returns x deep copy. Copy of nil argument is nil.
func IdentList ¶
func IdentList(xs []*ast.Ident, nMap CopyNodeMap) []*ast.Ident
IdentList returns xs identifier slice deep copy. Copy of nil argument is nil.
func IfStmt ¶
func IfStmt(x *ast.IfStmt, nMap CopyNodeMap) *ast.IfStmt
IfStmt returns x deep copy. Copy of nil argument is nil.
func ImportSpec ¶
func ImportSpec(x *ast.ImportSpec, nMap CopyNodeMap) *ast.ImportSpec
ImportSpec returns x deep copy. Copy of nil argument is nil.
func IncDecStmt ¶
func IncDecStmt(x *ast.IncDecStmt, nMap CopyNodeMap) *ast.IncDecStmt
IncDecStmt returns x deep copy. Copy of nil argument is nil.
func IndexExpr ¶
func IndexExpr(x *ast.IndexExpr, nMap CopyNodeMap) *ast.IndexExpr
IndexExpr returns x deep copy. Copy of nil argument is nil.
func InterfaceType ¶
func InterfaceType(x *ast.InterfaceType, nMap CopyNodeMap) *ast.InterfaceType
InterfaceType returns x deep copy. Copy of nil argument is nil.
func KeyValueExpr ¶
func KeyValueExpr(x *ast.KeyValueExpr, nMap CopyNodeMap) *ast.KeyValueExpr
KeyValueExpr returns x deep copy. Copy of nil argument is nil.
func LabeledStmt ¶
func LabeledStmt(x *ast.LabeledStmt, nMap CopyNodeMap) *ast.LabeledStmt
LabeledStmt returns x deep copy. Copy of nil argument is nil.
func MapType ¶
func MapType(x *ast.MapType, nMap CopyNodeMap) *ast.MapType
MapType returns x deep copy. Copy of nil argument is nil.
func Node ¶
func Node(x ast.Node, nMap CopyNodeMap) ast.Node
Node returns x node deep copy. Copy of nil argument is nil.
func NodeList ¶
func NodeList(xs []ast.Node, nMap CopyNodeMap) []ast.Node
NodeList returns xs node slice deep copy. Copy of nil argument is nil.
func Package ¶
func Package(x *ast.Package, nMap CopyNodeMap) *ast.Package
Package returns x deep copy. Copy of nil argument is nil.
func ParenExpr ¶
func ParenExpr(x *ast.ParenExpr, nMap CopyNodeMap) *ast.ParenExpr
ParenExpr returns x deep copy. Copy of nil argument is nil.
func RangeStmt ¶
func RangeStmt(x *ast.RangeStmt, nMap CopyNodeMap) *ast.RangeStmt
RangeStmt returns x deep copy. Copy of nil argument is nil.
func ReturnStmt ¶
func ReturnStmt(x *ast.ReturnStmt, nMap CopyNodeMap) *ast.ReturnStmt
ReturnStmt returns x deep copy. Copy of nil argument is nil.
func SelectStmt ¶
func SelectStmt(x *ast.SelectStmt, nMap CopyNodeMap) *ast.SelectStmt
SelectStmt returns x deep copy. Copy of nil argument is nil.
func SelectorExpr ¶
func SelectorExpr(x *ast.SelectorExpr, nMap CopyNodeMap) *ast.SelectorExpr
SelectorExpr returns x deep copy. Copy of nil argument is nil.
func SendStmt ¶
func SendStmt(x *ast.SendStmt, nMap CopyNodeMap) *ast.SendStmt
SendStmt returns x deep copy. Copy of nil argument is nil.
func SliceExpr ¶
func SliceExpr(x *ast.SliceExpr, nMap CopyNodeMap) *ast.SliceExpr
SliceExpr returns x deep copy. Copy of nil argument is nil.
func Spec ¶
func Spec(x ast.Spec, nMap CopyNodeMap) ast.Spec
Spec returns x deep copy. Copy of nil argument is nil.
func SpecList ¶
func SpecList(xs []ast.Spec, nMap CopyNodeMap) []ast.Spec
SpecList returns xs spec slice deep copy. Copy of nil argument is nil.
func StarExpr ¶
func StarExpr(x *ast.StarExpr, nMap CopyNodeMap) *ast.StarExpr
StarExpr returns x deep copy. Copy of nil argument is nil.
func Stmt ¶
func Stmt(x ast.Stmt, nMap CopyNodeMap) ast.Stmt
Stmt returns x statement deep copy. Copy of nil argument is nil.
func StmtList ¶
func StmtList(xs []ast.Stmt, nMap CopyNodeMap) []ast.Stmt
StmtList returns xs statement slice deep copy. Copy of nil argument is nil.
func StructType ¶
func StructType(x *ast.StructType, nMap CopyNodeMap) *ast.StructType
StructType returns x deep copy. Copy of nil argument is nil.
func SwitchStmt ¶
func SwitchStmt(x *ast.SwitchStmt, nMap CopyNodeMap) *ast.SwitchStmt
SwitchStmt returns x deep copy. Copy of nil argument is nil.
func TypeAssertExpr ¶
func TypeAssertExpr(x *ast.TypeAssertExpr, nMap CopyNodeMap) *ast.TypeAssertExpr
TypeAssertExpr returns x deep copy. Copy of nil argument is nil.
func TypeSpec ¶
func TypeSpec(x *ast.TypeSpec, nMap CopyNodeMap) *ast.TypeSpec
TypeSpec returns x deep copy. Copy of nil argument is nil.
func TypeSwitchStmt ¶
func TypeSwitchStmt(x *ast.TypeSwitchStmt, nMap CopyNodeMap) *ast.TypeSwitchStmt
TypeSwitchStmt returns x deep copy. Copy of nil argument is nil.