compiler: allow to declare global variables in multiple files
Traverse and count globals across all used files. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
babd84ec10
commit
7009417325
6 changed files with 36 additions and 8 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
@ -42,6 +43,16 @@ type buildInfo struct {
|
|||
program *loader.Program
|
||||
}
|
||||
|
||||
// ForEachFile executes fn on each file used in current program.
|
||||
func (c *codegen) ForEachFile(fn func(*ast.File)) {
|
||||
for _, pkg := range c.buildInfo.program.AllPackages {
|
||||
c.typeInfo = &pkg.Info
|
||||
for _, f := range pkg.Files {
|
||||
fn(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getBuildInfo(src interface{}) (*buildInfo, error) {
|
||||
conf := loader.Config{ParserMode: parser.ParseComments}
|
||||
f, err := conf.ParseFile("", src)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue