xapian-core  1.4.30
header.h
Go to the documentation of this file.
1 #include <stdio.h>
2 
3 #define SNOWBALL_VERSION "2.0.0"
4 
5 typedef unsigned char byte;
6 typedef unsigned short symbol;
7 
8 #define true 1
9 #define false 0
10 
11 #define MALLOC check_malloc
12 #define FREE check_free
13 
14 #define NEW(type, p) struct type * p = (struct type *) MALLOC(sizeof(struct type))
15 #define NEWVEC(type, p, n) struct type * p = (struct type *) MALLOC(sizeof(struct type) * (n))
16 
17 #define SIZE(p) ((int *)(p))[-1]
18 #define CAPACITY(p) ((int *)(p))[-2]
19 
20 extern symbol * create_b(int n);
21 extern void report_b(FILE * out, const symbol * p);
22 extern void lose_b(symbol * p);
23 extern symbol * increase_capacity(symbol * p, int n);
24 extern symbol * move_to_b(symbol * p, int n, const symbol * q);
25 extern symbol * add_to_b(symbol * p, int n, const symbol * q);
26 extern symbol * copy_b(const symbol * p);
27 extern char * b_to_s(const symbol * p);
28 extern symbol * add_s_to_b(symbol * p, const char * s);
29 
30 #define MOVE_TO_B(B, LIT) \
31  move_to_b(B, sizeof(LIT) / sizeof(LIT[0]), LIT)
32 
33 struct str; /* defined in space.c */
34 
35 extern struct str * str_new(void);
36 extern void str_delete(struct str * str);
37 extern void str_append(struct str * str, struct str * add);
38 extern void str_append_ch(struct str * str, char add);
39 extern void str_append_b(struct str * str, symbol * q);
40 extern void str_append_string(struct str * str, const char * s);
41 extern void str_append_int(struct str * str, int i);
42 extern void str_clear(struct str * str);
43 extern void str_assign(struct str * str, char * s);
44 extern struct str * str_copy(struct str * old);
45 extern symbol * str_data(struct str * str);
46 extern int str_len(struct str * str);
47 extern int str_back(struct str *str);
48 extern int get_utf8(const symbol * p, int * slot);
49 extern int put_utf8(int ch, symbol * p);
50 extern void output_str(FILE * outfile, struct str * str);
51 
53 
54 struct m_pair {
55 
56  struct m_pair * next;
59 
60 };
61 
62 /* struct input must be a prefix of struct tokeniser. */
63 struct input {
64 
65  struct input * next;
66  symbol * p;
67  int c;
68  char * file;
71 
72 };
73 
74 struct include {
75 
76  struct include * next;
77  symbol * b;
78 
79 };
80 
82 
83 #include "syswords2.h"
84 
93 
95 };
96 
101 };
102 
103 /* struct input must be a prefix of struct tokeniser. */
104 struct tokeniser {
105 
106  struct input * next;
108  int c;
109  char * file;
114  int number;
115  int m_start;
116  int m_end;
117  struct m_pair * m_pairs;
120  int token;
124 
125  int omission;
126  struct include * includes;
127 
128  /* Mode in which U+ has been used:
129  * UPLUS_NONE - not used yet
130  * UPLUS_DEFINED - stringdef U+xxxx ....
131  * UPLUS_UNICODE - {U+xxxx} used with implicit meaning
132  */
134 
136 };
137 
138 extern symbol * get_input(const char * filename);
139 extern struct tokeniser * create_tokeniser(symbol * b, char * file);
140 extern int read_token(struct tokeniser * t);
141 extern const char * name_of_token(int code);
142 extern void disable_token(struct tokeniser * t, int code);
143 extern void close_tokeniser(struct tokeniser * t);
144 
145 extern int space_count;
146 extern void * check_malloc(int n);
147 extern void check_free(void * p);
148 
149 struct node;
150 
151 struct name {
152 
153  struct name * next;
155  int type; /* t_string etc */
156  int mode; /* )_ for routines, externals */
157  struct node * definition; /* ) */
158  int count; /* 0, 1, 2 for each type */
159  int among_func_count; /* 1, 2, 3 for routines called by among */
160  struct grouping * grouping; /* for grouping names */
162  byte used_in_among; /* Function used in among? */
163  byte value_used; /* (For variables) is its value ever used? */
164  byte initialised; /* (For variables) is it ever initialised? */
165  byte used_in_definition; /* (grouping) used in grouping definition? */
166  struct node * used; /* First use, or NULL if not used */
167  struct name * local_to; /* Local to one routine/external */
168  int declaration_line_number;/* Line number of declaration */
169 
170 };
171 
173 
174  struct literalstring * next;
176 
177 };
178 
179 struct amongvec {
180 
181  symbol * b; /* the string giving the case */
182  int size; /* - and its size */
183  struct node * action; /* the corresponding action */
184  int i; /* the amongvec index of the longest substring of b */
185  int result; /* the numeric result for the case */
186  int line_number; /* for diagnostics and stable sorting */
187  struct name * function;
188 
189 };
190 
191 struct among {
192 
193  struct among * next;
194  struct amongvec * b; /* pointer to the amongvec */
195  int number; /* amongs are numbered 0, 1, 2 ... */
196  int literalstring_count; /* in this among */
197  int command_count; /* in this among */
198  int nocommand_count; /* number of "no command" entries in this among */
199  int function_count; /* in this among */
200  int amongvar_needed; /* do we need to set among_var? */
201  struct node * starter; /* i.e. among( (starter) 'string' ... ) */
202  struct node * substring; /* i.e. substring ... among ( ... ) */
203  struct node ** commands; /* array with command_count entries */
204 };
205 
206 struct grouping {
207 
208  struct grouping * next;
209  symbol * b; /* the characters of this group */
210  int largest_ch; /* character with max code */
211  int smallest_ch; /* character with min code */
212  struct name * name; /* so g->name->grouping == g */
214 };
215 
216 struct node {
217 
218  struct node * next;
219  struct node * left;
220  struct node * aux; /* used in setlimit */
221  struct among * among; /* used in among */
222  struct node * right;
223  int type;
224  int mode;
225  struct node * AE;
226  struct name * name;
228  int number;
230  int amongvar_needed; /* used in routine definitions */
231 };
232 
234 
235  t_size = 6,
236 
238  t_grouping = 5
239 
240 /* If this list is extended, adjust wvn in generator.c */
241 };
242 
243 /* In name_count[i] below, remember that
244  type is
245  ----+----
246  0 | string
247  1 | boolean
248  2 | integer
249  3 | routine
250  4 | external
251  5 | grouping
252 */
253 
254 struct analyser {
255 
257  struct node * nodes;
258  struct name * names;
260  int mode;
261  byte modifyable; /* false inside reverse(...) */
262  struct node * program;
263  struct node * program_end;
264  int name_count[t_size]; /* name_count[i] counts the number of names of type i */
265  struct among * amongs;
266  struct among * amongs_end;
268  int amongvar_needed; /* used in reading routine definitions */
269  struct grouping * groupings;
271  struct node * substring; /* pending 'substring' in current routine definition */
273  byte int_limits_used; /* are maxint or minint used? */
274 };
275 
277 
278  m_forward = 0, m_backward /*, m_integer */
279 
280 };
281 
282 extern void print_program(struct analyser * a);
283 extern struct analyser * create_analyser(struct tokeniser * t);
284 extern void close_analyser(struct analyser * a);
285 
286 extern void read_program(struct analyser * a);
287 
288 struct generator {
289 
290  struct analyser * analyser;
291  struct options * options;
292  int unreachable; /* 0 if code can be reached, 1 if current code
293  * is unreachable. */
294  int var_number; /* Number of next variable to use. */
295  struct str * outbuf; /* temporary str to store output */
296  struct str * declarations; /* str storing variable declarations */
298 #ifndef DISABLE_PYTHON
300 #endif
301  int margin;
302 
303  /* if > 0, keep_count to restore in case of a failure;
304  * if < 0, the negated keep_count for the limit to restore in case of
305  * failure. */
307 #if !defined(DISABLE_JAVA) && !defined(DISABLE_JS) && !defined(DISABLE_PYTHON) && !defined(DISABLE_CSHARP)
308  struct str * failure_str; /* This is used by some generators instead of failure_keep_count */
309 #endif
310 
311  int label_used; /* Keep track of whether the failure label is used. */
314  int copy_from_count; /* count of calls to copy_from() */
315 
316  const char * S[10]; /* strings */
317  symbol * B[10]; /* blocks */
318  int I[10]; /* integers */
319  struct name * V[5]; /* variables */
320  symbol * L[5]; /* literals, used in formatted write */
321 
322  int line_count; /* counts number of lines output */
323  int line_labelled; /* in ISO C, will need extra ';' if it is a block end */
325  int keep_count; /* used to number keep/restore pairs to avoid compiler warnings
326  about shadowed variables */
327 };
328 
329 /* Special values for failure_label in struct generator. */
331  x_return = -1
332 };
333 
334 struct options {
335 
336  /* for the command line: */
337 
338  const char * output_file;
339  const char * name;
340  FILE * output_src;
341  FILE * output_h;
343  byte comments;
346  const char * externals_prefix;
347  const char * variables_prefix;
348  const char * runtime_path;
349  const char * parent_class_name;
350  const char * package;
351  const char * go_snowball_runtime;
352  const char * string_class;
353  const char * among_class;
354  struct include * includes;
356 };
357 
358 /* Generator functions common to several backends. */
359 
360 extern struct generator * create_generator(struct analyser * a, struct options * o);
361 extern void close_generator(struct generator * g);
362 
363 extern void write_char(struct generator * g, int ch);
364 extern void write_newline(struct generator * g);
365 extern void write_string(struct generator * g, const char * s);
366 extern void write_int(struct generator * g, int i);
367 extern void write_b(struct generator * g, symbol * b);
368 extern void write_str(struct generator * g, struct str * str);
369 
370 extern void write_comment_content(struct generator * g, struct node * p);
372 extern void write_start_comment(struct generator * g,
373  const char * comment_start,
374  const char * comment_end);
375 
376 extern int K_needed(struct generator * g, struct node * p);
377 extern int repeat_restore(struct generator * g, struct node * p);
378 
379 /* Generator for C code. */
380 extern void generate_program_c(struct generator * g);
381 
382 #ifndef DISABLE_JAVA
383 /* Generator for Java code. */
384 extern void generate_program_java(struct generator * g);
385 #endif
386 
387 #ifndef DISABLE_CSHARP
388 /* Generator for C# code. */
389 extern void generate_program_csharp(struct generator * g);
390 #endif
391 
392 #ifndef DISABLE_PASCAL
393 extern void generate_program_pascal(struct generator * g);
394 #endif
395 
396 #ifndef DISABLE_PYTHON
397 /* Generator for Python code. */
398 extern void generate_program_python(struct generator * g);
399 #endif
400 
401 #ifndef DISABLE_JS
402 extern void generate_program_js(struct generator * g);
403 #endif
404 
405 #ifndef DISABLE_RUST
406 extern void generate_program_rust(struct generator * g);
407 #endif
408 
409 #ifndef DISABLE_GO
410 extern void generate_program_go(struct generator * g);
411 #endif
Definition: unittest.cc:678
void generate_program_c(struct generator *g)
void str_append_int(struct str *str, int i)
void str_clear(struct str *str)
unsigned char byte
Definition: header.h:5
void generate_program_csharp(struct generator *g)
int str_len(struct str *str)
void generate_program_js(struct generator *g)
int K_needed(struct generator *g, struct node *p)
void str_delete(struct str *str)
void str_append_b(struct str *str, symbol *q)
void close_generator(struct generator *g)
void write_generated_comment_content(struct generator *g)
int get_utf8(const symbol *p, int *slot)
int str_back(struct str *str)
void write_newline(struct generator *g)
void read_program(struct analyser *a)
special_labels
Definition: header.h:330
@ x_return
Definition: header.h:331
void write_int(struct generator *g, int i)
struct generator * create_generator(struct analyser *a, struct options *o)
analyser_modes
Definition: header.h:276
@ m_backward
Definition: header.h:278
@ m_forward
Definition: header.h:278
void disable_token(struct tokeniser *t, int code)
void write_char(struct generator *g, int ch)
uplus_modes
Definition: header.h:97
@ UPLUS_UNICODE
Definition: header.h:100
@ UPLUS_NONE
Definition: header.h:98
@ UPLUS_DEFINED
Definition: header.h:99
symbol * add_s_to_b(symbol *p, const char *s)
void output_str(FILE *outfile, struct str *str)
unsigned short symbol
Definition: header.h:6
void write_str(struct generator *g, struct str *str)
void generate_program_python(struct generator *g)
int put_utf8(int ch, symbol *p)
void * check_malloc(int n)
void report_b(FILE *out, const symbol *p)
void generate_program_pascal(struct generator *g)
int space_count
void print_program(struct analyser *a)
symbol * add_to_b(symbol *p, int n, const symbol *q)
void write_b(struct generator *g, symbol *b)
struct tokeniser * create_tokeniser(symbol *b, char *file)
void str_append_ch(struct str *str, char add)
enc
Definition: header.h:52
@ ENC_UTF8
Definition: header.h:52
@ ENC_WIDECHARS
Definition: header.h:52
@ ENC_SINGLEBYTE
Definition: header.h:52
void close_tokeniser(struct tokeniser *t)
int read_token(struct tokeniser *t)
symbol * increase_capacity(symbol *p, int n)
void close_analyser(struct analyser *a)
void str_append(struct str *str, struct str *add)
symbol * move_to_b(symbol *p, int n, const symbol *q)
void write_string(struct generator *g, const char *s)
void str_append_string(struct str *str, const char *s)
void check_free(void *p)
symbol * str_data(struct str *str)
token_codes
Definition: header.h:81
@ c_literalstring
Definition: header.h:88
@ c_neg
Definition: header.h:89
@ c_booltest
Definition: header.h:92
@ c_grouping
Definition: header.h:91
@ c_name
Definition: header.h:86
@ c_call
Definition: header.h:90
@ c_mathassign
Definition: header.h:85
@ NUM_TOKEN_CODES
Definition: header.h:94
@ c_number
Definition: header.h:87
void lose_b(symbol *p)
symbol * copy_b(const symbol *p)
struct str * str_new(void)
symbol * create_b(int n)
const char * name_of_token(int code)
struct str * str_copy(struct str *old)
char * b_to_s(const symbol *p)
void generate_program_java(struct generator *g)
void write_start_comment(struct generator *g, const char *comment_start, const char *comment_end)
void generate_program_rust(struct generator *g)
symbol * get_input(const char *filename)
int repeat_restore(struct generator *g, struct node *p)
name_types
Definition: header.h:233
@ t_grouping
Definition: header.h:238
@ t_routine
Definition: header.h:237
@ t_boolean
Definition: header.h:237
@ t_size
Definition: header.h:235
@ t_external
Definition: header.h:237
@ t_string
Definition: header.h:237
@ t_integer
Definition: header.h:237
void str_assign(struct str *str, char *s)
void generate_program_go(struct generator *g)
struct analyser * create_analyser(struct tokeniser *t)
void write_comment_content(struct generator *g, struct node *p)
string str(int value)
Convert int to std::string.
Definition: str.cc:90
Definition: header.h:191
struct amongvec * b
Definition: header.h:194
struct node * substring
Definition: header.h:202
int amongvar_needed
Definition: header.h:200
int command_count
Definition: header.h:197
int function_count
Definition: header.h:199
int nocommand_count
Definition: header.h:198
struct node ** commands
Definition: header.h:203
int literalstring_count
Definition: header.h:196
struct node * starter
Definition: header.h:201
struct among * next
Definition: header.h:193
int number
Definition: header.h:195
symbol * b
Definition: header.h:181
struct node * action
Definition: header.h:183
int result
Definition: header.h:185
int size
Definition: header.h:182
int i
Definition: header.h:184
int line_number
Definition: header.h:186
int amongvar_needed
Definition: header.h:268
struct name * names
Definition: header.h:258
struct among * amongs_end
Definition: header.h:266
byte int_limits_used
Definition: header.h:273
struct node * nodes
Definition: header.h:257
struct literalstring * literalstrings
Definition: header.h:259
int mode
Definition: header.h:260
byte modifyable
Definition: header.h:261
struct among * amongs
Definition: header.h:265
struct grouping * groupings_end
Definition: header.h:270
struct grouping * groupings
Definition: header.h:269
struct tokeniser * tokeniser
Definition: header.h:256
int among_count
Definition: header.h:267
struct node * substring
Definition: header.h:271
enc encoding
Definition: header.h:272
struct node * program_end
Definition: header.h:263
int name_count[t_size]
Definition: header.h:264
struct node * program
Definition: header.h:262
int max_label
Definition: header.h:299
symbol * L[5]
Definition: header.h:320
struct options * options
Definition: header.h:291
struct str * declarations
Definition: header.h:296
int keep_count
Definition: header.h:325
int unreachable
Definition: header.h:292
struct analyser * analyser
Definition: header.h:290
struct str * failure_str
Definition: header.h:308
int line_labelled
Definition: header.h:323
int var_number
Definition: header.h:294
int copy_from_count
Definition: header.h:314
const char * S[10]
Definition: header.h:316
int debug_count
Definition: header.h:313
struct name * V[5]
Definition: header.h:319
int failure_label
Definition: header.h:312
int next_label
Definition: header.h:297
struct str * outbuf
Definition: header.h:295
int line_count
Definition: header.h:322
int failure_keep_count
Definition: header.h:306
int I[10]
Definition: header.h:318
int label_used
Definition: header.h:311
int literalstring_count
Definition: header.h:324
int margin
Definition: header.h:301
struct grouping * next
Definition: header.h:208
int smallest_ch
Definition: header.h:211
int line_number
Definition: header.h:213
int largest_ch
Definition: header.h:210
symbol * b
Definition: header.h:209
struct name * name
Definition: header.h:212
Definition: header.h:74
struct include * next
Definition: header.h:76
symbol * b
Definition: header.h:77
Definition: header.h:63
symbol * p
Definition: header.h:66
int line_number
Definition: header.h:70
char * file
Definition: header.h:68
struct input * next
Definition: header.h:65
int c
Definition: header.h:67
int file_needs_freeing
Definition: header.h:69
symbol * b
Definition: header.h:175
struct literalstring * next
Definition: header.h:174
Definition: header.h:54
symbol * name
Definition: header.h:57
symbol * value
Definition: header.h:58
struct m_pair * next
Definition: header.h:56
Definition: header.h:151
struct node * definition
Definition: header.h:157
struct node * used
Definition: header.h:166
int type
Definition: header.h:155
struct name * local_to
Definition: header.h:167
byte value_used
Definition: header.h:163
struct name * next
Definition: header.h:153
symbol * b
Definition: header.h:154
byte initialised
Definition: header.h:164
struct grouping * grouping
Definition: header.h:160
byte used_in_definition
Definition: header.h:165
int mode
Definition: header.h:156
int count
Definition: header.h:158
byte referenced
Definition: header.h:161
byte used_in_among
Definition: header.h:162
int among_func_count
Definition: header.h:159
int declaration_line_number
Definition: header.h:168
Definition: header.h:216
symbol * literalstring
Definition: header.h:227
int type
Definition: header.h:223
int amongvar_needed
Definition: header.h:230
struct node * left
Definition: header.h:219
int mode
Definition: header.h:224
int number
Definition: header.h:228
struct node * aux
Definition: header.h:220
struct name * name
Definition: header.h:226
struct node * AE
Definition: header.h:225
struct node * right
Definition: header.h:222
struct node * next
Definition: header.h:218
int line_number
Definition: header.h:229
struct among * among
Definition: header.h:221
struct include * includes_end
Definition: header.h:355
FILE * output_h
Definition: header.h:341
const char * name
Definition: header.h:339
byte syntax_tree
Definition: header.h:342
const char * package
Definition: header.h:350
const char * among_class
Definition: header.h:353
const char * runtime_path
Definition: header.h:348
FILE * output_src
Definition: header.h:340
const char * parent_class_name
Definition: header.h:349
byte comments
Definition: header.h:343
enum options::@12 make_lang
const char * output_file
Definition: header.h:338
const char * string_class
Definition: header.h:352
const char * externals_prefix
Definition: header.h:346
@ LANG_C
Definition: header.h:345
@ LANG_JAVASCRIPT
Definition: header.h:345
@ LANG_PASCAL
Definition: header.h:345
@ LANG_CPLUSPLUS
Definition: header.h:345
@ LANG_CSHARP
Definition: header.h:345
@ LANG_PYTHON
Definition: header.h:345
@ LANG_JAVA
Definition: header.h:345
@ LANG_GO
Definition: header.h:345
@ LANG_RUST
Definition: header.h:345
const char * go_snowball_runtime
Definition: header.h:351
const char * variables_prefix
Definition: header.h:347
struct include * includes
Definition: header.h:354
enc encoding
Definition: header.h:344
struct include * includes
Definition: header.h:126
byte token_held
Definition: header.h:122
char token_disabled[NUM_TOKEN_CODES]
Definition: header.h:135
int get_depth
Definition: header.h:118
int token
Definition: header.h:120
struct input * next
Definition: header.h:106
int c
Definition: header.h:108
struct m_pair * m_pairs
Definition: header.h:117
int previous_token
Definition: header.h:121
int omission
Definition: header.h:125
symbol * b2
Definition: header.h:113
int uplusmode
Definition: header.h:133
char * file
Definition: header.h:109
symbol * b
Definition: header.h:112
symbol * p
Definition: header.h:107
int error_count
Definition: header.h:119
int file_needs_freeing
Definition: header.h:110
int m_start
Definition: header.h:115
int number
Definition: header.h:114
enc encoding
Definition: header.h:123
int m_end
Definition: header.h:116
int line_number
Definition: header.h:111