sys: Get rid of SharedData struct and cleanup code structure (#411)

* sys: Initial refactoring of the SharedData class

* sys/pattern: More refactoring, make every provider have its own patterns

* sys: Finished up refactoring. No more SharedData!

* sys: Fixed compile on Unix

* tests: Fixed unit tests

* sys: Moved view and lang files

* pattern: Added assignment operator support to for loops

* tests: Fixed compile issue
This commit is contained in:
WerWolv
2022-02-01 18:09:40 +01:00
committed by GitHub
parent 61fc479c79
commit 1991afb87b
110 changed files with 1592 additions and 1259 deletions

View File

@@ -123,7 +123,10 @@ namespace hex::pl {
return ast;
}
std::optional<std::vector<PatternData *>> PatternLanguage::executeString(prv::Provider *provider, const std::string &code, const std::map<std::string, Token::Literal> &envVars, const std::map<std::string, Token::Literal> &inVariables) {
bool PatternLanguage::executeString(prv::Provider *provider, const std::string &code, const std::map<std::string, Token::Literal> &envVars, const std::map<std::string, Token::Literal> &inVariables) {
this->m_running = true;
ON_SCOPE_EXIT { this->m_running = false; };
this->m_currError.reset();
this->m_evaluator->getConsole().clear();
this->m_evaluator->setProvider(provider);
@@ -143,20 +146,22 @@ namespace hex::pl {
auto ast = this->parseString(code);
if (!ast)
return std::nullopt;
return false;
this->m_currAST = ast.value();
auto patterns = this->m_evaluator->evaluate(ast.value());
if (!patterns.has_value()) {
this->m_currError = this->m_evaluator->getConsole().getLastHardError();
return std::nullopt;
return false;
}
return patterns;
this->m_patterns = std::move(patterns.value());
return true;
}
std::optional<std::vector<PatternData *>> PatternLanguage::executeFile(prv::Provider *provider, const fs::path &path, const std::map<std::string, Token::Literal> &envVars, const std::map<std::string, Token::Literal> &inVariables) {
bool PatternLanguage::executeFile(prv::Provider *provider, const fs::path &path, const std::map<std::string, Token::Literal> &envVars, const std::map<std::string, Token::Literal> &inVariables) {
File file(path, File::Mode::Read);
return this->executeString(provider, file.readString(), envVars, inVariables);
@@ -200,4 +205,12 @@ namespace hex::pl {
return this->m_evaluator->hasDangerousFunctionBeenCalled();
}
void PatternLanguage::reset() {
for (auto &pattern : this->m_patterns)
delete pattern;
this->m_patterns.clear();
this->m_currAST.clear();
}
}