tast

package
v0.0.0-...-093a1a0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Package tast saves data structures for typed AST. Compiling it should contain no semantic errors.

Index

Constants

View Source
const (
	SymNone = iota
	SymFunc
	SymVar
	SymStruct
	SymType
	SymConst
	SymImport
	SymField
	SymInterface
)

Symbol types

Variables

View Source
var Void = &Ref{Void: true}

Void is a void ref.

Functions

func SymStr

func SymStr(s int) string

SymStr returns the string representation of a symbol

Types

type AssignStmt

type AssignStmt struct {
	Left  Expr
	Op    *lexing.Token
	Right Expr
}

AssignStmt is an assignment statement, like "a,b=x,y".

type Block

type Block struct {
	Stmts []Stmt
}

Block is a statement block; it is also a statement itself.

type BreakStmt

type BreakStmt struct{}

BreakStmt is a "break"

type CallExpr

type CallExpr struct {
	Func Expr
	Args Expr
	*Ref
}

CallExpr is an expression like "f(x)"

type Case

type Case struct {
	Expr        Expr
	Stmts       []Stmt
	Fallthrough bool
}

Case is a case statement

type Cast

type Cast struct {
	From Expr
	*Ref
	Mask []bool
}

Cast cast from one type of reference to another

func NewCast

func NewCast(from Expr, to types.T) *Cast

NewCast creates a new casting operation

func NewMultiCast

func NewMultiCast(from Expr, to *Ref, mask []bool) *Cast

NewMultiCast creates a new casting operation for a list of refs.

func NewMultiCastType

func NewMultiCastType(from Expr, t types.T, mask []bool) *Cast

NewMultiCastType creates a new casting operation from an expression to a list of refs with the same length of a type.

func NewMultiCastTypes

func NewMultiCastTypes(from Expr, ts []types.T, mask []bool) *Cast

NewMultiCastTypes creates a new casting operation from an expression to a list of refs with the given type list

type Const

type Const struct{ *Ref }

Const is a constant.

func NewConst

func NewConst(t types.T) *Const

NewConst creates a new constant node from a const type t.

type ConstDecls

type ConstDecls struct {
	Decls []*Define
}

ConstDecls is a const declaration group.

type ContinueStmt

type ContinueStmt struct{}

ContinueStmt is a "continue"

type Define

type Define struct {
	Left  []*syms.Symbol
	Right Expr // zero out Left if Right==nil
}

Define is a define statement, like "a,b:=x,y".

type Expr

type Expr interface {
	R() *Ref
	Type() types.T
}

Expr is a generic interface for an expression.

type ExprList

type ExprList struct {
	Exprs []Expr
	*Ref
}

ExprList is a list of expressions.

func MakeExprList

func MakeExprList(expr Expr) (*ExprList, bool)

MakeExprList makes the expression an expression list if it not one yet.

func NewExprList

func NewExprList() *ExprList

NewExprList creates a new expression list.

func (*ExprList) Append

func (lst *ExprList) Append(expr Expr)

Append appends an expression into the expression list.

func (*ExprList) Len

func (lst *ExprList) Len() int

Len returns the length of the expression list.

type ExprStmt

type ExprStmt struct {
	Expr
}

ExprStmt is a statement with just an expression.

type ForStmt

type ForStmt struct {
	ThreeFold bool
	Init      Stmt
	Cond      Expr
	Iter      Stmt
	Body      Stmt
}

ForStmt is a for loop statement.

type Func

type Func struct {
	Sym *syms.Symbol // function symbol

	This     *types.Pointer
	Receiver *syms.Symbol // explicit receiver

	Args      []*syms.Symbol
	NamedRets []*syms.Symbol

	Body []Stmt
}

Func is a function.

func (*Func) IsMethod

func (f *Func) IsMethod() bool

IsMethod returns true when the function is a method.

type FuncAlias

type FuncAlias struct {
	Sym *syms.Symbol
	Of  *syms.Symbol
}

FuncAlias is a function alias.

type Ident

type Ident struct {
	Token *lexing.Token
	*Ref
	Sym *syms.Symbol
}

Ident is an identifier.

type IfStmt

