Documentation
¶
Index ¶
- func Scope2String(buf *strings.Builder, scope symbol.Scope, indent string)
- type AnnotatedTree
- func (a *AnnotatedTree) AppendOpOverload(op *symbol.OpOverload)
- func (a *AnnotatedTree) AppendType(t symbol.Type)
- func (a *AnnotatedTree) DumpAST() string
- func (a *AnnotatedTree) DumpSymbol() string
- func (a *AnnotatedTree) FindClass(scope symbol.Scope, name string) *symbol.Class
- func (a *AnnotatedTree) FindEncloseScopeOfNode(ctx antlr.ParserRuleContext) symbol.Scope
- func (a *AnnotatedTree) FindFunction(scope symbol.Scope, name string, paramTypes []symbol.Type) *symbol.Func
- func (a *AnnotatedTree) FindFunctionVariable(scope symbol.Scope, name string, paramTypes []symbol.Type) *symbol.Variable
- func (a *AnnotatedTree) FindFunctionWithName(scope symbol.Scope, name string) *symbol.Func
- func (a *AnnotatedTree) FindVariable(scope symbol.Scope, name string) *symbol.Variable
- func (a *AnnotatedTree) GetFunction2Scope(ctx antlr.ParserRuleContext) *symbol.Func
- func (a *AnnotatedTree) GetHttpPathVariable() *symbol.Variable
- func (a *AnnotatedTree) GetNode2Scope() map[antlr.ParserRuleContext]symbol.Scope
- func (a *AnnotatedTree) GetOpFunction(returnType symbol.Type, tokenType int) *symbol.Func
- func (a *AnnotatedTree) GetRecursion(ctx antlr.ParserRuleContext) bool
- func (a *AnnotatedTree) GetSymbolOfNode() map[antlr.ParserRuleContext]symbol.Symbol
- func (a *AnnotatedTree) GetTypeOfNode() map[antlr.ParserRuleContext]symbol.Type
- func (a *AnnotatedTree) GetTypes() []symbol.Type
- func (a *AnnotatedTree) IsCompileFail() bool
- func (a *AnnotatedTree) Log(ctx antlr.ParserRuleContext, msg string)
- func (a *AnnotatedTree) PutFunction2Scope(ctx antlr.ParserRuleContext, function *symbol.Func)
- func (a *AnnotatedTree) PutNode2Scope(ctx antlr.ParserRuleContext, symbol symbol.Scope)
- func (a *AnnotatedTree) PutSymbolOfNode(ctx antlr.ParserRuleContext, symbol symbol.Symbol)
- func (a *AnnotatedTree) PutTypeOfNode(ctx antlr.ParserRuleContext, t symbol.Type)
- func (a *AnnotatedTree) SetHttpPathVariable(path *symbol.Variable)
- func (a *AnnotatedTree) SetRecursion(ctx antlr.ParserRuleContext, isRecursion bool)
- func (a *AnnotatedTree) SetRootScope(scope symbol.Scope)
- type ClosureResolver
- type RefResolver
- func (s *RefResolver) EnterVariableDeclarators(ctx *parser.VariableDeclaratorsContext)
- func (s *RefResolver) ExitArrayInitializer(ctx *parser.ArrayInitializerContext)
- func (s *RefResolver) ExitBlockStms(ctx *parser.BlockStmsContext)
- func (s *RefResolver) ExitExpr(ctx *parser.ExprContext)
- func (s *RefResolver) ExitFunctionCall(ctx *parser.FunctionCallContext)
- func (s *RefResolver) ExitLiteral(ctx *parser.LiteralContext)
- func (s *RefResolver) ExitPrimary(ctx *parser.PrimaryContext)
- type TypeResolver
- func (t *TypeResolver) EnterClassDeclaration(ctx *parser.ClassDeclarationContext)
- func (t *TypeResolver) EnterClassOrInterfaceType(ctx *parser.ClassOrInterfaceTypeContext)
- func (t *TypeResolver) EnterVariableDeclaratorId(ctx *parser.VariableDeclaratorIdContext)
- func (t *TypeResolver) ExitFormalParameter(ctx *parser.FormalParameterContext)
- func (t *TypeResolver) ExitFunctionDeclaration(ctx *parser.FunctionDeclarationContext)
- func (t *TypeResolver) ExitFunctionType(ctx *parser.FunctionTypeContext)
- func (t *TypeResolver) ExitLastFormalParameter(ctx *parser.LastFormalParameterContext)
- func (t *TypeResolver) ExitPrimitiveType(ctx *parser.PrimitiveTypeContext)
- func (t *TypeResolver) ExitTypeType(ctx *parser.TypeTypeContext)
- func (t *TypeResolver) ExitTypeTypeOrVoid(ctx *parser.TypeTypeOrVoidContext)
- func (t *TypeResolver) ExitVariableDeclarators(ctx *parser.VariableDeclaratorsContext)
- type TypeScopeResolver
- func (t *TypeScopeResolver) EnterBlock(ctx *parser.BlockContext)
- func (t *TypeScopeResolver) EnterClassDeclaration(ctx *parser.ClassDeclarationContext)
- func (t *TypeScopeResolver) EnterFunctionDeclaration(ctx *parser.FunctionDeclarationContext)
- func (t *TypeScopeResolver) EnterOperatorOverloading(ctx *parser.OperatorOverloadingContext)
- func (t *TypeScopeResolver) EnterProg(ctx *parser.ProgContext)
- func (t *TypeScopeResolver) EnterStmFor(ctx *parser.StmForContext)
- func (t *TypeScopeResolver) EnterStmWhile(ctx *parser.StmWhileContext)
- func (t *TypeScopeResolver) ExitBlock(ctx *parser.BlockContext)
- func (t *TypeScopeResolver) ExitClassDeclaration(ctx *parser.ClassDeclarationContext)
- func (t *TypeScopeResolver) ExitFunctionDeclaration(ctx *parser.FunctionDeclarationContext)
- func (t *TypeScopeResolver) ExitOperatorOverloading(ctx *parser.OperatorOverloadingContext)
- func (t *TypeScopeResolver) ExitProg(ctx *parser.ProgContext)
- func (t *TypeScopeResolver) ExitStmFor(ctx *parser.StmForContext)
- func (t *TypeScopeResolver) ExitStmWhile(ctx *parser.StmWhileContext)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AnnotatedTree ¶
type AnnotatedTree struct {
// contains filtered or unexported fields
}
func NewAnnotatedTree ¶
func NewAnnotatedTree(ast antlr.ParseTree, r antlr.Recognizer) *AnnotatedTree
func (*AnnotatedTree) AppendOpOverload ¶ added in v0.0.7
func (a *AnnotatedTree) AppendOpOverload(op *symbol.OpOverload)
func (*AnnotatedTree) AppendType ¶
func (a *AnnotatedTree) AppendType(t symbol.Type)
func (*AnnotatedTree) DumpAST ¶ added in v0.0.11
func (a *AnnotatedTree) DumpAST() string
func (*AnnotatedTree) DumpSymbol ¶ added in v0.0.11
func (a *AnnotatedTree) DumpSymbol() string
func (*AnnotatedTree) FindEncloseScopeOfNode ¶
func (a *AnnotatedTree) FindEncloseScopeOfNode(ctx antlr.ParserRuleContext) symbol.Scope
FindEncloseScopeOfNode 查找某个 ctx 所在的 scope,逐级递归 ctx 查找
func (*AnnotatedTree) FindFunction ¶
func (a *AnnotatedTree) FindFunction(scope symbol.Scope, name string, paramTypes []symbol.Type) *symbol.Func
FindFunction 根据方法名称+方法参数查询方法
func (*AnnotatedTree) FindFunctionVariable ¶ added in v0.0.6
func (a *AnnotatedTree) FindFunctionVariable(scope symbol.Scope, name string, paramTypes []symbol.Type) *symbol.Variable
FindFunctionVariable 查找函数类型的变量:变量中存放的值是 functionObject
func (*AnnotatedTree) FindFunctionWithName ¶ added in v0.0.6
FindFunctionWithName 只通过函数名称查询 先查询 class 的method,再查询 function
func (*AnnotatedTree) FindVariable ¶
FindVariable 根据变量名称在 scope 中逐级查找变量
func (*AnnotatedTree) GetFunction2Scope ¶ added in v0.0.9
func (a *AnnotatedTree) GetFunction2Scope(ctx antlr.ParserRuleContext) *symbol.Func
func (*AnnotatedTree) GetHttpPathVariable ¶ added in v0.0.8
func (a *AnnotatedTree) GetHttpPathVariable() *symbol.Variable
func (*AnnotatedTree) GetNode2Scope ¶
func (a *AnnotatedTree) GetNode2Scope() map[antlr.ParserRuleContext]symbol.Scope
func (*AnnotatedTree) GetOpFunction ¶ added in v0.0.7
GetOpFunction 获取运算符重载函数 通过返回值以及运算符号(+-*/) 匹配重载函数
func (*AnnotatedTree) GetRecursion ¶ added in v0.0.9
func (a *AnnotatedTree) GetRecursion(ctx antlr.ParserRuleContext) bool
func (*AnnotatedTree) GetSymbolOfNode ¶
func (a *AnnotatedTree) GetSymbolOfNode() map[antlr.ParserRuleContext]symbol.Symbol
func (*AnnotatedTree) GetTypeOfNode ¶
func (a *AnnotatedTree) GetTypeOfNode() map[antlr.ParserRuleContext]symbol.Type
func (*AnnotatedTree) GetTypes ¶
func (a *AnnotatedTree) GetTypes() []symbol.Type
func (*AnnotatedTree) IsCompileFail ¶ added in v0.0.9
func (a *AnnotatedTree) IsCompileFail() bool
func (*AnnotatedTree) Log ¶ added in v0.0.9
func (a *AnnotatedTree) Log(ctx antlr.ParserRuleContext, msg string)
func (*AnnotatedTree) PutFunction2Scope ¶ added in v0.0.9
func (a *AnnotatedTree) PutFunction2Scope(ctx antlr.ParserRuleContext, function *symbol.Func)
func (*AnnotatedTree) PutNode2Scope ¶
func (a *AnnotatedTree) PutNode2Scope(ctx antlr.ParserRuleContext, symbol symbol.Scope)
func (*AnnotatedTree) PutSymbolOfNode ¶
func (a *AnnotatedTree) PutSymbolOfNode(ctx antlr.ParserRuleContext, symbol symbol.Symbol)
func (*AnnotatedTree) PutTypeOfNode ¶
func (a *AnnotatedTree) PutTypeOfNode(ctx antlr.ParserRuleContext, t symbol.Type)
func (*AnnotatedTree) SetHttpPathVariable ¶ added in v0.0.8
func (a *AnnotatedTree) SetHttpPathVariable(path *symbol.Variable)
func (*AnnotatedTree) SetRecursion ¶ added in v0.0.9
func (a *AnnotatedTree) SetRecursion(ctx antlr.ParserRuleContext, isRecursion bool)
func (*AnnotatedTree) SetRootScope ¶ added in v0.0.11
func (a *AnnotatedTree) SetRootScope(scope symbol.Scope)
type ClosureResolver ¶ added in v0.0.6
type ClosureResolver struct {
// contains filtered or unexported fields
}
ClosureResolver 闭包分析,为函数生成闭包变量
func NewClosureResolver ¶ added in v0.0.6
func NewClosureResolver(at *AnnotatedTree) *ClosureResolver
func (*ClosureResolver) Analyze ¶ added in v0.0.6
func (c *ClosureResolver) Analyze()
Analyze 计算闭包变量:所有声明变量-内部声明变量
type RefResolver ¶
type RefResolver struct { parser.BaseGScriptListener // contains filtered or unexported fields }
RefResolver 引用消解和类型推断 函数调用,消解出是哪个 function,以及返回值类型
func NewRefResolver ¶
func NewRefResolver(at *AnnotatedTree) *RefResolver
func (*RefResolver) EnterVariableDeclarators ¶
func (s *RefResolver) EnterVariableDeclarators(ctx *parser.VariableDeclaratorsContext)
EnterVariableDeclarators 本地变量必须是添加和解析同时进行
func (*RefResolver) ExitArrayInitializer ¶ added in v0.0.12
func (s *RefResolver) ExitArrayInitializer(ctx *parser.ArrayInitializerContext)
ExitArrayInitializer 数组初始化校验,int[] a={1,2,"1"};
func (*RefResolver) ExitBlockStms ¶ added in v0.0.9
func (s *RefResolver) ExitBlockStms(ctx *parser.BlockStmsContext)
处理递归函数
func (*RefResolver) ExitExpr ¶
func (s *RefResolver) ExitExpr(ctx *parser.ExprContext)
func (*RefResolver) ExitFunctionCall ¶
func (s *RefResolver) ExitFunctionCall(ctx *parser.FunctionCallContext)
ExitFunctionCall 设置当前 scope 中的函数以及函数返回值
func (*RefResolver) ExitLiteral ¶
func (s *RefResolver) ExitLiteral(ctx *parser.LiteralContext)
func (*RefResolver) ExitPrimary ¶
func (s *RefResolver) ExitPrimary(ctx *parser.PrimaryContext)
type TypeResolver ¶
type TypeResolver struct { parser.BaseGScriptListener // contains filtered or unexported fields }
TypeResolver 第二次扫描,记录变量,类继承、函数声明等信息到 symbolOfNode 设置变量类型 对局部变量需要边添加边解析,不然会引起变量消解错误,比如父级 scope 和 局部变量中存在名称相同的变量,会导致局部变量消解到父级中的变量。
func NewTypeResolver ¶
func NewTypeResolver(at *AnnotatedTree) *TypeResolver
func NewTypeResolverWithLocalVariable ¶
func NewTypeResolverWithLocalVariable(at *AnnotatedTree) *TypeResolver
func (*TypeResolver) EnterClassDeclaration ¶ added in v0.0.6
func (t *TypeResolver) EnterClassDeclaration(ctx *parser.ClassDeclarationContext)
func (*TypeResolver) EnterClassOrInterfaceType ¶ added in v0.0.6
func (t *TypeResolver) EnterClassOrInterfaceType(ctx *parser.ClassOrInterfaceTypeContext)
func (*TypeResolver) EnterVariableDeclaratorId ¶
func (t *TypeResolver) EnterVariableDeclaratorId(ctx *parser.VariableDeclaratorIdContext)
func (*TypeResolver) ExitFormalParameter ¶
func (t *TypeResolver) ExitFormalParameter(ctx *parser.FormalParameterContext)
ExitFormalParameter 函数入参,设置函数入参类型
func (*TypeResolver) ExitFunctionDeclaration ¶
func (t *TypeResolver) ExitFunctionDeclaration(ctx *parser.FunctionDeclarationContext)
ExitFunctionDeclaration 函数声明,设置函数的返回类型
func (*TypeResolver) ExitFunctionType ¶ added in v0.0.6
func (t *TypeResolver) ExitFunctionType(ctx *parser.FunctionTypeContext)
ExitFunctionType 函数类型
func (*TypeResolver) ExitLastFormalParameter ¶ added in v0.0.9
func (t *TypeResolver) ExitLastFormalParameter(ctx *parser.LastFormalParameterContext)
ExitLastFormalParameter is called when production lastFormalParameter is exited.
func (*TypeResolver) ExitPrimitiveType ¶
func (t *TypeResolver) ExitPrimitiveType(ctx *parser.PrimitiveTypeContext)
ExitPrimitiveType 记录当前 ctx 的基本类型
func (*TypeResolver) ExitTypeType ¶
func (t *TypeResolver) ExitTypeType(ctx *parser.TypeTypeContext)
ExitTypeType 在 ExitPrimitiveType 之后记录当前 ctx 的基本类型
func (*TypeResolver) ExitTypeTypeOrVoid ¶
func (t *TypeResolver) ExitTypeTypeOrVoid(ctx *parser.TypeTypeOrVoidContext)
func (*TypeResolver) ExitVariableDeclarators ¶
func (t *TypeResolver) ExitVariableDeclarators(ctx *parser.VariableDeclaratorsContext)
ExitVariableDeclarators 设置变量类型
type TypeScopeResolver ¶
type TypeScopeResolver struct { parser.BaseGScriptListener // contains filtered or unexported fields }
TypeScopeResolver 第一次扫描,记录所有的类型:类、函数、scope 到 node2Scope 中。
func NewTypeScopeResolver ¶
func NewTypeScopeResolver(at *AnnotatedTree) *TypeScopeResolver
func (*TypeScopeResolver) EnterBlock ¶
func (t *TypeScopeResolver) EnterBlock(ctx *parser.BlockContext)
EnterBlock is called when production block is entered.
func (*TypeScopeResolver) EnterClassDeclaration ¶ added in v0.0.6
func (t *TypeScopeResolver) EnterClassDeclaration(ctx *parser.ClassDeclarationContext)
func (*TypeScopeResolver) EnterFunctionDeclaration ¶
func (t *TypeScopeResolver) EnterFunctionDeclaration(ctx *parser.FunctionDeclarationContext)
EnterFunctionDeclaration 加入一个 func 的 scope
func (*TypeScopeResolver) EnterOperatorOverloading ¶ added in v0.0.7
func (t *TypeScopeResolver) EnterOperatorOverloading(ctx *parser.OperatorOverloadingContext)
EnterOperatorOverloading is called when production operatorOverloading is entered.
func (*TypeScopeResolver) EnterProg ¶
func (t *TypeScopeResolver) EnterProg(ctx *parser.ProgContext)
func (*TypeScopeResolver) EnterStmFor ¶
func (t *TypeScopeResolver) EnterStmFor(ctx *parser.StmForContext)
EnterStmFor is called when production StmFor is entered.
func (*TypeScopeResolver) EnterStmWhile ¶ added in v0.0.6
func (t *TypeScopeResolver) EnterStmWhile(ctx *parser.StmWhileContext)
EnterStmWhile is called when production StmWhile is entered.
func (*TypeScopeResolver) ExitBlock ¶
func (t *TypeScopeResolver) ExitBlock(ctx *parser.BlockContext)
ExitBlock is called when production block is exited.
func (*TypeScopeResolver) ExitClassDeclaration ¶ added in v0.0.6
func (t *TypeScopeResolver) ExitClassDeclaration(ctx *parser.ClassDeclarationContext)
func (*TypeScopeResolver) ExitFunctionDeclaration ¶
func (t *TypeScopeResolver) ExitFunctionDeclaration(ctx *parser.FunctionDeclarationContext)
ExitFunctionDeclaration is called when production functionDeclaration is exited.
func (*TypeScopeResolver) ExitOperatorOverloading ¶ added in v0.0.7
func (t *TypeScopeResolver) ExitOperatorOverloading(ctx *parser.OperatorOverloadingContext)
ExitOperatorOverloading is called when production operatorOverloading is exited.
func (*TypeScopeResolver) ExitProg ¶
func (t *TypeScopeResolver) ExitProg(ctx *parser.ProgContext)
func (*TypeScopeResolver) ExitStmFor ¶
func (t *TypeScopeResolver) ExitStmFor(ctx *parser.StmForContext)
ExitStmFor is called when production StmFor is exited.
func (*TypeScopeResolver) ExitStmWhile ¶ added in v0.0.6
func (t *TypeScopeResolver) ExitStmWhile(ctx *parser.StmWhileContext)
ExitStmWhile is called when production StmWhile is exited.