Documentation ¶
Overview ¶
Package gc is a Go compiler front end. Work in progess. API not stable.
Index ¶
- type ArrayType
- func (n *ArrayType) AssignableTo(t Type) bool
- func (n *ArrayType) ComparableWith(t Type) (r bool, _ string)
- func (n *ArrayType) Identical(t Type) bool
- func (n *ArrayType) Implements(t Type) (r bool)
- func (n *ArrayType) IsDefined() bool
- func (n *ArrayType) Kind() TypeKind
- func (n *ArrayType) String() string
- func (n *ArrayType) UnderlyingType() Type
- type Bindings
- type CaseBlock
- type ChanDir
- type ChannelType
- func (n *ChannelType) AssignableTo(t Type) bool
- func (n *ChannelType) ComparableWith(t Type) (r bool, _ string)
- func (n *ChannelType) Identical(t Type) bool
- func (n *ChannelType) Implements(t Type) (r bool)
- func (n *ChannelType) IsDefined() bool
- func (n *ChannelType) Kind() TypeKind
- func (n *ChannelType) String() string
- func (n *ChannelType) UnderlyingType() Type
- type CompLitExpr
- type CompLitExprExpr
- type CompLitExprKeyValList
- type ConstDecl
- type Context
- func (c *Context) Build(files []string) (*Package, error)
- func (c *Context) FilesForImportPath(position token.Position, importPath string) (dir string, sourceFiles []string, testFiles []string, err error)
- func (c *Context) Load(importPath string) (*Package, error)
- func (c *Context) NumPackages() int
- func (c *Context) SourceFileForPath(path string) *SourceFile
- type Declaration
- type DeclarationKind
- type ElseIf
- type Expr
- type ExprADD
- type ExprAND
- type ExprANDNOT
- type ExprARROW
- type ExprEQL
- type ExprGEQ
- type ExprGTR
- type ExprLAND
- type ExprLEQ
- type ExprLOR
- type ExprLSS
- type ExprMUL
- type ExprNEQ
- type ExprOR
- type ExprOrType
- type ExprOrTypeExpr
- type ExprOrTypeType
- type ExprQUO
- type ExprREM
- type ExprSHL
- type ExprSHR
- type ExprSUB
- type ExprXOR
- type FieldDeclaration
- type FieldDeclarationEmbedded
- type FieldDeclarationNamed
- type FuncDecl
- type FunctionType
- func (n *FunctionType) AssignableTo(t Type) bool
- func (n *FunctionType) ComparableWith(t Type) (r bool, _ string)
- func (n *FunctionType) Identical(t Type) bool
- func (n *FunctionType) Implements(t Type) (r bool)
- func (n *FunctionType) IsDefined() bool
- func (n *FunctionType) Kind() TypeKind
- func (n *FunctionType) Parameters() Type
- func (n *FunctionType) Result() Type
- func (n *FunctionType) String() (r string)
- func (n *FunctionType) UnderlyingType() Type
- type Ident
- type IfHeader
- type IfHeader1
- type IfHeader2
- type ImportDecl
- type InterfaceType
- func (n *InterfaceType) AssignableTo(t Type) bool
- func (n *InterfaceType) ComparableWith(t Type) (r bool, _ string)
- func (n *InterfaceType) Identical(t Type) bool
- func (n *InterfaceType) Implements(t Type) (r bool)
- func (n *InterfaceType) IsDefined() bool
- func (n *InterfaceType) Kind() TypeKind
- func (n *InterfaceType) String() string
- func (n *InterfaceType) UnderlyingType() Type
- type InvalidValue
- type KeyVal
- type KeyValExpr
- type KeyValKeyedExpr
- type MapType
- func (n *MapType) AssignableTo(t Type) bool
- func (n *MapType) ComparableWith(t Type) (r bool, _ string)
- func (n *MapType) Identical(t Type) bool
- func (n *MapType) Implements(t Type) (r bool)
- func (n *MapType) IsDefined() bool
- func (n *MapType) Kind() TypeKind
- func (n *MapType) String() string
- func (n *MapType) UnderlyingType() Type
- type MethodDecl
- type NamedType
- func (n *NamedType) AssignableTo(t Type) bool
- func (n *NamedType) ComparableWith(t Type) (r bool, _ string)
- func (n *NamedType) Declaration() *TypeDecl
- func (n *NamedType) Identical(t Type) bool
- func (n *NamedType) Implements(t Type) (r bool)
- func (n *NamedType) IsDefined() bool
- func (n *NamedType) Kind() TypeKind
- func (n *NamedType) Scope() *Scope
- func (n *NamedType) String() string
- func (n *NamedType) Type() Type
- func (n *NamedType) UnderlyingType() Type
- type Node
- type Operand
- type Option
- type Package
- type ParamType
- type ParamTypeIdentType
- type ParamTypeList
- type ParamTypeListIdentType
- type ParamTypeListType
- type ParamTypeType
- type PointerType
- func (n *PointerType) AssignableTo(t Type) bool
- func (n *PointerType) ComparableWith(t Type) (r bool, _ string)
- func (n *PointerType) Identical(t Type) bool
- func (n *PointerType) Implements(t Type) (r bool)
- func (n *PointerType) IsDefined() bool
- func (n *PointerType) Kind() TypeKind
- func (n *PointerType) String() string
- func (n *PointerType) UnderlyingType() Type
- type PrimaryExpr
- type PrimaryExprCall
- type PrimaryExprCompositeLiteral
- func (n *PrimaryExprCompositeLiteral) Package() *Package
- func (n *PrimaryExprCompositeLiteral) Pos() token.Pos
- func (n *PrimaryExprCompositeLiteral) Position() (r token.Position)
- func (n *PrimaryExprCompositeLiteral) SourceFile() *SourceFile
- func (e *PrimaryExprCompositeLiteral) Type() Type
- func (e *PrimaryExprCompositeLiteral) Value() Value
- type PrimaryExprConversion
- func (n *PrimaryExprConversion) Package() *Package
- func (n *PrimaryExprConversion) Pos() token.Pos
- func (n *PrimaryExprConversion) Position() (r token.Position)
- func (n *PrimaryExprConversion) SourceFile() *SourceFile
- func (e *PrimaryExprConversion) Type() Type
- func (e *PrimaryExprConversion) Value() Value
- type PrimaryExprFloatLiteral
- type PrimaryExprFullSlice
- func (n *PrimaryExprFullSlice) Package() *Package
- func (n *PrimaryExprFullSlice) Pos() token.Pos
- func (n *PrimaryExprFullSlice) Position() (r token.Position)
- func (n *PrimaryExprFullSlice) SourceFile() *SourceFile
- func (e *PrimaryExprFullSlice) Type() Type
- func (e *PrimaryExprFullSlice) Value() Value
- type PrimaryExprFuncLiteral
- func (n *PrimaryExprFuncLiteral) Package() *Package
- func (n *PrimaryExprFuncLiteral) Pos() token.Pos
- func (n *PrimaryExprFuncLiteral) Position() (r token.Position)
- func (n *PrimaryExprFuncLiteral) SourceFile() *SourceFile
- func (e *PrimaryExprFuncLiteral) Type() Type
- func (e *PrimaryExprFuncLiteral) Value() Value
- type PrimaryExprIdent
- type PrimaryExprImagLiteral
- type PrimaryExprIndex
- type PrimaryExprIntLiteral
- type PrimaryExprParenExpr
- func (n *PrimaryExprParenExpr) Package() *Package
- func (n *PrimaryExprParenExpr) Pos() token.Pos
- func (n *PrimaryExprParenExpr) Position() (r token.Position)
- func (n *PrimaryExprParenExpr) SourceFile() *SourceFile
- func (e *PrimaryExprParenExpr) Type() Type
- func (e *PrimaryExprParenExpr) Value() Value
- type PrimaryExprRuneLiteral
- type PrimaryExprSelector
- type PrimaryExprSimpleSlice
- func (n *PrimaryExprSimpleSlice) Package() *Package
- func (n *PrimaryExprSimpleSlice) Pos() token.Pos
- func (n *PrimaryExprSimpleSlice) Position() (r token.Position)
- func (n *PrimaryExprSimpleSlice) SourceFile() *SourceFile
- func (e *PrimaryExprSimpleSlice) Type() Type
- func (e *PrimaryExprSimpleSlice) Value() Value
- type PrimaryExprStringLiteral
- type PrimaryExprTypeAssertion
- func (n *PrimaryExprTypeAssertion) Package() *Package
- func (n *PrimaryExprTypeAssertion) Pos() token.Pos
- func (n *PrimaryExprTypeAssertion) Position() (r token.Position)
- func (n *PrimaryExprTypeAssertion) SourceFile() *SourceFile
- func (e *PrimaryExprTypeAssertion) Type() Type
- func (e *PrimaryExprTypeAssertion) Value() Value
- type PrimaryExprTypeSwitchGuard
- func (n *PrimaryExprTypeSwitchGuard) Package() *Package
- func (n *PrimaryExprTypeSwitchGuard) Pos() token.Pos
- func (n *PrimaryExprTypeSwitchGuard) Position() (r token.Position)
- func (n *PrimaryExprTypeSwitchGuard) SourceFile() *SourceFile
- func (e *PrimaryExprTypeSwitchGuard) Type() Type
- func (e *PrimaryExprTypeSwitchGuard) Value() Value
- type QualifiedNamedType
- func (n *QualifiedNamedType) AssignableTo(t Type) bool
- func (n *QualifiedNamedType) ComparableWith(t Type) (r bool, _ string)
- func (n *QualifiedNamedType) Declaration() *TypeDecl
- func (n *QualifiedNamedType) Identical(t Type) bool
- func (n *QualifiedNamedType) Implements(t Type) (r bool)
- func (n *QualifiedNamedType) IsDefined() bool
- func (n *QualifiedNamedType) Kind() TypeKind
- func (n *QualifiedNamedType) Scope() *Scope
- func (n *QualifiedNamedType) String() string
- func (n *QualifiedNamedType) Type() Type
- func (n *QualifiedNamedType) UnderlyingType() Type
- type Scope
- type ScopeKind
- type SimpleStmt
- type SimpleStmtAddAssign
- type SimpleStmtAndAssign
- type SimpleStmtAndNotAssign
- type SimpleStmtAssignment
- type SimpleStmtDec
- type SimpleStmtDecl
- type SimpleStmtDefine
- type SimpleStmtExpr
- type SimpleStmtInc
- type SimpleStmtMulAssign
- type SimpleStmtOrAssign
- type SimpleStmtQuoAssign
- type SimpleStmtRemAssign
- type SimpleStmtSend
- type SimpleStmtShlAssign
- type SimpleStmtShrAssign
- type SimpleStmtSubAssign
- type SimpleStmtXorAssign
- type SliceType
- func (n *SliceType) AssignableTo(t Type) bool
- func (n *SliceType) ComparableWith(t Type) (r bool, _ string)
- func (n *SliceType) Identical(t Type) bool
- func (n *SliceType) Implements(t Type) (r bool)
- func (n *SliceType) IsDefined() bool
- func (n *SliceType) Kind() TypeKind
- func (n *SliceType) String() string
- func (n *SliceType) UnderlyingType() Type
- type SourceFile
- type Stmt
- type StmtBlock
- type StmtBreak
- type StmtContinue
- type StmtDefer
- type StmtFallthrough
- type StmtFor
- type StmtForRange
- type StmtGo
- type StmtGoto
- type StmtIf
- type StmtLabeled
- type StmtReturn
- type StmtSelect
- type StmtSwitch
- type StructType
- func (n *StructType) AssignableTo(t Type) bool
- func (n *StructType) ComparableWith(t Type) (r bool, _ string)
- func (n *StructType) Identical(t Type) bool
- func (n *StructType) Implements(t Type) (r bool)
- func (n *StructType) IsDefined() bool
- func (n *StructType) Kind() TypeKind
- func (n *StructType) String() string
- func (n *StructType) UnderlyingType() Type
- type Token
- type TupleType
- func (n *TupleType) AssignableTo(t Type) bool
- func (n *TupleType) ComparableWith(t Type) (r bool, _ string)
- func (n *TupleType) Identical(t Type) bool
- func (n *TupleType) Implements(t Type) (r bool)
- func (n *TupleType) IsDefined() bool
- func (n *TupleType) Kind() TypeKind
- func (n *TupleType) String() string
- func (n *TupleType) UnderlyingType() Type
- type Type
- type TypeDecl
- type TypeKind
- func (n TypeKind) AssignableTo(t Type) bool
- func (n TypeKind) ComparableWith(t Type) (bool, string)
- func (n TypeKind) Identical(t Type) bool
- func (n TypeKind) Implements(t Type) bool
- func (n TypeKind) IsDefined() bool
- func (n TypeKind) Kind() TypeKind
- func (n TypeKind) Package() *Package
- func (n TypeKind) Position() (r token.Position)
- func (n TypeKind) SourceFile() *SourceFile
- func (n TypeKind) String() string
- func (n TypeKind) UnderlyingType() Type
- type UnaryExpr
- type UnaryExprAddr
- type UnaryExprDeref
- type UnaryExprNeg
- type UnaryExprNot
- type UnaryExprPos
- type UnaryExprReceive
- type UnaryExprXor
- type UntypedBooleanValue
- type UntypedFalse
- type UntypedIntOperand
- type UntypedIntValue
- type UntypedTrue
- type Value
- type VarDecl
Examples ¶
- ArrayType
- CaseBlock (Default)
- CaseBlock (SelectAssign)
- CaseBlock (SelectDefine)
- CaseBlock (SwitchExpr)
- CaseBlock (SwitchType)
- ChannelType
- CompLitExpr (Expr)
- CompLitExpr (KeyValList)
- ElseIf
- Expr (ADD)
- Expr (AND)
- Expr (ANDNOT)
- Expr (EQL)
- Expr (GEQ)
- Expr (GTR)
- Expr (LAND)
- Expr (LEQ)
- Expr (LOR)
- Expr (LSS)
- Expr (MUL)
- Expr (NEQ)
- Expr (OR)
- Expr (QUO)
- Expr (REM)
- Expr (SHL)
- Expr (SHR)
- Expr (SUB)
- Expr (XOR)
- ExprOrType (Expr)
- ExprOrType (Type)
- FieldDeclaration (Embedded)
- FieldDeclaration (EmbeddedPtr)
- FieldDeclaration (Named)
- FunctionType
- IfHeader (Assign)
- IfHeader (Define)
- IfHeader (Simple)
- InterfaceType
- KeyVal (Expr)
- KeyVal (KeyedExpr)
- MapType
- NamedType
- ParamType (IdentType)
- ParamType (Type)
- ParamTypeList (IdentType)
- ParamTypeList (Type)
- PointerType
- PrimaryExpr (Call)
- PrimaryExpr (CompositeLiteral)
- PrimaryExpr (Conversion)
- PrimaryExpr (FloatLiteral)
- PrimaryExpr (FullSlice)
- PrimaryExpr (FuncLiteral)
- PrimaryExpr (Ident)
- PrimaryExpr (ImagLiteral)
- PrimaryExpr (Index)
- PrimaryExpr (IntLiteral)
- PrimaryExpr (ParenExpr)
- PrimaryExpr (RuneLiteral)
- PrimaryExpr (Selector)
- PrimaryExpr (SimpleSlice)
- PrimaryExpr (StringLiteral)
- PrimaryExpr (TypeAssertion)
- PrimaryExpr (TypeSwitchGuard)
- QualifiedNamedType
- SimpleStmt (AddAssign)
- SimpleStmt (AndAssign)
- SimpleStmt (AndNotAssign)
- SimpleStmt (Assignment)
- SimpleStmt (Assingnment)
- SimpleStmt (Dec)
- SimpleStmt (Decl)
- SimpleStmt (Define)
- SimpleStmt (Expr)
- SimpleStmt (Inc)
- SimpleStmt (MulAssign)
- SimpleStmt (OrAssign)
- SimpleStmt (QuoAssign)
- SimpleStmt (RemAssign)
- SimpleStmt (Send)
- SimpleStmt (ShlAssign)
- SimpleStmt (ShrAssign)
- SimpleStmt (SubAssign)
- SimpleStmt (XorAssign)
- SliceType
- Stmt (Block)
- Stmt (Break)
- Stmt (Continue)
- Stmt (Defer)
- Stmt (Fallthrough)
- Stmt (For)
- Stmt (ForRange)
- Stmt (ForRangeAssign)
- Stmt (ForRangeDefine)
- Stmt (Go)
- Stmt (Goto)
- Stmt (If)
- Stmt (IfAssign)
- Stmt (IfDefine)
- Stmt (IfElseIf)
- Stmt (IfElseIfElse)
- Stmt (Labeled)
- Stmt (Return)
- Stmt (Select)
- Stmt (Switch)
- StructType
- UnaryExpr (Addr)
- UnaryExpr (Deref)
- UnaryExpr (Neg)
- UnaryExpr (Not)
- UnaryExpr (Pos)
- UnaryExpr (Receive)
- UnaryExpr (Xor)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayType ¶
ArrayType represents '[Expr]Element'.
Example ¶
example(&ArrayType{}, "type T [42]int")
Output: &gc.ArrayType{ · Expr: &gc.PrimaryExprIntLiteral{ · · Literal: 2:9: "42", · }, · Element: &gc.NamedType{ · · Name: "int", · }, }
func (*ArrayType) AssignableTo ¶
func (*ArrayType) ComparableWith ¶
func (*ArrayType) Implements ¶
func (*ArrayType) UnderlyingType ¶
func (n *ArrayType) UnderlyingType() Type
type CaseBlock ¶
type CaseBlock struct { ExprOrTypeList []ExprOrType Expr Expr Body []Stmt //TODO StmtBlock Default bool // "default" clause Define bool // true: case x := y; false: case y or case x = y. // contains filtered or unexported fields }
CaseBlock represents data reduced by productions
caseBlockList: | caseBlockList "case" exprOrTypeList ":=" expr ':' stmtList | caseBlockList "case" exprOrTypeList ':' stmtList | caseBlockList "case" exprOrTypeList '=' expr ':' stmtList | caseBlockList "default" ':' stmtList
Example (Default) ¶
example(CaseBlock{}, ` func foo() { switch x { case 42: bar() default: baz() } } `)
Output: List: []gc.CaseBlock{ // len 2 · 0: gc.CaseBlock{ · · ExprOrTypeList: []*gc.ExprOrTypeExpr{ // len 1 · · · 0: &gc.ExprOrTypeExpr{ · · · · Expr: &gc.PrimaryExprIntLiteral{ · · · · · Literal: 5:7: "42", · · · · }, · · · }, · · }, · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 6:3: "bar", · · · · · }, · · · · }, · · · }, · · }, · }, · 1: gc.CaseBlock{ · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 8:3: "baz", · · · · · }, · · · · }, · · · }, · · }, · · Default: true, · }, },
Example (SelectAssign) ¶
example(CaseBlock{}, ` func foo() { select { case x, ok = <-c: bar() } } `)
Output: List: []gc.CaseBlock{ // len 1 · 0: gc.CaseBlock{ · · ExprOrTypeList: []*gc.ExprOrTypeExpr{ // len 2 · · · 0: &gc.ExprOrTypeExpr{ · · · · Expr: &gc.PrimaryExprIdent{ · · · · · Ident: 5:7: "x", · · · · }, · · · }, · · · 1: &gc.ExprOrTypeExpr{ · · · · Expr: &gc.PrimaryExprIdent{ · · · · · Ident: 5:10: "ok", · · · · }, · · · }, · · }, · · Expr: &gc.UnaryExprReceive{ · · · Expr: &gc.PrimaryExprIdent{ · · · · Ident: 5:17: "c", · · · }, · · }, · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 6:3: "bar", · · · · · }, · · · · }, · · · }, · · }, · }, },
Example (SelectDefine) ¶
example(CaseBlock{}, ` func foo() { select { case x, ok := <-c: bar() } } `)
Output: List: []gc.CaseBlock{ // len 1 · 0: gc.CaseBlock{ · · ExprOrTypeList: []*gc.ExprOrTypeExpr{ // len 2 · · · 0: &gc.ExprOrTypeExpr{ · · · · Expr: &gc.PrimaryExprIdent{ · · · · · Ident: 5:7: "x", · · · · }, · · · }, · · · 1: &gc.ExprOrTypeExpr{ · · · · Expr: &gc.PrimaryExprIdent{ · · · · · Ident: 5:10: "ok", · · · · }, · · · }, · · }, · · Expr: &gc.UnaryExprReceive{ · · · Expr: &gc.PrimaryExprIdent{ · · · · Ident: 5:18: "c", · · · }, · · }, · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 6:3: "bar", · · · · · }, · · · · }, · · · }, · · }, · · Define: true, · }, },
Example (SwitchExpr) ¶
example(CaseBlock{}, ` func foo() { switch x { case 42: bar() } } `)
Output: List: []gc.CaseBlock{ // len 1 · 0: gc.CaseBlock{ · · ExprOrTypeList: []*gc.ExprOrTypeExpr{ // len 1 · · · 0: &gc.ExprOrTypeExpr{ · · · · Expr: &gc.PrimaryExprIntLiteral{ · · · · · Literal: 5:7: "42", · · · · }, · · · }, · · }, · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 6:3: "bar", · · · · · }, · · · · }, · · · }, · · }, · }, },
Example (SwitchType) ¶
example(CaseBlock{}, ` func foo() { switch x.(type) { case []int: bar() } } `)
Output: List: []gc.CaseBlock{ // len 1 · 0: gc.CaseBlock{ · · ExprOrTypeList: []*gc.ExprOrTypeType{ // len 1 · · · 0: &gc.ExprOrTypeType{ · · · }, · · }, · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 6:3: "bar", · · · · · }, · · · · }, · · · }, · · }, · }, },
type ChannelType ¶
ChannelType represents 'chan Element'.
Example ¶
example(&ChannelType{}, "type T <-chan int")
Output: &gc.ChannelType{ · Element: &gc.NamedType{ · · Name: "int", · }, · Dir: RxChan, }
func (*ChannelType) AssignableTo ¶
func (*ChannelType) ComparableWith ¶
func (*ChannelType) Implements ¶
func (*ChannelType) Kind ¶
func (n *ChannelType) Kind() TypeKind
func (*ChannelType) String ¶
func (n *ChannelType) String() string
func (*ChannelType) UnderlyingType ¶
func (n *ChannelType) UnderlyingType() Type
type CompLitExpr ¶
type CompLitExpr interface {
// contains filtered or unexported methods
}
CompLitExpr represents data reduced by productions
compLitExpr: '{' bracedKeyValList '}' | expr
Example (Expr) ¶
example(&CompLitExprExpr{}, "var v = []int{42}")
Output: Expr: &gc.CompLitExprExpr{ · Expr: &gc.PrimaryExprIntLiteral{ · · Literal: 2:15: "42", · }, },
Example (KeyValList) ¶
example(&CompLitExprKeyValList{}, "var v = [][]int{{1: 42, 3: 314}}")
Output: Expr: &gc.CompLitExprKeyValList{ · List: []*gc.KeyValKeyedExpr{ // len 2 · · 0: &gc.KeyValKeyedExpr{ · · · Key: &gc.CompLitExprExpr{ · · · · Expr: &gc.PrimaryExprIntLiteral{ · · · · · Literal: 2:18: "1", · · · · }, · · · }, · · · Expr: &gc.CompLitExprExpr{ · · · · Expr: &gc.PrimaryExprIntLiteral{ · · · · · Literal: 2:21: "42", · · · · }, · · · }, · · }, · · 1: &gc.KeyValKeyedExpr{ · · · Key: &gc.CompLitExprExpr{ · · · · Expr: &gc.PrimaryExprIntLiteral{ · · · · · Literal: 2:25: "3", · · · · }, · · · }, · · · Expr: &gc.CompLitExprExpr{ · · · · Expr: &gc.PrimaryExprIntLiteral{ · · · · · Literal: 2:28: "314", · · · · }, · · · }, · · }, · }, },
type CompLitExprExpr ¶
type CompLitExprExpr struct { Expr Expr // contains filtered or unexported fields }
CompLitExprExpr is a CompLitExpr.
type CompLitExprKeyValList ¶
type CompLitExprKeyValList struct { List []KeyVal // contains filtered or unexported fields }
CompLitExprKeyValList is a CompLitExpr.
type ConstDecl ¶
type ConstDecl struct { Value Operand // contains filtered or unexported fields }
ConstDecl describes a constant declaration.
func (*ConstDecl) Visibility ¶
Visibility implements Declaration.
type Context ¶
type Context struct {
// 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.ir/pkg/go/build/#hdr-Build_Constraints for details). searchPaths are examined when looking for a package to load.
func (*Context) Build ¶
Build constructs a package from files and returns the resulting Package or an error if any. Build panics if len(files) == 0.
The method is safe for concurrent use by multiple goroutines.
func (*Context) FilesForImportPath ¶
func (c *Context) FilesForImportPath(position token.Position, importPath string) (dir string, sourceFiles []string, testFiles []string, err error)
FilesForImportPath the package directory and a list of source and test files.
func (*Context) Load ¶
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 ¶
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 { //TODO Node // Kind returns the Declarations's kind. Kind() DeclarationKind // Name returns the declared name. Name() string // Position returns the position of the declaration. Position() token.Position // 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 // Type returns the declaration type. N/A for ImportDeclaration. Type() Type Package() *Package SourceFile() *SourceFile String() string // contains filtered or unexported methods }
Declaration is one of *ConstDecl, *FuncDecl, *ImportSpec, *MethodDecl, *TypeDecl or *VarDecl.
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 ElseIf ¶
ElseIf represents data reduced by productions
elseIfList: | elseIfList "else" "if" ifHeader loopBody
Example ¶
example(ElseIf{}, ` func foo() { if x { bar() } else if y { baz() } else if y { qux() } } `)
Output: ElseIf: []gc.ElseIf{ // len 2 · 0: gc.ElseIf{ · · IfHeader: &gc.IfHeader1{ · · · Stmt: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprIdent{ · · · · · Ident: 6:12: "y", · · · · }, · · · }, · · }, · · Body: &gc.StmtBlock{ · · · List: []*gc.SimpleStmtExpr{ // len 1 · · · · 0: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · Ident: 7:3: "baz", · · · · · · }, · · · · · }, · · · · }, · · · }, · · }, · }, · 1: gc.ElseIf{ · · IfHeader: &gc.IfHeader1{ · · · Stmt: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprIdent{ · · · · · Ident: 8:12: "y", · · · · }, · · · }, · · }, · · Body: &gc.StmtBlock{ · · · List: []*gc.SimpleStmtExpr{ // len 1 · · · · 0: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · Ident: 9:3: "qux", · · · · · · }, · · · · · }, · · · · }, · · · }, · · }, · }, },
type Expr ¶
type Expr interface { Operand Position() token.Position // contains filtered or unexported methods }
Expr represents data reduced by productions
expr: expr "!=" expr | expr "&&" expr | expr "&^" expr | expr "<-" expr | expr "<<" expr | expr "<=" expr | expr "==" expr | expr ">=" expr | expr ">>" expr | expr "||" expr | expr '%' expr | expr '&' expr | expr '*' expr | expr '+' expr | expr '-' expr | expr '/' expr | expr '<' expr | expr '>' expr | expr '^' expr | expr '|' expr | unaryExpr
Example (ADD) ¶
example(&ExprADD{}, "var v = a + b")
Output: Initializer: &gc.ExprADD{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:13: "b", · }, },
Example (AND) ¶
example(&ExprAND{}, "var v = a & b")
Output: Initializer: &gc.ExprAND{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:13: "b", · }, },
Example (ANDNOT) ¶
example(&ExprANDNOT{}, "var v = a &^ b")
Output: Initializer: &gc.ExprANDNOT{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "b", · }, },
Example (EQL) ¶
example(&ExprEQL{}, "var v = a == b")
Output: Initializer: &gc.ExprEQL{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "b", · }, },
Example (GEQ) ¶
example(&ExprGEQ{}, "var v = a >= b")
Output: Initializer: &gc.ExprGEQ{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "b", · }, },
Example (GTR) ¶
example(&ExprGTR{}, "var v = > b")
Output: Initializer: &gc.ExprGTR{ · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:11: "b", · }, },
Example (LAND) ¶
example(&ExprLAND{}, "var v = a && b")
Output: Initializer: &gc.ExprLAND{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "b", · }, },
Example (LEQ) ¶
example(&ExprLEQ{}, "var v = a <= b")
Output: Initializer: &gc.ExprLEQ{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "b", · }, },
Example (LOR) ¶
example(&ExprLOR{}, "var v = a || b")
Output: Initializer: &gc.ExprLOR{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "b", · }, },
Example (LSS) ¶
example(&ExprLSS{}, "var v = a < b")
Output: Initializer: &gc.ExprLSS{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:13: "b", · }, },
Example (MUL) ¶
example(&ExprMUL{}, "var v = a * b")
Output: Initializer: &gc.ExprMUL{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:13: "b", · }, },
Example (NEQ) ¶
example(&ExprNEQ{}, "var v = a != b")
Output: Initializer: &gc.ExprNEQ{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "b", · }, },
Example (OR) ¶
example(&ExprOR{}, "var v = a | b")
Output: Initializer: &gc.ExprOR{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:13: "b", · }, },
Example (QUO) ¶
example(&ExprQUO{}, "var v = a / b")
Output: Initializer: &gc.ExprQUO{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:13: "b", · }, },
Example (REM) ¶
example(&ExprREM{}, "var v = a % b")
Output: Initializer: &gc.ExprREM{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:13: "b", · }, },
Example (SHL) ¶
example(&ExprSHL{}, "var v = a << b")
Output: Initializer: &gc.ExprSHL{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "b", · }, },
Example (SHR) ¶
example(&ExprSHR{}, "var v = a >> b")
Output: Initializer: &gc.ExprSHR{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "b", · }, },
Example (SUB) ¶
example(&ExprSUB{}, "var v = a - b")
Output: Initializer: &gc.ExprSUB{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:13: "b", · }, },
Example (XOR) ¶
example(&ExprXOR{}, "var v = a ^ b")
Output: Initializer: &gc.ExprXOR{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:9: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:13: "b", · }, },
type ExprADD ¶
ExprADD represents LHS + RHS.
func (*ExprADD) SourceFile ¶
func (n *ExprADD) SourceFile() *SourceFile
type ExprAND ¶
ExprAND represents LHS & RHS.
func (*ExprAND) SourceFile ¶
func (n *ExprAND) SourceFile() *SourceFile
type ExprANDNOT ¶
ExprANDNOT represents LHS &^ RHS.
func (*ExprANDNOT) SourceFile ¶
func (n *ExprANDNOT) SourceFile() *SourceFile
type ExprARROW ¶
ExprARROW represents LHS <- RHS.
func (*ExprARROW) SourceFile ¶
func (n *ExprARROW) SourceFile() *SourceFile
type ExprEQL ¶
ExprEQL represents LHS == RHS.
func (*ExprEQL) SourceFile ¶
func (n *ExprEQL) SourceFile() *SourceFile
type ExprGEQ ¶
ExprGEQ represents LHS >= RHS.
func (*ExprGEQ) SourceFile ¶
func (n *ExprGEQ) SourceFile() *SourceFile
type ExprGTR ¶
ExprGTR represents LHS > RHS.
func (*ExprGTR) SourceFile ¶
func (n *ExprGTR) SourceFile() *SourceFile
type ExprLAND ¶
ExprLAND represents LHS && RHS.
func (*ExprLAND) SourceFile ¶
func (n *ExprLAND) SourceFile() *SourceFile
type ExprLEQ ¶
ExprLEQ represents LHS <= RHS.
func (*ExprLEQ) SourceFile ¶
func (n *ExprLEQ) SourceFile() *SourceFile
type ExprLOR ¶
ExprLOR represents LHS || RHS.
func (*ExprLOR) SourceFile ¶
func (n *ExprLOR) SourceFile() *SourceFile
type ExprLSS ¶
ExprLSS represents LHS < RHS.
func (*ExprLSS) SourceFile ¶
func (n *ExprLSS) SourceFile() *SourceFile
type ExprMUL ¶
ExprMUL represents LHS * RHS.
func (*ExprMUL) SourceFile ¶
func (n *ExprMUL) SourceFile() *SourceFile
type ExprNEQ ¶
ExprNEQ represents LHS != RHS.
func (*ExprNEQ) SourceFile ¶
func (n *ExprNEQ) SourceFile() *SourceFile
type ExprOR ¶
ExprOR represents LHS | RHS.
func (*ExprOR) SourceFile ¶
func (n *ExprOR) SourceFile() *SourceFile
type ExprOrType ¶
type ExprOrType interface { Position() token.Position Type() Type // contains filtered or unexported methods }
ExprOrType represents data reduced by productions
exprOrType: expr | nonExprType %prec _PreferToRightParen
Example (Expr) ¶
example(&ExprOrTypeExpr{}, "var v = foo(42)")
Output: 0: &gc.ExprOrTypeExpr{ · Expr: &gc.PrimaryExprIntLiteral{ · · Literal: 2:13: "42", · }, },
Example (Type) ¶
example(&ExprOrTypeType{}, "var v = make([]int, 42)")
Output: 0: &gc.ExprOrTypeType{ },
type ExprOrTypeExpr ¶
type ExprOrTypeExpr struct { Expr Expr // contains filtered or unexported fields }
ExprOrTypeExpr is an ExprOrType.
func (*ExprOrTypeExpr) Position ¶
func (n *ExprOrTypeExpr) Position() token.Position
Position implemenst Expr.
type ExprOrTypeType ¶
type ExprOrTypeType struct {
// contains filtered or unexported fields
}
ExprOrTypeType is an ExprOrType.
type ExprQUO ¶
ExprQUO represents LHS / RHS.
func (*ExprQUO) SourceFile ¶
func (n *ExprQUO) SourceFile() *SourceFile
type ExprREM ¶
ExprREM represents LHS % RHS.
func (*ExprREM) SourceFile ¶
func (n *ExprREM) SourceFile() *SourceFile
type ExprSHL ¶
ExprSHL represents LHS << RHS.
func (*ExprSHL) SourceFile ¶
func (n *ExprSHL) SourceFile() *SourceFile
type ExprSHR ¶
ExprSHR represents LHS >> RHS.
func (*ExprSHR) SourceFile ¶
func (n *ExprSHR) SourceFile() *SourceFile
type ExprSUB ¶
ExprSUB represents LHS - RHS.
func (*ExprSUB) SourceFile ¶
func (n *ExprSUB) SourceFile() *SourceFile
type ExprXOR ¶
ExprXOR represents LHS 6 RHS.
func (*ExprXOR) SourceFile ¶
func (n *ExprXOR) SourceFile() *SourceFile
type FieldDeclaration ¶
type FieldDeclaration interface {
// contains filtered or unexported methods
}
FieldDeclaration represents data reduced by productions
fieldDecl: '*' embeddedName literalOpt | identList typ literalOpt | embeddedName literalOpt
Example (Embedded) ¶
example(&FieldDeclarationEmbedded{}, "type T struct { io.Reader }")
Output: 0: &gc.FieldDeclarationEmbedded{ · Type: &gc.QualifiedNamedType{ · · Qualifier: "io", · · Name: "Reader", · }, },
Example (EmbeddedPtr) ¶
example(&FieldDeclarationEmbedded{}, "type T struct { *int }")
Output: 0: &gc.FieldDeclarationEmbedded{ · Type: &gc.PointerType{ · · Element: &gc.NamedType{ · · · Name: "int", · · }, · }, · Ptr: true, },
Example (Named) ¶
example(&FieldDeclarationNamed{}, "type T struct { i int }")
Output: 0: &gc.FieldDeclarationNamed{ · Name: 2:17: "i", · Type: &gc.NamedType{ · · Name: "int", · }, },
type FieldDeclarationEmbedded ¶
type FieldDeclarationEmbedded struct { Type Type Tag string Ptr bool // contains filtered or unexported fields }
FieldDeclarationEmbedded is a FieldDeclaration.
type FieldDeclarationNamed ¶
type FieldDeclarationNamed struct { Name Token Type Type Tag string // contains filtered or unexported fields }
FieldDeclarationNamed is a FieldDeclaration.
type FuncDecl ¶
type FuncDecl struct { Body *StmtBlock // contains filtered or unexported fields }
FuncDecl describes a function declaration.
func (*FuncDecl) Visibility ¶
Visibility implements Declaration.
type FunctionType ¶
type FunctionType struct { ParameterList ParamTypeList ResultList ParamTypeList Variadic bool // contains filtered or unexported fields }
FunctionType represents 'func(Params) Result'.
Example ¶
example(&FunctionType{}, "type T func(int, string) float64")
Output: &gc.FunctionType{ · ParameterList: &gc.ParamTypeListType{ · · List: []*gc.ParamTypeType{ // len 2 · · · 0: &gc.ParamTypeType{ · · · · Type: &gc.NamedType{ · · · · · Name: "int", · · · · }, · · · }, · · · 1: &gc.ParamTypeType{ · · · · Type: &gc.NamedType{ · · · · · Name: "string", · · · · }, · · · }, · · }, · }, · ResultList: &gc.ParamTypeListType{ · · List: []*gc.ParamTypeType{ // len 1 · · · 0: &gc.ParamTypeType{ · · · · Type: &gc.NamedType{ · · · · · Name: "float64", · · · · }, · · · }, · · }, · }, }
func (*FunctionType) AssignableTo ¶
func (*FunctionType) ComparableWith ¶
func (*FunctionType) Implements ¶
func (*FunctionType) Kind ¶
func (n *FunctionType) Kind() TypeKind
func (*FunctionType) Parameters ¶
func (n *FunctionType) Parameters() Type
Parameters returns the TupleType corresponding to n.ParametersList
func (*FunctionType) Result ¶
func (n *FunctionType) Result() Type
Result returns n's ResultList type as a TupleType or a non-tuple type if n has exactly one result.
func (*FunctionType) String ¶
func (n *FunctionType) String() (r string)
func (*FunctionType) UnderlyingType ¶
func (n *FunctionType) UnderlyingType() Type
type Ident ¶
type Ident struct { Token // contains filtered or unexported fields }
Ident represents an identifier and its resolution scope
func (*Ident) SourceFile ¶
func (n *Ident) SourceFile() *SourceFile
type IfHeader ¶
type IfHeader interface {
// contains filtered or unexported methods
}
IfHeader represents data reduced by productions
ifHeader: simpleStmtOpt | simpleStmtOpt ';' simpleStmtOpt
Example (Assign) ¶
example(&IfHeader2{}, "func foo() { if x = y; z {} }")
Output: IfHeader: &gc.IfHeader2{ · Stmt: &gc.SimpleStmtAssignment{ · · LHS: []*gc.PrimaryExprIdent{ // len 1 · · · 0: &gc.PrimaryExprIdent{ · · · · Ident: 2:17: "x", · · · }, · · }, · · RHS: []*gc.PrimaryExprIdent{ // len 1 · · · 0: &gc.PrimaryExprIdent{ · · · · Ident: 2:21: "y", · · · }, · · }, · }, · Stmt2: &gc.SimpleStmtExpr{ · · Expr: &gc.PrimaryExprIdent{ · · · Ident: 2:24: "z", · · }, · }, },
Example (Define) ¶
example(&IfHeader2{}, "func foo() { if x := y; z {} }")
Output: IfHeader: &gc.IfHeader2{ · Stmt: &gc.SimpleStmtDefine{ · · LHS: []*gc.PrimaryExprIdent{ // len 1 · · · 0: &gc.PrimaryExprIdent{ · · · · Ident: 2:17: "x", · · · }, · · }, · · RHS: []*gc.PrimaryExprIdent{ // len 1 · · · 0: &gc.PrimaryExprIdent{ · · · · Ident: 2:22: "y", · · · }, · · }, · }, · Stmt2: &gc.SimpleStmtExpr{ · · Expr: &gc.PrimaryExprIdent{ · · · Ident: 2:25: "z", · · }, · }, },
Example (Simple) ¶
example(&IfHeader1{}, "func foo() { if x {} }")
Output: IfHeader: &gc.IfHeader1{ · Stmt: &gc.SimpleStmtExpr{ · · Expr: &gc.PrimaryExprIdent{ · · · Ident: 2:17: "x", · · }, · }, },
type IfHeader1 ¶
type IfHeader1 struct { Stmt SimpleStmt // contains filtered or unexported fields }
IfHeader1 describes if foo() ...
type IfHeader2 ¶
type IfHeader2 struct { Stmt SimpleStmt Stmt2 SimpleStmt // contains filtered or unexported fields }
IfHeader2 describes if x := foo(); x > 3 ...
type ImportDecl ¶
type ImportDecl struct { ImportPath string // `foo/bar` in `import "foo/bar"` Qualifier string // `baz` in `import baz "foo/bar"`. Dot bool // The `import . "foo/bar"` variant is used. // contains filtered or unexported fields }
ImportDecl is an import declaration.
func (*ImportDecl) ImportSpec ¶
func (n *ImportDecl) ImportSpec() *ImportDecl
ImportSpec implements Declaration.
func (*ImportDecl) Package ¶
func (d *ImportDecl) Package() *Package
func (*ImportDecl) Visibility ¶
Visibility implements Declaration.
type InterfaceType ¶
type InterfaceType struct { Embedded []Type Methods map[string]*FunctionType // contains filtered or unexported fields }
InterfaceType represents 'interface{...}'.
Example ¶
example(&InterfaceType{}, "type T interface{ m(int) string }")
Output: &gc.InterfaceType{ · Methods: map[string]*gc.FunctionType{ · · "m": &gc.FunctionType{ · · · ParameterList: &gc.ParamTypeListType{ · · · · List: []*gc.ParamTypeType{ // len 1 · · · · · 0: &gc.ParamTypeType{ · · · · · · Type: &gc.NamedType{ · · · · · · · Name: "int", · · · · · · }, · · · · · }, · · · · }, · · · }, · · · ResultList: &gc.ParamTypeListType{ · · · · List: []*gc.ParamTypeType{ // len 1 · · · · · 0: &gc.ParamTypeType{ · · · · · · Type: &gc.NamedType{ · · · · · · · Name: "string", · · · · · · }, · · · · · }, · · · · }, · · · }, · · }, · }, }
func (*InterfaceType) AssignableTo ¶
func (*InterfaceType) ComparableWith ¶
func (*InterfaceType) Implements ¶
func (*InterfaceType) Kind ¶
func (n *InterfaceType) Kind() TypeKind
func (*InterfaceType) String ¶
func (n *InterfaceType) String() string
func (*InterfaceType) UnderlyingType ¶
func (n *InterfaceType) UnderlyingType() Type
type InvalidValue ¶
type InvalidValue struct {
// contains filtered or unexported fields
}
InvalidValue represents an invalidValue.
type KeyVal ¶
type KeyVal interface {
// contains filtered or unexported methods
}
KeyVal represents data reduced by productions
keyVal: compLitExpr | compLitExpr ':' compLitExpr
Example (Expr) ¶
example(&KeyValExpr{}, "var v = []int{42}")
Output: 0: &gc.KeyValExpr{ · Expr: &gc.CompLitExprExpr{ · · Expr: &gc.PrimaryExprIntLiteral{ · · · Literal: 2:15: "42", · · }, · }, },
Example (KeyedExpr) ¶
example(&KeyValKeyedExpr{}, "var v = []int{1: 42}")
Output: 0: &gc.KeyValKeyedExpr{ · Key: &gc.CompLitExprExpr{ · · Expr: &gc.PrimaryExprIntLiteral{ · · · Literal: 2:15: "1", · · }, · }, · Expr: &gc.CompLitExprExpr{ · · Expr: &gc.PrimaryExprIntLiteral{ · · · Literal: 2:18: "42", · · }, · }, },
type KeyValExpr ¶
type KeyValExpr struct { Expr CompLitExpr // contains filtered or unexported fields }
KeyValExpr is a KeyVal
type KeyValKeyedExpr ¶
type KeyValKeyedExpr struct { Key CompLitExpr Expr CompLitExpr // contains filtered or unexported fields }
KeyValKeyedExpr is a KeyVal
type MapType ¶
MapType represents 'map[Key]Value'.
Example ¶
example(&MapType{}, "type T map[int]string")
Output: &gc.MapType{ · Key: &gc.NamedType{ · · Name: "int", · }, · Value: &gc.NamedType{ · · Name: "string", · }, }
func (*MapType) AssignableTo ¶
func (*MapType) ComparableWith ¶
func (*MapType) Implements ¶
func (*MapType) UnderlyingType ¶
func (n *MapType) UnderlyingType() Type
type MethodDecl ¶
MethodDecl describes a method declaration.
func (*MethodDecl) IsPtrReceiver ¶
func (d *MethodDecl) IsPtrReceiver() bool
IsPtrReceiver reports whether d's receiver is a pointer.
func (*MethodDecl) Visibility ¶
Visibility implements Declaration.
type NamedType ¶
type NamedType struct { Name string // contains filtered or unexported fields }
NamedType represents 'identifier type'.
Example ¶
example(&NamedType{}, "type T int")
Output: &gc.NamedType{ · Name: "int", }
func (*NamedType) AssignableTo ¶
func (*NamedType) ComparableWith ¶
func (*NamedType) Declaration ¶
Declaration returns the declaration of n.
func (*NamedType) Implements ¶
func (*NamedType) UnderlyingType ¶
UnderlyingType implements Type.
type Node ¶
type Node interface { Package() *Package Position() token.Position SourceFile() *SourceFile String() string // contains filtered or unexported methods }
type Option ¶
Option amends Context.
func IgnoreRedeclarations ¶
func IgnoreRedeclarations() Option
IgnoreRedeclarations disables reporting redeclarations as errors.
func LocalImportsPath ¶
LocalImportsPath sets the relative path for local imports.
func NoErrorColumns ¶
func NoErrorColumns() Option
NoErrorColumns disable displaying of columns in error messages.
func NoErrorLimit ¶
func NoErrorLimit() Option
NoErrorLimit disables limit on number of errors reported.
type Package ¶
type Package struct { Dir string ImportPath string ImportedBy map[string]struct{} // import path: struct{}. Imports map[string]struct{} // import path: struct{}. Methods map[string]Bindings // receiver name: *MethodDecl Name string Scope *Scope // Package scope. SourceFiles []*SourceFile // contains filtered or unexported fields }
Package describes a package.
type ParamType ¶
type ParamType interface {
// contains filtered or unexported methods
}
ParamType represents data reduced by productions
paramType: IDENT dddType | IDENT typ | dddType | typ
Example (IdentType) ¶
example(&ParamTypeIdentType{}, "func foo(a int)")
Output: 0: &gc.ParamTypeIdentType{ · Ident: 2:10: "a", · Type: &gc.NamedType{ · · Name: "int", · }, },
Example (Type) ¶
example(&ParamTypeType{}, "func foo(int)")
Output: 0: &gc.ParamTypeType{ · Type: &gc.NamedType{ · · Name: "int", · }, },
type ParamTypeIdentType ¶
type ParamTypeIdentType struct { Ident Token Type Type Variadic bool // contains filtered or unexported fields }
ParamTypeIdentType is a ParamType that includes the name of the parameter.
type ParamTypeList ¶
type ParamTypeList interface {
// contains filtered or unexported methods
}
ParamTypeList represents data reduced by productions
paramTypeList: paramType | paramTypeList ',' paramType
Example (IdentType) ¶
example(ParamTypeListIdentType{}, "func foo(i int, s string)")
Output: ParameterList: &gc.ParamTypeListIdentType{ · List: []*gc.ParamTypeIdentType{ // len 2 · · 0: &gc.ParamTypeIdentType{ · · · Ident: 2:10: "i", · · · Type: &gc.NamedType{ · · · · Name: "int", · · · }, · · }, · · 1: &gc.ParamTypeIdentType{ · · · Ident: 2:17: "s", · · · Type: &gc.NamedType{ · · · · Name: "string", · · · }, · · }, · }, },
Example (Type) ¶
example(ParamTypeListType{}, "func foo(int, string)")
Output: ParameterList: &gc.ParamTypeListType{ · List: []*gc.ParamTypeType{ // len 2 · · 0: &gc.ParamTypeType{ · · · Type: &gc.NamedType{ · · · · Name: "int", · · · }, · · }, · · 1: &gc.ParamTypeType{ · · · Type: &gc.NamedType{ · · · · Name: "string", · · · }, · · }, · }, },
type ParamTypeListIdentType ¶
type ParamTypeListIdentType struct { List []*ParamTypeIdentType // contains filtered or unexported fields }
ParamTypeListIdentType is a ParamTypeList of ParamTypeIdentType
type ParamTypeListType ¶
type ParamTypeListType struct { List []*ParamTypeType // contains filtered or unexported fields }
ParamTypeListType is a ParamTypeList of ParamTypeType
type ParamTypeType ¶
ParamTypeType is a ParamType without a name of the parameter.
type PointerType ¶
type PointerType struct { Element Type // contains filtered or unexported fields }
PointerType represents '*Element'.
Example ¶
example(&PointerType{}, "type T *int")
Output: &gc.PointerType{ · Element: &gc.NamedType{ · · Name: "int", · }, }
func (*PointerType) AssignableTo ¶
func (*PointerType) ComparableWith ¶
func (*PointerType) Implements ¶
func (*PointerType) Kind ¶
func (n *PointerType) Kind() TypeKind
func (*PointerType) String ¶
func (n *PointerType) String() string
func (*PointerType) UnderlyingType ¶
func (n *PointerType) UnderlyingType() Type
type PrimaryExpr ¶
type PrimaryExpr Expr
PrimaryExpr represents data reduced by productions
primaryExpr: '(' exprOrType ')' | IDENT genericArgsOpt %prec _NotParen | convType '(' expr commaOpt ')' | fnType lbrace stmtList '}' | literal | otherType lbrace bracedKeyValList '}' | primaryExpr '(' ')' | primaryExpr '(' exprOrTypeList "..." commaOpt ')' | primaryExpr '(' exprOrTypeList commaOpt ')' | primaryExpr '.' '(' "type" ')' | primaryExpr '.' '(' exprOrType ')' | primaryExpr '.' IDENT | primaryExpr '[' expr ']' | primaryExpr '[' exprOpt ':' exprOpt ':' exprOpt ']' | primaryExpr '[' exprOpt ':' exprOpt ']' | primaryExpr '{' bracedKeyValList '}'
Example (Call) ¶
example(&PrimaryExprCall{}, "var v = foo(42)")
Output: Initializer: &gc.PrimaryExprCall{ · PrimaryExpr: &gc.PrimaryExprIdent{ · · Ident: 2:9: "foo", · }, · Args: []*gc.ExprOrTypeExpr{ // len 1 · · 0: &gc.ExprOrTypeExpr{ · · · Expr: &gc.PrimaryExprIntLiteral{ · · · · Literal: 2:13: "42", · · · }, · · }, · }, },
Example (CompositeLiteral) ¶
example(&PrimaryExprCompositeLiteral{}, "var v = []int{42}")
Output: Initializer: &gc.PrimaryExprCompositeLiteral{ · List: []*gc.KeyValExpr{ // len 1 · · 0: &gc.KeyValExpr{ · · · Expr: &gc.CompLitExprExpr{ · · · · Expr: &gc.PrimaryExprIntLiteral{ · · · · · Literal: 2:15: "42", · · · · }, · · · }, · · }, · }, },
Example (Conversion) ¶
example(&PrimaryExprConversion{}, "var v = ([]byte)(nil)")
Output: Initializer: &gc.PrimaryExprConversion{ · Expr: &gc.PrimaryExprIdent{ · · Ident: 2:18: "nil", · }, },
Example (FloatLiteral) ¶
example(&PrimaryExprFloatLiteral{}, "var v = 42.314")
Output: Initializer: &gc.PrimaryExprFloatLiteral{ · Literal: 2:9: "42.314", },
Example (FullSlice) ¶
example(&PrimaryExprFullSlice{}, "var v = foo[24:42:314]")
Output: Initializer: &gc.PrimaryExprFullSlice{ · PrimaryExpr: &gc.PrimaryExprIdent{ · · Ident: 2:9: "foo", · }, · Lo: &gc.PrimaryExprIntLiteral{ · · Literal: 2:13: "24", · }, · Hi: &gc.PrimaryExprIntLiteral{ · · Literal: 2:16: "42", · }, · Max: &gc.PrimaryExprIntLiteral{ · · Literal: 2:19: "314", · }, },
Example (FuncLiteral) ¶
example(&PrimaryExprFuncLiteral{}, "var v = func(){}")
Output: Initializer: &gc.PrimaryExprFuncLiteral{ · Body: &gc.StmtBlock{ · }, },
Example (Ident) ¶
example(&PrimaryExprIdent{}, "var v = foo")
Output: Initializer: &gc.PrimaryExprIdent{ · Ident: 2:9: "foo", },
Example (ImagLiteral) ¶
example(&PrimaryExprImagLiteral{}, "var v = 42i")
Output: Initializer: &gc.PrimaryExprImagLiteral{ · Literal: 2:9: "42i", },
Example (Index) ¶
example(&PrimaryExprIndex{}, "var v = foo[42]")
Output: Initializer: &gc.PrimaryExprIndex{ · PrimaryExpr: &gc.PrimaryExprIdent{ · · Ident: 2:9: "foo", · }, · Index: &gc.PrimaryExprIntLiteral{ · · Literal: 2:13: "42", · }, },
Example (IntLiteral) ¶
example(&PrimaryExprIntLiteral{}, "var v = 42")
Output: Initializer: &gc.PrimaryExprIntLiteral{ · Literal: 2:9: "42", },
Example (ParenExpr) ¶
example(&PrimaryExprParenExpr{}, "var v = (42)")
Output: Initializer: &gc.PrimaryExprParenExpr{ · Expr: &gc.PrimaryExprIntLiteral{ · · Literal: 2:10: "42", · }, },
Example (RuneLiteral) ¶
example(&PrimaryExprRuneLiteral{}, "var v = 'a'")
Output: Initializer: &gc.PrimaryExprRuneLiteral{ · Literal: 2:9: "'a'", },
Example (Selector) ¶
example(&PrimaryExprSelector{}, "var v = foo().bar")
Output: Initializer: &gc.PrimaryExprSelector{ · PrimaryExpr: &gc.PrimaryExprCall{ · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · Ident: 2:9: "foo", · · }, · }, · Selector: 2:15: "bar", },
Example (SimpleSlice) ¶
example(&PrimaryExprSimpleSlice{}, "var v = foo[24:42]")
Output: Initializer: &gc.PrimaryExprSimpleSlice{ · PrimaryExpr: &gc.PrimaryExprIdent{ · · Ident: 2:9: "foo", · }, · Lo: &gc.PrimaryExprIntLiteral{ · · Literal: 2:13: "24", · }, · Hi: &gc.PrimaryExprIntLiteral{ · · Literal: 2:16: "42", · }, },
Example (StringLiteral) ¶
example(&PrimaryExprStringLiteral{}, `var v = "foo"`)
Output: Initializer: &gc.PrimaryExprStringLiteral{ · Literal: 2:9: "\"foo\"", },
Example (TypeAssertion) ¶
example(&PrimaryExprTypeAssertion{}, "var v, ok = foo.(int)")
Output: Initializer: &gc.PrimaryExprTypeAssertion{ · PrimaryExpr: &gc.PrimaryExprIdent{ · · Ident: 2:13: "foo", · }, · Assert: &gc.ExprOrTypeExpr{ · · Expr: &gc.PrimaryExprIdent{ · · · Ident: 2:18: "int", · · }, · }, },
Example (TypeSwitchGuard) ¶
example(&PrimaryExprTypeSwitchGuard{}, ` func foo(x interface{}) { switch x.(type) { case []int: foo() case [42]string: bar() default: qux() } } `)
Output: Expr: &gc.PrimaryExprTypeSwitchGuard{ · PrimaryExpr: &gc.PrimaryExprIdent{ · · Ident: 4:9: "x", · }, },
type PrimaryExprCall ¶
type PrimaryExprCall struct { PrimaryExpr Expr Args []ExprOrType DDD bool IsConversion bool // contains filtered or unexported fields }
PrimaryExprCall is an Expr.
func (*PrimaryExprCall) SourceFile ¶
func (n *PrimaryExprCall) SourceFile() *SourceFile
type PrimaryExprCompositeLiteral ¶
type PrimaryExprCompositeLiteral struct { List []KeyVal // contains filtered or unexported fields }
PrimaryExprCompositeLiteral is an Expr.
func (*PrimaryExprCompositeLiteral) Package ¶
func (n *PrimaryExprCompositeLiteral) Package() *Package
func (*PrimaryExprCompositeLiteral) SourceFile ¶
func (n *PrimaryExprCompositeLiteral) SourceFile() *SourceFile
type PrimaryExprConversion ¶
type PrimaryExprConversion struct { Expr Expr // contains filtered or unexported fields }
PrimaryExprConversion is an Expr.
func (*PrimaryExprConversion) SourceFile ¶
func (n *PrimaryExprConversion) SourceFile() *SourceFile
type PrimaryExprFloatLiteral ¶
type PrimaryExprFloatLiteral struct { Literal Token // contains filtered or unexported fields }
PrimaryExprFloatLiteral is an Expr.
func (*PrimaryExprFloatLiteral) Position ¶
func (n *PrimaryExprFloatLiteral) Position() token.Position
Position implemenst Expr.
type PrimaryExprFullSlice ¶
type PrimaryExprFullSlice struct { PrimaryExpr Expr Lo Expr Hi Expr Max Expr // contains filtered or unexported fields }
PrimaryExprFullSlice is an Expr.
func (*PrimaryExprFullSlice) SourceFile ¶
func (n *PrimaryExprFullSlice) SourceFile() *SourceFile
type PrimaryExprFuncLiteral ¶
type PrimaryExprFuncLiteral struct { Body *StmtBlock // contains filtered or unexported fields }
PrimaryExprFuncLiteral is an Expr.
func (*PrimaryExprFuncLiteral) SourceFile ¶
func (n *PrimaryExprFuncLiteral) SourceFile() *SourceFile
type PrimaryExprIdent ¶
type PrimaryExprIdent struct { Ident Ident // contains filtered or unexported fields }
PrimaryExprIdent is an Expr.
func (*PrimaryExprIdent) Position ¶
func (n *PrimaryExprIdent) Position() token.Position
Position implemenst Expr.
type PrimaryExprImagLiteral ¶
type PrimaryExprImagLiteral struct { Literal Token // contains filtered or unexported fields }
PrimaryExprImagLiteral is an Expr.
func (*PrimaryExprImagLiteral) Position ¶
func (n *PrimaryExprImagLiteral) Position() token.Position
Position implemenst Expr.
type PrimaryExprIndex ¶
type PrimaryExprIndex struct { PrimaryExpr Expr Index Expr // contains filtered or unexported fields }
PrimaryExprIndex is an Expr.
func (*PrimaryExprIndex) SourceFile ¶
func (n *PrimaryExprIndex) SourceFile() *SourceFile
type PrimaryExprIntLiteral ¶
type PrimaryExprIntLiteral struct { Literal Token // contains filtered or unexported fields }
PrimaryExprIntLiteral is an Expr.
func (*PrimaryExprIntLiteral) Position ¶
func (n *PrimaryExprIntLiteral) Position() token.Position
Position implemenst Expr.
type PrimaryExprParenExpr ¶
type PrimaryExprParenExpr struct { Expr Expr // contains filtered or unexported fields }
PrimaryExprParenExpr is an Expr.
func (*PrimaryExprParenExpr) SourceFile ¶
func (n *PrimaryExprParenExpr) SourceFile() *SourceFile
type PrimaryExprRuneLiteral ¶
type PrimaryExprRuneLiteral struct { Literal Token // contains filtered or unexported fields }
PrimaryExprRuneLiteral is an Expr.
func (*PrimaryExprRuneLiteral) Position ¶
func (n *PrimaryExprRuneLiteral) Position() token.Position
Position implemenst Expr.
type PrimaryExprSelector ¶
type PrimaryExprSelector struct { PrimaryExpr Expr Selector Ident Declaration Declaration // Non-nil if the selector denotes a declaration. // contains filtered or unexported fields }
PrimaryExprSelector is an Expr.
func (*PrimaryExprSelector) SourceFile ¶
func (n *PrimaryExprSelector) SourceFile() *SourceFile
type PrimaryExprSimpleSlice ¶
type PrimaryExprSimpleSlice struct { PrimaryExpr Expr Lo Expr Hi Expr // contains filtered or unexported fields }
PrimaryExprSimpleSlice is an Expr.
func (*PrimaryExprSimpleSlice) SourceFile ¶
func (n *PrimaryExprSimpleSlice) SourceFile() *SourceFile
type PrimaryExprStringLiteral ¶
type PrimaryExprStringLiteral struct { Literal Token // contains filtered or unexported fields }
PrimaryExprStringLiteral is an Expr.
func (*PrimaryExprStringLiteral) Position ¶
func (n *PrimaryExprStringLiteral) Position() token.Position
Position implemenst Expr.
type PrimaryExprTypeAssertion ¶
type PrimaryExprTypeAssertion struct { PrimaryExpr Expr Assert ExprOrType // contains filtered or unexported fields }
PrimaryExprTypeAssertion is an Expr.
func (*PrimaryExprTypeAssertion) SourceFile ¶
func (n *PrimaryExprTypeAssertion) SourceFile() *SourceFile
type PrimaryExprTypeSwitchGuard ¶
type PrimaryExprTypeSwitchGuard struct { PrimaryExpr Expr // contains filtered or unexported fields }
PrimaryExprTypeSwitchGuard is an Expr.
func (*PrimaryExprTypeSwitchGuard) Package ¶
func (n *PrimaryExprTypeSwitchGuard) Package() *Package
func (*PrimaryExprTypeSwitchGuard) SourceFile ¶
func (n *PrimaryExprTypeSwitchGuard) SourceFile() *SourceFile
type QualifiedNamedType ¶
type QualifiedNamedType struct { Qualifier string Name string // contains filtered or unexported fields }
QualifiedNamedType represents 'qualifier.identifier'.
Example ¶
example(&QualifiedNamedType{}, "type T foo.Bar")
Output: &gc.QualifiedNamedType{ · Qualifier: "foo", · Name: "Bar", }
func (*QualifiedNamedType) AssignableTo ¶
func (*QualifiedNamedType) ComparableWith ¶
func (*QualifiedNamedType) Declaration ¶
func (n *QualifiedNamedType) Declaration() *TypeDecl
Declaration returns the declaration of n.
func (*QualifiedNamedType) Implements ¶
func (*QualifiedNamedType) IsDefined ¶
func (n *QualifiedNamedType) IsDefined() bool
IsDefined implements Type.
func (*QualifiedNamedType) Kind ¶
func (n *QualifiedNamedType) Kind() TypeKind
func (*QualifiedNamedType) Scope ¶
func (n *QualifiedNamedType) Scope() *Scope
func (*QualifiedNamedType) String ¶
func (n *QualifiedNamedType) String() string
func (*QualifiedNamedType) Type ¶
func (n *QualifiedNamedType) Type() Type
Type returns U in type T U.
func (*QualifiedNamedType) UnderlyingType ¶
func (n *QualifiedNamedType) UnderlyingType() Type
UnderlyingType implements Type.
type Scope ¶
type Scope struct { Bindings Bindings Kind ScopeKind Labels Bindings Parent *Scope Unbound []Declaration // Declarations named _. TODO needed? // contains filtered or unexported fields }
Scope tracks declarations.
type SimpleStmt ¶
type SimpleStmt Stmt
SimpleStmt represents data reduced by productions
simpleStmt: expr | expr "%=" expr | expr "&=" expr | expr "&^=" expr | expr "*=" expr | expr "++" | expr "+=" expr | expr "--" | expr "-=" expr | expr "/=" expr | expr "<<=" expr | expr ">>=" expr | expr "^=" expr | expr "|=" expr | exprList ":=" exprList | exprList '=' exprList
Example (AddAssign) ¶
example(&SimpleStmtAddAssign{}, "func foo() { a += b }")
Output: 0: &gc.SimpleStmtAddAssign{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:19: "b", · }, },
Example (AndAssign) ¶
example(&SimpleStmtAndAssign{}, "func foo() { a &= b }")
Output: 0: &gc.SimpleStmtAndAssign{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:19: "b", · }, },
Example (AndNotAssign) ¶
example(&SimpleStmtAndNotAssign{}, "func foo() { a &^= b }")
Output: 0: &gc.SimpleStmtAndNotAssign{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:20: "b", · }, },
Example (Assignment) ¶
example(&SimpleStmtAssignment{}, "func foo() { a, b = c, d }")
Output: 0: &gc.SimpleStmtAssignment{ · LHS: []*gc.PrimaryExprIdent{ // len 2 · · 0: &gc.PrimaryExprIdent{ · · · Ident: 2:14: "a", · · }, · · 1: &gc.PrimaryExprIdent{ · · · Ident: 2:17: "b", · · }, · }, · RHS: []*gc.PrimaryExprIdent{ // len 2 · · 0: &gc.PrimaryExprIdent{ · · · Ident: 2:21: "c", · · }, · · 1: &gc.PrimaryExprIdent{ · · · Ident: 2:24: "d", · · }, · }, },
Example (Assingnment) ¶
example(&SimpleStmtAssignment{}, "func foo() { a, b = c, d }")
Output: 0: &gc.SimpleStmtAssignment{ · LHS: []*gc.PrimaryExprIdent{ // len 2 · · 0: &gc.PrimaryExprIdent{ · · · Ident: 2:14: "a", · · }, · · 1: &gc.PrimaryExprIdent{ · · · Ident: 2:17: "b", · · }, · }, · RHS: []*gc.PrimaryExprIdent{ // len 2 · · 0: &gc.PrimaryExprIdent{ · · · Ident: 2:21: "c", · · }, · · 1: &gc.PrimaryExprIdent{ · · · Ident: 2:24: "d", · · }, · }, },
Example (Dec) ¶
example(&SimpleStmtDec{}, "func foo() { a-- }")
Output: 0: &gc.SimpleStmtDec{ · Expr: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, },
Example (Decl) ¶
example(&SimpleStmtDecl{}, "func foo() { var a, b int }")
Output: 0: &gc.SimpleStmtDecl{ · List: []*gc.VarDecl{ // len 2 · · 0: &gc.VarDecl{ · · }, · · 1: &gc.VarDecl{ · · }, · }, },
Example (Define) ¶
example(&SimpleStmtDefine{}, "func foo() { a, b := c, d }")
Output: 0: &gc.SimpleStmtDefine{ · LHS: []*gc.PrimaryExprIdent{ // len 2 · · 0: &gc.PrimaryExprIdent{ · · · Ident: 2:14: "a", · · }, · · 1: &gc.PrimaryExprIdent{ · · · Ident: 2:17: "b", · · }, · }, · RHS: []*gc.PrimaryExprIdent{ // len 2 · · 0: &gc.PrimaryExprIdent{ · · · Ident: 2:22: "c", · · }, · · 1: &gc.PrimaryExprIdent{ · · · Ident: 2:25: "d", · · }, · }, },
Example (Expr) ¶
example(&SimpleStmtExpr{}, "func foo() { bar() }")
Output: 0: &gc.SimpleStmtExpr{ · Expr: &gc.PrimaryExprCall{ · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · Ident: 2:14: "bar", · · }, · }, },
Example (Inc) ¶
example(&SimpleStmtInc{}, "func foo() { a++ }")
Output: 0: &gc.SimpleStmtInc{ · Expr: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, },
Example (MulAssign) ¶
example(&SimpleStmtMulAssign{}, "func foo() { a *= b }")
Output: 0: &gc.SimpleStmtMulAssign{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:19: "b", · }, },
Example (OrAssign) ¶
example(&SimpleStmtOrAssign{}, "func foo() { a |= b }")
Output: 0: &gc.SimpleStmtOrAssign{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:19: "b", · }, },
Example (QuoAssign) ¶
example(&SimpleStmtQuoAssign{}, "func foo() { a /= b }")
Output: 0: &gc.SimpleStmtQuoAssign{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:19: "b", · }, },
Example (RemAssign) ¶
example(&SimpleStmtRemAssign{}, "func foo() { a %= b }")
Output: 0: &gc.SimpleStmtRemAssign{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:19: "b", · }, },
Example (Send) ¶
example(&SimpleStmtSend{}, "func f() { a <- b }")
Output: 0: &gc.SimpleStmtSend{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:12: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:17: "b", · }, },
Example (ShlAssign) ¶
example(&SimpleStmtShlAssign{}, "func foo() { a <<= b }")
Output: 0: &gc.SimpleStmtShlAssign{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:20: "b", · }, },
Example (ShrAssign) ¶
example(&SimpleStmtShrAssign{}, "func foo() { a >>= b }")
Output: 0: &gc.SimpleStmtShrAssign{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:20: "b", · }, },
Example (SubAssign) ¶
example(&SimpleStmtSubAssign{}, "func foo() { a -= b }")
Output: 0: &gc.SimpleStmtSubAssign{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:19: "b", · }, },
Example (XorAssign) ¶
example(&SimpleStmtXorAssign{}, "func foo() { a ^= b }")
Output: 0: &gc.SimpleStmtXorAssign{ · LHS: &gc.PrimaryExprIdent{ · · Ident: 2:14: "a", · }, · RHS: &gc.PrimaryExprIdent{ · · Ident: 2:19: "b", · }, },
type SimpleStmtAddAssign ¶
SimpleStmtAddAssign describes expr += expr.
type SimpleStmtAndAssign ¶
SimpleStmtAndAssign describes expr &= expr.
type SimpleStmtAndNotAssign ¶
SimpleStmtAndNotAssign describes expr &^= expr.
type SimpleStmtAssignment ¶
type SimpleStmtAssignment struct { LHS []Expr RHS []Expr // contains filtered or unexported fields }
SimpleStmtAssignment describes exprList = exprList.
type SimpleStmtDec ¶
type SimpleStmtDec struct { Expr Expr // contains filtered or unexported fields }
SimpleStmtDec describes expr--.
type SimpleStmtDecl ¶
type SimpleStmtDecl struct { List []Declaration // contains filtered or unexported fields }
SimpleStmtDecl describes a list of declarations.
type SimpleStmtDefine ¶
SimpleStmtDefine describes exprList := exprList.
type SimpleStmtExpr ¶
type SimpleStmtExpr struct { Expr Expr // contains filtered or unexported fields }
SimpleStmtExpr describes an expresssion statement.
type SimpleStmtInc ¶
type SimpleStmtInc struct { Expr Expr // contains filtered or unexported fields }
SimpleStmtInc describes expr++.
type SimpleStmtMulAssign ¶
SimpleStmtMulAssign describes expr *= expr.
type SimpleStmtOrAssign ¶
SimpleStmtOrAssign describes expr |= expr.
type SimpleStmtQuoAssign ¶
SimpleStmtQuoAssign describes expr /= expr.
type SimpleStmtRemAssign ¶
SimpleStmtRemAssign describes expr %= expr.
type SimpleStmtSend ¶
SimpleStmtSend describes expr <- expr.
type SimpleStmtShlAssign ¶
SimpleStmtShlAssign describes expr <<= expr.
type SimpleStmtShrAssign ¶
SimpleStmtShrAssign describes expr >>= expr.
type SimpleStmtSubAssign ¶
SimpleStmtSubAssign describes expr -= expr.
type SimpleStmtXorAssign ¶
SimpleStmtXorAssign describes expr ^= expr.
type SliceType ¶
type SliceType struct { Element Type // contains filtered or unexported fields }
SliceType represents '[]Element'.
Example ¶
example(&SliceType{}, "type T []int")
Output: &gc.SliceType{ · Element: &gc.NamedType{ · · Name: "int", · }, }
func (*SliceType) AssignableTo ¶
func (*SliceType) ComparableWith ¶
func (*SliceType) Implements ¶
func (*SliceType) UnderlyingType ¶
func (n *SliceType) UnderlyingType() Type
type SourceFile ¶
type SourceFile struct { File *token.File ImportSpecs []*ImportDecl InitFunctions []Declaration Package *Package Path string Scope *Scope // File scope. TopLevelDecls []Declaration // contains filtered or unexported fields }
SourceFile describes a source file.
type Stmt ¶
type Stmt interface {
// contains filtered or unexported methods
}
Stmt represents data reduced by productions
stmt: | "break" identOpt | "continue" identOpt | "defer" primaryExpr | "fallthrough" | "for" "range" expr loopBody | "for" exprList ":=" "range" expr loopBody | "for" exprList '=' "range" expr loopBody | "for" simpleStmtOpt ';' simpleStmtOpt ';' simpleStmtOpt loopBody | "for" simpleStmtOpt loopBody | "go" primaryExpr | "goto" IDENT | "if" ifHeader loopBody elseIfList | "if" ifHeader loopBody elseIfList "else" compoundStmt | "return" | "return" exprList | "select" BODY caseBlockList '}' | "switch" ifHeader BODY caseBlockList '}' | IDENT ':' stmt | commonDecl | compoundStmt | simpleStmt
Example (Block) ¶
example(&StmtBlock{}, ` func foo() { { foo() bar() } } `)
Output: Body: &gc.StmtBlock{ · List: []*gc.StmtBlock{ // len 1 · · 0: &gc.StmtBlock{ · · · List: []*gc.SimpleStmtExpr{ // len 2 · · · · 0: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · Ident: 5:3: "foo", · · · · · · }, · · · · · }, · · · · }, · · · · 1: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · Ident: 6:3: "bar", · · · · · · }, · · · · · }, · · · · }, · · · }, · · }, · }, },
Example (Break) ¶
example(&StmtBreak{}, ` func foo() { out: for range expr { break out } } `)
Output: 0: &gc.StmtBreak{ · Label: 6:9: "out", },
Example (Continue) ¶
example(&StmtContinue{}, ` func foo() { next: for range expr { continue next } } `)
Output: 0: &gc.StmtContinue{ · Label: 6:12: "next", },
Example (Defer) ¶
example(&StmtDefer{}, "func foo() { defer bar() }")
Output: 0: &gc.StmtDefer{ · Expr: &gc.PrimaryExprCall{ · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · Ident: 2:20: "bar", · · }, · }, },
Example (Fallthrough) ¶
example(StmtFallthrough{}, ` func foo() { switch x { case 1: fallthrough default: } } `)
Output: Body: []*gc.StmtFallthrough{ // len 1 },
Example (For) ¶
example(&StmtFor{}, ` func foo() { for i := 0; i < 10; i++ { bar() } } `)
Output: 0: &gc.StmtFor{ · Stmt: &gc.SimpleStmtDefine{ · · LHS: []*gc.PrimaryExprIdent{ // len 1 · · · 0: &gc.PrimaryExprIdent{ · · · · Ident: 4:6: "i", · · · }, · · }, · · RHS: []*gc.PrimaryExprIntLiteral{ // len 1 · · · 0: &gc.PrimaryExprIntLiteral{ · · · · Literal: 4:11: "0", · · · }, · · }, · }, · Stmt2: &gc.SimpleStmtExpr{ · · Expr: &gc.ExprLSS{ · · · LHS: &gc.PrimaryExprIdent{ · · · · Ident: 4:14: "i", · · · }, · · · RHS: &gc.PrimaryExprIntLiteral{ · · · · Literal: 4:18: "10", · · · }, · · }, · }, · Stmt3: &gc.SimpleStmtInc{ · · Expr: &gc.PrimaryExprIdent{ · · · Ident: 4:22: "i", · · }, · }, · Body: &gc.StmtBlock{ · · List: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 5:3: "bar", · · · · · }, · · · · }, · · · }, · · }, · }, },
Example (ForRange) ¶
example(&StmtForRange{}, ` func foo() { for range expr { bar() } } `)
Output: 0: &gc.StmtForRange{ · Expr: &gc.PrimaryExprIdent{ · · Ident: 4:12: "expr", · }, · Body: &gc.StmtBlock{ · · List: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 5:3: "bar", · · · · · }, · · · · }, · · · }, · · }, · }, },
Example (ForRangeAssign) ¶
example(&StmtForRange{}, ` func foo() { for i, v = range expr { bar() } } `)
Output: 0: &gc.StmtForRange{ · ExprList: []*gc.PrimaryExprIdent{ // len 2 · · 0: &gc.PrimaryExprIdent{ · · · Ident: 4:6: "i", · · }, · · 1: &gc.PrimaryExprIdent{ · · · Ident: 4:9: "v", · · }, · }, · Expr: &gc.PrimaryExprIdent{ · · Ident: 4:19: "expr", · }, · Body: &gc.StmtBlock{ · · List: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 5:3: "bar", · · · · · }, · · · · }, · · · }, · · }, · }, },
Example (ForRangeDefine) ¶
example(&StmtForRange{}, ` func foo() { for i, v := range expr { bar() } } `)
Output: 0: &gc.StmtForRange{ · ExprList: []*gc.PrimaryExprIdent{ // len 2 · · 0: &gc.PrimaryExprIdent{ · · · Ident: 4:6: "i", · · }, · · 1: &gc.PrimaryExprIdent{ · · · Ident: 4:9: "v", · · }, · }, · Expr: &gc.PrimaryExprIdent{ · · Ident: 4:20: "expr", · }, · Body: &gc.StmtBlock{ · · List: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 5:3: "bar", · · · · · }, · · · · }, · · · }, · · }, · }, · Define: true, },
Example (Go) ¶
example(&StmtGo{}, "func foo() { go bar() }")
Output: 0: &gc.StmtGo{ · Expr: &gc.PrimaryExprCall{ · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · Ident: 2:17: "bar", · · }, · }, },
Example (Goto) ¶
example(&StmtGoto{}, "func foo() { label: goto label }")
Output: Stmt: &gc.StmtGoto{ · Ident: 2:26: "label", },
Example (If) ¶
example(&StmtIf{}, ` func foo() { if x { y() } } `)
Output: 0: &gc.StmtIf{ · IfHeader: &gc.IfHeader1{ · · Stmt: &gc.SimpleStmtExpr{ · · · Expr: &gc.PrimaryExprIdent{ · · · · Ident: 4:5: "x", · · · }, · · }, · }, · Body: &gc.StmtBlock{ · · List: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 5:3: "y", · · · · · }, · · · · }, · · · }, · · }, · }, },
Example (IfAssign) ¶
example(&StmtIf{}, ` func foo() { if x, y = bar(); x { y() } } `)
Output: 0: &gc.StmtIf{ · IfHeader: &gc.IfHeader2{ · · Stmt: &gc.SimpleStmtAssignment{ · · · LHS: []*gc.PrimaryExprIdent{ // len 2 · · · · 0: &gc.PrimaryExprIdent{ · · · · · Ident: 4:5: "x", · · · · }, · · · · 1: &gc.PrimaryExprIdent{ · · · · · Ident: 4:8: "y", · · · · }, · · · }, · · · RHS: []*gc.PrimaryExprCall{ // len 1 · · · · 0: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 4:12: "bar", · · · · · }, · · · · }, · · · }, · · }, · · Stmt2: &gc.SimpleStmtExpr{ · · · Expr: &gc.PrimaryExprIdent{ · · · · Ident: 4:19: "x", · · · }, · · }, · }, · Body: &gc.StmtBlock{ · · List: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 5:3: "y", · · · · · }, · · · · }, · · · }, · · }, · }, },
Example (IfDefine) ¶
example(&StmtIf{}, ` func foo() { if x, y := bar(); x { y() } } `)
Output: 0: &gc.StmtIf{ · IfHeader: &gc.IfHeader2{ · · Stmt: &gc.SimpleStmtDefine{ · · · LHS: []*gc.PrimaryExprIdent{ // len 2 · · · · 0: &gc.PrimaryExprIdent{ · · · · · Ident: 4:5: "x", · · · · }, · · · · 1: &gc.PrimaryExprIdent{ · · · · · Ident: 4:8: "y", · · · · }, · · · }, · · · RHS: []*gc.PrimaryExprCall{ // len 1 · · · · 0: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 4:13: "bar", · · · · · }, · · · · }, · · · }, · · }, · · Stmt2: &gc.SimpleStmtExpr{ · · · Expr: &gc.PrimaryExprIdent{ · · · · Ident: 4:20: "x", · · · }, · · }, · }, · Body: &gc.StmtBlock{ · · List: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 5:3: "y", · · · · · }, · · · · }, · · · }, · · }, · }, },
Example (IfElseIf) ¶
example(&StmtIf{}, ` func foo() { if x, y := bar(); x { y() } else if z { w() } } `)
Output: 0: &gc.StmtIf{ · IfHeader: &gc.IfHeader2{ · · Stmt: &gc.SimpleStmtDefine{ · · · LHS: []*gc.PrimaryExprIdent{ // len 2 · · · · 0: &gc.PrimaryExprIdent{ · · · · · Ident: 4:5: "x", · · · · }, · · · · 1: &gc.PrimaryExprIdent{ · · · · · Ident: 4:8: "y", · · · · }, · · · }, · · · RHS: []*gc.PrimaryExprCall{ // len 1 · · · · 0: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 4:13: "bar", · · · · · }, · · · · }, · · · }, · · }, · · Stmt2: &gc.SimpleStmtExpr{ · · · Expr: &gc.PrimaryExprIdent{ · · · · Ident: 4:20: "x", · · · }, · · }, · }, · Body: &gc.StmtBlock{ · · List: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 5:3: "y", · · · · · }, · · · · }, · · · }, · · }, · }, · ElseIf: []gc.ElseIf{ // len 1 · · 0: gc.ElseIf{ · · · IfHeader: &gc.IfHeader1{ · · · · Stmt: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprIdent{ · · · · · · Ident: 6:12: "z", · · · · · }, · · · · }, · · · }, · · · Body: &gc.StmtBlock{ · · · · List: []*gc.SimpleStmtExpr{ // len 1 · · · · · 0: &gc.SimpleStmtExpr{ · · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · · Ident: 7:3: "w", · · · · · · · }, · · · · · · }, · · · · · }, · · · · }, · · · }, · · }, · }, },
Example (IfElseIfElse) ¶
example(&StmtIf{}, ` func foo() { if x, y := bar(); x { y() } else if z { w() } else { qux() } } `)
Output: 0: &gc.StmtIf{ · IfHeader: &gc.IfHeader2{ · · Stmt: &gc.SimpleStmtDefine{ · · · LHS: []*gc.PrimaryExprIdent{ // len 2 · · · · 0: &gc.PrimaryExprIdent{ · · · · · Ident: 4:5: "x", · · · · }, · · · · 1: &gc.PrimaryExprIdent{ · · · · · Ident: 4:8: "y", · · · · }, · · · }, · · · RHS: []*gc.PrimaryExprCall{ // len 1 · · · · 0: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 4:13: "bar", · · · · · }, · · · · }, · · · }, · · }, · · Stmt2: &gc.SimpleStmtExpr{ · · · Expr: &gc.PrimaryExprIdent{ · · · · Ident: 4:20: "x", · · · }, · · }, · }, · Body: &gc.StmtBlock{ · · List: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 5:3: "y", · · · · · }, · · · · }, · · · }, · · }, · }, · ElseIf: []gc.ElseIf{ // len 1 · · 0: gc.ElseIf{ · · · IfHeader: &gc.IfHeader1{ · · · · Stmt: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprIdent{ · · · · · · Ident: 6:12: "z", · · · · · }, · · · · }, · · · }, · · · Body: &gc.StmtBlock{ · · · · List: []*gc.SimpleStmtExpr{ // len 1 · · · · · 0: &gc.SimpleStmtExpr{ · · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · · Ident: 7:3: "w", · · · · · · · }, · · · · · · }, · · · · · }, · · · · }, · · · }, · · }, · }, · Body2: &gc.StmtBlock{ · · List: []*gc.SimpleStmtExpr{ // len 1 · · · 0: &gc.SimpleStmtExpr{ · · · · Expr: &gc.PrimaryExprCall{ · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · Ident: 9:3: "qux", · · · · · }, · · · · }, · · · }, · · }, · }, },
Example (Labeled) ¶
example(&StmtLabeled{}, "func foo() { label: bar() }")
Output: 0: &gc.StmtLabeled{ · Label: 2:14: "label", · Stmt: &gc.SimpleStmtExpr{ · · Expr: &gc.PrimaryExprCall{ · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · Ident: 2:21: "bar", · · · }, · · }, · }, },
Example (Return) ¶
example(&StmtReturn{}, `func foo() (int, string) { return 42, "314" }`)
Output: 0: &gc.StmtReturn{ · ExprList: []*gc.PrimaryExprIntLiteral{ // len 2 · · 0: &gc.PrimaryExprIntLiteral{ · · · Literal: 2:35: "42", · · }, · · 1: &gc.PrimaryExprStringLiteral{ · · · Literal: 2:39: "\"314\"", · · }, · }, },
Example (Select) ¶
example(&StmtSelect{}, ` func foo() { select { case <-a: x() case <-b: y() default: z() } } `)
Output: 0: &gc.StmtSelect{ · List: []gc.CaseBlock{ // len 3 · · 0: gc.CaseBlock{ · · · ExprOrTypeList: []*gc.ExprOrTypeExpr{ // len 1 · · · · 0: &gc.ExprOrTypeExpr{ · · · · · Expr: &gc.PrimaryExprIdent{ · · · · · · Ident: 5:9: "a", · · · · · }, · · · · }, · · · }, · · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · · 0: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · Ident: 6:3: "x", · · · · · · }, · · · · · }, · · · · }, · · · }, · · }, · · 1: gc.CaseBlock{ · · · ExprOrTypeList: []*gc.ExprOrTypeExpr{ // len 1 · · · · 0: &gc.ExprOrTypeExpr{ · · · · · Expr: &gc.PrimaryExprIdent{ · · · · · · Ident: 7:9: "b", · · · · · }, · · · · }, · · · }, · · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · · 0: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · Ident: 8:3: "y", · · · · · · }, · · · · · }, · · · · }, · · · }, · · }, · · 2: gc.CaseBlock{ · · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · · 0: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · Ident: 10:3: "z", · · · · · · }, · · · · · }, · · · · }, · · · }, · · · Default: true, · · }, · }, },
Example (Switch) ¶
example(&StmtSwitch{}, ` func foo() { switch x := y; 2*y { case 42: x() case 314: y() default: z() } } `)
Output: 0: &gc.StmtSwitch{ · IfHeader: &gc.IfHeader2{ · · Stmt: &gc.SimpleStmtDefine{ · · · LHS: []*gc.PrimaryExprIdent{ // len 1 · · · · 0: &gc.PrimaryExprIdent{ · · · · · Ident: 4:9: "x", · · · · }, · · · }, · · · RHS: []*gc.PrimaryExprIdent{ // len 1 · · · · 0: &gc.PrimaryExprIdent{ · · · · · Ident: 4:14: "y", · · · · }, · · · }, · · }, · · Stmt2: &gc.SimpleStmtExpr{ · · · Expr: &gc.ExprMUL{ · · · · LHS: &gc.PrimaryExprIntLiteral{ · · · · · Literal: 4:17: "2", · · · · }, · · · · RHS: &gc.PrimaryExprIdent{ · · · · · Ident: 4:19: "y", · · · · }, · · · }, · · }, · }, · List: []gc.CaseBlock{ // len 3 · · 0: gc.CaseBlock{ · · · ExprOrTypeList: []*gc.ExprOrTypeExpr{ // len 1 · · · · 0: &gc.ExprOrTypeExpr{ · · · · · Expr: &gc.PrimaryExprIntLiteral{ · · · · · · Literal: 5:7: "42", · · · · · }, · · · · }, · · · }, · · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · · 0: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · Ident: 6:3: "x", · · · · · · }, · · · · · }, · · · · }, · · · }, · · }, · · 1: gc.CaseBlock{ · · · ExprOrTypeList: []*gc.ExprOrTypeExpr{ // len 1 · · · · 0: &gc.ExprOrTypeExpr{ · · · · · Expr: &gc.PrimaryExprIntLiteral{ · · · · · · Literal: 7:7: "314", · · · · · }, · · · · }, · · · }, · · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · · 0: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · Ident: 8:3: "y", · · · · · · }, · · · · · }, · · · · }, · · · }, · · }, · · 2: gc.CaseBlock{ · · · Body: []*gc.SimpleStmtExpr{ // len 1 · · · · 0: &gc.SimpleStmtExpr{ · · · · · Expr: &gc.PrimaryExprCall{ · · · · · · PrimaryExpr: &gc.PrimaryExprIdent{ · · · · · · · Ident: 10:3: "z", · · · · · · }, · · · · · }, · · · · }, · · · }, · · · Default: true, · · }, · }, },
type StmtBlock ¶
type StmtBlock struct { List []Stmt // contains filtered or unexported fields }
StmtBlock describes { stmt; stmt2; ... }.
type StmtBreak ¶
type StmtBreak struct { Label Token // contains filtered or unexported fields }
StmtBreak describes break label.
type StmtContinue ¶
type StmtContinue struct { Label Token // contains filtered or unexported fields }
StmtContinue describes continue label.
type StmtDefer ¶
type StmtDefer struct { Expr Expr // contains filtered or unexported fields }
StmtDefer describes defer expr.
type StmtFallthrough ¶
type StmtFallthrough struct {
// contains filtered or unexported fields
}
StmtFallthrough describes falltrough.
type StmtFor ¶
type StmtFor struct { Stmt SimpleStmt Stmt2 SimpleStmt Stmt3 SimpleStmt Body *StmtBlock // contains filtered or unexported fields }
StmtFor describes for stmt; stmt2; stmt3 { body }.
type StmtForRange ¶
type StmtForRange struct { ExprList []Expr Expr Expr Body *StmtBlock Define bool // true: for exprlist := range ..., false: for exprlist = range ... // contains filtered or unexported fields }
StmtForRange describes for i := range expr { body } or the = variant.
type StmtGo ¶
type StmtGo struct { Expr Expr // contains filtered or unexported fields }
StmtGo describes go expr.
type StmtGoto ¶
type StmtGoto struct { Ident Token // contains filtered or unexported fields }
StmtGoto describes goto ident.
type StmtIf ¶
type StmtIf struct { IfHeader IfHeader Body *StmtBlock ElseIf []ElseIf Body2 *StmtBlock // contains filtered or unexported fields }
StmtIf descibes if ifHeader body elseIfList else body2
type StmtLabeled ¶
StmtLabeled describes label: stmt.
type StmtReturn ¶
type StmtReturn struct { ExprList []Expr // contains filtered or unexported fields }
StmtReturn describes return expr.
type StmtSelect ¶
type StmtSelect struct { List []CaseBlock // contains filtered or unexported fields }
StmtSelect describes select {}.
type StmtSwitch ¶
type StmtSwitch struct { IfHeader IfHeader List []CaseBlock // contains filtered or unexported fields }
StmtSwitch describes switch {}.
type StructType ¶
type StructType struct { Fields []FieldDeclaration // contains filtered or unexported fields }
StructType represents 'struct{...}'.
Example ¶
example(&StructType{}, "type T struct{ i int; s string }")
Output: &gc.StructType{ · Fields: []*gc.FieldDeclarationNamed{ // len 2 · · 0: &gc.FieldDeclarationNamed{ · · · Name: 2:16: "i", · · · Type: &gc.NamedType{ · · · · Name: "int", · · · }, · · }, · · 1: &gc.FieldDeclarationNamed{ · · · Name: 2:23: "s", · · · Type: &gc.NamedType{ · · · · Name: "string", · · · }, · · }, · }, }
func (*StructType) AssignableTo ¶
func (*StructType) ComparableWith ¶
func (*StructType) Implements ¶
func (*StructType) Kind ¶
func (n *StructType) Kind() TypeKind
func (*StructType) String ¶
func (n *StructType) String() string
func (*StructType) UnderlyingType ¶
func (n *StructType) UnderlyingType() Type
type Token ¶
type Token struct { Val string // contains filtered or unexported fields }
Token represents the position and value of a token.
func (*Token) SourceFile ¶
func (n *Token) SourceFile() *SourceFile
type TupleType ¶
type TupleType struct { List []Type // contains filtered or unexported fields }
TupleType represents '(T1, T2, ...)'.
func (*TupleType) AssignableTo ¶
func (*TupleType) ComparableWith ¶
func (*TupleType) Implements ¶
func (*TupleType) UnderlyingType ¶
func (n *TupleType) UnderlyingType() Type
type Type ¶
type Type interface { //TODO Node AssignableTo(Type) bool //TODO Operand method ComparableWith(Type) (bool, string) //TODO Operand method Identical(Type) bool Implements(Type) bool IsDefined() bool Kind() TypeKind Package() *Package Position() token.Position SourceFile() *SourceFile String() string UnderlyingType() Type // contains filtered or unexported methods }
Type represents a Go type.
type TypeDecl ¶
type TypeDecl struct {
// contains filtered or unexported fields
}
TypeDecl describes a type declaration.
func (*TypeDecl) Visibility ¶
Visibility implements Declaration.
type TypeKind ¶
type TypeKind byte
TypeKind represents a particular type kind.
const ( Invalid TypeKind = iota Bool Complex128 Complex64 Float32 Float64 Int Int16 Int32 Int64 Int8 String Uint Uint16 Uint32 Uint64 Uint8 Uintptr UntypedBool UntypedComplex UntypedFloat UntypedInt UntypedNil UntypedRune UntypedString BuiltinGenericComplex // U in 'func complex(r, i T) U'. BuiltinGenericFloat // T in 'func complex(r, i T) U'. BuiltinGenericInteger // U in 'make(T, ...U)'. BuiltinGeneric // T in 'func make(T)'. BuiltinGeneric2 // U in 'func delete(map[T]U)'. Array // [Expr]Element Channel // chan T Function // func(params) result Interface // interface{...} Map // map[T]U Pointer // *T QualifiedTypeName // qualifier.ident Slice // []T Struct // struct{...} Tuple // (T1, T2, ...) TypeName // ident )
TypeKind values.
func (TypeKind) AssignableTo ¶
AssignableTo implements Type.
func (TypeKind) SourceFile ¶
func (n TypeKind) SourceFile() *SourceFile
func (TypeKind) UnderlyingType ¶
UnderlyingType implements Type.
type UnaryExpr ¶
type UnaryExpr Expr
UnaryExpr represents data reduced by productions
unaryExpr: "<-" unaryExpr | '!' unaryExpr | '&' unaryExpr | '*' unaryExpr | '+' unaryExpr | '-' unaryExpr | '^' unaryExpr | primaryExpr
Example (Addr) ¶
example(&UnaryExprAddr{}, "var v = &foo")
Output: Initializer: &gc.UnaryExprAddr{ · Expr: &gc.PrimaryExprIdent{ · · Ident: 2:10: "foo", · }, },
Example (Deref) ¶
example(&UnaryExprDeref{}, "var v = *foo")
Output: Initializer: &gc.UnaryExprDeref{ · Expr: &gc.PrimaryExprIdent{ · · Ident: 2:10: "foo", · }, },
Example (Neg) ¶
example(&UnaryExprNeg{}, "var v = -0")
Output: Initializer: &gc.UnaryExprNeg{ · Expr: &gc.PrimaryExprIntLiteral{ · · Literal: 2:10: "0", · }, },
Example (Not) ¶
example(&UnaryExprNot{}, "var v = !foo")
Output: Initializer: &gc.UnaryExprNot{ · Expr: &gc.PrimaryExprIdent{ · · Ident: 2:10: "foo", · }, },
Example (Pos) ¶
example(&UnaryExprPos{}, "var v = +0")
Output: Initializer: &gc.UnaryExprPos{ · Expr: &gc.PrimaryExprIntLiteral{ · · Literal: 2:10: "0", · }, },
Example (Receive) ¶
example(&UnaryExprReceive{}, "var v = <-foo")
Output: Initializer: &gc.UnaryExprReceive{ · Expr: &gc.PrimaryExprIdent{ · · Ident: 2:11: "foo", · }, },
Example (Xor) ¶
example(&UnaryExprXor{}, "var v = ^0")
Output: Initializer: &gc.UnaryExprXor{ · Expr: &gc.PrimaryExprIntLiteral{ · · Literal: 2:10: "0", · }, },
type UnaryExprAddr ¶
type UnaryExprAddr struct { Expr Expr // contains filtered or unexported fields }
UnaryExprAddr is an Expr.
func (*UnaryExprAddr) SourceFile ¶
func (n *UnaryExprAddr) SourceFile() *SourceFile
type UnaryExprDeref ¶
type UnaryExprDeref struct { Expr Expr // contains filtered or unexported fields }
UnaryExprDeref is an Expr.
func (*UnaryExprDeref) SourceFile ¶
func (n *UnaryExprDeref) SourceFile() *SourceFile
type UnaryExprNeg ¶
type UnaryExprNeg struct { Expr Expr // contains filtered or unexported fields }
UnaryExprNeg is an Expr.
func (*UnaryExprNeg) SourceFile ¶
func (n *UnaryExprNeg) SourceFile() *SourceFile
type UnaryExprNot ¶
type UnaryExprNot struct { Expr Expr // contains filtered or unexported fields }
UnaryExprNot is an Expr.
func (*UnaryExprNot) SourceFile ¶
func (n *UnaryExprNot) SourceFile() *SourceFile
type UnaryExprPos ¶
type UnaryExprPos struct { Expr Expr // contains filtered or unexported fields }
UnaryExprPos is an Expr.
func (*UnaryExprPos) SourceFile ¶
func (n *UnaryExprPos) SourceFile() *SourceFile
type UnaryExprReceive ¶
type UnaryExprReceive struct { Expr Expr // contains filtered or unexported fields }
UnaryExprReceive is an Expr.
func (*UnaryExprReceive) SourceFile ¶
func (n *UnaryExprReceive) SourceFile() *SourceFile
type UnaryExprXor ¶
type UnaryExprXor struct { Expr Expr // contains filtered or unexported fields }
UnaryExprXor is an Expr.
func (*UnaryExprXor) SourceFile ¶
func (n *UnaryExprXor) SourceFile() *SourceFile
type UntypedBooleanValue ¶
type UntypedBooleanValue struct { V bool // contains filtered or unexported fields }
UntypedBooleanValue represents a true/false value.
type UntypedIntOperand ¶
type UntypedIntOperand struct {
// contains filtered or unexported fields
}
UntypedIntOperand represents an integer operand.
type UntypedIntValue ¶
UntypedIntValue represents an untyped integer.
type Value ¶
type Value interface {
// contains filtered or unexported methods
}
Value represents operand's value.
type VarDecl ¶
type VarDecl struct { Initializer Expr // contains filtered or unexported fields }
VarDecl describes a variable declaration.
func (*VarDecl) Visibility ¶
Visibility implements Declaration.