cast

package
v0.0.0-...-0e42c13 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package cast 实现了一个C语言的抽象语法树

Index

Constants

This section is empty.

Variables

View Source
var Deferfunc func() = utils.Deferfunc
View Source
var (
	ObjKindSrtMap = [...]string{
		NoOP:      "noop (未定义的类型)",
		INTOBJ:    "intobj (整数)",
		FLOATOBJ:  "floatobj (浮点数)",
		BoolObj:   "boolobj (布尔值)",
		StringObj: "stringobj(字符串)",
		SymbolObj: "symbolobj (符号)",
		LeaObj:    "leaObj (取地址)",
		DerefObj:  "derefObj (解引用)",
		StructPtr: "StructPtr (结构体指针)",
		NilObj:    "NilObj (指针的零值)",
		EnumObj:   "EnumObj (枚举值)",
	}
)

Functions

func PaeserIr2

func PaeserIr2(toc *Ir2ToC, f *ir2.File)

Types

type ASSIGNNode

type ASSIGNNode struct {
	//目的操作数,源操作数
	Dest Node
	Src  Node
	// contains filtered or unexported fields
}

赋值节点

func NewASSIGNNode

func NewASSIGNNode(Dest Node, Src Node) *ASSIGNNode

NewASSIGNNode 创建赋值节点

func UtoCASSIGN

func UtoCASSIGN(a *ast.ASSIGNNode) *ASSIGNNode

UtoCASSIGN 将赋值节点转换为cast等价的 - a是被转换的,不能为nil

func (*ASSIGNNode) C

func (a *ASSIGNNode) C(buf *strings.Builder)

func (*ASSIGNNode) CType

func (a *ASSIGNNode) CType() cenum.NodeEnum

func (*ASSIGNNode) String

func (a *ASSIGNNode) String() string

type CallNode

type CallNode struct {
	Parame []Node //Parameter
	// contains filtered or unexported fields
}

函数调用节点

func NewCallNode

func NewCallNode(funcname string, nosemicolon bool, parame ...Node) *CallNode

NewCallNode 创建函数调用节点

func UtoCCall

func UtoCCall(c *ast.CallNode) *CallNode

UtoCCall 将调用节点转换为cast等价的 - c是被转换的,不能为nil

func (*CallNode) C

func (a *CallNode) C(buf *strings.Builder)

func (*CallNode) CType

func (a *CallNode) CType() cenum.NodeEnum

func (*CallNode) String

func (a *CallNode) String() string

type CaseNode

type CaseNode struct {
	Expr Node
}

case节点

func NewCaseNode

func NewCaseNode() *CaseNode

func UtoCCase

func UtoCCase(c *ast.CaseNode) *CaseNode

UtoCCase 将Case节点转换为cast等价的 - s是被转换的,不能为nil

func (*CaseNode) C

func (c *CaseNode) C(buf *strings.Builder)

func (*CaseNode) CType

func (c *CaseNode) CType() cenum.NodeEnum

func (*CaseNode) String

func (c *CaseNode) String() string

type ConstNode

type ConstNode struct {
	Value  Node
	Name   string
	TYPE   string
	IsFunc bool
	// contains filtered or unexported fields
}

常量声明节点

func NewConstNode

func NewConstNode(name string, Type string) *ConstNode

NewConstNode 创建常量声明节点

func UtoCConst

func UtoCConst(c *ast.ConstNode, IsFunc bool, isDecl bool) *ConstNode

UtoCConst 将常量节点转换为cast等价的 - c是被转换的,不能为nil

func (*ConstNode) C

func (c *ConstNode) C(buf *strings.Builder)

func (*ConstNode) CType

func (c *ConstNode) CType() cenum.NodeEnum

func (*ConstNode) String

func (c *ConstNode) String() string

type Dereference

type Dereference struct {
	Value Node
}

Dereference 解引用节点

func (*Dereference) C

func (d *Dereference) C(buf *strings.Builder)

func (*Dereference) CType

func (d *Dereference) CType() cenum.NodeEnum

func (*Dereference) String

func (d *Dereference) String() string

type ElseNode

type ElseNode struct {
	BoolExpr Node
}

else节点

func NewElseNode

func NewElseNode() *ElseNode

func UtocElseNode

func UtocElseNode(f *ast.ElseNode) *ElseNode

UtocElseNode 将else节点转换为cast等价的 - f是被转换的,不能为nil

func (*ElseNode) C

func (l *ElseNode) C(buf *strings.Builder)

func (*ElseNode) CType

func (l *ElseNode) CType() cenum.NodeEnum

func (*ElseNode) String

func (l *ElseNode) String() string

type ForNode

type ForNode struct {
	InitStmt Node
	BoolExpr Node
	EndStmt  Node
}

