X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fxforms%2Fcompute.c;h=46c693bbffe21cdd1f9a319b1e5fece7e923681b;hb=a1a4228b112a6aca97fef5aaaf9ffa21271a1f72;hp=5c13d2f23a7a3970139a1259eead41e75cd741a0;hpb=a37754c18dee3d5941e5fe041b2c1fa1a3370157;p=pspp-builds.git diff --git a/src/language/xforms/compute.c b/src/language/xforms/compute.c index 5c13d2f2..46c693bb 100644 --- a/src/language/xforms/compute.c +++ b/src/language/xforms/compute.c @@ -43,11 +43,11 @@ struct lvalue; /* Target of a COMPUTE or IF assignment, either a variable or a vector element. */ -static struct lvalue *lvalue_parse (void); -static int lvalue_get_type (const struct lvalue *); +static struct lvalue *lvalue_parse (struct dataset *); +static int lvalue_get_type (const struct lvalue *, const struct dictionary *); static bool lvalue_is_vector (const struct lvalue *); static void lvalue_finalize (struct lvalue *, - struct compute_trns *); + struct compute_trns *, struct dictionary *); static void lvalue_destroy (struct lvalue *); /* COMPUTE and IF transformation. */ @@ -69,34 +69,36 @@ struct compute_trns struct expression *rvalue; /* Rvalue expression. */ }; -static struct expression *parse_rvalue (const struct lvalue *); +static struct expression *parse_rvalue (const struct lvalue *, struct dataset *); static struct compute_trns *compute_trns_create (void); -static trns_proc_func *get_proc_func (const struct lvalue *); +static trns_proc_func *get_proc_func (const struct lvalue *, const struct dictionary *); static trns_free_func compute_trns_free; /* COMPUTE. */ int -cmd_compute (void) +cmd_compute (struct dataset *ds) { + struct dictionary *dict = dataset_dict (ds); struct lvalue *lvalue = NULL; struct compute_trns *compute = NULL; compute = compute_trns_create (); - lvalue = lvalue_parse (); + lvalue = lvalue_parse (ds); if (lvalue == NULL) goto fail; if (!lex_force_match ('=')) goto fail; - compute->rvalue = parse_rvalue (lvalue); + compute->rvalue = parse_rvalue (lvalue, ds); if (compute->rvalue == NULL) goto fail; - add_transformation (get_proc_func (lvalue), compute_trns_free, compute); + add_transformation (ds, get_proc_func (lvalue, dict), + compute_trns_free, compute); - lvalue_finalize (lvalue, compute); + lvalue_finalize (lvalue, compute, dict); return lex_end_of_command (); @@ -110,7 +112,7 @@ cmd_compute (void) /* Handle COMPUTE or IF with numeric target variable. */ static int -compute_num (void *compute_, struct ccase *c, casenum_t case_num) +compute_num (void *compute_, struct ccase *c, casenumber case_num) { struct compute_trns *compute = compute_; @@ -125,7 +127,7 @@ compute_num (void *compute_, struct ccase *c, casenum_t case_num) /* Handle COMPUTE or IF with numeric vector element target variable. */ static int -compute_num_vec (void *compute_, struct ccase *c, casenum_t case_num) +compute_num_vec (void *compute_, struct ccase *c, casenumber case_num) { struct compute_trns *compute = compute_; @@ -157,7 +159,7 @@ compute_num_vec (void *compute_, struct ccase *c, casenum_t case_num) /* Handle COMPUTE or IF with string target variable. */ static int -compute_str (void *compute_, struct ccase *c, casenum_t case_num) +compute_str (void *compute_, struct ccase *c, casenumber case_num) { struct compute_trns *compute = compute_; @@ -172,7 +174,7 @@ compute_str (void *compute_, struct ccase *c, casenum_t case_num) /* Handle COMPUTE or IF with string vector element target variable. */ static int -compute_str_vec (void *compute_, struct ccase *c, casenum_t case_num) +compute_str_vec (void *compute_, struct ccase *c, casenumber case_num) { struct compute_trns *compute = compute_; @@ -211,33 +213,35 @@ compute_str_vec (void *compute_, struct ccase *c, casenum_t case_num) /* IF. */ int -cmd_if (void) +cmd_if (struct dataset *ds) { + struct dictionary *dict = dataset_dict (ds); struct compute_trns *compute = NULL; struct lvalue *lvalue = NULL; compute = compute_trns_create (); /* Test expression. */ - compute->test = expr_parse (default_dict, EXPR_BOOLEAN); + compute->test = expr_parse (ds, EXPR_BOOLEAN); if (compute->test == NULL) goto fail; /* Lvalue variable. */ - lvalue = lvalue_parse (); + lvalue = lvalue_parse (ds); if (lvalue == NULL) goto fail; /* Rvalue expression. */ if (!lex_force_match ('=')) goto fail; - compute->rvalue = parse_rvalue (lvalue); + compute->rvalue = parse_rvalue (lvalue, ds); if (compute->rvalue == NULL) goto fail; - add_transformation (get_proc_func (lvalue), compute_trns_free, compute); + add_transformation (ds, get_proc_func (lvalue, dict), + compute_trns_free, compute); - lvalue_finalize (lvalue, compute); + lvalue_finalize (lvalue, compute, dict); return lex_end_of_command (); @@ -250,9 +254,9 @@ cmd_if (void) /* Code common to COMPUTE and IF. */ static trns_proc_func * -get_proc_func (const struct lvalue *lvalue) +get_proc_func (const struct lvalue *lvalue, const struct dictionary *dict) { - bool is_numeric = lvalue_get_type (lvalue) == NUMERIC; + bool is_numeric = lvalue_get_type (lvalue, dict) == NUMERIC; bool is_vector = lvalue_is_vector (lvalue); return (is_numeric @@ -263,11 +267,12 @@ get_proc_func (const struct lvalue *lvalue) /* Parses and returns an rvalue expression of the same type as LVALUE, or a null pointer on failure. */ static struct expression * -parse_rvalue (const struct lvalue *lvalue) +parse_rvalue (const struct lvalue *lvalue, struct dataset *ds) { - bool is_numeric = lvalue_get_type (lvalue) == NUMERIC; + const struct dictionary *dict = dataset_dict (ds); + bool is_numeric = lvalue_get_type (lvalue, dict) == NUMERIC; - return expr_parse (default_dict, is_numeric ? EXPR_NUMBER : EXPR_STRING); + return expr_parse (ds, is_numeric ? EXPR_NUMBER : EXPR_STRING); } /* Returns a new struct compute_trns after initializing its fields. */ @@ -310,7 +315,7 @@ struct lvalue /* Parses the target variable or vector element into a new `struct lvalue', which is returned. */ static struct lvalue * -lvalue_parse (void) +lvalue_parse (struct dataset *ds) { struct lvalue *lvalue; @@ -325,7 +330,7 @@ lvalue_parse (void) if (lex_look_ahead () == '(') { /* Vector. */ - lvalue->vector = dict_lookup_vector (default_dict, tokid); + lvalue->vector = dict_lookup_vector (dataset_dict (ds), tokid); if (lvalue->vector == NULL) { msg (SE, _("There is no vector named %s."), tokid); @@ -336,7 +341,7 @@ lvalue_parse (void) lex_get (); if (!lex_force_match ('(')) goto lossage; - lvalue->element = expr_parse (default_dict, EXPR_NUMBER); + lvalue->element = expr_parse (ds, EXPR_NUMBER); if (lvalue->element == NULL) goto lossage; if (!lex_force_match (')')) @@ -358,11 +363,11 @@ lvalue_parse (void) /* Returns the type (NUMERIC or ALPHA) of the target variable or vector in LVALUE. */ static int -lvalue_get_type (const struct lvalue *lvalue) +lvalue_get_type (const struct lvalue *lvalue, const struct dictionary *dict) { if (lvalue->vector == NULL) { - struct variable *var = dict_lookup_var (default_dict, lvalue->var_name); + struct variable *var = dict_lookup_var (dict, lvalue->var_name); if (var == NULL) return NUMERIC; else @@ -372,7 +377,7 @@ lvalue_get_type (const struct lvalue *lvalue) return lvalue->vector->var[0]->type; } -/* Returns nonzero if LVALUE has a vector as its target. */ +/* Returns true if LVALUE has a vector as its target. */ static bool lvalue_is_vector (const struct lvalue *lvalue) { @@ -382,14 +387,15 @@ lvalue_is_vector (const struct lvalue *lvalue) /* Finalizes making LVALUE the target of COMPUTE, by creating the target variable if necessary and setting fields in COMPUTE. */ static void -lvalue_finalize (struct lvalue *lvalue, struct compute_trns *compute) +lvalue_finalize (struct lvalue *lvalue, + struct compute_trns *compute, + struct dictionary *dict) { if (lvalue->vector == NULL) { - compute->variable = dict_lookup_var (default_dict, lvalue->var_name); + compute->variable = dict_lookup_var (dict, lvalue->var_name); if (compute->variable == NULL) - compute->variable = dict_create_var_assert (default_dict, - lvalue->var_name, 0); + compute->variable = dict_create_var_assert (dict, lvalue->var_name, 0); compute->fv = compute->variable->fv; compute->width = compute->variable->width;