Kùzu C++ API
Loading...
Searching...
No Matches
parsed_expression.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <string>
5#include <unordered_map>
6#include <vector>
7
8#include "cast.h"
9#include "copy_constructors.h"
10#include "expression_type.h"
11
12namespace kuzu {
13
14namespace common {
15struct FileInfo;
16class Serializer;
17class Deserializer;
18} // namespace common
19
20namespace parser {
21
23class ParsedExpressionChildrenVisitor;
24using parsed_expr_vector = std::vector<std::unique_ptr<ParsedExpression>>;
26 std::pair<std::unique_ptr<ParsedExpression>, std::unique_ptr<ParsedExpression>>;
27using s_parsed_expr_pair = std::pair<std::string, std::unique_ptr<ParsedExpression>>;
28
30 friend class ParsedExpressionChildrenVisitor;
31
32public:
33 ParsedExpression(common::ExpressionType type, std::unique_ptr<ParsedExpression> child,
34 std::string rawName);
35 ParsedExpression(common::ExpressionType type, std::unique_ptr<ParsedExpression> left,
36 std::unique_ptr<ParsedExpression> right, std::string rawName);
37 ParsedExpression(common::ExpressionType type, std::string rawName)
38 : type{type}, rawName{std::move(rawName)} {}
39 explicit ParsedExpression(common::ExpressionType type) : type{type} {}
40
41 ParsedExpression(common::ExpressionType type, std::string alias, std::string rawName,
42 parsed_expr_vector children)
43 : type{type}, alias{std::move(alias)}, rawName{std::move(rawName)},
44 children{std::move(children)} {}
46 virtual ~ParsedExpression() = default;
47
49
50 void setAlias(std::string name) { alias = std::move(name); }
51
52 bool hasAlias() const { return !alias.empty(); }
53
54 std::string getAlias() const { return alias; }
55
56 std::string getRawName() const { return rawName; }
57
58 uint32_t getNumChildren() const { return children.size(); }
59 ParsedExpression* getChild(uint32_t idx) const { return children[idx].get(); }
60
61 std::string toString() const { return rawName; }
62
63 virtual std::unique_ptr<ParsedExpression> copy() const {
64 return std::make_unique<ParsedExpression>(type, alias, rawName, copyVector(children));
65 }
66
67 void serialize(common::Serializer& serializer) const;
68
69 static std::unique_ptr<ParsedExpression> deserialize(common::Deserializer& deserializer);
70
71 template<class TARGET>
72 TARGET& cast() {
73 return common::ku_dynamic_cast<ParsedExpression&, TARGET&>(*this);
74 }
75 template<class TARGET>
76 const TARGET& constCast() const {
77 return common::ku_dynamic_cast<const ParsedExpression&, const TARGET&>(*this);
78 }
79 template<class TARGET>
80 const TARGET* constPtrCast() const {
81 return common::ku_dynamic_cast<const ParsedExpression*, const TARGET*>(this);
82 }
83
84private:
85 virtual void serializeInternal(common::Serializer&) const {}
86
87protected:
89 std::string alias;
90 std::string rawName;
92};
93
94using options_t = std::unordered_map<std::string, std::unique_ptr<parser::ParsedExpression>>;
95
97 static std::unique_ptr<ParsedExpression> getSerialDefaultExpr(const std::string& sequenceName);
98};
99
100} // namespace parser
101} // namespace kuzu
#define KUZU_API
Definition api.h:25
Definition deserializer.h:15
Definition serializer.h:15
Definition parsed_expression.h:29
const TARGET * constPtrCast() const
Definition parsed_expression.h:80
void setAlias(std::string name)
Definition parsed_expression.h:50
std::string getRawName() const
Definition parsed_expression.h:56
uint32_t getNumChildren() const
Definition parsed_expression.h:58
ParsedExpression(common::ExpressionType type, std::string rawName)
Definition parsed_expression.h:37
common::ExpressionType getExpressionType() const
Definition parsed_expression.h:48
void serialize(common::Serializer &serializer) const
common::ExpressionType type
Definition parsed_expression.h:88
virtual std::unique_ptr< ParsedExpression > copy() const
Definition parsed_expression.h:63
parsed_expr_vector children
Definition parsed_expression.h:91
ParsedExpression(common::ExpressionType type, std::unique_ptr< ParsedExpression > left, std::unique_ptr< ParsedExpression > right, std::string rawName)
std::string alias
Definition parsed_expression.h:89
TARGET & cast()
Definition parsed_expression.h:72
ParsedExpression(common::ExpressionType type, std::unique_ptr< ParsedExpression > child, std::string rawName)
std::string getAlias() const
Definition parsed_expression.h:54
std::string rawName
Definition parsed_expression.h:90
bool hasAlias() const
Definition parsed_expression.h:52
ParsedExpression(common::ExpressionType type, std::string alias, std::string rawName, parsed_expr_vector children)
Definition parsed_expression.h:41
ParsedExpression * getChild(uint32_t idx) const
Definition parsed_expression.h:59
static std::unique_ptr< ParsedExpression > deserialize(common::Deserializer &deserializer)
ParsedExpression(common::ExpressionType type)
Definition parsed_expression.h:39
std::string toString() const
Definition parsed_expression.h:61
virtual ~ParsedExpression()=default
const TARGET & constCast() const
Definition parsed_expression.h:76
DELETE_COPY_DEFAULT_MOVE(ParsedExpression)
ExpressionType
Definition expression_type.h:9
std::unordered_map< std::string, std::unique_ptr< parser::ParsedExpression > > options_t
Definition parsed_expression.h:94
std::vector< std::unique_ptr< ParsedExpression > > parsed_expr_vector
Definition parsed_expression.h:24
std::pair< std::unique_ptr< ParsedExpression >, std::unique_ptr< ParsedExpression > > parsed_expr_pair
Definition parsed_expression.h:25
std::pair< std::string, std::unique_ptr< ParsedExpression > > s_parsed_expr_pair
Definition parsed_expression.h:27
Definition alter_type.h:5
Definition parsed_expression.h:96
static std::unique_ptr< ParsedExpression > getSerialDefaultExpr(const std::string &sequenceName)