struct expression *end_loop_condition;
/* Inner transformations. */
- struct transformation *xforms;
- size_t n_xforms;
+ struct trns_chain xforms;
};
-static trns_proc_func loop_trns_proc;
-static trns_free_func loop_trns_free;
+static struct trns_class loop_trns_class;
+
+static int in_loop;
static bool parse_if_clause (struct lexer *, struct dataset *,
struct expression **);
lex_end_of_command (lexer);
proc_push_transformations (ds);
+ in_loop++;
for (;;)
{
if (lex_token (lexer) == T_STOP)
else
cmd_parse_in_state (lexer, ds, CMD_STATE_NESTED);
}
- proc_pop_transformations (ds, &loop->xforms, &loop->n_xforms);
+ in_loop--;
+ proc_pop_transformations (ds, &loop->xforms);
+ printf ("%zu loop transvformations\n", loop->xforms.n);
- add_transformation (ds, loop_trns_proc, loop_trns_free, loop);
+ add_transformation (ds, &loop_trns_class, loop);
return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
}
+static enum trns_result
+break_trns_proc (void *aux UNUSED, struct ccase **c UNUSED,
+ casenumber case_num UNUSED)
+{
+ return TRNS_BREAK;
+}
+
/* Parses BREAK. */
int
-cmd_break (struct lexer *lexer UNUSED, struct dataset *ds UNUSED)
+cmd_break (struct lexer *lexer UNUSED, struct dataset *ds)
{
- //add_transformation (ds, break_trns_proc, NULL, NULL);
+ if (!in_loop)
+ {
+ msg (SE, _("BREAK cannot appear outside LOOP...END LOOP."));
+ return CMD_FAILURE;
+ }
+
+ static const struct trns_class trns_class = {
+ .name = "BREAK",
+ .execute = break_trns_proc
+ };
+ add_transformation (ds, &trns_class, NULL);
return CMD_SUCCESS;
}
else
cur = by = last = 0.0;
- int max_pass = loop->index_var ? settings_get_mxloops () : -1;
- for (int i = 0; max_pass < 0 || i < max_pass; i++)
+ for (int i = 0; loop->index_var || i < settings_get_mxloops (); i++)
{
+ printf ("loop %g %g %g\n", cur, by, last);
if (loop->loop_condition
&& expr_evaluate_num (loop->loop_condition, *c, case_num) != 1.0)
break;
- enum trns_result r = transformations_execute (
- loop->xforms, loop->n_xforms, c, case_num);
+ enum trns_result r = trns_chain_execute (&loop->xforms, case_num, c);
if (r != TRNS_CONTINUE)
return r == TRNS_BREAK ? TRNS_CONTINUE : r;
expr_free (loop->loop_condition);
expr_free (loop->end_loop_condition);
- transformations_destroy (loop->xforms, loop->n_xforms);
+ trns_chain_uninit (&loop->xforms);
free (loop);
return true;
}
+
+static struct trns_class loop_trns_class = {
+ .name = "LOOP",
+ .execute = loop_trns_proc,
+ .destroy = loop_trns_free,
+};