| 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 | |
| 16 | typedef enum symtype { |
| 17 | type_int, |
| 18 | type_lng, |
| 19 | type_string, |
| 20 | type_list, |
| 21 | type_symbol, |
| 22 | type_type |
| 23 | } symtype; |
| 24 | |
| 25 | typedef 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 | |
| 34 | typedef struct dnode { |
| 35 | struct dnode *next; |
| 36 | symbdata data; |
| 37 | symtype type; |
| 38 | } dnode; |
| 39 | |
| 40 | typedef struct dlist { |
| 41 | dnode *h; |
| 42 | dnode *t; |
| 43 | int cnt; |
| 44 | } dlist; |
| 45 | |
| 46 | extern dlist *dlist_create(sql_allocator *sa); |
| 47 | extern int dlist_length(dlist *l); |
| 48 | |
| 49 | extern dlist *dlist_append_string(sql_allocator *sa, dlist *l, const char *data); |
| 50 | extern dlist *dlist_append_list(sql_allocator *sa, dlist *l, dlist *data); |
| 51 | extern dlist *dlist_append_int(sql_allocator *sa, dlist *l, int data); |
| 52 | extern dlist *dlist_append_lng(sql_allocator *sa, dlist *l, lng data); |
| 53 | extern dlist *dlist_append_symbol(sql_allocator *sa, dlist *l, struct symbol *data); |
| 54 | extern dlist *dlist_append_type(sql_allocator *sa, dlist *l, struct sql_subtype *data); |
| 55 | |
| 56 | typedef struct symbol { |
| 57 | tokens token; |
| 58 | symtype type; |
| 59 | symbdata data; |
| 60 | } symbol; |
| 61 | |
| 62 | typedef 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 | |
| 81 | typedef struct AtomNode { |
| 82 | symbol s; |
| 83 | struct atom *a; |
| 84 | } AtomNode; |
| 85 | |
| 86 | extern symbol *symbol_create(sql_allocator *sa, tokens token, char *data); |
| 87 | extern symbol *symbol_create_list(sql_allocator *sa, tokens token, dlist *data); |
| 88 | extern symbol *symbol_create_int(sql_allocator *sa, tokens token, int data); |
| 89 | extern symbol *symbol_create_lng(sql_allocator *sa, tokens token, lng data); |
| 90 | extern symbol *symbol_create_symbol(sql_allocator *sa, tokens token, symbol *data); |
| 91 | |
| 92 | extern 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 | |
| 94 | extern symbol *newAtomNode(sql_allocator *sa, atom *a); |
| 95 | |
| 96 | #endif /* SQL_SYMBOL_H */ |
| 97 | |
| 98 | |