| 1801 | } |
| 1802 | |
| 1803 | static bool GetBinaryOpResultType(HLSLBinaryOp binaryOp, const HLSLType& type1, const HLSLType& type2, HLSLType& result) |
| 1804 | { |
| 1805 | // only allow numeric types for binary operators |
| 1806 | if (!IsNumericType(type1.baseType) || type1.array || |
| 1807 | !IsNumericType(type2.baseType) || type2.array) { |
| 1808 | return false; |
| 1809 | } |
| 1810 | |
| 1811 | if (IsBitOp(binaryOp)) { |
| 1812 | if (!IsIntegerType(type1.baseType)) { |
| 1813 | return false; |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | if (IsLogicOp(binaryOp) || IsCompareOp(binaryOp)) { |
| 1818 | int numComponents = std::max(baseTypeDescriptions[type1.baseType].numComponents, baseTypeDescriptions[type2.baseType].numComponents); |
| 1819 | result.baseType = HLSLBaseType(HLSLBaseType_Bool + numComponents - 1); |
| 1820 | } |
| 1821 | else { |
| 1822 | // TODO: allso mulAssign, ... |
| 1823 | assert(!IsAssignOp(binaryOp)); |
| 1824 | |
| 1825 | result.baseType = ArithmeticOpResultType(binaryOp, type1.baseType, type2.baseType); |
| 1826 | } |
| 1827 | |
| 1828 | result.typeName = NULL; |
| 1829 | result.array = false; |
| 1830 | result.arraySize = NULL; |
| 1831 | result.flags = (type1.flags & type2.flags) & HLSLTypeFlag_Const; // Propagate constness. |
| 1832 | |
| 1833 | return result.baseType != HLSLBaseType_Unknown; |
| 1834 | } |
| 1835 | |
| 1836 | HLSLParser::HLSLParser(Allocator* allocator, const char* fileName, const char* buffer, size_t length) : m_tokenizer(fileName, buffer, length), |
| 1837 | m_userTypes(allocator), |
no test coverage detected