X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fxforms%2Fcompute.c;h=8e0ce85d61e08ddfe121ba3682eb95cfddea748a;hb=2c4b104df57f2e8b5ed2afa50819294aaac4aa6c;hp=82a1121fbf4b9452190dca43d7f3b4e65e3dd12e;hpb=9ade26c8349b4434008c46cf09bc7473ec743972;p=pspp diff --git a/src/language/xforms/compute.c b/src/language/xforms/compute.c index 82a1121fbf..8e0ce85d61 100644 --- a/src/language/xforms/compute.c +++ b/src/language/xforms/compute.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,12 +16,13 @@ #include +#include #include #include #include "data/case.h" +#include "data/dataset.h" #include "data/dictionary.h" -#include "data/procedure.h" #include "data/transformations.h" #include "data/variable.h" #include "data/vector.h" @@ -40,6 +41,18 @@ struct compute_trns; struct lvalue; +/* COMPUTE or IF target variable or vector element. + For a variable, the `variable' member is non-null. + For a vector element, the `vector' member is non-null. */ +struct lvalue + { + struct variable *variable; /* Destination variable. */ + bool is_new_variable; /* Did we create the variable? */ + + const struct vector *vector; /* Destination vector, if any, or NULL. */ + struct expression *element; /* Destination vector element, or NULL. */ + }; + /* Target of a COMPUTE or IF assignment, either a variable or a vector element. */ static struct lvalue *lvalue_parse (struct lexer *lexer, struct dataset *); @@ -120,7 +133,7 @@ compute_num (void *compute_, struct ccase **c, casenumber case_num) || expr_evaluate_num (compute->test, *c, case_num) == 1.0) { *c = case_unshare (*c); - case_data_rw (*c, compute->variable)->f + *case_num_rw (*c, compute->variable) = expr_evaluate_num (compute->rvalue, *c, case_num); } @@ -150,14 +163,14 @@ compute_num_vec (void *compute_, struct ccase **c, casenumber case_num) "as an index into vector %s."), vector_get_name (compute->vector)); else - msg (SW, _("When executing COMPUTE: %g is not a valid value as " + msg (SW, _("When executing COMPUTE: %.*g is not a valid value as " "an index into vector %s."), - index, vector_get_name (compute->vector)); + DBL_DIG + 1, index, vector_get_name (compute->vector)); return TRNS_CONTINUE; } *c = case_unshare (*c); - case_data_rw (*c, vector_get_var (compute->vector, rindx - 1))->f + *case_num_rw (*c, vector_get_var (compute->vector, rindx - 1)) = expr_evaluate_num (compute->rvalue, *c, case_num); } @@ -208,9 +221,9 @@ compute_str_vec (void *compute_, struct ccase **c, casenumber case_num) } else if (rindx < 1 || rindx > vector_get_var_cnt (compute->vector)) { - msg (SW, _("When executing COMPUTE: %g is not a valid value as " + msg (SW, _("When executing COMPUTE: %.*g is not a valid value as " "an index into vector %s."), - index, vector_get_name (compute->vector)); + DBL_DIG + 1, index, vector_get_name (compute->vector)); return TRNS_CONTINUE; } @@ -236,7 +249,7 @@ cmd_if (struct lexer *lexer, struct dataset *ds) compute = compute_trns_create (); /* Test expression. */ - compute->test = expr_parse (lexer, ds, EXPR_BOOLEAN); + compute->test = expr_parse_bool (lexer, NULL, ds); if (compute->test == NULL) goto fail; @@ -283,9 +296,10 @@ static struct expression * parse_rvalue (struct lexer *lexer, const struct lvalue *lvalue, struct dataset *ds) { - bool is_numeric = lvalue_get_type (lvalue) == VAL_NUMERIC; - - return expr_parse (lexer, ds, is_numeric ? EXPR_NUMBER : EXPR_STRING); + if (lvalue->is_new_variable) + return expr_parse_new_variable (lexer, NULL, ds, var_get_name (lvalue->variable)); + else + return expr_parse (lexer, NULL, ds, lvalue_get_type (lvalue)); } /* Returns a new struct compute_trns after initializing its fields. */ @@ -317,18 +331,6 @@ compute_trns_free (void *compute_) return true; } -/* COMPUTE or IF target variable or vector element. - For a variable, the `variable' member is non-null. - For a vector element, the `vector' member is non-null. */ -struct lvalue - { - struct variable *variable; /* Destination variable. */ - bool is_new_variable; /* Did we create the variable? */ - - const struct vector *vector; /* Destination vector, if any, or NULL. */ - struct expression *element; /* Destination vector element, or NULL. */ - }; - /* Parses the target variable or vector element into a new `struct lvalue', which is returned. */ static struct lvalue * @@ -360,7 +362,7 @@ lvalue_parse (struct lexer *lexer, struct dataset *ds) lex_get (lexer); if (!lex_force_match (lexer, T_LPAREN)) goto lossage; - lvalue->element = expr_parse (lexer, ds, EXPR_NUMBER); + lvalue->element = expr_parse (lexer, NULL, ds, VAL_NUMERIC); if (lvalue->element == NULL) goto lossage; if (!lex_force_match (lexer, T_RPAREN))