1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
7 */
8
9#ifndef SQL_SYMBOL_H
10#define SQL_SYMBOL_H
11
12#include "sql_types.h"
13#include "sql_atom.h"
14#include "sql_tokens.h"
15
16typedef enum symtype {
17 type_int,
18 type_lng,
19 type_string,
20 type_list,
21 type_symbol,
22 type_type
23} symtype;
24
25typedef union symbdata {
26 int i_val;
27 lng l_val;
28 char *sval;
29 struct dlist *lval;
30 struct symbol *sym;
31 struct sql_subtype typeval;
32} symbdata;
33
34typedef struct dnode {
35 struct dnode *next;
36 symbdata data;
37 symtype type;
38} dnode;
39
40typedef struct dlist {
41 dnode *h;
42 dnode *t;
43 int cnt;
44} dlist;
45
46extern dlist *dlist_create(sql_allocator *sa);
47extern int dlist_length(dlist *l);
48
49extern dlist *dlist_append_string(sql_allocator *sa, dlist *l, const char *data);
50extern dlist *dlist_append_list(sql_allocator *sa, dlist *l, dlist *data);
51extern dlist *dlist_append_int(sql_allocator *sa, dlist *l, int data);
52extern dlist *dlist_append_lng(sql_allocator *sa, dlist *l, lng data);
53extern dlist *dlist_append_symbol(sql_allocator *sa, dlist *l, struct symbol *data);
54extern dlist *dlist_append_type(sql_allocator *sa, dlist *l, struct sql_subtype *data);
55
56typedef struct symbol {
57 tokens token;
58 symtype type;
59 symbdata data;
60} symbol;
61
62typedef struct SelectNode {
63 symbol s;
64
65 symbol *limit;
66 symbol *offset;
67 symbol *sample;
68 int distinct;
69 int lateral;
70 struct dlist *selection;
71 struct dlist *into; /* ?? */
72 symbol *from;
73 symbol *where;
74 symbol *groupby;
75 symbol *having;
76 symbol *orderby;
77 symbol *name;
78 symbol *window;
79} SelectNode;
80
81typedef struct AtomNode {
82 symbol s;
83 struct atom *a;
84} AtomNode;
85
86extern symbol *symbol_create(sql_allocator *sa, tokens token, char *data);
87extern symbol *symbol_create_list(sql_allocator *sa, tokens token, dlist *data);
88extern symbol *symbol_create_int(sql_allocator *sa, tokens token, int data);
89extern symbol *symbol_create_lng(sql_allocator *sa, tokens token, lng data);
90extern symbol *symbol_create_symbol(sql_allocator *sa, tokens token, symbol *data);
91
92extern symbol *newSelectNode(sql_allocator *sa, int distinct, struct dlist *selection, struct dlist *into, symbol *from, symbol *where, symbol *groupby, symbol *having, symbol *orderby, symbol *name, symbol *limit, symbol *offset, symbol *sample, symbol *window);
93
94extern symbol *newAtomNode(sql_allocator *sa, atom *a);
95
96#endif /* SQL_SYMBOL_H */
97
98