private static ILFunction FindFunction(string name, VAList vaList)
 {
     foreach (var KV in f_functionFindMap)
     {
         if (KV.Key.Header.FunctionName == name)
         {
             if (KV.Key.Header.ParametersCount == vaList.Count)
             {
                 int i = 0;
                 bool ok = true;
                 foreach (var p in KV.Key.Header.Parameters)
                 {
                     if (p.Type.Equals(vaList[i].ResultType) == false)
                     {
                         ok = false;
                         break;
                     }
                     i++;
                 }
                 if (ok)
                     return KV.Value;
             }
         }
     }
     throw new InvalidOperationException("Bad ILEmit situation - can't find function =(");
 }
        public static bool ValidateFunctionCall(string name, VAList args, SymbolTableLight table, LexLocation location, ref VariableType returnType)
        {
            bool ok = true;
            List<FunctionHeader> callCandidates = new List<FunctionHeader>();

            foreach (FunctionDefinition functionDef in Program.Functions)
            {
                if (functionDef.Header.FunctionName == name && functionDef.Header.ParametersCount == args.Count)
                {
                    callCandidates.Add(functionDef.Header);
                }
            }
            if (callCandidates.Count == 0)
            {
                CompilerServices.AddError(
                    location,
                    "Can't find function prototype for specified function name and number of parameters"
                );
                return false;
            }

            foreach (Expression ex in args)
            {
                bool valid = ex.Validate(table);
                ok = ok && valid;
            }

            if (ok)
            {
                foreach (FunctionHeader header in callCandidates)
                {
                    bool match = true;
                    int i = 0;
                    foreach (FunctionParameter parameter in header.Parameters)
                    {
                        if (!IsAssignable(parameter.Type, args[i].ResultType))
                            match = false;
                        i++;
                    }
                    if (match)
                    {
                        returnType = header.ReturnType;
                        return true;
                    }
                }
                CompilerServices.AddError(
                    location,
                    "Can't find function prototype for specified parameters"
                );
                return false;
            }

            return ok;
        }