Documentation
¶
Index ¶
- Variables
- type ASSIGNNode
- type Array
- type AssignmentNode
- type AutoFreeNode
- type BreakStmt
- type CDecl
- type CType
- type CallNode
- type CaseNode
- type CodeBlockIface
- type ConstNode
- type ContinueStmt
- type DefaultNode
- type DerefExpr
- type ElseNode
- type EnumDecl
- type Expr
- type Field
- type ForNode
- type FuncInfo
- 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 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
- type RbraceNode
- type ReturnNode
- type Sbt
- func (s *Sbt) AddConst(n *ConstNode) errcode.ErrCode
- func (s *Sbt) AddEnum(n *EnumDecl) errcode.ErrCode
- func (s *Sbt) AddFunc(info *FuncNode) errcode.ErrCode
- func (s *Sbt) AddGenInst(node *GenericInstantiation)
- func (s *Sbt) AddMethod(method *MethodNode) errcode.ErrCode
- func (s *Sbt) AddPackage(p *Package) errcode.ErrCode
- func (s *Sbt) AddStruct(decl *StructDecl) errcode.ErrCode
- func (s *Sbt) AddVar(n *VarNode) errcode.ErrCode
- func (v *Sbt) Copy() *Sbt
- func (v *Sbt) Have(name string) (fmt.Stringer, errcode.ErrCode)
- func (v *Sbt) Have2(name string) (n fmt.Stringer, inlocal bool, err errcode.ErrCode)
- func (s *Sbt) HaveMethod(Type string, Name string) fmt.Stringer
- func (s *Sbt) HaveType(name string) (astdata.Typ, errcode.ErrCode)
- func (v *Sbt) Range(f func(key string, value fmt.Stringer) 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 (s *StructDecl) Copy() astdata.Typ
- 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) SetLea(i int)
- func (s *StructDecl) SetTyp()
- func (s *StructDecl) String() string
- func (s *StructDecl) Typ() string
- type SwitchNode
- type Tree
- type VarInitTable
- type VarNode
Constants ¶
This section is empty.
Variables ¶
var Builtin_func_info = map[string]Node{ enum.Printf: NewFuncNode(&FuncInfo{Name: enum.Printf, Parame: []astdata.Parame{astdata.NewNameAndType("format", NewObject(TypeObj, enum.String))}}), enum.Float: NewFuncNode(&FuncInfo{Name: enum.Float, RetValue: []astdata.RetValue{astdata.NewNameAndType("", NewObject(TypeObj, enum.Float))}}), enum.Int: NewFuncNode(&FuncInfo{Name: enum.Int, RetValue: []astdata.RetValue{astdata.NewNameAndType("", NewObject(TypeObj, enum.Int))}}), enum.Malloc: NewFuncNode(&FuncInfo{Name: enum.Malloc, Parame: []astdata.Parame{astdata.NewNameAndType("type", NewObject(TypeObj, "T"))}, RetValue: []astdata.RetValue{astdata.NewNameAndType("ptr", NewObject(TypeObj, "&T"))}}), enum.Free: NewFuncNode(&FuncInfo{Name: enum.Free, Parame: []astdata.Parame{astdata.NewNameAndType("ptr", NewObject(TypeObj, "&T"))}}), enum.UnsafeAdd: NewFuncNode(&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: NewFuncNode(&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: NewFuncNode(&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: NewFuncNode(&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: NewFuncNode(nil), enum.MemPoolNew: NewFuncNode(nil), enum.UnsafePointer: NewFuncNode(nil), }
预定义的函数或视为函数调用的类型转换
var NdSotfOn = false
有测试依赖函数体外的非声明语句,设置为true可以恢复之前的行为 缩写 Non declarative statements outside of a function 缩写成NdSotf
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]*Object{ "int": NewObject(TypeObj, "int"), "string": NewObject(TypeObj, "string"), "bool": NewObject(TypeObj, "bool"), "float": NewObject(TypeObj, "float"), enum.UnsafePointer: NewObject(TypeObj, enum.UnsafePointer), "any": NewObject(TypeObj, "any"), } )
Functions ¶
This section is empty.
Types ¶
type ASSIGNNode ¶
type ASSIGNNode = AssignmentNode
func NewASSIGNNode ¶
func NewASSIGNNode(Dest Expr, Src Expr, LineNum int) *ASSIGNNode
NewASSIGNNode 创建赋值节点
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 Array ¶
type Array struct {
Len Expr
TYPE astdata.Typ
UStr string
LineNum int
// contains filtered or unexported fields
}
Array 数组类型
type AssignmentNode ¶
type AssignmentNode struct {
//目的操作数,源操作数
Dest Expr
Src Expr
// contains filtered or unexported fields
}
赋值节点
type AutoFreeNode ¶
自动释放块节点
func NewAutoFreeNode ¶
func NewAutoFreeNode(FileName string, LineNum int) *AutoFreeNode
func (*AutoFreeNode) C ¶
func (a *AutoFreeNode) C(buf *strings.Builder)
func (*AutoFreeNode) String ¶
func (a *AutoFreeNode) String() string
type CallNode ¶
type CallNode struct {
FuncName Expr //调用函数名
Parame []Expr //Parameter
CCallFuncName string
InAutoFree bool
// contains filtered or unexported fields
}
函数调用节点
func NewCallExpr ¶
NewCallNode 创建函数调用节点
func (*CallNode) SetNosemicolon ¶
type CaseNode ¶
type CaseNode struct {
Expr Expr
// contains filtered or unexported fields
}
case节点
func NewCaseNode ¶
type CodeBlockIface ¶
type CodeBlockIface interface {
Node
// contains filtered or unexported methods
}
CodeBlockIface 是代码块节点接口
type ConstNode ¶
type ConstNode struct {
TYPE astdata.Typ
Value Expr
Name string
// contains filtered or unexported fields
}
常量声明节点
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 DefaultNode ¶
type DefaultNode struct {
// contains filtered or unexported fields
}
default节点
func NewDefaultNode ¶
func NewDefaultNode(LineNum int) *DefaultNode
func (*DefaultNode) C ¶
func (c *DefaultNode) C(buf *strings.Builder)
func (*DefaultNode) String ¶
func (d *DefaultNode) String() string
type DerefExpr ¶
type DerefExpr struct {
Value Expr
// contains filtered or unexported fields
}
DerefExpr 解引用节点
type ElseNode ¶
type ElseNode struct {
BoolExpr Expr
// contains filtered or unexported fields
}
else节点
type EnumDecl ¶
type EnumDecl struct {
Name string
Enums []string
InFunc bool
// contains filtered or unexported fields
}
EnumDecl 枚举声明
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
Parame []astdata.Parame
RetValue []astdata.RetValue
TypeParame []astdata.NameAndType
// contains filtered or unexported fields
}
FuncInfo 函数信息
type GenericInstantiation ¶
type GenericInstantiation struct {
BaseName astdata.Typ
ActualType []astdata.Typ
FileName string
// contains filtered or unexported fields
}
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 GotoStmt ¶
type GotoStmt struct {
Label string
// contains filtered or unexported fields
}
goto语句
func NewGotoStmt ¶
type ImportInfo ¶
type ImportInfo struct {
Path string
}
ImportInfo 导入信息
func (ImportInfo) String ¶
func (info ImportInfo) String() string
type LabelNode ¶
type LabelNode struct {
Value string
// contains filtered or unexported fields
}
标签
func NewLabelNode ¶
type MethodNode ¶
type MethodNode struct {
*FuncInfo
}
MethodNode 方法节点
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 Objects ¶
func NewObjects ¶
type OpExpr ¶
type OpExpr = OperationExpr
运算表达式节点
func (*OpExpr) SetNosemicolon ¶
type OperationExpr ¶
type OperationExpr struct {
Src1 Expr
Src2 Expr
OP enum.OPSymbol
Inparen bool //是否在小括号内
// contains filtered or unexported fields
}
运算表达式节点
type Package ¶
type Package struct {
PackageName string
//符号表
Sbt *Sbt
//保存抽象语法树
Trees data.Slice[*Tree]
//是否有init函数
IsInitFunc bool
//C语言头文件用到的节点
CHeaderFile data.Slice[CDecl]
//变量初始化
VarInitTable VarInitTable
//自己及依赖导入的包
ImportPackage map[string]*Package
//是所有的导入路径
ImporPath *Sbt
//并发
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
- dir是包的路径
- thread是控制是否并发
- errctx是错误处理上下文
- sbt是符号表
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 ReturnNode ¶
return节点
func (*ReturnNode) C ¶
func (l *ReturnNode) C(buf *strings.Builder)
func (*ReturnNode) String ¶
func (l *ReturnNode) String() string
type Sbt ¶
type Sbt struct {
//是否并发
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(method *MethodNode) errcode.ErrCode
AddMethod 记录方法 有错返回错误码
- method是语法节点
func (*Sbt) AddStruct ¶
func (s *Sbt) AddStruct(decl *StructDecl) errcode.ErrCode
AddStruct 记录结构体 有错返回错误码
- decl是语法节点
type SelfOpStmt ¶
自操作语句 缩写: Self-operating statement 缩写成 SelfOpStmt 源操作数只可能是下列类型
- 对象节点 ast2.Object
- 选择器节点 ast2.Objects
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
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) Copy ¶
func (s *StructDecl) Copy() astdata.Typ
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) SetLea ¶
func (s *StructDecl) SetLea(i int)
func (*StructDecl) SetTyp ¶
func (s *StructDecl) SetTyp()
func (*StructDecl) String ¶
func (s *StructDecl) String() string
func (*StructDecl) Typ ¶
func (s *StructDecl) Typ() string
type SwitchNode ¶
type SwitchNode struct {
Expr Expr
// contains filtered or unexported fields
}
switch节点
func NewSwitchNode ¶
func NewSwitchNode(LineNum int) *SwitchNode
func (*SwitchNode) C ¶
func (s *SwitchNode) C(buf *strings.Builder)
func (*SwitchNode) String ¶
func (s *SwitchNode) String() string
type Tree ¶
type Tree struct {
//包名
PackageName string
//文件名称
Filename string
//所有节点
Nodes []Node
//符号表
Sbt *Sbt
//变量初始化表
VarInitTable *VarInitTable
//HaveInitFunc 记录是否有自定义init函数
HaveInitFunc *bool
//C语言头文件用到的节点
CHeaderFile *data.Slice[CDecl]
//自己及依赖导入的包
ImportPackage *map[string]*Package
//是所有的导入路径
ImporPath *Sbt
//下面两个字段用于确定是否在函数内解析
Funcinfo *FuncInfo
//CheckInfo是专门在语义检查时使用的信息
CheckInfo struct {
//switch表达式的类型
SwitchExprTyp string
//是否要跳过switch代码块
SwitchSkip bool
//检查的符号是否是常量
IsConst bool
//一个函数内的标签
Label []*LabelNode
//一个函数内待检查的goto语句
Goto []*GotoStmt
//生成的临时变量数量
TmpInt int
}
// contains filtered or unexported fields
}
func (*Tree) PushNewSbt ¶
type VarInitTable ¶
VarInitTable 变量初始化表 实现了 sort.Interface 接口
func (*VarInitTable) InitOrder ¶
func (t *VarInitTable) InitOrder() []*VarNode
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)