type IfStmt struct {
	Expr Expr
	Body Stmt
	Else Stmt
}

IfStmt is an if statement.

type Import

type Import struct {
	Sym *syms.Symbol
}

Import is an import statement

type IncStmt

type IncStmt struct {
	Expr Expr
	Op   *lexing.Token
}

IncStmt is an "i++" or "i--".

type IndexExpr

type IndexExpr struct {
	Array, Index, IndexEnd Expr
	HasColon               bool
	*Ref
}

IndexExpr is an expression like "a[b:c]" Both b and c are optional.

type MemberExpr

type MemberExpr struct {
	Expr Expr
	Sub  *lexing.Token
	*Ref
	Sym *syms.Symbol
}

MemberExpr is an expression of "a.b"

type OpExpr

type OpExpr struct {
	A  Expr
	Op *lexing.Token
	B  Expr
	*Ref
}

OpExpr is an expression likfe "a+b"

type Pkg

type Pkg struct {
	Imports    []*syms.Symbol
	Consts     []*syms.Symbol
	Structs    []*syms.Symbol
	Interfaces []*syms.Symbol

	Vars        []*Define
	FuncAliases []*FuncAlias
	Funcs       []*Func
	Methods     []*Func
}

Pkg is a package of imports, consts, structs, vars and funcs.

type Ref

type Ref struct {
	// T is the type of the reference
	T types.T

	// ConstValue is not nil when the reference already has a value.
	ConstValue interface{}

	// Addressable tells if the reference is addressable
	Addressable bool

	// Recv save the receiver, if any.
	Recv *Ref

	// List saves the ref for an expression list.
	List []*Ref

	// Void is true when the reference is a void ref.
	// This is required for saving ref of an expression list
	// or a return value of a function call.
	Void bool
}

Ref is a reference to a evaluatd node.

func AppendRef

func AppendRef(base, toAdd *Ref) *Ref

AppendRef append a ref in a ref bundle.

func NewAddressableRef

func NewAddressableRef(t types.T) *Ref

NewAddressableRef creates a new addressable node.

func NewConstRef

func NewConstRef(t types.T, v interface{}) *Ref

NewConstRef creates a new reference node with a constant value.

func NewListRef

func NewListRef(ts []types.T) *Ref

NewListRef creates a new reference with a list of types.

func NewRef

func NewRef(t types.T) *Ref

NewRef creates a new reference node.

func NewTypeRef

func NewTypeRef(t types.T) *Ref

NewTypeRef creates a new reference node for a type expression.

func (*Ref) At

func (r *Ref) At(i int) *Ref

At returns the ref in the list.

func (*Ref) IsBool

func (r *Ref) IsBool() bool

IsBool checks if the ref is a single boolean ref.

func (*Ref) IsSingle

func (r *Ref) IsSingle() bool

IsSingle checks if the ref is a single ref.

func (*Ref) Len

func (r *Ref) Len() int

Len returns the number of refs in this ref bundle.

func (*Ref) R

func (r *Ref) R() *Ref

R returns itself.

func (*Ref) String

func (r *Ref) String() string

func (*Ref) Type

func (r *Ref) Type() types.T

Type returns the type of the ref.

func (*Ref) TypeList

func (r *Ref) TypeList() []types.T

TypeList returns the type list of the reference's type.

type ReturnStmt

type ReturnStmt struct {
	Exprs Expr
}

ReturnStmt is a statement like "return a,b"

type StarExpr

type StarExpr struct {
	Expr Expr
	*Ref
}

StarExpr is an expression like "*a"

type Stmt

type Stmt interface{}

Stmt is a generic interface for a statement.

type SwitchStmt

type SwitchStmt struct {
	Expr  Expr
	Cases []*Case
}

SwitchStmt is a switch statement

type This

type This struct{ *Ref }

This is the this pointer.

type Type

type Type struct{ *Ref }

Type is a type expression

func NewType

func NewType(t types.T) *Type

NewType creates a new type expression of a particular type.

type VarDecls

type VarDecls struct {
	Decls []*Define
}

VarDecls is a variable declaration group.

Jump to

Keyboard shortcuts

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