Added namespaces to most classes, general cleanup
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include "Parser/Parser.hpp"
|
||||
#include "Binder/Binder.hpp"
|
||||
|
||||
Script* Script::Create(const u16string& script) {
|
||||
Porygon::Script* Porygon::Script::Create(const u16string& script) {
|
||||
auto s = new Script();
|
||||
s -> Parse(script);
|
||||
return s;
|
||||
@@ -20,22 +20,22 @@ std::u16string To_UTF16(const string &s)
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
|
||||
return conv.from_bytes(s);
|
||||
}
|
||||
Script *Script::Create(const string &script) {
|
||||
Porygon::Script *Porygon::Script::Create(const string &script) {
|
||||
return Script::Create(To_UTF16(script));
|
||||
}
|
||||
|
||||
Script::Script() {
|
||||
Porygon::Script::Script() {
|
||||
Diagnostics = new DiagnosticsHolder();
|
||||
_evaluator = new Evaluator(this);
|
||||
_boundScript = nullptr;
|
||||
_scriptVariables = new unordered_map<uint32_t, shared_ptr<EvalValue>>(0);
|
||||
_evaluator = new Evaluator(this -> _scriptVariables);
|
||||
}
|
||||
|
||||
EvalValue* Script::Evaluate() {
|
||||
EvalValue* Porygon::Script::Evaluate() {
|
||||
return _evaluator->Evaluate(_boundScript);
|
||||
}
|
||||
|
||||
Script::~Script() {
|
||||
Porygon::Script::~Script() {
|
||||
delete this -> Diagnostics;
|
||||
delete this -> _boundScript;
|
||||
delete this -> _evaluator;
|
||||
@@ -43,10 +43,10 @@ Script::~Script() {
|
||||
delete this->_scriptVariables;
|
||||
}
|
||||
|
||||
void Script::Parse(const u16string& script) {
|
||||
void Porygon::Script::Parse(const u16string& script) {
|
||||
auto lexer = Lexer(script, this);
|
||||
auto lexResult = lexer.Lex();
|
||||
auto parser = Parser(lexResult, this);
|
||||
auto parser = Parser::Parser(lexResult, this);
|
||||
auto parseResult = parser.Parse();
|
||||
for (auto token : lexResult){
|
||||
delete token;
|
||||
@@ -55,7 +55,7 @@ void Script::Parse(const u16string& script) {
|
||||
if (!Diagnostics->HasErrors()){
|
||||
unordered_map<uint32_t, BoundVariable*> scriptScope;
|
||||
auto bindScope = new BoundScope(&scriptScope);
|
||||
this->_boundScript = Binder::Bind(this, parseResult, bindScope);
|
||||
this->_boundScript = Binder::Binder::Bind(this, parseResult, bindScope);
|
||||
for (const auto& v : scriptScope){
|
||||
this->_scriptVariables -> insert({v.first, nullptr});
|
||||
delete v.second;
|
||||
@@ -65,59 +65,57 @@ void Script::Parse(const u16string& script) {
|
||||
delete parseResult;
|
||||
}
|
||||
|
||||
EvalValue *Script::GetVariable(const u16string &key) {
|
||||
EvalValue *Porygon::Script::GetVariable(const u16string &key) {
|
||||
return _scriptVariables -> at(HashedString(key).GetHash()).get();
|
||||
}
|
||||
|
||||
bool Script::HasVariable(const u16string &key) {
|
||||
bool Porygon::Script::HasVariable(const u16string &key) {
|
||||
auto f = _scriptVariables->find(HashedString(key).GetHash());
|
||||
return f != _scriptVariables->end();
|
||||
}
|
||||
|
||||
EvalValue *Script::GetLastValue() {
|
||||
EvalValue *Porygon::Script::GetLastValue() {
|
||||
return _evaluator->GetLastValue();
|
||||
}
|
||||
|
||||
bool Script::HasFunction(const u16string &key) {
|
||||
bool Porygon::Script::HasFunction(const u16string &key) {
|
||||
auto f = _scriptVariables->find(HashedString(key).GetHash());
|
||||
return f != _scriptVariables->end() && f.operator->()->second->GetTypeClass() == TypeClass ::Function;
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Script::CallFunction(const u16string &key, const vector<EvalValue *>& variables) {
|
||||
shared_ptr<EvalValue> Porygon::Script::CallFunction(const u16string &key, const vector<EvalValue *>& variables) {
|
||||
auto var = (ScriptFunctionEvalValue*)GetVariable(key);
|
||||
return this->_evaluator->EvaluateFunction(var, variables);
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
Script* CreateScript(char16_t * s){
|
||||
return Script::Create(s);
|
||||
Porygon::Script* CreateScript(char16_t * s){
|
||||
return Porygon::Script::Create(s);
|
||||
}
|
||||
|
||||
void EvaluateScript(Script* script){
|
||||
void EvaluateScript(Porygon::Script* script){
|
||||
script->Evaluate();
|
||||
}
|
||||
|
||||
EvalValue* GetLastValue(Script* script){
|
||||
EvalValue* GetLastValue(Porygon::Script* script){
|
||||
return script->GetLastValue();
|
||||
}
|
||||
|
||||
bool HasVariable(Script* script, const char16_t* key){
|
||||
bool HasVariable(Porygon::Script* script, const char16_t* key){
|
||||
return script->HasVariable(key);
|
||||
}
|
||||
|
||||
EvalValue* GetVariable(Script* script, const char16_t* key){
|
||||
EvalValue* GetVariable(Porygon::Script* script, const char16_t* key){
|
||||
return script->GetVariable(key);
|
||||
}
|
||||
|
||||
bool HasFunction(Script* script, const char16_t* key){
|
||||
bool HasFunction(Porygon::Script* script, const char16_t* key){
|
||||
return script->HasFunction(key);
|
||||
}
|
||||
|
||||
EvalValue* CallFunction(Script* script, const char16_t* key, EvalValue* parameters[], int parameterCount){
|
||||
EvalValue* CallFunction(Porygon::Script* script, const char16_t* key, EvalValue* parameters[], int parameterCount){
|
||||
std::vector<EvalValue*> v(parameters, parameters + parameterCount);
|
||||
return script->CallFunction(key, v).get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user