1 /*-------------------------------------------------------------------------
2  *
3  * pgbench.h
4  *
5  * Portions Copyright (c) 1996-2017, 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  */
29 union YYSTYPE;
30 
31 /*
32  * Variable types used in parser.
33  */
34 typedef enum
35 {
36 	PGBT_INT,
37 	PGBT_DOUBLE
38 	/* add other types here */
39 } PgBenchValueType;
40 
41 typedef struct
42 {
43 	PgBenchValueType type;
44 	union
45 	{
46 		int64		ival;
47 		double		dval;
48 		/* add other types here */
49 	}			u;
50 } PgBenchValue;
51 
52 /* Types of expression nodes */
53 typedef enum PgBenchExprType
54 {
55 	ENODE_CONSTANT,
56 	ENODE_VARIABLE,
57 	ENODE_FUNCTION
58 } PgBenchExprType;
59 
60 /* List of operators and callable functions */
61 typedef enum PgBenchFunction
62 {
63 	PGBENCH_ADD,
64 	PGBENCH_SUB,
65 	PGBENCH_MUL,
66 	PGBENCH_DIV,
67 	PGBENCH_MOD,
68 	PGBENCH_DEBUG,
69 	PGBENCH_ABS,
70 	PGBENCH_LEAST,
71 	PGBENCH_GREATEST,
72 	PGBENCH_INT,
73 	PGBENCH_DOUBLE,
74 	PGBENCH_PI,
75 	PGBENCH_SQRT,
76 	PGBENCH_RANDOM,
77 	PGBENCH_RANDOM_GAUSSIAN,
78 	PGBENCH_RANDOM_EXPONENTIAL
79 } PgBenchFunction;
80 
81 typedef struct PgBenchExpr PgBenchExpr;
82 typedef struct PgBenchExprLink PgBenchExprLink;
83 typedef struct PgBenchExprList PgBenchExprList;
84 
85 struct PgBenchExpr
86 {
87 	PgBenchExprType etype;
88 	union
89 	{
90 		PgBenchValue constant;
91 		struct
92 		{
93 			char	   *varname;
94 		}			variable;
95 		struct
96 		{
97 			PgBenchFunction function;
98 			PgBenchExprLink *args;
99 		}			function;
100 	}			u;
101 };
102 
103 /* List of expression nodes */
104 struct PgBenchExprLink
105 {
106 	PgBenchExpr *expr;
107 	PgBenchExprLink *next;
108 };
109 
110 struct PgBenchExprList
111 {
112 	PgBenchExprLink *head;
113 	PgBenchExprLink *tail;
114 };
115 
116 extern PgBenchExpr *expr_parse_result;
117 
118 extern int	expr_yyparse(yyscan_t yyscanner);
119 extern int	expr_yylex(union YYSTYPE *lvalp, yyscan_t yyscanner);
120 extern void expr_yyerror(yyscan_t yyscanner, const char *str) pg_attribute_noreturn();
121 extern void expr_yyerror_more(yyscan_t yyscanner, const char *str,
122 				  const char *more) pg_attribute_noreturn();
123 extern bool expr_lex_one_word(PsqlScanState state, PQExpBuffer word_buf,
124 				  int *offset);
125 extern yyscan_t expr_scanner_init(PsqlScanState state,
126 				  const char *source, int lineno, int start_offset,
127 				  const char *command);
128 extern void expr_scanner_finish(yyscan_t yyscanner);
129 extern int	expr_scanner_offset(PsqlScanState state);
130 extern char *expr_scanner_get_substring(PsqlScanState state,
131 						   int start_offset, int end_offset);
132 extern int	expr_scanner_get_lineno(PsqlScanState state, int offset);
133 
134 extern void syntax_error(const char *source, int lineno, const char *line,
135 			 const char *cmd, const char *msg,
136 			 const char *more, int col) pg_attribute_noreturn();
137 
138 extern int64 strtoint64(const char *str);
139 
140 #endif							/* PGBENCH_H */
141