1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
10 /* Warning: if you add something here, see do_expr_as_string ! */
11 /* Warning: if you add something here, see ms-formula-write.c ! */
13 GNM_EXPR_OP_PAREN
, /* Parentheses for clarity */
14 GNM_EXPR_OP_EQUAL
, /* Compare value equal */
15 GNM_EXPR_OP_GT
, /* Compare value greather than */
16 GNM_EXPR_OP_LT
, /* Compare value less than */
17 GNM_EXPR_OP_GTE
, /* Compare value greather or equal than */
18 GNM_EXPR_OP_LTE
, /* Compare value less or equal than */
19 GNM_EXPR_OP_NOT_EQUAL
, /* Compare for non equivalence */
21 GNM_EXPR_OP_ADD
, /* Add */
22 GNM_EXPR_OP_SUB
, /* Subtract */
23 GNM_EXPR_OP_MULT
, /* Multiply */
24 GNM_EXPR_OP_DIV
, /* Divide */
25 GNM_EXPR_OP_EXP
, /* Exponentiate */
26 GNM_EXPR_OP_CAT
, /* String concatenation */
28 GNM_EXPR_OP_FUNCALL
, /* Function call invocation */
30 GNM_EXPR_OP_NAME
, /* Name reference */
32 GNM_EXPR_OP_CONSTANT
, /* Constant value */
33 GNM_EXPR_OP_CELLREF
, /* Cell content lookup (variable) */
34 GNM_EXPR_OP_UNARY_NEG
, /* Sign inversion */
35 GNM_EXPR_OP_UNARY_PLUS
, /* Mark as positive */
36 GNM_EXPR_OP_PERCENTAGE
, /* Percentage (value/100) */
37 GNM_EXPR_OP_ARRAY_CORNER
,/* Top Corner of an array */
38 GNM_EXPR_OP_ARRAY_ELEM
, /* General Array element */
39 GNM_EXPR_OP_SET
, /* A set of expressions */
40 GNM_EXPR_OP_RANGE_CTOR
, /* A constructed range eg A1:index(1,2) */
41 GNM_EXPR_OP_INTERSECT
/* The intersection of multiple ranges */
44 /* Shorthands for case statements. Easy to read, easy to maintain. */
45 #define GNM_EXPR_OP_ANY_BINARY GNM_EXPR_OP_EQUAL: case GNM_EXPR_OP_GT: case GNM_EXPR_OP_LT: case GNM_EXPR_OP_GTE: \
46 case GNM_EXPR_OP_LTE: case GNM_EXPR_OP_NOT_EQUAL: \
47 case GNM_EXPR_OP_ADD: case GNM_EXPR_OP_SUB: case GNM_EXPR_OP_MULT: case GNM_EXPR_OP_DIV: \
48 case GNM_EXPR_OP_EXP: case GNM_EXPR_OP_CAT
49 #define GNM_EXPR_OP_ANY_UNARY GNM_EXPR_OP_PAREN: case GNM_EXPR_OP_UNARY_NEG: case GNM_EXPR_OP_UNARY_PLUS: case GNM_EXPR_OP_PERCENTAGE
51 GType
gnm_expr_get_type (void);
52 GType
gnm_expr_array_corner_get_type (void); /* boxed type */
53 GnmExpr
const *gnm_expr_new_constant (GnmValue
*v
);
54 GnmExpr
const *gnm_expr_new_unary (GnmExprOp op
, GnmExpr
const *e
);
55 GnmExpr
const *gnm_expr_new_binary (GnmExpr
const *l
, GnmExprOp op
,
57 GnmExpr
const *gnm_expr_new_funcall (GnmFunc
*func
,
59 GnmExpr
const *gnm_expr_new_funcall1 (GnmFunc
*func
,
61 GnmExpr
const *gnm_expr_new_funcall2 (GnmFunc
*func
,
64 GnmExpr
const *gnm_expr_new_funcall3 (GnmFunc
*func
,
68 GnmExpr
const *gnm_expr_new_funcall4 (GnmFunc
*func
,
73 GnmExpr
const *gnm_expr_new_funcall5 (GnmFunc
*func
,
79 GnmExpr
const *gnm_expr_new_name (GnmNamedExpr
*name
,
80 Sheet
*sheet_scope
, Workbook
*wb_scope
);
81 GnmExpr
const *gnm_expr_new_cellref (GnmCellRef
const *cr
);
82 GnmExpr
const *gnm_expr_new_set (GnmExprList
*args
);
83 GnmExpr
const *gnm_expr_new_range_ctor (GnmExpr
const *l
, GnmExpr
const *r
);
85 GnmValue
*gnm_expr_get_range (GnmExpr
const *expr
);
86 GnmFunc
*gnm_expr_get_func_def (GnmExpr
const *expr
);
87 GnmExpr
const *gnm_expr_get_func_arg (GnmExpr
const *expr
, int i
);
89 void gnm_expr_free (GnmExpr
const *expr
);
90 GnmExpr
const *gnm_expr_copy (GnmExpr
const *expr
);
91 gboolean
gnm_expr_equal (GnmExpr
const *a
, GnmExpr
const *b
);
92 gboolean
gnm_expr_is_rangeref (GnmExpr
const *expr
);
93 gboolean
gnm_expr_is_data_table (GnmExpr
const *expr
,
94 GnmCellPos
*c_in
, GnmCellPos
*r_in
);
95 gboolean
gnm_expr_is_empty (GnmExpr
const *expr
);
97 GnmValue
const *gnm_expr_get_constant (GnmExpr
const *expr
);
99 GnmCellRef
const*gnm_expr_get_cellref (GnmExpr
const *expr
);
101 void gnm_expr_as_gstring (GnmExpr
const *expr
,
102 GnmConventionsOut
*out
);
103 char *gnm_expr_as_string (GnmExpr
const *expr
, GnmParsePos
const *pp
,
104 GnmConventions
const *convs
);
105 void gnm_expr_list_as_string (int argc
, GnmExprConstPtr
const *argv
,
106 GnmConventionsOut
*out
);
107 gboolean
gnm_expr_contains_subtotal (GnmExpr
const *expr
);
109 GnmValue
*gnm_expr_eval (GnmExpr
const *expr
, GnmEvalPos
const *pos
,
110 GnmExprEvalFlags flags
);
112 GnmExpr
const *gnm_expr_simplify_if (GnmExpr
const *expr
);
114 typedef struct GnmExprWalk_
{
118 /* Flags the walker callback can use to signal the engine. */
121 /* Internal flags. */
124 typedef GnmExpr
const * (*GnmExprWalkerFunc
) (GnmExpr
const *expr
, GnmExprWalk
*data
);
125 GnmExpr
const *gnm_expr_walk (GnmExpr
const *expr
, GnmExprWalkerFunc walker
, gpointer user
);
127 /*****************************************************************************/
129 #define gnm_expr_list_append(l,e) g_slist_append ((l), (gpointer)(e))
130 #define gnm_expr_list_prepend(l,e) g_slist_prepend ((l), (gpointer)(e))
131 #define gnm_expr_list_length(l) g_slist_length((GSList *)(l)) /* const cast */
132 #define gnm_expr_list_free g_slist_free
133 void gnm_expr_list_unref (GnmExprList
*list
);
134 GnmExprList
*gnm_expr_list_copy (GnmExprList
*list
);
136 /*****************************************************************************/
138 #define GNM_EXPR_TOP_MAGIC 0x42
139 #define GNM_IS_EXPR_TOP(et) ((et) && (et)->magic == GNM_EXPR_TOP_MAGIC)
143 unsigned hash
: 24; /* Zero meaning not yet computed. */
148 GnmExprTop
const *gnm_expr_top_new (GnmExpr
const *e
);
149 GnmExprTop
const *gnm_expr_top_new_constant (GnmValue
*v
);
150 GnmExprTop
const *gnm_expr_top_new_array_corner (int cols
, int rows
, GnmExpr
const *expr
);
151 GnmExprTop
const *gnm_expr_top_new_array_elem (int x
, int y
);
153 GType
gnm_expr_top_get_type (void);
154 void gnm_expr_top_ref (GnmExprTop
const *texpr
);
155 void gnm_expr_top_unref (GnmExprTop
const *texpr
);
156 gboolean
gnm_expr_top_equal (GnmExprTop
const *te1
, GnmExprTop
const *te2
);
157 guint
gnm_expr_top_hash (GnmExprTop
const *texpr
);
158 gboolean
gnm_expr_top_is_shared (GnmExprTop
const *texpr
);
159 gboolean
gnm_expr_top_is_err (GnmExprTop
const *texpr
, GnmStdError e
);
160 gboolean
gnm_expr_top_is_rangeref (GnmExprTop
const *texpr
);
161 gboolean
gnm_expr_top_is_array_elem (GnmExprTop
const *texpr
, int *x
, int *y
);
162 gboolean
gnm_expr_top_is_array_corner (GnmExprTop
const *texpr
);
163 gboolean
gnm_expr_top_is_array (GnmExprTop
const *texpr
);
164 void gnm_expr_top_get_array_size (GnmExprTop
const *texpr
, int *cols
, int *rows
);
165 GnmValue
*gnm_expr_top_get_array_value (GnmExprTop
const *texpr
);
166 GnmExpr
const *gnm_expr_top_get_array_expr (GnmExprTop
const *texpr
);
167 GnmValue
*gnm_expr_top_get_range (GnmExprTop
const *texpr
);
168 GSList
*gnm_expr_top_get_ranges (GnmExprTop
const *texpr
);
169 GnmValue
const *gnm_expr_top_get_constant (GnmExprTop
const *texpr
);
170 GnmCellRef
const*gnm_expr_top_get_cellref (GnmExprTop
const *texpr
);
171 void gnm_expr_top_get_boundingbox (GnmExprTop
const *texpr
,
174 gboolean
gnm_expr_top_contains_subtotal (GnmExprTop
const *texpr
);
175 gboolean
gnm_expr_top_is_volatile (GnmExprTop
const *texpr
);
176 GSList
*gnm_expr_top_referenced_sheets (GnmExprTop
const *texpr
);
177 GnmExpr
const *gnm_expr_top_first_funcall (GnmExprTop
const *texpr
);
178 GnmExprTop
const *gnm_expr_top_transpose (GnmExprTop
const *texpr
);
180 struct _GnmExprRelocateInfo
{
183 GnmRange origin
; /* References to cells in origin_sheet!range */
184 Sheet
*origin_sheet
; /* should to adjusted */
185 Sheet
*target_sheet
; /* to point at this sheet */
186 int col_offset
, row_offset
; /* and offset by this amount */
188 /* invalidate references to any sheets with
189 * Sheet::being_invalidated == TRUE */
190 GNM_EXPR_RELOCATE_INVALIDATE_SHEET
,
191 GNM_EXPR_RELOCATE_MOVE_RANGE
,
192 GNM_EXPR_RELOCATE_COLS
, /* ins/del col */
193 GNM_EXPR_RELOCATE_ROWS
/* ins/del row */
196 /* Valid for COLS/ROWS only. Assumed by MOVE_RANGE. If TRUE,
197 ranges ending at the edge of the sheet will keep the end
202 GnmExprTop
const *gnm_expr_top_relocate (GnmExprTop
const *texpr
,
203 GnmExprRelocateInfo
const *rinfo
,
204 gboolean include_rel
);
205 GnmExprTop
const * gnm_expr_top_relocate_sheet (GnmExprTop
const *texpr
,
209 GnmValue
*gnm_expr_top_eval (GnmExprTop
const *texpr
,
210 GnmEvalPos
const *pos
,
211 GnmExprEvalFlags flags
);
212 char *gnm_expr_top_as_string (GnmExprTop
const *texpr
,
213 GnmParsePos
const *pp
,
214 GnmConventions
const *convs
);
215 void gnm_expr_top_as_gstring (GnmExprTop
const *texpr
,
216 GnmConventionsOut
*out
);
218 /*****************************************************************************/
220 GType
gnm_expr_sharer_get_type (void);
221 GnmExprSharer
* gnm_expr_sharer_new (void);
222 void gnm_expr_sharer_destroy (GnmExprSharer
*es
);
223 GnmExprTop
const *gnm_expr_sharer_share (GnmExprSharer
*es
, GnmExprTop
const *texpr
);
224 void gnm_expr_sharer_report (GnmExprSharer
*es
);
226 /*****************************************************************************/
228 void _gnm_expr_init (void);
229 void _gnm_expr_shutdown (void);
233 #endif /* _GNM_EXPR_H_ */