mirror of https://github.com/WerWolv/ImHex.git
patterns: Fixed accessing global scope items through the parent keyword
This commit is contained in:
parent
46ba46ce9d
commit
9b1c09818c
|
@ -1526,13 +1526,19 @@ namespace hex::pl {
|
||||||
|
|
||||||
if (name == "parent") {
|
if (name == "parent") {
|
||||||
scopeIndex--;
|
scopeIndex--;
|
||||||
|
|
||||||
|
if (-scopeIndex >= evaluator->getScopeCount())
|
||||||
|
LogConsole::abortEvaluation("cannot access parent of global scope", this);
|
||||||
|
|
||||||
searchScope = *evaluator->getScope(scopeIndex).scope;
|
searchScope = *evaluator->getScope(scopeIndex).scope;
|
||||||
auto currParent = evaluator->getScope(scopeIndex).parent;
|
auto currParent = evaluator->getScope(scopeIndex).parent;
|
||||||
|
|
||||||
if (currParent == nullptr)
|
if (currParent == nullptr) {
|
||||||
LogConsole::abortEvaluation("no parent available", this);
|
currPattern = nullptr;
|
||||||
|
} else {
|
||||||
|
currPattern = currParent->clone();
|
||||||
|
}
|
||||||
|
|
||||||
currPattern = currParent->clone();
|
|
||||||
continue;
|
continue;
|
||||||
} else if (name == "this") {
|
} else if (name == "this") {
|
||||||
searchScope = *evaluator->getScope(scopeIndex).scope;
|
searchScope = *evaluator->getScope(scopeIndex).scope;
|
||||||
|
@ -1592,6 +1598,9 @@ namespace hex::pl {
|
||||||
}, index->getValue());
|
}, index->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currPattern == nullptr)
|
||||||
|
break;
|
||||||
|
|
||||||
if (auto pointerPattern = dynamic_cast<PatternDataPointer*>(currPattern)) {
|
if (auto pointerPattern = dynamic_cast<PatternDataPointer*>(currPattern)) {
|
||||||
auto newPattern = pointerPattern->getPointedAtPattern()->clone();
|
auto newPattern = pointerPattern->getPointedAtPattern()->clone();
|
||||||
delete currPattern;
|
delete currPattern;
|
||||||
|
@ -1611,6 +1620,9 @@ namespace hex::pl {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currPattern == nullptr)
|
||||||
|
LogConsole::abortEvaluation("cannot reference global scope", this);
|
||||||
|
|
||||||
return { currPattern };
|
return { currPattern };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,6 @@ namespace hex::pl {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Scope& getScope(s32 index) {
|
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];
|
return this->m_scopes[this->m_scopes.size() - 1 + index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +52,10 @@ namespace hex::pl {
|
||||||
return this->m_scopes.front();
|
return this->m_scopes.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t getScopeCount() {
|
||||||
|
return this->m_scopes.size();
|
||||||
|
}
|
||||||
|
|
||||||
bool isGlobalScope() {
|
bool isGlobalScope() {
|
||||||
return this->m_scopes.size() == 1;
|
return this->m_scopes.size() == 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue