Extract AST serialization to a new file
Reviewers: mtomic, mferencevic Reviewed By: mtomic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1631
This commit is contained in:
parent
db52b35ab6
commit
96537eb181
3
.gitignore
vendored
3
.gitignore
vendored
@ -66,8 +66,9 @@ src/distributed/token_sharing_rpc_messages.capnp
|
||||
src/distributed/token_sharing_rpc_messages.hpp
|
||||
src/distributed/updates_rpc_messages.capnp
|
||||
src/distributed/updates_rpc_messages.hpp
|
||||
src/query/frontend/ast/ast.capnp
|
||||
src/query/frontend/ast/ast.hpp
|
||||
src/query/frontend/ast/ast_serialization.capnp
|
||||
src/query/frontend/ast/ast_serialization.hpp
|
||||
src/query/plan/distributed_ops.capnp
|
||||
src/query/plan/distributed_ops.hpp
|
||||
src/query/plan/operator.hpp
|
||||
|
@ -117,8 +117,10 @@ add_capnp(distributed/dynamic_worker_rpc_messages.capnp)
|
||||
|
||||
# distributed_ops.lcp is leading the capnp code generation, so we don't need
|
||||
# to generate any capnp for operator.lcp
|
||||
add_lcp(query/frontend/ast/ast.lcp CAPNP_SCHEMA @0xb107d3d6b4b1600b)
|
||||
add_capnp(query/frontend/ast/ast.capnp)
|
||||
add_lcp(query/frontend/ast/ast.lcp)
|
||||
add_lcp(query/frontend/ast/ast_serialization.lcp CAPNP_SCHEMA @0xb107d3d6b4b1600b
|
||||
DEPENDS query/frontend/ast/ast.lcp)
|
||||
add_capnp(query/frontend/ast/ast_serialization.capnp)
|
||||
add_lcp(query/plan/operator.lcp)
|
||||
add_lcp(query/plan/distributed_ops.lcp CAPNP_SCHEMA @0xe5cae8d045d30c42
|
||||
DEPENDS query/plan/operator.lcp)
|
||||
|
@ -18,7 +18,7 @@ cpp<#
|
||||
|
||||
(lcp:capnp-namespace "distributed")
|
||||
|
||||
(lcp:capnp-import 'ast "/query/frontend/ast/ast.capnp")
|
||||
(lcp:capnp-import 'ast "/query/frontend/ast/ast_serialization.capnp")
|
||||
(lcp:capnp-import 'dist-ops "/query/plan/distributed_ops.capnp")
|
||||
(lcp:capnp-import 'query "/query/serialization.capnp")
|
||||
(lcp:capnp-import 'storage "/storage/serialization.capnp")
|
||||
|
@ -2,9 +2,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "storage/serialization.hpp"
|
||||
#include "utils/serialization.capnp.h"
|
||||
|
||||
namespace query {
|
||||
|
||||
AstStorage::AstStorage() {
|
||||
@ -33,15 +30,4 @@ ReturnBody CloneReturnBody(AstStorage &storage, const ReturnBody &body) {
|
||||
return new_body;
|
||||
}
|
||||
|
||||
// Capnproto serialization.
|
||||
Tree *AstStorage::Load(const capnp::Tree::Reader &tree,
|
||||
std::vector<int> *loaded_uids) {
|
||||
storage_.clear();
|
||||
std::unique_ptr<Tree> root;
|
||||
::query::Load(&root, tree, this, loaded_uids);
|
||||
root_idx_ = storage_.size();
|
||||
storage_.emplace_back(std::move(root));
|
||||
return storage_[root_idx_].get();
|
||||
}
|
||||
|
||||
} // namespace query
|
||||
|
@ -11,9 +11,6 @@
|
||||
#include "query/typed_value.hpp"
|
||||
#include "storage/property_value.hpp"
|
||||
#include "storage/types.hpp"
|
||||
#include "utils/serialization.hpp"
|
||||
|
||||
#include "ast.capnp.h"
|
||||
|
||||
// Hash function for the key in pattern atom property maps.
|
||||
namespace std {
|
||||
@ -35,10 +32,6 @@ class GraphDbAccessor;
|
||||
}
|
||||
|
||||
cpp<#
|
||||
(lcp:in-impl
|
||||
#>cpp
|
||||
#include "storage/serialization.hpp"
|
||||
cpp<#)
|
||||
|
||||
(lcp:namespace query)
|
||||
(lcp:capnp-namespace "query")
|
||||
@ -168,12 +161,10 @@ class AstStorage {
|
||||
|
||||
Query *query() const;
|
||||
|
||||
Tree *Load(const capnp::Tree::Reader &tree, std::vector<int> *loaded_uids);
|
||||
|
||||
private:
|
||||
// Public only for serialization access
|
||||
std::vector<std::unique_ptr<Tree>> storage_;
|
||||
int next_uid_ = 0;
|
||||
size_t root_idx_;
|
||||
std::vector<std::unique_ptr<Tree>> storage_;
|
||||
};
|
||||
cpp<#
|
||||
|
||||
@ -2504,4 +2495,4 @@ cpp<#
|
||||
#undef CLONE_UNARY_EXPRESSION
|
||||
cpp<#
|
||||
|
||||
(lcp:pop-namespace) ; namespace query
|
||||
(lcp:pop-namespace) ;; namespace query
|
||||
|
31
src/query/frontend/ast/ast_serialization.lcp
Normal file
31
src/query/frontend/ast/ast_serialization.lcp
Normal file
@ -0,0 +1,31 @@
|
||||
#>cpp
|
||||
#pragma once
|
||||
|
||||
#include "query/frontend/ast/ast.hpp"
|
||||
#include "query/frontend/ast/ast_serialization.capnp.h"
|
||||
#include "storage/serialization.hpp"
|
||||
cpp<#
|
||||
|
||||
(load "query/frontend/ast/ast.lcp")
|
||||
|
||||
(lcp:namespace query)
|
||||
|
||||
#>cpp
|
||||
Tree *Load(AstStorage *ast, const capnp::Tree::Reader &tree,
|
||||
std::vector<int> *loaded_uids);
|
||||
cpp<#
|
||||
|
||||
(lcp:in-impl
|
||||
#>cpp
|
||||
Tree *Load(AstStorage *ast, const capnp::Tree::Reader &tree,
|
||||
std::vector<int> *loaded_uids) {
|
||||
ast->storage_.clear();
|
||||
std::unique_ptr<Tree> root;
|
||||
::query::Load(&root, tree, ast, loaded_uids);
|
||||
ast->root_idx_ = ast->storage_.size();
|
||||
ast->storage_.emplace_back(std::move(root));
|
||||
return ast->storage_[ast->root_idx_].get();
|
||||
}
|
||||
cpp<#)
|
||||
|
||||
(lcp:pop-namespace) ;; namespace query
|
@ -3,9 +3,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "query/frontend/ast/ast_serialization.hpp"
|
||||
#include "query/plan/distributed_ops.capnp.h"
|
||||
#include "query/plan/operator.hpp"
|
||||
|
||||
cpp<#
|
||||
|
||||
(load "query/plan/operator.lcp")
|
||||
|
@ -139,7 +139,7 @@ cpp<#
|
||||
|
||||
(lcp:capnp-import 'utils "/utils/serialization.capnp")
|
||||
(lcp:capnp-import 'storage "/storage/serialization.capnp")
|
||||
(lcp:capnp-import 'ast "/query/frontend/ast/ast.capnp")
|
||||
(lcp:capnp-import 'ast "/query/frontend/ast/ast_serialization.capnp")
|
||||
(lcp:capnp-import 'semantic "/query/frontend/semantic/symbol.capnp")
|
||||
(lcp:capnp-import 'query "/query/serialization.capnp")
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
@0xf47e119e21912f20;
|
||||
|
||||
using Ast = import "/query/frontend/ast/ast.capnp";
|
||||
using Ast = import "/query/frontend/ast/ast_serialization.capnp";
|
||||
using Cxx = import "/capnp/c++.capnp";
|
||||
using Storage = import "/storage/serialization.capnp";
|
||||
using Utils = import "/utils/serialization.capnp";
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "serialization.hpp"
|
||||
#include "query/serialization.hpp"
|
||||
|
||||
#include "distributed/data_manager.hpp"
|
||||
|
||||
|
@ -11,13 +11,14 @@
|
||||
|
||||
#include "query/context.hpp"
|
||||
#include "query/frontend/ast/ast.hpp"
|
||||
#include "query/frontend/ast/ast_serialization.hpp"
|
||||
#include "query/frontend/ast/cypher_main_visitor.hpp"
|
||||
#include "query/frontend/opencypher/parser.hpp"
|
||||
#include "query/frontend/stripped.hpp"
|
||||
#include "query/typed_value.hpp"
|
||||
|
||||
#include "capnp/message.h"
|
||||
#include "query/frontend/ast/ast.capnp.h"
|
||||
#include "query/frontend/ast/ast_serialization.capnp.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -166,7 +167,7 @@ class CapnpAstGenerator : public Base {
|
||||
const query::capnp::Tree::Reader reader =
|
||||
message.getRoot<query::capnp::Tree>();
|
||||
std::vector<int> loaded_uids;
|
||||
new_ast.Load(reader, &loaded_uids);
|
||||
Load(&new_ast, reader, &loaded_uids);
|
||||
}
|
||||
return new_ast;
|
||||
}()),
|
||||
|
Loading…
Reference in New Issue
Block a user