1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 #ifndef EXPRESSIONS_PRIVATE_H
20 #define EXPRESSIONS_PRIVATE_H
24 #include <data/format.h>
25 #include <libpspp/str.h>
28 #include "operations.h"
32 /* Most operations produce a missing output value if any
33 input value is missing. Setting this bit indicates that
34 this operation may produce a non-missing result given
35 missing input values (although it is not obliged to do
36 so). Unless this bit is set, the operation's evaluation
37 function will never be passed a missing argument. */
38 OPF_ABSORB_MISS = 004,
40 /* If set, this operation's final operand is an array of one
42 OPF_ARRAY_OPERAND = 001,
44 /* If set, the user can specify the minimum number of array
45 elements that must be non-missing for the function result
46 to be non-missing. The operation must have an array
47 operand and the array must contain `double's. Both
48 OPF_ABSORB_MISS and OPF_ARRAY_OPERAND must also be set. */
51 /* If set, operation is non-optimizable in general. Unless
52 combined with OPF_ABSORB_MISS, missing input values are
53 still assumed to yield missing results. */
54 OPF_NONOPTIMIZABLE = 010,
56 /* If set, this operation is not implemented. */
57 OPF_UNIMPLEMENTED = 020,
59 /* If set, this operation is a PSPP extension. */
62 /* If set, this operation may not occur after TEMPORARY.
63 (Currently this applies only to LAG.) */
66 /* If set, this operation's name may not be abbreviated. */
70 #define EXPR_ARG_MAX 4
74 const char *prototype;
75 enum operation_flags flags;
78 atom_type args[EXPR_ARG_MAX];
80 int array_granularity;
83 extern const struct operation operations[];
85 /* Tree structured expressions. */
90 operation_type type; /* OP_number. */
96 operation_type type; /* OP_string. */
102 operation_type type; /* OP_variable. */
108 operation_type type; /* OP_integer. */
114 operation_type type; /* OP_vector. */
115 const struct vector *v;
120 operation_type type; /* OP_format. */
124 /* Any composite node. */
125 struct composite_node
127 operation_type type; /* One of OP_*. */
128 size_t arg_cnt; /* Number of arguments. */
129 union any_node **args; /* Arguments. */
130 size_t min_valid; /* Min valid array args to get valid result. */
137 struct number_node number;
138 struct string_node string;
139 struct variable_node variable;
140 struct integer_node integer;
141 struct vector_node vector;
142 struct format_node format;
143 struct composite_node composite;
148 operation_type operation;
150 struct substring string;
151 struct variable *variable;
152 const struct vector *vector;
153 struct fmt_spec *format;
160 struct pool *expr_pool; /* Pool for expression static data. */
161 struct dataset *ds ; /* The dataset */
162 atom_type type; /* Type of expression result. */
164 union operation_data *ops; /* Expression data. */
165 operation_type *op_types; /* ops[] element types (for debugging). */
166 size_t op_cnt, op_cap; /* Number of ops, amount of allocated space. */
168 double *number_stack; /* Evaluation stack: numerics, Booleans. */
169 struct substring *string_stack; /* Evaluation stack: strings. */
170 struct pool *eval_pool; /* Pool for evaluation temporaries. */
173 struct expression *expr_parse_any (struct lexer *lexer, struct dataset *, bool optimize);
174 void expr_debug_print_postfix (const struct expression *);
176 union any_node *expr_optimize (union any_node *, struct expression *);
177 void expr_flatten (union any_node *, struct expression *);
179 atom_type expr_node_returns (const union any_node *);
181 union any_node *expr_allocate_nullary (struct expression *e, operation_type);
182 union any_node *expr_allocate_unary (struct expression *e,
183 operation_type, union any_node *);
184 union any_node *expr_allocate_binary (struct expression *e, operation_type,
185 union any_node *, union any_node *);
186 union any_node *expr_allocate_composite (struct expression *e, operation_type,
187 union any_node **, size_t);
188 union any_node *expr_allocate_number (struct expression *e, double);
189 union any_node *expr_allocate_boolean (struct expression *e, double);
190 union any_node *expr_allocate_integer (struct expression *e, int);
191 union any_node *expr_allocate_pos_int (struct expression *e, int);
192 union any_node *expr_allocate_string_buffer (struct expression *e,
193 const char *string, size_t length);
194 union any_node *expr_allocate_string (struct expression *e,
196 union any_node *expr_allocate_variable (struct expression *e,
198 union any_node *expr_allocate_format (struct expression *e,
199 const struct fmt_spec *);
200 union any_node *expr_allocate_vector (struct expression *e,
201 const struct vector *);
203 #endif /* expressions/private.h */