Support for retrieving bound tree string from script objecsts
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
acc687f213
commit
da4258506e
|
@ -115,6 +115,15 @@ Porygon::Script::Script(shared_ptr<BoundScriptStatement> boundScript,
|
|||
_evaluator = new Evaluator(_scriptVariables, this -> GetScriptOptions());
|
||||
}
|
||||
|
||||
std::string Porygon::Script::GetTreeString() {
|
||||
if (_treeString.empty()){
|
||||
std::stringstream stream;
|
||||
_boundScript->GetTreeString(stream, 0);
|
||||
_treeString = stream.str();
|
||||
}
|
||||
return _treeString;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
Porygon::Script* CreateScript(char16_t * s, Porygon::ScriptOptions* options){
|
||||
return Porygon::Script::Create(s, options);
|
||||
|
@ -160,4 +169,16 @@ extern "C" {
|
|||
const char * GetResultError(Porygon::EvaluateResult * result){
|
||||
return result->GetError();
|
||||
}
|
||||
|
||||
const size_t GetTreeStringLength(Porygon::Script* script){
|
||||
return script->GetTreeString().size();
|
||||
}
|
||||
|
||||
void GetTreeString(Porygon::Script* script, char* buffer){
|
||||
auto s = script->GetTreeString();
|
||||
for (size_t i = 0; i < s.size(); i++){
|
||||
buffer[i] = s[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -23,6 +23,7 @@ namespace Porygon{
|
|||
shared_ptr<Binder::BoundScriptStatement> _boundScript;
|
||||
shared_ptr<const ScriptType> _returnType = nullptr;
|
||||
ScriptOptions* _scriptOptions;
|
||||
std::string _treeString;
|
||||
|
||||
explicit Script(const u16string&, ScriptOptions*);
|
||||
Script(shared_ptr<BoundScriptStatement> boundScript, shared_ptr<Diagnostics::DiagnosticsHolder> diagnostics);
|
||||
|
@ -65,6 +66,8 @@ namespace Porygon{
|
|||
const map<Utilities::HashedString, EvalValuePointer>* GetScriptVariables(){
|
||||
return _scriptVariables;
|
||||
}
|
||||
|
||||
std::string GetTreeString();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
#ifdef TESTS_BUILD
|
||||
#include <catch.hpp>
|
||||
#include "../src/Script.hpp"
|
||||
|
||||
using namespace Porygon;
|
||||
|
||||
TEST_CASE( "Basic script to bound tree string", "[integration]" ) {
|
||||
Script* script = Script::Create("return 10 + 500");
|
||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||
auto boundTreeString = script->GetTreeString();
|
||||
REQUIRE(boundTreeString == "BlockStatement\n"
|
||||
"\tReturnStatement\n"
|
||||
"\t\tBinaryExpression: addition (number)\n"
|
||||
"\t\t\tLiteralInteger: 10 (number)\n"
|
||||
"\t\t\tLiteralInteger: 500 (number)");
|
||||
delete script;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue