From e32e05bf60402d3229e45adcc9b4c8d5bb27d174 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 6 Mar 2005 19:06:30 +0000 Subject: [PATCH] Add another expression test and fix the bugs it found. --- po/en_GB.po | 40 +++++------ po/pspp.pot | 40 +++++------ src/expressions/.cvsignore | 7 ++ src/expressions/ChangeLog | 10 +++ src/expressions/operations.def | 5 ++ src/expressions/parse.c | 27 +++++--- tests/ChangeLog | 6 ++ tests/Makefile.am | 3 +- tests/expr.stat | 65 ----------------- tests/expressions/variables.sh | 123 +++++++++++++++++++++++++++++++++ 10 files changed, 210 insertions(+), 116 deletions(-) create mode 100644 src/expressions/.cvsignore delete mode 100644 tests/expr.stat create mode 100755 tests/expressions/variables.sh diff --git a/po/en_GB.po b/po/en_GB.po index 22d8fc65..33a1565b 100644 --- a/po/en_GB.po +++ b/po/en_GB.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PSPP 0.3.1\n" "Report-Msgid-Bugs-To: pspp-dev@gnu.org\n" -"POT-Creation-Date: 2005-03-03 06:08+0800\n" +"POT-Creation-Date: 2005-03-06 10:44-0800\n" "PO-Revision-Date: 2004-01-23 13:04+0800\n" "Last-Translator: John Darrington \n" "Language-Team: John Darrington \n" @@ -1210,25 +1210,6 @@ msgstr "" msgid "installation error" msgstr "" -#: src/filename.c:221 -#, c-format -msgid "Searching for `%s'..." -msgstr "" - -#: src/filename.c:229 src/filename.c:261 -msgid "Search unsuccessful!" -msgstr "" - -#: src/filename.c:254 -#, c-format -msgid "Found `%s'." -msgstr "" - -#: src/filename.c:686 -#, c-format -msgid "Not opening pipe file `%s' because SAFER option set." -msgstr "" - #: src/file-type.c:129 msgid "MIXED, GROUPED, or NESTED expected." msgstr "" @@ -1367,6 +1348,25 @@ msgstr "" msgid "Unknown record type %g." msgstr "" +#: src/filename.c:221 +#, c-format +msgid "Searching for `%s'..." +msgstr "" + +#: src/filename.c:229 src/filename.c:261 +msgid "Search unsuccessful!" +msgstr "" + +#: src/filename.c:254 +#, c-format +msgid "Found `%s'." +msgstr "" + +#: src/filename.c:686 +#, c-format +msgid "Not opening pipe file `%s' because SAFER option set." +msgstr "" + #: src/flip.c:81 msgid "" "FLIP ignores TEMPORARY. Temporary transformations will be made permanent." diff --git a/po/pspp.pot b/po/pspp.pot index 01591298..b4fd86b7 100644 --- a/po/pspp.pot +++ b/po/pspp.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: pspp-dev@gnu.org\n" -"POT-Creation-Date: 2005-03-03 06:08+0800\n" +"POT-Creation-Date: 2005-03-06 10:44-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1211,25 +1211,6 @@ msgstr "" msgid "installation error" msgstr "" -#: src/filename.c:221 -#, c-format -msgid "Searching for `%s'..." -msgstr "" - -#: src/filename.c:229 src/filename.c:261 -msgid "Search unsuccessful!" -msgstr "" - -#: src/filename.c:254 -#, c-format -msgid "Found `%s'." -msgstr "" - -#: src/filename.c:686 -#, c-format -msgid "Not opening pipe file `%s' because SAFER option set." -msgstr "" - #: src/file-type.c:129 msgid "MIXED, GROUPED, or NESTED expected." msgstr "" @@ -1368,6 +1349,25 @@ msgstr "" msgid "Unknown record type %g." msgstr "" +#: src/filename.c:221 +#, c-format +msgid "Searching for `%s'..." +msgstr "" + +#: src/filename.c:229 src/filename.c:261 +msgid "Search unsuccessful!" +msgstr "" + +#: src/filename.c:254 +#, c-format +msgid "Found `%s'." +msgstr "" + +#: src/filename.c:686 +#, c-format +msgid "Not opening pipe file `%s' because SAFER option set." +msgstr "" + #: src/flip.c:81 msgid "" "FLIP ignores TEMPORARY. Temporary transformations will be made permanent." diff --git a/src/expressions/.cvsignore b/src/expressions/.cvsignore new file mode 100644 index 00000000..d84d1242 --- /dev/null +++ b/src/expressions/.cvsignore @@ -0,0 +1,7 @@ +Makefile +Makefile.in +evaluate.h +evaluate.inc +operations.h +optimize.inc +parse.inc diff --git a/src/expressions/ChangeLog b/src/expressions/ChangeLog index e069ee8e..73c619ca 100644 --- a/src/expressions/ChangeLog +++ b/src/expressions/ChangeLog @@ -1,3 +1,13 @@ +Sun Mar 6 10:47:13 2005 Ben Pfaff + + * operations.def: Add VALUE function. + + * parse.c: (parse_function) Need an unary composite node for + variables in A TO B, not a variable node. Use + allocate_unary_variable(). + (parse_primary) Use allocate_unary_variable(). + (allocate_unary_variable) New function. + Thu Mar 3 23:53:32 2005 Ben Pfaff * PSPP_expressions.pm: Renamed it back to generate.pl but fixed diff --git a/src/expressions/operations.def b/src/expressions/operations.def index 021e188d..8338e18f 100644 --- a/src/expressions/operations.def +++ b/src/expressions/operations.def @@ -878,6 +878,11 @@ no_opt boolean function SYSMIS (num_var v) { return case_num (c, v->fv) == SYSMIS; } +no_opt boolean function VALUE (num_var v) + case c; +{ + return case_num (c, v->fv); +} no_opt operator VEC_ELEM_NUM (idx) vector v; diff --git a/src/expressions/parse.c b/src/expressions/parse.c index ea3b06a5..b1998f63 100644 --- a/src/expressions/parse.c +++ b/src/expressions/parse.c @@ -56,6 +56,8 @@ static struct expression *finish_expression (union any_node *, struct expression *); static bool type_check (struct expression *, union any_node **, enum expr_type expected_type); +static union any_node *allocate_unary_variable (struct expression *, + struct variable *); /* Public functions. */ @@ -402,7 +404,7 @@ type_coercion (struct expression *e, atom_type required_type, union any_node **node, const char *operator_name) { - return type_coercion_core (e, required_type, node, operator_name, 1); + return type_coercion_core (e, required_type, node, operator_name, true); } /* Coerces *NODE to type REQUIRED_TYPE. @@ -411,7 +413,7 @@ static void type_coercion_assert (struct expression *e, atom_type required_type, union any_node **node) { - int success = type_coercion_core (e, required_type, node, NULL, 1); + int success = type_coercion_core (e, required_type, node, NULL, true); assert (success); } @@ -421,7 +423,7 @@ static bool is_coercible (atom_type required_type, union any_node *const *node) { return type_coercion_core (NULL, required_type, - (union any_node **) node, NULL, 0); + (union any_node **) node, NULL, false); } /* How to parse an operator. */ @@ -783,12 +785,7 @@ parse_primary (struct expression *e) /* It looks like a user variable. (It could be a format specifier, but we'll assume it's a variable unless proven otherwise. */ - struct variable *v = parse_dict_variable (e->dict); - assert (v != NULL); - return expr_allocate_unary (e, - (v->type == NUMERIC - ? OP_NUM_VAR : OP_STR_VAR), - expr_allocate_variable (e, v)); + return allocate_unary_variable (e, parse_dict_variable (e->dict)); } else { @@ -1159,7 +1156,7 @@ parse_function (struct expression *e) goto fail; for (i = 0; i < var_cnt; i++) add_arg (&args, &arg_cnt, &arg_cap, - expr_allocate_variable (e, vars[i])); + allocate_unary_variable (e, vars[i])); free (vars); } else @@ -1422,3 +1419,13 @@ expr_allocate_format (struct expression *e, const struct fmt_spec *format) n->format.f = *format; return n; } + +/* Allocates a unary composite node that represents the value of + variable V in expression E. */ +static union any_node * +allocate_unary_variable (struct expression *e, struct variable *v) +{ + assert (v != NULL); + return expr_allocate_unary (e, v->type == NUMERIC ? OP_NUM_VAR : OP_STR_VAR, + expr_allocate_variable (e, v)); +} diff --git a/tests/ChangeLog b/tests/ChangeLog index b5a94bc8..bf2e3462 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +Sun Mar 6 11:03:58 2005 Ben Pfaff + + * Makefile.am: Add expressions/variables.sh. Remove expr.stat. + + * expr.stat: Removed. + 'Mon Feb 28 23:31:16 2005 Ben Pfaff * Makefile.am: Removed xforms/expressions.sh. Added diff --git a/tests/Makefile.am b/tests/Makefile.am index 3a714cfe..5ee230c3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -80,7 +80,8 @@ TESTS = \ stats/percentiles-enhanced.sh \ expressions/expressions.sh \ expressions/epoch.sh \ - expressions/randist.sh + expressions/randist.sh \ + expressions/variables.sh noinst_PROGRAMS = gengarbage diff --git a/tests/expr.stat b/tests/expr.stat deleted file mode 100644 index 0b9a4dab..00000000 --- a/tests/expr.stat +++ /dev/null @@ -1,65 +0,0 @@ -title 'Test optimization of constant expressions'. - -remark EOF ----------------------------------------------------------------------- -Testing ability of stat to optimize constant expressions. -stat must have been compiled with debugging enabled in order to -run these tests. ----------------------------------------------------------------------- -EOF -eval 1+2+3+(4*5). -eval (4-2+6.323)*(0/4-1)*(1-3+abs(-9.78)). -eval 3**(2**(8/2*3/4)). - -* Truth tables. -eval 0 and 0. -eval 0 and 1. -eval 1 and 0. -eval 1 and 1. - -eval 0 or 0. -eval 0 or 1. -eval 1 or 0. -eval 1 or 1. - -eval not 0. -eval not 1. - -eval (1 gt 2) and (2 gt 1). -eval (7/8+1 lt 2) or (2-1/6 lt 1). -eval not (7 ne 6). - -eval -(7/8). -eval abs(-6.5). -eval arcos(1.0). -eval arcos(sqrt(2)/2). -eval arsin(sqrt(2)/2). -eval artan(0). -eval artan(1.0). -eval cos(3.141592654/4). -eval cos(3.141592654/6). -eval exp(1). -eval exp(-1). -eval lg10(10). -eval lg10(128.910). -eval ln(2.71828182846). -eval ln(50). -eval mod10(128.910). -eval rnd(128.9). -eval rnd(-128.9). -eval rnd(128.1). -eval rnd(-128.1). -eval rnd(128). -eval rnd(-128). -eval rnd(128.5). -eval rnd(-128.5). -eval sin(2*3.141592654). -eval sin(3.141592654/6). -eval tan(0). -eval tan(3.141592654/8). -eval trunc(3.141592654). -eval trunc(-9.99). - -eval 'x'. -eval concat('x','y'). - diff --git a/tests/expressions/variables.sh b/tests/expressions/variables.sh new file mode 100755 index 00000000..9f325c7c --- /dev/null +++ b/tests/expressions/variables.sh @@ -0,0 +1,123 @@ +#!/bin/sh + +# This program tests use of variables in expressions. + +TEMPDIR=/tmp/pspp-tst-$$ + +here=`pwd`; + +# ensure that top_srcdir is absolute +cd $top_srcdir; top_srcdir=`pwd` + +export STAT_CONFIG_PATH=$top_srcdir/config + + +cleanup() +{ + rm -rf $TEMPDIR +} + + +fail() +{ + echo $activity + echo FAILED + cleanup; + exit 1; +} + + +no_result() +{ + echo $activity + echo NO RESULT; + cleanup; + exit 2; +} + +pass() +{ + cleanup; + exit 0; +} + +mkdir -p $TEMPDIR + +cd $TEMPDIR + +activity="create program" +cat > $TEMPDIR/variables.stat < $TEMPDIR/variables.err 2> $TEMPDIR/variables.out +if [ $? -ne 0 ] ; then fail ; fi + +activity="compare results" +diff -b -B $TEMPDIR/pspp.list - <