memgraph/query_engine/code_generator.hpp

38 lines
1.0 KiB
C++
Raw Normal View History

#pragma once
#include "utils/string/file.hpp"
#include "template_engine/engine.hpp"
#include "config/config.hpp"
2016-02-11 06:34:49 +08:00
#include "traverser/query_traverser.hpp"
using std::string;
class CodeGenerator
{
public:
2016-02-11 06:34:49 +08:00
void generate_cpp(const std::string& query,
const uint64_t stripped_hash,
const std::string& path)
{
string template_path = CONFIG(config::TEMPLATE_CPU_CPP_PATH);
string template_file = utils::read_file(template_path.c_str());
traverser.build_tree(query);
string code = traverser.traverse();
string generated = template_engine.render(
template_file,
{
{"class_name", "CodeCPU"},
{"stripped_hash", std::to_string(stripped_hash)},
{"query", query},
{"code", code},
{"return_type", "int"}
}
);
utils::write_file(generated, path);
}
private:
template_engine::TemplateEngine template_engine;
2016-02-11 06:34:49 +08:00
QueryTraverser traverser;
};