diff --git a/query_engine/code_generator.hpp b/query_engine/code_generator.hpp index cc4448590..600c43cd0 100644 --- a/query_engine/code_generator.hpp +++ b/query_engine/code_generator.hpp @@ -12,7 +12,6 @@ using std::string; class CodeGenerator { public: - void generate_cpp(const std::string& query, const uint64_t stripped_hash, const std::string& path) @@ -33,8 +32,7 @@ public: {"class_name", "CodeCPU"}, {"stripped_hash", std::to_string(stripped_hash)}, {"query", query}, - {"code", code_traverser.code}, - {"return_type", "int"} + {"code", code_traverser.code} } ); utils::write_file(generated, path); diff --git a/query_engine/main.cpp b/query_engine/main.cpp index 2708ad900..82436c06c 100644 --- a/query_engine/main.cpp +++ b/query_engine/main.cpp @@ -1,5 +1,7 @@ #include +#define DEBUG 1 + #include "utils/command_line/arguments.hpp" #include "cypher/common.hpp" #include "query_engine.hpp" diff --git a/query_engine/program_executor.hpp b/query_engine/program_executor.hpp index 1085a4078..819389176 100644 --- a/query_engine/program_executor.hpp +++ b/query_engine/program_executor.hpp @@ -5,17 +5,12 @@ #include "query_program.hpp" #include "database/db.hpp" #include "utils/log/logger.hpp" +#include "query_engine/debug.hpp" // preparations before execution // execution // postprocess the results -#define DEBUG 1 -#include "query_engine/debug.hpp" - -using std::cout; -using std::endl; - class ProgramExecutor { public: @@ -23,7 +18,7 @@ public: auto execute(QueryProgram& program) { auto result = program.code->run(db, program.stripped.arguments); - print_props(*result->data["n"]->data[0]); + PRINT_PROPS(*result->data["n"]->data[0]); return result; } diff --git a/query_engine/traverser/code.hpp b/query_engine/traverser/code.hpp new file mode 100644 index 000000000..de9c7040b --- /dev/null +++ b/query_engine/traverser/code.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +struct Code +{ + void reset() + { + code = ""; + } + + std::string code; +}; + diff --git a/query_engine/traverser/code_traverser.hpp b/query_engine/traverser/code_traverser.hpp index b6fa175ac..223aa95ae 100644 --- a/query_engine/traverser/code_traverser.hpp +++ b/query_engine/traverser/code_traverser.hpp @@ -4,20 +4,15 @@ #include "cypher/visitor/traverser.hpp" #include "cypher/ast/queries.hpp" +#include "code.hpp" #include "write_traverser.hpp" #include "read_traverser.hpp" +#include "update_traverser.hpp" +#include "delete_traverser.hpp" -class CodeTraverser : public Traverser +class CodeTraverser : public Traverser, public Code { public: - - std::string code; - - void reset() - { - code = ""; - } - void visit(ast::WriteQuery& write_query) override { auto write_traverser = WriteTraverser(); @@ -31,4 +26,18 @@ public: read_query.accept(read_traverser); code = read_traverser.code; } + + void visit(ast::UpdateQuery& update_query) override + { + auto update_traverser = UpdateTraverser(); + update_query.accept(update_traverser); + code = update_traverser.code; + } + + void visit(ast::DeleteQuery& delete_query) override + { + auto delete_traverser = DeleteTraverser(); + delete_query.accept(delete_traverser); + code = delete_traverser.code; + } }; diff --git a/query_engine/traverser/delete_traverser.hpp b/query_engine/traverser/delete_traverser.hpp new file mode 100644 index 000000000..b25872cd2 --- /dev/null +++ b/query_engine/traverser/delete_traverser.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include "code.hpp" +#include "cypher/visitor/traverser.hpp" + +class DeleteTraverser : public Traverser, public Code +{ +}; diff --git a/query_engine/traverser/read_traverser.hpp b/query_engine/traverser/read_traverser.hpp index ad42bf146..594cb5ad2 100644 --- a/query_engine/traverser/read_traverser.hpp +++ b/query_engine/traverser/read_traverser.hpp @@ -1,9 +1,8 @@ #pragma once +#include "code.hpp" #include "cypher/visitor/traverser.hpp" -class ReadTraverser : public Traverser +class ReadTraverser : public Traverser, public Code { -public: - std::string code; }; diff --git a/query_engine/traverser/update_traverser.hpp b/query_engine/traverser/update_traverser.hpp index 914076bdf..5e1a5b681 100644 --- a/query_engine/traverser/update_traverser.hpp +++ b/query_engine/traverser/update_traverser.hpp @@ -1,7 +1,8 @@ #pragma once +#include "code.hpp" #include "cypher/visitor/traverser.hpp" -class UpdateTraverser : public Traverser +class UpdateTraverser : public Traverser, public Code { };