| 1765 | }; |
| 1766 | |
| 1767 | static CompareFunctionsResult CompareFunctions(HLSLTree* tree, const HLSLFunctionCall* call, const HLSLFunction* function1, const HLSLFunction* function2) |
| 1768 | { |
| 1769 | int* function1Ranks = static_cast<int*>(alloca(sizeof(int) * call->numArguments)); |
| 1770 | int* function2Ranks = static_cast<int*>(alloca(sizeof(int) * call->numArguments)); |
| 1771 | |
| 1772 | const bool function1Viable = GetFunctionCallCastRanks(tree, call, function1, function1Ranks); |
| 1773 | const bool function2Viable = GetFunctionCallCastRanks(tree, call, function2, function2Ranks); |
| 1774 | |
| 1775 | // Both functions have to be viable to be able to compare them |
| 1776 | if (!(function1Viable && function2Viable)) { |
| 1777 | if (function1Viable) { |
| 1778 | return Function1Better; |
| 1779 | } |
| 1780 | else if (function2Viable) { |
| 1781 | return Function2Better; |
| 1782 | } |
| 1783 | else { |
| 1784 | return FunctionsEqual; |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | std::sort(function1Ranks, function1Ranks + call->numArguments, CompareRanks()); |
| 1789 | std::sort(function2Ranks, function2Ranks + call->numArguments, CompareRanks()); |
| 1790 | |
| 1791 | for (int i = 0; i < call->numArguments; ++i) { |
| 1792 | if (function1Ranks[i] < function2Ranks[i]) { |
| 1793 | return Function1Better; |
| 1794 | } |
| 1795 | else if (function2Ranks[i] < function1Ranks[i]) { |
| 1796 | return Function2Better; |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | return FunctionsEqual; |
| 1801 | } |
| 1802 | |
| 1803 | static bool GetBinaryOpResultType(HLSLBinaryOp binaryOp, const HLSLType& type1, const HLSLType& type2, HLSLType& result) |
| 1804 | { |
no test coverage detected