gc

package module
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: BSD-3-Clause Imports: 18 Imported by: 2

README

gc

Package GC is a Go compiler front end. (Work in progress, API unstable)

Installation

$ go get modernc.org/gc/v2

Documentation: pkg.go.dev/modernc.org/gc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ExtendedErrors optionally amends errors with a stack mini trace. Intended
	// for debugging only.
	ExtendedErrors bool
)
View Source
var Keywords = map[string]Ch{
	"break":       BREAK,
	"case":        CASE,
	"chan":        CHAN,
	"const":       CONST,
	"continue":    CONTINUE,
	"default":     DEFAULT,
	"defer":       DEFER,
	"else":        ELSE,
	"fallthrough": FALLTHROUGH,
	"for":         FOR,
	"func":        FUNC,
	"go":          GO,
	"goto":        GOTO,
	"if":          IF,
	"import":      IMPORT,
	"interface":   INTERFACE,
	"map":         MAP,
	"package":     PACKAGE,
	"range":       RANGE,
	"return":      RETURN,
	"select":      SELECT,
	"struct":      STRUCT,
	"switch":      SWITCH,
	"type":        TYPE,
	"var":         VAR,
}

Keywords represents the mapping of identifiers to Go reserved names.

Functions

This section is empty.

Types

type ABI added in v2.1.0

type ABI struct {
	ByteOrder binary.ByteOrder

	Types map[Kind]AbiType
	// contains filtered or unexported fields
}

ABI describes selected parts of the Application Binary Interface.

func NewABI added in v2.1.0

func NewABI(os, arch string) (*ABI, error)

NewABI creates an ABI based on the os+arch pair.

type AbiType added in v2.1.0

type AbiType struct {
	Size       int64
	Align      int
	FieldAlign int
}

type AliasDecl added in v2.0.2

type AliasDecl struct {
	Ident     Token
	Eq        Token
	TypeNode  Node
	Semicolon Token
	// contains filtered or unexported fields
}

AliasDecl describes a type alias.

AliasDecl = identifier "=" Type .

func (AliasDecl) LexicalScope added in v2.2.0

func (n AliasDecl) LexicalScope() *Scope

LexicalScope returns the lexical scope n appears in.

func (*AliasDecl) Position added in v2.0.2

func (n *AliasDecl) Position() (r token.Position)

Position implements Node.

func (*AliasDecl) Source added in v2.0.2

func (n *AliasDecl) Source(full bool) []byte

Source implements Node.

func (*AliasDecl) Tokens added in v2.1.0

func (n *AliasDecl) Tokens() []Token

Tokens returns the tokens n consist of.

func (AliasDecl) Type added in v2.0.2

func (t AliasDecl) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type AliasType added in v2.0.2

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

AliasType represents an alias type.

func (*AliasType) Kind added in v2.0.2

func (t *AliasType) Kind() Kind

Kind implements Type.

func (*AliasType) Position added in v2.0.2

func (t *AliasType) Position() (r token.Position)

Position implements Node.

func (AliasType) Source added in v2.0.2

func (AliasType) Source(bool) []byte

Source implements Node. It returns nil.

func (*AliasType) String added in v2.0.2

func (t *AliasType) String() string

func (AliasType) Tokens added in v2.1.0

func (AliasType) Tokens() []Token

Tokens implements Node. It returns nil.

func (AliasType) Type added in v2.0.2

func (t AliasType) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type Arguments added in v2.0.2

type Arguments struct {
	PrimaryExpr Expression
	LParen      Token
	TypeArg     Node
	Comma       Token
	ExprList    []*ExprListItem
	Ellipsis    Token
	Comma2      Token
	RParen      Token
	// contains filtered or unexported fields
}

Arguments describes a call or conversion.

Arguments = PrimaryExpr "(" [ ( ExpressionList | Type [ "," ExpressionList ] ) [ "..." ] [ "," ] ] ")" .

func (*Arguments) Position added in v2.0.2

func (n *Arguments) Position() (r token.Position)

Position implements Node.

func (*Arguments) SetValue added in v2.0.2

func (v *Arguments) SetValue(val constant.Value)

SetValue implements Expression

func (*Arguments) Source added in v2.0.2

func (n *Arguments) Source(full bool) []byte

Source implements Node.

func (*Arguments) Tokens added in v2.1.0

func (n *Arguments) Tokens() []Token

Tokens returns the tokens n consist of.

func (Arguments) Type added in v2.0.2

func (t Arguments) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (Arguments) Value added in v2.0.2

func (v Arguments) Value() constant.Value

Value implements Expression

type ArrayType added in v2.0.2

type ArrayType struct {
	Elem Type
	Len  int64
	// contains filtered or unexported fields
}

ArrayType represents an array type.

func (*ArrayType) Kind added in v2.0.2

func (t *ArrayType) Kind() Kind

Kind implements Type.

func (*ArrayType) Position added in v2.0.2

func (t *ArrayType) Position() (r token.Position)

Position implements Node.

func (ArrayType) Source added in v2.0.2

func (ArrayType) Source(bool) []byte

Source implements Node. It returns nil.

func (*ArrayType) String added in v2.0.2

func (t *ArrayType) String() string

func (ArrayType) Tokens added in v2.1.0

func (ArrayType) Tokens() []Token

Tokens implements Node. It returns nil.

type ArrayTypeNode added in v2.0.2

type ArrayTypeNode struct {
	LBracket    Token
	ArrayLength Expression
	Ellipsis    Token
	RBracket    Token
	ElementType Node
	// contains filtered or unexported fields
}

ArrayTypeNode describes a channel type.

ArrayType   = "[" ArrayLength "]" ElementType .
ArrayLength = Expression | "..."

func (*ArrayTypeNode) Position added in v2.0.2

func (n *ArrayTypeNode) Position() (r token.Position)

Position implements Node.

func (*ArrayTypeNode) Source added in v2.0.2

func (n *ArrayTypeNode) Source(full bool) []byte

Source implements Node.

func (*ArrayTypeNode) Tokens added in v2.1.0

func (n *ArrayTypeNode) Tokens() []Token

Tokens returns the tokens n consist of.

func (ArrayTypeNode) Type added in v2.0.2

func (t ArrayTypeNode) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type Assignment added in v2.0.2

type Assignment struct {
	LExprList []*ExprListItem
	AssOp     Token
	RExprList []*ExprListItem
	Semicolon Token
	// contains filtered or unexported fields
}

Assignment describes a short variable declaration.

Assignment = ExpressionList assign_op ExpressionList .

func (*Assignment) Position added in v2.0.2

func (n *Assignment) Position() (r token.Position)

Position implements Node.

func (*Assignment) Source added in v2.0.2

func (n *Assignment) Source(full bool) []byte

Source implements Node.

func (*Assignment) Tokens added in v2.1.0

func (n *Assignment) Tokens() []Token

Tokens returns the tokens n consist of.

type BasicLit added in v2.0.2

type BasicLit struct {
	Token Token
	// contains filtered or unexported fields
}

BasicLit represents a basic literal.

func (*BasicLit) Position added in v2.0.2

func (n *BasicLit) Position() (r token.Position)

Position implements Node.

func (*BasicLit) SetValue added in v2.0.2

func (v *BasicLit) SetValue(val constant.Value)

SetValue implements Expression

func (*BasicLit) Source added in v2.0.2

func (n *BasicLit) Source(full bool) []byte

Source implements Node.

func (*BasicLit) Tokens added in v2.1.0

func (n *BasicLit) Tokens() []Token

Tokens returns the tokens n consist of.

func (BasicLit) Type added in v2.0.2

func (t BasicLit) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (BasicLit) Value added in v2.0.2

func (v BasicLit) Value() constant.Value

Value implements Expression

type BinaryExpr added in v2.0.2

type BinaryExpr struct {
	A  Expression
	Op Token
	B  Expression
	// contains filtered or unexported fields
}

BinaryExpr describes a binary expression.

func (*BinaryExpr) Position added in v2.0.2

func (n *BinaryExpr) Position() (r token.Position)

Position implements Node.

func (*BinaryExpr) SetValue added in v2.0.2

func (v *BinaryExpr) SetValue(val constant.Value)

SetValue implements Expression

func (*BinaryExpr) Source added in v2.0.2

func (n *BinaryExpr) Source(full bool) []byte

Source implements Node.

func (*BinaryExpr) Tokens added in v2.1.0

func (n *BinaryExpr) Tokens() []Token

Tokens returns the tokens n consist of.

func (BinaryExpr) Type added in v2.0.2

func (t BinaryExpr) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (BinaryExpr) Value added in v2.0.2

func (v BinaryExpr) Value() constant.Value

Value implements Expression

type Block added in v2.0.2

type Block struct {
	LBrace        Token
	StatementList []Node
	RBrace        Token
	Semicolon     Token
	Scope         *Scope
}

Block describes a compound statement.

Block = "{" StatementList "}" .

func (*Block) Position added in v2.0.2

func (n *Block) Position() (r token.Position)

Position implements Node.

func (*Block) Source added in v2.0.2

func (n *Block) Source(full bool) []byte

Source implements Node.

func (*Block) Tokens added in v2.1.0

func (n *Block) Tokens() []Token

Tokens returns the tokens n consist of.

type BreakStmt added in v2.0.2

type BreakStmt struct {
	Break     Token
	Label     Token
	Semicolon Token
}

BreakStmt describes a continue statement.

BreakStmt = "break" [ Label ] .

func (*BreakStmt) Position added in v2.0.2

func (n *BreakStmt) Position() (r token.Position)

Position implements Node.

func (*BreakStmt) Source added in v2.0.2

func (n *BreakStmt) Source(full bool) []byte

Source implements Node.

func (*BreakStmt) Tokens added in v2.1.0

