patterns: Fixed accessing global scope items through the parent keyword

This commit is contained in:
WerWolv 2021-10-17 21:49:33 +02:00
parent 46ba46ce9d
commit 9b1c09818c
2 changed files with 19 additions and 6 deletions

View File

@ -1526,13 +1526,19 @@ namespace hex::pl {
if (name == "parent") {
scopeIndex--;
if (-scopeIndex >= evaluator->getScopeCount())
LogConsole::abortEvaluation("cannot access parent of global scope", this);
searchScope = *evaluator->getScope(scopeIndex).scope;
auto currParent = evaluator->getScope(scopeIndex).parent;
if (currParent == nullptr)
LogConsole::abortEvaluation("no parent available", this);
if (currParent == nullptr) {
currPattern = nullptr;
} else {
currPattern = currParent->clone();
}
currPattern = currParent->clone();
continue;
} else if (name == "this") {
searchScope = *evaluator->getScope(scopeIndex).scope;
@ -1592,6 +1598,9 @@ namespace hex::pl {
}, index->getValue());
}
if (currPattern == nullptr)
break;
if (auto pointerPattern = dynamic_cast<PatternDataPointer*>(currPattern)) {
auto newPattern = pointerPattern->getPointedAtPattern()->clone();
delete currPattern;
@ -1611,6 +1620,9 @@ namespace hex::pl {
}
if (currPattern == nullptr)
LogConsole::abortEvaluation("cannot reference global scope", this);
return { currPattern };
}

View File

@ -45,9 +45,6 @@ namespace hex::pl {
}
const Scope& getScope(s32 index) {
static Scope empty;
if (index > 0 || -index >= this->m_scopes.size()) return empty;
return this->m_scopes[this->m_scopes.size() - 1 + index];
}
@ -55,6 +52,10 @@ namespace hex::pl {
return this->m_scopes.front();
}
size_t getScopeCount() {
return this->m_scopes.size();
}
bool isGlobalScope() {
return this->m_scopes.size() == 1;
}