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_ATOM_H_
10#define _SQL_ATOM_H_
11
12#include "sql_mem.h"
13#include "sql_types.h"
14
15typedef struct atom {
16 int isnull;
17 sql_subtype tpe;
18 ValRecord data;
19 dbl d;
20 int varid;/* used during code generation only */
21} atom;
22
23#define atom_null(a) (((atom*)a)->isnull)
24
25extern void atom_init( atom *a );
26extern atom *atom_bool( sql_allocator *sa, sql_subtype *tpe, bit t);
27#ifdef HAVE_HGE
28extern atom *atom_int( sql_allocator *sa, sql_subtype *tpe, hge val);
29#else
30extern atom *atom_int( sql_allocator *sa, sql_subtype *tpe, lng val);
31#endif
32extern atom *atom_float( sql_allocator *sa, sql_subtype *tpe, double val);
33extern atom *atom_string( sql_allocator *sa, sql_subtype *tpe, const char *val);
34extern atom *atom_general( sql_allocator *sa, sql_subtype *tpe, const char *val);
35#ifdef HAVE_HGE
36extern atom *atom_dec( sql_allocator *sa, sql_subtype *tpe, hge val, double dval);
37#else
38extern atom *atom_dec( sql_allocator *sa, sql_subtype *tpe, lng val, double dval);
39#endif
40extern atom *atom_ptr( sql_allocator *sa, sql_subtype *tpe, void *v);
41
42extern int atom_neg( atom *a );
43extern unsigned int atom_num_digits( atom *a );
44
45/* duplicate atom */
46extern atom *atom_dup( sql_allocator *sa, atom *a);
47
48/* cast atom a to type tp (success == 1, fail == 0) */
49extern int atom_cast(sql_allocator *sa, atom *a, sql_subtype *tp);
50
51extern char *atom2string(sql_allocator *sa, atom *a);
52extern char *atom2sql(atom *a);
53extern sql_subtype *atom_type(atom *a);
54
55#ifdef HAVE_HGE
56extern hge atom_get_int(atom *a);
57#else
58extern lng atom_get_int(atom *a);
59#endif
60
61extern int atom_cmp(atom *a1, atom *a2);
62
63extern atom *atom_add(atom *a1, atom *a2);
64extern atom *atom_sub(atom *a1, atom *a2);
65extern atom *atom_mul(atom *a1, atom *a2);
66extern int atom_inc(atom *a);
67extern int atom_is_true(atom *a);
68extern int atom_is_zero(atom *a);
69
70#ifdef HAVE_HGE
71extern hge scales[39];
72#else
73extern lng scales[19];
74#endif
75
76extern atom* atom_zero_value(sql_allocator *sa, sql_subtype* tpe);
77
78#endif /* _SQL_ATOM_H_ */
79
80