memgraph/cypher/codegen/cppgen.hpp

54 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
2015-10-28 03:21:28 +08:00
2015-11-02 06:28:08 +08:00
#include <iostream>
#include <typeinfo>
2015-10-28 03:21:28 +08:00
#include "cypher/visitor/traverser.hpp"
2015-10-30 08:24:01 +08:00
using std::cout;
using std::endl;
2015-10-28 03:21:28 +08:00
class CppGen : public Traverser
{
struct CreateGen : public Traverser
{
void visit(ast::Pattern& pattern) override
{
2015-11-02 06:28:08 +08:00
Traverser::visit(pattern);
}
void visit(ast::Property& property) override
{
name = property.idn->name;
Traverser::visit(property);
json[name] = value;
2015-10-30 08:24:01 +08:00
}
2015-11-02 06:28:08 +08:00
void visit(ast::String& string) override
2015-10-30 08:24:01 +08:00
{
2015-11-02 06:28:08 +08:00
value = string.value;
}
2015-10-30 08:24:01 +08:00
2015-11-02 06:28:08 +08:00
void visit(ast::Node& node) override
{
cout << "Node: " << node.idn->name << endl;
2015-10-30 08:24:01 +08:00
Traverser::visit(node);
2015-11-02 06:28:08 +08:00
for (auto& kv : json) {
cout << "Key: " << kv.first << ", Value: " << kv.second << endl;
}
2015-10-28 03:21:28 +08:00
}
2015-11-02 06:28:08 +08:00
private:
std::string name;
std::string value;
std::map<std::string, std::string> json;
2015-10-28 03:21:28 +08:00
};
public:
2015-10-30 08:24:01 +08:00
void visit(ast::Create& create) override
2015-10-28 03:21:28 +08:00
{
2015-10-29 05:55:57 +08:00
auto create_gen = CreateGen();
create.accept(create_gen);
2015-10-28 03:21:28 +08:00
};
};