clang format was applied on src/memgraph and on some files at the src/query_engine folder

This commit is contained in:
Marko Budiselic 2016-06-06 11:29:52 +02:00
parent 4d03dcd545
commit 894ef67bc0
14 changed files with 117 additions and 140 deletions

View File

@ -6,18 +6,17 @@
#include "database/db.hpp"
#include "speedy/speedy.hpp"
#include "api/resources/include.hpp"
#include "speedy/speedy.hpp"
#include "threading/pool.hpp"
#include "threading/task.hpp"
#include "utils/terminate_handler.hpp"
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{
if(argc < 2)
{
if (argc < 2) {
std::cout << "Port not defined" << std::endl;
std::exit(0);
}

View File

@ -7,18 +7,17 @@
class CodeCompiler
{
public:
void compile(const std::string& in_file, const std::string& out_file)
void compile(const std::string &in_file, const std::string &out_file)
{
auto compile_command = utils::prints(
"clang++",
// "-std=c++1y -O2 -DNDEBUG", // compile flags
"-std=c++1y", // compile flags
in_file, // input file
"-o", out_file, // ouput file
"-I../", // include paths
"-shared -fPIC" // shared library flags
);
auto compile_command =
utils::prints("clang++",
// "-std=c++1y -O2 -DNDEBUG", // compile flags
"-std=c++1y", // compile flags
in_file, // input file
"-o", out_file, // ouput file
"-I../", // include paths
"-shared -fPIC" // shared library flags
);
// synchronous call
system(compile_command.c_str());

View File

@ -1,20 +1,19 @@
#pragma once
#include "config/config.hpp"
#include "cypher/ast/ast.hpp"
#include "cypher/compiler.hpp"
#include "utils/string/file.hpp"
#include "template_engine/engine.hpp"
#include "config/config.hpp"
#include "traverser/code_traverser.hpp"
#include "utils/string/file.hpp"
using std::string;
class CodeGenerator
{
public:
void generate_cpp(const std::string& query,
const uint64_t stripped_hash,
const std::string& path)
void generate_cpp(const std::string &query, const uint64_t stripped_hash,
const std::string &path)
{
// get paths
string template_path = CONFIG(config::TEMPLATE_CPU_CPP_PATH);
@ -27,19 +26,15 @@ public:
// save the code
string generated = template_engine.render(
template_file,
{
{"class_name", "CodeCPU"},
{"stripped_hash", std::to_string(stripped_hash)},
{"query", query},
{"code", code_traverser.code}
}
);
template_file, {{"class_name", "CodeCPU"},
{"stripped_hash", std::to_string(stripped_hash)},
{"query", query},
{"code", code_traverser.code}});
utils::write_file(generated, path);
}
private:
template_engine::TemplateEngine template_engine;
template_engine::TemplateEngine template_engine;
ast::Ast tree;
cypher::Compiler compiler;
CodeTraverser code_traverser;

View File

@ -2,14 +2,14 @@
#include <iostream>
#include "storage/model/properties/traversers/jsonwriter.hpp"
#include "storage/model/properties/properties.hpp"
#include "storage/model/properties/traversers/jsonwriter.hpp"
using std::cout;
using std::endl;
void print_props(const Properties& properties)
{
void print_props(const Properties &properties)
{
StringBuffer buffer;
JsonWriter<StringBuffer> writer(buffer);
properties.accept(writer);
@ -17,7 +17,7 @@ void print_props(const Properties& properties)
}
#ifdef DEBUG
# define PRINT_PROPS(_PROPS_) print_props(_PROPS_);
#define PRINT_PROPS(_PROPS_) print_props(_PROPS_);
#else
# define PRINT_PROPS(_)
#define PRINT_PROPS(_)
#endif

View File

@ -1,15 +1,15 @@
#pragma once
#include "database/db.hpp"
#include "query_engine/query_result.hpp"
#include "query_stripped.hpp"
#include "database/db.hpp"
class ICodeCPU
{
public:
virtual QueryResult::sptr run(Db& db, code_args_t& args) = 0;
virtual QueryResult::sptr run(Db &db, code_args_t &args) = 0;
virtual ~ICodeCPU() {}
};
using produce_t = ICodeCPU*(*)();
using destruct_t = void (*)(ICodeCPU*);
using produce_t = ICodeCPU *(*)();
using destruct_t = void (*)(ICodeCPU *);

View File

@ -2,10 +2,10 @@
#include <string>
#include "query_program.hpp"
#include "database/db.hpp"
#include "utils/log/logger.hpp"
#include "query_engine/debug.hpp"
#include "query_program.hpp"
#include "utils/log/logger.hpp"
// preparations before execution
// execution
@ -14,8 +14,7 @@
class ProgramExecutor
{
public:
auto execute(QueryProgram& program)
auto execute(QueryProgram &program)
{
auto result = program.code->run(db, program.stripped.arguments);
PRINT_PROPS(*result->data["n"]->data[0]);
@ -23,6 +22,5 @@ public:
}
public:
Db db;
};

View File

@ -1,34 +1,35 @@
#pragma once
#include <memory>
#include <string>
#include <unordered_map>
#include <memory>
#define NOT_LOG_INFO
#include "memgraph_dynamic_lib.hpp"
#include "query_stripper.hpp"
#include "code_compiler.hpp"
#include "code_generator.hpp"
#include "utils/hashing/fnv.hpp"
#include "config/config.hpp"
#include "utils/log/logger.hpp"
#include "memgraph_dynamic_lib.hpp"
#include "query_program.hpp"
#include "query_stripper.hpp"
#include "utils/hashing/fnv.hpp"
#include "utils/log/logger.hpp"
using std::string;
using std::cout;
using std::endl;
class ProgramLoader
{
{
public:
using sptr_code_lib = std::shared_ptr<CodeLib>;
ProgramLoader()
: stripper(make_query_stripper(TK_INT, TK_FLOAT, TK_STR, TK_BOOL)) {}
: stripper(make_query_stripper(TK_INT, TK_FLOAT, TK_STR, TK_BOOL))
{
}
auto load(const string& query)
auto load(const string &query)
{
auto stripped = stripper.strip(query);
LOG_INFO("stripped_query=" + stripped.query);
@ -51,8 +52,8 @@ public:
auto base_path = config::Config::instance()[config::COMPILE_CPU_PATH];
auto path_cpp = base_path + hash_string + ".cpp";
code_generator.generate_cpp(query, stripped_hash, path_cpp);
// TODO compile generated code
// TODO compile generated code
auto path_so = base_path + hash_string + ".so";
code_compiler.compile(path_cpp, path_so);
@ -65,7 +66,6 @@ public:
}
private:
// TODO somehow remove int.. from here
QueryStripper<int, int, int, int> stripper;
// TODO ifdef MEMGRAPH64 problem, how to use this kind
@ -76,7 +76,7 @@ private:
CodeGenerator code_generator;
CodeCompiler code_compiler;
sptr_code_lib load_code_lib(const string& path)
sptr_code_lib load_code_lib(const string &path)
{
sptr_code_lib code_lib = std::make_shared<CodeLib>(path);
code_lib->load();

View File

@ -1,7 +1,7 @@
#pragma once
#include "program_loader.hpp"
#include "program_executor.hpp"
#include "program_loader.hpp"
#include "query_result.hpp"
//
@ -12,8 +12,7 @@
class QueryEngine
{
public:
auto execute(const std::string& query)
auto execute(const std::string &query)
{
auto program = program_loader.load(query);
auto result = program_executor.execute(program);

View File

@ -5,12 +5,13 @@
struct QueryProgram
{
QueryProgram(ICodeCPU* code, QueryStripped&& stripped) :
code(code),
stripped(std::forward<QueryStripped>(stripped)) {}
QueryProgram(ICodeCPU *code, QueryStripped &&stripped)
: code(code), stripped(std::forward<QueryStripped>(stripped))
{
}
QueryProgram(QueryProgram& other) = delete;
QueryProgram(QueryProgram&& other) = default;
QueryProgram(QueryProgram &other) = delete;
QueryProgram(QueryProgram &&other) = default;
ICodeCPU *code;
QueryStripped stripped;

View File

@ -1,30 +1,25 @@
#pragma once
#include <string>
#include <vector>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "storage/model/properties/properties.hpp"
struct ResultList
{
using sptr = std::shared_ptr<ResultList>;
using data_t = std::vector<const Properties*>;
using data_t = std::vector<const Properties *>;
ResultList() = default;
ResultList(ResultList& other) = delete;
ResultList(ResultList&& other) = default;
ResultList(ResultList &other) = delete;
ResultList(ResultList &&other) = default;
ResultList(data_t &&data) : data(std::forward<data_t>(data)) {}
ResultList(data_t&& data) :
data(std::forward<data_t>(data)) {}
explicit operator bool() const { return data.size() > 0; }
explicit operator bool() const
{
return data.size() > 0;
}
std::vector<const Properties*> data;
std::vector<const Properties *> data;
};
struct QueryResult
@ -33,16 +28,11 @@ struct QueryResult
using data_t = std::unordered_map<std::string, ResultList::sptr>;
QueryResult() = default;
QueryResult(QueryResult& other) = delete;
QueryResult(QueryResult&& other) = default;
QueryResult(QueryResult &other) = delete;
QueryResult(QueryResult &&other) = default;
QueryResult(data_t &&data) : data(std::forward<data_t>(data)) {}
QueryResult(data_t&& data) :
data(std::forward<data_t>(data)) {}
explicit operator bool() const
{
return data.size() > 0;
}
explicit operator bool() const { return data.size() > 0; }
data_t data;
};

View File

@ -8,12 +8,14 @@ using code_args_t = std::vector<Property::sptr>;
struct QueryStripped
{
QueryStripped(const std::string&& query, code_args_t&& arguments) :
query(std::forward<const std::string>(query)),
arguments(std::forward<code_args_t>(arguments)) {}
QueryStripped(const std::string &&query, code_args_t &&arguments)
: query(std::forward<const std::string>(query)),
arguments(std::forward<code_args_t>(arguments))
{
}
QueryStripped(QueryStripped& other) = delete;
QueryStripped(QueryStripped&& other) = default;
QueryStripped(QueryStripped &other) = delete;
QueryStripped(QueryStripped &&other) = default;
std::string query;
code_args_t arguments;

View File

@ -2,40 +2,43 @@
#include <string>
#include <tuple>
#include <utility>
#include <unordered_map>
#include <utility>
#include "utils/string/transform.hpp"
#include "cypher/cypher.h"
#include "cypher/tokenizer/cypher_lexer.hpp"
#include "utils/variadic/variadic.hpp"
#include "storage/model/properties/all.hpp"
#include "query_stripped.hpp"
#include "storage/model/properties/all.hpp"
#include "utils/string/transform.hpp"
#include "utils/variadic/variadic.hpp"
#include <iostream>
template<class T, class V>
void store_query_param(code_args_t& arguments, V&& v)
template <class T, class V>
void store_query_param(code_args_t &arguments, V &&v)
{
arguments.emplace_back(std::make_shared<T>(std::forward<V>(v)));
}
template<typename ...Ts>
template <typename... Ts>
class QueryStripper
{
public:
QueryStripper(Ts &&... strip_types)
: strip_types(std::make_tuple(std::forward<Ts>(strip_types)...)),
lexer(std::make_unique<CypherLexer>())
{
}
QueryStripper(Ts&&... strip_types) :
strip_types(std::make_tuple(std::forward<Ts>(strip_types)...)),
lexer(std::make_unique<CypherLexer>()) {}
QueryStripper(QueryStripper &other) = delete;
QueryStripper(QueryStripper& other) = delete;
QueryStripper(QueryStripper &&other)
: strip_types(std::move(other.strip_types)),
lexer(std::move(other.lexer))
{
}
QueryStripper(QueryStripper&& other) :
strip_types(std::move(other.strip_types)),
lexer(std::move(other.lexer)) {}
auto strip(const std::string& query)
auto strip(const std::string &query)
{
// TODO write this more optimal (resplace string
// concatenation with something smarter)
@ -51,30 +54,27 @@ public:
std::string stripped_query;
stripped_query.reserve(query.size());
while (auto token = tokenizer.lookup())
{
while (auto token = tokenizer.lookup()) {
// TODO: better implementation
if (_or(token.id, strip_types, std::make_index_sequence<size>{})) {
auto index = counter++;
switch (token.id) {
case TK_INT:
store_query_param<Int32>(stripped_arguments,
std::stoi(token.value));
break;
case TK_STR:
store_query_param<String>(stripped_arguments,
token.value);
break;
case TK_BOOL: {
bool value = token.value[0] == 'T' ||
token.value[0] == 't';
store_query_param<Bool>(stripped_arguments, value);
break;
}
case TK_FLOAT:
store_query_param<Float>(stripped_arguments,
std::stof(token.value));
break;
case TK_INT:
store_query_param<Int32>(stripped_arguments,
std::stoi(token.value));
break;
case TK_STR:
store_query_param<String>(stripped_arguments, token.value);
break;
case TK_BOOL: {
bool value = token.value[0] == 'T' || token.value[0] == 't';
store_query_param<Bool>(stripped_arguments, value);
break;
}
case TK_FLOAT:
store_query_param<Float>(stripped_arguments,
std::stof(token.value));
break;
}
stripped_query += std::to_string(index);
} else {
@ -91,15 +91,16 @@ private:
std::tuple<Ts...> strip_types;
CypherLexer::uptr lexer;
template<typename Value, typename Tuple, std::size_t ...index>
bool _or(Value&& value, Tuple&& tuple, std::index_sequence<index...>)
template <typename Value, typename Tuple, std::size_t... index>
bool _or(Value &&value, Tuple &&tuple, std::index_sequence<index...>)
{
return or_vargs(std::forward<Value>(value),
std::get<index>(std::forward<Tuple>(tuple))...);
}
};
template<typename ...Ts>
decltype(auto) make_query_stripper(Ts&&... ts) {
template <typename... Ts>
decltype(auto) make_query_stripper(Ts &&... ts)
{
return QueryStripper<Ts...>(std::forward<Ts>(ts)...);
}

View File

@ -4,11 +4,7 @@
struct Code
{
void reset()
{
code = "";
}
void reset() { code = ""; }
std::string code;
};

View File

@ -2,7 +2,4 @@
#include <string>
std::string line(std::string line)
{
return "\t\t" + line + "\n";
}
std::string line(std::string line) { return "\t\t" + line + "\n"; }