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

Method ExitFunctionCall

resolver/ref_resolver.go:175–294  ·  view source on GitHub ↗

ExitFunctionCall 设置当前 scope 中的函数以及函数返回值

(ctx *parser.FunctionCallContext)

Source from the content-addressed store, hash-verified

173
174// ExitFunctionCall 设置当前 scope 中的函数以及函数返回值
175func (s *RefResolver) ExitFunctionCall(ctx *parser.FunctionCallContext) {
176
177 // todo crossoverJie 处理内置函数
178 name := ctx.IDENTIFIER().GetText()
179
180 paramTypes := s.getParamTypes(ctx)
181
182 scope := s.at.FindEncloseScopeOfNode(ctx)
183 found := false
184
185 // . 符号级联调用
186 context, ok := ctx.GetParent().(*parser.ExprContext)
187 if ok {
188 if context.GetBop() != nil && context.GetBop().GetTokenType() == parser.GScriptParserDOT {
189 sym := s.at.GetSymbolOfNode()[context.Expr(0)]
190 switch sym.(type) {
191 case *symbol.Variable:
192 variable := sym.(*symbol.Variable)
193 switch variable.GetType().(type) {
194 case *symbol.Class:
195 class := variable.GetType().(*symbol.Class)
196 // 查找类中的函数
197 function := class.GetFunction(name, paramTypes)
198 if function != nil {
199 found = true
200 s.at.PutSymbolOfNode(ctx, function)
201 s.at.PutTypeOfNode(ctx, function.GetReturnType())
202 } else {
203 // 类的变量是一个函数变量
204 functionVariable := class.GetClassFunctionVariable(name, paramTypes)
205 if functionVariable != nil {
206 found = true
207 s.at.PutSymbolOfNode(ctx, functionVariable)
208 // 改函数变量的返回类型
209 s.at.PutTypeOfNode(ctx, functionVariable.GetType().(symbol.FuncType).GetReturnType())
210 } else {
211 s.at.Log(ctx, fmt.Sprintf("%s.%s undefined (class %s has no function or function avariable)", variable.GetName(), name, class.GetName()))
212 }
213 }
214
215 }
216 }
217 }
218 }
219
220 // 查找全局函数
221 if !found {
222 function := s.at.FindFunction(scope, name, paramTypes)
223 if function != nil {
224 found = true
225 s.at.PutSymbolOfNode(ctx, function)
226 returnType := function.GetReturnType()
227 if returnType != nil {
228 // 兼容函数返回的是闭包变量 func int(int) f2 = f1();
229 newPrimitiveType := symbol.NewPrimitiveTypeWithType(returnType)
230 s.at.PutTypeOfNode(ctx, newPrimitiveType)
231 } else {
232 s.at.PutTypeOfNode(ctx, returnType)

Callers

nothing calls this directly

Calls 15

getParamTypesMethod · 0.95
NewPrimitiveTypeWithTypeFunction · 0.92
GetTextMethod · 0.80
GetParentMethod · 0.80
GetTokenTypeMethod · 0.80
GetSymbolOfNodeMethod · 0.80
GetTypeMethod · 0.80
PutSymbolOfNodeMethod · 0.80
PutTypeOfNodeMethod · 0.80
LogMethod · 0.80

Tested by

no test coverage detected