sources

package
v1.19.0-beta2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2025 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortedSourcesSlice

func SortedSourcesSlice(sourcesSlice []*Sources)

SortedSourcesSlice in place sorts the given slice of Sources by ImportPath. This will not change the order of the files within any Sources.

Types

type Importer

type Importer func(path, srcDir string) (*Sources, error)

type Sources

type Sources struct {
	// ImportPath representing the sources, if exists.
	//
	// May be empty for "virtual"
	// packages like testmain or playground-generated package.
	// Otherwise this must be the absolute import path for a package.
	ImportPath string

	// Dir is the directory containing package sources
	Dir string

	// Files is the parsed and augmented Go AST files for the package.
	Files []*ast.File

	// FileSet is the file set for the parsed files.
	FileSet *token.FileSet

	// JSFiles is the JavaScript files that are part of the package.
	JSFiles []jsFile.JSFile

	// TypeInfo is the type information for this package.
	// This is nil until set by Analyze.
	TypeInfo *analysis.Info

	// Package is the types package for these source files.
	// This is nil until set by TypeCheck.
	Package *types.Package

	// GoLinknames is the set of Go linknames for this package.
	// This is nil until set by ParseGoLinknames.
	GoLinknames []linkname.GoLinkname
	// contains filtered or unexported fields
}

Sources is a slice of parsed Go sources and additional data for a package.

Note that the sources would normally belong to a single logical Go package, but they don't have to be a real Go package (i.e. found on the file system) or represent a complete package (i.e. it could be only a few source files compiled by `gopherjs build foo.go bar.go`).

func (*Sources) Analyze

func (s *Sources) Analyze(importer Importer, tContext *types.Context, instances *typeparams.PackageInstanceSets)

Analyze will determine the type parameters instances, blocking, and other type information for the package. This will set the TypeInfo and Instances fields on the Sources.

This must be called after to simplify to ensure the pointers in the AST are still valid. The instances must be collected prior to this call.

Note that at the end of this call the analysis information has NOT been propagated across packages yet.

func (*Sources) CollectInstances

func (s *Sources) CollectInstances(tc *typeparams.Collector)

CollectInstances will determine the type parameters instances for the package.

This must be called before Analyze to have the type parameters instances needed during analysis.

Note that once all the sources are collected, the collector needs to be finished to ensure all the instances are collected.

func (*Sources) ParseGoLinknames

func (s *Sources) ParseGoLinknames() error

ParseGoLinknames extracts all //go:linkname compiler directive from the sources.

This will set the GoLinknames field on the Sources.

func (*Sources) Simplify

func (s *Sources) Simplify()

Simplify processed each Files entry with astrewrite.Simplify.

Note this function mutates the original Files slice. This must be called after TypeCheck and before analyze since this will change the pointers in the AST. For example, the pointers to function literals will change, making it impossible to find them in the type information, if analyze is called first.

func (*Sources) Sort

func (s *Sources) Sort()

sort the Go files slice by the original source name to ensure consistent order of processing. This is required for reproducible JavaScript output.

Note this function mutates the original Files slice.

func (*Sources) TypeCheck

func (s *Sources) TypeCheck(importer Importer, sizes types.Sizes, tContext *types.Context) error

TypeCheck the sources. Returns information about declared package types and type information for the supplied AST. This will set the Package field on the Sources.

If the Package field is not nil, e.g. this function has already been run, this will be a no-op.

This must be called prior to simplify to get the types.Info used by simplify.

func (*Sources) UnresolvedImports

func (s *Sources) UnresolvedImports(skip ...string) []string

UnresolvedImports calculates the import paths of the package's dependencies based on all the imports in the augmented Go AST files.

This is used to determine the unresolved imports that weren't in the PackageData.Imports slice since they were added during augmentation or during template generation.

The given skip paths (typically those imports from PackageData.Imports) will not be returned in the results. This will not return any `*_test` packages in the results.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL