MCPcopy Create free account
hub / github.com/crossoverJie/gscript / ExitFunctionDeclaration

Method ExitFunctionDeclaration

resolver/type_resolver.go:73–95  ·  view source on GitHub ↗

ExitFunctionDeclaration 函数声明,设置函数的返回类型

(ctx *parser.FunctionDeclarationContext)

Source from the content-addressed store, hash-verified

71
72// ExitFunctionDeclaration 函数声明,设置函数的返回类型
73func (t *TypeResolver) ExitFunctionDeclaration(ctx *parser.FunctionDeclarationContext) {
74 // TypeScopeResolver.EnterFunctionDeclaration() 写入的数据
75 function := t.at.GetNode2Scope()[ctx]
76 if ctx.TypeTypeOrVoid() != nil {
77 // ExitTypeTypeOrVoid 设置的返回值类型
78 returnType := t.at.GetTypeOfNode()[ctx.TypeTypeOrVoid()]
79 switch function.(type) {
80 case *symbol.Func:
81 function.(*symbol.Func).SetReturnType(returnType)
82 }
83 }
84
85 switch function.(type) {
86 case *symbol.Func:
87 fn := function.(*symbol.Func)
88 scope := t.at.FindEncloseScopeOfNode(ctx)
89 found := t.at.FindFunction(scope, fn.GetName(), fn.GetParameterType())
90 if found != nil && found != function && found.GetName() != symbol.OperatorName {
91 t.at.Log(ctx, fmt.Sprintf("%s already declared in this block", found.GetName()))
92 }
93 }
94
95}
96
97// ExitFormalParameter 函数入参,设置函数入参类型
98func (t *TypeResolver) ExitFormalParameter(ctx *parser.FormalParameterContext) {

Callers

nothing calls this directly

Calls 9

GetNode2ScopeMethod · 0.80
GetTypeOfNodeMethod · 0.80
SetReturnTypeMethod · 0.80
FindFunctionMethod · 0.80
LogMethod · 0.80
GetNameMethod · 0.65
GetParameterTypeMethod · 0.65
TypeTypeOrVoidMethod · 0.45

Tested by

no test coverage detected