patterns: Properly treat arrays and custom types as references
This commit is contained in:
parent
7d9c24ff51
commit
ef8e9a83bb
@ -23,6 +23,8 @@ namespace hex::pl {
|
|||||||
auto pattern = type == nullptr ? nullptr : type->createPatterns(this).front();
|
auto pattern = type == nullptr ? nullptr : type->createPatterns(this).front();
|
||||||
this->dataOffset() = startOffset;
|
this->dataOffset() = startOffset;
|
||||||
|
|
||||||
|
bool referenceType = false;
|
||||||
|
|
||||||
if (pattern == nullptr) {
|
if (pattern == nullptr) {
|
||||||
// Handle auto variables
|
// Handle auto variables
|
||||||
if (!value.has_value())
|
if (!value.has_value())
|
||||||
@ -38,19 +40,23 @@ namespace hex::pl {
|
|||||||
pattern = new PatternDataBoolean(this, 0);
|
pattern = new PatternDataBoolean(this, 0);
|
||||||
else if (std::get_if<char>(&value.value()) != nullptr)
|
else if (std::get_if<char>(&value.value()) != nullptr)
|
||||||
pattern = new PatternDataCharacter(this, 0);
|
pattern = new PatternDataCharacter(this, 0);
|
||||||
else if (std::get_if<PatternData *>(&value.value()) != nullptr)
|
|
||||||
pattern = std::get<PatternData *>(value.value())->clone();
|
|
||||||
else if (std::get_if<std::string>(&value.value()) != nullptr)
|
else if (std::get_if<std::string>(&value.value()) != nullptr)
|
||||||
pattern = new PatternDataString(this, 0, 1);
|
pattern = new PatternDataString(this, 0, 1);
|
||||||
else
|
else if (std::get_if<PatternData *>(&value.value()) != nullptr) {
|
||||||
|
pattern = std::get<PatternData *>(value.value())->clone();
|
||||||
|
referenceType = true;
|
||||||
|
} else
|
||||||
LogConsole::abortEvaluation("cannot determine type of auto variable", type);
|
LogConsole::abortEvaluation("cannot determine type of auto variable", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern->setVariableName(name);
|
pattern->setVariableName(name);
|
||||||
pattern->setLocal(true);
|
|
||||||
pattern->setOffset(this->getStack().size());
|
|
||||||
|
|
||||||
this->getStack().emplace_back();
|
if (!referenceType) {
|
||||||
|
pattern->setOffset(this->getStack().size());
|
||||||
|
pattern->setLocal(true);
|
||||||
|
this->getStack().emplace_back();
|
||||||
|
}
|
||||||
|
|
||||||
variables.push_back(pattern);
|
variables.push_back(pattern);
|
||||||
|
|
||||||
if (outVariable)
|
if (outVariable)
|
||||||
@ -86,6 +92,8 @@ namespace hex::pl {
|
|||||||
if (pattern == nullptr)
|
if (pattern == nullptr)
|
||||||
LogConsole::abortEvaluation(hex::format("no variable with name '{}' found", name));
|
LogConsole::abortEvaluation(hex::format("no variable with name '{}' found", name));
|
||||||
|
|
||||||
|
if (!pattern->isLocal()) return;
|
||||||
|
|
||||||
Token::Literal castedLiteral = std::visit(overloaded {
|
Token::Literal castedLiteral = std::visit(overloaded {
|
||||||
[&](double &value) -> Token::Literal {
|
[&](double &value) -> Token::Literal {
|
||||||
if (dynamic_cast<PatternDataUnsigned *>(pattern))
|
if (dynamic_cast<PatternDataUnsigned *>(pattern))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user