1/*-------------------------------------------------------------------------
2 *
3 * pgbench.h
4 *
5 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
6 * Portions Copyright (c) 1994, Regents of the University of California
7 *
8 *-------------------------------------------------------------------------
9 */
10
11#ifndef PGBENCH_H
12#define PGBENCH_H
13
14#include "fe_utils/psqlscan.h"
15
16/*
17 * This file is included outside exprscan.l, in places where we can't see
18 * flex's definition of typedef yyscan_t. Fortunately, it's documented as
19 * being "void *", so we can use a macro to keep the function declarations
20 * here looking like the definitions in exprscan.l. exprparse.y and
21 * pgbench.c also use this to be able to declare things as "yyscan_t".
22 */
23#define yyscan_t void *
24
25/*
26 * Likewise, we can't see exprparse.y's definition of union YYSTYPE here,
27 * but for now there's no need to know what the union contents are.
28 */
29union YYSTYPE;
30
31/*
32 * Variable types used in parser.
33 */
34typedef enum
35{
36 PGBT_NO_VALUE,
37 PGBT_NULL,
38 PGBT_INT,
39 PGBT_DOUBLE,
40 PGBT_BOOLEAN
41 /* add other types here */
42} PgBenchValueType;
43
44typedef struct
45{
46 PgBenchValueType type;
47 union
48 {
49 int64 ival;
50 double dval;
51 bool bval;
52 /* add other types here */
53 } u;
54} PgBenchValue;
55
56/* Types of expression nodes */
57typedef enum PgBenchExprType
58{
59 ENODE_CONSTANT,
60 ENODE_VARIABLE,
61 ENODE_FUNCTION
62} PgBenchExprType;
63
64/* List of operators and callable functions */
65typedef enum PgBenchFunction
66{
67 PGBENCH_ADD,
68 PGBENCH_SUB,
69 PGBENCH_MUL,
70 PGBENCH_DIV,
71 PGBENCH_MOD,
72 PGBENCH_DEBUG,
73 PGBENCH_ABS,
74 PGBENCH_LEAST,
75 PGBENCH_GREATEST,
76 PGBENCH_INT,
77 PGBENCH_DOUBLE,
78 PGBENCH_PI,
79 PGBENCH_SQRT,
80 PGBENCH_LN,
81 PGBENCH_EXP,
82 PGBENCH_RANDOM,
83 PGBENCH_RANDOM_GAUSSIAN,
84 PGBENCH_RANDOM_EXPONENTIAL,
85 PGBENCH_RANDOM_ZIPFIAN,
86 PGBENCH_POW,
87 PGBENCH_AND,
88 PGBENCH_OR,
89 PGBENCH_NOT,
90 PGBENCH_BITAND,
91 PGBENCH_BITOR,
92 PGBENCH_BITXOR,
93 PGBENCH_LSHIFT,
94 PGBENCH_RSHIFT,
95 PGBENCH_EQ,
96 PGBENCH_NE,
97 PGBENCH_LE,
98 PGBENCH_LT,
99 PGBENCH_IS,
100 PGBENCH_CASE,
101 PGBENCH_HASH_FNV1A,
102 PGBENCH_HASH_MURMUR2
103} PgBenchFunction;
104
105typedef struct PgBenchExpr PgBenchExpr;
106typedef struct PgBenchExprLink PgBenchExprLink;
107typedef struct PgBenchExprList PgBenchExprList;
108
109struct PgBenchExpr
110{
111 PgBenchExprType etype;
112 union
113 {
114 PgBenchValue constant;
115 struct
116 {
117 char *varname;
118 } variable;
119 struct
120 {
121 PgBenchFunction function;
122 PgBenchExprLink *args;
123 } function;
124 } u;
125};
126
127/* List of expression nodes */
128struct PgBenchExprLink
129{
130 PgBenchExpr *expr;
131 PgBenchExprLink *next;
132};
133
134struct PgBenchExprList
135{
136 PgBenchExprLink *head;
137 PgBenchExprLink *tail;
138};
139
140extern PgBenchExpr *expr_parse_result;
141
142extern int expr_yyparse(yyscan_t yyscanner);
143extern int expr_yylex(union YYSTYPE *lvalp, yyscan_t yyscanner);
144extern void expr_yyerror(yyscan_t yyscanner, const char *str) pg_attribute_noreturn();
145extern void expr_yyerror_more(yyscan_t yyscanner, const char *str,
146 const char *more) pg_attribute_noreturn();
147extern bool expr_lex_one_word(PsqlScanState state, PQExpBuffer word_buf,
148 int *offset);
149extern yyscan_t expr_scanner_init(PsqlScanState state,
150 const char *source, int lineno, int start_offset,
151 const char *command);
152extern void expr_scanner_finish(yyscan_t yyscanner);
153extern int expr_scanner_offset(PsqlScanState state);
154extern char *expr_scanner_get_substring(PsqlScanState state,
155 int start_offset, int end_offset,
156 bool chomp);
157extern int expr_scanner_get_lineno(PsqlScanState state, int offset);
158
159extern void syntax_error(const char *source, int lineno, const char *line,
160 const char *cmd, const char *msg,
161 const char *more, int col) pg_attribute_noreturn();
162
163extern bool strtoint64(const char *str, bool errorOK, int64 *pi);
164extern bool strtodouble(const char *str, bool errorOK, double *pd);
165
166#endif /* PGBENCH_H */
167