1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
10 /* Setup of the symbol table */
11 void functions_init (void);
12 void functions_shutdown (void);
14 GPtrArray
*gnm_func_enumerate (void);
16 /******************************************************************************/
17 /* Function group support */
19 struct _GnmFuncGroup
{
20 GOString
*internal_name
, *display_name
;
21 gboolean has_translation
;
23 unsigned ref_count
; /* boxed type */
26 GType
gnm_func_group_get_type (void); /* boxed type */
27 GnmFuncGroup
*gnm_func_group_get_nth (gint n
);
28 GnmFuncGroup
*gnm_func_group_fetch (char const *name
,
29 char const *translation
);
31 /******************************************************************************/
34 * Function registration routines
36 * Functions come in two fashions: Those that only deal with
37 * very specific data types and a constant number of arguments,
38 * and those who don't.
40 * The former kind of functions receives a precomputed array of
43 * The latter sort of functions receives the plain ExprNodes and
44 * it is up to that routine to do the value computations and range
49 * Argument tokens passed in 'args'
51 * With intersection and iteration support
52 * f : floating point (no errors, string conversion attempted)
53 * b : boolean (identical to f, Do we need this ?)
54 * s : string (no errors)
55 * S : 'scalar': any non-error value
56 * E : scalar including errors
57 * Without intersection or iteration support
58 * r : cell range content is _NOT_ guaranteed to have been evaluated yet
59 * A : area either range or array (as above)
63 * For optional arguments do:
64 * "ff|ss" where the strings are optional
68 GNM_FUNC_TYPE_ARGS
, /* Arguments get marshalled by type */
69 GNM_FUNC_TYPE_NODES
, /* Takes unevaulated expers directly */
71 /* implementation has not been loaded yet, but we know where it is */
77 GNM_FUNC_VOLATILE
= 1 << 0, /* eg now(), today() */
78 GNM_FUNC_RETURNS_NON_SCALAR
= 1 << 1, /* eg transpose(), mmult() */
80 /* For functions that are not exactly compatible with various import
81 * formats. We need to recalc their results to avoid changing values
82 * unexpectedly when we recalc later. This probably needs to be done
83 * on a per import format basis. It may not belong here.
85 /* GNM_FUNC_RECALC_ONLOAD = 1 << 2, */
87 /* an unknown function that will hopefully be defined later */
88 GNM_FUNC_IS_PLACEHOLDER
= 1 << 3,
89 GNM_FUNC_IS_WORKBOOK_LOCAL
= 1 << 5,
90 GNM_FUNC_INTERNAL
= 1 << 6,
92 GNM_FUNC_AUTO_UNKNOWN
= 0 << 8,
93 GNM_FUNC_AUTO_MONETARY
= 1 << 8, /* Like PV */
94 GNM_FUNC_AUTO_DATE
= 2 << 8, /* Like DATE */
95 GNM_FUNC_AUTO_TIME
= 3 << 8, /* Like TIME */
96 GNM_FUNC_AUTO_PERCENT
= 4 << 8, /* Like IRR */
97 GNM_FUNC_AUTO_FIRST
= 5 << 8, /* Like SUM */
98 GNM_FUNC_AUTO_SECOND
= 6 << 8, /* Like IF */
99 GNM_FUNC_AUTO_UNITLESS
= 7 << 8, /* Like COUNT */
100 GNM_FUNC_AUTO_MASK
= 7 << 8 /* The bits we use for AUTO. */
103 /* I do not like this. It is going to be different for different apps probably
104 * want to split it into bit file with our notion of its state, and 2 bits of
105 * state per import format.
108 GNM_FUNC_IMPL_STATUS_EXISTS
= 0,
109 GNM_FUNC_IMPL_STATUS_UNIMPLEMENTED
,
110 GNM_FUNC_IMPL_STATUS_SUBSET
,
111 GNM_FUNC_IMPL_STATUS_COMPLETE
,
112 GNM_FUNC_IMPL_STATUS_SUPERSET
,
113 GNM_FUNC_IMPL_STATUS_SUBSET_WITH_EXTENSIONS
,
114 GNM_FUNC_IMPL_STATUS_UNDER_DEVELOPMENT
,
115 GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC
119 GNM_FUNC_TEST_STATUS_UNKNOWN
= 0,
120 GNM_FUNC_TEST_STATUS_NO_TESTSUITE
,
121 GNM_FUNC_TEST_STATUS_BASIC
,
122 GNM_FUNC_TEST_STATUS_EXHAUSTIVE
,
123 GNM_FUNC_TEST_STATUS_UNDER_DEVELOPMENT
126 typedef GnmValue
*(*GnmFuncArgs
) (GnmFuncEvalInfo
*ei
, GnmValue
const * const *args
);
127 typedef GnmValue
*(*GnmFuncNodes
) (GnmFuncEvalInfo
*ei
,
128 int argc
, GnmExprConstPtr
const *argv
);
129 typedef GnmDependentFlags (*GnmFuncLink
) (GnmFuncEvalInfo
*ei
, gboolean qlink
);
131 typedef void (*GnmFuncUsageNotify
) (GnmFunc
*f
, int refcount
);
132 typedef gboolean (*GnmFuncLoadDesc
) (GnmFunc
const *f
, GnmFuncDescriptor
*fd
);
135 GNM_FUNC_HELP_END
, /* Format */
138 /* <NAME>:<1 SENTENCE DESCRIPTION> (translated) */
141 /* <NAME>:<1 SENTENCE DESCRIPTION> (translated) */
143 GNM_FUNC_HELP_DESCRIPTION
,
144 /* <LONG DESCRIPTION (reference args using @{arg})> (translated) */
147 /* <SPECIAL CASES (reference args using @{arg})> (translated) */
149 GNM_FUNC_HELP_EXAMPLES
,
151 * Either translated text, or a formula that is only marked for
152 * translation if it contains strings that need to be translated.
155 GNM_FUNC_HELP_SEEALSO
,
156 /* name,name,name ... (not translated) */
158 GNM_FUNC_HELP_EXTREF
,
160 * Link to external descriptions. The following styles defined:
162 * wiki:en:Trigonometric_functions
166 /* <SPECIAL NOTE RE EXCEL (reference args using @{arg})> (translated) */
169 /* <SPECIAL NOTE RE ODF (reference args using @{arg})> (translated) */
172 GnmFuncHelpType type
;
176 struct _GnmFuncDescriptor
{
178 char const *arg_spec
;
179 GnmFuncHelp
const *help
;
181 GnmFuncNodes fn_nodes
;
183 GnmFuncUsageNotify usage_notify
;
185 GnmFuncImplStatus impl_status
;
186 GnmFuncTestStatus test_status
;
191 GPtrArray
*arg_names_p
;
192 GnmFuncHelp
const *help
;
194 char *localized_name
;
199 char const *arg_spec
;
201 int min_args
, max_args
;
204 GnmFuncLoadDesc load_desc
;
206 GnmFuncGroup
*fn_group
; /* most recent it was assigned to */
208 GnmFuncUsageNotify usage_notify
;
209 GnmFuncImplStatus impl_status
;
210 GnmFuncTestStatus test_status
;
217 struct _GnmFuncEvalInfo
{
218 GnmEvalPos
const *pos
;
219 GnmExprFunction
const *func_call
;
220 GnmExprEvalFlags flags
;
223 GnmFunc
const *gnm_eval_info_get_func (GnmFuncEvalInfo
const *ei
);
224 int gnm_eval_info_get_arg_count (GnmFuncEvalInfo
const *ei
);
227 GType
gnm_func_get_type (void);
228 void gnm_func_free (GnmFunc
*func
);
229 GnmFunc
*gnm_func_ref (GnmFunc
*func
);
230 void gnm_func_unref (GnmFunc
*func
);
231 void gnm_func_load_if_stub (GnmFunc
*func
);
232 void gnm_func_load_stub (GnmFunc
*fn_def
);
233 char const *gnm_func_get_name (GnmFunc
const *func
,
235 gpointer
gnm_func_get_user_data (GnmFunc
const *func
);
236 void gnm_func_set_user_data (GnmFunc
*func
, gpointer user_data
);
237 GnmFunc
*gnm_func_lookup (char const *name
, Workbook
*scope
);
238 GnmFunc
*gnm_func_lookup_localized (char const *name
, Workbook
*scope
);
239 GSList
*gnm_func_lookup_prefix (char const *prefix
, Workbook
*scope
,
241 GnmFunc
*gnm_func_add (GnmFuncGroup
*group
,
242 GnmFuncDescriptor
const *descriptor
,
243 const char *tdomain
);
244 GnmFunc
*gnm_func_add_placeholder (Workbook
*optional_scope
,
247 GnmFunc
*gnm_func_add_placeholder_localized (char const *gname
, char const *lname
);
248 GnmFunc
*gnm_func_lookup_or_add_placeholder (char const *name
);
249 void gnm_func_upgrade_placeholder
251 GnmFuncGroup
*fn_group
,
253 GnmFuncLoadDesc load_desc
,
254 GnmFuncUsageNotify opt_usage_notify
);
257 char const *gnm_func_get_description (GnmFunc
const *fn_def
);
258 void gnm_func_count_args (GnmFunc
const *fn_def
,
259 gint
*min
, int *max
);
260 char gnm_func_get_arg_type (GnmFunc
const *fn_def
,
262 char const *gnm_func_get_arg_type_string (GnmFunc
const *fn_def
,
264 char *gnm_func_get_arg_name (GnmFunc
const *fn_def
,
266 char const *gnm_func_get_arg_description (GnmFunc
const *fn_def
,
268 char *gnm_func_convert_markup_to_pango (char const *desc
,
271 /*************************************************************************/
273 GnmValue
*function_call_with_exprs (GnmFuncEvalInfo
*ei
);
274 GnmValue
*function_call_with_values (GnmEvalPos
const *ep
, char const *name
,
275 int argc
, GnmValue
const * const *values
);
276 GnmValue
*function_def_call_with_values (GnmEvalPos
const *ep
, GnmFunc
const *fn
,
277 int argc
, GnmValue
const * const *values
);
279 /* Utilies to interate through ranges and argument lists */
280 typedef GnmValue
* (*FunctionIterateCB
) (GnmEvalPos
const *ep
, GnmValue
const *value
,
282 GnmValue
*function_iterate_argument_values (GnmEvalPos
const *ep
,
283 FunctionIterateCB callback
,
284 gpointer callback_closure
,
286 GnmExprConstPtr
const *argv
,
288 CellIterFlags iter_flags
);
292 #endif /* _GNM_FUNC_H_ */