> 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" >
Right! Awesome as usual! Thanks! > > 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. > It is not that i need to call Load multiple lines, it is that i know for sure, many identical processing will be done multiple times across multiple *binary* calls. I have this package (https://github.com/mh-cbon/export-funcmap), which basically will parse text/template (and few others very recurrent package). Result of this call can be use for several go:generate among the same, or different packages, i don t see why the host machine would re process those again and again and again. Its also a trade about where i spend time optimizing the whole program, spent on this cache, very fast effort, very secure effort, spent on the source code, more longer, difficult work and less confidence. Note that it is not that the loader is slow per se, in regards to what it does i m very satisfied by the speed, just that in my case i can make that happen without too much risk/complexity. BTW, i want to put emphasis that working with the loader/ast/typechecker, while not easy, has always been satisfactory ! thanks for the concerns and all. -- 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.