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

Method getFunctionObject

visitor.go:969–996  ·  view source on GitHub ↗

获取函数的 object 对象,需要用来压栈

(ctx *parser.FunctionCallContext)

Source from the content-addressed store, hash-verified

967
968// 获取函数的 object 对象,需要用来压栈
969func (v *Visitor) getFunctionObject(ctx *parser.FunctionCallContext) *stack.FuncObject {
970 var (
971 funcObject *stack.FuncObject
972 function *sym.Func
973 )
974 symbol := v.at.GetSymbolOfNode()[ctx]
975 switch symbol.(type) {
976 case *sym.Func:
977 function = symbol.(*sym.Func)
978 case *sym.Variable:
979 // symbol 是函数变量类型
980 variable := symbol.(*sym.Variable)
981 value := v.getLeftValue(variable).GetValue()
982 functionObject, ok := value.(*stack.FuncObject)
983 if ok {
984 function = functionObject.GetFunction()
985 return functionObject
986 }
987
988 default:
989 name := ctx.IDENTIFIER().GetText()
990 log.RuntimePanic(ctx, fmt.Sprintf("unable find function %s", name))
991
992 }
993
994 funcObject = stack.NewFuncObject(function)
995 return funcObject
996}
997
998// 构建函数调用的参数值 myfunc(2+2+a) 2+2+a 的值
999func (v *Visitor) buildParamValues(ctx *parser.FunctionCallContext) []interface{} {

Callers 2

VisitFunctionCallMethod · 0.95
receiveFunctionCallMethod · 0.95

Calls 8

getLeftValueMethod · 0.95
RuntimePanicFunction · 0.92
NewFuncObjectFunction · 0.92
GetSymbolOfNodeMethod · 0.80
GetTextMethod · 0.80
GetValueMethod · 0.65
GetFunctionMethod · 0.65
IDENTIFIERMethod · 0.45

Tested by

no test coverage detected