gc

package
v1.0.1-0...-133e5f6 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2018 License: BSD-3-Clause, BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package gc is a Go compiler front end. Work in progess.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VersionTags

func VersionTags() []string

VersionTags returns

[]string{"go1.1", "go1.2", "go1.3", "go1.4", "go1.5", "go1.6", "go1.7", "go1.8", "go1.9"}

Types

type Bindings

type Bindings map[string]Declaration

Bindings map names to Declarations.

type ConstDecl

type ConstDecl struct {
	// contains filtered or unexported fields
}

ConstDecl describes a constant declaration.

func (*ConstDecl) Const

func (d *ConstDecl) Const() *ConstDecl

Const implements Declaration.

func (*ConstDecl) Func

func (d *ConstDecl) Func() *FuncDecl

Func implements Declaration.

func (*ConstDecl) ImportSpec

func (d *ConstDecl) ImportSpec() *ImportSpec

ImportSpec implements Declaration.

func (*ConstDecl) Kind

func (d *ConstDecl) Kind() DeclarationKind

Kind implements Declaration.

func (*ConstDecl) Method

func (d *ConstDecl) Method() *MethodDecl

Method implements Declaration.

func (*ConstDecl) Name

func (d *ConstDecl) Name() string

Name implements Declaration.

func (*ConstDecl) Pos

func (d *ConstDecl) Pos() token.Pos

Pos implements Declaration.

func (*ConstDecl) Type

func (d *ConstDecl) Type() *TypeDecl

Type implements Declaration.

func (*ConstDecl) Var

func (d *ConstDecl) Var() *VarDecl

Var implements Declaration.

func (*ConstDecl) Visibility

func (d *ConstDecl) Visibility() token.Pos

Visibility implements Declaration.

type Context

type Context struct {
	FileSet *ftoken.FileSet // Contains all loaded files.
	// contains filtered or unexported fields
}

Context describes the context of loaded packages.

func NewContext

func NewContext(goos, goarch string, tags, searchPaths []string, options ...Option) (*Context, error)

