struct dataset *ds; /* The dataset */
struct clause *clauses; /* Clauses. */
size_t clause_cnt; /* Number of clauses. */
+ int DO_IF_index; /* DO IF transformation. */
int past_END_IF_index; /* Transformation just past last clause. */
};
+/* Jumps past the END IF. */
+struct end_if_trns
+ {
+ struct do_if_trns *do_if;
+ int index;
+ };
+
static const struct ctl_class do_if_class;
static int parse_clause (struct lexer *, struct do_if_trns *, struct dataset *ds);
static bool must_not_have_else (struct do_if_trns *);
static void close_do_if (void *do_if);
-static trns_proc_func do_if_trns_proc, break_trns_proc;
-static trns_free_func do_if_trns_free;
+static trns_proc_func do_if_trns_proc, end_if_trns_proc;
+static trns_free_func do_if_trns_free, end_if_trns_free;
/* Parse DO IF. */
int
do_if->clauses = NULL;
do_if->clause_cnt = 0;
do_if->ds = ds;
+ do_if->DO_IF_index = next_transformation (ds);
ctl_stack_push (&do_if_class, do_if);
add_transformation (ds, do_if_trns_proc, do_if_trns_free, do_if);
struct clause *clause;
if (do_if->clause_cnt > 0)
- add_transformation (do_if->ds, break_trns_proc, NULL, do_if);
+ {
+ struct end_if_trns *end_if;
+
+ end_if = xmalloc (sizeof *end_if);
+ end_if->do_if = do_if;
+ end_if->index = next_transformation (do_if->ds);
+ add_transformation (do_if->ds,
+ end_if_trns_proc, end_if_trns_free, end_if);
+ }
do_if->clauses = xnrealloc (do_if->clauses,
do_if->clause_cnt + 1, sizeof *do_if->clauses);
{
double boolean = expr_evaluate_num (clause->condition, *c, case_num);
if (boolean == 1.0)
- return clause->target_index;
+ return clause->target_index - do_if->DO_IF_index;
else if (boolean == SYSMIS)
- return do_if->past_END_IF_index;
+ return do_if->past_END_IF_index - do_if->DO_IF_index;
}
else
- return clause->target_index;
+ return clause->target_index - do_if->DO_IF_index;
}
return do_if->past_END_IF_index;
}
/* Breaks out of a DO IF construct. */
static int
-break_trns_proc (void *do_if_, struct ccase **c UNUSED,
+end_if_trns_proc (void *end_if_, struct ccase **c UNUSED,
casenumber case_num UNUSED)
{
- struct do_if_trns *do_if = do_if_;
+ struct end_if_trns *end_if = end_if_;
- return do_if->past_END_IF_index;
+ return end_if->do_if->past_END_IF_index - end_if->index;
}
+/* Frees an END IF transformation. */
+static bool
+end_if_trns_free (void *end_if_)
+{
+ struct end_if_trns *end_if = end_if_;
+
+ free (end_if);
+ return true;
+}
/* DO IF control structure class definition. */
static const struct ctl_class do_if_class =
{