Documentation
¶
Overview ¶
Package ast declares the types used to represent syntax trees for XGo packages.
Index ¶
- func FileExports(src *File) bool
- func FilterDecl(decl Decl, f Filter) bool
- func FilterFile(src *File, f Filter) bool
- func FilterPackage(pkg *Package, f Filter) bool
- func Fprint(w io.Writer, fset *token.FileSet, x any, f FieldFilter) error
- func Inspect(node Node, f func(Node) bool)
- func IsExported(name string) bool
- func NextPartPos(pos token.Pos, part any) (nextPos token.Pos)
- func NotNilFilter(_ string, v reflect.Value) bool
- func PackageExports(pkg *Package) bool
- func Print(fset *token.FileSet, x any) error
- func SortImports(fset *token.FileSet, f *File)
- func Walk(v Visitor, node Node)
- type AnySelectorExpr
- type ArrayType
- type AssignStmt
- type BadDecl
- type BadExpr
- type BadStmt
- type BasicLit
- type BinaryExpr
- type BlockStmt
- type BranchStmt
- type CallExpr
- type CaseClause
- type ChanDir
- type ChanType
- type CommClause
- type Comment
- type CommentGroup
- type CommentMap
- type CompositeLit
- type ComprehensionExpr
- type CondExpr
- type Decl
- type DeclStmt
- type DeferStmt
- type DomainTextLit
- type DomainTextLitEx
- type ElemEllipsis
- type Ellipsis
- type EmptyStmt
- type EnvExpr
- type ErrWrapExpr
- type Expr
- type ExprStmt
- type Field
- type FieldFilter
- type FieldList
- type File
- type Filter
- type ForPhrase
- type ForPhraseStmt
- type ForStmt
- type FuncDecl
- type FuncLit
- type FuncType
- type GenDecl
- type GoStmt
- type Ident
- type IfStmt
- type ImportSpec
- type IncDecStmt
- type IndexExpr
- type IndexListExpr
- type InterfaceType
- type KeyValueExpr
- type KwargExpr
- type LabeledStmt
- type LambdaExpr
- type LambdaExpr2
- type MapType
- type MatrixLit
- type MergeMode
- type Node
- type NumberUnitLit
- type ObjKind
- type Object
- type OverloadFuncDecl
- type Package
- type ParenExpr
- type RangeExpr
- type RangeStmt
- type ReturnStmt
- type Scope
- type SelectStmt
- type SelectorExpr
- type SendStmt
- type SliceExpr
- type SliceLit
- type Spec
- type StarExpr
- type Stmt
- type StringLitEx
- type StructType
- type SwitchStmt
- type TupleLit
- type TupleType
- type TypeAssertExpr
- type TypeSpec
- type TypeSwitchStmt
- type UnaryExpr
- type ValueSpec
- type Visitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileExports ¶
FileExports trims the AST for a Go source file in place such that only exported nodes remain: all top-level identifiers which are not exported and their associated information (such as type, initial value, or function body) are removed. Non-exported fields and methods of exported types are stripped. The File.Comments list is not changed.
FileExports reports whether there are exported declarations.
func FilterDecl ¶
FilterDecl trims the AST for a Go declaration in place by removing all names (including struct field and interface method names, but not from parameter lists) that don't pass through the filter f.
FilterDecl reports whether there are any declared names left after filtering.
func FilterFile ¶
FilterFile trims the AST for a Go file in place by removing all names from top-level declarations (including struct field and interface method names, but not from parameter lists) that don't pass through the filter f. If the declaration is empty afterwards, the declaration is removed from the AST. Import declarations are always removed. The File.Comments list is not changed.
FilterFile reports whether there are any top-level declarations left after filtering.
func FilterPackage ¶
FilterPackage trims the AST for a Go package in place by removing all names from top-level declarations (including struct field and interface method names, but not from parameter lists) that don't pass through the filter f. If the declaration is empty afterwards, the declaration is removed from the AST. The pkg.Files list is not changed, so that file names and top-level package comments don't get lost.
FilterPackage reports whether there are any top-level declarations left after filtering.
func Fprint ¶
Fprint prints the (sub-)tree starting at AST node x to w. If fset != nil, position information is interpreted relative to that file set. Otherwise positions are printed as integer values (file set specific offsets).
A non-nil FieldFilter f may be provided to control the output: struct fields for which f(fieldname, fieldvalue) is true are printed; all others are filtered from the output. Unexported struct fields are never printed.
func Inspect ¶
Inspect traverses an AST in depth-first order: It starts by calling f(node); node must not be nil. If f returns true, Inspect invokes f recursively for each of the non-nil children of node, followed by a call of f(nil).
func IsExported ¶
IsExported reports whether name starts with an upper-case letter.
func NextPartPos ¶
NextPartPos - position of first character of next part. pos - position of this part (not including quote character).
func NotNilFilter ¶
NotNilFilter returns true for field values that are not nil; it returns false otherwise.
func PackageExports ¶
PackageExports trims the AST for a Go package in place such that only exported nodes remain. The pkg.Files list is not changed, so that file names and top-level package comments don't get lost.
PackageExports reports whether there are exported declarations; it returns false otherwise.
func Print ¶
Print prints x to standard output, skipping nil fields. Print(fset, x) is the same as Fprint(os.Stdout, fset, x, NotNilFilter).
func SortImports ¶
SortImports sorts runs of consecutive import lines in import blocks in f. It also removes duplicate imports when it is possible to do so without data loss.
Types ¶
type AnySelectorExpr ¶ added in v1.6.3
type AnySelectorExpr struct {
X Expr // expression
TokPos token.Pos // position of "**"
Sel *Ident // field selector (it may not be a simple identifier)
}
AnySelectorExpr represents `X.**.Sel` expression, which selects any field named Sel in the nested object X. Sel may not be a simple identifier. For example:
- x.**.field
- x.**."field-name"
- x.**.*
func (*AnySelectorExpr) End ¶ added in v1.6.3
func (p *AnySelectorExpr) End() token.Pos
End - position of first character immediately after the node.
func (*AnySelectorExpr) Pos ¶ added in v1.6.3
func (p *AnySelectorExpr) Pos() token.Pos
Pos - position of first character belonging to the node.
type ArrayType ¶
type ArrayType struct {
Lbrack token.Pos // position of "["
Len Expr // Ellipsis node for [...]T array types, nil for slice types
Elt Expr // element type
}
An ArrayType node represents an array or slice type.
type AssignStmt ¶
type AssignStmt struct {
Lhs []Expr // left hand side expressions
TokPos token.Pos // position of Tok
Tok token.Token // assignment token, DEFINE
Rhs []Expr // right hand side expressions
}
An AssignStmt node represents an assignment or a short variable declaration.
func (*AssignStmt) End ¶
func (s *AssignStmt) End() token.Pos
End returns position of first character immediately after the node.
func (*AssignStmt) Pos ¶
func (s *AssignStmt) Pos() token.Pos
Pos returns position of first character belonging to the node.
type BadDecl ¶
A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.
type BadExpr ¶
A BadExpr node is a placeholder for expressions containing syntax errors for which no correct expression nodes can be created.
type BadStmt ¶
A BadStmt node is a placeholder for statements containing syntax errors for which no correct statement nodes can be created.
type BasicLit ¶
type BasicLit struct {
ValuePos token.Pos // literal position
Kind token.Token // token.INT, token.FLOAT, token.IMAG, token.RAT, token.CHAR, token.STRING, token.CSTRING
Value string // literal string; e.g. 42, 0x7f, 3.14, 1e-9, 2.4i, 3r, 'a', '\x7f', "foo" or `\m\n\o`
Extra *StringLitEx // optional (only available when Kind == token.STRING)
}
A BasicLit node represents a literal of basic type.
type BinaryExpr ¶
type BinaryExpr struct {
X Expr // left operand
OpPos token.Pos // position of Op
Op token.Token // operator
Y Expr // right operand
}
A BinaryExpr node represents a binary expression.
func (*BinaryExpr) End ¶
func (x *BinaryExpr) End() token.Pos
End returns position of first character immediately after the node.
func (*BinaryExpr) Pos ¶
func (x *BinaryExpr) Pos() token.Pos
Pos returns position of first character belonging to the node.
type BlockStmt ¶
type BlockStmt struct {
Lbrace token.Pos // position of "{"
List []Stmt
Rbrace token.Pos // position of "}", if any (may be absent due to syntax error)
}
A BlockStmt node represents a braced statement list.
type BranchStmt ¶
type BranchStmt struct {
TokPos token.Pos // position of Tok
Tok token.Token // keyword token (BREAK, CONTINUE, GOTO, FALLTHROUGH)
Label *Ident // label name; or nil
}
A BranchStmt node represents a break, continue, goto, or fallthrough statement.
func (*BranchStmt) End ¶
func (s *BranchStmt) End() token.Pos
End returns position of first character immediately after the node.
func (*BranchStmt) Pos ¶
func (s *BranchStmt) Pos() token.Pos
Pos returns position of first character belonging to the node.
type CallExpr ¶
type CallExpr struct {
Fun Expr // function expression
Lparen token.Pos // position of "("
Args []Expr // positional arguments; or nil
Ellipsis token.Pos // position of "..." (token.NoPos if there is no "...")
Kwargs []*KwargExpr // keyword arguments; or nil
Rparen token.Pos // position of ")"
NoParenEnd token.Pos
}
A CallExpr node represents an expression followed by an argument list. The argument list may include positional arguments (Args) and/or keyword arguments (Kwargs).
type CaseClause ¶
type CaseClause struct {
Case token.Pos // position of "case" or "default" keyword
List []Expr // list of expressions or types; nil means default case
Colon token.Pos // position of ":"
Body []Stmt // statement list; or nil
}
A CaseClause represents a case of an expression or type switch statement.
func (*CaseClause) End ¶
func (s *CaseClause) End() token.Pos
End returns position of first character immediately after the node.
func (*CaseClause) Pos ¶
func (s *CaseClause) Pos() token.Pos
Pos returns position of first character belonging to the node.
type ChanDir ¶
type ChanDir int
ChanDir is the direction of a channel type is indicated by a bit mask including one or both of the following constants.
type ChanType ¶
type ChanType struct {
Begin token.Pos // position of "chan" keyword or "<-" (whichever comes first)
Arrow token.Pos // position of "<-" (token.NoPos if there is no "<-")
Dir ChanDir // channel direction
Value Expr // value type
}
A ChanType node represents a channel type.
type CommClause ¶
type CommClause struct {
Case token.Pos // position of "case" or "default" keyword
Comm Stmt // send or receive statement; nil means default case
Colon token.Pos // position of ":"
Body []Stmt // statement list; or nil
}
A CommClause node represents a case of a select statement.
func (*CommClause) End ¶
func (s *CommClause) End() token.Pos
End returns position of first character immediately after the node.
func (*CommClause) Pos ¶
func (s *CommClause) Pos() token.Pos
Pos returns position of first character belonging to the node.
type CommentGroup ¶
type CommentGroup = ast.CommentGroup
A CommentGroup represents a sequence of comments with no other tokens and no empty lines between.
type CommentMap ¶
type CommentMap map[Node][]*CommentGroup
A CommentMap maps an AST node to a list of comment groups associated with it. See NewCommentMap for a description of the association.
func NewCommentMap ¶
func NewCommentMap(fset *token.FileSet, node Node, comments []*CommentGroup) CommentMap
NewCommentMap creates a new comment map by associating comment groups of the comments list with the nodes of the AST specified by node.
A comment group g is associated with a node n if:
- g starts on the same line as n ends
- g starts on the line immediately following n, and there is at least one empty line after g and before the next node
- g starts before n and is not associated to the node before n via the previous rules
NewCommentMap tries to associate a comment group to the "largest" node possible: For instance, if the comment is a line comment trailing an assignment, the comment is associated with the entire assignment rather than just the last operand in the assignment.
func (CommentMap) Comments ¶
func (cmap CommentMap) Comments() []*CommentGroup
Comments returns the list of comment groups in the comment map. The result is sorted in source order.
func (CommentMap) Filter ¶
func (cmap CommentMap) Filter(node Node) CommentMap
Filter returns a new comment map consisting of only those entries of cmap for which a corresponding node exists in the AST specified by node.
func (CommentMap) String ¶
func (cmap CommentMap) String() string
func (CommentMap) Update ¶
func (cmap CommentMap) Update(old, new Node) Node
Update replaces an old node in the comment map with the new node and returns the new node. Comments that were associated with the old node are associated with the new node.
type CompositeLit ¶
type CompositeLit struct {
Type Expr // literal type; or nil
Lbrace token.Pos // position of "{"
Elts []Expr // list of composite elements; or nil
Rbrace token.Pos // position of "}"
Incomplete bool // true if (source) expressions are missing in the Elts list
}
A CompositeLit node represents a composite literal.
func (*CompositeLit) End ¶
func (x *CompositeLit) End() token.Pos
End returns position of first character immediately after the node.
func (*CompositeLit) Pos ¶
func (x *CompositeLit) Pos() token.Pos
Pos returns position of first character belonging to the node.
type ComprehensionExpr ¶
type ComprehensionExpr struct {
Lpos token.Pos // position of "[" or "{"
Tok token.Token // token.LBRACK '[' or token.LBRACE '{'
Elt Expr // *KeyValueExpr or Expr or nil
Fors []*ForPhrase
Rpos token.Pos // position of "]" or "}"
}
ComprehensionExpr represents one of the following expressions:
`[vexpr for k1, v1 in container1, cond1 ...]` or
`{vexpr for k1, v1 in container1, cond1 ...}` or
`{kexpr: vexpr for k1, v1 in container1, cond1 ...}` or
`{for k1, v1 in container1, cond1 ...}`
func (*ComprehensionExpr) End ¶
func (p *ComprehensionExpr) End() token.Pos
End - position of first character immediately after the node.
func (*ComprehensionExpr) Pos ¶
func (p *ComprehensionExpr) Pos() token.Pos
Pos - position of first character belonging to the node.
type CondExpr ¶ added in v1.6.3
type CondExpr struct {
X Expr // expression
OpPos token.Pos // position of "@"
Cond Expr // condition expression (can be *CallExpr, *ParenExpr or *Ident)
}
A CondExpr node represents a conditional expression: `expr @ cond`.
- ns@(condExpr)
- ns@fn(args)
- ns@"elem-name" (Cond will be a *Ident with name "elem-name", not a *BasicLit)
- ns@name
type Decl ¶
type Decl interface {
Node
// contains filtered or unexported methods
}
Decl interface: all declaration nodes implement the Decl interface.
type DeclStmt ¶
type DeclStmt struct {
Decl Decl // *GenDecl with CONST, TYPE, or VAR token
}
A DeclStmt node represents a declaration in a statement list.
type DeferStmt ¶
A DeferStmt node represents a defer statement.
type DomainTextLit ¶
type DomainTextLit struct {
Domain *Ident // domain name
ValuePos token.Pos // literal position
Value string // literal string; e.g. `\m\n\o`
Extra any // *DomainTextLitEx or *xgo/tpl/ast.File, optional
}
A DomainTextLit node represents a domain-specific text literal. https://github.com/goplus/xgo/issues/2143
domainTag`...` domainTag`> arg1, arg2, ... ... `
func (*DomainTextLit) End ¶
func (x *DomainTextLit) End() token.Pos
End returns position of first character immediately after the node.
func (*DomainTextLit) Pos ¶
func (x *DomainTextLit) Pos() token.Pos
Pos returns position of first character belonging to the node.
type DomainTextLitEx ¶
type DomainTextLitEx struct {
Args []Expr // domain text arguments; or nil
RawPos token.Pos // position of the first character of the raw string
Raw string // raw string without backquote
}
DomainTextLitEx represents extra information for domain text literal.
type ElemEllipsis ¶
A ElemEllipsis node represents a matrix row elements.
func (*ElemEllipsis) End ¶
func (p *ElemEllipsis) End() token.Pos
End - position of first character immediately after the node.
func (*ElemEllipsis) Pos ¶
func (p *ElemEllipsis) Pos() token.Pos
Pos - position of first character belonging to the node.
type Ellipsis ¶
type Ellipsis struct {
Ellipsis token.Pos // position of "..."
Elt Expr // ellipsis element type (parameter lists only); or nil
}
An Ellipsis node stands for the "..." type in a parameter list or the "..." length in an array type.
type EmptyStmt ¶
type EmptyStmt struct {
Semicolon token.Pos // position of following ";"
Implicit bool // if set, ";" was omitted in the source
}
An EmptyStmt node represents an empty statement. The "position" of the empty statement is the position of the immediately following (explicit or implicit) semicolon.
type EnvExpr ¶
type EnvExpr struct {
TokPos token.Pos // position of "$"
Lbrace token.Pos // position of "{"
Name *Ident // name
Rbrace token.Pos // position of "}"
}
A EnvExpr node represents a ${name} expression.
type ErrWrapExpr ¶
type ErrWrapExpr struct {
X Expr
Tok token.Token // ! or ?
TokPos token.Pos
Default Expr // can be nil
}
ErrWrapExpr represents `expr!`, `expr?` or `expr?:defaultValue`.
func (*ErrWrapExpr) End ¶
func (p *ErrWrapExpr) End() token.Pos
End - position of first character immediately after the node.
func (*ErrWrapExpr) Pos ¶
func (p *ErrWrapExpr) Pos() token.Pos
Pos - position of first character belonging to the node.
type Expr ¶
type Expr interface {
Node
// contains filtered or unexported methods
}
Expr interface: all expression nodes implement the Expr interface.
type ExprStmt ¶
type ExprStmt struct {
X Expr // expression
}
An ExprStmt node represents a (stand-alone) expression in a statement list.
type Field ¶
type Field struct {
Doc *CommentGroup // associated documentation; or nil
Names []*Ident // field/method/parameter names; or nil
Type Expr // field/method/parameter type
Tag *BasicLit // field tag; or nil
Comment *CommentGroup // line comments; or nil
Optional token.Pos // position of "?", or NoPos if not optional
}
A Field represents a Field declaration list in a struct type, a method list in an interface type, or a parameter/result declaration in a signature. Field.Names is nil for unnamed parameters (parameter lists which only contain types) and embedded struct fields. In the latter case, the field name is the type name.
type FieldFilter ¶
A FieldFilter may be provided to Fprint to control the output.
type FieldList ¶
type FieldList struct {
Opening token.Pos // position of opening parenthesis/brace, if any
List []*Field // field list; or nil
Closing token.Pos // position of closing parenthesis/brace, if any
}
A FieldList represents a list of Fields, enclosed by parentheses or braces.
type File ¶
type File struct {
Doc *CommentGroup // associated documentation; or nil
Package token.Pos // position of "package" keyword; or NoPos
Name *Ident // package name
Decls []Decl // top-level declarations; or nil
Imports []*ImportSpec // imports in this file
Comments []*CommentGroup // list of all comments in the source file
Code []byte
ShadowEntry *FuncDecl // indicate the module entry point.
NoPkgDecl bool // no `package xxx` declaration
IsClass bool // is a classfile (including normal .gox file)
IsProj bool // is a project classfile
IsNormalGox bool // is a normal .gox file
}
A File node represents an XGo source file.
The Comments list contains all comments in the source file in order of appearance, including the comments that are pointed to from other nodes via Doc and Comment fields.
For correct printing of source code containing comments (using packages go/format and go/printer), special care must be taken to update comments when a File's syntax tree is modified: For printing, comments are interspersed between tokens based on their position. If syntax tree nodes are removed or moved, relevant comments in their vicinity must also be removed (from the File.Comments list) or moved accordingly (by updating their positions). A CommentMap may be used to facilitate some of these operations.
Whether and how a comment is associated with a node depends on the interpretation of the syntax tree by the manipulating program: Except for Doc and Comment comments directly associated with nodes, the remaining comments are "free-floating" (see also issues #18593, #20744).
func MergePackageFiles ¶
MergePackageFiles creates a file AST by merging the ASTs of the files belonging to a package. The mode flags control merging behavior.
func (*File) ClassFieldsDecl ¶
ClassFieldsDecl returns the class fields declaration.
func (*File) HasPkgDecl ¶
HasPkgDecl checks if `package xxx` exists or not.
func (*File) HasShadowEntry ¶
There is no entrypoint func to indicate the module entry point.
type ForPhrase ¶
type ForPhrase struct {
For token.Pos // position of "for" keyword
Key, Value *Ident // Key may be nil
TokPos token.Pos // position of "in" operator
X Expr // value to range over
IfPos token.Pos // position of if or comma; or NoPos
Init Stmt // initialization statement; or nil
Cond Expr // value filter, can be nil
}
ForPhrase represents `for k, v in container if init; cond` phrase.
type ForPhraseStmt ¶
A ForPhraseStmt represents a for statement with a for..in clause.
func (*ForPhraseStmt) End ¶
func (p *ForPhraseStmt) End() token.Pos
End - position of first character immediately after the node.
func (*ForPhraseStmt) Pos ¶
func (p *ForPhraseStmt) Pos() token.Pos
Pos - position of first character belonging to the node.
type ForStmt ¶
type ForStmt struct {
For token.Pos // position of "for" keyword
Init Stmt // initialization statement; or nil
Cond Expr // condition; or nil
Post Stmt // post iteration statement; or nil
Body *BlockStmt
}
A ForStmt represents a `for init; cond; post { ... }` statement.
type FuncDecl ¶
type FuncDecl struct {
Doc *CommentGroup // associated documentation; or nil
Recv *FieldList // receiver (methods); or nil (functions)
Name *Ident // function/method name
Type *FuncType // function signature: parameters, results, and position of "func" keyword
Body *BlockStmt // function body; or nil for external (non-Go) function
Operator bool // is operator or not
Shadow bool // is a shadow entry
IsClass bool // recv set by class
Static bool // recv is static (class method)
}
A FuncDecl node represents a function declaration.
type FuncLit ¶
A FuncLit node represents a function literal.
type FuncType ¶
type FuncType struct {
Func token.Pos // position of "func" keyword (token.NoPos if there is no "func")
TypeParams *FieldList // type parameters; or nil
Params *FieldList // (incoming) parameters; non-nil
Results *FieldList // (outgoing) results; or nil
}
A FuncType node represents a function type.
type GenDecl ¶
type GenDecl struct {
Doc *CommentGroup // associated documentation; or nil
TokPos token.Pos // position of Tok
Tok token.Token // IMPORT, CONST, TYPE, VAR
Lparen token.Pos // position of '(', if any
Specs []Spec
Rparen token.Pos // position of ')', if any
}
A GenDecl node (generic declaration node) represents an import, constant, type or variable declaration. A valid Lparen position (Lparen.IsValid()) indicates a parenthesized declaration.
Relationship between Tok value and Specs element type:
token.IMPORT *ImportSpec token.CONST *ValueSpec token.TYPE *TypeSpec token.VAR *ValueSpec
type GoStmt ¶
A GoStmt node represents a go statement.
type Ident ¶
type Ident struct {
NamePos token.Pos // identifier position
Name string // identifier name
Obj *Object // denoted object; or nil
}
An Ident node represents an identifier.
func NewIdent ¶
NewIdent creates a new Ident without position. Useful for ASTs generated by code other than the XGo parser.
func NewIdentEx ¶
NewIdentEx creates a new Ident with position and with the given kind.
func (*Ident) IsExported ¶
IsExported reports whether id starts with an upper-case letter.
type IfStmt ¶
type IfStmt struct {
If token.Pos // position of "if" keyword
Init Stmt // initialization statement; or nil
Cond Expr // condition
Body *BlockStmt
Else Stmt // else branch; or nil
}
An IfStmt node represents an if statement.
type ImportSpec ¶
type ImportSpec struct {
Doc *CommentGroup // associated documentation; or nil
Name *Ident // local package name (including "."); or nil
Path *BasicLit // import path
Comment *CommentGroup // line comments; or nil
EndPos token.Pos // end of spec (overrides Path.Pos if nonzero)
}
An ImportSpec node represents a single package import.
func (*ImportSpec) End ¶
func (s *ImportSpec) End() token.Pos
End returns position of first character immediately after the node.
func (*ImportSpec) Pos ¶
func (s *ImportSpec) Pos() token.Pos
Pos returns position of first character belonging to the node.
type IncDecStmt ¶
An IncDecStmt node represents an increment or decrement statement.
func (*IncDecStmt) End ¶
func (s *IncDecStmt) End() token.Pos
End returns position of first character immediately after the node.
func (*IncDecStmt) Pos ¶
func (s *IncDecStmt) Pos() token.Pos
Pos returns position of first character belonging to the node.
type IndexExpr ¶
type IndexExpr struct {
X Expr // expression
Lbrack token.Pos // position of "["
Index Expr // index expression
Rbrack token.Pos // position of "]"
}
An IndexExpr node represents an expression followed by an index.
type IndexListExpr ¶
type IndexListExpr struct {
X Expr // expression
Lbrack token.Pos // position of "["
Indices []Expr // index expressions
Rbrack token.Pos // position of "]"
}
An IndexListExpr node represents an expression followed by multiple indices.
func (*IndexListExpr) End ¶
func (x *IndexListExpr) End() token.Pos
End returns position of first character immediately after the node.
func (*IndexListExpr) Pos ¶
func (x *IndexListExpr) Pos() token.Pos
Pos returns position of first character belonging to the node.
type InterfaceType ¶
type InterfaceType struct {
Interface token.Pos // position of "interface" keyword
Methods *FieldList // list of methods
Incomplete bool // true if (source) methods are missing in the Methods list
}
An InterfaceType node represents an interface type.
func (*InterfaceType) End ¶
func (x *InterfaceType) End() token.Pos
End returns position of first character immediately after the node.
func (*InterfaceType) Pos ¶
func (x *InterfaceType) Pos() token.Pos
Pos returns position of first character belonging to the node.
type KeyValueExpr ¶
A KeyValueExpr node represents (key : value) pairs in composite literals.
func (*KeyValueExpr) End ¶
func (x *KeyValueExpr) End() token.Pos
End returns position of first character immediately after the node.
func (*KeyValueExpr) Pos ¶
func (x *KeyValueExpr) Pos() token.Pos
Pos returns position of first character belonging to the node.
type LabeledStmt ¶
A LabeledStmt node represents a labeled statement.
func (*LabeledStmt) End ¶
func (s *LabeledStmt) End() token.Pos
End returns position of first character immediately after the node.
func (*LabeledStmt) Pos ¶
func (s *LabeledStmt) Pos() token.Pos
Pos returns position of first character belonging to the node.
type LambdaExpr ¶
type LambdaExpr struct {
First token.Pos
Lhs []*Ident
Rarrow token.Pos
Rhs []Expr
Last token.Pos
LhsHasParen bool
RhsHasParen bool
}
LambdaExpr represents one of the following expressions:
`(x, y, ...) => exprOrExprTuple` `x => exprOrExprTuple` `=> exprOrExprTuple`
here exprOrExprTuple represents
`expr` `(expr1, expr2, ...)`
func (*LambdaExpr) End ¶
func (p *LambdaExpr) End() token.Pos
End - position of first character immediately after the node.
func (*LambdaExpr) Pos ¶
func (p *LambdaExpr) Pos() token.Pos
Pos - position of first character belonging to the node.
type LambdaExpr2 ¶
type LambdaExpr2 struct {
First token.Pos
Lhs []*Ident
Rarrow token.Pos
Body *BlockStmt
LhsHasParen bool
}
LambdaExpr2 represents one of the following expressions:
`(x, y, ...) => { ... }`
`x => { ... }`
`=> { ... }`
func (*LambdaExpr2) End ¶
func (p *LambdaExpr2) End() token.Pos
End - position of first character immediately after the node.
func (*LambdaExpr2) Pos ¶
func (p *LambdaExpr2) Pos() token.Pos
Pos - position of first character belonging to the node.
type MapType ¶
A MapType node represents a map type.
type MatrixLit ¶
type MatrixLit struct {
Lbrack token.Pos // position of "["
Elts [][]Expr // list of matrix elements
Rbrack token.Pos // position of "]"
Incomplete bool // true if (source) expressions are missing in the Elts list
}
A MatrixLit node represents a matrix literal.
type MergeMode ¶
type MergeMode uint
The MergeMode flags control the behavior of MergePackageFiles.
const ( // FilterFuncDuplicates - If set, duplicate function declarations are excluded. FilterFuncDuplicates MergeMode = 1 << iota // FilterUnassociatedComments - If set, comments that are not associated with a specific // AST node (as Doc or Comment) are excluded. FilterUnassociatedComments // FilterImportDuplicates - If set, duplicate import declarations are excluded. FilterImportDuplicates )
type NumberUnitLit ¶
type NumberUnitLit struct {
ValuePos token.Pos // literal position
Kind token.Token // token.INT or token.FLOAT
Value string // literal string of the number; e.g. 42, 0x7f, 3.14, 1e-9
Unit string // unit string of the number; e.g. "px", "em", "rem"
}
A NumberUnitLit node represents a number with unit.
func (*NumberUnitLit) End ¶
func (x *NumberUnitLit) End() token.Pos
func (*NumberUnitLit) Pos ¶
func (x *NumberUnitLit) Pos() token.Pos
type ObjKind ¶
type ObjKind int
ObjKind describes what an object represents.
type Object ¶
type Object struct {
Kind ObjKind
Name string // declared name
Decl any // corresponding Field, XxxSpec, FuncDecl, LabeledStmt, AssignStmt, Scope; or nil
Data any // object-specific data; or nil
Type any // placeholder for type information; may be nil
}
An Object describes a named language entity such as a package, constant, type, variable, function (incl. methods), or label.
The Data fields contains object-specific data:
Kind Data type Data value Pkg *Scope package scope Con int iota for the respective declaration
type OverloadFuncDecl ¶
type OverloadFuncDecl struct {
Doc *CommentGroup // associated documentation; or nil
Func token.Pos // position of "func" keyword
Recv *FieldList // receiver (methods); or nil (functions)
Name *Ident // function/method name
Assign token.Pos // position of token "="
Lparen token.Pos // position of "("
Funcs []Expr // overload functions. here `Expr` can be *FuncLit, *Ident or *SelectorExpr
Rparen token.Pos // position of ")"
Operator bool // is operator or not
IsClass bool // recv set by class
}
OverloadFuncDecl node represents an overload function declaration:
`func name = (overloadFuncs)` `func (T).nameOrOp = (overloadFuncs)`
here overloadFunc represents
`func(params) results {...}` `funcName` `(*T).methodName`
func (*OverloadFuncDecl) End ¶
func (p *OverloadFuncDecl) End() token.Pos
End - position of first character immediately after the node.
func (*OverloadFuncDecl) Pos ¶
func (p *OverloadFuncDecl) Pos() token.Pos
Pos - position of first character belonging to the node.
type Package ¶
type Package struct {
Name string // package name
Imports map[string]*Object // map of package id -> package object
Files map[string]*File // XGo source files by filename
GoFiles map[string]*ast.File // Go source files by filename
}
A Package node represents a set of source files collectively building an XGo package.
type ParenExpr ¶
type ParenExpr struct {
Lparen token.Pos // position of "("
X Expr // parenthesized expression
Rparen token.Pos // position of ")"
}
A ParenExpr node represents a parenthesized expression.
type RangeExpr ¶
type RangeExpr struct {
First Expr // start of composite elements; or nil
To token.Pos // position of ":"
Last Expr // end of composite elements
Colon2 token.Pos // position of ":" or token.NoPos
Expr3 Expr // step (or max) of composite elements; or nil
}
A RangeExpr node represents a range expression.
type RangeStmt ¶
type RangeStmt struct {
For token.Pos // position of "for" keyword
Key, Value Expr // Key, Value may be nil
TokPos token.Pos // position of Tok; invalid if Key == nil
Tok token.Token // ILLEGAL if Key == nil, ASSIGN, DEFINE
X Expr // value to range over
Body *BlockStmt
NoRangeOp bool
}
A RangeStmt represents a for statement with a range clause.
type ReturnStmt ¶
type ReturnStmt struct {
Return token.Pos // position of "return" keyword
Results []Expr // result expressions; or nil
}
A ReturnStmt node represents a return statement.
func (*ReturnStmt) End ¶
func (s *ReturnStmt) End() token.Pos
End returns position of first character immediately after the node.
func (*ReturnStmt) Pos ¶
func (s *ReturnStmt) Pos() token.Pos
Pos returns position of first character belonging to the node.
type Scope ¶
A Scope maintains the set of named language entities declared in the scope and a link to the immediately surrounding (outer) scope.
func (*Scope) Insert ¶
Insert attempts to insert a named object obj into the scope s. If the scope already contains an object alt with the same name, Insert leaves the scope unchanged and returns alt. Otherwise it inserts obj and returns nil.
type SelectStmt ¶
type SelectStmt struct {
Select token.Pos // position of "select" keyword
Body *BlockStmt // CommClauses only
}
A SelectStmt node represents a select statement.
func (*SelectStmt) End ¶
func (s *SelectStmt) End() token.Pos
End returns position of first character immediately after the node.
func (*SelectStmt) Pos ¶
func (s *SelectStmt) Pos() token.Pos
Pos returns position of first character belonging to the node.
type SelectorExpr ¶
type SelectorExpr struct {
X Expr // expression
Sel *Ident // field selector (it may not be a simple identifier)
}
A SelectorExpr node represents an expression followed by a selector. Sel may not be a simple identifier. For example:
- x.field
- x."field-name"
- x.$attr
- x.$"attr-name"
- x.0, x.1, ...
- x.*
func (*SelectorExpr) End ¶
func (x *SelectorExpr) End() token.Pos
End returns position of first character immediately after the node.
func (*SelectorExpr) Pos ¶
func (x *SelectorExpr) Pos() token.Pos
Pos returns position of first character belonging to the node.
type SendStmt ¶
type SendStmt struct {
Chan Expr
Arrow token.Pos // position of "<-"
Values []Expr // len(Values) must > 0
Ellipsis token.Pos // position of "..."
}
A SendStmt node represents a send statement.
type SliceExpr ¶
type SliceExpr struct {
X Expr // expression
Lbrack token.Pos // position of "["
Low Expr // begin of slice range; or nil
High Expr // end of slice range; or nil
Max Expr // maximum capacity of slice; or nil
Slice3 bool // true if 3-index slice (2 colons present)
Rbrack token.Pos // position of "]"
}
A SliceExpr node represents an expression followed by slice indices.
type SliceLit ¶
type SliceLit struct {
Lbrack token.Pos // position of "["
Elts []Expr // list of slice elements; or nil
Rbrack token.Pos // position of "]"
Incomplete bool // true if (source) expressions are missing in the Elts list
}
A SliceLit node represents a slice literal.
type Spec ¶
type Spec interface {
Node
// contains filtered or unexported methods
}
The Spec type stands for any of *ImportSpec, *ValueSpec, and *TypeSpec.
type StarExpr ¶
A StarExpr node represents an expression of the form "*" Expression. Semantically it could be a unary "*" expression, or a pointer type.
type Stmt ¶
type Stmt interface {
Node
// contains filtered or unexported methods
}
Stmt interface: all statement nodes implement the Stmt interface.
type StringLitEx ¶
type StringLitEx struct {
Parts []any // can be (val string) or (xval Expr)
}
type StructType ¶
type StructType struct {
Struct token.Pos // position of "struct" keyword
Fields *FieldList // list of field declarations
Incomplete bool // true if (source) fields are missing in the Fields list
}
A StructType node represents a struct type.
func (*StructType) End ¶
func (x *StructType) End() token.Pos
End returns position of first character immediately after the node.
func (*StructType) Pos ¶
func (x *StructType) Pos() token.Pos
Pos returns position of first character belonging to the node.
type SwitchStmt ¶
type SwitchStmt struct {
Switch token.Pos // position of "switch" keyword
Init Stmt // initialization statement; or nil
Tag Expr // tag expression; or nil
Body *BlockStmt // CaseClauses only
}
A SwitchStmt node represents an expression switch statement.
func (*SwitchStmt) End ¶
func (s *SwitchStmt) End() token.Pos
End returns position of first character immediately after the node.
func (*SwitchStmt) Pos ¶
func (s *SwitchStmt) Pos() token.Pos
Pos returns position of first character belonging to the node.
type TupleLit ¶ added in v1.6.1
type TupleLit struct {
Lparen token.Pos // position of "("
Elts []Expr // list of tuple elements; or nil
Ellipsis token.Pos // position of "..." (token.NoPos if there is no "...")
Rparen token.Pos // position of ")"
}
A TupleLit node represents a tuple literal.
type TupleType ¶ added in v1.6.0
type TupleType struct {
Lparen token.Pos // position of "("
Fields *FieldList // tuple element types (and optional names)
Rparen token.Pos // position of ")"
}
A TupleType node represents a tuple type. Tuple types are syntactic sugar for anonymous structs with ordinal field names. Examples:
() ≡ struct{}
(T) ≡ T (degenerates to the type itself)
(T0, T1, ..., TN) ≡ struct{ _0 T0; _1 T1; ...; _N TN }
(name0 T0, name1 T1, ..., nameN TN) ≡ struct{ _0 T0; _1 T1; ...; _N TN }
Named fields are compile-time aliases only; runtime uses ordinal fields.
type TypeAssertExpr ¶
type TypeAssertExpr struct {
X Expr // expression
Lparen token.Pos // position of "("
Type Expr // asserted type; nil means type switch X.(type)
Rparen token.Pos // position of ")"
}
A TypeAssertExpr node represents an expression followed by a type assertion.
func (*TypeAssertExpr) End ¶
func (x *TypeAssertExpr) End() token.Pos
End returns position of first character immediately after the node.
func (*TypeAssertExpr) Pos ¶
func (x *TypeAssertExpr) Pos() token.Pos
Pos returns position of first character belonging to the node.
type TypeSpec ¶
type TypeSpec struct {
Doc *CommentGroup // associated documentation; or nil
Name *Ident // type name
TypeParams *FieldList // type parameters; or nil
Assign token.Pos // position of '=', if any
Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
Comment *CommentGroup // line comments; or nil
}
A TypeSpec node represents a type declaration (TypeSpec production).
type TypeSwitchStmt ¶
type TypeSwitchStmt struct {
Switch token.Pos // position of "switch" keyword
Init Stmt // initialization statement; or nil
Assign Stmt // x := y.(type) or y.(type)
Body *BlockStmt // CaseClauses only
}
A TypeSwitchStmt node represents a type switch statement.
func (*TypeSwitchStmt) End ¶
func (s *TypeSwitchStmt) End() token.Pos
End returns position of first character immediately after the node.
func (*TypeSwitchStmt) Pos ¶
func (s *TypeSwitchStmt) Pos() token.Pos
Pos returns position of first character belonging to the node.
type UnaryExpr ¶
type UnaryExpr struct {
OpPos token.Pos // position of Op
Op token.Token // operator
X Expr // operand
}
A UnaryExpr node represents a unary expression. Unary "*" expressions are represented via StarExpr nodes.
type ValueSpec ¶
type ValueSpec struct {
Doc *CommentGroup // associated documentation; or nil
Names []*Ident // value names (len(Names) > 0)
Type Expr // value type; or nil
Tag *BasicLit // classfile field tag; or nil
Values []Expr // initial values; or nil
Comment *CommentGroup // line comments; or nil
}
A ValueSpec node represents a constant or variable declaration (ConstSpec or VarSpec production).