Documentation
¶
Overview ¶
Package ast 实现了一个抽象语法树
创建抽象语法树 ¶
创建抽象语法树推荐使用 pkg/gitee.com/u-language/u-language/ucom/parser 提供的简便函数
从词法分析结果创建抽象语法树,只需要调用 NewTree
如果要进行错误处理请自行使用 pkg/gitee.com/u-language/u-language/ucom/errcode
辅助语义检查 ¶
- 会检查符号是否和其他符号重名
- 会检查枚举值是否重名
- 会检查是否调用禁止调用的init或main函数
- 会检查非main包是否有main函数
Index ¶
- 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 BreakStmt
- type CDecl
- type CHeaderFile
- type CType
- 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) C(buf *strings.Builder)
- 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
- type GetImport
- type GotoStmt
- type IfNode
- type ImportInfo
- type IndexExpr
- type LabelNode
- type MethodNode
- type MethodTableInfo
- type Node
- type ObjKind
- type Object
- type Objects
- type OpExpr
- type OperationExpr
- type Package
- func (p *Package) AddFile(ft *lex.FileToken)
- func (p *Package) Dep(i int) data.IsItARecursiveType
- func (p *Package) DepLen() int
- 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) 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) CDecl(buf *strings.Builder)
- func (info *StructDecl) Dep(i int) data.IsItARecursiveType
- func (info *StructDecl) DepLen() int
- func (info *StructDecl) FindField(Name string) Field
- func (info *StructDecl) My() string
- func (s *StructDecl) String() string
- 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 ¶
This section is empty.
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 Num0 = NewObject(INTOBJ, "0")
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) C ¶
func (a *ASSIGNNode) C(buf *strings.Builder)
func (*ASSIGNNode) SetNosemicolon ¶
func (a *ASSIGNNode) SetNosemicolon(nosemicolon bool)
func (*ASSIGNNode) String ¶
func (a *ASSIGNNode) String() string
type AssignmentNode ¶
type AssignmentNode struct {
//目的操作数,源操作数
Dest Expr
Src Expr
// contains filtered or unexported fields
}
赋值节点
type AutoFreeNode ¶
自动释放块节点
func NewAutoFreeNode ¶
func NewAutoFreeNode(FileName string) *AutoFreeNode
func (*AutoFreeNode) C ¶
func (a *AutoFreeNode) C(buf *strings.Builder)
func (*AutoFreeNode) String ¶
func (a *AutoFreeNode) String() string
type CHeaderFile ¶
type CallNode ¶
type CallNode struct {
FuncName FuncNameNode //调用函数名
Parame []Expr //Parameter
CCallFuncName string
InAutoFree bool
// contains filtered or unexported fields
}
函数调用节点
func NewCallExpr ¶
func NewCallExpr(funcname FuncNameNode, InAutoFree bool, parame ...Expr) *CallNode
NewCallNode 创建函数调用节点
func (*CallNode) SetNosemicolon ¶
type ContinueStmt ¶
type ContinueStmt struct{}
continue语句
func NewContinueStmt ¶
func NewContinueStmt() ContinueStmt
func (ContinueStmt) C ¶
func (c ContinueStmt) C(buf *strings.Builder)
func (ContinueStmt) String ¶
func (c ContinueStmt) String() string
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
type DefaultNode ¶
defaultcase节点
func NewDefaultNode ¶
func NewDefaultNode() *DefaultNode
func (*DefaultNode) C ¶
func (c *DefaultNode) C(buf *strings.Builder)
func (*DefaultNode) String ¶
func (d *DefaultNode) String() string
type Dereference ¶
type Dereference struct {
Value Expr
}
Dereference 解引用节点
func (*Dereference) C ¶
func (d *Dereference) C(buf *strings.Builder)
func (*Dereference) String ¶
func (d *Dereference) String() string
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) C ¶
func (g *GenericInstantiation) C(buf *strings.Builder)
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
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 MethodNode ¶
MethodNode 方法节点
func NewMethodNode ¶
func NewMethodNode(typ string, info *FuncInfo) *MethodNode
NewMethodNode 创建函数节点
func (*MethodNode) C ¶
func (m *MethodNode) C(buf *strings.Builder)
func (*MethodNode) CDecl ¶
func (m *MethodNode) CDecl(buf *strings.Builder)
func (*MethodNode) String ¶
func (m *MethodNode) String() string
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]
//是否有init函数
IsInitFunc atomic.Bool
//是否有自动释放块
IsHaveAutoFree atomic.Bool
//C代码的头文件包含的节点
CHeaderFile data.Slice[CHeaderFile]
//并发
Thread bool
// contains filtered or unexported fields
}
Package 管理一个包的所有源代码文件的抽象语法树
func NewPackage ¶
func NewPackage(dir string, thread bool, errctx *errcode.ErrCtx, sbt *Sbt, ImportPackage *map[string]*Package) *Package
NewPackage 创建管理一个包的所有源代码文件的抽象语法树的 Package
- thread是控制是否并发
- errctx是错误处理上下文
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
//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) String ¶
func (b RbraceNode) String() string
type RemoveGenericsInfo ¶
func (RemoveGenericsInfo) String ¶
func (info RemoveGenericsInfo) String() string
type ReturnNode ¶
type ReturnNode struct {
RetValue Expr
}
return节点
func (*ReturnNode) C ¶
func (l *ReturnNode) C(buf *strings.Builder)
func (*ReturnNode) String ¶
func (l *ReturnNode) String() string
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) 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) C ¶
func (o *SelfOpStmt) C(buf *strings.Builder)
func (*SelfOpStmt) SetNosemicolon ¶
func (o *SelfOpStmt) SetNosemicolon(nosemicolon bool)
func (*SelfOpStmt) String ¶
func (o *SelfOpStmt) String() string
type StructDecl ¶
type StructDecl struct {
Name string
FileName string
FieldTable []Field
LineNum int
TypeParame []astdata.NameAndType
InFunc bool
// contains filtered or unexported fields
}
StructDecl 结构体声明
缩写:struct declaration 缩写成:StructDecl
func (*StructDecl) C ¶
func (s *StructDecl) C(buf *strings.Builder)
func (*StructDecl) CDecl ¶
func (s *StructDecl) CDecl(buf *strings.Builder)
func (*StructDecl) Dep ¶
func (info *StructDecl) Dep(i int) data.IsItARecursiveType
func (*StructDecl) DepLen ¶
func (info *StructDecl) DepLen() int
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
type SwitchNode ¶
type SwitchNode struct {
Expr Expr
// contains filtered or unexported fields
}
switch节点
func NewSwitchNode ¶
func NewSwitchNode() *SwitchNode
func (*SwitchNode) C ¶
func (s *SwitchNode) C(buf *strings.Builder)
func (*SwitchNode) String ¶
func (s *SwitchNode) String() string
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
//自己及依赖导入的包
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
//C代码的头文件包含的节点
CHeaderFile *data.Slice[CHeaderFile]
//是否并发
Thread bool
// contains filtered or unexported fields
}
一个抽象语法树
func NewTree ¶
func NewTree(ft *lex.FileToken, errctx *errcode.ErrCtx, sbt *Sbt, ImportPackage *map[string]*Package) *Tree
NewTree 创建抽象语法树,从词法分析结果开始
- ft是词法分析结果
- errctx是错误处理上下文
- Thread控制是否并发
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)
type VarNode ¶
type VarNode struct {
TYPE astdata.Typ //变量类型
Value Expr //值
Name string //变量名
CType string
//后两个用于出错时报错
FileName string
LineNum int
IsFunc bool
// contains filtered or unexported fields
}
变量声明节点
func NewVarNode ¶
NewVarNode 创建变量声明节点