xast

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeNameMapPrefix   = "map["
	TypeNameArrayPrefix = "array["
	TypeNameSlicePrefix = "slice["
)

Variables

View Source
var AstMetaKey = "xxxxx"
View Source
var (
	EmptyTopTree = TopNode{}
)

Functions

func IsArrayType

func IsArrayType(typeName string) bool

func IsMapType

func IsMapType(typeName string) bool

func IsSliceOrArrayType

func IsSliceOrArrayType(typeName string) bool

func IsSliceType

func IsSliceType(typeName string) bool

func IsSpecBuildIn

func IsSpecBuildIn(typeName string) bool

Types

type AstMeta

type AstMeta struct {
	VarName     string   // 声明
	SysType     string   // 系统类型名
	FullName    string   // 全名
	RawExpr     ast.Expr // array: *ast.ArrayType, map: *ast.MapType, struct: *ast.Ident, it will be nil it cross file struct happen
	Comment     *ast.CommentGroup
	Doc         *ast.CommentGroup
	CrossModule bool // 是否有可能引用跨模块或者跨文件的类型,只是有可能,并不一定是
}

func NewAstMeta

func NewAstMeta(varName, sysType, fullName string, comment, doc *ast.CommentGroup, crossModule bool, rawExpr ast.Expr) AstMeta

func (*AstMeta) Copy

func (meta *AstMeta) Copy() *AstMeta

type ExtraNode

type ExtraNode struct {
	TypeName    string
	Meta        interface{}           `json:",omitempty"`
	LeavesNodes map[string]*LeafNode  `json:",omitempty"` // key => varName
	ExtraNodes  map[string]*ExtraNode `json:",omitempty"` // key => varName
	WalkPath    string                `json:",omitempty"`
}

ExtraNode include type: map, array, struct

func NewExtraNode

func NewExtraNode(typeName string,
	walkPath string,
	meta interface{},
	extraNodes map[string]*ExtraNode,
	leaves map[string]*LeafNode) *ExtraNode

func (*ExtraNode) Copy

func (extraNode *ExtraNode) Copy() *ExtraNode

type LeafNode

type LeafNode struct {
	TypeName string
	Meta     interface{} `json:",omitempty"`
	WalkPath string      `json:",omitempty"`
}

LeafNode include type: int8,uint8,int16,uint16,int32,uint32,int,int64,uint64,float32,float64,byte,string

func NewLeafNode

func NewLeafNode(typeName string, walkPath string, meta interface{}) *LeafNode

func (*LeafNode) Copy

func (leafNode *LeafNode) Copy() *LeafNode

type TopNode

type TopNode struct {
	TypeName    string
	LeavesNodes map[string]*LeafNode  `json:",omitempty"` // key => varName
	ExtraNodes  map[string]*ExtraNode `json:",omitempty"` // key => varName
	Meta        interface{}
}

TopNode: current only support struct

func NewTopNode

func NewTopNode(typeName string,
	Leaves map[string]*LeafNode,
	extraNodes map[string]*ExtraNode,
	meta interface{}) *TopNode

func (*TopNode) AfterInsertExtraNode

func (topNode *TopNode) AfterInsertExtraNode(parentWalkPath, varName string, extraNode ExtraNode) error

Parent Node Must be topNode or ExtraNode

func (*TopNode) AfterInsertLeafNode

func (topNode *TopNode) AfterInsertLeafNode(parentWalkPath, varName string, leafNode LeafNode) error

Parent Node Must be topNode or ExtraNode

func (*TopNode) BreadthFirst

func (topNode *TopNode) BreadthFirst(ctx context.Context, walkFunc WalkFunc)

func (*TopNode) DepthCount

func (topNode *TopNode) DepthCount() int

func (*TopNode) DepthFirst

func (topNode *TopNode) DepthFirst(ctx context.Context, walkFunc WalkFunc)

func (*TopNode) FindNode

func (topNode *TopNode) FindNode(walkPath string) (targetNode interface{}, ok bool)

func (*TopNode) FindNodesByFullNames

func (topNode *TopNode) FindNodesByFullNames(fullNames []string) (targetNodes []interface{})

注意map[key]value 和 value 以及 []xxxx 和 xxxx的比较

func (*TopNode) FindNodesBySimpleNames

func (topNode *TopNode) FindNodesBySimpleNames(simpleNames []string, simpleFn func(node interface{}) string) (targetNodes []interface{})

func (*TopNode) NodeCount

func (topNode *TopNode) NodeCount() int

func (*TopNode) ReBuildWalkPath

func (topNode *TopNode) ReBuildWalkPath()

type WalkFunc

type WalkFunc func(ctx context.Context, walkPath string, node interface{}) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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