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 ¶
- func ArrayType(x *ast.ArrayType) *ast.ArrayType
- func AssignStmt(x *ast.AssignStmt) *ast.AssignStmt
- func BadDecl(x *ast.BadDecl) *ast.BadDecl
- func BadExpr(x *ast.BadExpr) *ast.BadExpr
- func BadStmt(x *ast.BadStmt) *ast.BadStmt
- func BasicLit(x *ast.BasicLit) *ast.BasicLit
- func BinaryExpr(x *ast.BinaryExpr) *ast.BinaryExpr
- func BlockStmt(x *ast.BlockStmt) *ast.BlockStmt
- func BranchStmt(x *ast.BranchStmt) *ast.BranchStmt
- func CallExpr(x *ast.CallExpr) *ast.CallExpr
- func CaseClause(x *ast.CaseClause) *ast.CaseClause
- func ChanType(x *ast.ChanType) *ast.ChanType
- func CommClause(x *ast.CommClause) *ast.CommClause
- func Comment(x *ast.Comment) *ast.Comment
- func CommentGroup(x *ast.CommentGroup) *ast.CommentGroup
- func CompositeLit(x *ast.CompositeLit) *ast.CompositeLit
- func Decl(x ast.Decl) ast.Decl
- func DeclList(xs []ast.Decl) []ast.Decl
- func DeclStmt(x *ast.DeclStmt) *ast.DeclStmt
- func DeferStmt(x *ast.DeferStmt) *ast.DeferStmt
- func Ellipsis(x *ast.Ellipsis) *ast.Ellipsis
- func EmptyStmt(x *ast.EmptyStmt) *ast.EmptyStmt
- func Expr(x ast.Expr) ast.Expr
- func ExprList(xs []ast.Expr) []ast.Expr
- func ExprStmt(x *ast.ExprStmt) *ast.ExprStmt
- func Field(x *ast.Field) *ast.Field
- func FieldList(x *ast.FieldList) *ast.FieldList
- func File(x *ast.File) *ast.File
- func ForStmt(x *ast.ForStmt) *ast.ForStmt
- func FuncDecl(x *ast.FuncDecl) *ast.FuncDecl
- func FuncLit(x *ast.FuncLit) *ast.FuncLit
- func FuncType(x *ast.FuncType) *ast.FuncType
- func GenDecl(x *ast.GenDecl) *ast.GenDecl
- func GoStmt(x *ast.GoStmt) *ast.GoStmt
- func Ident(x *ast.Ident) *ast.Ident
- func IdentList(xs []*ast.Ident) []*ast.Ident
- func IfStmt(x *ast.IfStmt) *ast.IfStmt
- func ImportSpec(x *ast.ImportSpec) *ast.ImportSpec
- func IncDecStmt(x *ast.IncDecStmt) *ast.IncDecStmt
- func IndexExpr(x *ast.IndexExpr) *ast.IndexExpr
- func IndexListExpr(x *typeparams.IndexListExpr) *typeparams.IndexListExpr
- func InterfaceType(x *ast.InterfaceType) *ast.InterfaceType
- func KeyValueExpr(x *ast.KeyValueExpr) *ast.KeyValueExpr
- func LabeledStmt(x *ast.LabeledStmt) *ast.LabeledStmt
- func MapType(x *ast.MapType) *ast.MapType
- func Node(x ast.Node) ast.Node
- func NodeList(xs []ast.Node) []ast.Node
- func Package(x *ast.Package) *ast.Package
- func ParenExpr(x *ast.ParenExpr) *ast.ParenExpr
- func RangeStmt(x *ast.RangeStmt) *ast.RangeStmt
- func ReturnStmt(x *ast.ReturnStmt) *ast.ReturnStmt
- func SelectStmt(x *ast.SelectStmt) *ast.SelectStmt
- func SelectorExpr(x *ast.SelectorExpr) *ast.SelectorExpr
- func SendStmt(x *ast.SendStmt) *ast.SendStmt
- func SliceExpr(x *ast.SliceExpr) *ast.SliceExpr
- func Spec(x ast.Spec) ast.Spec
- func SpecList(xs []ast.Spec) []ast.Spec
- func StarExpr(x *ast.StarExpr) *ast.StarExpr
- func Stmt(x ast.Stmt) ast.Stmt
- func StmtList(xs []ast.Stmt) []ast.Stmt
- func StructType(x *ast.StructType) *ast.StructType
- func SwitchStmt(x *ast.SwitchStmt) *ast.SwitchStmt
- func TypeAssertExpr(x *ast.TypeAssertExpr) *ast.TypeAssertExpr
- func TypeSpec(x *ast.TypeSpec) *ast.TypeSpec
- func TypeSwitchStmt(x *ast.TypeSwitchStmt) *ast.TypeSwitchStmt
- func UnaryExpr(x *ast.UnaryExpr) *ast.UnaryExpr
- func ValueSpec(x *ast.ValueSpec) *ast.ValueSpec
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignStmt ¶
func AssignStmt(x *ast.AssignStmt) *ast.AssignStmt
AssignStmt 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 BranchStmt ¶
func BranchStmt(x *ast.BranchStmt) *ast.BranchStmt
BranchStmt 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 CommClause ¶
func CommClause(x *ast.CommClause) *ast.CommClause
CommClause 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 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 IndexListExpr ¶ added in v1.0.2
func IndexListExpr(x *typeparams.IndexListExpr) *typeparams.IndexListExpr
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 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 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 TypeSwitchStmt ¶
func TypeSwitchStmt(x *ast.TypeSwitchStmt) *ast.TypeSwitchStmt
TypeSwitchStmt returns x deep copy. Copy of nil argument is nil.
Types ¶
This section is empty.