Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

astcopy: make it possible to copy ast.Object #1

Open
quasilyte opened this issue Jun 13, 2018 · 2 comments
Open

astcopy: make it possible to copy ast.Object #1

quasilyte opened this issue Jun 13, 2018 · 2 comments

Comments

@quasilyte
Copy link
Contributor

quasilyte commented Jun 13, 2018

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.

@quasilyte quasilyte changed the title add Objects function to copy all objects make it possible to copy ast.Object Jun 13, 2018
@quasilyte quasilyte changed the title make it possible to copy ast.Object astcopy: make it possible to copy ast.Object Jun 13, 2018
@cristaloleg
Copy link
Member

WDYT about astcopy.IdentDeep ?

@quasilyte
Copy link
Contributor Author

@cristaloleg that could work too.

This is not high priority though. go-critic will never need that.

Although it's good that we have an idea how to add this feature if someone really needs it.
We are prepared. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants