Documentation
¶
Index ¶
- type AnnotatedTree
- func (a *AnnotatedTree) AppendType(t symbol.Type)
- 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) FindVariable(scope symbol.Scope, name string) *symbol.Variable
- func (a *AnnotatedTree) GetNode2Scope() map[antlr.ParserRuleContext]symbol.Scope
- 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) 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)
- type RefResolver
- func (s *RefResolver) EnterVariableDeclarators(ctx *parser.VariableDeclaratorsContext)
- 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) EnterVariableDeclaratorId(ctx *parser.VariableDeclaratorIdContext)
- func (t *TypeResolver) ExitFormalParameter(ctx *parser.FormalParameterContext)
- func (t *TypeResolver) ExitFunctionDeclaration(ctx *parser.FunctionDeclarationContext)
- 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) EnterFunctionDeclaration(ctx *parser.FunctionDeclarationContext)
- func (t *TypeScopeResolver) EnterProg(ctx *parser.ProgContext)
- func (t *TypeScopeResolver) EnterStmFor(ctx *parser.StmForContext)
- func (t *TypeScopeResolver) ExitBlock(ctx *parser.BlockContext)
- func (t *TypeScopeResolver) ExitFunctionDeclaration(ctx *parser.FunctionDeclarationContext)
- func (t *TypeScopeResolver) ExitProg(ctx *parser.ProgContext)
- func (t *TypeScopeResolver) ExitStmFor(ctx *parser.StmForContext)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnnotatedTree ¶
type AnnotatedTree struct {
// contains filtered or unexported fields
}
func NewAnnotatedTree ¶
func NewAnnotatedTree(ast antlr.ParseTree) *AnnotatedTree
func (*AnnotatedTree) AppendType ¶
func (a *AnnotatedTree) AppendType(t symbol.Type)
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) FindVariable ¶
FindVariable 根据变量名称在 scope 中逐级查找变量
func (*AnnotatedTree) GetNode2Scope ¶
func (a *AnnotatedTree) GetNode2Scope() map[antlr.ParserRuleContext]symbol.Scope
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) 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)
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) 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) 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) 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) EnterFunctionDeclaration ¶
func (t *TypeScopeResolver) EnterFunctionDeclaration(ctx *parser.FunctionDeclarationContext)
EnterFunctionDeclaration 加入一个 func 的 scope
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) ExitBlock ¶
func (t *TypeScopeResolver) ExitBlock(ctx *parser.BlockContext)
ExitBlock is called when production block is exited.
func (*TypeScopeResolver) ExitFunctionDeclaration ¶
func (t *TypeScopeResolver) ExitFunctionDeclaration(ctx *parser.FunctionDeclarationContext)
ExitFunctionDeclaration is called when production functionDeclaration 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.