Commit d660a287 authored by Morten Welinder's avatar Morten Welinder

Standards: be C99 compliant when accessing GnmValue's type.

There are three standards compliant ways of getting the tag field
for a union like GnmValue.

1. Via the subtype struct that the value has.  That only works (and
   is utterly pointless) when we already know the value type.

2. Via another union member that is a structure having one or more
   initial members matching the actual struct type.  The silly thing
   is that this rule only applies to structs; I guess that is an
   oversight, but a fat lot of good that does us now.  In practice
   this means we should use ->v_any.type for that.

3. Using the pointer-to-first-struct-member rule.

To simplify matters, define VALUE_IS_ARRAY and VALUE_IS_CELLRANGE
macros.
parent 4a87da3d
2014-10-26 Morten Welinder <terra@gnome.org>
* src/value.h (VALUE_IS_CELLRANGE, VALUE_IS_ARRAY): New macros.
Use throughout.
(GnmValue): Drop type union member. C99 requires that this be
accessed in a structure. We have v_any for that.
2014-10-25 Morten Welinder <terra@gnome.org>
* src/expr-impl.h (GNM_EXPR_GET_OPER): Redefine in a way that
......
......@@ -2,6 +2,7 @@ Gnumeric 1.12.19
Morten:
* Plug leaks.
* Pay more attention to union access rules.
--------------------------------------------------------------------------
Gnumeric 1.12.18
......
......@@ -5491,7 +5491,7 @@ chart_write_siindex (XLChartWriteState *s, guint msdim)
msdim--;
for (i = 0; i < s->values[msdim]->len; i++) {
XLValue *xlval = s->values[msdim]->pdata[i];
if (xlval->value->type != VALUE_ARRAY)
if (!VALUE_IS_ARRAY (xlval->value))
continue;
as_col = xlval->value->v_array.y > xlval->value->v_array.x;
jmax = as_col
......@@ -5501,7 +5501,7 @@ chart_write_siindex (XLChartWriteState *s, guint msdim)
GnmValue const* value = as_col
? xlval->value->v_array.vals[0][j]
: xlval->value->v_array.vals[j][0];
switch (value->type) {
switch (value->v_any.type) {
case VALUE_FLOAT:
data = ms_biff_put_len_next (s->bp, BIFF_NUMBER_v2, 14);
GSF_LE_SET_DOUBLE (data + 6, value_get_as_float (value));
......
......@@ -3698,7 +3698,7 @@ excel_parse_name (GnmXLImporter *importer, Sheet *sheet, char *name,
if (0 == strcmp (name, "Print_Area")) {
GnmValue *val = gnm_expr_get_range (texpr->expr);
if (val != NULL && val->type == VALUE_CELLRANGE) {
if (val != NULL && VALUE_IS_CELLRANGE (val)) {
GnmEvalPos ep;
int height, width;
......
......@@ -3386,7 +3386,7 @@ excel_write_map_errcode (GnmValue const *v)
static void
excel_write_value (ExcelWriteState *ewb, GnmValue *v, guint32 col, guint32 row, guint16 xf)
{
switch (v->type) {
switch (v->v_any.type) {
case VALUE_EMPTY: {
guint8 *data = ms_biff_put_len_next (ewb->bp, BIFF_BLANK_v2, 6);
......@@ -3486,7 +3486,7 @@ excel_write_value (ExcelWriteState *ewb, GnmValue *v, guint32 col, guint32 row,
break;
default:
g_printerr ("Unhandled value type %d\n", v->type);
g_printerr ("Unhandled value type %d\n", v->v_any.type);
break;
}
}
......@@ -3518,7 +3518,7 @@ excel_write_FORMULA (ExcelWriteState *ewb, ExcelWriteSheet *esheet, GnmCell cons
EX_SETROW (data, row);
EX_SETCOL (data, col);
EX_SETXF (data, xf);
switch (v->type) {
switch (v->v_any.type) {
case VALUE_FLOAT:
gsf_le_set_double (data + 6, value_get_as_float (v));
break;
......@@ -3547,7 +3547,7 @@ excel_write_FORMULA (ExcelWriteState *ewb, ExcelWriteSheet *esheet, GnmCell cons
break;
default:
g_warning ("Unhandled value->type (%d) in excel_write_FORMULA.", v->type);
g_warning ("Unhandled value->type (%d) in excel_write_FORMULA.", v->v_any.type);
}
GSF_LE_SET_GUINT16 (data + 14, /* alwaysCalc & calcOnLoad */
......@@ -3994,7 +3994,7 @@ excel_write_DOPER (GnmFilterCondition const *cond, int i, guint8 *buf)
if (cond->op[i] == GNM_FILTER_UNUSED)
return NULL;
switch (v->type) {
switch (v->v_any.type) {
case VALUE_BOOLEAN:
buf[0] = 8;
buf[2] = 0;
......
......@@ -118,7 +118,7 @@ cb_excel_write_prep_expr (GnmExpr const *expr, GnmExprWalk *data)
case GNM_EXPR_OP_CONSTANT: {
GnmValue const *v = expr->constant.value;
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
ExcelSheetPair pair;
pair.a = v->v_range.cell.a.sheet;
pair.b = v->v_range.cell.b.sheet;
......@@ -753,7 +753,7 @@ write_node (PolishData *pd, GnmExpr const *expr, int paren_level,
case GNM_EXPR_OP_CONSTANT : {
GnmValue const *v = expr->constant.value;
switch (v->type) {
switch (v->v_any.type) {
case VALUE_FLOAT: {
guint8 data[10];
......@@ -826,10 +826,8 @@ write_node (PolishData *pd, GnmExpr const *expr, int paren_level,
}
default : {
gchar *err = g_strdup_printf ("Unknown value %d\n", v->type);
write_string (pd, err);
g_free (err);
g_warning ("Unhandled value type %d", v->type);
write_string (pd, "(Unknown value)");
g_warning ("Unhandled value type %d", v->v_any.type);
break;
}
}
......
......@@ -106,7 +106,7 @@ static void
xls_write_pivot_cache_value (ExcelWriteState *ewb, GOVal const *v)
{
if (NULL != v) {
switch (v->type) {
switch (v->v_any.type) {
case VALUE_CELLRANGE:
case VALUE_ARRAY:
g_warning ("REMOVE THIS CODE WHEN WE MOVE TO GOFFICE");
......
......@@ -37,7 +37,7 @@ xlsx_write_pivot_val (XLSXWriteState *state, GsfXMLOut *xml,
GOVal const *v)
{
g_return_if_fail (v != NULL);
switch (v->type) {
switch (v->v_any.type) {
case VALUE_CELLRANGE:
case VALUE_ARRAY:
g_warning ("REMOVE THIS CODE WHEN WE MOVE TO GOFFICE");
......
......@@ -1588,7 +1588,7 @@ xlsx_write_cells (XLSXWriteState *state, GsfXMLOut *xml,
if (style_id > -1)
gsf_xml_out_add_int (xml, "s", style_id);
switch (val->type) {
switch (val->v_any.type) {
default :
case VALUE_EMPTY:
type = NULL; /* FIXME : what to do ? */
......
......@@ -148,7 +148,7 @@ static const char *
gnm_value_type_name (const GnmValue*g)
{
if (NULL != g) {
switch (g->type) {
switch (g->v_any.type) {
CASE(VALUE_EMPTY);
CASE(VALUE_BOOLEAN);
CASE(VALUE_FLOAT);
......@@ -277,7 +277,7 @@ copy_construct_xloper_from_gnm_value (XLOPER*out, const GnmValue*in,
out->val.num = 0;
if (NULL != in) {
switch (in->type) {
switch (in->v_any.type) {
case VALUE_EMPTY:
out->xltype = xltypeNil;
break;
......@@ -347,7 +347,7 @@ copy_construct_xloper_from_gnm_value (XLOPER*out, const GnmValue*in,
break;
}
default:;
g_warning (_("Unsupported GnmValue type (%d)"),in->type);
g_warning (_("Unsupported GnmValue type (%d)"),in->v_any.type);
}
}
}
......
......@@ -222,7 +222,7 @@ database_float_range_function (GnmFuncEvalInfo *ei,
return value_new_error_NUM (ei->pos);
/* I don't like this -- minimal fix for now. 509427. */
if (criteria->type != VALUE_CELLRANGE)
if (!VALUE_IS_CELLRANGE (criteria))
return value_new_error_NUM (ei->pos);
criterias = parse_database_criteria (ei->pos, database, criteria);
......@@ -284,7 +284,7 @@ database_value_range_function (GnmFuncEvalInfo *ei,
return value_new_error_NUM (ei->pos);
/* I don't like this -- minimal fix for now. 509427. */
if (criteria->type != VALUE_CELLRANGE)
if (!VALUE_IS_CELLRANGE (criteria))
return value_new_error_NUM (ei->pos);
criterias = parse_database_criteria (ei->pos, database, criteria);
......
......@@ -86,7 +86,7 @@ val_to_base (GnmFuncEvalInfo *ei,
if (aplaces && VALUE_IS_BOOLEAN (aplaces))
return value_new_error_VALUE (ei->pos);
switch (value->type) {
switch (value->v_any.type) {
default:
return value_new_error_NUM (ei->pos);
......
......@@ -1181,7 +1181,7 @@ static GnmValue *
gnumeric_expression (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
GnmValue const * const v = argv[0];
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
GnmCell *cell;
GnmCellRef const * a = &v->v_range.cell.a;
GnmCellRef const * b = &v->v_range.cell.b;
......@@ -1221,7 +1221,7 @@ static GnmValue *
gnumeric_get_formula (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
GnmValue const * const v = argv[0];
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
GnmCell *cell;
GnmCellRef const * a = &v->v_range.cell.a;
GnmCellRef const * b = &v->v_range.cell.b;
......@@ -1260,7 +1260,7 @@ static GnmValue *
gnumeric_isformula (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
GnmValue const * const v = argv[0];
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
GnmCell *cell;
GnmCellRef const * a = &v->v_range.cell.a;
GnmCellRef const * b = &v->v_range.cell.b;
......@@ -1312,7 +1312,7 @@ gnumeric_countblank (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
value_area_get_height (v, ei->pos);
int nsheets = 1;
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
GnmRange r;
Sheet *start_sheet, *end_sheet;
......@@ -1766,7 +1766,7 @@ static GnmValue *
gnumeric_type (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
GnmValue const *v = argv[0];
switch (v ? v->type : VALUE_EMPTY) {
switch (v ? v->v_any.type : VALUE_EMPTY) {
case VALUE_BOOLEAN:
return value_new_int (4);
case VALUE_EMPTY:
......@@ -1826,7 +1826,7 @@ gnumeric_get_link (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
GnmValue const * const v = argv[0];
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
GnmCellRef const * a = &v->v_range.cell.a;
GnmCellRef const * b = &v->v_range.cell.b;
Sheet *sheet;
......
......@@ -325,7 +325,7 @@ get_linear_lookup_cache (GnmFuncEvalInfo *ei,
return NULL;
}
switch (data->type) {
switch (data->v_any.type) {
case VALUE_CELLRANGE: {
GnmSheetRange sr;
GnmRangeRef const *rr = value_get_rangeref (data);
......@@ -425,7 +425,7 @@ get_bisection_lookup_cache (GnmFuncEvalInfo *ei,
return NULL;
}
switch (data->type) {
switch (data->v_any.type) {
case VALUE_CELLRANGE: {
GnmSheetRange sr;
GnmRangeRef const *rr = value_get_rangeref (data);
......@@ -491,7 +491,7 @@ find_compare_type_valid (GnmValue const *find, GnmValue const *val)
if (!val)
return FALSE;
if (find->type == val->type)
if (find->v_any.type == val->v_any.type)
return TRUE;
/* Note: floats do not match bools. */
......@@ -595,7 +595,7 @@ find_index_linear_equal_float (GnmFuncEvalInfo *ei,
LinearLookupInfo info;
/* This handles floats and bools, but with separate caches. */
h = get_linear_lookup_cache (ei, data, find->type, vertical,
h = get_linear_lookup_cache (ei, data, find->v_any.type, vertical,
&info);
if (!h)
return LOOKUP_DATA_ERROR;
......@@ -688,12 +688,12 @@ find_index_bisection (GnmFuncEvalInfo *ei,
LookupBisectionCacheItemElem key;
BisectionLookupInfo info;
bc = get_bisection_lookup_cache (ei, data, find->type, vertical,
bc = get_bisection_lookup_cache (ei, data, find->v_any.type, vertical,
&info);
if (!bc)
return LOOKUP_DATA_ERROR;
stringp = (find->type == VALUE_STRING);
stringp = VALUE_IS_STRING (find);
comparer = stringp ? bisection_compare_string : bisection_compare_float;
if (info.is_new) {
......@@ -926,7 +926,7 @@ gnumeric_areas (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
case GNM_EXPR_OP_CONSTANT:
if (VALUE_IS_ERROR (expr->constant.value))
return value_dup (expr->constant.value);
if (expr->constant.value->type != VALUE_CELLRANGE)
if (!VALUE_IS_CELLRANGE (expr->constant.value))
break;
case GNM_EXPR_OP_CELLREF:
......@@ -938,7 +938,7 @@ gnumeric_areas (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
case GNM_EXPR_OP_FUNCALL: {
GnmValue *v = gnm_expr_eval (expr, ei->pos,
GNM_EXPR_EVAL_PERMIT_NON_SCALAR);
if (v->type == VALUE_CELLRANGE)
if (VALUE_IS_CELLRANGE (v))
res = 1;
value_release (v);
break;
......@@ -1198,7 +1198,7 @@ gnumeric_lookup (GnmFuncEvalInfo *ei, GnmValue const * const *args)
}
vertical_lookup = (width < height);
is_cellrange = (lookup->type == VALUE_CELLRANGE);
is_cellrange = VALUE_IS_CELLRANGE (lookup);
#if 0
if (is_cellrange) {
GnmRange r;
......@@ -1422,7 +1422,7 @@ gnumeric_index (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
}
#warning Work out a way to fall back to returning value when a reference is unneeded
if (VALUE_CELLRANGE == v->type) {
if (VALUE_IS_CELLRANGE (v)) {
GnmRangeRef const *src = &v->v_range.cell;
GnmCellRef a = src->a, b = src->b;
Sheet *start_sheet, *end_sheet;
......@@ -1436,7 +1436,7 @@ gnumeric_index (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
a.col = r.start.col; if (a.col_relative) a.col -= ei->pos->eval.col;
b.col = r.start.col; if (b.col_relative) b.col -= ei->pos->eval.col;
res = value_new_cellrange_unsafe (&a, &b);
} else if (VALUE_ARRAY == v->type)
} else if (VALUE_IS_ARRAY (v))
res = value_dup (value_area_fetch_x_y (v, elem[1], elem[0], ei->pos));
else
res = value_new_error_REF (ei->pos);
......@@ -1474,7 +1474,7 @@ gnumeric_column (GnmFuncEvalInfo *ei, GnmValue const * const *args)
width = ei->pos->array->cols;
else
return value_new_int (col);
} else if (ref->type == VALUE_CELLRANGE) {
} else if (VALUE_IS_CELLRANGE (ref)) {
Sheet *tmp;
GnmRange r;
......@@ -1625,7 +1625,7 @@ gnumeric_row (GnmFuncEvalInfo *ei, GnmValue const * const *args)
n = ei->pos->array->rows;
else
return value_new_int (row);
} else if (ref->type == VALUE_CELLRANGE) {
} else if (VALUE_IS_CELLRANGE (ref)) {
Sheet *tmp;
GnmRange r;
......@@ -1681,7 +1681,7 @@ gnumeric_sheets (GnmFuncEvalInfo *ei, GnmValue const * const *args)
GnmValue const *v = args[0];
if(v) {
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
GnmRangeRef const *r = &v->v_range.cell;
int ans_min, ans_max, a, b;
......@@ -1722,7 +1722,7 @@ gnumeric_sheet (GnmFuncEvalInfo *ei, GnmValue const * const *args)
int n;
if(v) {
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
GnmRangeRef const *r = &v->v_range.cell;
int a, b;
......@@ -1735,7 +1735,7 @@ gnumeric_sheet (GnmFuncEvalInfo *ei, GnmValue const * const *args)
n = MAX (a,b);
else
return value_new_error_NUM (ei->pos);
} else if (v->type == VALUE_STRING) {
} else if (VALUE_IS_STRING (v)) {
Sheet *sheet = workbook_sheet_by_name
(wb, value_peek_string (v));
if (!sheet)
......
......@@ -524,7 +524,7 @@ gnumeric_countif (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
* not need to.
* 1) @range must be a range, arrays are not supported
* 2) @range can not be 3d */
if (r->type != VALUE_CELLRANGE ||
if (!VALUE_IS_CELLRANGE (argv[0]) ||
((sheet = eval_sheet (r->cell.a.sheet, ei->pos->sheet)) != r->cell.b.sheet &&
r->cell.b.sheet != NULL) ||
(!VALUE_IS_NUMBER (argv[1]) && !VALUE_IS_STRING (argv[1])))
......@@ -622,9 +622,9 @@ gnumeric_sumif (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
* not need to.
* 1) @range must be a range, arrays are not supported
* 2) @range can not be 3d */
if (argv[0]->type != VALUE_CELLRANGE ||
if (!VALUE_IS_CELLRANGE (argv[0]) ||
(!VALUE_IS_NUMBER (argv[1]) && !VALUE_IS_STRING (argv[1])) ||
(argv[2] != NULL && argv[2]->type != VALUE_CELLRANGE))
(argv[2] != NULL && !VALUE_IS_CELLRANGE (argv[2])))
return value_new_error_VALUE (ei->pos);
gnm_rangeref_normalize (&argv[0]->v_range.cell, ei->pos,
......@@ -687,9 +687,9 @@ gnumeric_averageif (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
* not need to.
* 1) @range must be a range, arrays are not supported
* 2) @range can not be 3d */
if (argv[0]->type != VALUE_CELLRANGE ||
if (!VALUE_IS_CELLRANGE (argv[0]) ||
(!VALUE_IS_NUMBER (argv[1]) && !VALUE_IS_STRING (argv[1])) ||
(argv[2] != NULL && argv[2]->type != VALUE_CELLRANGE))
(argv[2] != NULL && !VALUE_IS_CELLRANGE (argv[2])))
return value_new_error_VALUE (ei->pos);
gnm_rangeref_normalize (&argv[0]->v_range.cell, ei->pos,
......@@ -3064,7 +3064,7 @@ gnumeric_sumproduct_common (gboolean ignore_bools, GnmFuncEvalInfo *ei,
for (x = 0; x < thissizex; x++) {
/* FIXME: efficiency worries? */
GnmValue const *v = value_area_fetch_x_y (val, x, y, ei->pos);
switch (v->type) {
switch (v->v_any.type) {
case VALUE_ERROR:
/*
* We carefully tranverse the argument
......
......@@ -3685,7 +3685,7 @@ gnumeric_logfit (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
int nx, ny, i;
gnm_float *logfit_res = NULL;
if (argv[0] == NULL || argv[0]->type != VALUE_CELLRANGE)
if (argv[0] == NULL || !VALUE_IS_CELLRANGE (argv[0]))
goto out;
ys = collect_floats_value (argv[0], ei->pos,
COLLECT_IGNORE_BLANKS | /* zeroing blanks
......@@ -3697,7 +3697,7 @@ numbers */
&ny, &result);
if (result)
goto out;
if (argv[1] == NULL || argv[1]->type != VALUE_CELLRANGE)
if (argv[1] == NULL || !VALUE_IS_CELLRANGE (argv[1]))
goto out;
xs = collect_floats_value (argv[1], ei->pos,
COLLECT_IGNORE_BLANKS |
......@@ -4355,12 +4355,11 @@ function_marshal_arg (GnmFuncEvalInfo *ei,
else
v = gnm_expr_eval (t, ei->pos, GNM_EXPR_EVAL_PERMIT_NON_SCALAR);
if (v->type != VALUE_ARRAY &&
v->type != VALUE_CELLRANGE) {
if (!VALUE_IS_ARRAY (v) && !VALUE_IS_CELLRANGE (v)) {
*type_mismatch = value_new_error_VALUE (ei->pos);
}
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
gnm_cellref_make_abs (&v->v_range.cell.a, &v->v_range.cell.a,
ei->pos);
gnm_cellref_make_abs (&v->v_range.cell.b, &v->v_range.cell.b,
......
......@@ -332,7 +332,7 @@ html_write_cell_content (GsfOutput *output, GnmCell *cell, GnmStyle const *style
gsf_output_printf (output, "<font color=\"#%02X%02X%02X\">", r, g, b);
}
if ((cell->value->type == VALUE_STRING)
if (VALUE_IS_STRING (cell->value)
&& (VALUE_FMT (cell->value) != NULL)
&& go_format_is_markup (VALUE_FMT (cell->value)))
markup = go_format_get_markup (VALUE_FMT (cell->value));
......
......@@ -3343,7 +3343,7 @@ odf_write_cell (GnmOOExport *state, GnmCell *cell, GnmRange const *merge_range,
g_free (eq_formula);
}
switch (cell->value->type) {
switch (cell->value->v_any.type) {
case VALUE_EMPTY:
break;
case VALUE_BOOLEAN:
......@@ -4035,7 +4035,7 @@ odf_write_sheet_control_radio_button (GnmOOExport *state, SheetObject *so)
gsf_xml_out_add_cstr (state->xml, FORM "label", label);
if (val != NULL) {
switch (val->type) {
switch (val->v_any.type) {
case VALUE_EMPTY:
break;
case VALUE_BOOLEAN:
......@@ -6199,7 +6199,7 @@ odf_write_data_element_range (GnmOOExport *state, GnmParsePos *pp, GnmExprTop c
switch (GNM_EXPR_GET_OPER (texpr->expr)) {
case GNM_EXPR_OP_CONSTANT:
if (texpr->expr->constant.value->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (texpr->expr->constant.value)) {
str = gnm_expr_top_as_string (texpr, pp, state->conv);
gsf_xml_out_add_cstr (state->xml, attribute,
odf_strip_brackets (str));
......@@ -6215,7 +6215,7 @@ odf_write_data_element_range (GnmOOExport *state, GnmParsePos *pp, GnmExprTop c
for (i = 0; i < expr->set.argc; i++) {
GnmExpr const *expr_arg = expr->set.argv[i];
if (GNM_EXPR_GET_OPER (expr_arg) == GNM_EXPR_OP_CONSTANT &&
expr_arg->constant.value->type == VALUE_CELLRANGE) {
VALUE_IS_CELLRANGE (expr_arg->constant.value)) {
char *str = gnm_expr_as_string (expr_arg, pp, state->conv);
if (gstr->len > 0)
g_string_append_c (gstr, ' ');
......@@ -7891,7 +7891,7 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *graph,
= gnm_go_data_get_expr (dat);
if (texpr != NULL &&
GNM_EXPR_GET_OPER (texpr->expr) == GNM_EXPR_OP_CONSTANT
&& texpr->expr->constant.value->type == VALUE_STRING) {
&& VALUE_IS_STRING (texpr->expr->constant.value)) {
gboolean white_written = TRUE;
char const *str;
gboolean pp = TRUE;
......
......@@ -6,7 +6,7 @@ value2perl(const GnmValue *v)
{
SV *sv;
switch (v->type) {
switch (v->v_any.type) {
case VALUE_BOOLEAN:
sv = newSViv(value_get_as_int (v));
break;
......
......@@ -325,7 +325,7 @@ gnm_value_to_py_obj (const GnmEvalPos *eval_pos, const GnmValue *val)
g_return_val_if_fail (eval_pos != NULL, NULL);
g_return_val_if_fail (val != NULL, NULL);
switch (val->type) {
switch (val->v_any.type) {
case VALUE_BOOLEAN:
py_val = py_new_Boolean_object (value_get_as_checked_bool (val));
break;
......
......@@ -261,7 +261,7 @@ sc_parse_coord_real (ScParseState *state, char const *strdata, GnmCellPos *pos,
parse_pos_init (&pp, NULL, state->sheet, 0, 0);
nexpr = expr_name_lookup (&pp, tmpstr);
if (nexpr && (v = gnm_expr_top_get_range (nexpr->texpr))) {
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
GnmEvalPos ep;
const GnmCellRef *cr = &v->v_range.cell.a;
......
......@@ -157,7 +157,7 @@ do_af_suggest (GnmExpr const *expr, GnmEvalPos const *epos, GOFormat const **exp
case GNM_EXPR_OP_CONSTANT: {
GnmValue const *v = expr->constant.value;
switch (v->type) {
switch (v->v_any.type) {
case VALUE_STRING:
case VALUE_ERROR:
return GNM_FUNC_AUTO_UNKNOWN;
......
......@@ -321,7 +321,7 @@ callback_function_collect (GnmEvalPos const *ep, GnmValue const *value,
collect_floats_t *cl = closure;
gboolean ignore = FALSE;
switch (value ? value->type : VALUE_EMPTY) {
switch (value ? value->v_any.type : VALUE_EMPTY) {
case VALUE_EMPTY:
if (cl->flags & COLLECT_IGNORE_BLANKS)
ignore = TRUE;
......@@ -381,7 +381,7 @@ callback_function_collect (GnmEvalPos const *ep, GnmValue const *value,
default:
g_warning ("Trouble in callback_function_collect. (%d)",
value->type);
value->v_any.type);
ignore = TRUE;
}
......@@ -783,9 +783,9 @@ collect_float_pairs (GnmValue const *vx, GnmValue const *vy,
PairsFloatsCacheEntry *ce = NULL;
gboolean use_cache, free_keys = TRUE;
if (vx->type == VALUE_CELLRANGE)
if (VALUE_IS_CELLRANGE (vx))
key_x = get_single_cache_key_from_value (vx, ep);
if (vy->type == VALUE_CELLRANGE)
if (VALUE_IS_CELLRANGE (vy))
key_y = get_single_cache_key_from_value (vy, ep);
if ((use_cache = (key_x && key_y)))
......
......@@ -1076,7 +1076,7 @@ link_unlink_expr_dep (GnmEvalPos *ep, GnmExpr const *tree, gboolean qlink)
/* TODO: pass in eval flags so that we can use implicit
* intersection
*/
if (VALUE_CELLRANGE == tree->constant.value->type)
if (VALUE_IS_CELLRANGE (tree->constant.value))
return link_unlink_cellrange_dep
(ep->dep, dependent_pos (ep->dep),
&tree->constant.value->v_range.cell.a,
......
......@@ -136,7 +136,7 @@ sign_test_two_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget *dummy,
input_range = gnm_expr_entry_parse_as_value
(GNM_EXPR_ENTRY (state->base.input_entry),
state->base.sheet);
if (input_range == NULL || input_range->type != VALUE_CELLRANGE) {
if (input_range == NULL || !VALUE_IS_CELLRANGE (input_range)) {
gtk_label_set_text (GTK_LABEL (state->base.warning),
(state->base.input_entry_2 == NULL)
? _("The input range is invalid.")
......@@ -157,7 +157,7 @@ sign_test_two_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget *dummy,
input_range = gnm_expr_entry_parse_as_value
(GNM_EXPR_ENTRY (state->base.input_entry_2),
state->base.sheet);
if (input_range == NULL || input_range->type != VALUE_CELLRANGE) {
if (input_range == NULL || !VALUE_IS_CELLRANGE (input_range)) {
gtk_label_set_text (GTK_LABEL (state->base.warning),
_("The second input range is invalid."));
gtk_widget_set_sensitive (state->base.ok_button, FALSE);
......
......@@ -100,8 +100,8 @@ prepare_ranges (simulation_t *sim)
{
int i, n, base_col, base_row;
if (sim->inputs->type != VALUE_CELLRANGE ||
sim->outputs->type != VALUE_CELLRANGE)
if (!VALUE_IS_CELLRANGE (sim->inputs) ||
!VALUE_IS_CELLRANGE (sim->outputs))
return TRUE;
sim->ref_inputs = gnm_rangeref_dup (value_get_rangeref (sim->inputs));
......
......@@ -459,7 +459,7 @@ cb_check_name (G_GNUC_UNUSED gpointer key, GnmNamedExpr *nexpr,
v = gnm_expr_top_get_range (nexpr->texpr);
if (v != NULL) {
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
GnmRangeRef const *ref = &v->v_range.cell;
if (!ref->a.col_relative &&
!ref->b.col_relative &&
......
......@@ -674,7 +674,7 @@ gnm_expr_extract_ref (GnmRangeRef *res, GnmExpr const *expr,
v = function_call_with_exprs (&ei);
if (v != NULL) {
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
*res = v->v_range.cell;
failed = FALSE;
}
......@@ -690,7 +690,7 @@ gnm_expr_extract_ref (GnmRangeRef *res, GnmExpr const *expr,
case GNM_EXPR_OP_CONSTANT: {
GnmValue const *v = expr->constant.value;
if (v->type == VALUE_CELLRANGE) {
if (VALUE_IS_CELLRANGE (v)) {
*res = v->v_range.cell;
return FALSE;
}
......@@ -750,7 +750,7 @@ value_intersection (GnmValue *v, GnmEvalPos const *pos)
Sheet *start_sheet, *end_sheet;
gboolean found = FALSE;
if (v->type == VALUE_ARRAY) {
if (VALUE_IS_ARRAY (v)) {
res = (v->v_array.x == 0 || v->v_array.y == 0)
? value_new_error_VALUE (NULL)
: value_dup (v->v_array.vals[0][0]);
......@@ -1025,7 +1025,7 @@ bin_array_iter_a (GnmEvalPos const *ep,
* If both items have non-singular sizes for
* the same dimension use the min size (see samples/array.xls) */
if (b != NULL &&
(b->type == VALUE_CELLRANGE || b->type == VALUE_ARRAY)) {
(VALUE_IS_CELLRANGE (b) || VALUE_IS_ARRAY (b))) {
int sa, sb, w = 1, h = 1;
sa = value_area_get_width (a, ep);
......@@ -1248,7 +1248,7 @@ gnm_expr_eval (GnmExpr const *expr, GnmEvalPos const *pos,
if (a != NULL) {
if (VALUE_IS_ERROR (a))
return a;
if (a->type == VALUE_CELLRANGE || a->type == VALUE_ARRAY)
if (VALUE_IS_CELLRANGE (a) || VALUE_IS_ARRAY (a))
return bin_array_iter_a (pos, a,
gnm_expr_eval (expr->binary.value_b, pos, flags),
(BinOpImplicitIteratorFunc) cb_bin_cmp,
......@@ -1261,7 +1261,7 @@ gnm_expr_eval (GnmExpr const *expr, GnmEvalPos const *pos,
value_release (a);
return b;
}
if (b->type == VALUE_CELLRANGE || b->type == VALUE_ARRAY)
if (VALUE_IS_CELLRANGE (b) || VALUE_IS_ARRAY (b))