for节点

func NewForNode

func NewForNode() *ForNode

NewForNode 创建for节点

func UtocForNode

func UtocForNode(f *ast.ForNode, IsGeneric bool, oldi int) *ForNode

UtocForNode 将for节点转换为cast等价的 - f是被转换的,不能为nil

func (*ForNode) C

func (l *ForNode) C(buf *strings.Builder)

func (*ForNode) CType

func (l *ForNode) CType() cenum.NodeEnum

func (*ForNode) String

func (l *ForNode) String() string

type FuncNode

type FuncNode struct {
	Name     string
	Parame   []astdata.Parame
	RetValue []astdata.RetValue
	TYPE     cenum.NodeEnum
	// contains filtered or unexported fields
}

函数节点

func NewFuncNode

func NewFuncNode(Name string) *FuncNode

NewFuncNode 创建函数节点

func UtoCMethod

func UtoCMethod(m *ast.MethodNode) *FuncNode

UtoCCase 将方法节点转换为cast等价的 - m是被转换的,不能为nil

func UtocFuncNode

func UtocFuncNode(f *ast.FuncNode) *FuncNode

UtocFuncNode 将函数节点转换为cast等价的

  • f是转换的,不能为nil

func (*FuncNode) C

func (f *FuncNode) C(buf *strings.Builder)

func (*FuncNode) CType

func (f *FuncNode) CType() cenum.NodeEnum

func (*FuncNode) String

func (f *FuncNode) String() string

type IfNode

type IfNode struct {
	BoolExpr Node
}

if节点

func NewIfNode

func NewIfNode() *IfNode

func UtocIfNode

func UtocIfNode(f *ast.IfNode) *IfNode

UtocIfNode 将if节点转换为cast等价的 - f是转换的,不能为nil

func (*IfNode) C

func (l *IfNode) C(buf *strings.Builder)

func (*IfNode) CType

func (l *IfNode) CType() cenum.NodeEnum

func (*IfNode) String

func (l *IfNode) String() string

type IndexExpr

type IndexExpr struct {
	X     Node
	Index Node
}

IndexExpr 索引表达式 缩写index expression 缩写成 IndexExpr

func NewIndexExpr

func NewIndexExpr(X Node, Index Node) *IndexExpr

func (*IndexExpr) C

func (l *IndexExpr) C(buf *strings.Builder)

func (*IndexExpr) CType

func (l *IndexExpr) CType() cenum.NodeEnum

func (*IndexExpr) String

func (l *IndexExpr) String() string

type Ir2ToC

type Ir2ToC struct {
	Nodes []Node
	// contains filtered or unexported fields
}

func NewIr2ToC

func NewIr2ToC(packageName string, isInitFunc bool) *Ir2ToC

func (*Ir2ToC) C

func (c *Ir2ToC) C() string

type Node

type Node interface {
	// Type 返回节点类型枚举
	CType() cenum.NodeEnum
	String() string
	// C 写入等效C语言代码
	C(buf *strings.Builder)
}

func ParserNode

func ParserNode(c *UtoC, Nodes []ast.Node, index int, end int, ret []Node, IsFunc bool, Thread bool, IsGeneric bool, oldi int) []Node

func UtoCExprNode

func UtoCExprNode(obj ast.Expr) Node

UtoCExprNode 将表达式节点,转换为cast等价的 - obj是被转换的,不能为nil

type ObjKind

type ObjKind int
const (
	NoOP ObjKind = 1 << iota
	INTOBJ
	FLOATOBJ
	BoolObj
	StringObj
	SymbolObj
	LeaObj
	DerefObj
	StructPtr
	NilObj
	TypeObj
	EnumObj
)

func (ObjKind) String

func (o ObjKind) String() string

type Object

type Object struct {
	Name string
	Kind ObjKind
}

对象节点

func NewObject

func NewObject(Kind ObjKind, Name string) *Object

func UtoCObject

func UtoCObject(obj *ast.Object) *Object

UtoCObject 将对象节点,转换为cast等价的 - obj是被转换的,不能为nil

func (*Object) C

func (o *Object) C(buf *strings.Builder)

func (*Object) CType

func (o *Object) CType() cenum.NodeEnum

func (*Object) String

func (o *Object) String() string

type Objects

type Objects struct {
	Slice          []*Object
	IsImportSymbol bool //是否是导入符号,由语义检查填充
}

func NewObjects

func NewObjects(slice []*Object) *Objects

func UtoCObjects

func UtoCObjects(o *ast.Objects) *Objects

UtoCObjects 将选择器节点转换为cast等价的 - o是被转换的,不能为nil

func (*Objects) C

func (o *Objects) C(buf *strings.Builder)

func (*Objects) CType

func (o *Objects) CType() cenum.NodeEnum

