#include "debug-print.h"
-/* *INDENT-OFF* */
/* LOOP strategy:
Each loop causes 3 different transformations to be output. The
transformation to -1. This ensures that the pass number is set to
-1 every time the loop is encountered, before the first iteration.
- The second transformation increments the pass number. If there is
- no indexing or test clause on either LOOP or END LOOP, then the
- pass number is checked against MXLOOPS and control may pass out of
- the loop; otherwise the indexing or test clause(s) on LOOP are
- checked, and again control may pass out of the loop.
+ The second transformation increments the pass number. If
+ there is no indexing or test clause on either LOOP or END
+ LOOP, then the pass number is checked against MXLOOPS and
+ control may pass out of the loop. Otherwise the indexing or
+ test clause(s) on LOOP are checked, and again control may pass
+ out of the loop.
- After the second transformation the body of the loop is executed.
+ After the second transformation the body of the loop is
+ executed.
The last transformation checks the test clause if present and
- either jumps back up to the second transformation or terminates the
- loop.
-
- Flow of control: (The characters ^V<> represents arrows.)
-
- 1. LOOP (sets pass # to -1)
- V
- V
- >>2. LOOP (increment pass number)
- ^ (test optional indexing clause)
- ^ (test optional IF clause)
- ^ if we need another trip if we're done with the loop>>V
- ^ V V
- ^ V V
- ^ *. execute loop body V
- ^ . V
- ^ . (any number of transformations) V
- ^ . V
- ^ V
- ^ 3. END LOOP (test optional IF clause) V
- ^<<<<if we need another trip if we're done with the loop>>V
- V
- V
- *. transformations after loop body<<<<<<<<<<<<<<<<<<<<<<<<<<<
+ either jumps back up to the second transformation or
+ terminates the loop.
+ Flow of control:
+
+ 1. LOOP. Sets pass number to -1 and continues to next
+ transformation.
+
+ 2. LOOP. Increments pass number. Tests optional indexing
+ clause and optional IF clause. If we're done with the
+ loop, we jump to the transformation just after LOOP
+ transformation 3.
+
+ Otherwise, we continue through the transformations in the
+ loop body.
+
+ 3. END LOOP. We test the optional IF clause. If we need to
+ make another pass through the loop, we jump to LOOP
+ transformation 2.
+
+ Otherwise, we continue with the transformation jump after
+ the loop.
*/
-/* *INDENT-ON* */
/* Types of limits on loop execution. */
enum
static int internal_cmd_loop (void);
static int internal_cmd_end_loop (void);
-static int break_trns_proc (struct trns_header *, struct ccase *);
-static int loop_1_trns_proc (struct trns_header *, struct ccase *);
-static void loop_1_trns_free (struct trns_header *);
-static int loop_2_trns_proc (struct trns_header *, struct ccase *);
-static void loop_2_trns_free (struct trns_header *);
-static int loop_3_trns_proc (struct trns_header *, struct ccase *);
-static void loop_3_trns_free (struct trns_header *);
+static trns_proc_func break_trns_proc;
+static trns_proc_func loop_1_trns_proc, loop_2_trns_proc, loop_3_trns_proc;
+static trns_free_func loop_1_trns_free, loop_2_trns_free, loop_3_trns_free;
static void pop_ctl_stack (void);
\f
/* LOOP. */
/* Performs transformation 1. */
static int
-loop_1_trns_proc (struct trns_header * trns, struct ccase * c)
+loop_1_trns_proc (struct trns_header * trns, struct ccase * c,
+ int case_num)
{
struct loop_1_trns *one = (struct loop_1_trns *) trns;
struct loop_2_trns *two = one->two;
{
union value t1, t2, t3;
- expr_evaluate (one->init, c, &t1);
+ expr_evaluate (one->init, c, case_num, &t1);
if (one->incr)
- expr_evaluate (one->incr, c, &t2);
+ expr_evaluate (one->incr, c, case_num, &t2);
else
t2.f = 1.0;
- expr_evaluate (one->term, c, &t3);
+ expr_evaluate (one->term, c, case_num, &t3);
/* Even if the loop is never entered, force the index variable
to assume the initial value. */
/* Performs transformation 2. */
static int
-loop_2_trns_proc (struct trns_header * trns, struct ccase * c)
+loop_2_trns_proc (struct trns_header * trns, struct ccase * c,
+ int case_num UNUSED)
{
struct loop_2_trns *two = (struct loop_2_trns *) trns;
/* Conditional clause limiter. */
if ((two->flags & LPC_COND)
- && expr_evaluate (two->cond, c, NULL) != 1.0)
+ && expr_evaluate (two->cond, c, case_num, NULL) != 1.0)
return two->loop_term;
return -1;
/* Performs transformation 3. */
static int
-loop_3_trns_proc (struct trns_header * trns, struct ccase * c)
+loop_3_trns_proc (struct trns_header * trns, struct ccase * c,
+ int case_num)
{
struct loop_3_trns *thr = (struct loop_3_trns *) trns;
/* Note that it breaks out of the loop if the expression is true *or
missing*. This is conformant. */
- if (thr->cond && expr_evaluate (two->cond, c, NULL) != 0.0)
+ if (thr->cond && expr_evaluate (two->cond, c, case_num, NULL) != 0.0)
return -1;
return thr->loop_start;
}
static int
-break_trns_proc (struct trns_header * trns, struct ccase * c UNUSED)
+break_trns_proc (struct trns_header * trns, struct ccase * c UNUSED,
+ int case_num UNUSED)
{
return ((struct break_trns *) trns)->loop_term;
}