patterns: Allow casting integers to str

This commit is contained in:
WerWolv
2021-09-21 23:45:45 +02:00
parent 85b8698e35
commit d1c05174b6
3 changed files with 14 additions and 3 deletions

View File

@@ -445,6 +445,17 @@ namespace hex::pl {
return new ASTNodeLiteral(u128(char16_t(endianAdjustedValue)));
case Token::ValueType::Boolean:
return new ASTNodeLiteral(bool(endianAdjustedValue));
case Token::ValueType::String:
{
std::string string(sizeof(value), '\x00');
std::memcpy(string.data(), &value, string.size());
hex::trim(string);
if (typePattern->getEndian() != std::endian::native)
std::reverse(string.begin(), string.end());
return new ASTNodeLiteral(string);
}
default:
LogConsole::abortEvaluation(hex::format("cannot cast value to '{}'", Token::getTypeName(type)), this);
}