Documentation
¶
Index ¶
- Constants
- Variables
- func GetType(t1, t2 Type, left, right interface{}) (Type, Type)
- func MatchNil(t Type) bool
- func Value2Float(v interface{}) float64
- type BlockScope
- func (s BlockScope) AddSymbol(symbol Symbol)
- func (s BlockScope) ContainsSymbol(symbol Symbol) bool
- func (s BlockScope) GetClass(name string) *Class
- func (s BlockScope) GetCtx() antlr.ParserRuleContext
- func (s BlockScope) GetFunction(name string, paramTypes []Type) *Func
- func (s BlockScope) GetFunctionVariable(name string, paramTypes []Type) *Variable
- func (s BlockScope) GetSymbols() []Symbol
- func (s BlockScope) GetVariable(name string) *Variable
- func (s BlockScope) SetCtx(ctx antlr.ParserRuleContext)
- func (v *BlockScope) String() string
- type Class
- func (c *Class) AddSymbol(symbol Symbol)
- func (c *Class) ContainsSymbol(symbol Symbol) bool
- func (s Class) GetClass(name string) *Class
- func (c *Class) GetClassFunctionVariable(name string, paramTypes []Type) *Variable
- func (c *Class) GetConstructorFunc(paramTypes []Type) *Func
- func (s Class) GetCtx() antlr.ParserRuleContext
- func (c *Class) GetDefaultConstructorFunc() *DefaultConstructorFunc
- func (c *Class) GetFunction(name string, paramTypes []Type) *Func
- func (s Class) GetFunctionVariable(name string, paramTypes []Type) *Variable
- func (s Class) GetSymbols() []Symbol
- func (c *Class) GetVariable(name string) *Variable
- func (c *Class) IsArray() bool
- func (c *Class) IsType(t Type) bool
- func (c *Class) SetArray(isArray bool)
- func (s Class) SetCtx(ctx antlr.ParserRuleContext)
- func (c *Class) String() string
- type DeclareFunctionType
- func (d *DeclareFunctionType) AppendParameterType(t Type)
- func (d *DeclareFunctionType) GetEncloseScope() Scope
- func (d *DeclareFunctionType) GetName() string
- func (d *DeclareFunctionType) GetParameterType() []Type
- func (d *DeclareFunctionType) GetReturnType() Type
- func (d *DeclareFunctionType) IsArray() bool
- func (d *DeclareFunctionType) IsType(t Type) bool
- func (d *DeclareFunctionType) MatchParameterTypes(types []Type) bool
- func (d *DeclareFunctionType) SetArray(isArray bool)
- type DefaultConstructorFunc
- func (s DefaultConstructorFunc) AddSymbol(symbol Symbol)
- func (s DefaultConstructorFunc) ContainsSymbol(symbol Symbol) bool
- func (d *DefaultConstructorFunc) GetClass() *Class
- func (s DefaultConstructorFunc) GetCtx() antlr.ParserRuleContext
- func (s DefaultConstructorFunc) GetFunction(name string, paramTypes []Type) *Func
- func (s DefaultConstructorFunc) GetFunctionVariable(name string, paramTypes []Type) *Variable
- func (s DefaultConstructorFunc) GetSymbols() []Symbol
- func (s DefaultConstructorFunc) GetVariable(name string) *Variable
- func (s DefaultConstructorFunc) SetCtx(ctx antlr.ParserRuleContext)
- func (d *DefaultConstructorFunc) String() string
- type Func
- func (s Func) AddSymbol(symbol Symbol)
- func (f *Func) AppendParameter(v *Variable)
- func (s Func) ContainsSymbol(symbol Symbol) bool
- func (s Func) GetClass(name string) *Class
- func (f *Func) GetClosureVar() container.Set
- func (s Func) GetCtx() antlr.ParserRuleContext
- func (f *Func) GetEncloseScope() Scope
- func (s Func) GetFunction(name string, paramTypes []Type) *Func
- func (s Func) GetFunctionVariable(name string, paramTypes []Type) *Variable
- func (f *Func) GetName() string
- func (f *Func) GetParameterType() []Type
- func (f *Func) GetReturnType() Type
- func (s Func) GetSymbols() []Symbol
- func (s Func) GetVariable(name string) *Variable
- func (f *Func) IsArray() bool
- func (f *Func) IsConstructor() bool
- func (f *Func) IsMethod() bool
- func (f *Func) IsType(t Type) bool
- func (f *Func) MatchParameterTypes(paramTypes []Type) bool
- func (f *Func) SetArray(isArray bool)
- func (f *Func) SetClosureVar(closureVar container.Set)
- func (s Func) SetCtx(ctx antlr.ParserRuleContext)
- func (f *Func) SetEncloseScope(scope Scope)
- func (f *Func) SetName(name string)
- func (f *Func) SetReturnType(t Type)
- func (f *Func) String() string
- type FuncType
- type OpOverload
- type PrimitiveType
- type Scope
- type Symbol
- type Type
- type Variable
- func (s Variable) GetEncloseScope() Scope
- func (s Variable) GetName() string
- func (v *Variable) GetType() Type
- func (v *Variable) IsArray() bool
- func (v *Variable) SetArray(isArray bool)
- func (s Variable) SetEncloseScope(scope Scope)
- func (s Variable) SetName(name string)
- func (v *Variable) SetType(t Type)
- func (v *Variable) String() string
- type VoidType
Constants ¶
View Source
const ( PrimitiveInt = "int" PrimitiveString = "string" PrimitiveFloat = "float" PrimitiveBool = "bool" PrimitiveNil = "nil" PrimitiveAny = "any" PrimitiveByte = "byte" )
View Source
const OperatorName = "operator"
Variables ¶
View Source
var ( Int = &PrimitiveType{name: PrimitiveInt} String = &PrimitiveType{name: PrimitiveString} Float = &PrimitiveType{name: PrimitiveFloat} Bool = &PrimitiveType{name: PrimitiveBool} Byte = &PrimitiveType{name: PrimitiveByte} Void = &VoidType{} Nil = &PrimitiveType{name: PrimitiveNil} Any = &PrimitiveType{name: PrimitiveAny} )
Functions ¶
func GetType ¶ added in v0.0.8
GetType 运行时根据实际值推算出类型 *
if( n[0] + n[1] == 3){ println(3); }
推断出 n[0] + n[1] 的 type 为 int,因为这个表达式 type 在编译器计算不出来
func Value2Float ¶ added in v0.0.6
func Value2Float(v interface{}) float64
Types ¶
type BlockScope ¶
type BlockScope struct {
// contains filtered or unexported fields
}
func (BlockScope) ContainsSymbol ¶
func (BlockScope) GetCtx ¶
func (s BlockScope) GetCtx() antlr.ParserRuleContext
func (BlockScope) GetFunction ¶
func (BlockScope) GetFunctionVariable ¶ added in v0.0.6
func (BlockScope) GetSymbols ¶
func (s BlockScope) GetSymbols() []Symbol
func (BlockScope) GetVariable ¶
func (BlockScope) SetCtx ¶
func (s BlockScope) SetCtx(ctx antlr.ParserRuleContext)
func (*BlockScope) String ¶
func (v *BlockScope) String() string
type Class ¶ added in v0.0.6
type Class struct {
// contains filtered or unexported fields
}
func (*Class) ContainsSymbol ¶ added in v0.0.6
func (*Class) GetClassFunctionVariable ¶ added in v0.0.6
GetClassFunctionVariable 查找类中的函数变量
func (*Class) GetConstructorFunc ¶ added in v0.0.6
GetConstructorFunc 查找显式的构造函数,函数名称就是类名称
func (Class) GetCtx ¶ added in v0.0.6
func (s Class) GetCtx() antlr.ParserRuleContext
func (*Class) GetDefaultConstructorFunc ¶ added in v0.0.6
func (c *Class) GetDefaultConstructorFunc() *DefaultConstructorFunc
func (*Class) GetFunction ¶ added in v0.0.6
GetFunction 查找类中的函数
func (Class) GetFunctionVariable ¶ added in v0.0.6
func (Class) GetSymbols ¶ added in v0.0.6
func (s Class) GetSymbols() []Symbol
func (*Class) GetVariable ¶ added in v0.0.6
GetVariable 在 class 中查找变量
func (Class) SetCtx ¶ added in v0.0.6
func (s Class) SetCtx(ctx antlr.ParserRuleContext)
type DeclareFunctionType ¶ added in v0.0.6
type DeclareFunctionType struct {
// contains filtered or unexported fields
}
func NewDeclareFunctionType ¶ added in v0.0.6
func NewDeclareFunctionType(returnType Type) *DeclareFunctionType
NewDeclareFunctionType 函数类型的变量 func int(int) f2 = f1(); f2 的类型
func (*DeclareFunctionType) AppendParameterType ¶ added in v0.0.6
func (d *DeclareFunctionType) AppendParameterType(t Type)
func (*DeclareFunctionType) GetEncloseScope ¶ added in v0.0.6
func (d *DeclareFunctionType) GetEncloseScope() Scope
func (*DeclareFunctionType) GetName ¶ added in v0.0.6
func (d *DeclareFunctionType) GetName() string
func (*DeclareFunctionType) GetParameterType ¶ added in v0.0.6
func (d *DeclareFunctionType) GetParameterType() []Type
func (*DeclareFunctionType) GetReturnType ¶ added in v0.0.6
func (d *DeclareFunctionType) GetReturnType() Type
func (*DeclareFunctionType) IsArray ¶ added in v0.0.11
func (d *DeclareFunctionType) IsArray() bool
func (*DeclareFunctionType) IsType ¶ added in v0.0.6
func (d *DeclareFunctionType) IsType(t Type) bool
func (*DeclareFunctionType) MatchParameterTypes ¶ added in v0.0.6
func (d *DeclareFunctionType) MatchParameterTypes(types []Type) bool
func (*DeclareFunctionType) SetArray ¶ added in v0.0.11
func (d *DeclareFunctionType) SetArray(isArray bool)
type DefaultConstructorFunc ¶ added in v0.0.6
type DefaultConstructorFunc struct {
// contains filtered or unexported fields
}
func NewDefaultConstructorFunc ¶ added in v0.0.6
func NewDefaultConstructorFunc(name string, class *Class) *DefaultConstructorFunc
func (DefaultConstructorFunc) AddSymbol ¶ added in v0.0.6
func (s DefaultConstructorFunc) AddSymbol(symbol Symbol)
func (DefaultConstructorFunc) ContainsSymbol ¶ added in v0.0.6
func (*DefaultConstructorFunc) GetClass ¶ added in v0.0.6
func (d *DefaultConstructorFunc) GetClass() *Class
GetClass 获取构造函数对应的 class
func (DefaultConstructorFunc) GetCtx ¶ added in v0.0.6
func (s DefaultConstructorFunc) GetCtx() antlr.ParserRuleContext
func (DefaultConstructorFunc) GetFunction ¶ added in v0.0.6
func (DefaultConstructorFunc) GetFunctionVariable ¶ added in v0.0.6
func (DefaultConstructorFunc) GetSymbols ¶ added in v0.0.6
func (s DefaultConstructorFunc) GetSymbols() []Symbol
func (DefaultConstructorFunc) GetVariable ¶ added in v0.0.6
func (DefaultConstructorFunc) SetCtx ¶ added in v0.0.6
func (s DefaultConstructorFunc) SetCtx(ctx antlr.ParserRuleContext)
func (*DefaultConstructorFunc) String ¶ added in v0.0.6
func (d *DefaultConstructorFunc) String() string
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
func GetFunction ¶
GetFunction 在 scope 中查询函数,需要入参相同
func (*Func) AppendParameter ¶
func (Func) ContainsSymbol ¶
func (*Func) GetClosureVar ¶ added in v0.0.6
func (Func) GetCtx ¶
func (s Func) GetCtx() antlr.ParserRuleContext
func (*Func) GetEncloseScope ¶
func (Func) GetFunction ¶
func (Func) GetFunctionVariable ¶ added in v0.0.6
func (*Func) GetReturnType ¶
func (Func) GetSymbols ¶
func (s Func) GetSymbols() []Symbol
func (Func) GetVariable ¶
func (*Func) IsConstructor ¶ added in v0.0.6
IsConstructor 当前函数是否为构造函数,也就是函数名称是否与函数声明所在的 class 名称相同
func (*Func) MatchParameterTypes ¶
MatchParameterTypes 通过参数类型匹配函数是否一致
func (*Func) SetClosureVar ¶ added in v0.0.6
func (Func) SetCtx ¶
func (s Func) SetCtx(ctx antlr.ParserRuleContext)
func (*Func) SetEncloseScope ¶
func (*Func) SetReturnType ¶
type OpOverload ¶ added in v0.0.7
type OpOverload struct {
// contains filtered or unexported fields
}
OpOverload 重载符
func NewOpOverload ¶ added in v0.0.7
func NewOpOverload(function *Func, tokenType int) *OpOverload
func (*OpOverload) GetFunc ¶ added in v0.0.7
func (o *OpOverload) GetFunc() *Func
func (*OpOverload) GetTokenType ¶ added in v0.0.7
func (o *OpOverload) GetTokenType() int
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) IsArray ¶ added in v0.0.6
func (b *PrimitiveType) IsArray() bool
func (*PrimitiveType) IsType ¶
func (b *PrimitiveType) IsType(t Type) bool
func (*PrimitiveType) SetArray ¶ added in v0.0.11
func (b *PrimitiveType) SetArray(isArray 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) GetCtx() antlr.ParserRuleContext GetVariable(name string) *Variable GetFunction(name string, paramTypes []Type) *Func GetFunctionVariable(name string, paramTypes []Type) *Variable GetClass(name string) *Class String() string }
func NewBlockScope ¶
func NewBlockScope(ctx antlr.ParserRuleContext, name string, s Scope) Scope
type Type ¶
type Type interface { GetName() string GetEncloseScope() Scope // IsType 判断类型是否相同,或者是不是 is-a ,是否为子类 IsType(t Type) bool IsArray() bool SetArray(isArray bool) }
func GetUpperType ¶ added in v0.0.6
func GetUpperType(ctx antlr.ParserRuleContext, t1, t2 Type) Type
GetUpperType 根据两个参数类型,推导返回的类型
func GetUpperTypeWithValue ¶ added in v0.0.8
func GetUpperTypeWithValue(ctx antlr.ParserRuleContext, v1, v2 interface{}) Type
GetUpperTypeWithValue 根据两个参数值,返回推到类型
func NewPrimitiveType ¶ added in v0.0.12
func NewPrimitiveTypeWithType ¶ added in v0.0.12
type Variable ¶
type Variable struct {
// contains filtered or unexported fields
}
func GetFunctionVariable ¶ added in v0.0.6
GetFunctionVariable 在当前 scope 中查找函数变量,其中变量中的函数的入参得匹配。
func GetVariable ¶
GetVariable 从 scope 中通过变量名称查询变量
func NewVariable ¶
func (Variable) GetEncloseScope ¶
func (s Variable) GetEncloseScope() Scope
func (Variable) SetEncloseScope ¶
func (s Variable) SetEncloseScope(scope Scope)
Click to show internal directories.
Click to hide internal directories.