[gnumeric] Names: minor cleanups.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Names: minor cleanups.
- Date: Fri, 20 May 2011 16:59:10 +0000 (UTC)
commit 79faa0448984be5ecb760d7c312af33a39906c4e
Author: Morten Welinder <terra gnome org>
Date: Fri May 20 12:58:52 2011 -0400
Names: minor cleanups.
ChangeLog | 7 ++++
plugins/excel/ms-container.c | 6 ++-
plugins/excel/ms-excel-read.c | 5 ++-
plugins/excel/ms-excel-write.c | 2 +-
plugins/fn-lookup/functions.c | 2 +-
src/dependent.c | 4 +-
src/expr-name.c | 68 +++++++++++++++++-----------------------
src/expr-name.h | 3 +-
src/expr.c | 12 +++---
src/parse-util.c | 2 +-
src/ssconvert.c | 2 +-
11 files changed, 58 insertions(+), 55 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index aa0895d..f483a4a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-05-20 Morten Welinder <terra gnome org>
+
+ * src/expr-name.c (expr_name_is_active): New function.
+
+ * src/expr-name.h (_GnmNamedExpr): Replace active member by scope
+ member. All users changed.
+
2011-05-19 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/expr-name.h (gnm_named_expr_collection_rename): new
diff --git a/plugins/excel/ms-container.c b/plugins/excel/ms-container.c
index b688482..8406cfb 100644
--- a/plugins/excel/ms-container.c
+++ b/plugins/excel/ms-container.c
@@ -75,7 +75,10 @@ ms_container_finalize (MSContainer *container)
if (nexpr != NULL) {
/* NAME placeholders need removal, EXTERNNAME placeholders
* will no be active */
- if (nexpr->active && nexpr->is_placeholder && nexpr->ref_count == 2)
+ if (expr_name_is_active (nexpr) &&
+ expr_name_is_placeholder (nexpr) &&
+ /* FIXME: Why do we need this? */
+ nexpr->ref_count == 2)
expr_name_remove (nexpr);
expr_name_unref (nexpr);
}
@@ -83,7 +86,6 @@ ms_container_finalize (MSContainer *container)
g_ptr_array_free (container->v7.externnames, TRUE);
container->v7.externnames = NULL;
}
-
}
void
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index 5316ab7..9684430 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -3289,7 +3289,10 @@ gnm_xl_importer_free (GnmXLImporter *importer)
/* NAME placeholders need removal, EXTERNNAME
* placeholders will no be active */
- if (nexpr->active && nexpr->is_placeholder && nexpr->ref_count == 2) {
+ if (expr_name_is_active (nexpr) &&
+ expr_name_is_placeholder (nexpr) &&
+ /* FIXME: Why do we need this? */
+ nexpr->ref_count == 2) {
d (1, g_printerr ("Removing name %s\n", expr_name_name (nexpr)););
expr_name_remove (nexpr);
}
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 101acb8..bea48f9 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -6325,7 +6325,7 @@ excel_write_v8 (ExcelWriteState *ewb, GsfOutfile *outfile)
static void
cb_check_names (gpointer key, GnmNamedExpr *nexpr, ExcelWriteState *ewb)
{
- if (nexpr->active)
+ if (expr_name_is_active (nexpr))
excel_write_prep_expr (ewb, nexpr->texpr);
}
diff --git a/plugins/fn-lookup/functions.c b/plugins/fn-lookup/functions.c
index 1bb9782..31e4f94 100644
--- a/plugins/fn-lookup/functions.c
+++ b/plugins/fn-lookup/functions.c
@@ -851,7 +851,7 @@ gnumeric_areas (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
}
case GNM_EXPR_OP_NAME:
- if (expr->name.name->active) {
+ if (expr_name_is_active (expr->name.name)) {
expr = expr->name.name->texpr->expr;
goto restart;
}
diff --git a/src/dependent.c b/src/dependent.c
index 8e38c92..5ff096c 100644
--- a/src/dependent.c
+++ b/src/dependent.c
@@ -1072,7 +1072,7 @@ link_expr_dep (GnmEvalPos *ep, GnmExpr const *tree)
case GNM_EXPR_OP_NAME:
expr_name_add_dep (tree->name.name, ep->dep);
- if (tree->name.name->active)
+ if (expr_name_is_active (tree->name.name))
return link_expr_dep (ep, tree->name.name->texpr->expr) | DEPENDENT_USES_NAME;
return DEPENDENT_USES_NAME;
@@ -1161,7 +1161,7 @@ unlink_expr_dep (GnmDependent *dep, GnmExpr const *tree)
case GNM_EXPR_OP_NAME:
expr_name_remove_dep (tree->name.name, dep);
- if (tree->name.name->active)
+ if (expr_name_is_active (tree->name.name))
unlink_expr_dep (dep, tree->name.name->texpr->expr);
return;
diff --git a/src/expr-name.c b/src/expr-name.c
index 9a787cf..7225a4a 100644
--- a/src/expr-name.c
+++ b/src/expr-name.c
@@ -127,9 +127,9 @@ expr_name_validate (const char *name)
static void
cb_nexpr_remove (GnmNamedExpr *nexpr)
{
- g_return_if_fail (nexpr->active);
+ g_return_if_fail (nexpr->scope != NULL);
- nexpr->active = FALSE;
+ nexpr->scope = NULL;
expr_name_set_expr (nexpr, NULL);
expr_name_unref (nexpr);
}
@@ -224,11 +224,9 @@ gnm_named_expr_collection_unlink (GnmNamedExprCollection *names)
if (!names)
return;
- if (names->names) {
- g_hash_table_foreach (names->names,
- cb_unlink_all_names,
- NULL);
- }
+ g_hash_table_foreach (names->names,
+ cb_unlink_all_names,
+ NULL);
}
static void
@@ -246,11 +244,9 @@ gnm_named_expr_collection_relink (GnmNamedExprCollection *names)
if (!names)
return;
- if (names->names) {
- g_hash_table_foreach (names->names,
- cb_relink_all_names,
- NULL);
- }
+ g_hash_table_foreach (names->names,
+ cb_relink_all_names,
+ NULL);
}
GnmNamedExpr *
@@ -279,7 +275,7 @@ GSList *
gnm_named_expr_collection_list (GnmNamedExprCollection const *scope)
{
GSList *res = NULL;
- if (scope && scope->names) {
+ if (scope) {
g_hash_table_foreach (scope->names,
cb_list_names,
&res);
@@ -288,7 +284,7 @@ gnm_named_expr_collection_list (GnmNamedExprCollection const *scope)
}
static void
-gnm_named_expr_collection_insert (GnmNamedExprCollection const *scope,
+gnm_named_expr_collection_insert (GnmNamedExprCollection *scope,
GnmNamedExpr *nexpr)
{
if (gnm_debug_flag ("names")) {
@@ -304,7 +300,7 @@ gnm_named_expr_collection_insert (GnmNamedExprCollection const *scope,
/* name can be active at this point, eg we are converting a
* placeholder, or changing a scope */
- nexpr->active = TRUE;
+ nexpr->scope = scope;
g_hash_table_replace (nexpr->is_placeholder
? scope->placeholders : scope->names, (gpointer)nexpr->name->str, nexpr);
}
@@ -321,7 +317,7 @@ cb_check_name (G_GNUC_UNUSED gpointer key, GnmNamedExpr *nexpr,
{
GnmValue *v;
- if (!nexpr->active || nexpr->is_hidden || !nexpr->texpr)
+ if (nexpr->scope == NULL || nexpr->is_hidden || !nexpr->texpr)
return;
v = gnm_expr_top_get_range (nexpr->texpr);
@@ -357,8 +353,7 @@ gnm_named_expr_collection_check (GnmNamedExprCollection *scope,
user.r = r;
user.res = NULL;
- g_hash_table_foreach (scope->names,
- (GHFunc) cb_check_name, &user);
+ g_hash_table_foreach (scope->names, (GHFunc)cb_check_name, &user);
return user.res;
}
@@ -487,7 +482,6 @@ expr_name_new (char const *name)
nexpr = g_new0 (GnmNamedExpr,1);
nexpr->ref_count = 1;
- nexpr->active = FALSE;
nexpr->name = go_string_new (name);
nexpr->texpr = NULL;
nexpr->dependents = NULL;
@@ -495,6 +489,7 @@ expr_name_new (char const *name)
nexpr->is_hidden = FALSE;
nexpr->is_permanent = FALSE;
nexpr->is_editable = TRUE;
+ nexpr->scope = NULL;
if (gnm_debug_flag ("names"))
g_printerr ("Created new name %s\n", name);
@@ -684,11 +679,11 @@ expr_name_unref (GnmNamedExpr *nexpr)
if (nexpr->ref_count-- > 1)
return;
- g_return_if_fail (!nexpr->active);
-
if (gnm_debug_flag ("names"))
g_printerr ("Finalizing name %s\n", nexpr->name->str);
+ g_return_if_fail (nexpr->scope == NULL);
+
if (nexpr->name) {
go_string_unref (nexpr->name);
nexpr->name = NULL;
@@ -719,30 +714,17 @@ expr_name_unref (GnmNamedExpr *nexpr)
void
expr_name_remove (GnmNamedExpr *nexpr)
{
- GnmNamedExprCollection *scope;
-
g_return_if_fail (nexpr != NULL);
- g_return_if_fail (nexpr->pos.sheet != NULL || nexpr->pos.wb != NULL);
- g_return_if_fail (nexpr->active);
-
- scope = (nexpr->pos.sheet != NULL)
- ? nexpr->pos.sheet->names : nexpr->pos.wb->names;
-
- g_return_if_fail (scope != NULL);
+ g_return_if_fail (nexpr->scope != NULL);
if (gnm_debug_flag ("names")) {
- char *scope_name = nexpr->pos.sheet
- ? g_strdup_printf ("sheet %s", nexpr->pos.sheet->name_quoted)
- : g_strdup ("workbook");
- g_printerr ("Removing name %s from its %s container%s\n",
+ g_printerr ("Removing name %s from its container%s\n",
nexpr->name->str,
- scope_name,
nexpr->is_placeholder ? " as a placeholder" : "");
- g_free (scope_name);
}
g_hash_table_remove (
- nexpr->is_placeholder ? scope->placeholders : scope->names,
+ nexpr->is_placeholder ? nexpr->scope->placeholders : nexpr->scope->names,
nexpr->name->str);
}
@@ -795,7 +777,7 @@ expr_name_downgrade_to_placeholder (GnmNamedExpr *nexpr)
g_return_if_fail (nexpr != NULL);
g_return_if_fail (nexpr->pos.sheet != NULL || nexpr->pos.wb != NULL);
- g_return_if_fail (nexpr->active);
+ g_return_if_fail (nexpr->scope != NULL);
g_return_if_fail (!nexpr->is_placeholder);
scope = (nexpr->pos.sheet != NULL)
@@ -831,7 +813,7 @@ expr_name_set_scope (GnmNamedExpr *nexpr, Sheet *sheet)
g_return_val_if_fail (nexpr != NULL, NULL);
g_return_val_if_fail (nexpr->pos.sheet != NULL || nexpr->pos.wb != NULL, NULL);
- g_return_val_if_fail (nexpr->active, NULL);
+ g_return_val_if_fail (nexpr->scope != NULL, NULL);
scope = (nexpr->pos.sheet != NULL)
? nexpr->pos.sheet->names : nexpr->pos.wb->names;
@@ -943,6 +925,14 @@ expr_name_is_placeholder (GnmNamedExpr const *nexpr)
gnm_expr_top_is_err (nexpr->texpr, GNM_ERROR_NAME));
}
+gboolean
+expr_name_is_active (GnmNamedExpr const *nexpr)
+{
+ g_return_val_if_fail (nexpr != NULL, FALSE);
+ return nexpr->scope != NULL;
+}
+
+
static gboolean
cb_expr_name_check_for_name (gpointer key,
gpointer value,
diff --git a/src/expr-name.h b/src/expr-name.h
index 51e0906..2ce6ff8 100644
--- a/src/expr-name.h
+++ b/src/expr-name.h
@@ -16,11 +16,11 @@ struct _GnmNamedExpr {
GnmParsePos pos;
GHashTable *dependents;
GnmExprTop const *texpr;
- gboolean active;
gboolean is_placeholder;
gboolean is_hidden;
gboolean is_permanent;
gboolean is_editable;
+ GnmNamedExprCollection *scope;
};
gboolean expr_name_validate (const char *name);
@@ -48,6 +48,7 @@ void expr_name_set_expr (GnmNamedExpr *ne, GnmExprTop const *texpr);
void expr_name_add_dep (GnmNamedExpr *ne, GnmDependent *dep);
void expr_name_remove_dep (GnmNamedExpr *ne, GnmDependent *dep);
gboolean expr_name_is_placeholder (GnmNamedExpr const *ne);
+gboolean expr_name_is_active (GnmNamedExpr const *ne);
void expr_name_downgrade_to_placeholder (GnmNamedExpr *nexpr);
gboolean expr_name_in_use (GnmNamedExpr *nexpr);
diff --git a/src/expr.c b/src/expr.c
index 15b0d65..8bf8774 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -668,7 +668,7 @@ gnm_expr_extract_ref (GnmRangeRef *res, GnmExpr const *expr,
}
case GNM_EXPR_OP_NAME:
- if (!expr->name.name->active)
+ if (!expr_name_is_active (expr->name.name))
return TRUE;
return gnm_expr_extract_ref (res, expr->name.name->texpr->expr,
pos, flags);
@@ -1441,7 +1441,7 @@ gnm_expr_eval (GnmExpr const *expr, GnmEvalPos const *pos,
}
case GNM_EXPR_OP_NAME:
- if (expr->name.name->active)
+ if (expr_name_is_active (expr->name.name))
return handle_empty (expr_name_eval (expr->name.name, pos, flags), flags);
return value_new_error_REF (pos);
@@ -2095,7 +2095,7 @@ gnm_expr_relocate (GnmExpr const *expr, RelocInfoInternal const *rinfo)
* sitting in the undo queue, or the clipboard. So we just
* flag the name as inactive and remove the reference here.
*/
- if (!nexpr->active)
+ if (!expr_name_is_active (nexpr))
return gnm_expr_new_constant (value_new_error_REF (NULL));
switch (rinfo->details->reloc_type) {
@@ -2408,7 +2408,7 @@ gnm_expr_contains_subtotal (GnmExpr const *expr)
}
case GNM_EXPR_OP_NAME:
- if (expr->name.name->active)
+ if (expr_name_is_active (expr->name.name))
return gnm_expr_contains_subtotal (expr->name.name->texpr->expr);
case GNM_EXPR_OP_ARRAY_CORNER:
@@ -2505,7 +2505,7 @@ gnm_expr_get_range (GnmExpr const *expr)
return NULL;
case GNM_EXPR_OP_NAME:
- if (!expr->name.name->active)
+ if (!expr_name_is_active (expr->name.name))
return NULL;
return gnm_expr_top_get_range (expr->name.name->texpr);
@@ -2609,7 +2609,7 @@ gnm_expr_is_rangeref (GnmExpr const *expr)
return FALSE;
case GNM_EXPR_OP_NAME:
- if (expr->name.name->active)
+ if (expr_name_is_active (expr->name.name))
return gnm_expr_is_rangeref (expr->name.name->texpr->expr);
return FALSE;
diff --git a/src/parse-util.c b/src/parse-util.c
index 16028dc..a1826ec 100644
--- a/src/parse-util.c
+++ b/src/parse-util.c
@@ -1168,7 +1168,7 @@ std_expr_name_handler (GnmConventionsOut *out, GnmExprName const *name)
GnmNamedExpr const *thename = name->name;
GString *target = out->accum;
- if (!thename->active) {
+ if (!expr_name_is_active (thename)) {
g_string_append (target,
value_error_name (GNM_ERROR_REF,
out->convs->output.translated));
diff --git a/src/ssconvert.c b/src/ssconvert.c
index 63a9360..47c887a 100644
--- a/src/ssconvert.c
+++ b/src/ssconvert.c
@@ -330,7 +330,7 @@ merge_single (Workbook *wb, Workbook *wb2,
GnmNamedExpr *nexpr2;
Sheet *sheet;
- if (!nexpr->active)
+ if (!expr_name_is_active (nexpr))
continue;
if (nexpr->pos.wb == NULL || nexpr->pos.sheet != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]