Commit fd2f9805 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

A better fix for function INDIRECT dependencies.

1999-12-10  Jody Goldberg <jgoldberg@home.com>

	* src/functions/fn-lookup.c (gnumeric_indirect) : This solution is
	  more paletable.  Always attempt to add the dependency, but only
	  actually do so if the calling cell does not already depend on the
	  indirected cell.

	* src/eval.c (cell_add_explicit_dependency) : Expand this function to
	  test to see if a dependency already exists.
parent ab983180
1999-12-10 Jody Goldberg <jgoldberg@home.com>
* src/functions/fn-lookup.c (gnumeric_indirect) : This solution is
more paletable. Always attempt to add the dependency, but only
actually do so if the calling cell does not already depend on the
indirected cell.
* src/eval.c (cell_add_explicit_dependency) : Expand this function to
test to see if a dependency already exists.
1999-12-10 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Added EURO function for
......
1999-12-10 Jody Goldberg <jgoldberg@home.com>
* src/functions/fn-lookup.c (gnumeric_indirect) : This solution is
more paletable. Always attempt to add the dependency, but only
actually do so if the calling cell does not already depend on the
indirected cell.
* src/eval.c (cell_add_explicit_dependency) : Expand this function to
test to see if a dependency already exists.
1999-12-10 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Added EURO function for
......
......@@ -688,20 +688,10 @@ gnumeric_indirect (FunctionEvalInfo *ei, Value **args)
&col, &row);
dest_cell = sheet_cell_get (ei->pos.sheet, col, row);
/* This is not terribly pretty. We really just want to remove the
* dependency on the indirected cell. However, that would require a
* space penalty to be paid by all dependancies to flag which depend was
* a result of the indirection. So I propose that we just clear all
* deps from this cell and then add them again.
*
* FIXME FIXME FIXME : This will not work for multiple indirection calls
* in a single expression.
*/
calling_cell = sheet_cell_get (ei->pos.sheet,
ei->pos.eval_col, ei->pos.eval_row);
cell_drop_dependencies (calling_cell);
cell_add_dependencies (calling_cell);
/* A dependency on the indirection cell if we do not already depend on it */
cell_add_explicit_dependency (calling_cell, &ref);
if (!dest_cell)
......
......@@ -162,6 +162,24 @@ add_cell_range_dep (Cell *cell, DependencyRange const * const range)
g_hash_table_insert (cell->sheet->dependency_hash, result, result);
}
static inline void
dependency_range_ctor (DependencyRange * const range, Cell const * const cell,
CellRef const * const a, CellRef const * const b)
{
int col = cell->col->pos;
int row = cell->row->pos;
/* Convert to absolute cordinates */
cell_get_abs_col_row (a, col, row, &range->range.start.col, &range->range.start.row);
cell_get_abs_col_row (b, col, row, &range->range.end.col, &range->range.end.row);
range->ref_count = 0;
if (b->sheet && a->sheet != b->sheet)
g_warning ("FIXME: 3D references need work");
range->sheet = eval_sheet (a->sheet, cell->sheet);
}
/*
* We add the dependency of Cell a in the ranges
* enclose by CellRef a and CellRef b
......@@ -172,18 +190,7 @@ static void
add_cell_range_deps (Cell *cell, const CellRef *a, const CellRef *b)
{
DependencyRange range;
int col = cell->col->pos;
int row = cell->row->pos;
/* Convert to absolute cordinates */
cell_get_abs_col_row (a, col, row, &range.range.start.col, &range.range.start.row);
cell_get_abs_col_row (b, col, row, &range.range.end.col, &range.range.end.row);
range.ref_count = 0;
if (b->sheet && a->sheet != b->sheet)
g_warning ("FIXME: 3D references need work");
range.sheet = eval_sheet (a->sheet, cell->sheet);
dependency_range_ctor (&range, cell, a, b);
add_cell_range_dep (cell, &range);
}
......@@ -312,11 +319,36 @@ cell_add_dependencies (Cell *cell)
add_tree_deps (cell, cell->parsed_node);
}
/* Explicitly add a dependency */
/*
* Add a dependency on a CellRef iff the cell is not already dependent on the
* cellref.
*
* @cell : The cell which will depend on.
* @ref : The row/col of the cell in the same sheet as cell to depend on.
*/
void
cell_add_explicit_dependency (Cell *cell, CellRef const *a)
cell_add_explicit_dependency (Cell *cell, CellRef const *ref)
{
add_cell_range_deps (cell, a, a);
DependencyRange range, *result;
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->sheet != NULL);
g_return_if_fail (cell->parsed_node != NULL);
if (!cell->sheet->dependency_hash)
dependency_hash_init (cell->sheet);
dependency_range_ctor (&range, cell, ref, ref);
/* Look it up */
result = g_hash_table_lookup (cell->sheet->dependency_hash, &range);
if (result) {
/* Is the cell already listed? */
GList const * const cl = g_list_find (result->cell_list, cell);
if (cl)
return;
}
add_cell_range_dep (cell, &range);
}
/*
......
......@@ -162,6 +162,24 @@ add_cell_range_dep (Cell *cell, DependencyRange const * const range)
g_hash_table_insert (cell->sheet->dependency_hash, result, result);
}
static inline void
dependency_range_ctor (DependencyRange * const range, Cell const * const cell,
CellRef const * const a, CellRef const * const b)
{
int col = cell->col->pos;
int row = cell->row->pos;
/* Convert to absolute cordinates */
cell_get_abs_col_row (a, col, row, &range->range.start.col, &range->range.start.row);
cell_get_abs_col_row (b, col, row, &range->range.end.col, &range->range.end.row);
range->ref_count = 0;
if (b->sheet && a->sheet != b->sheet)
g_warning ("FIXME: 3D references need work");
range->sheet = eval_sheet (a->sheet, cell->sheet);
}
/*
* We add the dependency of Cell a in the ranges
* enclose by CellRef a and CellRef b
......@@ -172,18 +190,7 @@ static void
add_cell_range_deps (Cell *cell, const CellRef *a, const CellRef *b)
{
DependencyRange range;
int col = cell->col->pos;
int row = cell->row->pos;
/* Convert to absolute cordinates */
cell_get_abs_col_row (a, col, row, &range.range.start.col, &range.range.start.row);
cell_get_abs_col_row (b, col, row, &range.range.end.col, &range.range.end.row);
range.ref_count = 0;
if (b->sheet && a->sheet != b->sheet)
g_warning ("FIXME: 3D references need work");
range.sheet = eval_sheet (a->sheet, cell->sheet);
dependency_range_ctor (&range, cell, a, b);
add_cell_range_dep (cell, &range);
}
......@@ -312,11 +319,36 @@ cell_add_dependencies (Cell *cell)
add_tree_deps (cell, cell->parsed_node);
}
/* Explicitly add a dependency */
/*
* Add a dependency on a CellRef iff the cell is not already dependent on the
* cellref.
*
* @cell : The cell which will depend on.
* @ref : The row/col of the cell in the same sheet as cell to depend on.
*/
void
cell_add_explicit_dependency (Cell *cell, CellRef const *a)
cell_add_explicit_dependency (Cell *cell, CellRef const *ref)
{
add_cell_range_deps (cell, a, a);
DependencyRange range, *result;
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->sheet != NULL);
g_return_if_fail (cell->parsed_node != NULL);
if (!cell->sheet->dependency_hash)
dependency_hash_init (cell->sheet);
dependency_range_ctor (&range, cell, ref, ref);
/* Look it up */
result = g_hash_table_lookup (cell->sheet->dependency_hash, &range);
if (result) {
/* Is the cell already listed? */
GList const * const cl = g_list_find (result->cell_list, cell);
if (cl)
return;
}
add_cell_range_dep (cell, &range);
}
/*
......
......@@ -688,20 +688,10 @@ gnumeric_indirect (FunctionEvalInfo *ei, Value **args)
&col, &row);
dest_cell = sheet_cell_get (ei->pos.sheet, col, row);
/* This is not terribly pretty. We really just want to remove the
* dependency on the indirected cell. However, that would require a
* space penalty to be paid by all dependancies to flag which depend was
* a result of the indirection. So I propose that we just clear all
* deps from this cell and then add them again.
*
* FIXME FIXME FIXME : This will not work for multiple indirection calls
* in a single expression.
*/
calling_cell = sheet_cell_get (ei->pos.sheet,
ei->pos.eval_col, ei->pos.eval_row);
cell_drop_dependencies (calling_cell);
cell_add_dependencies (calling_cell);
/* A dependency on the indirection cell if we do not already depend on it */
cell_add_explicit_dependency (calling_cell, &ref);
if (!dest_cell)
......
......@@ -340,15 +340,17 @@ range_dump (Range const *src)
* keep these as 2 print statements, because
* col_name uses a static buffer
*/
printf ("%s%d",
fprintf (stderr, "%s%d",
col_name (src->start.col),
src->start.row + 1);
if (src->start.col != src->end.col ||
src->start.row != src->end.row)
printf (":%s%d\n",
fprintf (stderr, ":%s%d\n",
col_name (src->end.col),
src->end.row + 1);
else
fputc ('\n', stderr);
}
/*
......
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