diff --git a/include/lang/pattern_data.hpp b/include/lang/pattern_data.hpp index 281527cd0..01f1f6368 100644 --- a/include/lang/pattern_data.hpp +++ b/include/lang/pattern_data.hpp @@ -261,6 +261,10 @@ namespace hex::lang { return "Pointer"; } + [[nodiscard]] PatternData* getPointedAtPattern() { + return this->m_pointedAt; + } + private: PatternData *m_pointedAt; }; diff --git a/source/lang/evaluator.cpp b/source/lang/evaluator.cpp index e584ddbfb..184e34905 100644 --- a/source/lang/evaluator.cpp +++ b/source/lang/evaluator.cpp @@ -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(currPattern); structPattern != nullptr) currMembers = structPattern->getMembers(); else if (auto unionPattern = dynamic_cast(currPattern); unionPattern != nullptr) currMembers = unionPattern->getMembers(); + else if (auto pointerPattern = dynamic_cast(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(currPattern); pointerPattern != nullptr) + currPattern = pointerPattern->getPointedAtPattern(); + if (auto unsignedPattern = dynamic_cast(currPattern); unsignedPattern != nullptr) { u8 value[unsignedPattern->getSize()]; this->m_provider->read(unsignedPattern->getOffset(), value, unsignedPattern->getSize());