cypher compiler and Ast are now wrapped inside the query engine

This commit is contained in:
Marko Budiselic 2016-01-28 00:29:38 +01:00
parent e2bbcae3ac
commit 0cf55d36c6
6 changed files with 41 additions and 1 deletions

View File

@ -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)

View File

@ -2,6 +2,7 @@
#include <iostream>
#include <typeinfo>
#include <map>
#include "cypher/visitor/traverser.hpp"

4
query_engine/compile.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
# TODO: create Makefile or cmake script
clang++ -std=c++1y -I../ main.cpp ../cypher/cypher.cpp -o engine

Binary file not shown.

View File

@ -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;

View File

@ -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;
};