Patch #5885.
[pspp-builds.git] / src / language / expressions / parse.c
index 07a56f8ef675ef5f7c3f7bdd0cbcc92949a535b9..a253bb4accabcaa37dfae7a80baf92576bb6118d 100644 (file)
@@ -1,6 +1,5 @@
 /* PSPP - computes sample statistics.
    Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
-   Written by Ben Pfaff <blp@gnu.org>.
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -62,7 +61,7 @@ static struct expression *finish_expression (union any_node *,
 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 *); 
+                                                const struct variable *); 
 \f
 /* Public functions. */
 
@@ -1217,13 +1216,14 @@ parse_function (struct lexer *lexer, struct expression *e)
   if (lex_token (lexer) != ')')
     for (;;)
       {
-        if (lex_token (lexer) == T_ID && lex_look_ahead (lexer) == 'T')
+        if (lex_token (lexer) == T_ID
+            && toupper (lex_look_ahead (lexer)) == 'T')
           {
-            struct variable **vars;
+            const struct variable **vars;
             size_t var_cnt;
             size_t i;
 
-            if (!parse_variables (lexer, dataset_dict (e->ds), &vars, &var_cnt, PV_SINGLE))
+            if (!parse_variables_const (lexer, dataset_dict (e->ds), &vars, &var_cnt, PV_SINGLE))
               goto fail;
             for (i = 0; i < var_cnt; i++)
               add_arg (&args, &arg_cnt, &arg_cap,
@@ -1279,18 +1279,14 @@ parse_function (struct lexer *lexer, struct expression *e)
   n->composite.min_valid = min_valid != -1 ? min_valid : f->array_min_elems; 
 
   if (n->type == OP_LAG_Vn || n->type == OP_LAG_Vs) 
-    {
-      if (dataset_n_lag (e->ds) < 1)
-        dataset_set_n_lag (e->ds, 1);
-    }
+    dataset_need_lag (e->ds, 1);
   else if (n->type == OP_LAG_Vnn || n->type == OP_LAG_Vsn)
     {
       int n_before;
       assert (n->composite.arg_cnt == 2);
       assert (n->composite.args[1]->type == OP_pos_int);
       n_before = n->composite.args[1]->integer.i;
-      if ( dataset_n_lag (e->ds) < n_before)
-        dataset_set_n_lag (e->ds, n_before);
+      dataset_need_lag (e->ds, n_before);
     }
   
   free (args);
@@ -1485,7 +1481,7 @@ expr_allocate_string (struct expression *e, struct substring s)
 }
 
 union any_node *
-expr_allocate_variable (struct expression *e, struct variable *v)
+expr_allocate_variable (struct expression *e, const struct variable *v)
 {
   union any_node *n = pool_alloc (e->expr_pool, sizeof n->variable);
   n->type = var_is_numeric (v) ? OP_num_var : OP_str_var;
@@ -1505,9 +1501,48 @@ expr_allocate_format (struct expression *e, const struct fmt_spec *format)
 /* 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) 
+allocate_unary_variable (struct expression *e, const struct variable *v) 
 {
   assert (v != NULL);
   return expr_allocate_unary (e, var_is_numeric (v) ? OP_NUM_VAR : OP_STR_VAR,
                               expr_allocate_variable (e, v));
 }
+\f
+/* Export function details to other modules. */
+
+/* Returns the operation structure for the function with the
+   given IDX. */
+const struct operation *
+expr_get_function (size_t idx)
+{
+  assert (idx < OP_function_cnt);
+  return &operations[OP_function_first + idx];
+}
+
+/* Returns the number of expression functions. */
+size_t
+expr_get_function_cnt (void) 
+{
+  return OP_function_cnt;
+}
+
+/* Returns the name of operation OP. */
+const char *
+expr_operation_get_name (const struct operation *op) 
+{
+  return op->name;
+}
+
+/* Returns the human-readable prototype for operation OP. */
+const char *
+expr_operation_get_prototype (const struct operation *op) 
+{
+  return op->prototype;
+}
+
+/* Returns the number of arguments for operation OP. */
+int
+expr_operation_get_arg_cnt (const struct operation *op) 
+{
+  return op->arg_cnt;
+}