func (*Objects) String

func (o *Objects) String() string

type OneIr2ToC

type OneIr2ToC ir2.IrNode

func (OneIr2ToC) C

func (ir OneIr2ToC) C(buf *strings.Builder)

func (OneIr2ToC) CType

func (ir OneIr2ToC) CType() cenum.NodeEnum

func (OneIr2ToC) String

func (ir OneIr2ToC) String() string

type OpExpr

type OpExpr = OperationExpr

运算表达式节点

func NewOpExpr

func NewOpExpr(OP enum.OPSymbol, Src1, Src2 Node) *OpExpr

NewOpExpr 创建运算表达式节点

func UtoCOpExpr

func UtoCOpExpr(expr *ast.OpExpr) *OpExpr

UtoCOpExpr 将运算表达式节点转换为cast等价的 - expr是被转换的,不能为nil

func (*OpExpr) C

func (a *OpExpr) C(buf *strings.Builder)

func (*OpExpr) CType

func (a *OpExpr) CType() cenum.NodeEnum

func (*OpExpr) String

func (a *OpExpr) String() string

type OperationExpr

type OperationExpr struct {
	Src1    Node
	Src2    Node
	OP      enum.OPSymbol
	IsStr   bool //操作数类型是否是字符串
	Inparen bool //是否在小括号内
}

运算表达式节点

type Package

type Package struct {

	//并发
	Thread bool
	// contains filtered or unexported fields
}

func NewPackage

func NewPackage(Thread bool) *Package

func (*Package) AddUastSlice

func (p *Package) AddUastSlice(astp *ast.Package, importPackage map[string]*Package)

func (*Package) C

func (p *Package) C(buf *strings.Builder)

func (*Package) OupputC

func (p *Package) OupputC(dir string) ([]string, error)

OupputC 输出C文件到目录

func (*Package) String

func (p *Package) String() string

func (*Package) WithAutoFree

func (p *Package) WithAutoFree() bool

type ReturnNode

type ReturnNode struct {
	RetValue Node
}

return节点

func NewReturnNode

func NewReturnNode() *ReturnNode

NewReturnNode 创建return节点

func UtoCReturn

func UtoCReturn(r *ast.ReturnNode) *ReturnNode

UtoCReturn 将返回语句节点转换为cast等价的 - r是被转换的,不能为nil

func (*ReturnNode) C

func (l *ReturnNode) C(buf *strings.Builder)

func (*ReturnNode) CType

func (l *ReturnNode) CType() cenum.NodeEnum

func (*ReturnNode) String

func (l *ReturnNode) String() string

type SelfOpStmt

type SelfOpStmt struct {
	Dest Node
	OP   enum.OPSymbol
	// contains filtered or unexported fields
}

自操作语句 缩写: Self-operating statement 缩写成 SelfOpStmt

func NewSelfOpStmt

func NewSelfOpStmt(OP enum.OPSymbol, Dest Node) *SelfOpStmt

func (*SelfOpStmt) C

func (o *SelfOpStmt) C(buf *strings.Builder)

func (*SelfOpStmt) CType

func (o *SelfOpStmt) CType() cenum.NodeEnum

func (*SelfOpStmt) String

func (o *SelfOpStmt) String() string

type SwitchNode

type SwitchNode struct {
	Expr Node
}

switch节点

func UtoCSwitch

func UtoCSwitch(s *ast.SwitchNode) *SwitchNode

UtoCSwitch 将switch节点转换为cast等价的 - s是被转换的,不能为nil

func (*SwitchNode) C

func (s *SwitchNode) C(buf *strings.Builder)

func (*SwitchNode) CType

func (s *SwitchNode) CType() cenum.NodeEnum

func (*SwitchNode) String

func (s *SwitchNode) String() string

type UtoC

type UtoC struct {
	PackageName string
	FileName    string

	Nodes []Node

	Thread bool

	InAutoFree bool
	// contains filtered or unexported fields
}

func NewUtoC

func NewUtoC(Thread bool) *UtoC

func (*UtoC) C

func (c *UtoC) C() string

func (*UtoC) Parser

func (c *UtoC) Parser(t *ast.Tree, inPackage bool)

func (*UtoC) String

func (c *UtoC) String() string

type VarNode

type VarNode struct {
	Value   Node
	Name    string
	MemType string
	IsFunc  bool
	// contains filtered or unexported fields
}

变量节点

func NewVarNode

func NewVarNode(n *ast.VarNode, isDecl bool) *VarNode

NewVarNode 创建变量节点

func (*VarNode) C

func (v *VarNode) C(buf *strings.Builder)

func (*VarNode) CType

func (v *VarNode) CType() cenum.NodeEnum

func (*VarNode) String

func (v *VarNode) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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