Source File
gcimporter.go
Belonging Package
golang.org/x/tools/internal/gcimporter
// Copyright 2011 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// This file is a reduced copy of $GOROOT/src/go/internal/gcimporter/gcimporter.go.// Package gcimporter provides various functions for reading// gc-generated object files that can be used to implement the// Importer interface defined by the Go 1.5 standard library package.//// The encoding is deterministic: if the encoder is applied twice to// the same types.Package data structure, both encodings are equal.// This property may be important to avoid spurious changes in// applications such as build systems.//// However, the encoder is not necessarily idempotent. Importing an// exported package may yield a types.Package that, while it// represents the same set of Go types as the original, may differ in// the details of its internal representation. Because of these// differences, re-encoding the imported package may yield a// different, but equally valid, encoding of the package.package gcimporter // import "golang.org/x/tools/internal/gcimporter"import ()const (// Enable debug during development: it adds some additional checks, and// prevents errors from being recovered.debug = false// If trace is set, debugging output is printed to std out.trace = false)// Import imports a gc-generated package given its import path and srcDir, adds// the corresponding package object to the packages map, and returns the object.// The packages map must contain all packages already imported.//// Import is only used in tests.func ( *token.FileSet, map[string]*types.Package, , string, func( string) (io.ReadCloser, error)) ( *types.Package, error) {var io.ReadCloservar stringif != nil {// With custom lookup specified, assume that caller has// converted path to a canonical import path for use in the map.if == "unsafe" {return types.Unsafe, nil}=// No need to re-import if the package was imported completely before.if = []; != nil && .Complete() {return}, := ()if != nil {return nil,}=} else {var string, , = FindPkg(, )if == "" {if == "unsafe" {return types.Unsafe, nil}return nil,}// no need to re-import if the package was imported completely beforeif = []; != nil && .Complete() {return}// open file, := os.Open()if != nil {return nil,}defer func() {if != nil {// add file name to error= fmt.Errorf("%s: %v", , )}}()=}defer .Close():= bufio.NewReader(), := ReadUnified()if != nil {= fmt.Errorf("import %q: %v", , )return}// unified: emitted by cmd/compile since go1.20._, , = UImportData(, , , )return}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)