1
0
mirror of synced 2025-01-18 09:04:52 +01:00

Allow accessing of pointer values in mathematical expressions

This commit is contained in:
WerWolv 2021-01-08 20:12:16 +01:00
parent 80e0782fdb
commit 17ecdbf8ec
2 changed files with 15 additions and 1 deletions

View File

@ -261,6 +261,10 @@ namespace hex::lang {
return "Pointer";
}
[[nodiscard]] PatternData* getPointedAtPattern() {
return this->m_pointedAt;
}
private:
PatternData *m_pointedAt;
};

View File

@ -57,11 +57,18 @@ namespace hex::lang {
std::copy(this->m_globalMembers.begin(), this->m_globalMembers.end(), std::back_inserter(currMembers));
PatternData *currPattern = nullptr;
for (const auto &identifier : node->getPath()) {
for (u32 i = 0; i < node->getPath().size(); i++) {
const auto &identifier = node->getPath()[i];
if (auto structPattern = dynamic_cast<PatternDataStruct*>(currPattern); structPattern != nullptr)
currMembers = structPattern->getMembers();
else if (auto unionPattern = dynamic_cast<PatternDataUnion*>(currPattern); unionPattern != nullptr)
currMembers = unionPattern->getMembers();
else if (auto pointerPattern = dynamic_cast<PatternDataPointer*>(currPattern); pointerPattern != nullptr) {
currPattern = pointerPattern->getPointedAtPattern();
i--;
continue;
}
else if (currPattern != nullptr)
throwEvaluateError("tried to access member of a non-struct/union type", node->getLineNumber());
@ -75,6 +82,9 @@ namespace hex::lang {
throwEvaluateError(hex::format("could not find identifier '%s'", identifier.c_str()), node->getLineNumber());
}
if (auto pointerPattern = dynamic_cast<PatternDataPointer*>(currPattern); pointerPattern != nullptr)
currPattern = pointerPattern->getPointedAtPattern();
if (auto unsignedPattern = dynamic_cast<PatternDataUnsigned*>(currPattern); unsignedPattern != nullptr) {
u8 value[unsignedPattern->getSize()];
this->m_provider->read(unsignedPattern->getOffset(), value, unsignedPattern->getSize());