compiler: allow to use exported variables
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
b8d7e93459
commit
6df019913d
5 changed files with 124 additions and 23 deletions
|
@ -49,11 +49,29 @@ func (c *codegen) ForEachFile(fn func(*ast.File, *types.Package)) {
|
|||
for _, pkg := range c.buildInfo.program.AllPackages {
|
||||
c.typeInfo = &pkg.Info
|
||||
for _, f := range pkg.Files {
|
||||
c.fillImportMap(f, pkg.Pkg)
|
||||
fn(f, pkg.Pkg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fillImportMap fills import map for f.
|
||||
func (c *codegen) fillImportMap(f *ast.File, pkg *types.Package) {
|
||||
c.importMap = map[string]string{"": pkg.Path()}
|
||||
for _, imp := range f.Imports {
|
||||
// We need to load find package metadata because
|
||||
// name specified in `package ...` decl, can be in
|
||||
// conflict with package path.
|
||||
pkgPath := strings.Trim(imp.Path.Value, `"`)
|
||||
realPkg := c.buildInfo.program.Package(pkgPath)
|
||||
name := realPkg.Pkg.Name()
|
||||
if imp.Name != nil {
|
||||
name = imp.Name.Name
|
||||
}
|
||||
c.importMap[name] = realPkg.Pkg.Path()
|
||||
}
|
||||
}
|
||||
|
||||
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