1 /* $NetBSD: defs.h,v 1.9 2015/01/04 01:34:20 christos Exp $ */
3 #if HAVE_NBTOOL_CONFIG_H
4 #include "nbtool_config.h"
6 /* Id: defs.h,v 1.51 2014/10/02 22:38:13 tom Exp */
20 #if defined(__cplusplus) /* __cplusplus, etc. */
27 #define CONCAT(first,second) first #second
28 #define CONCAT1(string,number) CONCAT(string, number)
29 #define CONCAT2(first,second) #first "." #second
32 #define VSTRING(a,b) CONCAT2(a,b) CONCAT1(" ",YYPATCH)
34 #define VSTRING(a,b) CONCAT2(a,b)
37 #define VERSION VSTRING(YYMAJOR, YYMINOR)
39 /* machine-dependent definitions: */
41 /* MAXCHAR is the largest unsigned character value */
42 /* MAXTABLE is the maximum table size */
43 /* YYINT is the smallest C integer type that can be */
44 /* used to address a table of size MAXTABLE */
45 /* MAXYYINT is the largest value of a YYINT */
46 /* MINYYINT is the most negative value of a YYINT */
47 /* BITS_PER_WORD is the number of bits in a C unsigned */
48 /* WORDSIZE computes the number of words needed to */
50 /* BIT returns the value of the n-th bit starting */
51 /* from r (0-indexed) */
52 /* SETBIT sets the n-th bit starting from r */
54 #define MAXCHAR UCHAR_MAX
56 #define MAXTABLE 32500
58 #if MAXTABLE <= SHRT_MAX
60 #define MAXYYINT SHRT_MAX
61 #define MINYYINT SHRT_MIN
62 #elif MAXTABLE <= INT_MAX
64 #define MAXYYINT INT_MAX
65 #define MINYYINT INT_MIN
67 #error "MAXTABLE is too large for this machine architecture!"
70 #define BITS_PER_WORD ((int) sizeof (unsigned) * CHAR_BIT)
71 #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
72 #define BIT(r, n) ((((r)[(n)/BITS_PER_WORD])>>((n)&(BITS_PER_WORD-1)))&1)
73 #define SETBIT(r, n) ((r)[(n)/BITS_PER_WORD]|=((unsigned)1<<((n)&(BITS_PER_WORD-1))))
77 #define NUL '\0' /* the null character */
78 #define NEWLINE '\n' /* line feed */
79 #define SP ' ' /* space */
80 #define BS '\b' /* backspace */
81 #define HT '\t' /* horizontal tab */
82 #define VT '\013' /* vertical tab */
83 #define CR '\r' /* carriage return */
84 #define FF '\f' /* form feed */
85 #define QUOTE '\'' /* single quote */
86 #define DOUBLE_QUOTE '\"' /* double quote */
87 #define BACKSLASH '\\' /* backslash */
89 #define UCH(c) (unsigned char)(c)
91 /* defines for constructing filenames */
94 #define CODE_SUFFIX "_code.c"
95 #define DEFINES_SUFFIX "_tab.h"
96 #define EXTERNS_SUFFIX "_tab.i"
97 #define OUTPUT_SUFFIX "_tab.c"
99 #define CODE_SUFFIX ".code.c"
100 #define DEFINES_SUFFIX ".tab.h"
101 #define EXTERNS_SUFFIX ".tab.i"
102 #define OUTPUT_SUFFIX ".tab.c"
104 #define VERBOSE_SUFFIX ".output"
105 #define GRAPH_SUFFIX ".dot"
121 #define PURE_PARSER 12
122 #define PARSE_PARAM 13
124 #define POSIX_YACC 15
125 #define TOKEN_TABLE 16
126 #define ERROR_VERBOSE 17
129 #if defined(YYBTYACC)
131 #define DESTRUCTOR 20
132 #define INITIAL_ACTION 21
143 /* the undefined value */
145 #define UNDEFINED (-1)
152 /* character macros */
154 #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
155 #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
156 #define NUMERIC_VALUE(c) ((c) - '0')
160 #define ISTOKEN(s) ((s) < start_symbol)
161 #define ISVAR(s) ((s) >= start_symbol)
163 /* storage allocation macros */
165 #define CALLOC(k,n) (calloc((size_t)(k),(size_t)(n)))
166 #define FREE(x) (free((char*)(x)))
167 #define MALLOC(n) (malloc((size_t)(n)))
168 #define TCMALLOC(t,n) ((t*) calloc((size_t)(n), sizeof(t)))
169 #define TMALLOC(t,n) ((t*) malloc((size_t)(n) * sizeof(t)))
170 #define NEW(t) ((t*)allocate(sizeof(t)))
171 #define NEW2(n,t) ((t*)allocate(((size_t)(n)*sizeof(t))))
172 #define REALLOC(p,n) (realloc((char*)(p),(size_t)(n)))
173 #define TREALLOC(t,p,n) ((t*)realloc((char*)(p), (size_t)(n) * sizeof(t)))
175 #define DO_FREE(x) if (x) { FREE(x); x = 0; }
177 #define NO_SPACE(p) if (p == 0) no_space(); assert(p != 0)
180 #define PLURAL(n) ((n) > 1 ? "s" : "")
183 * Features which depend indirectly on the btyacc configuration, but are not
186 #if defined(YYBTYACC)
187 #define USE_HEADER_GUARDS 1
189 #define USE_HEADER_GUARDS 0
192 typedef char Assoc_t
;
193 typedef char Class_t
;
194 typedef YYINT Index_t
;
195 typedef YYINT Value_t
;
197 /* the structure of a symbol table entry */
199 typedef struct bucket bucket
;
206 #if defined(YYBTYACC)
219 /* the structure of the LR(0) state machine */
221 typedef struct core core
;
227 Value_t accessing_symbol
;
232 /* the structure used to record shifts */
234 typedef struct shifts shifts
;
243 /* the structure used to store reductions */
245 typedef struct reductions reductions
;
248 struct reductions
*next
;
254 /* the structure used to represent parser actions */
256 typedef struct action action
;
268 /* the structure used to store parse/lex parameters */
269 typedef struct param param
;
273 char *name
; /* parameter name */
274 char *type
; /* everything before parameter name */
275 char *type2
; /* everything after parameter name */
278 /* global variables */
288 extern const char *symbol_prefix
;
290 extern const char *myname
;
295 extern int exit_code
;
296 extern int pure_parser
;
297 extern int token_table
;
298 extern int error_verbose
;
299 #if defined(YYBTYACC)
300 extern int locations
;
301 extern int backtrack
;
302 extern int destructor
;
303 extern char *initial_action
;
306 extern const char *const banner
[];
307 extern const char *const xdecls
[];
308 extern const char *const tables
[];
309 extern const char *const global_vars
[];
310 extern const char *const impure_vars
[];
311 extern const char *const hdr_defs
[];
312 extern const char *const hdr_vars
[];
313 extern const char *const body_1
[];
314 extern const char *const body_vars
[];
315 extern const char *const body_2
[];
316 extern const char *const body_3
[];
317 extern const char *const trailer
[];
319 extern char *code_file_name
;
320 extern char *input_file_name
;
321 extern char *defines_file_name
;
322 extern char *externs_file_name
;
324 extern FILE *action_file
;
325 extern FILE *code_file
;
326 extern FILE *defines_file
;
327 extern FILE *externs_file
;
328 extern FILE *input_file
;
329 extern FILE *output_file
;
330 extern FILE *text_file
;
331 extern FILE *union_file
;
332 extern FILE *verbose_file
;
333 extern FILE *graph_file
;
335 extern Value_t nitems
;
336 extern Value_t nrules
;
337 extern Value_t nsyms
;
338 extern Value_t ntokens
;
339 extern Value_t nvars
;
342 extern char unionized
;
343 extern char line_format
[];
345 extern Value_t start_symbol
;
346 extern char **symbol_name
;
347 extern char **symbol_pname
;
348 extern Value_t
*symbol_value
;
349 extern Value_t
*symbol_prec
;
350 extern char *symbol_assoc
;
352 #if defined(YYBTYACC)
353 extern Value_t
*symbol_pval
;
354 extern char **symbol_destructor
;
355 extern char **symbol_type_tag
;
358 extern Value_t
*ritem
;
359 extern Value_t
*rlhs
;
360 extern Value_t
*rrhs
;
361 extern Value_t
*rprec
;
362 extern Assoc_t
*rassoc
;
364 extern Value_t
**derives
;
365 extern char *nullable
;
367 extern bucket
*first_symbol
;
368 extern bucket
*last_symbol
;
371 extern core
*first_state
;
372 extern shifts
*first_shift
;
373 extern reductions
*first_reduction
;
374 extern Value_t
*accessing_symbol
;
375 extern core
**state_table
;
376 extern shifts
**shift_table
;
377 extern reductions
**reduction_table
;
379 extern Value_t
*LAruleno
;
380 extern Value_t
*lookaheads
;
381 extern Value_t
*goto_base
;
382 extern Value_t
*goto_map
;
383 extern Value_t
*from_state
;
384 extern Value_t
*to_state
;
386 extern action
**parser
;
391 extern Value_t
*SRconflicts
;
392 extern Value_t
*RRconflicts
;
393 extern Value_t
*defred
;
394 extern Value_t
*rules_used
;
395 extern Value_t nunused
;
396 extern Value_t final_state
;
398 extern Value_t
*itemset
;
399 extern Value_t
*itemsetend
;
400 extern unsigned *ruleset
;
402 extern param
*lex_param
;
403 extern param
*parse_param
;
405 /* global functions */
409 #define GCC_NORETURN __dead2
410 #elif defined(__dead)
411 #define GCC_NORETURN __dead
413 #define GCC_NORETURN /* nothing */
418 #if defined(__unused)
419 #define GCC_UNUSED __unused
421 #define GCC_UNUSED /* nothing */
425 #ifndef GCC_PRINTFLIKE
426 #define GCC_PRINTFLIKE(fmt,var) /*nothing*/
430 extern void closure(Value_t
* nucleus
, int n
);
431 extern void finalize_closure(void);
432 extern void set_first_derives(void);
435 extern void arg_number_disagree_warning(int a_lineno
, char *a_name
);
436 extern void arg_type_disagree_warning(int a_lineno
, int i
, char *a_name
);
437 extern void at_error(int a_lineno
, char *a_line
, char *a_cptr
) GCC_NORETURN
;
438 extern void at_warning(int a_lineno
, int i
);
439 extern void bad_formals(void) GCC_NORETURN
;
440 extern void default_action_warning(void);
446 extern void destructor_redeclared_warning(const struct ainfo
*);
447 extern void dollar_error(int a_lineno
, char *a_line
, char *a_cptr
) GCC_NORETURN
;
448 extern void dollar_warning(int a_lineno
, int i
);
449 extern void fatal(const char *msg
) GCC_NORETURN
;
450 extern void illegal_character(char *c_cptr
) GCC_NORETURN
;
451 extern void illegal_tag(int t_lineno
, char *t_line
, char *t_cptr
) GCC_NORETURN
;
452 extern void missing_brace(void) GCC_NORETURN
;
453 extern void no_grammar(void) GCC_NORETURN
;
454 extern void no_space(void) GCC_NORETURN
;
455 extern void open_error(const char *filename
) GCC_NORETURN
;
456 extern void over_unionized(char *u_cptr
) GCC_NORETURN
;
457 extern void prec_redeclared(void);
458 extern void reprec_warning(char *s
);
459 extern void restarted_warning(void);
460 extern void retyped_warning(char *s
);
461 extern void revalued_warning(char *s
);
462 extern void start_requires_args(char *a_name
);
463 extern void syntax_error(int st_lineno
, char *st_line
, char *st_cptr
) GCC_NORETURN
;
464 extern void terminal_lhs(int s_lineno
) GCC_NORETURN
;
465 extern void terminal_start(char *s
) GCC_NORETURN
;
466 extern void tokenized_start(char *s
) GCC_NORETURN
;
467 extern void undefined_goal(char *s
) GCC_NORETURN
;
468 extern void undefined_symbol_warning(char *s
);
469 extern void unexpected_EOF(void) GCC_NORETURN
;
470 extern void unknown_arg_warning(int d_lineno
, const char *dlr_opt
, const char *d_arg
, const char *d_line
, const char *d_cptr
);
471 extern void unknown_rhs(int i
) GCC_NORETURN
;
472 extern void unsupported_flag_warning(const char *flag
, const char *details
);
473 extern void unterminated_action(const struct ainfo
*);
474 extern void unterminated_comment(const struct ainfo
*) GCC_NORETURN
;
475 extern void unterminated_string(const struct ainfo
*) GCC_NORETURN
;
476 extern void unterminated_text(const struct ainfo
*) GCC_NORETURN
;
477 extern void unterminated_union(const struct ainfo
*) GCC_NORETURN
;
478 extern void untyped_arg_warning(int a_lineno
, const char *dlr_opt
, const char *a_name
);
479 extern void untyped_lhs(void) GCC_NORETURN
;
480 extern void untyped_rhs(int i
, char *s
) GCC_NORETURN
;
481 extern void used_reserved(char *s
) GCC_NORETURN
;
482 extern void unterminated_arglist(const struct ainfo
*) GCC_NORETURN
;
483 extern void wrong_number_args_warning(const char *which
, const char *a_name
);
484 extern void wrong_type_for_arg_warning(int i
, char *a_name
);
487 extern void graph(void);
490 extern void lalr(void);
493 extern void lr0(void);
494 extern void show_cores(void);
495 extern void show_ritems(void);
496 extern void show_rrhs(void);
497 extern void show_shifts(void);
500 extern void *allocate(size_t n
);
501 extern void done(int k
) GCC_NORETURN
;
504 extern void free_parser(void);
505 extern void make_parser(void);
510 char *base
, *ptr
, *end
;
513 extern void msprintf(struct mstring
*, const char *, ...) GCC_PRINTFLIKE(2,3);
514 extern int mputchar(struct mstring
*, int);
515 extern struct mstring
*msnew(void);
516 extern char *msdone(struct mstring
*);
517 extern int strnscmp(const char *, const char *);
518 extern unsigned int strnshash(const char *);
520 #define mputc(m, ch) (((m)->ptr == (m)->end) \
522 : (*(m)->ptr++ = (char) (ch)))
525 extern void output(void);
528 extern void reader(void);
530 /* skeleton.c (generated by skel2c) */
531 extern void write_section(FILE * fp
, const char *const section
[]);
534 extern bucket
*make_bucket(const char *);
535 extern bucket
*lookup(const char *);
536 extern void create_symbol_table(void);
537 extern void free_symbol_table(void);
538 extern void free_symbols(void);
541 extern void verbose(void);
544 extern void reflexive_transitive_closure(unsigned *R
, int n
);
548 extern void print_closure(int n
);
549 extern void print_EFF(void);
550 extern void print_first_derives(void);
552 extern void print_derives(void);
556 extern void lr0_leaks(void);
557 extern void lalr_leaks(void);
558 extern void mkpar_leaks(void);
559 extern void output_leaks(void);
560 extern void mstring_leaks(void);
561 extern void reader_leaks(void);