On Friday, 20 January 2017 14:11:37 UTC-5, mhh...@gmail.com wrote:
>
> Hi,
>
> How would i revert an ast.Decl (import, var, ect) 
> to the file path declaring it ?
>
> Looks like ast.File does not remember its path,
> https://golang.org/pkg/go/ast/#File
>
>
The parser stores in the FileSet a mapping from token.Pos positions to 
file/line/column triples.
Every piece of syntax (ast.File, ast.FuncDecl, etc) has a Pos for its start 
and end positions, and perhaps others too.

fset := token.NewFileSet( 
f, err := parser.Parse(fset, "foo.go", ...)
fmt.Println(fset.Position(f.Pos())) // "foo.go:1:1"


I process go files via the loader to produce some results.
> But the loader has a lot to do, 
> thus it takes a noticeable amount of time, 
> so i wish to cache this step using 
> the files timestamp, hash (whatever), 
> of the files i m interesting in.
>

The loader (golang.org/x/tools/go/loader) loads each package only once and 
caches it, even if there are many ways in which it is imported by your 
initial packages.

But each call to Load is completely independent of the others.  It would be 
nice if you could just add more packages and load again, but there are 
subtle technical obstacles that make this very hard.

What are you doing that requires multiple calls to Load?  Most tools only 
need a single call.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to