1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #ifndef EXPRESSIONS_PRIVATE_H
21 #define EXPRESSIONS_PRIVATE_H
25 #include <data/format.h>
26 #include <libpspp/str.h>
29 #include "operations.h"
33 /* Most operations produce a missing output value if any
34 input value is missing. Setting this bit indicates that
35 this operation may produce a non-missing result given
36 missing input values (although it is not obliged to do
37 so). Unless this bit is set, the operation's evaluation
38 function will never be passed a missing argument. */
39 OPF_ABSORB_MISS = 004,
41 /* If set, this operation's final operand is an array of one
43 OPF_ARRAY_OPERAND = 001,
45 /* If set, the user can specify the minimum number of array
46 elements that must be non-missing for the function result
47 to be non-missing. The operation must have an array
48 operand and the array must contain `double's. Both
49 OPF_ABSORB_MISS and OPF_ARRAY_OPERAND must also be set. */
52 /* If set, operation is non-optimizable in general. Unless
53 combined with OPF_ABSORB_MISS, missing input values are
54 still assumed to yield missing results. */
55 OPF_NONOPTIMIZABLE = 010,
57 /* If set, this operation is not implemented. */
58 OPF_UNIMPLEMENTED = 020,
60 /* If set, this operation is a PSPP extension. */
63 /* If set, this operation may not occur after TEMPORARY.
64 (Currently this applies only to LAG.) */
68 #define EXPR_ARG_MAX 4
72 const char *prototype;
73 enum operation_flags flags;
76 atom_type args[EXPR_ARG_MAX];
78 int array_granularity;
81 extern const struct operation operations[];
83 /* Tree structured expressions. */
88 operation_type type; /* OP_number. */
94 operation_type type; /* OP_string. */
100 operation_type type; /* OP_variable. */
106 operation_type type; /* OP_integer. */
112 operation_type type; /* OP_vector. */
113 const struct vector *v;
118 operation_type type; /* OP_format. */
122 /* Any composite node. */
123 struct composite_node
125 operation_type type; /* One of OP_*. */
126 size_t arg_cnt; /* Number of arguments. */
127 union any_node **args; /* Arguments. */
128 size_t min_valid; /* Min valid array args to get valid result. */
135 struct number_node number;
136 struct string_node string;
137 struct variable_node variable;
138 struct integer_node integer;
139 struct vector_node vector;
140 struct format_node format;
141 struct composite_node composite;
146 operation_type operation;
148 struct substring string;
149 struct variable *variable;
150 const struct vector *vector;
151 struct fmt_spec *format;
158 struct pool *expr_pool; /* Pool for expression static data. */
159 struct dataset *ds ; /* The dataset */
160 atom_type type; /* Type of expression result. */
162 union operation_data *ops; /* Expression data. */
163 operation_type *op_types; /* ops[] element types (for debugging). */
164 size_t op_cnt, op_cap; /* Number of ops, amount of allocated space. */
166 double *number_stack; /* Evaluation stack: numerics, Booleans. */
167 struct substring *string_stack; /* Evaluation stack: strings. */
168 struct pool *eval_pool; /* Pool for evaluation temporaries. */
171 struct expression *expr_parse_any (struct lexer *lexer, struct dataset *, bool optimize);
172 void expr_debug_print_postfix (const struct expression *);
174 union any_node *expr_optimize (union any_node *, struct expression *);
175 void expr_flatten (union any_node *, struct expression *);
177 atom_type expr_node_returns (const union any_node *);
179 union any_node *expr_allocate_nullary (struct expression *e, operation_type);
180 union any_node *expr_allocate_unary (struct expression *e,
181 operation_type, union any_node *);
182 union any_node *expr_allocate_binary (struct expression *e, operation_type,
183 union any_node *, union any_node *);
184 union any_node *expr_allocate_composite (struct expression *e, operation_type,
185 union any_node **, size_t);
186 union any_node *expr_allocate_number (struct expression *e, double);
187 union any_node *expr_allocate_boolean (struct expression *e, double);
188 union any_node *expr_allocate_integer (struct expression *e, int);
189 union any_node *expr_allocate_pos_int (struct expression *e, int);
190 union any_node *expr_allocate_string_buffer (struct expression *e,
191 const char *string, size_t length);
192 union any_node *expr_allocate_string (struct expression *e,
194 union any_node *expr_allocate_variable (struct expression *e,
196 union any_node *expr_allocate_format (struct expression *e,
197 const struct fmt_spec *);
198 union any_node *expr_allocate_vector (struct expression *e,
199 const struct vector *);
201 #endif /* expressions/private.h */