diff --git a/cypher/ast/tree.hpp b/cypher/ast/tree.hpp index 0f7f93034..9b8b7ca2a 100644 --- a/cypher/ast/tree.hpp +++ b/cypher/ast/tree.hpp @@ -21,6 +21,18 @@ public: this->items = std::move(other.items); } + Ast& operator=(Ast&& other) + { + // TODO: write this more appropriate + // here is CP of above code + if(this != &other) { + this->root = other.root; + other.root = nullptr; + this->items = std::move(other.items); + } + return *this; + } + AstVisitable* root; void traverse(AstVisitor& visitor) diff --git a/cypher/codegen/cppgen.hpp b/cypher/codegen/cppgen.hpp index cf02170d7..395e88c22 100644 --- a/cypher/codegen/cppgen.hpp +++ b/cypher/codegen/cppgen.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "cypher/visitor/traverser.hpp" diff --git a/query_engine/compile.sh b/query_engine/compile.sh new file mode 100755 index 000000000..2451f942a --- /dev/null +++ b/query_engine/compile.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# TODO: create Makefile or cmake script +clang++ -std=c++1y -I../ main.cpp ../cypher/cypher.cpp -o engine diff --git a/query_engine/engine b/query_engine/engine index 59d50c162..e2ccb1702 100755 Binary files a/query_engine/engine and b/query_engine/engine differ diff --git a/query_engine/query_engine.hpp b/query_engine/query_engine.hpp index 2c0ef9cc3..786e05187 100644 --- a/query_engine/query_engine.hpp +++ b/query_engine/query_engine.hpp @@ -21,11 +21,13 @@ class QueryEngine public: QueryResult execute(const std::string& query) { - cout << "execute: " << query << endl; + traverser.build_tree(query); + traverser.traverse(); return QueryResult(); } private: + // TODO: use IoC or something similar QueryTraverser traverser; CodeGenerator generator; CodeCompiler compiler; diff --git a/query_engine/query_traverser.hpp b/query_engine/query_traverser.hpp index c5405fd35..1297cfb86 100644 --- a/query_engine/query_traverser.hpp +++ b/query_engine/query_traverser.hpp @@ -1,5 +1,26 @@ #pragma once +#include "cypher/codegen/cppgen.hpp" +#include "cypher/compiler.hpp" +#include "cypher/ast/ast.hpp" + class QueryTraverser { +public: + QueryTraverser() = default; + + void build_tree(const std::string& query) + { + tree = compiler.syntax_tree(query); + } + + void traverse() + { + tree.root->accept(traverser); + } + +private: + ast::Ast tree; + cypher::Compiler compiler; + CppGen traverser; };