Documentation ¶
Overview ¶
Package ast 实现了一个抽象语法树
创建抽象语法树 ¶
创建抽象语法树推荐使用 pkg/gitee.com/u-language/u-language/pkg/parser 提供的简便函数
从词法分析结果创建抽象语法树,只需要调用 NewTree
如果要进行错误处理请自行使用 pkg/gitee.com/u-language/u-language/pkg/errcode
辅助语义检查 ¶
- 会检查符号是否和其他符号重名
- 会检查枚举值是否重名
- 会检查是否调用禁止调用的init或main函数
Index ¶
- Constants
- Variables
- func Instatination(findTree func(string) *Tree, t *Tree, GenInstNodes *Sbt, LineNum int, ...)
- func RetType(ptr *Object, sbt *Sbt) string
- func RetTypeSize(Type string) int64deprecated
- type ASSIGNInfo
- type ASSIGNNode
- type AssignmentNode
- type AutoFreeNode
- type BlankLineNode
- type BreakStmt
- type CallNode
- type CaseNode
- type ConstNode
- type ContinueStmt
- type ContinuityType
- type DefaultNode
- type Dereference
- type ElseNode
- type EnumDecl
- type Expr
- type Field
- type ForNode
- type FuncInfo
- type FuncNameNode
- type FuncNode
- type GenericInstantiation
- func (g *GenericInstantiation) Copy() astdata.Typ
- func (g *GenericInstantiation) FuncName() string
- func (g *GenericInstantiation) SetLea(i int)
- func (g *GenericInstantiation) SetTyp()
- func (g *GenericInstantiation) String() string
- func (g *GenericInstantiation) Typ() string
- func (g *GenericInstantiation) Type() NodeEnum
- type GetImport
- type GotoStmt
- type IfNode
- type ImportInfo
- type IndexExpr
- type LabelNode
- type MLCEndNode
- type MLCInNode
- type MLCStartNode
- type MethodNode
- type MethodTableInfo
- type Node
- type NodeEnum
- type ObjKind
- type Object
- type Objects
- type OpExpr
- type OperationExpr
- type Package
- func (p *Package) AddFile(ft *lex.FileToken)
- func (p *Package) Dep() []data.IsItARecursiveType
- func (p *Package) FindTree(file string) *Tree
- func (p *Package) GerImportPackage() *map[string]*Package
- func (p *Package) GetImportLoacl() *[]data.IsItARecursiveType
- func (p *Package) GetImportTable() *Sbt
- func (p *Package) My() string
- func (p *Package) Parser()
- func (p *Package) String() string
- type ParserNodeState
- type RbraceNode
- type RemoveGenericsInfo
- type ReturnNode
- type Sbt
- func (s *Sbt) AddConst(n *ConstNode) errcode.ErrCode
- func (s *Sbt) AddEnum(n *EnumDecl) errcode.ErrCode
- func (v *Sbt) AddFunc(info *FuncInfo) errcode.ErrCode
- func (s *Sbt) AddGenInst(node *GenericInstantiation)
- func (s *Sbt) AddMethod(Type string, method *MethodNode) errcode.ErrCode
- func (s *Sbt) AddStruct(name string, decl *StructDecl) errcode.ErrCode
- func (s *Sbt) AddVar(name string, Type astdata.Typ, IsStackAlloc bool, LineNum int, FileName string) errcode.ErrCode
- func (v *Sbt) Copy() *Sbt
- func (v *Sbt) Have(name string) SymbolInfo
- func (v *Sbt) Have2(name string) (SymbolInfo, bool)
- func (s *Sbt) HaveImportSymbol(packageName, name string) (SymbolInfo, bool)
- func (s *Sbt) HaveImportType(packageName, name string) SymbolInfo
- func (s *Sbt) HaveMethod(Type string, Name string) SymbolInfo
- func (s *Sbt) HaveType(name string) SymbolInfo
- func (v *Sbt) Range(f func(key string, value SymbolInfo) bool)
- func (v *Sbt) String() string
- type SelfOpStmt
- type StructDecl
- func (s *StructDecl) C(buf *strings.Builder)
- func (s *StructDecl) CType() cenum.NodeEnum
- func (info *StructDecl) Dep() []data.IsItARecursiveType
- func (info *StructDecl) FindField(Name string) Field
- func (info *StructDecl) My() string
- func (s *StructDecl) String() string
- func (s *StructDecl) Type() NodeEnum
- type SwitchNode
- type SymbolInfo
- type Tree
- func (t *Tree) FindTree(file string) *Tree
- func (t *Tree) GerImportPackage() *map[string]*Package
- func (t *Tree) GetImportLoacl() *[]data.IsItARecursiveType
- func (t *Tree) GetImportTable() *Sbt
- func (t *Tree) Panic(line *lex.Line, msg errcode.Msg, err ...errcode.ErrCode)
- func (t *Tree) String() string
- type VarInfoSbt
- type VarInitTable
- type VarNode
Constants ¶
const (
File = iota
)
Variables ¶
var Builtin_func_info = map[string]SymbolInfo{ enum.Printf: NewSymbolInfo_Func(&FuncInfo{Name: enum.Printf, Parame: []astdata.Parame{astdata.NewNameAndType("format", NewObject(TypeObj, enum.String))}}), enum.Float: NewSymbolInfo_Func(&FuncInfo{Name: enum.Float, RetValue: []astdata.RetValue{astdata.NewNameAndType("", NewObject(TypeObj, enum.Float))}}), enum.Int: NewSymbolInfo_Func(&FuncInfo{Name: enum.Int, RetValue: []astdata.RetValue{astdata.NewNameAndType("", NewObject(TypeObj, enum.Int))}}), enum.Malloc: NewSymbolInfo_Func(&FuncInfo{Name: enum.Malloc, Parame: []astdata.Parame{astdata.NewNameAndType("type", NewObject(TypeObj, "T"))}, RetValue: []astdata.RetValue{astdata.NewNameAndType("ptr", NewObject(TypeObj, "&T"))}}), enum.Free: NewSymbolInfo_Func(&FuncInfo{Name: enum.Free, Parame: []astdata.Parame{astdata.NewNameAndType("ptr", NewObject(TypeObj, "&T"))}}), enum.UnsafeAdd: NewSymbolInfo_Func(&FuncInfo{Name: enum.UnsafeAdd, Parame: []astdata.Parame{astdata.NewNameAndType("ptr", NewObject(TypeObj, "&T")), astdata.NewNameAndType("offset", NewObject(TypeObj, enum.Int))}, RetValue: []astdata.RetValue{astdata.NewNameAndType("ptr", NewObject(TypeObj, "&T"))}}), enum.UnsafeConvert: NewSymbolInfo_Func(&FuncInfo{Name: enum.UnsafeConvert, Parame: []astdata.Parame{astdata.NewNameAndType("ptr", NewObject(TypeObj, enum.UnsafePointer)), astdata.NewNameAndType("type", NewObject(TypeObj, "T"))}, RetValue: []astdata.RetValue{astdata.NewNameAndType("ptr", NewObject(TypeObj, "&T"))}}), enum.UnsafeSizeof: NewSymbolInfo_Func(&FuncInfo{Name: enum.UnsafeSizeof, Parame: []astdata.Parame{astdata.NewNameAndType("type", NewObject(TypeObj, "T"))}, RetValue: []astdata.RetValue{astdata.NewNameAndType("size", NewObject(TypeObj, enum.Int))}}), enum.MallocSize: NewSymbolInfo_Func(&FuncInfo{Name: enum.MallocSize, Parame: []astdata.Parame{astdata.NewNameAndType("size", NewObject(TypeObj, enum.Int))}, RetValue: []astdata.RetValue{astdata.NewNameAndType("ptr", NewObject(TypeObj, enum.UnsafePointer))}}), enum.MemPoolFree: SymbolInfo{}, enum.MemPoolNew: SymbolInfo{}, enum.UnsafePointer: SymbolInfo{}, }
预定义的函数或视为函数调用的类型转换
var Deferfunc func() = utils.Deferfunc
var FirstLineNoPackageDeclOn = false
缩写 The first line does not have a package declaration 缩写成FirstLineNoPackageDecl 控制是否允许第一行没有包声明
var NdSotfOn = false
有测试依赖函数体外的非声明语句,设置为true可以恢复之前的行为 缩写 Non declarative statements outside of a function 缩写成NdSotf
var ( NodeEnumSrtMap = [...]string{ VAR: "var (变量节点)", FUNC: "func (函数节点)", ASSIGN: "assign (赋值节点)", OPEXPR: "opexpr (运算表达式节点)", OBJECT: "object (对象节点)", BlankLine: "blankline (空行节点)", Rbrace: "rbrace(右大括号节点)", Lbrace: "lbrace (左大括号节点)", IF: "if (if 节点)", Else: "else (else 节点)", MLCStart: "Start of multiline comment (多行注释开头)", MLCEnd: "End of multiline comment(多行注释结束)", MLCIn: "In multiline comments (在多行注释中)", For: "for(for语句)", Call: "call(调用节点)", Return: "return (返回语句)", GOTO: "goto (语句)", Label: "label (标签)", Break: "break", Continue: "continue", Const: "const (常量节点)", Struct: "strcut (结构体)", ObjectsEnum: "ObjectsEnum (多个object)", SelfOpStmtEnum: "SelfOpStmtEnum (自操作语句)", Switch: "switch", Case: "case", Default: "default", Method: "method (方法)", AutoFree: "autofree (自动释放块)", Enum: "enum (枚举声明)", ContinuityTypeEnum: "ContinuityTypeEnum (连续类型)", IndexExprEnum: "IndexExprEnum (索引表达式)", GenInst: "GenericInstantiation (泛型实例化)", Deref: "dereference (解引用节点)", } )
var ( ObjKindSrtMap = [...]string{ NoKind: "nokind (未定义的枚举)", INTOBJ: "intobj (整数)", FLOATOBJ: "floatobj (浮点数)", BoolObj: "boolobj (布尔值)", StringObj: "stringobj(字符串)", SymbolObj: "SymbolObj (符号)", LeaObj: "leaObj (取地址)", DerefObj: "derefObj (解引用)", StructPtr: "StructPtr (结构体指针)", NilObj: "NilObj (指针的零值)", EnumObj: "EnumObj (枚举值)", TypeObj: "TypeObj(类型)", } )
var ( TypeEnumStrMap = map[string]struct{}{ "int": struct{}{}, "string": struct{}{}, "bool": struct{}{}, "float": struct{}{}, enum.UnsafePointer: struct{}{}, "any": struct{}{}, } )
Functions ¶
func Instatination ¶
func RetTypeSize
deprecated
Types ¶
type ASSIGNInfo ¶
type ASSIGNInfo struct { Ptr *ASSIGNNode LineNum int }
type ASSIGNNode ¶
type ASSIGNNode = AssignmentNode
func (*ASSIGNNode) String ¶
func (a *ASSIGNNode) String() string
func (*ASSIGNNode) Type ¶
func (a *ASSIGNNode) Type() NodeEnum
type AutoFreeNode ¶
type AutoFreeNode struct { Expr Expr // contains filtered or unexported fields }
自动释放块节点
func NewAutoFreeNode ¶
func NewAutoFreeNode(Thread bool) *AutoFreeNode
func (*AutoFreeNode) String ¶
func (a *AutoFreeNode) String() string
func (*AutoFreeNode) Type ¶
func (a *AutoFreeNode) Type() NodeEnum
type BlankLineNode ¶
type BlankLineNode struct{}
空行节点
func NewBlinkLineNode ¶
func NewBlinkLineNode() BlankLineNode
func (BlankLineNode) C ¶
func (b BlankLineNode) C(buf *strings.Builder)
func (BlankLineNode) CType ¶
func (b BlankLineNode) CType() cenum.NodeEnum
func (BlankLineNode) String ¶
func (b BlankLineNode) String() string
func (BlankLineNode) Type ¶
func (b BlankLineNode) Type() NodeEnum
type CallNode ¶
type CallNode struct { FuncName FuncNameNode //调用函数名 Parame []Expr //Parameter InAutoFree bool }
函数调用节点
func NewCallExpr ¶
func NewCallExpr(funcname FuncNameNode, InAutoFree bool, parame ...Expr) *CallNode
NewCallNode 创建函数调用节点
type ContinueStmt ¶
type ContinueStmt struct{}
continue语句
func NewContinueStmt ¶
func NewContinueStmt() ContinueStmt
func (ContinueStmt) C ¶
func (c ContinueStmt) C(buf *strings.Builder)
func (ContinueStmt) CType ¶
func (c ContinueStmt) CType() cenum.NodeEnum
func (ContinueStmt) String ¶
func (c ContinueStmt) String() string
func (ContinueStmt) Type ¶
func (c ContinueStmt) Type() NodeEnum
type ContinuityType ¶
ContinuityType 连续类型
func NewContinuityType ¶
func NewContinuityType(Len Expr, Type astdata.Typ, UStr string) *ContinuityType
func (*ContinuityType) Copy ¶
func (c *ContinuityType) Copy() astdata.Typ
func (*ContinuityType) SetLea ¶
func (c *ContinuityType) SetLea(i int)
func (*ContinuityType) SetTyp ¶
func (c *ContinuityType) SetTyp()
func (*ContinuityType) String ¶
func (c *ContinuityType) String() string
func (*ContinuityType) Typ ¶
func (c *ContinuityType) Typ() string
func (*ContinuityType) Type ¶
func (c *ContinuityType) Type() NodeEnum
type DefaultNode ¶
defaultcase节点
func NewDefaultNode ¶
func NewDefaultNode(Thread bool) *DefaultNode
func (*DefaultNode) C ¶
func (c *DefaultNode) C(buf *strings.Builder)
func (*DefaultNode) CType ¶
func (d *DefaultNode) CType() cenum.NodeEnum
func (*DefaultNode) String ¶
func (d *DefaultNode) String() string
func (*DefaultNode) Type ¶
func (d *DefaultNode) Type() NodeEnum
type Dereference ¶
type Dereference struct {
Value Expr
}
Dereference 解引用节点
func (*Dereference) String ¶
func (d *Dereference) String() string
func (*Dereference) Type ¶
func (d *Dereference) Type() NodeEnum
type ElseNode ¶
type ElseNode struct { BoolExpr Expr // contains filtered or unexported fields }
else节点
type Field ¶
type Field = astdata.NameAndType
type ForNode ¶
type ForNode struct { InitStmt Node BoolExpr Expr EndStmt Node // contains filtered or unexported fields }
for节点
type FuncInfo ¶
type FuncInfo struct { Name string FileName string Parame []astdata.Parame RetValue []astdata.RetValue TypeParame []astdata.NameAndType LineNum int }
FuncInfo 函数信息
type FuncNameNode ¶
type GenericInstantiation ¶
type GenericInstantiation struct { BaseName astdata.Typ LineNum int ActualType []astdata.Typ FileName string }
GenericInstantiation 泛型实例化
func (*GenericInstantiation) Copy ¶
func (g *GenericInstantiation) Copy() astdata.Typ
func (*GenericInstantiation) FuncName ¶
func (g *GenericInstantiation) FuncName() string
func (*GenericInstantiation) SetLea ¶
func (g *GenericInstantiation) SetLea(i int)
func (*GenericInstantiation) SetTyp ¶
func (g *GenericInstantiation) SetTyp()
func (*GenericInstantiation) String ¶
func (g *GenericInstantiation) String() string
func (*GenericInstantiation) Typ ¶
func (g *GenericInstantiation) Typ() string
func (*GenericInstantiation) Type ¶
func (g *GenericInstantiation) Type() NodeEnum
type GetImport ¶
type GetImport interface { //导入表 GetImportTable() *Sbt //自己及依赖导入的包 GerImportPackage() *map[string]*Package //自己导入的包 GetImportLoacl() *[]data.IsItARecursiveType }
type ImportInfo ¶
type ImportInfo struct {
Path string
}
ImportInfo 导入信息
func (ImportInfo) String ¶
func (info ImportInfo) String() string
type MLCEndNode ¶
type MLCEndNode struct{}
多行注释结束节点
func NewMLCEndNode ¶
func NewMLCEndNode() MLCEndNode
func (MLCEndNode) String ¶
func (b MLCEndNode) String() string
func (MLCEndNode) Type ¶
func (b MLCEndNode) Type() NodeEnum
type MLCInNode ¶
type MLCInNode struct{}
多行注释中节点 In multiline comments 为了统一多行注释前缀写为MLCIn
func NewMLCInNode ¶
func NewMLCInNode() MLCInNode
type MLCStartNode ¶
type MLCStartNode struct{}
多行注释开头节点
func NewMLCStartNode ¶
func NewMLCStartNode() MLCStartNode
func (MLCStartNode) String ¶
func (b MLCStartNode) String() string
func (MLCStartNode) Type ¶
func (b MLCStartNode) Type() NodeEnum
type MethodNode ¶
MethodNode 方法节点
func NewMethodNode ¶
func NewMethodNode(typ string, info *FuncInfo, Thread bool) *MethodNode
NewMethodNode 创建函数节点
func (*MethodNode) String ¶
func (m *MethodNode) String() string
func (*MethodNode) Type ¶
func (m *MethodNode) Type() NodeEnum
type MethodTableInfo ¶
type MethodTableInfo struct {
Infos *Sbt
}
func NewMethodTableInfo ¶
func NewMethodTableInfo(Thread bool) MethodTableInfo
func (MethodTableInfo) String ¶
func (info MethodTableInfo) String() string
type Node ¶
节点接口,代表一个抽象语法树节点
func ParserNode ¶
ParserNode 解析几行已经完成词法分析的代码,并返回自动生成的节点
- tree是抽象语法树, Tree.LVarTable Tree.Sbt 不能为空
- lines是词法分析结果
- sbt是被使用的符号表
- index是被解析开始行偏移量
- end是被结束开始行偏移量
- ret是结果保存切片,为nil将自动分配一个长度为len(lines)的
- IsFunc是被解析结果是否在函数内
- Thread控制是否并发
对同一个 Tree 同时调用 ParserNode 有数据竞争可能
type Objects ¶
func NewObjects ¶
type OperationExpr ¶
type OperationExpr struct { Src1 Expr Src2 Expr OP enum.OPSymbol IsStr bool //是否是字符串类型,由check处理 Inparen bool //是否在小括号内 }
运算表达式节点
type Package ¶
type Package struct { //导入表 ImportTable *Sbt PackageName atomic.Pointer[string] //在自动释放块被调用的函数名 InAutoFreeFuncCallName data.RemoveDupStrck[FuncNameNode] //符号表 Sbt *Sbt //泛型表 GenericTable *Sbt //泛型实例化节点 GenInstNodes *Sbt //自己及依赖导入的包 ImportPackage map[string]*Package Dir string //自己导入的包 ImportLoacl []data.IsItARecursiveType //变量初始化 VarInitTable_Global VarInitTable //保存抽象语法树 Trees data.Slice[*Tree] //全局声明数量 Number of globar declarations GlobarDeclNum atomic.Uint32 //是否有init函数 IsInitFunc atomic.Bool //是否有自动释放块 IsHaveAutoFree atomic.Bool //并发 Thread bool // contains filtered or unexported fields }
Package 管理一个包的所有源代码文件的抽象语法树
func (*Package) Dep ¶
func (p *Package) Dep() []data.IsItARecursiveType
func (*Package) GerImportPackage ¶
func (*Package) GetImportLoacl ¶
func (p *Package) GetImportLoacl() *[]data.IsItARecursiveType
func (*Package) GetImportTable ¶
type ParserNodeState ¶
type ParserNodeState struct { //解析结果的保存切片,如果为nil,[ParserNode]会自动创建一个 Ret []Node //被解析的词法分析结果开头偏移量 Index int //被解析的词法分析结果结尾偏移量(解析时这个偏移量的词法分析结果不会被处理) End int //是否在解析函数内,如果是,函数信息 FuncInfo *FuncInfo //控制是否并发 Thread bool //is recursion 是否递归 IsRecursion bool //是否在自动释放块 InAutoFree bool }
ParserNodeState 是 ParserNode 的可选参数
type RbraceNode ¶
type RbraceNode struct{}
右大括号节点
func NewRbraceNode ¶
func NewRbraceNode() RbraceNode
func (RbraceNode) C ¶
func (b RbraceNode) C(buf *strings.Builder)
func (RbraceNode) CType ¶
func (b RbraceNode) CType() cenum.NodeEnum
func (RbraceNode) String ¶
func (b RbraceNode) String() string
func (RbraceNode) Type ¶
func (b RbraceNode) Type() NodeEnum
type RemoveGenericsInfo ¶
func (RemoveGenericsInfo) String ¶
func (info RemoveGenericsInfo) String() string
type ReturnNode ¶
type ReturnNode struct {
RetValue Expr
}
return节点
func (*ReturnNode) String ¶
func (l *ReturnNode) String() string
func (*ReturnNode) Type ¶
func (l *ReturnNode) Type() NodeEnum
type Sbt ¶
type Sbt struct { //变量总大小,为兼容之前的VAT存在 Size int64 //是否并发 Thread bool // contains filtered or unexported fields }
Sbt 符号表 symbolTable
func (*Sbt) AddGenInst ¶
func (s *Sbt) AddGenInst(node *GenericInstantiation)
AddGenInst 记录泛型实例化信息
- node是泛型实例化节点
func (*Sbt) AddMethod ¶
func (s *Sbt) AddMethod(Type string, method *MethodNode) errcode.ErrCode
AddMethod 记录方法 有错返回错误码
- Type是方法所属的类型名
- FuncInfo是函数的信息
func (*Sbt) AddStruct ¶
func (s *Sbt) AddStruct(name string, decl *StructDecl) errcode.ErrCode
AddStruct 记录结构体 有错返回错误码
- name是变量名
- FieldTable是字段表
func (*Sbt) AddVar ¶
func (s *Sbt) AddVar(name string, Type astdata.Typ, IsStackAlloc bool, LineNum int, FileName string) errcode.ErrCode
AddVar 记录变量 有错返回错误码
- name是变量名
- Type是类型字符串
- IsStackAlloc是否在栈中分配
func (*Sbt) Have ¶
func (v *Sbt) Have(name string) SymbolInfo
Have 查询是否记录了符号
- name是符号名
如果符号不存在,被设计为程序不应继续执行,将panic
func (*Sbt) Have2 ¶
func (v *Sbt) Have2(name string) (SymbolInfo, bool)
Have2 查询是否记录了符号
- name是符号名
如果符号不存在,被设计为程序不应继续执行,将panic
func (*Sbt) HaveImportSymbol ¶
func (s *Sbt) HaveImportSymbol(packageName, name string) (SymbolInfo, bool)
HaveImportSymbol 查询导入符号
- packageName是被导入的包名
- name是被导入的符号名
func (*Sbt) HaveImportType ¶
func (s *Sbt) HaveImportType(packageName, name string) SymbolInfo
HaveImportType 查询导入类型
- packageName是被导入的包名
- name是被导入的类型名
如果被导入的包没有类型名,将panic
func (*Sbt) HaveMethod ¶
func (s *Sbt) HaveMethod(Type string, Name string) SymbolInfo
HaveMethod 查询是否记录了方法
- Type是类型名
- Name是函数的名字
如果符号不存在,返回空信息
func (*Sbt) HaveType ¶
func (s *Sbt) HaveType(name string) SymbolInfo
HaveType 查询是否记录了指定类型的符号
- name是符号名
如果符号不存在,被设计为程序不应继续执行,将panic
type SelfOpStmt ¶
自操作语句 缩写: Self-operating statement 缩写成 SelfOpStmt 源操作数只可能是下列类型
- 对象节点 ast.Object
func NewSelfOpStmt ¶
func NewSelfOpStmt(OP enum.OPSymbol, Dest Expr) *SelfOpStmt
func (*SelfOpStmt) String ¶
func (o *SelfOpStmt) String() string
func (*SelfOpStmt) Type ¶
func (o *SelfOpStmt) Type() NodeEnum
type StructDecl ¶
type StructDecl struct { Name string FileName string FieldTable []Field LineNum int TypeParame []astdata.NameAndType // contains filtered or unexported fields }
StructDecl 结构体声明
缩写:struct declaration 缩写成:StructDecl
func NewStructDecl ¶
func NewStructDecl(Name string) *StructDecl
func (*StructDecl) C ¶
func (s *StructDecl) C(buf *strings.Builder)
func (*StructDecl) CType ¶
func (s *StructDecl) CType() cenum.NodeEnum
func (*StructDecl) Dep ¶
func (info *StructDecl) Dep() []data.IsItARecursiveType
func (*StructDecl) FindField ¶
func (info *StructDecl) FindField(Name string) Field
FindField 寻找结构体字段中是否有Name 返回值Field.Name==""表示结构体字段中没有要查询到
func (*StructDecl) My ¶
func (info *StructDecl) My() string
func (*StructDecl) String ¶
func (s *StructDecl) String() string
func (*StructDecl) Type ¶
func (s *StructDecl) Type() NodeEnum
type SwitchNode ¶
type SwitchNode struct { Expr Expr // contains filtered or unexported fields }
switch节点
func NewSwitchNode ¶
func NewSwitchNode(Thread bool) *SwitchNode
func (*SwitchNode) String ¶
func (s *SwitchNode) String() string
func (*SwitchNode) Type ¶
func (s *SwitchNode) Type() NodeEnum
type SymbolInfo ¶
SymbolInfo 符号信息
func NewSymbolInfo_Func ¶
func NewSymbolInfo_Func(info *FuncInfo) SymbolInfo
NewSymbolInfo_Func 创建函数符号信息
func NewSymbolInfo_Var ¶
func NewSymbolInfo_Var(info VarInfoSbt) SymbolInfo
func (*SymbolInfo) Name ¶
func (s *SymbolInfo) Name() string
func (*SymbolInfo) PtrFuncInfo ¶
func (s *SymbolInfo) PtrFuncInfo() *FuncInfo
PtrFuncInfo 将SymbolInfo的Info字段解释为FuncInfo,并返回指针
func (*SymbolInfo) PtrStructDecl ¶
func (s *SymbolInfo) PtrStructDecl() *StructDecl
PtrStructDecl 将SymbolInfo的Info字段解释为StructInfo指针,并返回
func (*SymbolInfo) PtrVarInfoSbt ¶
func (s *SymbolInfo) PtrVarInfoSbt() VarInfoSbt
PtrVarVarInfoSbt 将SymbolInfo的Info字段解释为VarInfoSbt,并返回
func (SymbolInfo) String ¶
func (s SymbolInfo) String() string
func (*SymbolInfo) Type ¶
func (s *SymbolInfo) Type() string
type Tree ¶
type Tree struct { //自己导入的包 ImportLoacl *[]data.IsItARecursiveType //是否有自动是否块 IsHaveAutoFree *atomic.Bool //符号表 Sbt *Sbt //全局声明数量 GlobarDeclNum *atomic.Uint32 //自己及依赖导入的包 ImportPackage *map[string]*Package //是否有init函数 IsInitFunc *atomic.Bool //变量初始化表 VarInitTable_File *VarInitTable //在自动是否块被调用的函数名 InAutoFreeFuncCallName *data.RemoveDupStrck[FuncNameNode] //导入表 ImportTable *Sbt //泛型表 GenericTable *Sbt //泛型实例化节点 GenInstNodes *Sbt //包名 PackageName string //文件名称 Filename string //所有节点 Nodes []Node //是否并发 Thread bool // contains filtered or unexported fields }
一个抽象语法树
func (*Tree) GerImportPackage ¶
func (*Tree) GetImportLoacl ¶
func (t *Tree) GetImportLoacl() *[]data.IsItARecursiveType
func (*Tree) GetImportTable ¶
type VarInfoSbt ¶
type VarInfoSbt struct { Name string Type astdata.Typ //后两个用于出错时报错 FileName string LineNum int //是否是全局 IsStackAlloc bool }
VarInfoSbt 变量符号信息
func NewVarInfoSbt ¶
func NewVarInfoSbt(Name string, Type astdata.Typ, IsStackAlloc bool, LineNum int, FileName string) VarInfoSbt
创建变量符号信息
func (VarInfoSbt) String ¶
func (info VarInfoSbt) String() string
type VarInitTable ¶
type VarInitTable struct { data.Slice[ASSIGNInfo] // contains filtered or unexported fields }
VarInitTable 变量初始化表 实现了 sort.Interface 接口
func (*VarInitTable) InitOrder ¶
func (t *VarInitTable) InitOrder() []ASSIGNInfo
InitOrder 返回按行升序排列的变量初始化信息
func (*VarInitTable) Len ¶
func (t *VarInitTable) Len() int
func (*VarInitTable) Less ¶
func (t *VarInitTable) Less(i, j int) bool
func (*VarInitTable) Swap ¶
func (t *VarInitTable) Swap(i, j int)