This repository was archived by the owner on Aug 10, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathExpr.h
More file actions
176 lines (127 loc) · 3.86 KB
/
Copy pathExpr.h
File metadata and controls
176 lines (127 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#ifndef __SQLPARSER__EXPR_H__
#define __SQLPARSER__EXPR_H__
#include <stdlib.h>
#include <memory>
#include <vector>
namespace hsql {
struct SelectStatement;
// Helper function used by the lexer.
// TODO: move to more appropriate place.
char* substr(const char* source, int from, int to);
enum ExprType {
kExprLiteralFloat,
kExprLiteralString,
kExprLiteralInt,
kExprLiteralNull,
kExprStar,
kExprParameter,
kExprColumnRef,
kExprFunctionRef,
kExprOperator,
kExprSelect,
kExprHint,
kExprArray,
kExprArrayIndex
};
// Operator types. These are important for expressions of type kExprOperator.
enum OperatorType {
kOpNone,
// Ternary operator
kOpBetween,
// n-nary special case
kOpCase,
kOpCaseListElement, // `WHEN expr THEN expr`
// Binary operators.
kOpPlus,
kOpMinus,
kOpAsterisk,
kOpSlash,
kOpPercentage,
kOpCaret,
kOpEquals,
kOpNotEquals,
kOpLess,
kOpLessEq,
kOpGreater,
kOpGreaterEq,
kOpLike,
kOpNotLike,
kOpILike,
kOpAnd,
kOpOr,
kOpIn,
kOpConcat,
// Unary operators.
kOpNot,
kOpUnaryMinus,
kOpIsNull,
kOpExists
};
typedef struct Expr Expr;
// Represents SQL expressions (i.e. literals, operators, column_refs).
// TODO: When destructing a placeholder expression, we might need to alter the
// placeholder_list.
struct Expr {
Expr(ExprType type);
virtual ~Expr();
ExprType type;
// TODO: Replace expressions by list.
Expr* expr;
Expr* expr2;
std::vector<Expr*>* exprList;
SelectStatement* select;
char* name;
char* table;
char* alias;
float fval;
int64_t ival;
int64_t ival2;
OperatorType opType;
bool distinct;
// Convenience accessor methods.
bool isType(ExprType exprType) const;
bool isLiteral() const;
bool hasAlias() const;
bool hasTable() const;
const char* getName() const;
// Static constructors.
static Expr* make(ExprType type);
static Expr* makeOpUnary(OperatorType op, Expr* expr);
static Expr* makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2);
static Expr* makeBetween(Expr* expr, Expr* left, Expr* right);
static Expr* makeCaseList(Expr* caseListElement);
static Expr* makeCaseListElement(Expr* when, Expr* then);
static Expr* caseListAppend(Expr* caseList, Expr* caseListElement);
static Expr* makeCase(Expr* expr, Expr* when, Expr* elseExpr);
static Expr* makeLiteral(int64_t val);
static Expr* makeLiteral(double val);
static Expr* makeLiteral(char* val);
static Expr* makeNullLiteral();
static Expr* makeColumnRef(char* name);
static Expr* makeColumnRef(char* table, char* name);
static Expr* makeStar(void);
static Expr* makeStar(char* table);
static Expr* makeFunctionRef(char* func_name, std::vector<Expr*>* exprList,
bool distinct);
static Expr* makeArray(std::vector<Expr*>* exprList);
static Expr* makeArrayIndex(Expr* expr, int64_t index);
static Expr* makeParameter(int id);
static Expr* makeSelect(SelectStatement* select);
static Expr* makeExists(SelectStatement* select);
static Expr* makeInOperator(Expr* expr, std::vector<Expr*>* exprList);
static Expr* makeInOperator(Expr* expr, SelectStatement* select);
};
// Zero initializes an Expr object and assigns it to a space in the heap
// For Hyrise we still had to put in the explicit NULL constructor
// http://www.ex-parrot.com/~chris/random/initialise.html
// Unused
#define ALLOC_EXPR(var, type) \
Expr* var; \
do { \
Expr zero = {type}; \
var = (Expr*)malloc(sizeof *var); \
*var = zero; \
} while (0);
#undef ALLOC_EXPR
} // namespace hsql
#endif