package syntax import "mxc/token" type Node interface { Pos() token.Pos SetPos(token.Pos) aNode() } type node struct { pos token.Pos } func (n *node) Pos() (p token.Pos) { return n.pos } func (n *node) SetPos(pos token.Pos) { n.pos = pos } func (*node) aNode() {} type File struct { Pragma Pragma PkgName *Name DeclList []Decl EOF token.Pos GoVersion string node } type ( Decl interface { Node aDecl() } ImportDecl struct { Group *Group Pragma Pragma LocalPkgName *Name Path *BasicLit decl } ConstDecl struct { Group *Group Pragma Pragma NameList []*Name Type Expr Values Expr decl } TypeDecl struct { Group *Group Pragma Pragma Name *Name TParamList []*Field Alias bool Type Expr decl } VarDecl struct { Group *Group Pragma Pragma NameList []*Name Type Expr Values Expr decl } FuncDecl struct { Pragma Pragma Recv *Field Name *Name TParamList []*Field Type *FuncType Body *BlockStmt decl } ) type decl struct{ node } func (*decl) aDecl() {} type Group struct { _ int32 } func NewName(pos token.Pos, value string) (n *Name) { n := &Name{} n.pos = pos n.Value = value return n } type ( Expr interface { Node typeInfo aExpr() } BadExpr struct { expr } Name struct { Value string expr } BasicLit struct { Value string Kind token.LitKind Bad bool expr } CompositeLit struct { Type Expr ElemList []Expr NKeys int32 Rbrace token.Pos expr } KeyValueExpr struct { Key, Value Expr expr } FuncLit struct { Type *FuncType Body *BlockStmt expr } ParenExpr struct { X Expr expr } SelectorExpr struct { X Expr Sel *Name expr } IndexExpr struct { X Expr Index Expr expr } SliceExpr struct { X Expr Index [3]Expr Full bool expr } AssertExpr struct { X Expr Type Expr expr } TypeSwitchGuard struct { Lhs *Name X Expr expr } Operation struct { Op token.Operator X, Y Expr expr } CallExpr struct { Fun Expr ArgList []Expr HasDots bool expr } ListExpr struct { ElemList []Expr expr } ArrayType struct { Len Expr Elem Expr expr } SliceType struct { Elem Expr expr } DotsType struct { Elem Expr expr } StructType struct { FieldList []*Field TagList []*BasicLit expr } Field struct { Name *Name Type Expr node } InterfaceType struct { MethodList []*Field expr } FuncType struct { ParamList []*Field ResultList []*Field expr } MapType struct { Key, Value Expr expr } ChanType struct { Dir ChanDir Elem Expr expr } ) type Type interface { Underlying() Type String() string } type typeInfo interface { SetTypeInfo(TypeAndValue) GetTypeInfo() TypeAndValue } type ConstVal = interface{ String() string } type TypeAndValue struct { Type Type Value ConstVal exprFlags } type exprFlags uint16 func (f exprFlags) IsVoid() (ok bool) { return f&1 != 0 } func (f exprFlags) IsType() (ok bool) { return f&2 != 0 } func (f exprFlags) IsBuiltin() (ok bool) { return f&4 != 0 } func (f exprFlags) IsValue() (ok bool) { return f&8 != 0 } func (f exprFlags) IsNil() (ok bool) { return f&16 != 0 } func (f exprFlags) Addressable() (ok bool) { return f&32 != 0 } func (f exprFlags) Assignable() (ok bool) { return f&64 != 0 } func (f exprFlags) HasOk() (ok bool) { return f&128 != 0 } func (f exprFlags) IsRuntimeHelper() (ok bool) { return f&256 != 0 } func (f *exprFlags) SetIsVoid() { *f |= 1 } func (f *exprFlags) SetIsType() { *f |= 2 } func (f *exprFlags) SetIsBuiltin() { *f |= 4 } func (f *exprFlags) SetIsValue() { *f |= 8 } func (f *exprFlags) SetIsNil() { *f |= 16 } func (f *exprFlags) SetAddressable() { *f |= 32 } func (f *exprFlags) SetAssignable() { *f |= 64 } func (f *exprFlags) SetHasOk() { *f |= 128 } func (f *exprFlags) SetIsRuntimeHelper() { *f |= 256 } type typeAndValue struct { tv TypeAndValue } func (x *typeAndValue) SetTypeInfo(tv TypeAndValue) { x.tv = tv } func (x *typeAndValue) GetTypeInfo() (t TypeAndValue) { return x.tv } type expr struct { node typeAndValue } func (*expr) aExpr() {} type ChanDir uint32 const ( _ ChanDir = iota SendOnly RecvOnly ) type ( Stmt interface { Node aStmt() } SimpleStmt interface { Stmt aSimpleStmt() } EmptyStmt struct { simpleStmt } LabeledStmt struct { Label *Name Stmt Stmt stmt } BlockStmt struct { List []Stmt Rbrace token.Pos stmt } ExprStmt struct { X Expr simpleStmt } SendStmt struct { Chan, Value Expr simpleStmt } DeclStmt struct { DeclList []Decl stmt } AssignStmt struct { Op token.Operator Lhs, Rhs Expr simpleStmt } BranchStmt struct { Tok token.Token Label *Name Target Stmt stmt } CallStmt struct { Tok token.Token Call Expr DeferAt Expr stmt } ReturnStmt struct { Results Expr stmt } IfStmt struct { Init SimpleStmt Cond Expr Then *BlockStmt Else Stmt stmt } ForStmt struct { Init SimpleStmt Cond Expr Post SimpleStmt Body *BlockStmt stmt } SwitchStmt struct { Init SimpleStmt Tag Expr Body []*CaseClause Rbrace token.Pos stmt } SelectStmt struct { Body []*CommClause Rbrace token.Pos stmt } ) type ( RangeClause struct { Lhs Expr Def bool X Expr simpleStmt } CaseClause struct { Cases Expr Body []Stmt Colon token.Pos node } CommClause struct { Comm SimpleStmt Body []Stmt Colon token.Pos node } ) type stmt struct{ node } func (stmt) aStmt() {} type simpleStmt struct { stmt } func (simpleStmt) aSimpleStmt() {} type CommentKind uint32 const ( Above CommentKind = iota Below Left Right ) type Comment struct { Kind CommentKind Text string Next *Comment }