github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/internal/loader/vendor.patch (about) 1 diff --git a/loader.go b/loader.go 2 index 5555faa..11d06af 100644 3 --- a/loader.go 4 +++ b/loader.go 5 @@ -11,16 +11,15 @@ import ( 6 "fmt" 7 "go/ast" 8 "go/build" 9 + goimporter "go/importer" 10 "go/parser" 11 "go/token" 12 + "go/types" 13 "os" 14 "sort" 15 "strings" 16 "sync" 17 "time" 18 - 19 - "github.com/democratic-coin/dcoin-go/vendor/src/golang.org/x/tools/go/ast/astutil" 20 - "github.com/democratic-coin/dcoin-go/vendor/src/golang.org/x/tools/go/types" 21 ) 22 23 const trace = false // show timing info for type-checking 24 @@ -303,33 +302,6 @@ func (conf *Config) addImport(path string, tests bool) { 25 conf.ImportPkgs[path] = conf.ImportPkgs[path] || tests 26 } 27 28 -// PathEnclosingInterval returns the PackageInfo and ast.Node that 29 -// contain source interval [start, end), and all the node's ancestors 30 -// up to the AST root. It searches all ast.Files of all packages in prog. 31 -// exact is defined as for astutil.PathEnclosingInterval. 32 -// 33 -// The zero value is returned if not found. 34 -// 35 -func (prog *Program) PathEnclosingInterval(start, end token.Pos) (pkg *PackageInfo, path []ast.Node, exact bool) { 36 - for _, info := range prog.AllPackages { 37 - for _, f := range info.Files { 38 - if f.Pos() == token.NoPos { 39 - // This can happen if the parser saw 40 - // too many errors and bailed out. 41 - // (Use parser.AllErrors to prevent that.) 42 - continue 43 - } 44 - if !tokenFileContainsPos(prog.Fset.File(f.Pos()), start) { 45 - continue 46 - } 47 - if path, exact := astutil.PathEnclosingInterval(f, start, end); path != nil { 48 - return info, path, exact 49 - } 50 - } 51 - } 52 - return nil, nil, false 53 -} 54 - 55 // InitialPackages returns a new slice containing the set of initial 56 // packages (Created + Imported) in unspecified order. 57 // 58 @@ -690,55 +662,6 @@ func (conf *Config) parsePackageFiles(bp *build.Package, which rune) ([]*ast.Fil 59 return files, errs 60 } 61 62 -// doImport imports the package denoted by path. 63 -// It implements the types.Importer signature. 64 -// 65 -// imports is the type-checker's package canonicalization map. 66 -// 67 -// It returns an error if a package could not be created 68 -// (e.g. go/build or parse error), but type errors are reported via 69 -// the types.Config.Error callback (the first of which is also saved 70 -// in the package's PackageInfo). 71 -// 72 -// Idempotent. 73 -// 74 -func (imp *importer) doImport(from *PackageInfo, to string) (*types.Package, error) { 75 - // Package unsafe is handled specially, and has no PackageInfo. 76 - // TODO(adonovan): move this check into go/types? 77 - if to == "unsafe" { 78 - return types.Unsafe, nil 79 - } 80 - if to == "C" { 81 - // This should be unreachable, but ad hoc packages are 82 - // not currently subject to cgo preprocessing. 83 - // See https://github.com/democratic-coin/dcoin-go/vendor/src/github.com/golang/go/issues/11627. 84 - return nil, fmt.Errorf(`the loader doesn't cgo-process ad hoc packages like %q; see Go issue 11627`, 85 - from.Pkg.Path()) 86 - } 87 - 88 - imp.importedMu.Lock() 89 - ii := imp.imported[to] 90 - imp.importedMu.Unlock() 91 - if ii == nil { 92 - panic("internal error: unexpected import: " + to) 93 - } 94 - if ii.err != nil { 95 - return nil, ii.err 96 - } 97 - if ii.info != nil { 98 - return ii.info.Pkg, nil 99 - } 100 - 101 - // Import of incomplete package: this indicates a cycle. 102 - fromPath := from.Pkg.Path() 103 - if cycle := imp.findPath(to, fromPath); cycle != nil { 104 - cycle = append([]string{fromPath}, cycle...) 105 - return nil, fmt.Errorf("import cycle: %s", strings.Join(cycle, " -> ")) 106 - } 107 - 108 - panic("internal error: import of incomplete (yet acyclic) package: " + fromPath) 109 -} 110 - 111 // loadAll loads, parses, and type-checks the specified packages in 112 // parallel and returns their completed importInfos in unspecified order. 113 // 114 @@ -922,9 +845,7 @@ func (imp *importer) newPackageInfo(path string) *PackageInfo { 115 if f := imp.conf.TypeCheckFuncBodies; f != nil { 116 tc.IgnoreFuncBodies = !f(path) 117 } 118 - tc.Import = func(_ map[string]*types.Package, to string) (*types.Package, error) { 119 - return imp.doImport(info, to) 120 - } 121 + tc.Importer = goimporter.Default() 122 tc.Error = info.appendError // appendError wraps the user's Error function 123 124 info.checker = types.NewChecker(&tc, imp.conf.fset(), pkg, &info.Info) 125 diff --git a/util.go b/util.go 126 index 0404e99..b651fc6 100644 127 --- a/util.go 128 +++ b/util.go 129 @@ -11,10 +11,9 @@ import ( 130 "go/token" 131 "io" 132 "os" 133 + "path/filepath" 134 "strconv" 135 "sync" 136 - 137 - "github.com/democratic-coin/dcoin-go/vendor/src/golang.org/x/tools/go/buildutil" 138 ) 139 140 // We use a counting semaphore to limit 141 @@ -29,6 +28,15 @@ var sema = make(chan bool, 10) 142 // displayPath is used to transform the filenames attached to the ASTs. 143 // 144 func parseFiles(fset *token.FileSet, ctxt *build.Context, displayPath func(string) string, dir string, files []string, mode parser.Mode) ([]*ast.File, []error) { 145 + isAbsPath := ctxt.IsAbsPath 146 + if isAbsPath == nil { 147 + isAbsPath = filepath.IsAbs 148 + } 149 + joinPath := ctxt.JoinPath 150 + if joinPath == nil { 151 + joinPath = filepath.Join 152 + } 153 + 154 if displayPath == nil { 155 displayPath = func(path string) string { return path } 156 } 157 @@ -37,8 +45,8 @@ func parseFiles(fset *token.FileSet, ctxt *build.Context, displayPath func(strin 158 parsed := make([]*ast.File, n) 159 errors := make([]error, n) 160 for i, file := range files { 161 - if !buildutil.IsAbsPath(ctxt, file) { 162 - file = buildutil.JoinPath(ctxt, dir, file) 163 + if !isAbsPath(file) { 164 + file = joinPath(dir, file) 165 } 166 wg.Add(1) 167 go func(i int, file string) {