[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[q2c 04/12] LOOP: Correctly implement MXLOOPS and add a test.
From: |
Ben Pfaff |
Subject: |
[q2c 04/12] LOOP: Correctly implement MXLOOPS and add a test. |
Date: |
Sat, 5 Nov 2011 20:11:26 -0700 |
Previously the MXLOOPS value was implemented incorrectly: the
loop would actually iterate MXLOOPS+1 times. This commit fixes
the problem.
---
src/language/control/loop.c | 8 +-----
tests/language/control/loop.at | 43 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/src/language/control/loop.c b/src/language/control/loop.c
index e91d943..e4877b9 100644
--- a/src/language/control/loop.c
+++ b/src/language/control/loop.c
@@ -367,12 +367,8 @@ end_loop_trns_proc (void *loop_, struct ccase **c,
casenumber case_num UNUSED)
goto break_out;
/* MXLOOPS limiter. */
- if (loop->max_pass_count >= 0)
- {
- if (loop->pass >= loop->max_pass_count)
- goto break_out;
- loop->pass++;
- }
+ if (loop->max_pass_count >= 0 && ++loop->pass >= loop->max_pass_count)
+ goto break_out;
/* Indexing clause limiter: counting downward. */
if (loop->index_var != NULL)
diff --git a/tests/language/control/loop.at b/tests/language/control/loop.at
index af8d8ae..be214cc 100644
--- a/tests/language/control/loop.at
+++ b/tests/language/control/loop.at
@@ -208,10 +208,9 @@ AT_CHECK([cat pspp.csv], [0], [dnl
])
AT_CLEANUP
-AT_SETUP([LOOP with no conditions])
+AT_SETUP([LOOP with no conditions containing BREAK])
AT_DATA([loop.sps], [dnl
LOOP_DATA
-set mxloops = 2.
compute #p = x.
loop.
print /#p.
@@ -246,3 +245,43 @@ AT_CHECK([cat pspp.csv], [0], [dnl
--------
])
AT_CLEANUP
+
+AT_SETUP([LOOP with no conditions that ends due to MXLOOPS])
+AT_DATA([loop.sps], [dnl
+LOOP_DATA
+set mxloops=2.
+loop.
+compute #p = #p + 1.
+print /x #p.
+end loop.
+print/'--------'.
+execute.
+])
+AT_CHECK([pspp -o pspp.csv loop.sps])
+AT_CHECK([cat pspp.csv], [0], [dnl
+1 1.00 @&t@
+
+1 2.00 @&t@
+
+--------
+
+2 3.00 @&t@
+
+2 4.00 @&t@
+
+--------
+
+3 5.00 @&t@
+
+3 6.00 @&t@
+
+--------
+
+4 7.00 @&t@
+
+4 8.00 @&t@
+
+--------
+])
+AT_CLEANUP
+
--
1.7.2.5
- [q2c 00/12] Fix i18n problems in q2c-generated strings, Ben Pfaff, 2011/11/05
- [q2c 01/12] SET: Warn for more obsolete subcommands., Ben Pfaff, 2011/11/05
- [q2c 04/12] LOOP: Correctly implement MXLOOPS and add a test.,
Ben Pfaff <=
- [q2c 03/12] settings: Implement MXLOOPS subcommand., Ben Pfaff, 2011/11/05
- [q2c 09/12] lexer: New function lex_force_string_or_id()., Ben Pfaff, 2011/11/05
- [q2c 08/12] lexer: New functions lex_spec_missing(), lex_spec_only_once()., Ben Pfaff, 2011/11/05
- [q2c 07/12] lexer: Use error helper functions in more situations., Ben Pfaff, 2011/11/06
- [q2c 12/12] q2c: Remove gettext.h #include from generated code., Ben Pfaff, 2011/11/06
- [q2c 02/12] settings: Update default MXLOOPS and document., Ben Pfaff, 2011/11/06
- [q2c 06/12] lexer: Drop lexer parameter from lex_sbc_missing()., Ben Pfaff, 2011/11/06
- [q2c 11/12] q2c: Remove final untranslated strings from q2c.c., Ben Pfaff, 2011/11/06
- [q2c 10/12] q2c: Use new subc_list_error() to report too many subcommands., Ben Pfaff, 2011/11/06
- [q2c 05/12] lexer: New function lex_error_expecting()., Ben Pfaff, 2011/11/06