const debug … var pkgExts … // FindPkg returns the filename and unique package id for an import // path based on package information provided by build.Import (using // the build.Default build.Context). A relative srcDir is interpreted // relative to the current working directory. // If no file was found, an empty filename is returned. // func FindPkg(path, srcDir string) (filename, id string) { … } // ImportData imports a package by reading the gc-generated export data, // adds the corresponding package object to the packages map indexed by id, // and returns the object. // // The packages map must contains all packages already imported. The data // reader position must be the beginning of the export data section. The // filename is only used in error messages. // // If packages[id] contains the completely imported package, that package // can be used directly, and there is no need to call this function (but // there is also no harm but for extra time used). // func ImportData(packages map[string]*types.Package, filename, id string, data io.Reader) (pkg *types.Package, err error) { … } // 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. // func Import(packages map[string]*types.Package, path, srcDir string, lookup func(path string) (io.ReadCloser, error)) (pkg *types.Package, err error) { … } type parser … func (p *parser) init(filename, id string, src io.Reader, packages map[string]*types.Package) { … } func (p *parser) next() { … } func declTypeName(pkg *types.Package, name string) *types.TypeName { … } type importError … func (e importError) Error() string { … } func (p *parser) error(err interface{ … } func (p *parser) errorf(format string, args ...interface{ … } func (p *parser) expect(tok rune) string { … } func (p *parser) expectSpecial(tok string) { … } func (p *parser) expectKeyword(keyword string) { … } // PackageId = string_lit . // func (p *parser) parsePackageID() string { … } // PackageName = ident . // func (p *parser) parsePackageName() string { … } // dotIdentifier = ( ident | '·' ) { ident | int | '·' } . func (p *parser) parseDotIdent() string { … } // QualifiedName = "@" PackageId "." ( "?" | dotIdentifier ) . // func (p *parser) parseQualifiedName() (id, name string) { … } // getPkg returns the package for a given id. If the package is // not found, create the package and add it to the p.localPkgs // and p.sharedPkgs maps. name is the (expected) name of the // package. If name == "", the package name is expected to be // set later via an import clause in the export data. // // id identifies a package, usually by a canonical package path like // "encoding/json" but possibly by a non-canonical import path like // "./json". // func (p *parser) getPkg(id, name string) *types.Package { … } // parseExportedName is like parseQualifiedName, but // the package id is resolved to an imported *types.Package. // func (p *parser) parseExportedName() (pkg *types.Package, name string) { … } // BasicType = identifier . // func (p *parser) parseBasicType() types.Type { … } // ArrayType = "[" int_lit "]" Type . // func (p *parser) parseArrayType(parent *types.Package) types.Type { … } // MapType = "map" "[" Type "]" Type . // func (p *parser) parseMapType(parent *types.Package) types.Type { … } // Name = identifier | "?" | QualifiedName . // // For unqualified and anonymous names, the returned package is the parent // package unless parent == nil, in which case the returned package is the // package being imported. (The parent package is not nil if the name // is an unqualified struct field or interface method name belonging to a // type declared in another package.) // // For qualified names, the returned package is nil (and not created if // it doesn't exist yet) unless materializePkg is set (which creates an // unnamed package with valid package path). In the latter case, a // subsequent import clause is expected to provide a name for the package. // func (p *parser) parseName(parent *types.Package, materializePkg bool) (pkg *types.Package, name string) { … } func deref(typ types.Type) types.Type { … } // Field = Name Type [ string_lit ] . // func (p *parser) parseField(parent *types.Package) (*types.Var, string) { … } // StructType = "struct" "{" [ FieldList ] "}" . // FieldList = Field { ";" Field } . // func (p *parser) parseStructType(parent *types.Package) types.Type { … } // Parameter = ( identifier | "?" ) [ "..." ] Type [ string_lit ] . // func (p *parser) parseParameter() (par *types.Var, isVariadic bool) { … } // Parameters = "(" [ ParameterList ] ")" . // ParameterList = { Parameter "," } Parameter . // func (p *parser) parseParameters() (list []*types.Var, isVariadic bool) { … } // Signature = Parameters [ Result ] . // Result = Type | Parameters . // func (p *parser) parseSignature(recv *types.Var) *types.Signature { … } // InterfaceType = "interface" "{" [ MethodList ] "}" . // MethodList = Method { ";" Method } . // Method = Name Signature . // // The methods of embedded interfaces are always "inlined" // by the compiler and thus embedded interfaces are never // visible in the export data. // func (p *parser) parseInterfaceType(parent *types.Package) types.Type { … } // ChanType = ( "chan" [ "<-" ] | "<-" "chan" ) Type . // func (p *parser) parseChanType(parent *types.Package) types.Type { … } // Type = // BasicType | TypeName | ArrayType | SliceType | StructType | // PointerType | FuncType | InterfaceType | MapType | ChanType | // "(" Type ")" . // // BasicType = ident . // TypeName = ExportedName . // SliceType = "[" "]" Type . // PointerType = "*" Type . // FuncType = "func" Signature . // func (p *parser) parseType(parent *types.Package) types.Type { … } // ImportDecl = "import" PackageName PackageId . // func (p *parser) parseImportDecl() { … } // int_lit = [ "+" | "-" ] { "0" ... "9" } . // func (p *parser) parseInt() string { … } // number = int_lit [ "p" int_lit ] . // func (p *parser) parseNumber() (typ *types.Basic, val constant.Value) { … } // ConstDecl = "const" ExportedName [ Type ] "=" Literal . // Literal = bool_lit | int_lit | float_lit | complex_lit | rune_lit | string_lit . // bool_lit = "true" | "false" . // complex_lit = "(" float_lit "+" float_lit "i" ")" . // rune_lit = "(" int_lit "+" int_lit ")" . // string_lit = `"` { unicode_char } `"` . // func (p *parser) parseConstDecl() { … } // TypeDecl = "type" ExportedName Type . // func (p *parser) parseTypeDecl() { … } // VarDecl = "var" ExportedName Type . // func (p *parser) parseVarDecl() { … } // Func = Signature [ Body ] . // Body = "{" ... "}" . // func (p *parser) parseFunc(recv *types.Var) *types.Signature { … } // MethodDecl = "func" Receiver Name Func . // Receiver = "(" ( identifier | "?" ) [ "*" ] ExportedName ")" . // func (p *parser) parseMethodDecl() { … } // FuncDecl = "func" ExportedName Func . // func (p *parser) parseFuncDecl() { … } // Decl = [ ImportDecl | ConstDecl | TypeDecl | VarDecl | FuncDecl | MethodDecl ] "\n" . // func (p *parser) parseDecl() { … } // Export = "PackageClause { Decl } "$$" . // PackageClause = "package" PackageName [ "safe" ] "\n" . // func (p *parser) parseExport() *types.Package { … } type byPath … func (a byPath) Len() int { … } func (a byPath) Swap(i, j int) { … } func (a byPath) Less(i, j int) bool { … }