X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fexpressions%2Fevaluate.c;h=3ff879f2b29b9689628d81089da5477d117df878;hb=e070d7ddf78446b9852c61c9af84ad3659bac3b3;hp=ac36d18110d558f69e41b1985f65b0f4c8837184;hpb=97d4f38945476834fd7fce612b663f19f2b291f8;p=pspp diff --git a/src/language/expressions/evaluate.c b/src/language/expressions/evaluate.c index ac36d18110..3ff879f2b2 100644 --- a/src/language/expressions/evaluate.c +++ b/src/language/expressions/evaluate.c @@ -32,12 +32,19 @@ static void expr_evaluate (struct expression *e, const struct ccase *c, int case_idx, void *result) { + struct dataset *ds = e->ds; union operation_data *op = e->ops; double *ns = e->number_stack; struct substring *ss = e->string_stack; - assert ((c != NULL) == (e->dict != NULL)); + /* Without a dictionary/dataset, the expression can't refer to variables, + and you don't need to specify a case when you evaluate the + expression. With a dictionary/dataset, the expression can refer + to variables, so you must specify a case when you evaluate the + expression. */ + assert ((c != NULL) == (e->ds != NULL)); + pool_clear (e->eval_pool); for (;;) @@ -102,18 +109,21 @@ expr_evaluate_str (struct expression *e, const struct ccase *c, int case_idx, #include int -cmd_debug_evaluate (void) +cmd_debug_evaluate (struct dataset *dsother UNUSED) { bool optimize = true; int retval = CMD_FAILURE; bool dump_postfix = false; - struct dictionary *d = NULL; + struct ccase *c = NULL; + struct dataset *ds = NULL; + struct expression *expr; for (;;) { + struct dictionary *d = NULL; if (lex_match_id ("NOOPTIMIZE")) optimize = 0; else if (lex_match_id ("POSTFIX")) @@ -148,9 +158,12 @@ cmd_debug_evaluate (void) lex_error (_("expecting number or string")); goto done; } - - if (d == NULL) - d = dict_create (); + + if ( ds == NULL ) + { + ds = create_dataset (); + d = dataset_dict (ds); + } old_value_cnt = dict_get_next_value_idx (d); v = dict_create_var (d, name, width); @@ -163,9 +176,10 @@ cmd_debug_evaluate (void) if (c == NULL) { c = xmalloc (sizeof *c); - case_nullify (c); + case_create (c, dict_get_next_value_idx (d)); } - case_resize (c, old_value_cnt, dict_get_next_value_idx (d)); + else + case_resize (c, old_value_cnt, dict_get_next_value_idx (d)); if (lex_is_number ()) case_data_rw (c, v->fv)->f = tokval; @@ -185,12 +199,13 @@ cmd_debug_evaluate (void) lex_force_match ('/'); goto done; } - if (d != NULL) - fprintf (stderr, "; "); + + if ( ds != NULL ) + fprintf(stderr, "; "); fprintf (stderr, "%s => ", lex_rest_of_line (NULL)); lex_get (); - expr = expr_parse_any (d, optimize); + expr = expr_parse_any (ds, optimize); if (!expr || lex_end_of_command () != CMD_SUCCESS) { if (expr != NULL) @@ -241,12 +256,15 @@ cmd_debug_evaluate (void) retval = CMD_SUCCESS; done: + if (ds) + destroy_dataset (ds); + if (c != NULL) { case_destroy (c); free (c); } - dict_destroy (d); + return retval; }