projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Rewrite and improve formatted output routines.
[pspp]
/
src
/
language
/
expressions
/
parse.c
diff --git
a/src/language/expressions/parse.c
b/src/language/expressions/parse.c
index 979e756acedfe83ea649e96098329c233aaec2cb..43aa553d894456227bcb7eb7eb328627a15de455 100644
(file)
--- a/
src/language/expressions/parse.c
+++ b/
src/language/expressions/parse.c
@@
-1,5
+1,5
@@
/* PSPP - computes sample statistics.
/* PSPP - computes sample statistics.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+ 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
Written by Ben Pfaff <blp@gnu.org>.
This program is free software; you can redistribute it and/or
@@
-18,26
+18,29
@@
02110-1301, USA. */
#include <config.h>
02110-1301, USA. */
#include <config.h>
+
#include "private.h"
#include "private.h"
+
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <stdlib.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <stdlib.h>
-#include <libpspp/array.h>
-#include
<libpspp/alloc.h>
+
+#include
"helpers.h"
#include <data/case.h>
#include <data/dictionary.h>
#include <data/case.h>
#include <data/dictionary.h>
-#include <
libpspp/message
.h>
-#include
"helpers.h"
+#include <
data/settings
.h>
+#include
<data/variable.h>
#include <language/lexer/format-parser.h>
#include <language/lexer/lexer.h>
#include <language/lexer/variable-parser.h>
#include <language/lexer/format-parser.h>
#include <language/lexer/lexer.h>
#include <language/lexer/variable-parser.h>
+#include <libpspp/alloc.h>
+#include <libpspp/array.h>
#include <libpspp/assertion.h>
#include <libpspp/assertion.h>
+#include <libpspp/message.h>
#include <libpspp/misc.h>
#include <libpspp/pool.h>
#include <libpspp/misc.h>
#include <libpspp/pool.h>
-#include <data/settings.h>
#include <libpspp/str.h>
#include <libpspp/str.h>
-#include <data/variable.h>
\f
/* Declarations. */
\f
/* Declarations. */
@@
-50,7
+53,7
@@
static parse_recursively_func parse_primary;
static parse_recursively_func parse_vector_element, parse_function;
/* Utility functions. */
static parse_recursively_func parse_vector_element, parse_function;
/* Utility functions. */
-static struct expression *expr_create (struct d
ictionary *
);
+static struct expression *expr_create (struct d
ataset *ds
);
atom_type expr_node_returns (const union any_node *);
static const char *atom_type_name (atom_type);
atom_type expr_node_returns (const union any_node *);
static const char *atom_type_name (atom_type);
@@
-70,14
+73,14
@@
static union any_node *allocate_unary_variable (struct expression *,
Returns the new expression if successful or a null pointer
otherwise. */
struct expression *
Returns the new expression if successful or a null pointer
otherwise. */
struct expression *
-expr_parse (struct d
ictionary *dict
, enum expr_type type)
+expr_parse (struct d
ataset *ds
, enum expr_type type)
{
union any_node *n;
struct expression *e;
assert (type == EXPR_NUMBER || type == EXPR_STRING || type == EXPR_BOOLEAN);
{
union any_node *n;
struct expression *e;
assert (type == EXPR_NUMBER || type == EXPR_STRING || type == EXPR_BOOLEAN);
- e = expr_create (d
ict
);
+ e = expr_create (d
s
);
n = parse_or (e);
if (n != NULL && type_check (e, &n, type))
return finish_expression (expr_optimize (n, e), e);
n = parse_or (e);
if (n != NULL && type_check (e, &n, type))
return finish_expression (expr_optimize (n, e), e);
@@
-93,9
+96,10
@@
expr_parse (struct dictionary *dict, enum expr_type type)
the expression as well. */
struct expression *
expr_parse_pool (struct pool *pool,
the expression as well. */
struct expression *
expr_parse_pool (struct pool *pool,
- struct dictionary *dict, enum expr_type type)
+ struct dataset *ds,
+ enum expr_type type)
{
{
- struct expression *e = expr_parse (d
ict
, type);
+ struct expression *e = expr_parse (d
s
, type);
if (e != NULL)
pool_add_subpool (pool, e->expr_pool);
return e;
if (e != NULL)
pool_add_subpool (pool, e->expr_pool);
return e;
@@
-110,12
+114,12
@@
expr_free (struct expression *e)
}
struct expression *
}
struct expression *
-expr_parse_any (struct d
ictionary *dict
, bool optimize)
+expr_parse_any (struct d
ataset *ds
, bool optimize)
{
union any_node *n;
struct expression *e;
{
union any_node *n;
struct expression *e;
- e = expr_create (d
ict
);
+ e = expr_create (d
s
);
n = parse_or (e);
if (n == NULL)
{
n = parse_or (e);
if (n == NULL)
{
@@
-350,25
+354,31
@@
type_coercion_core (struct expression *e,
NOT_REACHED ();
case OP_ni_format:
NOT_REACHED ();
case OP_ni_format:
+ msg_disable ();
if ((*node)->type == OP_format
if ((*node)->type == OP_format
- &&
check_input_specifier (&(*node)->format.f, false
)
- &&
check_specifier_type (&(*node)->format.f, NUMERIC, false
))
+ &&
fmt_check_input (&(*node)->format.f
)
+ &&
fmt_check_type_compat (&(*node)->format.f, NUMERIC
))
{
{
+ msg_enable ();
if (do_coercion)
(*node)->type = OP_ni_format;
return true;
}
if (do_coercion)
(*node)->type = OP_ni_format;
return true;
}
+ msg_enable ();
break;
case OP_no_format:
break;
case OP_no_format:
+ msg_disable ();
if ((*node)->type == OP_format
if ((*node)->type == OP_format
- &&
check_output_specifier (&(*node)->format.f, false
)
- &&
check_specifier_type (&(*node)->format.f, NUMERIC, false
))
+ &&
fmt_check_output (&(*node)->format.f
)
+ &&
fmt_check_type_compat (&(*node)->format.f, NUMERIC
))
{
{
+ msg_enable ();
if (do_coercion)
(*node)->type = OP_no_format;
return true;
}
if (do_coercion)
(*node)->type = OP_no_format;
return true;
}
+ msg_enable ();
break;
case OP_num_var:
break;
case OP_num_var:
@@
-733,7
+743,7
@@
parse_sysvar (struct expression *e)
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC",
};
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC",
};
- time_t last_proc_time = time_of_last_procedure (
current_dataset
);
+ time_t last_proc_time = time_of_last_procedure (
e->ds
);
struct tm *time;
char temp_buf[10];
struct tm *time;
char temp_buf[10];
@@
-751,7
+761,7
@@
parse_sysvar (struct expression *e)
return expr_allocate_number (e, SYSMIS);
else if (lex_match_id ("$JDATE"))
{
return expr_allocate_number (e, SYSMIS);
else if (lex_match_id ("$JDATE"))
{
- time_t time = time_of_last_procedure (
current_dataset
);
+ time_t time = time_of_last_procedure (
e->ds
);
struct tm *tm = localtime (&time);
return expr_allocate_number (e, expr_ymd_to_ofs (tm->tm_year + 1900,
tm->tm_mon + 1,
struct tm *tm = localtime (&time);
return expr_allocate_number (e, expr_ymd_to_ofs (tm->tm_year + 1900,
tm->tm_mon + 1,
@@
-759,7
+769,7
@@
parse_sysvar (struct expression *e)
}
else if (lex_match_id ("$TIME"))
{
}
else if (lex_match_id ("$TIME"))
{
- time_t time = time_of_last_procedure (
current_dataset
);
+ time_t time = time_of_last_procedure (
e->ds
);
struct tm *tm = localtime (&time);
return expr_allocate_number (e,
expr_ymd_to_date (tm->tm_year + 1900,
struct tm *tm = localtime (&time);
return expr_allocate_number (e,
expr_ymd_to_date (tm->tm_year + 1900,
@@
-792,7
+802,7
@@
parse_primary (struct expression *e)
/* An identifier followed by a left parenthesis may be
a vector element reference. If not, it's a function
call. */
/* An identifier followed by a left parenthesis may be
a vector element reference. If not, it's a function
call. */
- if (e->d
ict != NULL && dict_lookup_vector (e->dict
, tokid) != NULL)
+ if (e->d
s != NULL && dict_lookup_vector (dataset_dict (e->ds)
, tokid) != NULL)
return parse_vector_element (e);
else
return parse_function (e);
return parse_vector_element (e);
else
return parse_function (e);
@@
-802,12
+812,12
@@
parse_primary (struct expression *e)
/* $ at the beginning indicates a system variable. */
return parse_sysvar (e);
}
/* $ at the beginning indicates a system variable. */
return parse_sysvar (e);
}
- else if (e->d
ict != NULL && dict_lookup_var (e->dict
, tokid))
+ else if (e->d
s != NULL && dict_lookup_var (dataset_dict (e->ds)
, tokid))
{
/* It looks like a user variable.
(It could be a format specifier, but we'll assume
it's a variable unless proven otherwise. */
{
/* It looks like a user variable.
(It could be a format specifier, but we'll assume
it's a variable unless proven otherwise. */
- return allocate_unary_variable (e, parse_
dict_variable (e->dict
));
+ return allocate_unary_variable (e, parse_
variable (dataset_dict (e->ds)
));
}
else
{
}
else
{
@@
-872,7
+882,7
@@
parse_vector_element (struct expression *e)
/* Find vector, skip token.
The caller must already have verified that the current token
is the name of a vector. */
/* Find vector, skip token.
The caller must already have verified that the current token
is the name of a vector. */
- vector = dict_lookup_vector (dataset_dict (
current_dataset
), tokid);
+ vector = dict_lookup_vector (dataset_dict (
e->ds
), tokid);
assert (vector != NULL);
lex_get ();
assert (vector != NULL);
lex_get ();
@@
-894,7
+904,7
@@
parse_vector_element (struct expression *e)
\f
/* Individual function parsing. */
\f
/* Individual function parsing. */
-struct operation operations[OP_first + OP_cnt] = {
+
const
struct operation operations[OP_first + OP_cnt] = {
#include "parse.inc"
};
#include "parse.inc"
};
@@
-953,7
+963,7
@@
lookup_function_helper (const char *name,
const struct operation **first,
const struct operation **last)
{
const struct operation **first,
const struct operation **last)
{
- struct operation *f;
+
const
struct operation *f;
for (f = operations + OP_function_first;
f <= operations + OP_function_last; f++)
for (f = operations + OP_function_first;
f <= operations + OP_function_last; f++)
@@
-1185,7
+1195,7
@@
parse_function (struct expression *e)
size_t var_cnt;
size_t i;
size_t var_cnt;
size_t i;
- if (!parse_variables (dataset_dict (
current_dataset
), &vars, &var_cnt, PV_SINGLE))
+ if (!parse_variables (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,
goto fail;
for (i = 0; i < var_cnt; i++)
add_arg (&args, &arg_cnt, &arg_cap,
@@
-1231,7
+1241,7
@@
parse_function (struct expression *e)
goto fail;
}
if ((f->flags & OPF_PERM_ONLY) &&
goto fail;
}
if ((f->flags & OPF_PERM_ONLY) &&
- proc_in_temporary_transformations (
current_dataset
))
+ proc_in_temporary_transformations (
e->ds
))
{
msg (SE, _("%s may not appear after TEMPORARY."), f->prototype);
goto fail;
{
msg (SE, _("%s may not appear after TEMPORARY."), f->prototype);
goto fail;
@@
-1242,8
+1252,8
@@
parse_function (struct expression *e)
if (n->type == OP_LAG_Vn || n->type == OP_LAG_Vs)
{
if (n->type == OP_LAG_Vn || n->type == OP_LAG_Vs)
{
- if (dataset_n_lag (
current_dataset
) < 1)
- dataset_set_n_lag (
current_dataset
, 1);
+ if (dataset_n_lag (
e->ds
) < 1)
+ dataset_set_n_lag (
e->ds
, 1);
}
else if (n->type == OP_LAG_Vnn || n->type == OP_LAG_Vsn)
{
}
else if (n->type == OP_LAG_Vnn || n->type == OP_LAG_Vsn)
{
@@
-1251,8
+1261,8
@@
parse_function (struct expression *e)
assert (n->composite.arg_cnt == 2);
assert (n->composite.args[1]->type == OP_pos_int);
n_before = n->composite.args[1]->integer.i;
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 (
current_dataset
) < n_before)
- dataset_set_n_lag (
current_dataset
, n_before);
+ if ( dataset_n_lag (
e->ds
) < n_before)
+ dataset_set_n_lag (
e->ds
, n_before);
}
free (args);
}
free (args);
@@
-1268,12
+1278,12
@@
fail:
/* Utility functions. */
static struct expression *
/* Utility functions. */
static struct expression *
-expr_create (struct d
ictionary *dict
)
+expr_create (struct d
ataset *ds
)
{
struct pool *pool = pool_create ();
struct expression *e = pool_alloc (pool, sizeof *e);
e->expr_pool = pool;
{
struct pool *pool = pool_create ();
struct expression *e = pool_alloc (pool, sizeof *e);
e->expr_pool = pool;
- e->d
ict = dict
;
+ e->d
s = ds
;
e->eval_pool = pool_create_subpool (e->expr_pool);
e->ops = NULL;
e->op_types = NULL;
e->eval_pool = pool_create_subpool (e->expr_pool);
e->ops = NULL;
e->op_types = NULL;
@@
-1327,7
+1337,7
@@
expr_allocate_binary (struct expression *e, operation_type op,
static bool
is_valid_node (union any_node *n)
{
static bool
is_valid_node (union any_node *n)
{
- struct operation *op;
+
const
struct operation *op;
size_t i;
assert (n != NULL);
size_t i;
assert (n != NULL);