struct dataset *);
static struct compute_trns *compute_trns_create (void);
-static trns_proc_func *get_proc_func (const struct lvalue *);
-static trns_free_func compute_trns_free;
+static bool compute_trns_free (void *compute_);
+static const struct trns_class *get_trns_class (const struct lvalue *);
\f
/* COMPUTE. */
if (compute->rvalue == NULL)
goto fail;
- add_transformation (ds, get_proc_func (lvalue), compute_trns_free, compute);
+ add_transformation (ds, get_trns_class (lvalue), compute);
lvalue_finalize (lvalue, compute, dict);
/* Transformation functions. */
/* Handle COMPUTE or IF with numeric target variable. */
-static int
+static enum trns_result
compute_num (void *compute_, struct ccase **c, casenumber case_num)
{
struct compute_trns *compute = compute_;
/* Handle COMPUTE or IF with numeric vector element target
variable. */
-static int
+static enum trns_result
compute_num_vec (void *compute_, struct ccase **c, casenumber case_num)
{
struct compute_trns *compute = compute_;
index = expr_evaluate_num (compute->element, *c, case_num);
rindx = floor (index + EPSILON);
if (index == SYSMIS
- || rindx < 1 || rindx > vector_get_var_cnt (compute->vector))
+ || rindx < 1 || rindx > vector_get_n_vars (compute->vector))
{
if (index == SYSMIS)
msg (SW, _("When executing COMPUTE: SYSMIS is not a valid value "
}
/* Handle COMPUTE or IF with string target variable. */
-static int
+static enum trns_result
compute_str (void *compute_, struct ccase **c, casenumber case_num)
{
struct compute_trns *compute = compute_;
/* Handle COMPUTE or IF with string vector element target
variable. */
-static int
+static enum trns_result
compute_str_vec (void *compute_, struct ccase **c, casenumber case_num)
{
struct compute_trns *compute = compute_;
vector_get_name (compute->vector));
return TRNS_CONTINUE;
}
- else if (rindx < 1 || rindx > vector_get_var_cnt (compute->vector))
+ else if (rindx < 1 || rindx > vector_get_n_vars (compute->vector))
{
msg (SW, _("When executing COMPUTE: %.*g is not a valid value as "
"an index into vector %s."),
compute = compute_trns_create ();
/* Test expression. */
- compute->test = expr_parse_bool (lexer, NULL, ds);
+ compute->test = expr_parse_bool (lexer, ds);
if (compute->test == NULL)
goto fail;
if (compute->rvalue == NULL)
goto fail;
- add_transformation (ds, get_proc_func (lvalue), compute_trns_free, compute);
+ add_transformation (ds, get_trns_class (lvalue), compute);
lvalue_finalize (lvalue, compute, dict);
\f
/* Code common to COMPUTE and IF. */
-static trns_proc_func *
-get_proc_func (const struct lvalue *lvalue)
+static const struct trns_class *
+get_trns_class (const struct lvalue *lvalue)
{
+ static const struct trns_class classes[2][2] = {
+ [false][false] = {
+ .name = "COMPUTE",
+ .execute = compute_str,
+ .destroy = compute_trns_free
+ },
+ [false][true] = {
+ .name = "COMPUTE",
+ .execute = compute_str_vec,
+ .destroy = compute_trns_free
+ },
+ [true][false] = {
+ .name = "COMPUTE",
+ .execute = compute_num,
+ .destroy = compute_trns_free
+ },
+ [true][true] = {
+ .name = "COMPUTE",
+ .execute = compute_num_vec,
+ .destroy = compute_trns_free
+ },
+ };
+
bool is_numeric = lvalue_get_type (lvalue) == VAL_NUMERIC;
bool is_vector = lvalue_is_vector (lvalue);
-
- return (is_numeric
- ? (is_vector ? compute_num_vec : compute_num)
- : (is_vector ? compute_str_vec : compute_str));
+ return &classes[is_numeric][is_vector];
}
/* Parses and returns an rvalue expression of the same type as
const struct lvalue *lvalue, struct dataset *ds)
{
if (lvalue->is_new_variable)
- return expr_parse_new_variable (lexer, NULL, ds, var_get_name (lvalue->variable));
+ return expr_parse_new_variable (lexer, ds, var_get_name (lvalue->variable));
else
- return expr_parse (lexer, NULL, ds, lvalue_get_type (lvalue));
+ return expr_parse (lexer, ds, lvalue_get_type (lvalue));
}
/* Returns a new struct compute_trns after initializing its fields. */
lex_get (lexer);
if (!lex_force_match (lexer, T_LPAREN))
goto lossage;
- lvalue->element = expr_parse (lexer, NULL, ds, VAL_NUMERIC);
+ lvalue->element = expr_parse (lexer, ds, VAL_NUMERIC);
if (lvalue->element == NULL)
goto lossage;
if (!lex_force_match (lexer, T_RPAREN))