[gnumeric] Expr: prune more uses of expr-impl.h
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Expr: prune more uses of expr-impl.h
- Date: Mon, 1 Jan 2018 01:33:21 +0000 (UTC)
commit 3e2f57c300ee281614eee268a40c14102e723043
Author: Morten Welinder <terra gnome org>
Date: Sun Dec 31 20:32:42 2017 -0500
Expr: prune more uses of expr-impl.h
plugins/excel/ms-excel-write.c | 2 +-
plugins/excel/ms-formula-write.c | 19 ++++++++++++-------
plugins/excel/ms-formula-write.h | 2 +-
src/expr-name.c | 5 ++---
src/expr.c | 16 ++++++++++++++++
src/expr.h | 2 ++
src/func-builtin.c | 3 +--
src/graph.c | 4 +++-
src/hlink.c | 3 +--
src/xml-sax-read.c | 23 ++++++++++++-----------
10 files changed, 51 insertions(+), 28 deletions(-)
---
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 7e9c5c7..8e05c04 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -3623,7 +3623,7 @@ excel_write_FORMULA (ExcelWriteState *ewb, ExcelWriteSheet *esheet, GnmCell cons
GSF_LE_SET_GUINT32 (data+8, 0);
GSF_LE_SET_GUINT16 (data+12, 0); /* bogus len, fill in later */
ms_biff_put_var_write (ewb->bp, data, 14);
- len = excel_write_array_formula (ewb, gnm_expr_top_get_array_expr (texpr),
+ len = excel_write_array_formula (ewb, texpr,
esheet->gnum_sheet, col, row);
ms_biff_put_var_seekto (ewb->bp, 12);
diff --git a/plugins/excel/ms-formula-write.c b/plugins/excel/ms-formula-write.c
index d1c080d..2197913 100644
--- a/plugins/excel/ms-formula-write.c
+++ b/plugins/excel/ms-formula-write.c
@@ -194,6 +194,7 @@ typedef struct {
/* Accumulator for storing arrays after the expression */
GSList *arrays;
+ GnmExprTop const *array_texpr;
} PolishData;
static void write_node (PolishData *pd, GnmExpr const *expr,
@@ -863,10 +864,7 @@ write_node (PolishData *pd, GnmExpr const *expr, int paren_level,
guint8 data[5];
int x, y, ptg;
- if (GNM_EXPR_OP_ARRAY_ELEM == op) {
- x = expr->array_elem.x;
- y = expr->array_elem.y;
- } else
+ if (!gnm_expr_top_is_array_elem (pd->array_texpr, &x, &y))
x = y = 0;
ptg = FORMULA_PTG_EXPR;
@@ -981,7 +979,7 @@ write_arrays (PolishData *pd)
guint32
excel_write_array_formula (ExcelWriteState *ewb,
- GnmExpr const *array_expr,
+ GnmExprTop const *texpr,
Sheet *sheet, int fn_col, int fn_row)
{
PolishData pd;
@@ -989,19 +987,20 @@ excel_write_array_formula (ExcelWriteState *ewb,
guint32 len;
g_return_val_if_fail (ewb, 0);
- g_return_val_if_fail (array_expr, 0);
+ g_return_val_if_fail (texpr, 0);
pd.col = fn_col;
pd.row = fn_row;
pd.sheet = sheet;
pd.ewb = ewb;
pd.arrays = NULL;
+ pd.array_texpr = texpr;
pd.context = CTXT_ARRAY;
pd.use_name_variant = FALSE;
pd.allow_sheetless_ref = TRUE;
start = ewb->bp->curpos;
- write_node (&pd, array_expr, 0, XL_ROOT);
+ write_node (&pd, gnm_expr_top_get_array_expr (texpr), 0, XL_ROOT);
len = ewb->bp->curpos - start;
write_arrays (&pd);
@@ -1033,6 +1032,12 @@ excel_write_formula (ExcelWriteState *ewb, GnmExprTop const *texpr,
pd.arrays = NULL;
pd.allow_sheetless_ref = TRUE;
+ if (gnm_expr_top_is_array_corner (texpr) ||
+ gnm_expr_top_is_array_elem (texpr, NULL, NULL))
+ pd.array_texpr = texpr;
+ else
+ pd.array_texpr = NULL;
+
switch (context) {
case EXCEL_CALLED_FROM_CELL:
pd.context = CTXT_CELL;
diff --git a/plugins/excel/ms-formula-write.h b/plugins/excel/ms-formula-write.h
index 9e09641..7ed4ce1 100644
--- a/plugins/excel/ms-formula-write.h
+++ b/plugins/excel/ms-formula-write.h
@@ -29,7 +29,7 @@ guint32 excel_write_formula (ExcelWriteState *ewb,
Sheet *sheet, int fn_col, int fn_row,
ExcelFuncContext context);
guint32 excel_write_array_formula (ExcelWriteState *ewb,
- GnmExpr const *array_expr,
+ GnmExprTop const *texpr,
Sheet *sheet, int fn_col, int fn_row);
void excel_write_prep_expressions (ExcelWriteState *ewb);
diff --git a/src/expr-name.c b/src/expr-name.c
index b5a31cc..b6fd080 100644
--- a/src/expr-name.c
+++ b/src/expr-name.c
@@ -19,7 +19,6 @@
#include "value.h"
#include "workbook-priv.h"
#include "expr.h"
-#include "expr-impl.h"
#include "sheet.h"
#include "ranges.h"
#include "gutils.h"
@@ -632,8 +631,8 @@ cb_name_loop_check (GnmExpr const *expr, GnmExprWalk *data)
{
struct cb_name_loop_check *args = data->user;
- if (GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_NAME) {
- GnmNamedExpr const *nexpr2 = expr->name.name;
+ GnmNamedExpr const *nexpr2 = gnm_expr_get_name (expr);
+ if (nexpr2) {
if ((args->name && !strcmp (nexpr2->name->str, args->name)) ||
args->nexpr == nexpr2 ||
(!args->stop_at_name && nexpr2->texpr &&
diff --git a/src/expr.c b/src/expr.c
index c2b8af9..506339e 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1840,6 +1840,22 @@ gnm_expr_get_constant (GnmExpr const *expr)
}
/**
+ * gnm_expr_get_name:
+ * @expr:
+ *
+ * If this expression consists of just a name, return it.
+ */
+GnmNamedExpr const *
+gnm_expr_get_name (GnmExpr const *expr)
+{
+ if (GNM_EXPR_GET_OPER (expr) != GNM_EXPR_OP_NAME)
+ return NULL;
+
+ return expr->name.name;
+}
+
+
+/**
* gnm_expr_get_cellref:
* @expr:
*
diff --git a/src/expr.h b/src/expr.h
index a66eea1..2ec4ff9 100644
--- a/src/expr.h
+++ b/src/expr.h
@@ -96,6 +96,8 @@ gboolean gnm_expr_is_empty (GnmExpr const *expr);
GnmValue const *gnm_expr_get_constant (GnmExpr const *expr);
+GnmNamedExpr const *gnm_expr_get_name (GnmExpr const *expr);
+
GnmCellRef const*gnm_expr_get_cellref (GnmExpr const *expr);
void gnm_expr_as_gstring (GnmExpr const *expr,
diff --git a/src/func-builtin.c b/src/func-builtin.c
index cbca75c..10622be 100644
--- a/src/func-builtin.c
+++ b/src/func-builtin.c
@@ -29,7 +29,6 @@
#include <value.h>
#include <selection.h>
#include <expr.h>
-#include <expr-impl.h>
#include <expr-deriv.h>
#include <sheet.h>
#include <cell.h>
@@ -363,7 +362,7 @@ gnumeric_if (GnmFuncEvalInfo *ei, GnmValue const * const *args)
if (args[res])
return value_dup (args[res]);
- if (ei->func_call->argc < res + 1)
+ if (gnm_eval_info_get_arg_count (ei) < res + 1)
/* arg-not-there: default to TRUE/FALSE. */
return value_new_bool (res == 1);
else
diff --git a/src/graph.c b/src/graph.c
index d736fa5..f5a8110 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -535,7 +535,9 @@ gnm_go_data_vector_load_len (GODataVector *dat)
if (vec->val == NULL && vec->dep.texpr != NULL) {
GSList *l = NULL;
if (GNM_EXPR_GET_OPER (vec->dep.texpr->expr) == GNM_EXPR_OP_SET &&
- gnm_expr_is_rangeref (vec->dep.texpr->expr) && ((l = gnm_expr_top_get_ranges
(vec->dep.texpr))) && l->next != NULL) {
+ gnm_expr_is_rangeref (vec->dep.texpr->expr) &&
+ ((l = gnm_expr_top_get_ranges (vec->dep.texpr))) &&
+ l->next != NULL) {
unsigned len = g_slist_length (l);
GSList *cur = l;
unsigned i;
diff --git a/src/hlink.c b/src/hlink.c
index 01fd96d..d195edb 100644
--- a/src/hlink.c
+++ b/src/hlink.c
@@ -36,7 +36,6 @@
#include "position.h"
#include "expr-name.h"
#include "expr.h"
-#include "expr-impl.h"
#include "value.h"
#include "mstyle.h"
@@ -320,7 +319,7 @@ gnm_hlink_cur_wb_set_target (GnmHLink *lnk, const char *target)
if (texpr == NULL || gnm_expr_top_is_err (texpr, GNM_ERROR_REF)) {
// Nothing, error
- } else if (GNM_EXPR_GET_OPER (texpr->expr) == GNM_EXPR_OP_NAME) {
+ } else if (gnm_expr_get_name (texpr->expr)) {
// Nothing, we're good
} else {
// Allow only ranges and normalize
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index c941bcd..f0a6267 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -45,7 +45,6 @@
#include "cell.h"
#include "position.h"
#include "expr.h"
-#include "expr-impl.h"
#include "expr-name.h"
#include "print-info.h"
#include "value.h"
@@ -1754,9 +1753,9 @@ xml_sax_condition_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
}
/*
- * We have saving expressions relative to A1. This means that we read
- * see a relative reference to a cell above as R[65535]C. This function
- * patches that to R[-1]C.
+ * We have been saving expressions relative to A1. This means that when we
+ * read, we see a relative reference to a cell above as R[65535]C. This
+ * function patches that to R[-1]C.
*
* We ought to fix the format, but then old Gnumerics couldn't read new
* files. In fact, if we just added a "Position" attribute then we would
@@ -1767,12 +1766,13 @@ cond_patchup (GnmExpr const *expr, GnmExprWalk *data)
{
XMLSaxParseState *state = data->user;
GnmCellPos const *pos = &state->style_range.start;
- if (GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_CELLREF) {
+ GnmCellRef const *oref = gnm_expr_get_cellref (expr);
+ GnmValue const *ocst = gnm_expr_get_constant (expr);
+
+ if (oref) {
GnmCellPos tpos;
- GnmCellRef const *oref = &expr->cellref.ref;
GnmCellRef tref = *oref;
- gnm_cellpos_init_cellref (&tpos, &expr->cellref.ref,
- pos, state->sheet);
+ gnm_cellpos_init_cellref (&tpos, oref, pos, state->sheet);
if (tref.col_relative)
tref.col = tpos.col - pos->col;
if (tref.row_relative)
@@ -1780,9 +1780,10 @@ cond_patchup (GnmExpr const *expr, GnmExprWalk *data)
if (gnm_cellref_equal (&tref, oref))
return NULL;
return gnm_expr_new_cellref (&tref);
- } else if (GNM_EXPR_GET_OPER (expr) == GNM_EXPR_OP_CONSTANT &&
- VALUE_IS_CELLRANGE (expr->constant.value)) {
- GnmRangeRef const *oref = value_get_rangeref (expr->constant.value);
+ }
+
+ if (ocst && VALUE_IS_CELLRANGE (ocst)) {
+ GnmRangeRef const *oref = value_get_rangeref (ocst);
GnmRangeRef tref = *oref;
GnmRange trange;
Sheet *start_sheet, *end_sheet;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]