First step in making struct variable opaque: the boring mechanical
[pspp-builds.git] / src / language / stats / regression.q
index 5ac6b93aab16adcaf96f5521fc212b925e195e9e..7068d7f67108b5af00431712d78dea051e08b966 100644 (file)
@@ -230,7 +230,7 @@ reg_stats_coeff (pspp_linreg_cache * c)
       label = var_to_string (v);
       /* Do not overwrite the variable's name. */
       strncpy (tmp, label, MAX_STRING);
-      if (v->type == ALPHA)
+      if (var_is_alpha (v))
        {
          /*
             Append the value associated with this coefficient.
@@ -546,7 +546,7 @@ regression_trns_free (void *t_)
  */
 static int
 regression_trns_pred_proc (void *t_, struct ccase *c,
-                          casenum_t case_idx UNUSED)
+                          casenumber case_idx UNUSED)
 {
   size_t i;
   size_t n_vals;
@@ -585,7 +585,7 @@ regression_trns_pred_proc (void *t_, struct ccase *c,
  */
 static int
 regression_trns_resid_proc (void *t_, struct ccase *c,
-                           casenum_t case_idx UNUSED)
+                           casenumber case_idx UNUSED)
 {
   size_t i;
   size_t n_vals;
@@ -748,12 +748,12 @@ reg_print_categorical_encoding (FILE * fp, pspp_linreg_cache * c)
     {
       coeff = c->coeff[i];
       v = pspp_coeff_get_var (coeff, 0);
-      if (v->type == ALPHA)
+      if (var_is_alpha (v))
        {
          if (!reg_inserted (v, varlist, n_vars))
            {
              fprintf (fp, "struct pspp_reg_categorical_variable %s;\n\t",
-                      v->name);
+                      var_get_name (v));
              varlist[n_vars] = (struct variable *) v;
              n_vars++;
            }
@@ -764,22 +764,25 @@ reg_print_categorical_encoding (FILE * fp, pspp_linreg_cache * c)
           n_vars);
   for (i = 0; i < n_vars - 1; i++)
     {
-      fprintf (fp, "&%s,\n\t\t", varlist[i]->name);
+      fprintf (fp, "&%s,\n\t\t", var_get_name (varlist[i]));
     }
-  fprintf (fp, "&%s};\n\t", varlist[i]->name);
+  fprintf (fp, "&%s};\n\t", var_get_name (varlist[i]));
 
   for (i = 0; i < n_vars; i++)
     {
       coeff = c->coeff[i];
-      fprintf (fp, "%s.name = \"%s\";\n\t", varlist[i]->name,
-              varlist[i]->name);
-      fprintf (fp, "%s.n_vals = %d;\n\t", varlist[i]->name,
+      fprintf (fp, "%s.name = \"%s\";\n\t",
+               var_get_name (varlist[i]),
+              var_get_name (varlist[i]));
+      fprintf (fp, "%s.n_vals = %d;\n\t",
+               var_get_name (varlist[i]),
               varlist[i]->obs_vals->n_categories);
 
       for (j = 0; j < varlist[i]->obs_vals->n_categories; j++)
        {
          val = cat_subscript_to_value ((const size_t) j, varlist[i]);
-         fprintf (fp, "%s.values[%d] = \"%s\";\n\t", varlist[i]->name, j,
+         fprintf (fp, "%s.values[%d] = \"%s\";\n\t",
+                   var_get_name (varlist[i]), j,
                   value_to_string (val, varlist[i]));
        }
     }
@@ -798,11 +801,11 @@ reg_print_depvars (FILE * fp, pspp_linreg_cache * c)
     {
       coeff = c->coeff[i];
       v = pspp_coeff_get_var (coeff, 0);
-      fprintf (fp, "\"%s\",\n\t\t", v->name);
+      fprintf (fp, "\"%s\",\n\t\t", var_get_name (v));
     }
   coeff = c->coeff[i];
   v = pspp_coeff_get_var (coeff, 0);
-  fprintf (fp, "\"%s\"};\n\t", v->name);
+  fprintf (fp, "\"%s\"};\n\t", var_get_name (v));
 }
 static void
 reg_print_getvar (FILE * fp, pspp_linreg_cache * c)
@@ -824,10 +827,8 @@ reg_has_categorical (pspp_linreg_cache * c)
   for (i = 1; i < c->n_coeffs; i++)
     {
       v = pspp_coeff_get_var (c->coeff[i], 0);
-      if (v->type == ALPHA)
-       {
-         return 1;
-       }
+      if (var_is_alpha (v))
+        return 1;
     }
   return 0;
 }
@@ -916,31 +917,31 @@ subcommand_export (int export, pspp_linreg_cache * c)
 }
 
 static int
-regression_custom_export (struct dataset *ds UNUSED, struct cmd_regression *cmd UNUSED, void *aux UNUSED)
+regression_custom_export (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_regression *cmd UNUSED, void *aux UNUSED)
 {
   /* 0 on failure, 1 on success, 2 on failure that should result in syntax error */
-  if (!lex_force_match ('('))
+  if (!lex_force_match (lexer, '('))
     return 0;
 
-  if (lex_match ('*'))
+  if (lex_match (lexer, '*'))
     model_file = NULL;
   else
     {
-      model_file = fh_parse (FH_REF_FILE);
+      model_file = fh_parse (lexer, FH_REF_FILE);
       if (model_file == NULL)
        return 0;
     }
 
-  if (!lex_force_match (')'))
+  if (!lex_force_match (lexer, ')'))
     return 0;
 
   return 1;
 }
 
 int
-cmd_regression (struct dataset *ds)
+cmd_regression (struct lexer *lexer, struct dataset *ds)
 {
-  if (!parse_regression (ds, &cmd, NULL))
+  if (!parse_regression (lexer, ds, &cmd, NULL))
     return CMD_FAILURE;
 
   models = xnmalloc (cmd.n_dependent, sizeof *models);
@@ -980,14 +981,14 @@ mark_missing_cases (const struct casefile *cf, struct variable *v,
   size_t row;
   const union value *val;
 
-  for (r = casefile_get_reader (cf);
+  for (r = casefile_get_reader (cf, NULL);
        casereader_read (r, &c); case_destroy (&c))
     {
       row = casereader_cnum (r) - 1;
 
       val = case_data (&c, v->fv);
       cat_value_update (v, val);
-      if (mv_is_value_missing (&v->miss, val))
+      if (var_is_value_missing (v, val))
        {
          if (!is_missing_case[row])
            {
@@ -1004,20 +1005,20 @@ mark_missing_cases (const struct casefile *cf, struct variable *v,
 
 /* Parser for the variables sub command */
 static int
-regression_custom_variables (struct dataset *ds, 
+regression_custom_variables (struct lexer *lexer, struct dataset *ds, 
                             struct cmd_regression *cmd UNUSED,
                             void *aux UNUSED)
 {
   const struct dictionary *dict = dataset_dict (ds);
 
-  lex_match ('=');
+  lex_match (lexer, '=');
 
-  if ((token != T_ID || dict_lookup_var (dict, tokid) == NULL)
-      && token != T_ALL)
+  if ((lex_token (lexer) != T_ID || dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
+      && lex_token (lexer) != T_ALL)
     return 2;
 
 
-  if (!parse_variables (dict, &v_variables, &n_variables, PV_NONE))
+  if (!parse_variables (lexer, dict, &v_variables, &n_variables, PV_NONE))
     {
       free (v_variables);
       return 0;
@@ -1071,7 +1072,7 @@ prepare_data (int n_data, int is_missing_case[],
        {
          indep_vars[j] = v_variables[i];
          j++;
-         if (v_variables[i]->type == ALPHA)
+         if (var_is_alpha (v_variables[i]))
            {
              /* Make a place to hold the binary vectors 
                 corresponding to this variable's values. */
@@ -1135,7 +1136,7 @@ run_regression (const struct ccase *first,
 
   for (i = 0; i < cmd.n_dependent; i++)
     {
-      if (cmd.v_dependent[i]->type != NUMERIC)
+      if (!var_is_numeric (cmd.v_dependent[i]))
        {
          msg (SE, gettext ("Dependent variable must be numeric."));
          pspp_reg_rc = CMD_FAILURE;
@@ -1186,7 +1187,7 @@ run_regression (const struct ccase *first,
          The second pass fills the design matrix.
        */
       row = 0;
-      for (r = casefile_get_reader (cf); casereader_read (r, &c);
+      for (r = casefile_get_reader (cf, NULL); casereader_read (r, &c);
           case_destroy (&c))
        /* Iterate over the cases. */
        {
@@ -1209,12 +1210,12 @@ run_regression (const struct ccase *first,
                   */
                  if (!is_depvar (i, cmd.v_dependent[k]))
                    {
-                     if (v_variables[i]->type == ALPHA)
+                     if (var_is_alpha (v_variables[i]))
                        {
                          design_matrix_set_categorical (X, row,
                                                         v_variables[i], val);
                        }
-                     else if (v_variables[i]->type == NUMERIC)
+                     else
                        {
                          design_matrix_set_numeric (X, row, v_variables[i],
                                                     val);