public override Exit visitFuncInvoke(FuncInvocation funcInvocation, Environment env) { for (var i = 0; i < funcInvocation.args.Count; i++) { analyzeExpr(funcInvocation.args[i], env); } return(0); }
public override Type visitFuncInvoke(FuncInvocation invocation, Environment env) { // resolve func string name = invocation.funcName; FuncSymbol fsym = (FuncSymbol)env.scope.findFirst(name, s => s.kind == Kind.FUNC); if (fsym == null) { log.error(invocation.Pos, messages.functionNotDefined, name); // we dont need any validation invocation.type = symtab.errorType; return(symtab.errorType); } return(analyzeInvocation(invocation, fsym, env)); }
private Type analyzeInvocation(FuncInvocation invocation, FuncSymbol fsym, Environment env) { IList <Expression> args = invocation.args; // check argument count IList <VarSymbol> paramSyms = fsym.parameters; if (fsym.isVararg ? args.Count < paramSyms.Count : args.Count != paramSyms.Count) { log.error(invocation.Pos, messages.wrongNumberOfArgs, fsym.name, paramSyms.Count, args.Count); } // check argument types int count = Math.Min(args.Count, paramSyms.Count); for (int i = 0; i < count; i++) { VarSymbol paramSym = paramSyms[i]; Type argType = analyzeExpr(args[i], env); // we don't consider implicit numeric conversions for now if (!typings.isAssignableFrom(paramSym.type, argType)) { log.error(invocation.Pos, messages.paramTypeMismatch, fsym.name); } } for (int i = count; i < args.Count; ++i) { analyzeExpr(args[i], env); } fsym.isInvoked = true; invocation.funcSym = fsym; invocation.type = fsym.type.ReturnType; return(fsym.type.ReturnType); }
public virtual T visitFuncInvoke(FuncInvocation funcInvocation, A arg) => visit(funcInvocation, arg);