Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libdss/cx.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2002-2012 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* C expression library interface
23
*
24
* Glenn Fowler
25
* AT&T Research
26
*/
27
28
#ifndef _CX_H
29
#define _CX_H
30
31
#include <ast.h>
32
#include <math.h>
33
#include <dt.h>
34
#include <vmalloc.h>
35
36
#define CX_ID "cx"
37
#define CX_VERSION 20110811L
38
39
/* Cx_t.flags */
40
41
#define CX_DEBUG (1<<0) /* debug trace */
42
#define CX_QUIET (1<<1) /* no non-fatal messages*/
43
#define CX_REGRESS (1<<2) /* regression output */
44
#define CX_TRACE (1<<3) /* algorithm trace */
45
#define CX_VALIDATE (1<<4) /* validate constraints */
46
#define CX_VERBOSE (1<<5) /* verbose feedback */
47
48
#define CX_BALANCED (1<<6) /* cx input () balanced */
49
#define CX_INCLUDE (1<<7) /* include cxpush() */
50
#define CX_FLAGS (1L<<8) /* first caller flag */
51
52
/* _CX_HEADER_.flags */
53
54
#define CX_NORMALIZED 0x0001
55
#define CX_INITIALIZED 0x0002
56
#define CX_REFERENCED 0x0004
57
#define CX_DEPRECATED 0x0008
58
#define CX_IGNORECASE 0x0100
59
60
/* Cxpart_t.flags */
61
62
#define CX_ALL 0x0001
63
64
/* Cxtype_t.representation */
65
66
#define CX_void 0
67
#define CX_number 1
68
#define CX_string 2
69
#define CX_pointer 3
70
#define CX_reference 4
71
#define CX_buffer 5 /* allocated separately */
72
#define CX_type 6
73
74
/* Cxformat_t.flags */
75
76
#define CX_STRING 0x0001
77
#define CX_INTEGER 0x0002
78
#define CX_UNSIGNED 0x0004
79
#define CX_FLOAT 0x0008
80
#define CX_BUFFER 0x0010
81
#define CX_BINARY 0x0020
82
#define CX_MULTIPLE 0x0100
83
#define CX_FREE 0x0200
84
#define CX_NUL 0x0400
85
#define CX_VARIABLE 0x0800
86
#define CX_QUOTEALL 0x1000
87
#define CX_LONG 0x2000
88
89
#define CX_ASSIGN 01
90
#define CX_X2 02
91
#define CX_UNARY 04
92
#define CX_ATTR 3
93
94
#define CX_OPNAME "0+&/>~<~%*!|-^CDeGLnpRJSst"
95
96
#define CX_NOP (( 0))
97
98
#define CX_ADD (( 1<<CX_ATTR))
99
#define CX_AND (( 2<<CX_ATTR))
100
#define CX_DIV (( 3<<CX_ATTR))
101
#define CX_GT (( 4<<CX_ATTR))
102
#define CX_INV (( 5<<CX_ATTR)|CX_UNARY)
103
#define CX_LT (( 6<<CX_ATTR))
104
#define CX_MAT (( 7<<CX_ATTR))
105
#define CX_MOD (( 8<<CX_ATTR))
106
#define CX_MPY (( 9<<CX_ATTR))
107
#define CX_NOT ((10<<CX_ATTR)|CX_UNARY)
108
#define CX_OR ((11<<CX_ATTR))
109
#define CX_SUB ((12<<CX_ATTR))
110
#define CX_XOR ((13<<CX_ATTR))
111
112
#define CX_CALL ((14<<CX_ATTR)|CX_UNARY)
113
#define CX_DEL ((15<<CX_ATTR))
114
#define CX_END ((16<<CX_ATTR))
115
#define CX_GET ((17<<CX_ATTR)|CX_UNARY)
116
#define CX_LOG ((18<<CX_ATTR)|CX_UNARY)
117
#define CX_NUM ((19<<CX_ATTR))
118
#define CX_POP ((20<<CX_ATTR))
119
#define CX_REF (CX_AND|CX_UNARY)
120
#define CX_RET ((21<<CX_ATTR)|CX_UNARY)
121
#define CX_SC0 ((22<<CX_ATTR))
122
#define CX_SC1 (CX_SC0|CX_X2)
123
#define CX_SET ((23<<CX_ATTR)|CX_ASSIGN)
124
#define CX_STR ((24<<CX_ATTR))
125
#define CX_TST ((25<<CX_ATTR))
126
#define CX_OPERATORS ((26<<CX_ATTR))
127
128
#define CX_CAST (CX_SET|CX_UNARY)
129
#define CX_EQ (CX_SET|CX_X2)
130
#define CX_ANDAND (CX_AND|CX_X2)
131
#define CX_OROR (CX_OR|CX_X2)
132
#define CX_LSH (CX_LT|CX_X2)
133
#define CX_RSH (CX_GT|CX_X2)
134
#define CX_UPLUS (CX_ADD|CX_UNARY)
135
#define CX_UMINUS (CX_SUB|CX_UNARY)
136
137
#define CX_MATCH (CX_MAT|CX_ASSIGN)
138
#define CX_NOMATCH (CX_MAT)
139
140
#define CX_GE (CX_GT|CX_ASSIGN)
141
#define CX_LE (CX_LT|CX_ASSIGN)
142
#define CX_NE ((CX_NOT&~CX_UNARY)|CX_ASSIGN)
143
144
#define CX_CTYPE_ALPHA (1<<0)
145
#define CX_CTYPE_DIGIT (1<<1)
146
#define CX_CTYPE_FLOAT (1<<2)
147
#define CX_CTYPE_SPACE (1<<3)
148
149
#define CXMIN(a,b) (((a)<(b))?(a):(b))
150
#define CXMAX(a,b) (((a)>(b))?(a):(b))
151
152
#define CXINTEGER(n) ((Cxinteger_t)(n))
153
#define CXUNSIGNED(n) ((Cxunsigned_t)CXINTEGER(n))
154
155
#define CXDETAILS(d,f,t,v) \
156
((d)?(d):((d)=(f)&&(f)->details?(f)->details:(t)->format.details?(t)->format.details:(v)))
157
158
#define CX_HEADER_INIT {{0},0}
159
#define CX_CALLOUT_INIT(op,type1,type2,callout,description) \
160
{0,description,CX_HEADER_INIT,op,(Cxtype_t*)type1,(Cxtype_t*)type2,callout},
161
#define CX_FUNCTION_INIT(name,type,function,prototype,description) \
162
{name,description,CX_HEADER_INIT,function,(Cxtype_t*)type,prototype},
163
#define CX_RECODE_INIT(op,type1,type2,recode,description) \
164
{0,description,CX_HEADER_INIT,op,(Cxtype_t*)type1,(Cxtype_t*)type2,recode},
165
#define CX_TYPE_INIT(name,base,external,internal,match,description) \
166
{name,description,CX_HEADER_INIT,(Cxtype_t*)base,0,external,internal,0,0,0,0,CX_HEADER_INIT,match},
167
#define CX_VARIABLE_INIT(name,type,index,description) \
168
{name,description,CX_HEADER_INIT,0,(Cxtype_t*)type,0,index},
169
170
#define cxrepresentation(t) ((t)->representation)
171
#define cxisbuffer(t) (cxrepresentation(t)==CX_buffer)
172
#define cxisnumber(t) (cxrepresentation(t)==CX_number)
173
#define cxisstring(t) (cxrepresentation(t)==CX_string)
174
#define cxisvoid(t) (cxrepresentation(t)==CX_void)
175
176
#define cxsize(t,v) ((cxisstring(t)||cxisbuffer(t))?((v)->buffer.size):0)
177
178
#if ! _ast_fltmax_double
179
#undef strtod
180
#define strtod(a,b) strtold(a,b)
181
#undef strntod
182
#define strntod(a,b,c) strntold(a,b,c)
183
#endif
184
185
typedef _ast_fltmax_t Cxnumber_t;
186
typedef uint32_t Cxflags_t;
187
typedef intmax_t Cxinteger_t;
188
typedef uintmax_t Cxunsigned_t;
189
190
struct Cx_s; typedef struct Cx_s Cx_t;
191
struct Cxarray_s; typedef struct Cxarray_s Cxarray_t;
192
struct Cxconstraint_s; typedef struct Cxconstraint_s Cxconstraint_t;
193
struct Cxdisc_s; typedef struct Cxdisc_s Cxdisc_t;
194
struct Cxedit_s; typedef struct Cxedit_s Cxedit_t;
195
struct Cxexpr_s; typedef struct Cxexpr_s Cxexpr_t;
196
struct Cxformat_s; typedef struct Cxformat_s Cxformat_t;
197
struct Cxinstruction_s; typedef struct Cxinstruction_s Cxinstruction_t;
198
struct Cxitem_s; typedef struct Cxitem_s Cxitem_t;
199
struct Cxlib_s; typedef struct Cxlib_s Cxlib_t;
200
struct Cxmatch_s; typedef struct Cxmatch_s Cxmatch_t;
201
struct Cxmap_s; typedef struct Cxmap_s Cxmap_t;
202
struct Cxmember_s; typedef struct Cxmember_s Cxmember_t;
203
struct Cxop_s; typedef struct Cxop_s Cxop_t;
204
struct Cxoperand_s; typedef struct Cxoperand_s Cxoperand_t;
205
struct Cxpart_s; typedef struct Cxpart_s Cxpart_t;
206
struct Cxquery_s; typedef struct Cxquery_s Cxquery_t;
207
struct Cxreference_s; typedef struct Cxreference_s Cxreference_t;
208
struct Cxstate_s; typedef struct Cxstate_s Cxstate_t;
209
struct Cxstructure_s; typedef struct Cxstructure_s Cxstructure_t;
210
struct Cxtype_s; typedef struct Cxtype_s Cxtype_t;
211
struct Cxvariable_s; typedef struct Cxvariable_s Cxvariable_t;
212
213
struct Cxop_s /* callout/recode op */
214
{
215
int code; /* op code */
216
Cxtype_t* type1; /* operand 1 type */
217
Cxtype_t* type2; /* operand 2 type */
218
};
219
220
#define _CX_HEADER_ \
221
const char* name; /* key name */ \
222
const char* description; /* description */
223
224
#define _CX_HEADER_LINK_ \
225
Dtlink_t link; /* dictionary link */ \
226
uint16_t flags; /* CX_INITIALIZED|CX_REFERENCED */ \
227
uint16_t index; /* member index */
228
229
#define _CX_NAME_HEADER_ \
230
_CX_HEADER_ \
231
struct \
232
{ \
233
_CX_HEADER_LINK_ \
234
} header;
235
236
#define _CX_LIST_HEADER_ \
237
_CX_HEADER_ \
238
struct \
239
{ \
240
_CX_HEADER_LINK_ \
241
Dtlink_t list; \
242
} header;
243
244
#define _CX_CODE_HEADER_ \
245
_CX_NAME_HEADER_ \
246
Cxop_t op; /* operator */
247
248
typedef struct Cxheader_s /* name/description header */
249
{
250
_CX_HEADER_
251
} Cxheader_t;
252
253
typedef struct Cxnameheader_s /* name key dict element header */
254
{
255
_CX_NAME_HEADER_
256
} Cxnameheader_t;
257
258
typedef struct Cxlistheader_s /* list key dict element header */
259
{
260
_CX_LIST_HEADER_
261
} Cxlistheader_t;
262
263
typedef struct Cxcodeheader_s /* code key dict element header */
264
{
265
_CX_CODE_HEADER_
266
} Cxcodeheader_t;
267
268
typedef struct Cxbuffer_s /* buffer type */
269
{
270
void* data; /* data pointer */
271
uint32_t size; /* data size */
272
uint32_t elements; /* sizeof() elements */
273
} Cxbuffer_t;
274
275
typedef struct Cxstring_s /* string type */
276
{
277
char* data; /* data pointer */
278
size_t size; /* data size */
279
} Cxstring_t;
280
281
typedef union Cxvalue_u /* fundamental types */
282
{
283
Cxbuffer_t buffer; /* sized buffer */
284
Cxnumber_t number; /* long/double number */
285
void* pointer; /* generic pointer */
286
Cxstring_t string; /* 0-terminated string */
287
Cxtype_t* type; /* type */
288
Cxvariable_t* variable; /* variable reference */
289
} Cxvalue_t;
290
291
typedef int (*Cxcallout_f) (Cx_t*, Cxinstruction_t*, Cxoperand_t*,
292
Cxoperand_t*, Cxoperand_t*, void*, Cxdisc_t*);
293
typedef int (*Cxconstraint_f)(Cx_t*, Cxvalue_t*, void*, Cxdisc_t*);
294
typedef int (*Cxdone_f) (Cx_t*, void*, Cxdisc_t*);
295
typedef ssize_t (*Cxexternal_f) (Cx_t*, Cxtype_t*, const char*, Cxformat_t*,
296
Cxvalue_t*, char*, size_t, Cxdisc_t*);
297
typedef int (*Cxfunction_f) (Cx_t*, Cxvariable_t*, Cxoperand_t*,
298
Cxoperand_t*, int, void*, Cxdisc_t*);
299
typedef void* (*Cxinit_f) (void*, Cxdisc_t*);
300
typedef ssize_t (*Cxinternal_f) (Cx_t*, Cxtype_t*, const char*, Cxformat_t*,
301
Cxoperand_t*, const char*, size_t, Vmalloc_t*,
302
Cxdisc_t*);
303
typedef Cxlib_t*(*Cxload_f) (const char*, Cxdisc_t*);
304
typedef char* (*Cxlocation_f) (Cx_t*, void*, Cxdisc_t*);
305
typedef void* (*Cxmatchcomp_f)(Cx_t*, Cxtype_t*, Cxtype_t*, Cxvalue_t*, Cxdisc_t*);
306
typedef int (*Cxmatchexec_f)(Cx_t*, void*, Cxtype_t*, Cxvalue_t*, Cxdisc_t*);
307
typedef int (*Cxmatchfree_f)(Cx_t*, void*, Cxdisc_t*);
308
typedef char* (*Cxnum2str_f) (Cx_t*, Cxunsigned_t, Cxdisc_t*);
309
typedef int (*Cxquery_f) (Cx_t*, Cxexpr_t*, void*, Cxdisc_t*);
310
typedef int (*Cxrecode_f) (Cx_t*, Cxexpr_t*, Cxinstruction_t*,
311
Cxinstruction_t*, Cxinstruction_t*, void*,
312
Cxdisc_t*);
313
typedef int (*Cxstr2num_f) (Cx_t*, const char*, size_t, Cxunsigned_t*, Cxdisc_t*);
314
315
struct Cxoperand_s /* expression operand */
316
{
317
Cxtype_t* type; /* type */
318
int refs; /* reference count */
319
Cxvalue_t value; /* value */
320
};
321
322
struct Cxitem_s /* map item */
323
{
324
Cxitem_t* next; /* next item */
325
const char* name; /* item name */
326
Cxunsigned_t mask; /* local mask */
327
Cxunsigned_t value; /* item value */
328
Cxmap_t* map; /* optional map on value match */
329
#ifdef _CX_ITEM_PRIVATE_
330
_CX_ITEM_PRIVATE_
331
#endif
332
};
333
334
struct Cxedit_s /* edit list element */
335
{
336
_CX_NAME_HEADER_
337
Cxedit_t* next; /* next in list */
338
Cxinit_f initf; /* called at cxaddedit() */
339
Cxnum2str_f num2strf; /* num=>str function */
340
Cxstr2num_f str2numf; /* str=>num function */
341
void* data; /* private data */
342
#ifdef _CX_EDIT_PRIVATE_
343
_CX_EDIT_PRIVATE_
344
#endif
345
};
346
347
struct Cxpart_s /* map part */
348
{
349
Cxpart_t* next; /* next part */
350
Cxunsigned_t shift; /* local shift */
351
Cxunsigned_t mask; /* local mask */
352
Cxitem_t* item; /* item list */
353
Cxflags_t flags; /* flags */
354
Cxtype_t* type; /* item value type */
355
Cxedit_t* num2str; /* num=>str edit list */
356
Cxedit_t* str2num; /* str=>num edit list */
357
Cxedit_t* edit; /* str=>str edit list */
358
};
359
360
struct Cxmap_s /* str<=>num map */
361
{
362
_CX_NAME_HEADER_
363
Cxunsigned_t shift; /* global shift */
364
Cxunsigned_t mask; /* global mask */
365
Cxpart_t* part; /* part list */
366
Dt_t* str2num; /* str=>num dict */
367
Dt_t* num2str; /* pure value num=>str dict */
368
Cxmap_t* map; /* indirect reference */
369
};
370
371
struct Cxconstraint_s /* value constraints */
372
{
373
_CX_NAME_HEADER_
374
Cxinit_f initf; /* called at cxaddconstraint() */
375
Cxconstraint_f constraintf; /* external constraint function */
376
Cxvalue_t* def; /* default value */
377
Cxvalue_t* min; /* numeric minimum */
378
Cxvalue_t* max; /* numeric maximum */
379
const char* expression; /* expression on ``.'' */
380
const char* pattern; /* string match pattern */
381
void* data; /* private data */
382
#ifdef _CX_CONSTRAINT_PRIVATE_
383
_CX_CONSTRAINT_PRIVATE_
384
#endif
385
};
386
387
struct Cxformat_s /* format info */
388
{
389
const char* description; /* external details description */
390
char* details; /* default external details */
391
unsigned short flags; /* flags */
392
short width; /* width in bytes */
393
short print; /* print width hint */
394
short base; /* base */
395
short fill; /* fill character */
396
short code; /* code set */
397
short delimiter; /* delimiter */
398
short escape; /* escape */
399
short quotebegin; /* quotebegin */
400
short quoteend; /* quoteend */
401
short fixedpoint; /* fixed point width */
402
short unused; /* not used */
403
Cxmap_t* map; /* str<=>num map */
404
Cxconstraint_t* constraint; /* value constraints */
405
};
406
407
struct Cxreference_s /* member reference */
408
{
409
Cxreference_t* next; /* submember */
410
Cxvariable_t* variable; /* member variable */
411
Cxmember_t* member; /* member info */
412
};
413
414
struct Cxarray_s /* array info */
415
{
416
Cxvariable_t* variable; /* variable size value */
417
size_t size; /* fixed or max size */
418
short delimiter; /* value delimiter */
419
};
420
421
struct Cxstructure_s /* structure info */
422
{
423
Cxvariable_t* parent; /* parent structure */
424
Cxvariable_t* members; /* member list (children) */
425
Cxvariable_t* next; /* next member (sibling) */
426
size_t size; /* size */
427
int level; /* structure level */
428
};
429
430
struct Cxvariable_s /* variable info */
431
{
432
_CX_LIST_HEADER_
433
Cxfunction_f function; /* pointer if function */
434
Cxtype_t* type; /* value type */
435
const char* prototype; /* (proto)type name */
436
unsigned long index; /* caller defined index */
437
Cxformat_t format; /* format info */
438
void* data; /* caller defined data */
439
Cxreference_t* reference; /* member reference list */
440
Cxtype_t* member; /* member type */
441
Cxarray_t* array; /* array info */
442
Cxstructure_t* structure; /* structure info */
443
};
444
445
struct Cxmatch_s /* type match info */
446
{
447
_CX_NAME_HEADER_
448
Cxmatchcomp_f compf; /* match pattern compile */
449
Cxmatchexec_f execf; /* match pattern exec */
450
Cxmatchfree_f freef; /* match pattern free */
451
};
452
453
struct Cxmember_s /* type member info */
454
{
455
Cxcallout_f getf; /* get member value */
456
Cxcallout_f setf; /* set member value */
457
Dt_t* members; /* Cxvariable_t member dict */
458
};
459
460
struct Cxtype_s /* type info */
461
{
462
_CX_NAME_HEADER_
463
Cxtype_t* base; /* base type */
464
Cxinit_f initf; /* called at cxaddtype() */
465
Cxexternal_f externalf; /* internal => external */
466
Cxinternal_f internalf; /* external => internal */
467
unsigned short representation; /* fundamental type index */
468
unsigned short index; /* caller defined index */
469
unsigned short size; /* sizeof() size in bytes */
470
unsigned short element; /* element size in bytes */
471
Cxformat_t format; /* format defaults */
472
Cxmatch_t* match; /* match info */
473
Cxmember_t* member; /* member info */
474
Cxtype_t** generic; /* generic implementation table */
475
Cxtype_t* fundamental; /* fundamental type */
476
void* data; /* private data */
477
};
478
479
typedef struct Cxcallout_s /* op code callout */
480
{
481
_CX_CODE_HEADER_
482
Cxcallout_f callout; /* callout function */
483
} Cxcallout_t;
484
485
typedef struct Cxrecode_s /* recode callout */
486
{
487
_CX_CODE_HEADER_
488
Cxrecode_f recode; /* callout function */
489
} Cxrecode_t;
490
491
struct Cxinstruction_s /* parsed instruction */
492
{
493
int op; /* op code */
494
int pp; /* stack push(>0) pop(<0) count */
495
Cxtype_t* type; /* return type */
496
Cxvalue_t data; /* optional data */
497
Cxcallout_f callout; /* callout function */
498
};
499
500
struct Cxdisc_s /* user discipline */
501
{
502
unsigned long version; /* interface version */
503
Error_f errorf; /* error function */
504
Cxload_f loadf; /* library load function */
505
Cxlocation_f locationf; /* input location function */
506
const char* ps1; /* primary prompt */
507
const char* ps2; /* secondary prompt */
508
const char* map; /* map file */
509
};
510
511
struct Cxquery_s /* query */
512
{
513
_CX_NAME_HEADER_
514
Cxquery_f beg; /* called before first eval */
515
Cxquery_f sel; /* select current data */
516
Cxquery_f act; /* act on selected data */
517
Cxquery_f end; /* called after last eval */
518
const char* method; /* caller specific method match */
519
Cxquery_f ref; /* compile-time reference */
520
#ifdef _CX_QUERY_PRIVATE_
521
_CX_QUERY_PRIVATE_
522
#endif
523
};
524
525
struct Cxmeth_s; typedef struct Cxmeth_s Cxmeth_t;
526
527
struct Cxlib_s /* Cxdisc_t.loadf library info */
528
{
529
_CX_NAME_HEADER_
530
const char** libraries; /* library list */
531
Cxmeth_t* meth; /* caller method */
532
Cxtype_t* types; /* type table */
533
Cxcallout_t* callouts; /* callout table */
534
Cxrecode_t* recodes; /* recode table */
535
Cxmap_t** maps; /* map table */
536
Cxquery_t* queries; /* query table */
537
Cxconstraint_t* constraints; /* constraint table */
538
Cxedit_t* edits; /* edit table */
539
Cxvariable_t* functions; /* function table */
540
541
void* pad[7]; /* pad for future expansion */
542
543
/* the remaining are set by Cxdisc_t.loadf */
544
545
const char* path; /* library path name */
546
};
547
548
struct Cxexpr_s /* compiled expression node */
549
{
550
Cxexpr_t* parent; /* parent */
551
Cxexpr_t* group; /* group */
552
Cxexpr_t* next; /* next sibling */
553
Cxexpr_t* pass; /* pass branch */
554
Cxexpr_t* fail; /* fail branch */
555
Cxquery_t* query; /* query callouts */
556
const char* file; /* output file */
557
Sfio_t* op; /* output stream for file */
558
void* data; /* query private data */
559
char** argv; /* query argv */
560
Cxunsigned_t queried; /* # records queried */
561
Cxunsigned_t selected; /* # records selected */
562
#ifdef _CX_EXPR_PRIVATE_
563
_CX_EXPR_PRIVATE_
564
#endif
565
};
566
567
struct Cxstate_s /* cx library global state */
568
{
569
Dt_t* libraries; /* Dsslib_t dictionary (ouch) */
570
Dt_t* methods; /* Cxnameheader_t dictionary */
571
Dt_t* types; /* Cxtype_t dictionary */
572
Dt_t* callouts; /* Cxcallout_t dictionary */
573
Dt_t* recodes; /* Cxrecode_t dictionary */
574
Dt_t* maps; /* Cxmap_t dictionary */
575
Dt_t* queries; /* Cxquery_t dictionary */
576
Dt_t* constraints; /* Cxconstraint_t dictionary */
577
Dt_t* edits; /* Cxedit_t dictionary */
578
Dt_t* variables; /* Cxvariable_t dictionary */
579
Cxtype_t* type_buffer; /* buffer fundamental type */
580
Cxtype_t* type_number; /* number fundamental type */
581
Cxtype_t* type_reference; /* reference fundamental type */
582
Cxtype_t* type_string; /* string fundamental type */
583
Cxtype_t* type_type_t; /* type */
584
Cxtype_t* type_void; /* void fundamental type */
585
#ifdef _CX_STATE_PRIVATE_
586
_CX_STATE_PRIVATE_
587
#endif
588
};
589
590
struct Cx_s /* interface handle */
591
{
592
const char* id; /* interface id */
593
Vmalloc_t* vm; /* handle memory */
594
Vmalloc_t* em; /* eval memory */
595
Vmalloc_t* rm; /* record memory */
596
Cxflags_t flags; /* CX_* flags */
597
Cxflags_t test; /* test mask */
598
int eof; /* input at eof */
599
int error; /* error occurred */
600
int interactive; /* interactive input */
601
Cxstate_t* state; /* global state */
602
Cxdisc_t* disc; /* user discipline */
603
Sfio_t* buf; /* tmp buffer stream */
604
void* caller; /* caller defined handle */
605
Dt_t* variables; /* sorted variable symbol table */
606
Dt_t* fields; /* order variable field list */
607
Dt_t* types; /* Cxtype_t dictionary */
608
Dt_t* callouts; /* Cxcallout_t dictionary */
609
Dt_t* recodes; /* Cxrecode_t dictionary */
610
Dt_t* maps; /* Cxmap_t dictionary */
611
Dt_t* queries; /* Cxquery_t dictionary */
612
Dt_t* constraints; /* Cxconstraint_t dictionary */
613
Dt_t* edits; /* Cxedit_t dictionary */
614
Cx_t* scope; /* next scope */
615
unsigned char* ctype; /* ctype table */
616
#ifdef _CX_PRIVATE_
617
_CX_PRIVATE_
618
#endif
619
};
620
621
#define cxinit(d,e) (memset(d,0,sizeof(Cxdisc_t)),(d)->version=CX_VERSION,(d)->errorf=(Error_f)(e),cxstate(d))
622
623
#if _BLD_cx && defined(__EXPORT__)
624
#define extern __EXPORT__
625
#endif
626
627
extern Cxstate_t* cxstate(Cxdisc_t*);
628
629
extern Cx_t* cxopen(Cxflags_t, Cxflags_t, Cxdisc_t*);
630
extern Cx_t* cxscope(Cx_t*, Cx_t*, Cxflags_t, Cxflags_t, Cxdisc_t*);
631
extern int cxclose(Cx_t*);
632
633
extern void* cxpush(Cx_t*, const char*, Sfio_t*, const char*, ssize_t, Cxflags_t);
634
extern int cxpop(Cx_t*, void*);
635
extern ssize_t cxtell(Cx_t*);
636
extern Cxexpr_t* cxcomp(Cx_t*);
637
extern int cxbeg(Cx_t*, Cxexpr_t*, const char*);
638
extern int cxeval(Cx_t*, Cxexpr_t*, void*, Cxoperand_t*);
639
extern int cxend(Cx_t*, Cxexpr_t*);
640
extern int cxlist(Cx_t*, Cxexpr_t*, Sfio_t*);
641
extern int cxfree(Cx_t*, Cxexpr_t*);
642
extern int cxcast(Cx_t*, Cxoperand_t*, Cxvariable_t*, Cxtype_t*, void*, const char*);
643
extern size_t cxsizeof(Cx_t*, Cxvariable_t*, Cxtype_t*, Cxvalue_t*);
644
645
extern char* cxcontext(Cx_t*);
646
extern char* cxlocation(Cx_t*, void*);
647
648
extern void cxcodetrace(Cx_t*, const char*, Cxinstruction_t*, unsigned int, Cxoperand_t*, Cxoperand_t*);
649
extern char* cxcodename(int);
650
extern char* cxopname(int, Cxtype_t*, Cxtype_t*);
651
652
extern int cxaddcallout(Cx_t*, Cxcallout_t*, Cxdisc_t*);
653
extern int cxaddconstraint(Cx_t*, Cxconstraint_t*, Cxdisc_t*);
654
extern int cxaddedit(Cx_t*, Cxedit_t*, Cxdisc_t*);
655
extern int cxaddmap(Cx_t*, Cxmap_t*, Cxdisc_t*);
656
extern int cxaddquery(Cx_t*, Cxquery_t*, Cxdisc_t*);
657
extern int cxaddrecode(Cx_t*, Cxrecode_t*, Cxdisc_t*);
658
extern int cxaddtype(Cx_t*, Cxtype_t*, Cxdisc_t*);
659
extern int cxaddvariable(Cx_t*, Cxvariable_t*, Cxdisc_t*);
660
661
extern Cxtype_t* cxattr(Cx_t*, const char*, char**, Cxformat_t*, Cxdisc_t*);
662
extern Cxcallout_f cxcallout(Cx_t*, int, Cxtype_t*, Cxtype_t*, Cxdisc_t*);
663
extern Cxconstraint_t* cxconstraint(Cx_t*, const char*, Cxdisc_t*);
664
extern Cxedit_t* cxedit(Cx_t*, const char*, Cxdisc_t*);
665
extern Cxvariable_t* cxfunction(Cx_t*, const char*, Cxdisc_t*);
666
extern Cxmap_t* cxmap(Cx_t*, const char*, Cxdisc_t*);
667
extern Cxquery_t* cxquery(Cx_t*, const char*, Cxdisc_t*);
668
extern Cxrecode_f cxrecode(Cx_t*, int, Cxtype_t*, Cxtype_t*, Cxdisc_t*);
669
extern Cxtype_t* cxtype(Cx_t*, const char*, Cxdisc_t*);
670
extern Cxvariable_t* cxvariable(Cx_t*, const char*, Cxtype_t*, Cxdisc_t*);
671
672
extern int cxnum2str(Cx_t*, Cxformat_t*, Cxunsigned_t, char**);
673
extern int cxstr2num(Cx_t*, Cxformat_t*, const char*, size_t, Cxunsigned_t*);
674
675
extern int cxsub(Cx_t*, Cxedit_t*, Cxoperand_t*);
676
extern int cxsuball(Cx_t*, Cxpart_t*, Cxoperand_t*);
677
678
extern char* cxcvt(Cx_t*, const char*, size_t);
679
680
extern int cxatfree(Cx_t*, Cxexpr_t*, Cxdone_f, void*);
681
682
#undef extern
683
684
#endif
685
686