| 311 | } |
| 312 | |
| 313 | static int compare_functions(const std::vector<reshadefx::expression> &arguments, const reshadefx::function *function1, const reshadefx::function *function2) |
| 314 | { |
| 315 | const size_t num_arguments = arguments.size(); |
| 316 | |
| 317 | // Check if the first function matches the argument types |
| 318 | bool function1_viable = true; |
| 319 | const auto function1_ranks = static_cast<unsigned int *>(alloca(num_arguments * sizeof(unsigned int))); |
| 320 | for (size_t i = 0; i < num_arguments; ++i) |
| 321 | { |
| 322 | if ((function1_ranks[i] = reshadefx::type::rank(arguments[i].type, function1->parameter_list[i].type)) == 0) |
| 323 | { |
| 324 | function1_viable = false; |
| 325 | break; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // Catch case where the second function does not exist |
| 330 | if (function2 == nullptr) |
| 331 | return function1_viable ? -1 : 1; // If the first function is not viable, this compare fails |
| 332 | |
| 333 | // Check if the second function matches the argument types |
| 334 | bool function2_viable = true; |
| 335 | const auto function2_ranks = static_cast<unsigned int *>(alloca(num_arguments * sizeof(unsigned int))); |
| 336 | for (size_t i = 0; i < num_arguments; ++i) |
| 337 | { |
| 338 | if ((function2_ranks[i] = reshadefx::type::rank(arguments[i].type, function2->parameter_list[i].type)) == 0) |
| 339 | { |
| 340 | function2_viable = false; |
| 341 | break; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | // If one of the functions is not viable, then the other one automatically wins |
| 346 | if (!function1_viable || !function2_viable) |
| 347 | return function2_viable - function1_viable; |
| 348 | |
| 349 | // Both functions are possible, so find the one with the higher ranking |
| 350 | std::sort(function1_ranks, function1_ranks + num_arguments, std::greater<unsigned int>()); |
| 351 | std::sort(function2_ranks, function2_ranks + num_arguments, std::greater<unsigned int>()); |
| 352 | |
| 353 | for (size_t i = 0; i < num_arguments; ++i) |
| 354 | if (function1_ranks[i] > function2_ranks[i]) |
| 355 | return -1; // Left function wins |
| 356 | else if (function2_ranks[i] > function1_ranks[i]) |
| 357 | return +1; // Right function wins |
| 358 | |
| 359 | return 0; // Both functions are equally viable |
| 360 | } |
| 361 | |
| 362 | bool reshadefx::symbol_table::resolve_function_call(const std::string &name, const std::vector<expression> &arguments, const scope &scope, symbol &out_data, bool &is_ambiguous) const |
| 363 | { |
no outgoing calls
no test coverage detected