Commit f70376be authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Fix some error handling.


1999-07-31  Morten Welinder  <terra@diku.dk>

	* src/fn-logical.c (gnumeric_if): Fix case of first argument
 	yielding an error.

	* src/expr.c (expr_dump_tree): Constify.

	* src/func.c (function_iterate_do_value): Fix behaviour of strict
 	functions.

	* src/expr.c (do_expr_tree_invalidate_references): Handle
 	VALUE_BOOLEAN and VALUE_ERROR.
	(eval_expr_real): Make comparisons strict.
parent 34a54e0a
1999-07-31 Morten Welinder <terra@diku.dk>
* src/fn-logical.c (gnumeric_if): Fix case of first argument
yielding an error.
* src/expr.c (expr_dump_tree): Constify.
* src/func.c (function_iterate_do_value): Fix behaviour of strict
functions.
* src/expr.c (do_expr_tree_invalidate_references): Handle
VALUE_BOOLEAN and VALUE_ERROR.
(eval_expr_real): Make comparisons strict.
* src/summary.c (summary_info_free): Fix leak.
(summary_item_free): Fix leak.
......
1999-07-31 Morten Welinder <terra@diku.dk>
* src/fn-logical.c (gnumeric_if): Fix case of first argument
yielding an error.
* src/expr.c (expr_dump_tree): Constify.
* src/func.c (function_iterate_do_value): Fix behaviour of strict
functions.
* src/expr.c (do_expr_tree_invalidate_references): Handle
VALUE_BOOLEAN and VALUE_ERROR.
(eval_expr_real): Make comparisons strict.
* src/summary.c (summary_info_free): Fix leak.
(summary_item_free): Fix leak.
......
......@@ -160,8 +160,8 @@ gnumeric_if (FunctionEvalInfo *ei, GList *expr_node_list)
/* Compute the if part */
value = eval_expr (ei, (ExprTree *) expr_node_list->data);
if (value == NULL)
return NULL;
if (VALUE_IS_PROBLEM (value))
return value;
/* Choose which expression we will evaluate */
ret = value_get_as_bool (value, &err);
......
......@@ -777,14 +777,19 @@ eval_expr_real (FunctionEvalInfo *s, ExprTree const *tree)
int comp;
a = eval_expr_real (s, tree->u.binary.value_a);
if (VALUE_IS_PROBLEM(a))
return a;
b = eval_expr_real (s, tree->u.binary.value_b);
if (VALUE_IS_PROBLEM(b)){
value_release (a);
return b;
}
comp = compare (a, b);
if (a != NULL)
value_release (a);
if (b != NULL)
value_release (b);
value_release (a);
value_release (b);
if (comp == TYPE_MISMATCH){
/* TODO TODO TODO : Make error more informative
......@@ -1486,7 +1491,11 @@ do_expr_tree_invalidate_references (ExprTree *src, const struct expr_tree_frob_r
case VALUE_STRING:
case VALUE_INTEGER:
case VALUE_FLOAT:
case VALUE_BOOLEAN:
case VALUE_ERROR:
case VALUE_EMPTY:
return NULL;
case VALUE_CELLRANGE: {
CellRef ca = v->v.cell_range.cell_a; /* Copy a structure, not a pointer. */
CellRef cb = v->v.cell_range.cell_b; /* Copy a structure, not a pointer. */
......@@ -1830,13 +1839,11 @@ expr_tree_fixup_references (ExprTree *src, EvalPosition *src_fp,
/* Debugging utility to print an expression */
void
expr_dump_tree (ExprTree *tree)
expr_dump_tree (const ExprTree *tree)
{
Symbol *s;
CellRef *cr;
switch (tree->oper){
case OPER_VAR:
case OPER_VAR: {
const CellRef *cr;
cr = &tree->u.ref;
printf ("Cell: %s%c%s%d\n",
cr->col_relative ? "" : "$",
......@@ -1844,19 +1851,22 @@ expr_dump_tree (ExprTree *tree)
cr->row_relative ? "" : "$",
cr->row + '1');
return;
}
case OPER_CONSTANT:
value_dump (tree->u.constant);
return;
case OPER_FUNCALL:
case OPER_FUNCALL: {
const Symbol *s;
s = symbol_lookup (global_symbol_table, tree->u.function.symbol->str);
printf ("Function call: %s\n", s->str);
break;
return;
}
case OPER_NAME:
printf ("Name : %s\n", tree->u.name->name->str);
break;
return;
case OPER_ANY_BINARY:
expr_dump_tree (tree->u.binary.value_a);
......@@ -1877,16 +1887,16 @@ expr_dump_tree (ExprTree *tree)
default:
printf ("Error\n");
}
break;
return;
case OPER_NEG:
expr_dump_tree (tree->u.value);
printf ("NEGATIVE\n");
break;
return;
case OPER_ARRAY:
printf ("ARRAY??\n");
break;
return;
}
}
......@@ -213,7 +213,7 @@ int expr_tree_get_const_int (ExprTree const *const expr);
char const * expr_tree_get_const_str (ExprTree const *const expr);
/* Debugging */
void expr_dump_tree (ExprTree *tree);
void expr_dump_tree (const ExprTree *tree);
/*
* Returns int(0) if the expression uses a non-existant cell for anything
......
......@@ -160,8 +160,8 @@ gnumeric_if (FunctionEvalInfo *ei, GList *expr_node_list)
/* Compute the if part */
value = eval_expr (ei, (ExprTree *) expr_node_list->data);
if (value == NULL)
return NULL;
if (VALUE_IS_PROBLEM (value))
return value;
/* Choose which expression we will evaluate */
ret = value_get_as_bool (value, &err);
......
......@@ -72,13 +72,19 @@ function_iterate_do_value (const EvalPosition *ep,
Value *res = NULL;
switch (value->type){
case VALUE_BOOLEAN:
case VALUE_ERROR:
if (strict) {
res = value_duplicate (value);
break;
}
/* Fall through. */
case VALUE_BOOLEAN:
case VALUE_INTEGER:
case VALUE_FLOAT:
case VALUE_STRING:
res = (*callback)(ep, value, closure);
break;
break;
case VALUE_ARRAY:
{
......@@ -144,19 +150,15 @@ function_iterate_argument_values (const EvalPosition *fp,
func_eval_info_pos (&fs, fp);
val = eval_expr (&fs, tree);
if (!VALUE_IS_PROBLEM(val)) {
if (!VALUE_IS_PROBLEM(val) || !strict) {
result = function_iterate_do_value (
fp, callback, callback_closure,
val, strict);
value_release (val);
} else if (strict) {
/* A strict function -- just short circuit. */
/* FIXME : Make the new position of the error here */
result = (val != NULL)
? value_duplicate(val) : value_terminate();
} else {
/* A non-strict function -- call the handler. */
result = (*callback) (fp, val, callback_closure);
/* A strict function with an error -- just short circuit. */
/* FIXME : Make the new position of the error here */
return val;
}
}
return result;
......
......@@ -160,8 +160,8 @@ gnumeric_if (FunctionEvalInfo *ei, GList *expr_node_list)
/* Compute the if part */
value = eval_expr (ei, (ExprTree *) expr_node_list->data);
if (value == NULL)
return NULL;
if (VALUE_IS_PROBLEM (value))
return value;
/* Choose which expression we will evaluate */
ret = value_get_as_bool (value, &err);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment