mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
AST.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <memory>
7#include <mutable/mutable-config.hpp>
8#include <variant>
9#include <vector>
10
11
12namespace m {
13
14struct Type;
15struct Function;
16struct Attribute;
17struct Table;
18
19namespace ast {
20
21struct ASTClauseVisitor;
24struct ASTExprVisitor;
29struct Sema;
30struct Stmt;
31
32
33/*======================================================================================================================
34* Expressions
35*====================================================================================================================*/
36
38struct M_EXPORT Expr
39{
40 friend struct Sema;
41 friend struct GetCorrelationInfo;
42
44
45 private:
47 const Type *type_ = nullptr;
50 bool is_correlated_ = false;
51
52 public:
53 explicit Expr(Token tok) : tok(std::move(tok)) { }
54 Expr(Token tok, const Type *type) : tok(std::move(tok)), type_(type) { }
55 virtual ~Expr() { }
56
58 const Type * type() const { return M_notnull(type_); }
61 void type(const Type *type) { M_insist(not type_); type_ = type; }
63 bool has_type() const { return type_ != nullptr; }
64
67 virtual bool is_constant() const = 0;
69 virtual bool can_be_null() const = 0;
70
73 virtual bool contains_free_variables() const = 0;
76 virtual bool contains_bound_variables() const = 0;
77
80 virtual uint64_t hash() const = 0;
81
83 virtual bool operator==(const Expr &other) const = 0;
85 bool operator!=(const Expr &other) const { return not operator==(other); }
86
87 virtual void accept(ASTExprVisitor &v) = 0;
88 virtual void accept(ConstASTExprVisitor &v) const = 0;
89
95 Schema get_required() const;
96
98 void dot(std::ostream &out) const;
99
100 friend std::ostream & M_EXPORT operator<<(std::ostream &out, const Expr &e);
101
103 friend std::string to_string(const Expr &e) {
104 std::ostringstream oss;
105 oss << e;
106 return oss.str();
107 }
109
110 void dump(std::ostream &out) const;
111 void dump() const;
112};
113
115struct M_EXPORT ErrorExpr : Expr
116{
117 explicit ErrorExpr(Token tok) : Expr(std::move(tok)) { }
118
119 bool is_constant() const override { return false; }
120 bool can_be_null() const override { return false; }
121 bool contains_free_variables() const override { return false; }
122 bool contains_bound_variables() const override { return false; }
123
124 uint64_t hash() const override { return 8546018603292329429UL; }
125
126 bool operator==(const Expr &other) const override;
127
128 void accept(ASTExprVisitor &v) override;
129 void accept(ConstASTExprVisitor &v) const override;
130};
131
133struct M_EXPORT Designator : Expr
134{
135 friend struct Sema;
136
137 using target_type = std::variant<std::monostate, const Expr*, const Attribute*>;
140 private:
142 unsigned binding_depth_ = 0;
144
145 public:
146 explicit Designator(Token attr_name)
147 : Expr(attr_name)
148 , table_name(Token::CreateArtificial())
149 , attr_name(std::move(attr_name))
150 { }
151
152 Designator(Token dot, Token table_name, Token attr_name)
153 : Expr(std::move(dot))
154 , table_name(std::move(table_name))
155 , attr_name(std::move(attr_name))
156 { }
157
158 Designator(Token dot, Token table_name, Token attr_name, const Type *type, target_type target)
159 : Expr(std::move(dot), type)
160 , table_name(std::move(table_name))
161 , attr_name(std::move(attr_name))
162 , target_(target)
163 { }
164
165 bool is_constant() const override {
166 if (auto e = std::get_if<const Expr*>(&target_))
167 return (*e)->is_constant();
168 return false;
169 }
170 bool can_be_null() const override {
171 return std::visit(overloaded {
172 [](const Expr *e) -> bool { return e->can_be_null(); },
173 [](const Attribute *a) -> bool { return not a->not_nullable; },
174 [](std::monostate) -> bool { return true; }
175 }, target_);
176 }
177
179 bool contains_free_variables() const override { return binding_depth_ != 0; }
181 bool contains_bound_variables() const override { return binding_depth_ == 0; }
182
183 unsigned binding_depth() const { return binding_depth_; }
184
185 uint64_t hash() const override;
186
187 bool operator==(const Expr &other) const override;
188
189 void accept(ASTExprVisitor &v) override;
190 void accept(ConstASTExprVisitor &v) const override;
191
192 bool has_explicit_table_name() const { return bool(table_name); }
194 bool is_identifier() const { return not has_table_name(); }
195
196 bool has_table_name() const { return table_name.text.has_value(); }
198 M_insist(has_table_name(),
199 "if the table name was not explicitly provided, semantic analysis must deduce it first");
200 return table_name.text.assert_not_none();
201 }
202
203 const target_type & target() const { return target_; }
204
205 private:
207 void set_binding_depth(unsigned depth) { binding_depth_ = depth; }
208 void decrease_binding_depth() { M_insist(binding_depth_ > 0); --binding_depth_; }
209};
210
212struct M_EXPORT Constant : Expr
213{
214 Constant(Token tok) : Expr(std::move(tok)) {}
215
216 bool is_constant() const override { return true; }
217 bool can_be_null() const override { return is_null(); }
218 bool contains_free_variables() const override { return false; }
219 bool contains_bound_variables() const override { return false; }
220
221 uint64_t hash() const override;
222
223 bool operator==(const Expr &other) const override;
224
225 void accept(ASTExprVisitor &v) override;
226 void accept(ConstASTExprVisitor &v) const override;
227
228 bool is_null() const { return tok.type == TK_Null; }
229 bool is_bool() const { return tok.type == TK_True or tok.type == TK_False; }
230 bool is_number() const { return is_integer() or is_float(); }
231 bool is_integer() const { return tok.type == TK_OCT_INT or tok.type == TK_DEC_INT or tok.type == TK_HEX_FLOAT; }
232 bool is_float() const { return tok.type == TK_DEC_FLOAT or tok.type == TK_HEX_FLOAT; }
233 bool is_string() const { return tok.type == TK_STRING_LITERAL; }
234 bool is_date() const { return tok.type == TK_DATE; }
235 bool is_datetime() const { return tok.type == TK_DATE_TIME; }
236};
237
239struct M_EXPORT PostfixExpr : Expr
240{
241 PostfixExpr(Token tok) : Expr(std::move(tok)) {}
242};
243
246{
247 friend struct Sema;
248
249 std::unique_ptr<Expr> fn;
250 std::vector<std::unique_ptr<Expr>> args;
251 private:
252 const Function *func_ = nullptr;
253
254 public:
255 FnApplicationExpr(Token lpar, std::unique_ptr<Expr> fn, std::vector<std::unique_ptr<Expr>> args)
256 : PostfixExpr(std::move(lpar))
257 , fn(M_notnull(std::move(fn)))
258 , args(std::move(args))
259 {
260#ifndef NDEBUG
261 for (auto &arg : args) M_insist(bool(arg));
262#endif
263 }
264
265 bool is_constant() const override { return false; }
266 bool can_be_null() const override {
267 if (not func_)
268 return true;
269 switch (func_->fnid) {
270 default:
271 M_unreachable("function kind not implemented");
272
274 return true;
275
276 case Function::FN_COUNT:
277 case Function::FN_ISNULL:
278 return false;
279
280 case Function::FN_MIN:
281 case Function::FN_MAX:
282 case Function::FN_SUM:
283 case Function::FN_AVG:
284 case Function::FN_INT:
285 M_insist(args.size() == 1);
286 return args[0]->can_be_null();
287 }
288 }
289
290 /* A `FnApplicationExpr` is correlated iff at least one argument is correlated. */
291 bool contains_free_variables() const override {
292 // if (fn->contains_free_variables()) return true;
293 for (auto &arg : args)
294 if (arg->contains_free_variables())
295 return true;
296 return false;
297 }
298
299 bool contains_bound_variables() const override {
300 if (fn->contains_bound_variables()) return true;
301 for (auto &arg : args)
302 if (arg->contains_bound_variables())
303 return true;
304 return false;
305 }
306
307 uint64_t hash() const override;
308
309 bool operator==(const Expr &other) const override;
310
311 bool has_function() const { return func_; }
312 const Function &get_function() const {
313 if (not func_)
314 throw runtime_error("no function provided");
315 return *func_;
316 }
317
318 void accept(ASTExprVisitor &v) override;
319 void accept(ConstASTExprVisitor &v) const override;
320};
321
323struct M_EXPORT UnaryExpr : Expr
324{
325 std::unique_ptr<Expr> expr;
326
327 UnaryExpr(Token op, std::unique_ptr<Expr> expr)
328 : Expr(std::move(op))
329 , expr(M_notnull(std::move(expr)))
330 { }
331
332 bool is_constant() const override { return expr->is_constant(); }
333 bool can_be_null() const override { return expr->can_be_null(); }
334 bool contains_free_variables() const override { return expr->contains_free_variables(); }
335 bool contains_bound_variables() const override { return expr->contains_bound_variables(); }
336 Token op() const { return tok; }
337
338 uint64_t hash() const override;
339
340 bool operator==(const Expr &other) const override;
341
342 void accept(ASTExprVisitor &v) override;
343 void accept(ConstASTExprVisitor &v) const override;
344};
345
347struct M_EXPORT BinaryExpr : Expr
348{
349 std::unique_ptr<Expr> lhs;
350 std::unique_ptr<Expr> rhs;
351 const Numeric *common_operand_type = nullptr;
352
353 BinaryExpr(Token op, std::unique_ptr<Expr> lhs, std::unique_ptr<Expr> rhs)
354 : Expr(std::move(op))
355 , lhs(M_notnull(std::move(lhs)))
356 , rhs(M_notnull(std::move(rhs)))
357 { }
358
359 bool is_constant() const override { return lhs->is_constant() and rhs->is_constant(); }
360 bool can_be_null() const override {
361 if (tok.type == TK_And or tok.type == TK_Or) { // special case handling for ternary logic of `AND` and `OR`
362 /* TODO: use `is_constant()` and check whether one side *evaluates* to dominating element */
363 const auto dominating_element = tok.type == TK_And ? TK_False : TK_True;
364 const auto lhs_const = cast<Constant>(lhs.get());
365 const auto rhs_const = cast<Constant>(rhs.get());
366 const bool lhs_dominates = lhs_const and lhs_const->tok.type == dominating_element;
367 const bool rhs_dominates = rhs_const and rhs_const->tok.type == dominating_element;
368 return not lhs_dominates and not rhs_dominates and (lhs->can_be_null() or rhs->can_be_null());
369 }
370 return lhs->can_be_null() or rhs->can_be_null();
371 }
372
373 bool contains_free_variables() const override
374 { return lhs->contains_free_variables() or rhs->contains_free_variables(); }
375 bool contains_bound_variables() const override
376 { return lhs->contains_bound_variables() or rhs->contains_bound_variables(); }
377 Token op() const { return tok; }
378
379 uint64_t hash() const override;
380
381 bool operator==(const Expr &other) const override;
382
383 void accept(ASTExprVisitor &v) override;
384 void accept(ConstASTExprVisitor &v) const override;
385};
386
388struct M_EXPORT QueryExpr : Expr
389{
390 std::unique_ptr<Stmt> query;
391
392 private:
394
395 public:
396 QueryExpr(Token op, std::unique_ptr<Stmt> query)
397 : Expr(std::move(op))
398 , query(M_notnull(std::move(query)))
399 , alias_(make_unique_alias())
400 { }
401
402 bool is_constant() const override;
403 bool can_be_null() const override;
404
408 bool contains_free_variables() const override { return false; }
412 bool contains_bound_variables() const override { return true; }
413
414 uint64_t hash() const override;
415
416 bool operator==(const Expr &other) const override;
417
418 void accept(ASTExprVisitor &v) override;
419 void accept(ConstASTExprVisitor &v) const override;
420
421 const ThreadSafePooledString & alias() const { return alias_; }
422
423 private:
424 static ThreadSafePooledString make_unique_alias();
425};
426
427#define M_AST_EXPR_LIST(X) \
428 X(m::ast::ErrorExpr) \
429 X(m::ast::Designator) \
430 X(m::ast::Constant) \
431 X(m::ast::FnApplicationExpr) \
432 X(m::ast::UnaryExpr) \
433 X(m::ast::BinaryExpr) \
434 X(m::ast::QueryExpr)
435
438
440template<bool C>
442{
443 using super = std::conditional_t<C, ConstASTExprVisitor, ASTExprVisitor>;
444 template<typename T> using Const = typename super::template Const<T>;
445
447
448 using super::operator();
450 (*this)(*e.fn);
451 for (auto &arg : e.args)
452 (*this)(*arg);
453 }
454 void operator()(Const<UnaryExpr> &e) override { (*this)(*e.expr); }
455 void operator()(Const<BinaryExpr> &e) override { (*this)(*e.lhs); (*this)(*e.rhs); }
456};
457
460
461template<bool C>
462struct M_EXPORT ThePreOrderExprVisitor : std::conditional_t<C, ConstASTExprVisitor, ASTExprVisitor>
463{
464 using super = std::conditional_t<C, ConstASTExprVisitor, ASTExprVisitor>;
465 template<typename T> using Const = typename super::template Const<T>;
466
468
469 void operator()(Const<Expr> &e);
470};
471
472template<bool C>
473struct M_EXPORT ThePostOrderExprVisitor : std::conditional_t<C, ConstASTExprVisitor, ASTExprVisitor>
474{
475 using super = std::conditional_t<C, ConstASTExprVisitor, ASTExprVisitor>;
476 template<typename T> using Const = typename super::template Const<T>;
477
479
480 void operator()(Const<Expr> &e);
481};
482
487
492
493
494/*======================================================================================================================
495 * Clauses
496 *====================================================================================================================*/
497
498struct M_EXPORT Clause
499{
501
502 Clause(Token tok) : tok(std::move(tok)) { }
503 virtual ~Clause() { }
504
505 virtual void accept(ASTClauseVisitor &v) = 0;
506 virtual void accept(ConstASTClauseVisitor &v) const = 0;
507
508 void dot(std::ostream &out) const;
509
510 void dump(std::ostream &out) const;
511 void dump() const;
512
513 friend std::ostream & M_EXPORT operator<<(std::ostream &out, const Clause &c);
514};
515
516struct M_EXPORT ErrorClause : Clause
517{
518 ErrorClause(Token tok) : Clause(std::move(tok)) { }
519
520 void accept(ASTClauseVisitor &v) override;
521 void accept(ConstASTClauseVisitor &v) const override;
522};
523
524struct M_EXPORT SelectClause : Clause
525{
526 using select_type = std::pair<std::unique_ptr<Expr>, Token>;
527
528 std::vector<select_type> select;
530 std::vector<std::unique_ptr<Expr>> expanded_select_all;
531
532 SelectClause(Token tok, std::vector<select_type> select, Token select_all)
533 : Clause(std::move(tok))
534 , select(std::move(select))
535 , select_all(std::move(select_all))
536 { }
537
538 void accept(ASTClauseVisitor &v) override;
539 void accept(ConstASTClauseVisitor &v) const override;
540};
541
542struct M_EXPORT FromClause : Clause
543{
545 {
546 friend struct Sema;
547
548 public:
549 std::variant<Token, Stmt*> source;
551
552 private:
553 const Table *table_ = nullptr;
554
555 public:
556 from_type(Token name, Token alias) : source(std::move(name)), alias(std::move(alias)) { }
557 from_type(std::unique_ptr<Stmt> S, Token alias) : source(S.release()), alias(std::move(alias)) { }
558
559 const Table & table() const { return *M_notnull(table_); }
560 bool has_table() const { return table_ != nullptr; }
561 };
562
563 std::vector<from_type> from;
564
565 FromClause(Token tok, std::vector<from_type> from) : Clause(std::move(tok)), from(std::move(from)) { }
566 ~FromClause();
567
568 void accept(ASTClauseVisitor &v) override;
569 void accept(ConstASTClauseVisitor &v) const override;
570};
571
572struct M_EXPORT WhereClause : Clause
573{
574 std::unique_ptr<Expr> where;
575
576 WhereClause(Token tok, std::unique_ptr<Expr> where)
577 : Clause(std::move(tok))
578 , where(M_notnull(std::move(where)))
579 { }
580
581 void accept(ASTClauseVisitor &v) override;
582 void accept(ConstASTClauseVisitor &v) const override;
583};
584
585struct M_EXPORT GroupByClause : Clause
586{
587 using group_type = std::pair<std::unique_ptr<Expr>, Token>;
588 std::vector<group_type> group_by;
589
590 GroupByClause(Token tok, std::vector<group_type> group_by)
591 : Clause(std::move(tok))
592 , group_by(std::move(group_by))
593 { }
594
595 void accept(ASTClauseVisitor &v) override;
596 void accept(ConstASTClauseVisitor &v) const override;
597};
598
599struct M_EXPORT HavingClause : Clause
600{
601 std::unique_ptr<Expr> having;
602
603 HavingClause(Token tok, std::unique_ptr<Expr> having)
604 : Clause(std::move(tok))
605 , having(M_notnull(std::move(having)))
606 { }
607
608 void accept(ASTClauseVisitor &v) override;
609 void accept(ConstASTClauseVisitor &v) const override;
610};
611
612struct M_EXPORT OrderByClause : Clause
613{
614 using order_type = std::pair<std::unique_ptr<Expr>, bool>;
615
616 std::vector<order_type> order_by;
617
618 OrderByClause(Token tok, std::vector<order_type> order_by)
619 : Clause(std::move(tok))
620 , order_by(std::move(order_by))
621 { }
622
623 void accept(ASTClauseVisitor &v) override;
624 void accept(ConstASTClauseVisitor &v) const override;
625};
626
627struct M_EXPORT LimitClause : Clause
628{
631
632 LimitClause(Token tok, Token limit, Token offset)
633 : Clause(std::move(tok))
634 , limit(std::move(limit))
635 , offset(std::move(offset))
636 { }
637
638 void accept(ASTClauseVisitor &v) override;
639 void accept(ConstASTClauseVisitor &v) const override;
640};
641
642#define M_AST_CLAUSE_LIST(X) \
643 X(m::ast::ErrorClause) \
644 X(m::ast::SelectClause) \
645 X(m::ast::FromClause) \
646 X(m::ast::WhereClause) \
647 X(m::ast::GroupByClause) \
648 X(m::ast::HavingClause) \
649 X(m::ast::OrderByClause) \
650 X(m::ast::LimitClause)
651
654
655
656/*======================================================================================================================
657 * Constraints
658 *====================================================================================================================*/
659
661struct M_EXPORT Constraint
662{
664
665 Constraint(Token tok) : tok(std::move(tok)) { }
666
667 virtual ~Constraint() { }
668
669 virtual void accept(ASTConstraintVisitor &v) = 0;
670 virtual void accept(ConstASTConstraintVisitor &v) const = 0;
671};
672
674{
676
677 void accept(ASTConstraintVisitor &v) override;
678 void accept(ConstASTConstraintVisitor &v) const override;
679};
680
682{
683 UniqueConstraint(Token tok) : Constraint(std::move(tok)) { }
684
685 void accept(ASTConstraintVisitor &v) override;
686 void accept(ConstASTConstraintVisitor &v) const override;
687};
688
690{
691 NotNullConstraint(Token tok) : Constraint(std::move(tok)) { }
692
693 void accept(ASTConstraintVisitor &v) override;
694 void accept(ConstASTConstraintVisitor &v) const override;
695};
696
698{
699 std::unique_ptr<Expr> cond;
700
701 CheckConditionConstraint(Token tok, std::unique_ptr<Expr> cond)
702 : Constraint(std::move(tok))
703 , cond(std::move(cond))
704 {
705 M_insist(bool(this->cond));
706 }
707
708 void accept(ASTConstraintVisitor &v) override;
709 void accept(ConstASTConstraintVisitor &v) const override;
710};
711
713{
715 {
718 };
719
723
724 ReferenceConstraint(Token tok, Token table_name, Token attr_name, OnDeleteAction action)
725 : Constraint(std::move(tok))
726 , table_name(std::move(table_name))
727 , attr_name(std::move(attr_name))
728 , on_delete(action)
729 { }
730
731 void accept(ASTConstraintVisitor &v) override;
732 void accept(ConstASTConstraintVisitor &v) const override;
733};
734
735#define M_AST_CONSTRAINT_LIST(X) \
736 X(m::ast::PrimaryKeyConstraint) \
737 X(m::ast::UniqueConstraint) \
738 X(m::ast::NotNullConstraint) \
739 X(m::ast::CheckConditionConstraint) \
740 X(m::ast::ReferenceConstraint)
741
744
745
746/*======================================================================================================================
747 * Command
748 *====================================================================================================================*/
749
750struct M_EXPORT Command
751{
752 virtual ~Command() = default;
753
754 virtual void accept(ASTCommandVisitor &v) = 0;
755 virtual void accept(ConstASTCommandVisitor &v) const = 0;
756
757 void dump(std::ostream &out) const;
758 void dump() const;
759
760 friend std::ostream & M_EXPORT operator<<(std::ostream &out, const Command &cmd);
761};
762
763
764/*======================================================================================================================
765 * Instruction
766 *====================================================================================================================*/
767
768struct M_EXPORT Instruction : Command
769{
775 std::vector<std::string> args;
776
777 Instruction(Token tok, ThreadSafePooledString name, std::vector<std::string> args)
778 : tok(std::move(tok))
779 , name(std::move(name))
780 , args(std::move(args))
781 { }
782
783 void accept(ASTCommandVisitor &v) override;
784 void accept(ConstASTCommandVisitor &v) const override;
785};
786
787
788/*======================================================================================================================
789 * Statements
790 *====================================================================================================================*/
791
793struct M_EXPORT Stmt : Command
794{
795 virtual ~Stmt() { }
796
798 void dot(std::ostream &out) const;
799};
800
802struct M_EXPORT ErrorStmt : Stmt
803{
805
806 explicit ErrorStmt(Token tok) : tok(std::move(tok)) { }
807
808 void accept(ASTCommandVisitor &v) override;
809 void accept(ConstASTCommandVisitor &v) const override;
810};
811
812struct M_EXPORT EmptyStmt : Stmt
813{
815
816 explicit EmptyStmt(Token tok) : tok(std::move(tok)) { }
817
818 void accept(ASTCommandVisitor &v) override;
819 void accept(ConstASTCommandVisitor &v) const override;
820};
821
822struct M_EXPORT CreateDatabaseStmt : Stmt
823{
825
826 explicit CreateDatabaseStmt(Token database_name) : database_name(std::move(database_name)) { }
827
828 void accept(ASTCommandVisitor &v) override;
829 void accept(ConstASTCommandVisitor &v) const override;
830};
831
832struct M_EXPORT DropDatabaseStmt : Stmt
833{
836
837 explicit DropDatabaseStmt(Token database_name, bool has_if_exists)
838 : database_name(std::move(database_name))
839 , has_if_exists(has_if_exists)
840 { }
841
842 void accept(ASTCommandVisitor &v) override;
843 void accept(ConstASTCommandVisitor &v) const override;
844};
845
846struct M_EXPORT UseDatabaseStmt : Stmt
847{
849
850 explicit UseDatabaseStmt(Token database_name) : database_name(std::move(database_name)) { }
851
852 void accept(ASTCommandVisitor &v) override;
853 void accept(ConstASTCommandVisitor &v) const override;
854};
855
856struct M_EXPORT CreateTableStmt : Stmt
857{
859 {
861 const Type *type;
862 std::vector<std::unique_ptr<Constraint>> constraints;
863
864 attribute_definition(Token name, const Type *type, std::vector<std::unique_ptr<Constraint>> constraints)
865 : name(std::move(name))
866 , type(type)
867 , constraints(std::move(constraints))
868 { }
869 };
870
872 std::vector<std::unique_ptr<attribute_definition>> attributes;
873
874 CreateTableStmt(Token table_name, std::vector<std::unique_ptr<attribute_definition>> attributes)
875 : table_name(std::move(table_name))
876 , attributes(std::move(attributes))
877 { }
878
879 void accept(ASTCommandVisitor &v) override;
880 void accept(ConstASTCommandVisitor &v) const override;
881};
882
883struct M_EXPORT DropTableStmt : Stmt
884{
885 std::vector<std::unique_ptr<Token>> table_names;
887
888 DropTableStmt(std::vector<std::unique_ptr<Token>> table_names, bool has_if_exists)
889 : table_names(std::move(table_names))
890 , has_if_exists(has_if_exists)
891 { }
892
893 void accept(ASTCommandVisitor &v) override;
894 void accept(ConstASTCommandVisitor &v) const override;
895};
896
897struct M_EXPORT CreateIndexStmt : Stmt
898{
904 std::vector<std::unique_ptr<Expr>> key_fields;
905
906 CreateIndexStmt(Token has_unique, bool has_if_not_exists, Token index_name, Token table_name, Token method,
907 std::vector<std::unique_ptr<Expr>> key_fields)
908 : has_unique(std::move(has_unique))
909 , has_if_not_exists(has_if_not_exists)
910 , index_name(std::move(index_name))
911 , table_name(std::move(table_name))
912 , method(std::move(method))
913 , key_fields(std::move(key_fields))
914 { }
915
916 void accept(ASTCommandVisitor &v) override;
917 void accept(ConstASTCommandVisitor &v) const override;
918};
919
920struct M_EXPORT DropIndexStmt : Stmt
921{
922 std::vector<std::unique_ptr<Token>> index_names;
924
925 DropIndexStmt(std::vector<std::unique_ptr<Token>> index_names, bool has_if_exists)
926 : index_names(std::move(index_names))
927 , has_if_exists(has_if_exists)
928 { }
929
930 void accept(ASTCommandVisitor &v) override;
931 void accept(ConstASTCommandVisitor &v) const override;
932};
933
935struct M_EXPORT SelectStmt : Stmt
936{
937 std::unique_ptr<Clause> select;
938 std::unique_ptr<Clause> from;
939 std::unique_ptr<Clause> where;
940 std::unique_ptr<Clause> group_by;
941 std::unique_ptr<Clause> having;
942 std::unique_ptr<Clause> order_by;
943 std::unique_ptr<Clause> limit;
944
945 SelectStmt(std::unique_ptr<Clause> select,
946 std::unique_ptr<Clause> from,
947 std::unique_ptr<Clause> where,
948 std::unique_ptr<Clause> group_by,
949 std::unique_ptr<Clause> having,
950 std::unique_ptr<Clause> order_by,
951 std::unique_ptr<Clause> limit)
952 : select(M_notnull(std::move(select)))
953 , from(std::move(from))
954 , where(std::move(where))
955 , group_by(std::move(group_by))
956 , having(std::move(having))
957 , order_by(std::move(order_by))
958 , limit(std::move(limit))
959 { }
960
961 void accept(ASTCommandVisitor &v) override;
962 void accept(ConstASTCommandVisitor &v) const override;
963};
964
966struct M_EXPORT InsertStmt : Stmt
967{
968 enum kind_t { I_Default, I_Null, I_Expr };
969 using element_type = std::pair<kind_t, std::unique_ptr<Expr>>;
970 using tuple_t = std::vector<element_type>;
971
973 std::vector<tuple_t> tuples;
974
975 InsertStmt(Token table_name, std::vector<tuple_t> tuples)
976 : table_name(std::move(table_name))
977 , tuples(std::move(tuples))
978 { }
979
980 void accept(ASTCommandVisitor &v) override;
981 void accept(ConstASTCommandVisitor &v) const override;
982};
983
985struct M_EXPORT UpdateStmt : Stmt
986{
987 using set_type = std::pair<Token, std::unique_ptr<Expr>>;
988
990 std::vector<set_type> set;
991 std::unique_ptr<Clause> where;
992
993 UpdateStmt(Token table_name, std::vector<set_type> set, std::unique_ptr<Clause> where)
994 : table_name(std::move(table_name))
995 , set(std::move(set))
996 , where(std::move(where))
997 { }
998
999 void accept(ASTCommandVisitor &v) override;
1000 void accept(ConstASTCommandVisitor &v) const override;
1001};
1002
1004struct M_EXPORT DeleteStmt : Stmt
1005{
1007 std::unique_ptr<Clause> where = nullptr;
1008
1009 DeleteStmt(Token table_name, std::unique_ptr<Clause> where)
1010 : table_name(std::move(table_name))
1011 , where(std::move(where))
1012 { }
1013
1014 void accept(ASTCommandVisitor &v) override;
1015 void accept(ConstASTCommandVisitor &v) const override;
1016};
1017
1019struct M_EXPORT ImportStmt : Stmt
1020{
1022 ImportStmt(Token table_name) : table_name(std::move(table_name)) { }
1023};
1024
1026struct M_EXPORT DSVImportStmt : ImportStmt
1027{
1028 Token path = Token::CreateArtificial();
1029 Token delimiter = Token::CreateArtificial();
1030 Token escape = Token::CreateArtificial();
1031 Token quote = Token::CreateArtificial();
1032 Token rows = Token::CreateArtificial();
1033 bool has_header = false;
1034 bool skip_header = false;
1035
1036 DSVImportStmt(Token table_name) : ImportStmt(std::move(table_name)) { }
1037
1038 void accept(ASTCommandVisitor &v) override;
1039 void accept(ConstASTCommandVisitor &v) const override;
1040};
1041
1042#define M_AST_COMMAND_LIST(X) \
1043 X(m::ast::Instruction) \
1044 X(m::ast::ErrorStmt) \
1045 X(m::ast::EmptyStmt) \
1046 X(m::ast::CreateDatabaseStmt) \
1047 X(m::ast::UseDatabaseStmt) \
1048 X(m::ast::DropDatabaseStmt) \
1049 X(m::ast::CreateTableStmt) \
1050 X(m::ast::DropTableStmt) \
1051 X(m::ast::CreateIndexStmt) \
1052 X(m::ast::DropIndexStmt) \
1053 X(m::ast::SelectStmt) \
1054 X(m::ast::InsertStmt) \
1055 X(m::ast::UpdateStmt) \
1056 X(m::ast::DeleteStmt) \
1057 X(m::ast::DSVImportStmt)
1058
1061
1062
1063#define M_AST_LIST(X) \
1064 M_AST_EXPR_LIST(X) \
1065 M_AST_CLAUSE_LIST(X) \
1066 M_AST_CONSTRAINT_LIST(X) \
1067 M_AST_COMMAND_LIST(X)
1068
1070{
1071 template<typename T> using Const = ASTExprVisitor::Const<T>; // resolve ambiguous name lookup
1072
1073 using ASTExprVisitor::operator();
1074 using ASTClauseVisitor::operator();
1075 using ASTConstraintVisitor::operator();
1076 using ASTCommandVisitor::operator();
1077};
1078
1080{
1081 template<typename T> using Const = ConstASTExprVisitor::Const<T>; // resolve ambiguous name lookup
1082
1083 using ConstASTExprVisitor::operator();
1084 using ConstASTClauseVisitor::operator();
1085 using ConstASTConstraintVisitor::operator();
1086 using ConstASTCommandVisitor::operator();
1087};
1088
1093
1098
1099}
1100
1101}
1102
1103namespace std {
1104
1106template<>
1107struct hash<m::ast::Expr>
1108{
1109 std::size_t operator()(const m::ast::Expr &e) const { return e.hash(); }
1110};
1111
1112}
#define M_AST_LIST(X)
Definition: AST.hpp:1063
#define M_AST_EXPR_LIST(X)
Definition: AST.hpp:427
#define M_AST_CONSTRAINT_LIST(X)
Definition: AST.hpp:735
#define M_AST_COMMAND_LIST(X)
Definition: AST.hpp:1042
#define M_AST_CLAUSE_LIST(X)
Definition: AST.hpp:642
#define M_DECLARE_VISITOR(VISITOR_NAME, BASE_CLASS, CLASS_LIST)
Defines a visitor VISITOR_NAME to visit the class hierarchy rooted in BASE_CLASS and with subclasses ...
Definition: Visitor.hpp:181
#define M_MAKE_STL_VISITABLE(VISITOR, BASE_CLASS, CLASS_LIST)
Defines a function visit() to make the class hierarchy STL-style visitable with VISITOR.
Definition: Visitor.hpp:166
and(sizeof(T)==4) U64x1 reinterpret_to_U64(m
Definition: WasmAlgo.cpp:266
struct @5 args
#define M_unreachable(MSG)
Definition: macro.hpp:146
#define M_notnull(ARG)
Definition: macro.hpp:182
#define M_insist(...)
Definition: macro.hpp:129
‍mutable namespace
Definition: Backend.hpp:10
std::string escape(char c)
Definition: fn.hpp:292
std::string quote(const std::string &str)
Definition: fn.hpp:306
const Type
Definition: Type.hpp:498
ThreadSafeStringPool::proxy_type ThreadSafePooledString
Definition: Pool.hpp:464
ThreadSafeStringPool::proxy_optional_type ThreadSafePooledOptionalString
Definition: Pool.hpp:465
STL namespace.
An attribute of a table.
Definition: Schema.hpp:289
Defines a function.
Definition: Schema.hpp:828
The numeric type represents integer and floating-point types of different precision and scale.
Definition: Type.hpp:393
A Schema represents a sequence of identifiers, optionally with a prefix, and their associated types.
Definition: Schema.hpp:39
A table is a sorted set of attributes.
Definition: Schema.hpp:388
This class represents types in the SQL type system.
Definition: Type.hpp:46
ASTExprVisitor::Const< T > Const
Definition: AST.hpp:1071
A binary expression.
Definition: AST.hpp:348
void accept(ASTExprVisitor &v) override
std::unique_ptr< Expr > lhs
Definition: AST.hpp:349
bool is_constant() const override
Returns true iff this Expr is constant, i.e.
Definition: AST.hpp:359
BinaryExpr(Token op, std::unique_ptr< Expr > lhs, std::unique_ptr< Expr > rhs)
Definition: AST.hpp:353
bool can_be_null() const override
Returns true iff this Expr is nullable, i.e.
Definition: AST.hpp:360
void accept(ConstASTExprVisitor &v) const override
bool contains_free_variables() const override
Returns true iff this Expr contains a free variable.
Definition: AST.hpp:373
bool contains_bound_variables() const override
Returns true iff this Expr contains a bound variable.
Definition: AST.hpp:375
std::unique_ptr< Expr > rhs
Definition: AST.hpp:350
Token op() const
Definition: AST.hpp:377
void accept(ASTConstraintVisitor &v) override
void accept(ConstASTConstraintVisitor &v) const override
std::unique_ptr< Expr > cond
Definition: AST.hpp:699
CheckConditionConstraint(Token tok, std::unique_ptr< Expr > cond)
Definition: AST.hpp:701
Token tok
Definition: AST.hpp:500
friend std::ostream &M_EXPORT operator<<(std::ostream &out, const Clause &c)
Clause(Token tok)
Definition: AST.hpp:502
virtual void accept(ASTClauseVisitor &v)=0
virtual ~Clause()
Definition: AST.hpp:503
virtual void accept(ConstASTClauseVisitor &v) const =0
virtual void accept(ASTCommandVisitor &v)=0
friend std::ostream &M_EXPORT operator<<(std::ostream &out, const Command &cmd)
virtual void accept(ConstASTCommandVisitor &v) const =0
virtual ~Command()=default
ConstASTExprVisitor::Const< T > Const
Definition: AST.hpp:1081
A constant: a string literal or a numeric constant.
Definition: AST.hpp:213
bool is_string() const
Definition: AST.hpp:233
bool is_bool() const
Definition: AST.hpp:229
bool contains_bound_variables() const override
Returns true iff this Expr contains a bound variable.
Definition: AST.hpp:219
Constant(Token tok)
Definition: AST.hpp:214
bool is_null() const
Definition: AST.hpp:228
bool contains_free_variables() const override
Returns true iff this Expr contains a free variable.
Definition: AST.hpp:218
bool is_number() const
Definition: AST.hpp:230
bool is_float() const
Definition: AST.hpp:232
void accept(ConstASTExprVisitor &v) const override
bool can_be_null() const override
Returns true iff this Expr is nullable, i.e.
Definition: AST.hpp:217
bool is_datetime() const
Definition: AST.hpp:235
bool is_integer() const
Definition: AST.hpp:231
void accept(ASTExprVisitor &v) override
bool is_date() const
Definition: AST.hpp:234
bool is_constant() const override
Returns true iff this Expr is constant, i.e.
Definition: AST.hpp:216
Abstract class to represent constraints attached to attributes of a table.
Definition: AST.hpp:662
Constraint(Token tok)
Definition: AST.hpp:665
virtual void accept(ASTConstraintVisitor &v)=0
virtual ~Constraint()
Definition: AST.hpp:667
virtual void accept(ConstASTConstraintVisitor &v) const =0
CreateDatabaseStmt(Token database_name)
Definition: AST.hpp:826
void accept(ConstASTCommandVisitor &v) const override
void accept(ASTCommandVisitor &v) override
void accept(ConstASTCommandVisitor &v) const override
CreateIndexStmt(Token has_unique, bool has_if_not_exists, Token index_name, Token table_name, Token method, std::vector< std::unique_ptr< Expr > > key_fields)
Definition: AST.hpp:906
std::vector< std::unique_ptr< Expr > > key_fields
Definition: AST.hpp:904
void accept(ASTCommandVisitor &v) override
attribute_definition(Token name, const Type *type, std::vector< std::unique_ptr< Constraint > > constraints)
Definition: AST.hpp:864
std::vector< std::unique_ptr< Constraint > > constraints
Definition: AST.hpp:862
std::vector< std::unique_ptr< attribute_definition > > attributes
Definition: AST.hpp:872
void accept(ASTCommandVisitor &v) override
CreateTableStmt(Token table_name, std::vector< std::unique_ptr< attribute_definition > > attributes)
Definition: AST.hpp:874
void accept(ConstASTCommandVisitor &v) const override
An import statement for a delimiter separated values (DSV) file.
Definition: AST.hpp:1027
void accept(ASTCommandVisitor &v) override
DSVImportStmt(Token table_name)
Definition: AST.hpp:1036
void accept(ConstASTCommandVisitor &v) const override
A SQL delete statement.
Definition: AST.hpp:1005
Token table_name
Definition: AST.hpp:1006
DeleteStmt(Token table_name, std::unique_ptr< Clause > where)
Definition: AST.hpp:1009
void accept(ConstASTCommandVisitor &v) const override
void accept(ASTCommandVisitor &v) override
A designator.
Definition: AST.hpp:134
Designator(Token dot, Token table_name, Token attr_name)
Definition: AST.hpp:152
ThreadSafePooledOptionalString unique_id_
a unique ID created for Designators in nested queries (for decorrelation)
Definition: AST.hpp:143
ThreadSafePooledString get_table_name() const
Definition: AST.hpp:197
bool contains_bound_variables() const override
Returns false iff this Designator is a free variable.
Definition: AST.hpp:181
void decrease_binding_depth()
Definition: AST.hpp:208
bool is_constant() const override
Returns true iff this Expr is constant, i.e.
Definition: AST.hpp:165
Designator(Token attr_name)
Definition: AST.hpp:146
void set_binding_depth(unsigned depth)
Marks this Designator as free variable, i.e.
Definition: AST.hpp:207
bool can_be_null() const override
Returns true iff this Expr is nullable, i.e.
Definition: AST.hpp:170
Token table_name
Definition: AST.hpp:138
bool contains_free_variables() const override
Returns true iff this Designator is a free variable.
Definition: AST.hpp:179
void accept(ConstASTExprVisitor &v) const override
unsigned binding_depth() const
Definition: AST.hpp:183
void accept(ASTExprVisitor &v) override
Token attr_name
Definition: AST.hpp:139
bool has_explicit_table_name() const
Definition: AST.hpp:192
bool is_identifier() const
Returns true iff this Designator has no table name, neither explicitly nor implicitly (by sema).
Definition: AST.hpp:194
std::variant< std::monostate, const Expr *, const Attribute * > target_type
Definition: AST.hpp:137
bool has_table_name() const
Definition: AST.hpp:196
Designator(Token dot, Token table_name, Token attr_name, const Type *type, target_type target)
Definition: AST.hpp:158
const target_type & target() const
Definition: AST.hpp:203
target_type target_
the target that is referenced by this designator
Definition: AST.hpp:141
void accept(ConstASTCommandVisitor &v) const override
DropDatabaseStmt(Token database_name, bool has_if_exists)
Definition: AST.hpp:837
void accept(ASTCommandVisitor &v) override
void accept(ASTCommandVisitor &v) override
DropIndexStmt(std::vector< std::unique_ptr< Token > > index_names, bool has_if_exists)
Definition: AST.hpp:925
void accept(ConstASTCommandVisitor &v) const override
std::vector< std::unique_ptr< Token > > index_names
Definition: AST.hpp:922
std::vector< std::unique_ptr< Token > > table_names
Definition: AST.hpp:885
DropTableStmt(std::vector< std::unique_ptr< Token > > table_names, bool has_if_exists)
Definition: AST.hpp:888
void accept(ASTCommandVisitor &v) override
void accept(ConstASTCommandVisitor &v) const override
void accept(ConstASTCommandVisitor &v) const override
EmptyStmt(Token tok)
Definition: AST.hpp:816
void accept(ASTCommandVisitor &v) override
void accept(ASTClauseVisitor &v) override
ErrorClause(Token tok)
Definition: AST.hpp:518
void accept(ConstASTClauseVisitor &v) const override
The error expression.
Definition: AST.hpp:116
bool is_constant() const override
Returns true iff this Expr is constant, i.e.
Definition: AST.hpp:119
uint64_t hash() const override
Computes a hash of this, considering only syntactic properties.
Definition: AST.hpp:124
bool contains_free_variables() const override
Returns true iff this Expr contains a free variable.
Definition: AST.hpp:121
bool contains_bound_variables() const override
Returns true iff this Expr contains a bound variable.
Definition: AST.hpp:122
void accept(ASTExprVisitor &v) override
void accept(ConstASTExprVisitor &v) const override
bool can_be_null() const override
Returns true iff this Expr is nullable, i.e.
Definition: AST.hpp:120
ErrorExpr(Token tok)
Definition: AST.hpp:117
The error statement.
Definition: AST.hpp:803
ErrorStmt(Token tok)
Definition: AST.hpp:806
void accept(ConstASTCommandVisitor &v) const override
void accept(ASTCommandVisitor &v) override
An expression.
Definition: AST.hpp:39
virtual bool contains_bound_variables() const =0
Returns true iff this Expr contains a bound variable.
virtual ~Expr()
Definition: AST.hpp:55
bool has_type() const
Returns true iff this Expr has been assigned a Type, most likely by Sema.
Definition: AST.hpp:63
const Type * type() const
Returns the Type of this Expr.
Definition: AST.hpp:58
virtual bool is_constant() const =0
Returns true iff this Expr is constant, i.e.
virtual bool contains_free_variables() const =0
Returns true iff this Expr contains a free variable.
bool operator!=(const Expr &other) const
Returns false iff other is syntactically equal to this.
Definition: AST.hpp:85
virtual uint64_t hash() const =0
Computes a hash of this, considering only syntactic properties.
M_LCOV_EXCL_START friend std::string to_string(const Expr &e)
Definition: AST.hpp:103
Expr(Token tok, const Type *type)
Definition: AST.hpp:54
Expr(Token tok)
Definition: AST.hpp:53
virtual void accept(ConstASTExprVisitor &v) const =0
Token tok
the token of the expression; serves as an anchor to locate the expression in the source
Definition: AST.hpp:43
virtual void accept(ASTExprVisitor &v)=0
virtual bool operator==(const Expr &other) const =0
Returns true iff other is syntactically equal to this.
void type(const Type *type)
Sets the Type of this Expr.
Definition: AST.hpp:61
friend std::ostream &M_EXPORT operator<<(std::ostream &out, const Expr &e)
virtual bool can_be_null() const =0
Returns true iff this Expr is nullable, i.e.
A function application.
Definition: AST.hpp:246
std::vector< std::unique_ptr< Expr > > args
Definition: AST.hpp:250
FnApplicationExpr(Token lpar, std::unique_ptr< Expr > fn, std::vector< std::unique_ptr< Expr > > args)
Definition: AST.hpp:255
bool is_constant() const override
Returns true iff this Expr is constant, i.e.
Definition: AST.hpp:265
const Function & get_function() const
Definition: AST.hpp:312
std::unique_ptr< Expr > fn
Definition: AST.hpp:249
bool contains_bound_variables() const override
Returns true iff this Expr contains a bound variable.
Definition: AST.hpp:299
bool has_function() const
Definition: AST.hpp:311
void accept(ConstASTExprVisitor &v) const override
void accept(ASTExprVisitor &v) override
bool contains_free_variables() const override
Returns true iff this Expr contains a free variable.
Definition: AST.hpp:291
bool can_be_null() const override
Returns true iff this Expr is nullable, i.e.
Definition: AST.hpp:266
std::variant< Token, Stmt * > source
Definition: AST.hpp:549
from_type(std::unique_ptr< Stmt > S, Token alias)
Definition: AST.hpp:557
const Table & table() const
Definition: AST.hpp:559
bool has_table() const
Definition: AST.hpp:560
from_type(Token name, Token alias)
Definition: AST.hpp:556
FromClause(Token tok, std::vector< from_type > from)
Definition: AST.hpp:565
void accept(ConstASTClauseVisitor &v) const override
void accept(ASTClauseVisitor &v) override
std::vector< from_type > from
Definition: AST.hpp:563
void accept(ASTClauseVisitor &v) override
GroupByClause(Token tok, std::vector< group_type > group_by)
‍a list of expressions to group by
Definition: AST.hpp:590
void accept(ConstASTClauseVisitor &v) const override
std::pair< std::unique_ptr< Expr >, Token > group_type
Definition: AST.hpp:587
std::vector< group_type > group_by
Definition: AST.hpp:588
HavingClause(Token tok, std::unique_ptr< Expr > having)
Definition: AST.hpp:603
std::unique_ptr< Expr > having
Definition: AST.hpp:601
void accept(ConstASTClauseVisitor &v) const override
void accept(ASTClauseVisitor &v) override
A SQL import statement.
Definition: AST.hpp:1020
Token table_name
Definition: AST.hpp:1021
ImportStmt(Token table_name)
Definition: AST.hpp:1022
A SQL insert statement.
Definition: AST.hpp:967
Token table_name
Definition: AST.hpp:972
InsertStmt(Token table_name, std::vector< tuple_t > tuples)
Definition: AST.hpp:975
std::vector< tuple_t > tuples
Definition: AST.hpp:973
void accept(ConstASTCommandVisitor &v) const override
void accept(ASTCommandVisitor &v) override
std::pair< kind_t, std::unique_ptr< Expr > > element_type
Definition: AST.hpp:969
std::vector< element_type > tuple_t
Definition: AST.hpp:970
void accept(ASTCommandVisitor &v) override
Token tok
‍the token of the Instruction; starts with \
Definition: AST.hpp:771
Instruction(Token tok, ThreadSafePooledString name, std::vector< std::string > args)
Definition: AST.hpp:777
ThreadSafePooledString name
‍the name of the Instruction (without leading \‍)
Definition: AST.hpp:773
std::vector< std::string > args
‍the arguments to the Instruction; may be empty
Definition: AST.hpp:775
void accept(ConstASTCommandVisitor &v) const override
void accept(ConstASTClauseVisitor &v) const override
LimitClause(Token tok, Token limit, Token offset)
Definition: AST.hpp:632
void accept(ASTClauseVisitor &v) override
NotNullConstraint(Token tok)
Definition: AST.hpp:691
void accept(ConstASTConstraintVisitor &v) const override
void accept(ASTConstraintVisitor &v) override
std::vector< order_type > order_by
‍true means ascending, false means descending
Definition: AST.hpp:616
void accept(ASTClauseVisitor &v) override
std::pair< std::unique_ptr< Expr >, bool > order_type
Definition: AST.hpp:614
OrderByClause(Token tok, std::vector< order_type > order_by)
Definition: AST.hpp:618
void accept(ConstASTClauseVisitor &v) const override
A postfix expression.
Definition: AST.hpp:240
PostfixExpr(Token tok)
Definition: AST.hpp:241
PrimaryKeyConstraint(Token tok)
Definition: AST.hpp:675
void accept(ASTConstraintVisitor &v) override
void accept(ConstASTConstraintVisitor &v) const override
A query expression for nested queries.
Definition: AST.hpp:389
QueryExpr(Token op, std::unique_ptr< Stmt > query)
Definition: AST.hpp:396
bool contains_bound_variables() const override
Conceptually, QueryExprs have no variables at all.
Definition: AST.hpp:412
bool contains_free_variables() const override
Conceptually, QueryExprs have no variables at all.
Definition: AST.hpp:408
std::unique_ptr< Stmt > query
Definition: AST.hpp:390
void accept(ASTExprVisitor &v) override
ThreadSafePooledString alias_
the alias that is used for this query expression
Definition: AST.hpp:393
const ThreadSafePooledString & alias() const
Definition: AST.hpp:421
void accept(ConstASTExprVisitor &v) const override
void accept(ConstASTConstraintVisitor &v) const override
ReferenceConstraint(Token tok, Token table_name, Token attr_name, OnDeleteAction action)
Definition: AST.hpp:724
OnDeleteAction on_delete
Definition: AST.hpp:722
void accept(ASTConstraintVisitor &v) override
void accept(ConstASTClauseVisitor &v) const override
SelectClause(Token tok, std::vector< select_type > select, Token select_all)
‍list of expressions expanded from SELECT *
Definition: AST.hpp:532
std::vector< select_type > select
‍list of selected elements; expr AS name
Definition: AST.hpp:528
void accept(ASTClauseVisitor &v) override
std::pair< std::unique_ptr< Expr >, Token > select_type
Definition: AST.hpp:526
std::vector< std::unique_ptr< Expr > > expanded_select_all
Definition: AST.hpp:530
A SQL select statement.
Definition: AST.hpp:936
std::unique_ptr< Clause > from
Definition: AST.hpp:938
std::unique_ptr< Clause > select
Definition: AST.hpp:937
void accept(ASTCommandVisitor &v) override
void accept(ConstASTCommandVisitor &v) const override
std::unique_ptr< Clause > where
Definition: AST.hpp:939
std::unique_ptr< Clause > order_by
Definition: AST.hpp:942
SelectStmt(std::unique_ptr< Clause > select, std::unique_ptr< Clause > from, std::unique_ptr< Clause > where, std::unique_ptr< Clause > group_by, std::unique_ptr< Clause > having, std::unique_ptr< Clause > order_by, std::unique_ptr< Clause > limit)
Definition: AST.hpp:945
std::unique_ptr< Clause > having
Definition: AST.hpp:941
std::unique_ptr< Clause > group_by
Definition: AST.hpp:940
std::unique_ptr< Clause > limit
Definition: AST.hpp:943
A SQL statement.
Definition: AST.hpp:794
virtual ~Stmt()
Definition: AST.hpp:795
std::conditional_t< C, ConstASTExprVisitor, ASTExprVisitor > super
Definition: AST.hpp:475
typename super::template Const< T > Const
Definition: AST.hpp:476
virtual ~ThePostOrderExprVisitor()
Definition: AST.hpp:478
typename super::template Const< T > Const
Definition: AST.hpp:465
std::conditional_t< C, ConstASTExprVisitor, ASTExprVisitor > super
Definition: AST.hpp:464
virtual ~ThePreOrderExprVisitor()
Definition: AST.hpp:467
A generic base class for implementing recursive ast::Expr visitors.
Definition: AST.hpp:442
typename super::template Const< T > Const
Definition: AST.hpp:444
void operator()(Const< UnaryExpr > &e) override
Definition: AST.hpp:454
void operator()(Const< FnApplicationExpr > &e) override
Definition: AST.hpp:449
std::conditional_t< C, ConstASTExprVisitor, ASTExprVisitor > super
Definition: AST.hpp:443
void operator()(Const< BinaryExpr > &e) override
Definition: AST.hpp:455
ThreadSafePooledOptionalString text
declared as optional for dummy tokens
Definition: Token.hpp:16
A unary expression: "+e", "-e", "~e", "NOT e".
Definition: AST.hpp:324
bool contains_free_variables() const override
Returns true iff this Expr contains a free variable.
Definition: AST.hpp:334
Token op() const
Definition: AST.hpp:336
bool can_be_null() const override
Returns true iff this Expr is nullable, i.e.
Definition: AST.hpp:333
void accept(ConstASTExprVisitor &v) const override
UnaryExpr(Token op, std::unique_ptr< Expr > expr)
Definition: AST.hpp:327
void accept(ASTExprVisitor &v) override
std::unique_ptr< Expr > expr
Definition: AST.hpp:325
bool is_constant() const override
Returns true iff this Expr is constant, i.e.
Definition: AST.hpp:332
bool contains_bound_variables() const override
Returns true iff this Expr contains a bound variable.
Definition: AST.hpp:335
UniqueConstraint(Token tok)
Definition: AST.hpp:683
void accept(ASTConstraintVisitor &v) override
void accept(ConstASTConstraintVisitor &v) const override
A SQL update statement.
Definition: AST.hpp:986
UpdateStmt(Token table_name, std::vector< set_type > set, std::unique_ptr< Clause > where)
Definition: AST.hpp:993
std::unique_ptr< Clause > where
Definition: AST.hpp:991
std::pair< Token, std::unique_ptr< Expr > > set_type
Definition: AST.hpp:987
void accept(ConstASTCommandVisitor &v) const override
Token table_name
Definition: AST.hpp:989
std::vector< set_type > set
Definition: AST.hpp:990
void accept(ASTCommandVisitor &v) override
void accept(ConstASTCommandVisitor &v) const override
UseDatabaseStmt(Token database_name)
Definition: AST.hpp:850
void accept(ASTCommandVisitor &v) override
WhereClause(Token tok, std::unique_ptr< Expr > where)
Definition: AST.hpp:576
void accept(ConstASTClauseVisitor &v) const override
std::unique_ptr< Expr > where
Definition: AST.hpp:574
void accept(ASTClauseVisitor &v) override
Signals a runtime error that mu*t*able is not responsible for and that mu*t*able was not able to reco...
Definition: exception.hpp:49
std::size_t operator()(const m::ast::Expr &e) const
Definition: AST.hpp:1109