func (n *BreakStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type Ch

type Ch rune

Ch represents the lexical value of a Token. Valid values of type Ch are non-zero.

const (
	ADD_ASSIGN     Ch // +=
	AND_ASSIGN        // &=
	AND_NOT           // &^
	AND_NOT_ASSIGN    // &^=
	ARROW             // <-
	BREAK             // break
	CASE              // case
	CHAN              // chan
	CONST             // const
	CONTINUE          // continue
	DEC               // --
	DEFAULT           // default
	DEFER             // defer
	DEFINE            // :=
	ELLIPSIS          // ...
	ELSE              // else
	EOF               // end of file
	EQ                // ==
	FALLTHROUGH       // fallthrough
	FLOAT_LIT         // floating point literal
	FOR               // for
	FUNC              // func
	GE                // >=
	GO                // go
	GOTO              // goto
	IDENTIFIER        // identifier
	IF                // if
	IMAG_LIT          // imaginary literal
	IMPORT            // import
	INC               // ++
	INTERFACE         // interface
	INT_LIT           // integer literal
	LAND              // &&
	LE                // <=
	LOR               // ||
	MAP               // map
	MUL_ASSIGN        // *=
	NE                // !=
	OR_ASSIGN         // |=
	PACKAGE           // package
	QUO_ASSIGN        // /=
	RANGE             // range
	REM_ASSIGN        // %=
	RETURN            // return
	RUNE_LIT          // rune literal
	SELECT            // select
	SHL               // <<
	SHL_ASSIGN        // <<=
	SHR               // >>
	SHR_ASSIGN        // >>=
	STRING_LIT        // string literal
	STRUCT            // struct
	SUB_ASSIGN        // -=
	SWITCH            // switch
	TILDE             // ~
	TYPE              // type
	VAR               // var
	XOR_ASSIGN        // ^=

)

Named values of Ch.

func (Ch) String

func (i Ch) String() string

type ChanDir added in v2.0.2

type ChanDir int

ChanDir represents a channel direction.

const (
	SendRecv ChanDir = iota
	SendOnly
	RecvOnly
)

Values of type ChanDir.

type ChannelType added in v2.0.2

type ChannelType struct {
	Dir  ChanDir
	Elem Type
	// contains filtered or unexported fields
}

ChannelType represents a channel type.

func (*ChannelType) Kind added in v2.0.2

func (t *ChannelType) Kind() Kind

Kind implements Type.

func (*ChannelType) Position added in v2.0.2

func (t *ChannelType) Position() (r token.Position)

Position implements Node.

func (ChannelType) Source added in v2.0.2

func (ChannelType) Source(bool) []byte

Source implements Node. It returns nil.

func (*ChannelType) String added in v2.0.2

func (t *ChannelType) String() string

func (ChannelType) Tokens added in v2.1.0

func (ChannelType) Tokens() []Token

Tokens implements Node. It returns nil.

type ChannelTypeNode added in v2.0.2

type ChannelTypeNode struct {
	ArrowPre    Token
	Chan        Token
	ArrayPost   Token
	ElementType Node
	// contains filtered or unexported fields
}

ChannelTypeNode describes a channel type.

ChannelTypeNode = ( "chan" | "chan" "<-" | "<-" "chan" ) ElementType .

func (*ChannelTypeNode) Position added in v2.0.2

func (n *ChannelTypeNode) Position() (r token.Position)

Position implements Node.

func (*ChannelTypeNode) Source added in v2.0.2

func (n *ChannelTypeNode) Source(full bool) []byte

Source implements Node.

func (*ChannelTypeNode) Tokens added in v2.1.0

func (n *ChannelTypeNode) Tokens() []Token

Tokens returns the tokens n consist of.

type CommCase added in v2.0.2

type CommCase struct {
	CaseOrDefault Token
	Statement     Node
}

CommCase describes an communication clause case.

CommCase   = "case" ( SendStmt | RecvStmt ) | "default" .

func (*CommCase) Position added in v2.0.2

func (n *CommCase) Position() (r token.Position)

Position implements Node.

func (*CommCase) Source added in v2.0.2

func (n *CommCase) Source(full bool) []byte

Source implements Node.

func (*CommCase) Tokens added in v2.1.0

func (n *CommCase) Tokens() []Token

Tokens returns the tokens n consist of.

type CommClause added in v2.0.2

type CommClause struct {
	CommCase      *CommCase
	Colon         Token
	StatementList []Node
}

CommClause describes an select statement communication clause.

CommClause = CommCase ":" StatementList .

func (*CommClause) Position added in v2.0.2

func (n *CommClause) Position() (r token.Position)

Position implements Node.

func (*CommClause) Source added in v2.0.2

func (n *CommClause) Source(full bool) []byte

Source implements Node.

func (*CommClause) Tokens added in v2.1.0

func (n *CommClause) Tokens() []Token

Tokens returns the tokens n consist of.

type CompositeLit added in v2.0.2

type CompositeLit struct {
	LiteralType  Node
	LiteralValue *LiteralValue
	// contains filtered or unexported fields
}

CompositeLit describes a composite literal.

CompositeLit = LiteralType LiteralValue .

func (*CompositeLit) Position added in v2.0.2

func (n *CompositeLit) Position() (r token.Position)

Position implements Node.

func (*CompositeLit) SetValue added in v2.0.2

func (v *CompositeLit) SetValue(val constant.Value)

SetValue implements Expression

func (*CompositeLit) Source added in v2.0.2

func (n *CompositeLit) Source(full bool) []byte

Source implements Node.

func (*CompositeLit) Tokens added in v2.1.0

func (n *CompositeLit) Tokens() []Token

Tokens returns the tokens n consist of.

func (CompositeLit) Type added in v2.0.2

func (t CompositeLit) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (CompositeLit) Value added in v2.0.2

func (v CompositeLit) Value() constant.Value

Value implements Expression

type ConstDecl added in v2.0.2

type ConstDecl struct {
	Const      Token
	LParen     Token
	ConstSpecs []*ConstSpec
	RParen     Token
	Semicolon  Token
}

ConstDecl describes a constant declaration.

ConstDecl = "const" ( ConstSpec | "(" { ConstSpec ";" } ")" ) .

func (*ConstDecl) Position added in v2.0.2

func (n *ConstDecl) Position() (r token.Position)

Position implements Node.

func (*ConstDecl) Source added in v2.0.2

func (n *ConstDecl) Source(full bool) []byte

Source implements Node.

func (*ConstDecl) Tokens added in v2.1.0

func (n *ConstDecl) Tokens() []Token

Tokens returns the tokens n consist of.

type ConstSpec added in v2.0.2

type ConstSpec struct {
	IdentifierList []*IdentListItem
	Type           Node
	Eq             Token
	ExprList       []*ExprListItem
	Semicolon      Token
	// contains filtered or unexported fields
}

ConstSpec describes a constant specification.

ConstSpec = IdentifierList [ [ Type ] "=" ExpressionList ] .

func (*ConstSpec) Position added in v2.0.2

func (n *ConstSpec) Position() (r token.Position)

Position implements Node.

func (*ConstSpec) Source added in v2.0.2

func (n *ConstSpec) Source(full bool) []byte

Source implements Node.

func (*ConstSpec) Tokens added in v2.1.0

func (n *ConstSpec) Tokens() []Token

Tokens returns the tokens n consist of.

type Constant added in v2.0.2

type Constant struct {
	Expr  Expression
	Ident Token
	// contains filtered or unexported fields
}

Constant represents a Go constant.

func (*Constant) Position added in v2.0.2

func (n *Constant) Position() (r token.Position)

Position implements Node.

func (*Constant) SetValue added in v2.0.2

func (v *Constant) SetValue(val constant.Value)

SetValue implements Expression

func (*Constant) Source added in v2.0.2

func (n *Constant) Source(full bool) []byte

Source implements Node.

func (*Constant) Tokens added in v2.1.0

func (n *Constant) Tokens() []Token

Tokens returns the tokens n consist of.

func (Constant) Type added in v2.0.2

func (t Constant) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (Constant) Value added in v2.0.2

func (v Constant) Value() constant.Value

Value implements Expression

type ContinueStmt added in v2.0.2

type ContinueStmt struct {
	Continue  Token
	Label     Token
	Semicolon Token
}

ContinueStmt describes a continue statement.

ContinueStmt = "continue" [ Label ] .

func (*ContinueStmt) Position added in v2.0.2

func (n *ContinueStmt) Position() (r token.Position)

Position implements Node.

func (*ContinueStmt) Source added in v2.0.2

func (n *ContinueStmt) Source(full bool) []byte

Source implements Node.

func (*ContinueStmt) Tokens added in v2.1.0

func (n *ContinueStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type Conversion added in v2.0.2

type Conversion struct {
	ConvertType Node
	LParen      Token
	Expr        Expression
	Comma       Token
	RParen      Token
	// contains filtered or unexported fields
}

Conversion describes a conversion.

Conversion = Type "(" Expression [ "," ] ")" .

func (*Conversion) Position added in v2.0.2

func (n *Conversion) Position() (r token.Position)

Position implements Node.

func (*Conversion) SetValue added in v2.0.2

func (v *Conversion) SetValue(val constant.Value)

SetValue implements Expression

func (*Conversion) Source added in v2.0.2

func (n *Conversion) Source(full bool) []byte

Source implements Node.

func (*Conversion) Tokens added in v2.1.0

func (n *Conversion) Tokens() []Token

Tokens returns the tokens n consist of.

func (Conversion) Type added in v2.0.2

func (t Conversion) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (Conversion) Value added in v2.0.2

func (v Conversion) Value() constant.Value

Value implements Expression

type DeferStmt added in v2.0.2

type DeferStmt struct {
	Defer     Token
	Expr      Expression
	Semicolon Token
}

DeferStmt describes a defer statement.

DeferStmt = "defer" Expression .

func (*DeferStmt) Position added in v2.0.2

func (n *DeferStmt) Position() (r token.Position)

Position implements Node.

func (*DeferStmt) Source added in v2.0.2

func (n *DeferStmt) Source(full bool) []byte

Source implements Node.

func (*DeferStmt) Tokens added in v2.1.0

func (n *DeferStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type EmbeddedField added in v2.0.2

type EmbeddedField struct {
	Star     Token
	TypeName *TypeNameNode
}

EmbeddedField describes an embeded field.

EmbeddedField = [ "*" ] TypeName .

func (*EmbeddedField) Position added in v2.0.2

func (n *EmbeddedField) Position() (r token.Position)

Position implements Node.

func (*EmbeddedField) Source added in v2.0.2

func (n *EmbeddedField) Source(full bool) []byte

Source implements Node.

func (*EmbeddedField) Tokens added in v2.1.0

func (n *EmbeddedField) Tokens() []Token

Tokens returns the tokens n consist of.

type EmptyStmt added in v2.0.2

type EmptyStmt struct {
	Semicolon Token
}

EmptyStmt describes an empty statement.

EmptyStmt = .

func (*EmptyStmt) Position added in v2.0.2

func (n *EmptyStmt) Position() (r token.Position)

Position implements Node.

func (*EmptyStmt) Source added in v2.0.2

func (n *EmptyStmt) Source(full bool) []byte

Source implements Node.

func (*EmptyStmt) Tokens added in v2.1.0

func (n *EmptyStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type ExprCaseClause added in v2.0.2

type ExprCaseClause struct {
	ExprSwitchCase *ExprSwitchCase
	Colon          Token
	StatementList  []Node
}

ExprCaseClause describes an expression switch case clause.

ExprCaseClause = ExprSwitchCase ":" StatementList .

func (*ExprCaseClause) Position added in v2.0.2

func (n *ExprCaseClause) Position() (r token.Position)

Position implements Node.

func (*ExprCaseClause) Source added in v2.0.2

func (n *ExprCaseClause) Source(full bool) []byte

Source implements Node.

func (*ExprCaseClause) Tokens added in v2.1.0

func (n *ExprCaseClause) Tokens() []Token

Tokens returns the tokens n consist of.

type ExprListItem added in v2.0.2

type ExprListItem struct {
	Expr  Expression
	Comma Token
}

ExprListItem describes an item of an expression list.

ExpressionList = Expression { "," Expression } .

func (*ExprListItem) Position added in v2.0.2

func (n *ExprListItem) Position() (r token.Position)

Position implements Node.

func (*ExprListItem) Source added in v2.0.2

func (n *ExprListItem) Source(full bool) []byte

Source implements Node.

func (*ExprListItem) Tokens added in v2.1.0

func (n *ExprListItem) Tokens() []Token

Tokens returns the tokens n consist of.

type ExprSwitchCase added in v2.0.2

type ExprSwitchCase struct {
	CaseOrDefault Token
	ExprList      []*ExprListItem
}

ExprSwitchCase describes an expression switch case.

ExprSwitchCase = "case" ExpressionList | "default" .

func (*ExprSwitchCase) Position added in v2.0.2

func (n *ExprSwitchCase) Position() (r token.Position)

Position implements Node.

func (*ExprSwitchCase) Source added in v2.0.2

func (n *ExprSwitchCase) Source(full bool) []byte

Source implements Node.

func (*ExprSwitchCase) Tokens added in v2.1.0

func (n *ExprSwitchCase) Tokens() []Token

Tokens returns the tokens n consist of.

type Expression added in v2.0.2

type Expression interface {
	Node
	Type() Type
	Value() constant.Value
	SetValue(constant.Value)
	// contains filtered or unexported methods
}

Expression represents a computation.

type ExpressionStmt added in v2.0.2

type ExpressionStmt struct {
	Expr      Expression
	Semicolon Token
}

ExpressionStmt describes an expression statement.

func (*ExpressionStmt) Position added in v2.0.2

func (n *ExpressionStmt) Position() (r token.Position)

Position implements Node.

func (*ExpressionStmt) Source added in v2.0.2

func (n *ExpressionStmt) Source(full bool) []byte

Source implements Node.

func (*ExpressionStmt) Tokens added in v2.1.0

func (n *ExpressionStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type ExpressionSwitchStmt added in v2.0.2

type ExpressionSwitchStmt struct {
	Switch          Token
	SimpleStmt      Node
	Semicolon       Token
	Expr            Expression
	LBrace          Token
	ExprCaseClauses []*ExprCaseClause
	RBrace          Token
	Semicolon2      Token
	Scope           *Scope // Implicit scope of the switch statement
}

ExpressionSwitchStmt describes an expression switch statement.

ExprSwitchStmt = "switch" [ SimpleStmt ";" ] [ Expression ] "{" { ExprCaseClause } "}" .

func (*ExpressionSwitchStmt) Position added in v2.0.2

func (n *ExpressionSwitchStmt) Position() (r token.Position)

Position implements Node.

func (*ExpressionSwitchStmt) Source added in v2.0.2

func (n *ExpressionSwitchStmt) Source(full bool) []byte

Source implements Node.

func (*ExpressionSwitchStmt) Tokens added in v2.1.0

func (n *ExpressionSwitchStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type FallthroughStmt added in v2.0.2

type FallthroughStmt struct {
	Fallthrough Token
	Semicolon   Token
}

FallthroughStmt describes a fallthrough statement.

FallthroughStmt = "fallthrough" .

func (*FallthroughStmt) Position added in v2.0.2

func (n *FallthroughStmt) Position() (r token.Position)

Position implements Node.

func (*FallthroughStmt) Source added in v2.0.2

func (n *FallthroughStmt) Source(full bool) []byte

Source implements Node.

func (*FallthroughStmt) Tokens added in v2.1.0

func (n *FallthroughStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type Field added in v2.0.2

type Field struct {
	Name string
	// contains filtered or unexported fields
}

Field represents a struct field.

func NewField added in v2.0.2

func NewField(name string, typ Type) *Field

NewField returns a newly created struct field.

func (*Field) Index added in v2.0.2

func (n *Field) Index() int

Index returns n's zero-base index.

func (Field) Type added in v2.0.2

func (t Field) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type FieldDecl added in v2.0.2

type FieldDecl struct {
	IdentifierList []*IdentListItem
	Type           Node
	EmbeddedField  *EmbeddedField
	Tag            Token
	Semicolon      Token
}

FieldDecl describes a field declaration.

FieldDecl = (IdentifierList Type | EmbeddedField) [ Tag ] .

func (*FieldDecl) Position added in v2.0.2

func (n *FieldDecl) Position() (r token.Position)

Position implements Node.

func (*FieldDecl) Source added in v2.0.2

func (n *FieldDecl) Source(full bool) []byte

Source implements Node.

func (*FieldDecl) Tokens added in v2.1.0

func (n *FieldDecl) Tokens() []Token

Tokens returns the tokens n consist of.

type ForClause added in v2.0.2

type ForClause struct {
	InitStmt   Node
	Semicolon  Token
	Condition  Expression
	Semicolon2 Token
	PostStmt   Node
}

ForClause describes a for clause.

ForClause = [ InitStmt ] ";" [ Condition ] ";" [ PostStmt ] .

func (*ForClause) Position added in v2.0.2

func (n *ForClause) Position() (r token.Position)

Position implements Node.

func (*ForClause) Source added in v2.0.2

func (n *ForClause) Source(full bool) []byte

Source implements Node.

func (*ForClause) Tokens added in v2.1.0

func (n *ForClause) Tokens() []Token

Tokens returns the tokens n consist of.

type ForStmt added in v2.0.2

type ForStmt struct {
	For         Token
	ForClause   *ForClause
	RangeClause *RangeClause
	Block       *Block
	Semicolon   Token
	Scope       *Scope // Implicit scope of the for statement
}

ForStmt describes a for statement.

ForStmt = "for" [ Condition | ForClause | RangeClause ] Block .

func (*ForStmt) Position added in v2.0.2

func (n *ForStmt) Position() (r token.Position)

Position implements Node.

func (*ForStmt) Source added in v2.0.2

func (n *ForStmt) Source(full bool) []byte

Source implements Node.

func (*ForStmt) Tokens added in v2.1.0

func (n *ForStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type FunctionDecl added in v2.0.2

type FunctionDecl struct {
	Func           Token
	FunctionName   Token
	TypeParameters *TypeParameters
	Signature      *Signature
	FunctionBody   *Block
	Semicolon      Token
	// contains filtered or unexported fields
}

FunctionDecl describes a function declaration.

FunctionDecl = "func" FunctionName [ TypeParameters ] Signature [ FunctionBody ] .

func (*FunctionDecl) Position added in v2.0.2

func (n *FunctionDecl) Position() (r token.Position)

Position implements Node.

func (*FunctionDecl) Source added in v2.0.2

func (n *FunctionDecl) Source(full bool) []byte

Source implements Node.

func (*FunctionDecl) Tokens added in v2.1.0

func (n *FunctionDecl) Tokens() []Token

Tokens returns the tokens n consist of.

func (FunctionDecl) Type added in v2.0.2

func (t FunctionDecl) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type FunctionLit added in v2.0.2

type FunctionLit struct {
	Func         Token
	Signature    *Signature
	FunctionBody *Block
	// contains filtered or unexported fields
}

FunctionLit describes a function literal.

FunctionLit = "func" Signature FunctionBody .

func (*FunctionLit) Position added in v2.0.2

func (n *FunctionLit) Position() (r token.Position)

Position implements Node.

func (*FunctionLit) SetValue added in v2.0.2

func (v *FunctionLit) SetValue(val constant.Value)

SetValue implements Expression

func (*FunctionLit) Source added in v2.0.2

func (n *FunctionLit) Source(full bool) []byte

Source implements Node.

func (*FunctionLit) Tokens added in v2.1.0

func (n *FunctionLit) Tokens() []Token

Tokens returns the tokens n consist of.

func (FunctionLit) Type added in v2.0.2

func (t FunctionLit) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (FunctionLit) Value added in v2.0.2

func (v FunctionLit) Value() constant.Value

Value implements Expression

type FunctionType added in v2.0.2

type FunctionType struct {
	Parameters *TupleType
	Result     *TupleType

	IsVariadic bool
	// contains filtered or unexported fields
}

FunctionType represents a channel type.

func (*FunctionType) Kind added in v2.0.2

func (t *FunctionType) Kind() Kind

Kind implements Type.

func (*FunctionType) Position added in v2.0.2

func (t *FunctionType) Position() (r token.Position)

Position implements Node.

func (FunctionType) Source added in v2.0.2

func (FunctionType) Source(bool) []byte

Source implements Node. It returns nil.

func (*FunctionType) String added in v2.0.2

func (t *FunctionType) String() string

func (FunctionType) Tokens added in v2.1.0

func (FunctionType) Tokens() []Token

Tokens implements Node. It returns nil.

type FunctionTypeNode added in v2.0.2

type FunctionTypeNode struct {
	Func      Token
	Signature *Signature
	// contains filtered or unexported fields
}

FunctionTypeNode describes a function type.

FunctionTypeNode = "func" Signature .

func (*FunctionTypeNode) Position added in v2.0.2

func (n *FunctionTypeNode) Position() (r token.Position)

Position implements Node.

func (*FunctionTypeNode) Source added in v2.0.2

func (n *FunctionTypeNode) Source(full bool) []byte

Source implements Node.

func (*FunctionTypeNode) Tokens added in v2.1.0

func (n *FunctionTypeNode) Tokens() []Token

Tokens returns the tokens n consist of.

func (FunctionTypeNode) Type added in v2.0.2

func (t FunctionTypeNode) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type GenericOperand added in v2.0.2

type GenericOperand struct {
	OperandName Node
	TypeArgs    *TypeArgs
	// contains filtered or unexported fields
}

GenericOperand describes an operand name and type arguments.

GenericOperand = OperandName TypeArgs .

func (*GenericOperand) Position added in v2.0.2

func (n *GenericOperand) Position() (r token.Position)

Position implements Node.

func (*GenericOperand) SetValue added in v2.0.2

func (v *GenericOperand) SetValue(val constant.Value)

SetValue implements Expression

func (*GenericOperand) Source added in v2.0.2

func (n *GenericOperand) Source(full bool) []byte

Source implements Node.

func (*GenericOperand) Tokens added in v2.1.0

func (n *GenericOperand) Tokens() []Token

Tokens returns the tokens n consist of.

func (GenericOperand) Type added in v2.0.2

func (t GenericOperand) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (GenericOperand) Value added in v2.0.2

func (v GenericOperand) Value() constant.Value

Value implements Expression

type GoStmt added in v2.0.2

type GoStmt struct {
	Go        Token
	Expr      Expression
	Semicolon Token
}

GoStmt describes a go statement.

GoStmt = "go" Expression .

func (*GoStmt) Position added in v2.0.2

func (n *GoStmt) Position() (r token.Position)

Position implements Node.

func (*GoStmt) Source added in v2.0.2

func (n *GoStmt) Source(full bool) []byte

Source implements Node.

func (*GoStmt) Tokens added in v2.1.0

func (n *GoStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type GotoStmt added in v2.0.2

type GotoStmt struct {
	Goto      Token
	Label     Token
	Semicolon Token
}

GotoStmt describes a goto statement.

GotoStmt = "goto" Label .

func (*GotoStmt) Position added in v2.0.2

func (n *GotoStmt) Position() (r token.Position)

Position implements Node.

func (*GotoStmt) Source added in v2.0.2

func (n *GotoStmt) Source(full bool) []byte

Source implements Node.

func (*GotoStmt) Tokens added in v2.1.0

func (n *GotoStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type Ident added in v2.0.2

type Ident struct {
	Token Token
	// contains filtered or unexported fields
}

Ident represents an unqualified operand/type name.

func (Ident) LexicalScope added in v2.0.2

func (n Ident) LexicalScope() *Scope

LexicalScope returns the lexical scope n appears in.

func (*Ident) Position added in v2.0.2

func (n *Ident) Position() (r token.Position)

Position implements Node.

func (*Ident) ResolvedTo added in v2.0.2

func (n *Ident) ResolvedTo() Node

ResolvedTo returns the node n refers to. Valid after type checking.

func (*Ident) SetValue added in v2.0.2

func (v *Ident) SetValue(val constant.Value)

SetValue implements Expression

func (*Ident) Source added in v2.0.2

func (n *Ident) Source(full bool) []byte

Source implements Node.

func (*Ident) Tokens added in v2.1.0

func (n *Ident) Tokens() []Token

Tokens returns the tokens n consist of.

func (Ident) Type added in v2.0.2

func (t Ident) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (Ident) Value added in v2.0.2

func (v Ident) Value() constant.Value

Value implements Expression

type IdentListItem added in v2.0.2

type IdentListItem struct {
	Ident Token
	Comma Token
}

IdentListItem describes an item of an identifier list.

func (*IdentListItem) Position added in v2.0.2

func (n *IdentListItem) Position() (r token.Position)

Position implements Node.

func (*IdentListItem) Source added in v2.0.2

func (n *IdentListItem) Source(full bool) []byte

Source implements Node.

func (*IdentListItem) Tokens added in v2.1.0

func (n *IdentListItem) Tokens() []Token

Tokens returns the tokens n consist of.

type IfStmt added in v2.0.2

type IfStmt struct {
	If         Token
	SimpleStmt Node
	Semicolon  Token
	Expr       Expression
	Block      *Block
	Else       Token
	ElsePart   Node
	Semicolon2 Token
	Scope      *Scope // Implicit scope of the if statement
}

IfStmt describes an if statement.

IfStmt = "if" [ SimpleStmt ";" ] Expression Block [ "else" ( IfStmt | Block ) ] .

func (*IfStmt) Position added in v2.0.2

func (n *IfStmt) Position() (r token.Position)

Position implements Node.

func (*IfStmt) Source added in v2.0.2

func (n *IfStmt) Source(full bool) []byte

Source implements Node.

func (*IfStmt) Tokens added in v2.1.0

func (n *IfStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type ImportDecl added in v2.0.1

type ImportDecl struct {
	Import      Token
	LParen      Token
	ImportSpecs []*ImportSpec
	RParen      Token
	Semicolon   Token
}

ImportDecl describes an import declaration.

ImportDecl = "import" ( ImportSpec | "(" { ImportSpec ";" } ")" ) .

func (*ImportDecl) Position added in v2.0.1

func (n *ImportDecl) Position() (r token.Position)

Position implements Node.

func (*ImportDecl) Source added in v2.0.2

func (n *ImportDecl) Source(full bool) []byte

Source implements Node.

func (*ImportDecl) Tokens added in v2.1.0

func (n *ImportDecl) Tokens() []Token

Tokens returns the tokens n consist of.

type ImportSpec added in v2.0.2

type ImportSpec struct {
	Qualifier  Token
	ImportPath Token
	Semicolon  Token
}

ImportSpec describes an import specification.

ImportSpec = [ "." | PackageName ] ImportPath .

func (*ImportSpec) Position added in v2.0.2

func (n *ImportSpec) Position() (r token.Position)

Position implements Node.

func (*ImportSpec) Source added in v2.0.2

func (n *ImportSpec) Source(full bool) []byte

Source implements Node.

func (*ImportSpec) Tokens added in v2.1.0

func (n *ImportSpec) Tokens() []Token

Tokens returns the tokens n consist of.

type IncDecStmt added in v2.0.2

type IncDecStmt struct {
	Expr      Expression
	Op        Token
	Semicolon Token
	// contains filtered or unexported fields
}

IncDecStmt describes an increment or decrement statemen.

IncDecStmt = Expression ( "++" | "--" ) .

func (*IncDecStmt) Position added in v2.0.2

func (n *IncDecStmt) Position() (r token.Position)

Position implements Node.

func (*IncDecStmt) Source added in v2.0.2

func (n *IncDecStmt) Source(full bool) []byte

Source implements Node.

func (*IncDecStmt) Tokens added in v2.1.0

func (n *IncDecStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type Index added in v2.0.2

type Index struct {
	PrimaryExpr Expression
	LBracket    Token
	Expr        Expression
	RBracket    Token
	// contains filtered or unexported fields
}

Index describes an index.

Index = "[" Expression "]" .

func (*Index) Position added in v2.0.2

func (n *Index) Position() (r token.Position)

Position implements Node.

func (*Index) SetValue added in v2.0.2

func (v *Index) SetValue(val constant.Value)

SetValue implements Expression

func (*Index) Source added in v2.0.2

func (n *Index) Source(full bool) []byte

Source implements Node.

func (*Index) Tokens added in v2.1.0

func (n *Index) Tokens() []Token

Tokens returns the tokens n consist of.

func (Index) Type added in v2.0.2

func (t Index) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (Index) Value added in v2.0.2

func (v Index) Value() constant.Value

Value implements Expression

type InterfaceType added in v2.0.2

type InterfaceType struct {
	Elems []Node //TODO
	// contains filtered or unexported fields
}

InterfaceType represents an interface type.

func (*InterfaceType) Kind added in v2.0.2

func (t *InterfaceType) Kind() Kind

Kind implements Type.

func (*InterfaceType) Position added in v2.0.2

func (t *InterfaceType) Position() (r token.Position)

Position implements Node.

func (InterfaceType) Source added in v2.0.2

func (InterfaceType) Source(bool) []byte

Source implements Node. It returns nil.

func (*InterfaceType) String added in v2.0.2

func (t *InterfaceType) String() string

func (InterfaceType) Tokens added in v2.1.0

func (InterfaceType) Tokens() []Token

Tokens implements Node. It returns nil.

type InterfaceTypeNode added in v2.0.2

type InterfaceTypeNode struct {
	Interface      Token
	LBrace         Token
	InterfaceElems []Node
	RBrace         Token
	// contains filtered or unexported fields
}

InterfaceTypeNode describes an interface type.

InterfaceTypeNode = "interface" "{" { InterfaceElem ";" } "}" .

func (*InterfaceTypeNode) Position added in v2.0.2

func (n *InterfaceTypeNode) Position() (r token.Position)

Position implements Node.

func (*InterfaceTypeNode) Source added in v2.0.2

func (n *InterfaceTypeNode) Source(full bool) []byte

Source implements Node.

func (*InterfaceTypeNode) Tokens added in v2.1.0

func (n *InterfaceTypeNode) Tokens() []Token

Tokens returns the tokens n consist of.

func (InterfaceTypeNode) Type added in v2.0.2

func (t InterfaceTypeNode) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type InvalidType added in v2.0.2

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

InvalidType represents an invalid type.

func (*InvalidType) Kind added in v2.0.2

func (t *InvalidType) Kind() Kind

Kind implements Type.

func (*InvalidType) Position added in v2.0.2

func (t *InvalidType) Position() (r token.Position)

Position implements Node. Position returns a zero value.

func (InvalidType) Source added in v2.0.2

func (InvalidType) Source(bool) []byte

Source implements Node. It returns nil.

func (*InvalidType) String added in v2.0.2

func (t *InvalidType) String() string

func (InvalidType) Tokens added in v2.1.0

func (InvalidType) Tokens() []Token

Tokens implements Node. It returns nil.

type KeyedElement added in v2.0.2

type KeyedElement struct {
	Key     Node
	Colon   Token
	Element Node
	Comma   Token
	// contains filtered or unexported fields
}

KeyedElement describes an optionally keyed element.

KeyedElement = [ Key ":" ] Element .

func (*KeyedElement) Position added in v2.0.2

func (n *KeyedElement) Position() (r token.Position)

Position implements Node.

func (*KeyedElement) Source added in v2.0.2

func (n *KeyedElement) Source(full bool) []byte

Source implements Node.

func (*KeyedElement) Tokens added in v2.1.0

func (n *KeyedElement) Tokens() []Token

Tokens returns the tokens n consist of.

func (KeyedElement) Type added in v2.0.2

func (t KeyedElement) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type Kind added in v2.0.2

type Kind int

A Kind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.

const (
	InvalidKind Kind = iota // <invalid type>

	Array          // array
	Bool           // bool
	Chan           // chan
	Complex128     // complex128
	Complex64      // complex64
	Defined        // typename
	Float32        // float32
	Float64        // float64
	Function       // function
	Int            // int
	Int16          // int16
	Int32          // int32
	Int64          // int64
	Int8           // int8
	Interface      // interface
	Map            // map
	Pointer        // pointer
	Slice          // slice
	String         // string
	Struct         // struct
	Tuple          // tuple
	Uint           // uint
	Uint16         // uint16
	Uint32         // uint32
	Uint64         // uint64
	Uint8          // uint8
	Uintptr        // uintptr
	UnsafePointer  // unsafe.Pointer
	UntypedBool    // untyped bool
	UntypedComplex // untyped complex
	UntypedFloat   // untyped float
	UntypedInt     // untyped int
	UntypedNil     // untyped nil
	UntypedString  // untyped string
)

Values of type Kind

func (Kind) String added in v2.0.2

func (i Kind) String() string

type LabeledStmt added in v2.0.2

type LabeledStmt struct {
	Label     Token
	Colon     Token
	Statement Node
}

LabeledStmt describes a labeled statement.

LabeledStmt = Label ":" Statement .

func (*LabeledStmt) Position added in v2.0.2

func (n *LabeledStmt) Position() (r token.Position)

Position implements Node.

func (*LabeledStmt) Source added in v2.0.2

func (n *LabeledStmt) Source(full bool) []byte

Source implements Node.

func (*LabeledStmt) Tokens added in v2.1.0

func (n *LabeledStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type LiteralValue added in v2.0.2

type LiteralValue struct {
	LBrace      Token
	ElementList []*KeyedElement
	RBrace      Token
}

LiteralValue describes a composite literal value.

LiteralValue = "{" [ ElementList [ "," ] ] "}" .

func (*LiteralValue) Position added in v2.0.2

func (n *LiteralValue) Position() (r token.Position)

Position implements Node.

func (*LiteralValue) Source added in v2.0.2

func (n *LiteralValue) Source(full bool) []byte

Source implements Node.

func (*LiteralValue) Tokens added in v2.1.0

func (n *LiteralValue) Tokens() []Token

Tokens returns the tokens n consist of.

type MapType added in v2.0.2

type MapType struct {
	Elem Type
	Key  Type
	// contains filtered or unexported fields
}

MapType represents a map type.

func (*MapType) Kind added in v2.0.2

func (t *MapType) Kind() Kind

Kind implements Type.

func (*MapType) Position added in v2.0.2

func (t *MapType) Position() (r token.Position)

Position implements Node.

func (MapType) Source added in v2.0.2

func (MapType) Source(bool) []byte

Source implements Node. It returns nil.

func (*MapType) String added in v2.0.2

func (t *MapType) String() string

func (MapType) Tokens added in v2.1.0

func (MapType) Tokens() []Token

Tokens implements Node. It returns nil.

type MapTypeNode added in v2.0.2

type MapTypeNode struct {
	Map         Token
	LBracket    Token
	KeyType     Node
	RBracket    Token
	ElementType Node
	// contains filtered or unexported fields
}

MapTypeNode describes a map type.

MapTypeNode = "map" "[" KeyType "]" ElementType .

func (*MapTypeNode) Position added in v2.0.2

func (n *MapTypeNode) Position() (r token.Position)

Position implements Node.

func (*MapTypeNode) Source added in v2.0.2

func (n *MapTypeNode) Source(full bool) []byte

Source implements Node.

func (*MapTypeNode) Tokens added in v2.1.0

func (n *MapTypeNode) Tokens() []Token

Tokens returns the tokens n consist of.

type MethodDecl added in v2.0.2

type MethodDecl struct {
	Func         Token
	Receiver     *Parameters
	MethodName   Token
	Signature    *Signature
	FunctionBody *Block
	Semicolon    Token
	// contains filtered or unexported fields
}

MethodDecl describes a method declaration.

MethodDecl = "func" Receiver MethodName Signature [ FunctionBody ] .

func (*MethodDecl) Position added in v2.0.2

func (n *MethodDecl) Position() (r token.Position)

Position implements Node.

func (*MethodDecl) Source added in v2.0.2

func (n *MethodDecl) Source(full bool) []byte

Source implements Node.

func (*MethodDecl) Tokens added in v2.1.0

func (n *MethodDecl) Tokens() []Token

Tokens returns the tokens n consist of.

func (MethodDecl) Type added in v2.0.2

func (t MethodDecl) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type MethodElem added in v2.0.2

type MethodElem struct {
	MethodName Token
	Signature  *Signature
	Semicolon  Token
}

MethodElem describes a method element.

MethodElem = MethodName Signature .

func (*MethodElem) Position added in v2.0.2

func (n *MethodElem) Position() (r token.Position)

Position implements Node.

func (*MethodElem) Source added in v2.0.2

func (n *MethodElem) Source(full bool) []byte

Source implements Node.

func (*MethodElem) Tokens added in v2.1.0

func (n *MethodElem) Tokens() []Token

Tokens returns the tokens n consist of.

type MethodExpr added in v2.0.2

type MethodExpr struct {
	Receiver Node
	Dot      Token
	Ident    Token
	// contains filtered or unexported fields
}

MethodExpr describes a method expression.

MethodExpr    = ReceiverType "." MethodName .

func (*MethodExpr) Position added in v2.0.2

func (n *MethodExpr) Position() (r token.Position)

Position implements Node.

func (*MethodExpr) SetValue added in v2.0.2

func (v *MethodExpr) SetValue(val constant.Value)

SetValue implements Expression

func (*MethodExpr) Source added in v2.0.2

func (n *MethodExpr) Source(full bool) []byte

Source implements Node.

func (*MethodExpr) Tokens added in v2.1.0

func (n *MethodExpr) Tokens() []Token

Tokens returns the tokens n consist of.

func (MethodExpr) Type added in v2.0.2

func (t MethodExpr) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (MethodExpr) Value added in v2.0.2

func (v MethodExpr) Value() constant.Value

Value implements Expression

type Node

type Node interface {
	Position() token.Position
	// Source returns the source form of n. Setting full to false will replace
	// every non-empty token separator by a single space character and drop the
	// first token separator entirely, if any.
	Source(full bool) []byte
	// Tokens returns the tokens a node consists of.
	Tokens() []Token
}

Node is an item of the CST tree.

type Package added in v2.0.2

type Package struct {
	ImportPath  string
	Inits       []*FunctionDecl
	Blanks      []Node
	Name        string
	Scope       *Scope
	SourceFiles []*SourceFile
	// contains filtered or unexported fields
}

Package collects source files.

func NewPackage added in v2.0.2

func NewPackage(importPath string, files []*SourceFile) (r *Package, err error)

NewPackage returns a newly created Package or an error, if any.

func (*Package) Check added in v2.0.2

func (n *Package) Check(checker PackageChecker) error

Check type checks n.

func (*Package) Position added in v2.0.2

func (n *Package) Position() (r token.Position)

Position implements Node. Position return a zero value.

func (*Package) Source added in v2.0.2

func (n *Package) Source(full bool) []byte

Source implements Node. Source returns a zero value.

func (*Package) Tokens added in v2.1.0

func (n *Package) Tokens() []Token

Tokens returns the tokens n consist of. Tokens returns nil.

type PackageChecker added in v2.0.2

type PackageChecker interface {
	// PackageLoader returns a package by its import path or an error, if any. The
	// type checker never calls PackageLoader for  certain packages.
	PackageLoader(pkg *Package, src *SourceFile, importPath string) (*Package, error)
	// SymbolResolver returns the node bound to 'ident' within package 'pkg', using
	// currentScope and fileScope or an error, if any. The type checker never calls
	// SymbolResolver for certain identifiers of some packages.
	SymbolResolver(currentScope, fileScope *Scope, pkg *Package, ident Token) (Node, error)
	// CheckFunctions reports whether Check should type check function/method
	// bodies.
	CheckFunctions() bool
	// GOARCH reports the target architecture, it returns the same values as runtime.GOARCH.
	GOARCH() string
}

PackageChecker provides the resolution API for (*Package).Check.

type PackageClause added in v2.0.1

type PackageClause struct {
	Package     Token
	PackageName Token
	Semicolon   Token
}

PackageClause describes the package clause.

PackageClause = "package" PackageName .

func (*PackageClause) Position added in v2.0.1

func (n *PackageClause) Position() (r token.Position)

Position implements Node.

func (*PackageClause) Source added in v2.0.2

func (n *PackageClause) Source(full bool) []byte

Source implements Node.

func (*PackageClause) Tokens added in v2.1.0

func (n *PackageClause) Tokens() []Token

Tokens returns the tokens n consist of.

type Parameter added in v2.0.2

type Parameter struct {
	Name string
	// contains filtered or unexported fields
}

Parameter represents a function input/output paramater.

func (Parameter) Type added in v2.0.2

func (t Parameter) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type ParameterDecl added in v2.0.2

type ParameterDecl struct {
	IdentifierList []*IdentListItem
	Ellipsis       Token
	Type           Node
	Comma          Token
}

ParameterDecl describes a parameter declaration.

ParameterDecl = [ IdentifierList ] [ "..." ] Type .

func (*ParameterDecl) Position added in v2.0.2

func (n *ParameterDecl) Position() (r token.Position)

Position implements Node.

func (*ParameterDecl) Source added in v2.0.2

func (n *ParameterDecl) Source(full bool) []byte

Source implements Node.

func (*ParameterDecl) Tokens added in v2.1.0

func (n *ParameterDecl) Tokens() []Token

Tokens returns the tokens n consist of.

type Parameters added in v2.0.2

type Parameters struct {
	LParen        Token
	ParameterList []*ParameterDecl
	Comma         Token
	RParen        Token
}

Parameters describes function parameters or a function result.

Parameters = "(" [ ParameterList [ "," ] ] ")" .
ParameterList = ParameterDecl { "," ParameterDecl } .

func (*Parameters) Position added in v2.0.2

func (n *Parameters) Position() (r token.Position)

Position implements Node.

func (*Parameters) Source added in v2.0.2

func (n *Parameters) Source(full bool) []byte

Source implements Node.

func (*Parameters) Tokens added in v2.1.0

func (n *Parameters) Tokens() []Token

Tokens returns the tokens n consist of.

type ParenExpr added in v2.0.2

type ParenExpr struct {
	LParen Token
	Expr   Expression
	RParen Token
	// contains filtered or unexported fields
}

ParenExpr describes a parenthesized expression.

ParenExpr = "(" Expression ")" .

func (*ParenExpr) Position added in v2.0.2

func (n *ParenExpr) Position() (r token.Position)

Position implements Node.

func (*ParenExpr) SetValue added in v2.0.2

func (v *ParenExpr) SetValue(val constant.Value)

SetValue implements Expression

func (*ParenExpr) Source added in v2.0.2

func (n *ParenExpr) Source(full bool) []byte

Source implements Node.

func (*ParenExpr) Tokens added in v2.1.0

func (n *ParenExpr) Tokens() []Token

Tokens returns the tokens n consist of.

func (ParenExpr) Type added in v2.0.2

func (t ParenExpr) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (ParenExpr) Value added in v2.0.2

func (v ParenExpr) Value() constant.Value

Value implements Expression

type ParenType added in v2.0.2

type ParenType struct {
	LParen   Token
	TypeNode Node
	RParen   Token
	// contains filtered or unexported fields
}

ParenType describes a parenthesized type.

ParenType = "(" Type ")" .

func (*ParenType) Position added in v2.0.2

func (n *ParenType) Position() (r token.Position)

Position implements Node.

func (*ParenType) Source added in v2.0.2

func (n *ParenType) Source(full bool) []byte

Source implements Node.

func (*ParenType) Tokens added in v2.1.0

func (n *ParenType) Tokens() []Token

Tokens returns the tokens n consist of.

func (ParenType) Type added in v2.0.2

func (t ParenType) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type ParseSourceFileConfig added in v2.0.1

type ParseSourceFileConfig struct {
	// Accept, if non nil, is called once the package clause and imports are
	// parsed. If Accept return a non-nil error the parsing stops and the error is
	// returned.  Passing nil Accept is the same as passing a function that always
	// returns nil
	Accept func(*SourceFile) error

	AllErrors bool
	// contains filtered or unexported fields
}

ParseSourceFileConfig configures ParseSourceFile.

type PointerType added in v2.0.2

type PointerType struct {
	Elem Type
	// contains filtered or unexported fields
}

PointerType represents a pointer type.

func (*PointerType) Kind added in v2.0.2

func (t *PointerType) Kind() Kind

Kind implements Type.

func (*PointerType) Position added in v2.0.2

func (t *PointerType) Position() (r token.Position)

Position implements Node.

func (PointerType) Source added in v2.0.2

func (PointerType) Source(bool) []byte

Source implements Node. It returns nil.

func (*PointerType) String added in v2.0.2

func (t *PointerType) String() string

func (PointerType) Tokens added in v2.1.0

func (PointerType) Tokens() []Token

Tokens implements Node. It returns nil.

type PointerTypeNode added in v2.0.2

type PointerTypeNode struct {
	Star     Token
	BaseType Node
	// contains filtered or unexported fields
}

PointerTypeNode describes a pointer type.

PointerTypeNode = "*" BaseType .

func (*PointerTypeNode) Position added in v2.0.2

func (n *PointerTypeNode) Position() (r token.Position)

Position implements Node.

func (*PointerTypeNode) Source added in v2.0.2

func (n *PointerTypeNode) Source(full bool) []byte

Source implements Node.

func (*PointerTypeNode) Tokens added in v2.1.0

func (n *PointerTypeNode) Tokens() []Token

Tokens returns the tokens n consist of.

func (PointerTypeNode) Type added in v2.0.2

func (t PointerTypeNode) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type PredefinedType added in v2.0.2

type PredefinedType Kind

PredefinedType represents a predefined type.

func (PredefinedType) Kind added in v2.0.2

func (t PredefinedType) Kind() Kind

Kind implements Type.

func (PredefinedType) Position added in v2.0.2

func (t PredefinedType) Position() (r token.Position)

Position implements Node. Position returns a zero value.

func (PredefinedType) Source added in v2.0.2

func (t PredefinedType) Source(full bool) []byte

Source implements Node. It returns nil.

func (PredefinedType) String added in v2.0.2

func (t PredefinedType) String() string

func (PredefinedType) Tokens added in v2.1.0

func (t PredefinedType) Tokens() []Token

Tokens implements Node. It returns nil.

type QualifiedIdent added in v2.0.2

type QualifiedIdent struct {
	PackageName Token
	Dot         Token
	Ident       Token
	// contains filtered or unexported fields
}

QualifiedIdent describes an optionally qualified identifier.

QualifiedIdent = PackageName "." identifier .

func (QualifiedIdent) LexicalScope added in v2.0.2

func (n QualifiedIdent) LexicalScope() *Scope

LexicalScope returns the lexical scope n appears in.

func (*QualifiedIdent) Position added in v2.0.2

func (n *QualifiedIdent) Position() (r token.Position)

Position implements Node.

func (*QualifiedIdent) ResolvedIn added in v2.0.2

func (n *QualifiedIdent) ResolvedIn() *Package

ResolvedIn returns the package n refers to. Valid after type checking.

func (*QualifiedIdent) ResolvedTo added in v2.0.2

func (n *QualifiedIdent) ResolvedTo() Node

ResolvedTo returns the node n refers to. Valid after type checking.

func (*QualifiedIdent) SetValue added in v2.0.2

func (v *QualifiedIdent) SetValue(val constant.Value)

SetValue implements Expression

func (*QualifiedIdent) Source added in v2.0.2

func (n *QualifiedIdent) Source(full bool) []byte

Source implements Node.

func (*QualifiedIdent) Tokens added in v2.1.0

func (n *QualifiedIdent) Tokens() []Token

Tokens returns the tokens n consist of.

func (QualifiedIdent) Type added in v2.0.2

func (t QualifiedIdent) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (QualifiedIdent) Value added in v2.0.2

func (v QualifiedIdent) Value() constant.Value

Value implements Expression

type RangeClause added in v2.0.2

type RangeClause struct {
	ExprList []*ExprListItem
	Assign   Token
	Range    Token
	Expr     Expression
}

RangeClause describes a range clause.

RangeClause = [ ExpressionList "=" | IdentifierList ":=" ] "range" Expression .

func (*RangeClause) Position added in v2.0.2

func (n *RangeClause) Position() (r token.Position)

Position implements Node.

func (*RangeClause) Source added in v2.0.2

func (n *RangeClause) Source(full bool) []byte

Source implements Node.

func (*RangeClause) Tokens added in v2.1.0

func (n *RangeClause) Tokens() []Token

Tokens returns the tokens n consist of.

type ReturnStmt added in v2.0.2

type ReturnStmt struct {
	Return    Token
	ExprList  []*ExprListItem
	Semicolon Token
	// contains filtered or unexported fields
}

ReturnStmt describes a return statement.

ReturnStmt = "return" [ ExpressionList ] .

func (*ReturnStmt) Position added in v2.0.2

func (n *ReturnStmt) Position() (r token.Position)

Position implements Node.

func (*ReturnStmt) Source added in v2.0.2

func (n *ReturnStmt) Source(full bool) []byte

Source implements Node.

func (*ReturnStmt) Tokens added in v2.1.0

func (n *ReturnStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type Scanner

type Scanner struct {

	// Tok is the current token. It is valid after first call to Scan. The value is
	// read only.
	Tok Token

	// CommentHandler, if not nil, is invoked on line and general comments, passing
	// the offset and content of the comment. The content must not be modified.
	CommentHandler func(off int32, s []byte)
	// contains filtered or unexported fields
}

Scanner provides lexical analysis of its buffer.

func NewScanner

func NewScanner(name string, buf []byte) (*Scanner, error)

NewScanner returns a newly created scanner that will tokenize buf. Positions are reported as if buf is coming from a file named name. The buffer becomes owned by the scanner and must not be modified after calling NewScanner.

func (*Scanner) Err

func (s *Scanner) Err() error

Err reports any errors the scanner encountered during .Scan() invocations. For typical use please see the .Scan() documentation.

func (*Scanner) Scan

func (s *Scanner) Scan() (r bool)

Scan moves to the next token and returns true if not at end of file. Usage example:

s, _ = NewScanner(buf, name, false)
for s.Scan() {
	...
}
if err := s.Err() {
	...
}

type Scope added in v2.0.2

type Scope struct {
	Nodes  map[string]Scoped
	Parent *Scope
}

Scope binds names to nodes.

func (*Scope) IsPackage added in v2.0.2

func (s *Scope) IsPackage() bool

IsPackage reports whether s is a package scope.

type Scoped added in v2.0.2

type Scoped struct {
	Node        Node
	VisibleFrom int
}

Scoped represents a node bound to a name and the offset where the visibility starts. Declarations outside of a function/method reports their visibility starts at zero.

type SelectStmt added in v2.0.2

type SelectStmt struct {
	Select      Token
	LBrace      Token
	CommClauses []*CommClause
	RBrace      Token
	Semicolon   Token
}

SelectStmt describes a select statement.

SelectStmt = "select" "{" { CommClause } "}" .

func (*SelectStmt) Position added in v2.0.2

func (n *SelectStmt) Position() (r token.Position)

Position implements Node.

func (*SelectStmt) Source added in v2.0.2

func (n *SelectStmt) Source(full bool) []byte

Source implements Node.

func (*SelectStmt) Tokens added in v2.1.0

func (n *SelectStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type Selector added in v2.0.2

type Selector struct {
	PrimaryExpr Expression
	Dot         Token
	Ident       Token
	// contains filtered or unexported fields
}

Selector describes a selector.

Selector = PrimaryExpr "." identifier .

func (*Selector) Position added in v2.0.2

func (n *Selector) Position() (r token.Position)

Position implements Node.

func (*Selector) SetValue added in v2.0.2

func (v *Selector) SetValue(val constant.Value)

SetValue implements Expression

func (*Selector) Source added in v2.0.2

func (n *Selector) Source(full bool) []byte

Source implements Node.

func (*Selector) Tokens added in v2.1.0

func (n *Selector) Tokens() []Token

Tokens returns the tokens n consist of.

func (Selector) Type added in v2.0.2

func (t Selector) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (Selector) Value added in v2.0.2

func (v Selector) Value() constant.Value

Value implements Expression

type SendStmt added in v2.0.2

type SendStmt struct {
	Channel   Node
	Arrow     Token
	Expr      Expression
	Semicolon Token
	// contains filtered or unexported fields
}

SendStmt describes a send statement.

SendStmt = Channel "<-" Expression .

func (*SendStmt) Position added in v2.0.2

func (n *SendStmt) Position() (r token.Position)

Position implements Node.

func (*SendStmt) Source added in v2.0.2

func (n *SendStmt) Source(full bool) []byte

Source implements Node.

func (*SendStmt) Tokens added in v2.1.0

func (n *SendStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type ShortVarDecl added in v2.0.2

type ShortVarDecl struct {
	IdentifierList []*IdentListItem
	Define         Token
	ExprList       []*ExprListItem
	Semicolon      Token
	// contains filtered or unexported fields
}

ShortVarDecl describes a short variable declaration.

ShortVarDecl = IdentifierList ":=" ExpressionList .

func (ShortVarDecl) LexicalScope added in v2.0.2

func (n ShortVarDecl) LexicalScope() *Scope

LexicalScope returns the lexical scope n appears in.

func (*ShortVarDecl) Position added in v2.0.2

func (n *ShortVarDecl) Position() (r token.Position)

Position implements Node.

func (*ShortVarDecl) Source added in v2.0.2

func (n *ShortVarDecl) Source(full bool) []byte

Source implements Node.

func (*ShortVarDecl) Tokens added in v2.1.0

func (n *ShortVarDecl) Tokens() []Token

Tokens returns the tokens n consist of.

type Signature added in v2.0.2

type Signature struct {
	Parameters *Parameters
	Result     Node
	// contains filtered or unexported fields
}

Signature describes a function signature.

Signature = Parameters [ Result ] .

func (*Signature) Position added in v2.0.2

func (n *Signature) Position() (r token.Position)

Position implements Node.

func (*Signature) Source added in v2.0.2

func (n *Signature) Source(full bool) []byte

Source implements Node.

func (*Signature) Tokens added in v2.1.0

func (n *Signature) Tokens() []Token

Tokens returns the tokens n consist of.

func (Signature) Type added in v2.0.2

func (t Signature) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type SliceExpr added in v2.0.2

type SliceExpr struct {
	PrimaryExpr Expression
	LBracket    Token
	Expr        Expression
	Colon       Token
	Expr2       Expression
	Colon2      Token
	Expr3       Expression
	RBracket    Token
	// contains filtered or unexported fields
}

SliceExpr describes a slice expression.

SliceExpr = "[" [ Expression ] ":" [ Expression ] "]" | "[" [ Expression ] ":" Expression ":" Expression "]" .

func (*SliceExpr) Position added in v2.0.2

func (n *SliceExpr) Position() (r token.Position)

Position implements Node.

func (*SliceExpr) SetValue added in v2.0.2

func (v *SliceExpr) SetValue(val constant.Value)

SetValue implements Expression

func (*SliceExpr) Source added in v2.0.2

func (n *SliceExpr) Source(full bool) []byte

Source implements Node.

func (*SliceExpr) Tokens added in v2.1.0

func (n *SliceExpr) Tokens() []Token

Tokens returns the tokens n consist of.

func (SliceExpr) Type added in v2.0.2

func (t SliceExpr) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (SliceExpr) Value added in v2.0.2

func (v SliceExpr) Value() constant.Value

Value implements Expression

type SliceType added in v2.0.2

type SliceType struct {
	Elem Type
	// contains filtered or unexported fields
}

SliceType represents a slice type.

func (*SliceType) Kind added in v2.0.2

func (t *SliceType) Kind() Kind

Kind implements Type.

func (*SliceType) Position added in v2.0.2

func (t *SliceType) Position() (r token.Position)

Position implements Node.

func (SliceType) Source added in v2.0.2

func (SliceType) Source(bool) []byte

Source implements Node. It returns nil.

func (*SliceType) String added in v2.0.2

func (t *SliceType) String() string

func (SliceType) Tokens added in v2.1.0

func (SliceType) Tokens() []Token

Tokens implements Node. It returns nil.

type SliceTypeNode added in v2.0.2

type SliceTypeNode struct {
	LBracket    Token
	RBracket    Token
	ElementType Node
	// contains filtered or unexported fields
}

SliceTypeNode describes a slice type.

SliceTypeNode = "[" "]" ElementType .

func (*SliceTypeNode) Position added in v2.0.2

func (n *SliceTypeNode) Position() (r token.Position)

Position implements Node.

func (*SliceTypeNode) Source added in v2.0.2

func (n *SliceTypeNode) Source(full bool) []byte

Source implements Node.

func (*SliceTypeNode) Tokens added in v2.1.0

func (n *SliceTypeNode) Tokens() []Token

Tokens returns the tokens n consist of.

type SourceFile added in v2.0.1

type SourceFile struct {
	PackageClause *PackageClause
	ImportDecls   []*ImportDecl
	TopLevelDecls []Node
	EOF           Token
	Scope         *Scope
	// contains filtered or unexported fields
}

SourceFile describes a source file.

SourceFile = PackageClause ";" { ImportDecl ";" } { TopLevelDecl ";" } .

func ParseSourceFile added in v2.0.1

func ParseSourceFile(cfg *ParseSourceFileConfig, name string, buf []byte) (r *SourceFile, err error)

ParseSourceFile parses buf and returns a *SourceFile or an error, if any. Positions are reported as if buf is coming from a file named name. The buffer becomes owned by the *SourceFile and must not be modified after calling ParseSourceFile. The same cfg argument must be used for all source files within a package. Distinct, new instances of the cfg arguments must be used for distinct packages.

func (*SourceFile) Position added in v2.0.1

func (n *SourceFile) Position() (r token.Position)

Position implements Node.

func (*SourceFile) Source added in v2.0.2

func (n *SourceFile) Source(full bool) []byte

Source implements Node.

func (*SourceFile) Tokens added in v2.1.0

func (n *SourceFile) Tokens() []Token

Tokens returns the tokens n consist of.

type StructType added in v2.0.2

type StructType struct {
	Fields []*Field
	// contains filtered or unexported fields
}

StructType represents a struct type.

func (*StructType) FieldByName added in v2.0.2

func (t *StructType) FieldByName(nm string) *Field

FieldByName returns the field named nm or nil, if no such field exists.

func (*StructType) Kind added in v2.0.2

func (t *StructType) Kind() Kind

Kind implements Type.

func (*StructType) Position added in v2.0.2

func (t *StructType) Position() (r token.Position)

Position implements Node.

func (StructType) Source added in v2.0.2

func (StructType) Source(bool) []byte

Source implements Node. It returns nil.

func (*StructType) String added in v2.0.2

func (t *StructType) String() string

func (StructType) Tokens added in v2.1.0

func (StructType) Tokens() []Token

Tokens implements Node. It returns nil.

type StructTypeNode added in v2.0.2

type StructTypeNode struct {
	Struct     Token
	LBrace     Token
	FieldDecls []Node
	RBrace     Token
	// contains filtered or unexported fields
}

StructTypeNode describes a struct type.

StructTyp = "struct" "{" { FieldDecl ";" } "}" .

func (*StructTypeNode) Position added in v2.0.2

func (n *StructTypeNode) Position() (r token.Position)

Position implements Node.

func (*StructTypeNode) Source added in v2.0.2

func (n *StructTypeNode) Source(full bool) []byte

Source implements Node.

func (*StructTypeNode) Tokens added in v2.1.0

func (n *StructTypeNode) Tokens() []Token

Tokens returns the tokens n consist of.

func (StructTypeNode) Type added in v2.0.2

func (t StructTypeNode) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type Token

type Token struct {
	Ch
	// contains filtered or unexported fields
}

Token is the product of Scanner.Scan and a terminal node of the complete syntax tree.

func (Token) IsValid

func (n Token) IsValid() bool

IsValid reports the validity of n. Tokens not present in some nodes will report false.

func (*Token) Offset

func (n *Token) Offset() int

Offset reports n's offset, in bytes, within its source file.

func (Token) Position

func (n Token) Position() (r token.Position)

Position implements Node.

func (Token) Sep

func (n Token) Sep() string

Sep returns the whitespace preceding n, if any.

func (*Token) Set added in v2.0.1

func (n *Token) Set(sep, src string)

Set sets the result of n.Sep to be sep and n.Src() to be src. Set will allocate at least len(sep+src) bytes of additional memory.

func (*Token) SetSep added in v2.0.2

func (n *Token) SetSep(sep string)

SetSep sets the result of n.Sep to be sep. SetSep will allocate at least len(sep+n.Src()) bytes of additional memory.

func (*Token) SetSrc added in v2.0.2

func (n *Token) SetSrc(src string)

SetSrc sets the result of n.Src to be src. SetSrc will allocate at least len(n.Sep()+src()) bytes of additional memory.

func (Token) Source added in v2.0.2

func (n Token) Source(full bool) []byte

Source implements Node.

func (Token) Src

func (n Token) Src() string

Src returns the textual form of n.

func (Token) String

func (n Token) String() string

String pretty formats n.

func (Token) Tokens added in v2.1.0

func (n Token) Tokens() []Token

Tokens returns the tokens n consist of.

type TupleType added in v2.0.2

type TupleType struct {
	Types []Type
}

TupleType represents an ordered list of types.

func (*TupleType) Kind added in v2.0.2

func (t *TupleType) Kind() Kind

Kind implements Type.

func (*TupleType) Position added in v2.0.2

func (t *TupleType) Position() (r token.Position)

Position implements Node.

func (*TupleType) Source added in v2.0.2

func (t *TupleType) Source(bool) []byte

Source implements Node. It returns nil.

func (*TupleType) String added in v2.0.2

func (t *TupleType) String() string

func (*TupleType) Tokens added in v2.1.0

func (t *TupleType) Tokens() []Token

Tokens implements Node. It returns nil.

type Type added in v2.0.2

type Type interface {
	fmt.Stringer
	Node
	// Kind returns the specific kind of a type.
	Kind() Kind
}

Type is the representation of a Go type.

The dynamic type of a Type is one of

*AliasType
*ArrayType
*ChannelType
*FunctionType
*InterfaceType
*InvalidType
*InvalidType
*MapType
*PointerType
*SliceType
*StructType
*TupleType
*TypeName
PredefinedType
var (
	Invalid            Type = &InvalidType{}
	UntypedBoolType    Type = PredefinedType(UntypedBool)
	UntypedComplexType Type = PredefinedType(UntypedComplex)
	UntypedFloatType   Type = PredefinedType(UntypedFloat)
	UntypedIntType     Type = PredefinedType(UntypedInt)
	UntypedNilType     Type = PredefinedType(UntypedNil)
	UntypedStringType  Type = PredefinedType(UntypedString)
)

Singleton instances of some compile-time only pseudo types.

type TypeArgs added in v2.0.2

type TypeArgs struct {
	LBracket Token
	TypeList []*TypeListItem
	RBracket Token
	Comma    Token
}

TypeArgs describes a type name.

TypeArgs = "[" TypeList [ "," ] "]" .

func (*TypeArgs) Position added in v2.0.2

func (n *TypeArgs) Position() (r token.Position)

Position implements Node.

func (*TypeArgs) Source added in v2.0.2

func (n *TypeArgs) Source(full bool) []byte

Source implements Node.

func (*TypeArgs) Tokens added in v2.1.0

func (n *TypeArgs) Tokens() []Token

Tokens returns the tokens n consist of.

type TypeAssertion added in v2.0.2

type TypeAssertion struct {
	PrimaryExpr Expression
	Dot         Token
	LParen      Token
	AssertType  Node
	RParen      Token
	// contains filtered or unexported fields
}

TypeAssertion describes a type assertion.

TypeAssertion = PrimaryExpr "." "(" Type ")" .

func (*TypeAssertion) Position added in v2.0.2

func (n *TypeAssertion) Position() (r token.Position)

Position implements Node.

func (*TypeAssertion) SetValue added in v2.0.2

func (v *TypeAssertion) SetValue(val constant.Value)

SetValue implements Expression

func (*TypeAssertion) Source added in v2.0.2

func (n *TypeAssertion) Source(full bool) []byte

Source implements Node.

func (*TypeAssertion) Tokens added in v2.1.0

func (n *TypeAssertion) Tokens() []Token

Tokens returns the tokens n consist of.

func (TypeAssertion) Type added in v2.0.2

func (t TypeAssertion) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (TypeAssertion) Value added in v2.0.2

func (v TypeAssertion) Value() constant.Value

Value implements Expression

type TypeCaseClause added in v2.0.2

type TypeCaseClause struct {
	TypeSwitchCase *TypeSwitchCase
	Colon          Token
	StatementList  []Node
}

TypeCaseClause describes a type switch case clause.

TypeCaseClause  = TypeSwitchCase ":" StatementList .

func (*TypeCaseClause) Position added in v2.0.2

func (n *TypeCaseClause) Position() (r token.Position)

Position implements Node.

func (*TypeCaseClause) Source added in v2.0.2

func (n *TypeCaseClause) Source(full bool) []byte

Source implements Node.

func (*TypeCaseClause) Tokens added in v2.1.0

func (n *TypeCaseClause) Tokens() []Token

Tokens returns the tokens n consist of.

type TypeDecl added in v2.0.2

type TypeDecl struct {
	TypeTok   Token
	LParen    Token
	TypeSpecs []Node
	RParen    Token
	Semicolon Token
}

TypeDecl describes a type declaration.

TypeDecl = "type" ( TypeSpec | "(" { TypeSpec ";" } ")" ) .

func (*TypeDecl) Position added in v2.0.2

func (n *TypeDecl) Position() (r token.Position)

Position implements Node.

func (*TypeDecl) Source added in v2.0.2

func (n *TypeDecl) Source(full bool) []byte

Source implements Node.

func (*TypeDecl) Tokens added in v2.1.0

func (n *TypeDecl) Tokens() []Token

Tokens returns the tokens n consist of.

type TypeDef added in v2.0.2

type TypeDef struct {
	Ident          Token
	TypeParameters *TypeParameters
	TypeNode       Node
	Semicolon      Token
	// contains filtered or unexported fields
}

TypeDef describes a type definition.

TypeDef = identifier [ TypeParameters ] Type .

func (*TypeDef) Kind added in v2.0.2

func (t *TypeDef) Kind() Kind

Kind implements Type.

func (TypeDef) LexicalScope added in v2.2.0

func (n TypeDef) LexicalScope() *Scope

LexicalScope returns the lexical scope n appears in.

func (*TypeDef) Position added in v2.0.2

func (n *TypeDef) Position() (r token.Position)

Position implements Node.

func (*TypeDef) Source added in v2.0.2

func (n *TypeDef) Source(full bool) []byte

Source implements Node.

func (*TypeDef) String added in v2.0.2

func (t *TypeDef) String() string

func (*TypeDef) Tokens added in v2.1.0

func (n *TypeDef) Tokens() []Token

Tokens returns the tokens n consist of.

func (TypeDef) Type added in v2.0.2

func (t TypeDef) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type TypeElem added in v2.0.2

type TypeElem struct {
	TypeTerms []*TypeTerm
	Semicolon Token
}

TypeElem describes a type element.

TypeElem = TypeTerm { "|" TypeTerm } .

func (*TypeElem) Position added in v2.0.2

func (n *TypeElem) Position() (r token.Position)

Position implements Node.

func (*TypeElem) Source added in v2.0.2

func (n *TypeElem) Source(full bool) []byte

Source implements Node.

func (*TypeElem) Tokens added in v2.1.0

func (n *TypeElem) Tokens() []Token

Tokens returns the tokens n consist of.

type TypeListItem added in v2.0.2

type TypeListItem struct {
	Type  Node
	Comma Token
}

TypeListItem describes an item of a type list.

func (*TypeListItem) Position added in v2.0.2

func (n *TypeListItem) Position() (r token.Position)

Position implements Node.

func (*TypeListItem) Source added in v2.0.2

func (n *TypeListItem) Source(full bool) []byte

Source implements Node.

func (*TypeListItem) Tokens added in v2.1.0

func (n *TypeListItem) Tokens() []Token

Tokens returns the tokens n consist of.

type TypeNameNode added in v2.0.2

type TypeNameNode struct {
	Name     *QualifiedIdent
	TypeArgs *TypeArgs
	// contains filtered or unexported fields
}

TypeNameNode describes a type name.

TypeNameNode = QualifiedIdent [ TypeArgs ]
	| identifier [ TypeArgs ] .

func (*TypeNameNode) Position added in v2.0.2

func (n *TypeNameNode) Position() (r token.Position)

Position implements Node.

func (*TypeNameNode) Source added in v2.0.2

func (n *TypeNameNode) Source(full bool) []byte

Source implements Node.

func (*TypeNameNode) Tokens added in v2.1.0

func (n *TypeNameNode) Tokens() []Token

Tokens returns the tokens n consist of.

func (TypeNameNode) Type added in v2.0.2

func (t TypeNameNode) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

type TypeParamDecl added in v2.0.2

type TypeParamDecl struct {
	IdentifierList []*IdentListItem
	TypeConstraint *TypeElem
	Comma          Token
}

TypeParamDecl describes an item of a type parameter list.

TypeParamDecl = IdentifierList TypeConstraint .

func (*TypeParamDecl) Position added in v2.0.2

func (n *TypeParamDecl) Position() (r token.Position)

Position implements Node.

func (*TypeParamDecl) Source added in v2.0.2

func (n *TypeParamDecl) Source(full bool) []byte

Source implements Node.

func (*TypeParamDecl) Tokens added in v2.1.0

func (n *TypeParamDecl) Tokens() []Token

Tokens returns the tokens n consist of.

type TypeParameters added in v2.0.2

type TypeParameters struct {
	LBracket      Token
	TypeParamList []*TypeParamDecl
	RBracket      Token
}

TypeParameters describes type parameters.

TypeParameters = "[" TypeParamList [ "," ] "]" .

func (*TypeParameters) Position added in v2.0.2

func (n *TypeParameters) Position() (r token.Position)

Position implements Node.

func (*TypeParameters) Source added in v2.0.2

func (n *TypeParameters) Source(full bool) []byte

Source implements Node.

func (*TypeParameters) Tokens added in v2.1.0

func (n *TypeParameters) Tokens() []Token

Tokens returns the tokens n consist of.

type TypeSwitchCase added in v2.0.2

type TypeSwitchCase struct {
	CaseOrDefault Token
	TypeList      []*TypeListItem
}

TypeSwitchCase describes an expression switch case.

TypeSwitchCase  = "case" TypeList | "default" .

func (*TypeSwitchCase) Position added in v2.0.2

func (n *TypeSwitchCase) Position() (r token.Position)

Position implements Node.

func (*TypeSwitchCase) Source added in v2.0.2

func (n *TypeSwitchCase) Source(full bool) []byte

Source implements Node.

func (*TypeSwitchCase) Tokens added in v2.1.0

func (n *TypeSwitchCase) Tokens() []Token

Tokens returns the tokens n consist of.

type TypeSwitchGuard added in v2.0.2

type TypeSwitchGuard struct {
	Ident       Token
	Define      Token
	PrimaryExpr Expression
	Dot         Token
	LParen      Token
	TypeToken   Token
	RParen      Token
	// contains filtered or unexported fields
}

TypeSwitchGuard describes a type switch guard.

TypeSwitchGuard = [ identifier ":=" ] PrimaryExpr "." "(" "type" ")" .

func (*TypeSwitchGuard) Position added in v2.0.2

func (n *TypeSwitchGuard) Position() (r token.Position)

Position implements Node.

func (*TypeSwitchGuard) SetValue added in v2.0.2

func (v *TypeSwitchGuard) SetValue(val constant.Value)

SetValue implements Expression

func (*TypeSwitchGuard) Source added in v2.0.2

func (n *TypeSwitchGuard) Source(full bool) []byte

Source implements Node.

func (*TypeSwitchGuard) Tokens added in v2.1.0

func (n *TypeSwitchGuard) Tokens() []Token

Tokens returns the tokens n consist of.

func (TypeSwitchGuard) Type added in v2.0.2

func (t TypeSwitchGuard) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (TypeSwitchGuard) Value added in v2.0.2

func (v TypeSwitchGuard) Value() constant.Value

Value implements Expression

type TypeSwitchStmt added in v2.0.2

type TypeSwitchStmt struct {
	Switch          Token
	SimpleStmt      Node
	Semicolon       Token
	TypeSwitchGuard *TypeSwitchGuard
	LBrace          Token
	TypeCaseClauses []*TypeCaseClause
	RBrace          Token
	Semicolon2      Token
	Scope           *Scope // Implicit scope of the switch statement
}

TypeSwitchStmt describes a type switch statement.

TypeSwitchStmt  = "switch" [ SimpleStmt ";" ] TypeSwitchGuard "{" { TypeCaseClause } "}" .

func (*TypeSwitchStmt) Position added in v2.0.2

func (n *TypeSwitchStmt) Position() (r token.Position)

Position implements Node.

func (*TypeSwitchStmt) Source added in v2.0.2

func (n *TypeSwitchStmt) Source(full bool) []byte

Source implements Node.

func (*TypeSwitchStmt) Tokens added in v2.1.0

func (n *TypeSwitchStmt) Tokens() []Token

Tokens returns the tokens n consist of.

type TypeTerm added in v2.0.2

type TypeTerm struct {
	Tilde Token
	Type  Node
	Pipe  Token
}

TypeTerm describes a type term.

TypeTerm = Type | UnderlyingType .
UnderlyingType = "~" Type .

func (*TypeTerm) Position added in v2.0.2

func (n *TypeTerm) Position() (r token.Position)

Position implements Node.

func (*TypeTerm) Source added in v2.0.2

func (n *TypeTerm) Source(full bool) []byte

Source implements Node.

func (*TypeTerm) Tokens added in v2.1.0

func (n *TypeTerm) Tokens() []Token

Tokens returns the tokens n consist of.

type UnaryExpr added in v2.0.2

type UnaryExpr struct {
	Op   Token
	Expr Expression
	// contains filtered or unexported fields
}

UnaryExpr describes an unary expression.

UnaryExpr = PrimaryExpr | unary_op UnaryExpr .

func (*UnaryExpr) Position added in v2.0.2

func (n *UnaryExpr) Position() (r token.Position)

Position implements Node.

func (*UnaryExpr) SetValue added in v2.0.2

func (v *UnaryExpr) SetValue(val constant.Value)

SetValue implements Expression

func (*UnaryExpr) Source added in v2.0.2

func (n *UnaryExpr) Source(full bool) []byte

Source implements Node.

func (*UnaryExpr) Tokens added in v2.1.0

func (n *UnaryExpr) Tokens() []Token

Tokens returns the tokens n consist of.

func (UnaryExpr) Type added in v2.0.2

func (t UnaryExpr) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (UnaryExpr) Value added in v2.0.2

func (v UnaryExpr) Value() constant.Value

Value implements Expression

type VarDecl added in v2.0.2

type VarDecl struct {
	Var       Token
	LParen    Token
	VarSpecs  []*VarSpec
	RParen    Token
	Semicolon Token
	// contains filtered or unexported fields
}

VarDecl describes a variable declaration.

VarDecl = "var" ( VarSpec | "(" { VarSpec ";" } ")" ) .

func (VarDecl) LexicalScope added in v2.0.2

func (n VarDecl) LexicalScope() *Scope

LexicalScope returns the lexical scope n appears in.

func (*VarDecl) Position added in v2.0.2

func (n *VarDecl) Position() (r token.Position)

Position implements Node.

func (*VarDecl) Source added in v2.0.2

func (n *VarDecl) Source(full bool) []byte

Source implements Node.

func (*VarDecl) Tokens added in v2.1.0

func (n *VarDecl) Tokens() []Token

Tokens returns the tokens n consist of.

type VarSpec added in v2.0.2

type VarSpec struct {
	IdentifierList []*IdentListItem
	Type           Node
	Eq             Token
	ExprList       []*ExprListItem
	Semicolon      Token
}

VarSpec describes a variable specification.

VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) .

func (*VarSpec) Position added in v2.0.2

func (n *VarSpec) Position() (r token.Position)

Position implements Node.

func (*VarSpec) Source added in v2.0.2

func (n *VarSpec) Source(full bool) []byte

Source implements Node.

func (*VarSpec) Tokens added in v2.1.0

func (n *VarSpec) Tokens() []Token

Tokens returns the tokens n consist of.

type Variable added in v2.0.2

type Variable struct {
	Expr     Expression
	Ident    Token
	TypeNode Node
	// contains filtered or unexported fields
}

Variable represents a Go variable.

func (*Variable) IsParameter added in v2.0.2

func (n *Variable) IsParameter() bool

IsParameter reports whether n is a function/method parameter, result variable or receiver.

func (*Variable) Position added in v2.0.2

func (n *Variable) Position() (r token.Position)

Position implements Node.

func (*Variable) SetValue added in v2.0.2

func (v *Variable) SetValue(val constant.Value)

SetValue implements Expression

func (*Variable) Source added in v2.0.2

func (n *Variable) Source(full bool) []byte

Source implements Node.

func (*Variable) Tokens added in v2.1.0

func (n *Variable) Tokens() []Token

Tokens returns the tokens n consist of.

func (Variable) Type added in v2.0.2

func (t Variable) Type() Type

Type returns the type of a node or Invalid if the type is unknown/undetermined.

func (Variable) Value added in v2.0.2

func (v Variable) Value() constant.Value

Value implements Expression

Jump to

Keyboard shortcuts

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