NewContext returns a newly created Context. tags are the build tags considered when loading packages having build directives (see https://golang.org/pkg/go/build/#hdr-Build_Constraints for details). searchPaths are examined when looking for a package to load.

func (*Context) Load

func (c *Context) Load(importPath string) (*Package, error)

Load finds the package in importPath and returns the resulting Package or an error if any.

The method is safe for concurrent use by multiple goroutines.

func (*Context) NumPackages

func (c *Context) NumPackages() int

NumPackages returns the number of loaded packages.

The method is safe for concurrent use by multiple goroutines.

func (*Context) SourceFileForPath

func (c *Context) SourceFileForPath(path string) *SourceFile

SourceFileForPath searches loaded packages for the one containing the file at path and returns the corresponding SourceFile. The result is nil if the file is not considered for build by any of the loaded packages.

The method is safe for concurrent use by multiple goroutines.

type Declaration

type Declaration interface {
	Node

	// Const returns the Declaration's *ConstDecl. It panics if Kind is not
	// ConstDeclaration.
	Const() *ConstDecl

	// Func returns the Declaration's  *FuncDecl. It panics if Kind is not
	// FuncDeclaration.
	Func() *FuncDecl

	// ImportSpec returns the Declaration's  *ImportSpec. It panics if Kind
	// is not ImportDeclaration.
	ImportSpec() *ImportSpec

	// Kind returns the Declarations's kind.
	Kind() DeclarationKind

	// Method returns the Declaration's  *MethodDecl. It panics if Kind is
	// not MethodDeclaration.
	Method() *MethodDecl

	// Name returns the declared name.
	Name() string

	// Type returns the Declaration's  *TypeDecl. It panics if Kind is not
	// TypeDeclaration.
	Type() *TypeDecl

	// Var returns the Declaration's  *VarDecl. It panics if Kind is not
	// VarDeclaration.
	Var() *VarDecl

	// Visibility returns the position at which the declaration is visible
	// in its declaration scope or token.NoPos for declarations in package
	// and file scope.
	Visibility() token.Pos
}

Declaration describes a constant, function, method, type or variable declaration.

type DeclarationKind

type DeclarationKind int

DeclarationKind describes a Declaration's Kind.

const (
	ConstDeclaration DeclarationKind = iota
	FuncDeclaration
	ImportDeclaration
	MethodDeclaration
	TypeDeclaration
	VarDeclaration
)

Values of DeclarationKind.

func (DeclarationKind) String

func (i DeclarationKind) String() string

type FuncDecl

type FuncDecl struct {
	// contains filtered or unexported fields
}

FuncDecl describes a function declaration.

func (*FuncDecl) Const

func (d *FuncDecl) Const() *ConstDecl

Const implements Declaration.

func (*FuncDecl) Func

func (d *FuncDecl) Func() *FuncDecl

Func implements Declaration.

func (*FuncDecl) ImportSpec

func (d *FuncDecl) ImportSpec() *ImportSpec

ImportSpec implements Declaration.

func (*FuncDecl) Kind

func (d *FuncDecl) Kind() DeclarationKind

Kind implements Declaration.

func (*FuncDecl) Method

func (d *FuncDecl) Method() *MethodDecl

Method implements Declaration.

func (*FuncDecl) Name

func (d *FuncDecl) Name() string

Name implements Declaration.

func (*FuncDecl) Pos

func (d *FuncDecl) Pos() token.Pos

Pos implements Declaration.

func (*FuncDecl) Type

func (d *FuncDecl) Type() *TypeDecl

Type implements Declaration.

func (*FuncDecl) Var

func (d *FuncDecl) Var() *VarDecl

Var implements Declaration.

func (*FuncDecl) Visibility

func (d *FuncDecl) Visibility() token.Pos

Visibility implements Declaration.

type ImportSpec

type ImportSpec struct {
	Dot        bool     // The `import . "foo/bar"` variant is used.
	ImportPath string   // `foo/bar` in `import "foo/bar"`
	Package    *Package // The imported package, if exists.
	Qualifier  string   // `baz` in `import baz "foo/bar"`.
	// contains filtered or unexported fields
}

ImportSpec is an import declaration.

func (*ImportSpec) Const

func (d *ImportSpec) Const() *ConstDecl

Const implements Declaration.

func (*ImportSpec) Func

func (d *ImportSpec) Func() *FuncDecl

Func implements Declaration.

func (*ImportSpec) ImportSpec

func (n *ImportSpec) ImportSpec() *ImportSpec

ImportSpec implements Declaration.

func (*ImportSpec) Kind

func (n *ImportSpec) Kind() DeclarationKind

Kind implements Declaration.

func (*ImportSpec) Method

func (d *ImportSpec) Method() *MethodDecl

Method implements Declaration.

func (*ImportSpec) Name

func (n *ImportSpec) Name() string

Name implements Declaration.

func (*ImportSpec) Pos

func (d *ImportSpec) Pos() token.Pos

Pos implements Declaration.

func (*ImportSpec) Type

func (d *ImportSpec) Type() *TypeDecl

Type implements Declaration.

func (*ImportSpec) Var

func (d *ImportSpec) Var() *VarDecl

Var implements Declaration.

func (*ImportSpec) Visibility

func (d *ImportSpec) Visibility() token.Pos

Visibility implements Declaration.

type Lexer

type Lexer struct {
	CommentHandler func(off int32, lit []byte)
	// contains filtered or unexported fields
}

Lexer tokenizes source code.

func NewLexer

func NewLexer(file *ftoken.File, src []byte) *Lexer

NewLexer returns a newly created Lexer.

func (*Lexer) Scan

func (l *Lexer) Scan() (off int32, tok token.Token)

Scan returns the next token and its offset.

func (*Lexer) Token

func (l *Lexer) Token(off int32) Token

Token returns the last scanned Token. 'off' must be the offset returned from last call to Scan().

type MethodDecl

type MethodDecl struct {
	// contains filtered or unexported fields
}

MethodDecl describes a method declaration.

func (*MethodDecl) Const

func (d *MethodDecl) Const() *ConstDecl

Const implements Declaration.

func (*MethodDecl) Func

func (d *MethodDecl) Func() *FuncDecl

Func implements Declaration.

func (*MethodDecl) ImportSpec

func (d *MethodDecl) ImportSpec() *ImportSpec

ImportSpec implements Declaration.

func (*MethodDecl) Kind

func (d *MethodDecl) Kind() DeclarationKind

Kind implements Declaration.

func (*MethodDecl) Method

func (d *MethodDecl) Method() *MethodDecl

Method implements Declaration.

func (*MethodDecl) Name

func (d *MethodDecl) Name() string

Name implements Declaration.

func (*MethodDecl) Pos

func (d *MethodDecl) Pos() token.Pos

Pos implements Declaration.

func (*MethodDecl) Type

func (d *MethodDecl) Type() *TypeDecl

Type implements Declaration.

func (*MethodDecl) Var

func (d *MethodDecl) Var() *VarDecl

Var implements Declaration.

func (*MethodDecl) Visibility

func (d *MethodDecl) Visibility() token.Pos

Visibility implements Declaration.

type Node

type Node interface {
	Pos() token.Pos
}

Node is implemented by all AST nodes.

type Option

type Option func(c *Context) error

Option amends Context.

func DeclarationXref

func DeclarationXref() Option

DeclarationXref enables keeping a declaration cross reference.

func IgnoreRedeclarations

func IgnoreRedeclarations() Option

IgnoreRedeclarations disables reporting redeclarations as errors.

type Package

type Package struct {
	Dir         string
	ImportPath  string
	ImportedBy  map[string]struct{} // R/O, key: import path.
	Imports     map[string]struct{} // R/O, key: import path.
	Name        string
	Scope       *Scope // Package scope.
	SourceFiles []*SourceFile
	// contains filtered or unexported fields
}

Package describes a package.

type Scope

type Scope struct {
	Bindings Bindings
	Kind     ScopeKind
	Labels   Bindings
	Parent   *Scope
	Unbound  []Declaration // Declarations named _.
	// contains filtered or unexported fields
}

Scope tracks declarations.

func (*Scope) Lookup

func (s *Scope) Lookup(pkg *Package, fileScope *Scope, nm Token) Declaration

Lookup searches for nm in s or any of its parents. fileScope, if not nil, is searched prior to searching the universe scope when lookup does not find nm in package scope and s belongs to pkg.

type ScopeKind

type ScopeKind int

ScopeKind describe a Scope's Kind.

const (
	UniverseScope ScopeKind = iota
	PackageScope
	FileScope
	BlockScope
)

Values of ScopeKind.

func (ScopeKind) String

func (i ScopeKind) String() string

type SourceFile

type SourceFile struct {
	File          *ftoken.File
	ImportSpecs   []*ImportSpec
	InitFunctions []Declaration
	Package       *Package
	Path          string
	Scope         *Scope // File scope.
	TopLevelDecls []Declaration
	Xref          map[token.Pos]token.Pos // Identifier position: declaration position.
	Xref0         map[Token]*Scope        // Token: Resolution scope. Enabled by DeclarationXref.
	// contains filtered or unexported fields
}

SourceFile describes a source file.

type Token

type Token struct {
	Pos token.Pos
	Val string
}

Token represents the position and value of a token.

type TypeDecl

type TypeDecl struct {
	// contains filtered or unexported fields
}

TypeDecl describes a type declaration.

func (*TypeDecl) Const

func (d *TypeDecl) Const() *ConstDecl

Const implements Declaration.

func (*TypeDecl) Func

func (d *TypeDecl) Func() *FuncDecl

Func implements Declaration.

func (*TypeDecl) ImportSpec

func (d *TypeDecl) ImportSpec() *ImportSpec

ImportSpec implements Declaration.

func (*TypeDecl) Kind

func (d *TypeDecl) Kind() DeclarationKind

Kind implements Declaration.

func (*TypeDecl) Method

func (d *TypeDecl) Method() *MethodDecl

Method implements Declaration.

func (*TypeDecl) Name

func (d *TypeDecl) Name() string

Name implements Declaration.

func (*TypeDecl) Pos

func (d *TypeDecl) Pos() token.Pos

Pos implements Declaration.

func (*TypeDecl) Type

func (d *TypeDecl) Type() *TypeDecl

Type implements Declaration.

func (*TypeDecl) Var

func (d *TypeDecl) Var() *VarDecl

Var implements Declaration.

func (*TypeDecl) Visibility

func (d *TypeDecl) Visibility() token.Pos

Visibility implements Declaration.

type VarDecl

type VarDecl struct {
	// contains filtered or unexported fields
}

VarDecl describes a variable declaration.

func (*VarDecl) Const

func (d *VarDecl) Const() *ConstDecl

Const implements Declaration.

func (*VarDecl) Func

func (d *VarDecl) Func() *FuncDecl

Func implements Declaration.

func (*VarDecl) ImportSpec

func (d *VarDecl) ImportSpec() *ImportSpec

ImportSpec implements Declaration.

func (*VarDecl) Kind

func (d *VarDecl) Kind() DeclarationKind

Kind implements Declaration.

func (*VarDecl) Method

func (d *VarDecl) Method() *MethodDecl

Method implements Declaration.

func (*VarDecl) Name

func (d *VarDecl) Name() string

Name implements Declaration.

func (*VarDecl) Pos

func (d *VarDecl) Pos() token.Pos

Pos implements Declaration.

func (*VarDecl) Type

func (d *VarDecl) Type() *TypeDecl

Type implements Declaration.

func (*VarDecl) Var

func (d *VarDecl) Var() *VarDecl

Var implements Declaration.

func (*VarDecl) Visibility

func (d *VarDecl) Visibility() token.Pos

Visibility implements Declaration.

Jump to

Keyboard shortcuts

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