package types // Global bridge variables - DEPRECATED. These exist only for the legacy // compiler's codegen which reads them directly. Stage4 code accesses // these through cctx.universe.Registry / cctx.universe.DirectImports. var ImportRegistry map[string]*TCPackage var PkgDirectImports map[string][]string // ImportByName / LookupImportByName - DEPRECATED. Use UniverseState.LookupByName. var ImportByName map[string]*TCPackage func LookupImportByName(name string) (pkg *TCPackage) { if ImportByName == nil { ImportByName = map[string]*TCPackage{} for _, p := range ImportRegistry { if p != nil { ImportByName[p.Name] = p } } } return ImportByName[name] } func EnsureImportRegistry() {} // DirectImportPaths on UniverseState - the correct path. func (u *UniverseState) DirectImportPaths(pkg *TCPackage) (paths []string) { if pkg == nil || u == nil { return nil } if ps, ok := u.DirectImports[pkg.Path]; ok { return ps } var out []string for _, ip := range pkg.Imports { push(out, ip.Path) } if len(out) == 0 { sc := pkg.Scope if sc == nil { return nil } for _, n := range sc.Names() { if pn, ok := sc.Lookup(n).(*PkgName); ok && pn.Imported != nil { push(out, pn.Imported.Path) } } } u.DirectImports[pkg.Path] = out return out } // DirectImportPaths - DEPRECATED global version. Use UniverseState method. func DirectImportPaths(pkg *TCPackage) (paths []string) { if pkg == nil { return nil } if ps, ok := PkgDirectImports[pkg.Path]; ok { return ps } var out []string for _, ip := range pkg.Imports { push(out, ip.Path) } if len(out) == 0 { sc := pkg.Scope if sc == nil { return nil } for _, n := range sc.Names() { if pn, ok := sc.Lookup(n).(*PkgName); ok && pn.Imported != nil { push(out, pn.Imported.Path) } } } PkgDirectImports[pkg.Path] = out return out }