| 127 | } |
| 128 | |
| 129 | static void setTokenValueCast(Token *parent, const ValueType &valueType, Value value, const Settings &settings) |
| 130 | { |
| 131 | if (valueType.pointer || value.isImpossible()) |
| 132 | setTokenValue(parent,std::move(value),settings); |
| 133 | else if (valueType.type == ValueType::Type::CHAR) |
| 134 | setTokenValue(parent, castValue(std::move(value), valueType.sign, settings.platform.char_bit), settings); |
| 135 | else if (valueType.type == ValueType::Type::SHORT) |
| 136 | setTokenValue(parent, castValue(std::move(value), valueType.sign, settings.platform.short_bit), settings); |
| 137 | else if (valueType.type == ValueType::Type::INT) |
| 138 | setTokenValue(parent, castValue(std::move(value), valueType.sign, settings.platform.int_bit), settings); |
| 139 | else if (valueType.type == ValueType::Type::LONG) |
| 140 | setTokenValue(parent, castValue(std::move(value), valueType.sign, settings.platform.long_bit), settings); |
| 141 | else if (valueType.type == ValueType::Type::LONGLONG) |
| 142 | setTokenValue(parent, castValue(std::move(value), valueType.sign, settings.platform.long_long_bit), settings); |
| 143 | else if (valueType.isFloat() && isNumeric(value)) { |
| 144 | if (value.isIntValue()) |
| 145 | value.floatValue = static_cast<double>(value.intvalue); |
| 146 | value.valueType = Value::ValueType::FLOAT; |
| 147 | setTokenValue(parent, std::move(value), settings); |
| 148 | } else if (value.isIntValue()) { |
| 149 | const long long charMax = settings.platform.signedCharMax(); |
| 150 | const long long charMin = settings.platform.signedCharMin(); |
| 151 | if (charMin <= value.intvalue && value.intvalue <= charMax) { |
| 152 | // unknown type, but value is small so there should be no truncation etc |
| 153 | setTokenValue(parent,std::move(value),settings); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // does the operation cause a loss of information? |
| 159 | static bool isNonInvertibleOperation(const Token* tok) |
no test coverage detected