Giter Club home page Giter Club logo

astcopy's Issues

When positions doesn't matter

I've come across a problem where I want to copy everything except the position.
To solve this problem I cloned astcopy.go and made changes to all functions.

For example, this is how the UnaryExpr is now copied:

func UnaryExpr(x *ast.UnaryExpr) *ast.UnaryExpr {
	if x == nil {
		return nil
	}
	return &ast.UnaryExpr{
		Op: x.Op,
		X:  copyExpr(x.X),
	}
}

Is this something you would like to incorporate into this repo. Otherwise I will clone this repo and make an alternative version of it.

astcopy: make it possible to copy ast.Object

The problem: astcopy functions do not copy ast.Object fields because some projects may not care about them at all (go/types.Object is better and deprecates ast.Object). But if for whatever reason user must copy objects, there will be troubles.

I'm proposing this functions:

func IdentObjects(dst, src *ast.Ident) {/**/}
func ScopeObjects(dst, src *ast.Scope) {/**/}
func PackageObjects(dst, src *ast.Package) {/**/}

So, copy of *ast.Ident with objects may be done this way:

y := astcopy.Ident(x)
astcopy.IdentObjects(y, x)

This can be wrapped by user into simple function:

func copyIdent(x) *ast.Ident {
  y := astcopy.Ident(x)
  astcopy.IdentObjects(y, x)
  return y
}

This way, we avoid quite expensive copy that may be unnecessary in a first place and provide a way to copy objects if they are required.

Note that copying objects may be non-trivial.
It needs some investigation and problem overview beforehand.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.