symbol

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Int    = &PrimitiveType{name: "int"}
	String = &PrimitiveType{name: "string"}
	Float  = &PrimitiveType{name: "float"}
	Bool   = &PrimitiveType{name: "bool"}
	Void   = &VoidType{}
)

Functions

This section is empty.

Types

type BlockScope

type BlockScope struct {
	// contains filtered or unexported fields
}

func (BlockScope) AddSymbol

func (s BlockScope) AddSymbol(symbol Symbol)

func (BlockScope) ContainsSymbol

func (s BlockScope) ContainsSymbol(symbol Symbol) bool

func (BlockScope) GetCtx

func (s BlockScope) GetCtx() antlr.ParserRuleContext

func (BlockScope) GetFunction

func (s BlockScope) GetFunction(name string, paramTypes []Type) *Func

func (BlockScope) GetSymbols

func (s BlockScope) GetSymbols() []Symbol

func (BlockScope) GetVariable

func (s BlockScope) GetVariable(name string) *Variable

func (BlockScope) SetCtx

func (s BlockScope) SetCtx(ctx antlr.ParserRuleContext)

func (BlockScope) String

func (s BlockScope) String() string

type Func

type Func struct {
	// contains filtered or unexported fields
}

func GetFunction

func GetFunction(scope Scope, name string, paramTypes []Type) *Func

func NewFunc

func NewFunc(ctx antlr.ParserRuleContext, name string, encloseScope Scope) *Func

func (Func) AddSymbol

func (s Func) AddSymbol(symbol Symbol)

func (*Func) AppendParameter

func (f *Func) AppendParameter(v *Variable)

func (Func) ContainsSymbol

func (s Func) ContainsSymbol(symbol Symbol) bool

func (Func) GetCtx

func (s Func) GetCtx() antlr.ParserRuleContext

func (*Func) GetEncloseScope

func (f *Func) GetEncloseScope() Scope

func (Func) GetFunction

func (s Func) GetFunction(name string, paramTypes []Type) *Func

func (*Func) GetName

func (f *Func) GetName() string

func (*Func) GetParameterType

func (f *Func) GetParameterType() []Type

GetParameterType 获取和初始化

func (*Func) GetReturnType

func (f *Func) GetReturnType() Type

func (Func) GetSymbols

func (s Func) GetSymbols() []Symbol

func (Func) GetVariable

func (s Func) GetVariable(name string) *Variable

func (*Func) IsType

func (f *Func) IsType(t Type) bool

func (*Func) MatchParameterTypes

func (f *Func) MatchParameterTypes(paramTypes []Type) bool

MatchParameterTypes 通过参数类型匹配函数是否一致

func (Func) SetCtx

func (s Func) SetCtx(ctx antlr.ParserRuleContext)

func (*Func) SetEncloseScope

func (f *Func) SetEncloseScope(scope Scope)

func (*Func) SetName

func (f *Func) SetName(name string)

func (*Func) SetReturnType

func (f *Func) SetReturnType(t Type)

func (Func) String

func (s Func) String() string

type FuncType

type FuncType interface {
	Type
	GetReturnType() Type

	GetParameterType() []Type

	// MatchParameterTypes 检查参数类型是否和函数匹配
	MatchParameterTypes(types []Type) bool
}

type PrimitiveType

type PrimitiveType struct {
	// contains filtered or unexported fields
}

func (*PrimitiveType) GetEncloseScope

func (b *PrimitiveType) GetEncloseScope() Scope

func (*PrimitiveType) GetName

func (b *PrimitiveType) GetName() string

func (*PrimitiveType) IsType

func (b *PrimitiveType) IsType(t Type) bool

func (*PrimitiveType) String

func (b *PrimitiveType) String() string

type Scope

type Scope interface {
	Symbol
	AddSymbol(symbol Symbol)
	ContainsSymbol(symbol Symbol) bool
	GetSymbols() []Symbol
	SetCtx(ctx antlr.ParserRuleContext)
	GetVariable(name string) *Variable
	GetFunction(name string, paramTypes []Type) *Func
	String() string
}

func NewBlockScope

func NewBlockScope(ctx antlr.ParserRuleContext, name string, s Scope) Scope

type Symbol

type Symbol interface {
	SetName(name string)
	GetName() string
	GetEncloseScope() Scope
	SetEncloseScope(scope Scope)
}

type Type

type Type interface {
	GetName() string
	GetEncloseScope() Scope

	// IsType 判断类型是否相同,或者是不是 is-a ,是否为子类
	IsType(t Type) bool
}

type Variable

type Variable struct {
	// contains filtered or unexported fields
}

func GetVariable

func GetVariable(scope Scope, name string) *Variable

GetVariable 从 scope 中通过变量名称查询变量

func NewVariable

func NewVariable(ctx antlr.ParserRuleContext, name string, enclose Scope) *Variable

func (Variable) GetEncloseScope

func (s Variable) GetEncloseScope() Scope

func (Variable) GetName

func (s Variable) GetName() string

func (*Variable) GetType

func (v *Variable) GetType() Type

func (Variable) SetEncloseScope

func (s Variable) SetEncloseScope(scope Scope)

func (Variable) SetName

func (s Variable) SetName(name string)

func (*Variable) SetType

func (v *Variable) SetType(t Type)

func (*Variable) String

func (v *Variable) String() string

type VoidType

type VoidType struct {
}

func (*VoidType) GetEncloseScope

func (v *VoidType) GetEncloseScope() Scope

func (*VoidType) GetName

func (v *VoidType) GetName() string

func (*VoidType) IsType

func (v *VoidType) IsType(t Type) bool

Jump to

Keyboard shortcuts

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