cypher_quries are moved to the tests folder and another part of CMakeLists file is written

This commit is contained in:
Marko Budiselic 2016-05-23 07:51:36 +02:00
parent 8aed81de38
commit 18838f5318
30 changed files with 89 additions and 13 deletions

View File

@ -8,7 +8,60 @@ string(REPLACE " " "_" ProjectId ${ProjectId})
# set project name
project(${ProjectId})
INCLUDE(ExternalProject)
# external dependencies
include(ExternalProject)
set(libs_dir "${CMAKE_SOURCE_DIR}/libs")
# lemon
set(lemon_dir "${libs_dir}/lemon")
set(lemon_tag "f38a55106d79b7a4c063abb958517d6c47dc6ac7")
set(lemon_url "http://www.sqlite.org/src/raw/tool/lemon.c?name=${lemon_tag}")
ExternalProject_Add(
lemon
DOWNLOAD_COMMAND wget ${lemon_url} -O lemon.c
DOWNLOAD_DIR ${lemon_dir}
SOURCE_DIR ${lemon_dir}
BINARY_DIR ${lemon_dir}
CONFIGURE_COMMAND ""
BUILD_COMMAND clang lemon.c -o lemon -O2
INSTALL_COMMAND ""
TEST_COMMAND ""
)
# lempar
set(lempar_dir "${libs_dir}/lemon")
set(lempar_tag "404ea3dc27dbeed343f0e61b1d36e97b9f5f0fb6")
set(lempar_url "http://www.sqlite.org/src/raw/tool/lempar.c?name=${lempar_tag}")
ExternalProject_Add(
lempar
DOWNLOAD_COMMAND wget ${lempar_url} -O lempar.c
DOWNLOAD_DIR ${lempar_dir}
SOURCE_DIR ${lempar_dir}
BINARY_DIR ${lempar_dir}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
# build memgraph's cypher grammer
FILE(COPY ${CMAKE_SOURCE_DIR}/src/cypher/cypher.y DESTINATION ${CMAKE_BINARY_DIR})
EXECUTE_PROCESS(
COMMAND ${lemon_dir}/lemon ${CMAKE_BINARY_DIR}/cypher.y -s
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
FILE(RENAME ${CMAKE_BINARY_DIR}/cypher.c ${CMAKE_BINARY_DIR}/cypher.cpp)
# lexertl
ExternalProject_Add(
lexertl
GIT_REPOSITORY "https://github.com/BenHanson/lexertl.git"
GIT_TAG "7d4d36a357027df0e817453cc9cf948f71047ca9"
SOURCE_DIR "${libs_dir}/lexertl"
TEST_COMMAND ""
INSTALL_COMMAND ""
)
# compiler options
SET(COMPILE_OPTIONS "-O0 -g3 -Wall -Werror -fmessage-length=0")

View File

@ -28,9 +28,13 @@ foreach(test_file ${test_files})
endforeach()
MESSAGE(STATUS "Available tests are: ${tests}")
# copy test data
file(COPY ${CMAKE_SOURCE_DIR}/tests/data DESTINATION ${CMAKE_BINARY_DIR}/tests)
# build tests
foreach(test ${tests})
add_executable(${test} ${test}.cpp)
target_link_libraries(${test} stdc++fs)
add_test(NAME ${test} COMMAND ${test})
set_property(TARGET ${test} PROPERTY CXX_STANDARD 14)
endforeach()

View File

@ -4,27 +4,46 @@
#include "cypher/compiler.hpp"
#include "cypher/debug/tree_print.hpp"
#include <fstream>
#include <iostream>
#include <iterator>
#include <iterator>
#include <vector>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
using std::cout;
using std::endl;
int calc(int i)
std::vector<std::string> load_queries()
{
return i + 1;
std::vector<std::string> queries;
fs::path queries_path = "data/cypher_queries";
for (auto& directory_entry :
fs::recursive_directory_iterator(queries_path)) {
if (!fs::is_regular_file(directory_entry))
continue;
std::ifstream infile(directory_entry.path().c_str());
if (infile) {
std::string file_text((std::istreambuf_iterator<char>(infile)),
std::istreambuf_iterator<char>());
queries.emplace_back(file_text);
}
}
return queries;
}
int main()
{
// TODO
// auto print_visitor = new PrintVisitor(cout);
auto queries = load_queries();
// // create AST
// cypher::Compiler compiler;
// auto tree = compiler.syntax_tree("MATCH (n) DELETE n");
// // traverser the tree
// tree.root->accept(*print_visitor);
//
assert(calc(0) == 1);
for (auto& query : queries) {
auto print_visitor = new PrintVisitor(cout);
cypher::Compiler compiler;
auto tree = compiler.syntax_tree(query);
tree.root->accept(*print_visitor);
}
return 0;
}