Added Gnulib intprops module.
[portablexdr.git] / rpcgen_int.h
1 /* -*- C -*-
2  * rpcgen - Generate XDR bindings automatically.
3  * Copyright (C) 2008 Red Hat Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #ifndef RPCGEN_INT_H
21 #define RPCGEN_INT_H
22
23 /* Current input file (updated by # line directives in the source). */
24 extern char *input_filename;
25
26 /* Current output file. */
27 extern const char *output_filename;
28
29 /* Current output mode. */
30 enum output_mode {
31   output_c = 0,
32   output_h = 1,
33 };
34 extern enum output_mode output_mode;
35
36 /* Abstract syntax tree types. */
37 enum type_enum {
38   type_char, type_short, type_int, type_hyper,
39   type_float, type_double,
40   type_bool,
41   type_ident,
42 };
43
44 struct type {
45   enum type_enum type;
46   int sgn;                      /* true if signed, false if unsigned */
47   char *ident;
48 };
49
50 extern struct type *new_type (enum type_enum, int, char *);
51 extern void free_type (struct type *);
52
53 enum decl_type {
54   decl_type_string,             /* string foo<len>; (len is optional) */
55   decl_type_opaque_fixed,       /* opaque foo[len]; */
56   decl_type_opaque_variable,    /* opaque foo<len>; */
57   decl_type_simple,             /* type ident; */
58   decl_type_fixed_array,        /* type ident[len]; */
59   decl_type_variable_array,     /* type ident<len>; (len is optional) */
60   decl_type_pointer,            /* type *ident; */
61 };
62
63 struct decl {
64   enum decl_type decl_type;
65   struct type *type;            /* NULL for string & opaque types. */
66   char *ident;
67   char *len;
68 };
69
70 extern struct decl *new_decl (enum decl_type, struct type *, char *, char *);
71 extern void free_decl (struct decl *);
72
73 struct enum_value {
74   char *ident;
75   char *value;
76 };
77
78 extern struct enum_value *new_enum_value (char *, char *);
79 extern void free_enum_value (struct enum_value *);
80
81 enum union_case_type {
82   union_case_normal,            /* case const: decl; */
83   union_case_default_void,      /* default: void; */
84   union_case_default_decl,      /* default: decl; */
85 };
86
87 struct union_case {
88   enum union_case_type type;
89   char *const_;
90   struct decl *decl;
91 };
92
93 extern struct union_case *new_union_case (enum union_case_type, char *, struct decl *);
94 extern void free_union_case (struct union_case *);
95
96 typedef void (*free_fn) (void *);
97
98 struct cons {
99   struct cons *next; /* cdr/tail */
100   void *ptr; /* car/head */
101   free_fn free; /* free the head element */
102 };
103
104 extern struct cons *new_cons (struct cons *, void *, free_fn);
105 extern struct cons *list_rev (struct cons *);
106 extern void list_free (struct cons *);
107
108 /* Code generator functions. */
109 extern void gen_prologue (const char *filename);
110 extern void gen_epilogue (void);
111 extern void gen_const (const char *name, const char *value);
112 extern void gen_enum (const char *name, const struct cons *enum_values);
113 extern void gen_struct (const char *name, const struct cons *decls);
114 extern void gen_union (const char *name, const struct decl *discrim, const struct cons *union_cases);
115 extern void gen_typedef (const struct decl *decl);
116
117 /* Global functions used by the scanner. */
118 extern void start_string (void);
119 extern char *end_string (void);
120 extern void add_char (int);
121 extern void add_string (const char *);
122
123 /* These functions print an error and then exit. */
124 extern void error (const char *, ...)
125   __attribute__((noreturn, format(printf,1,2)));
126 extern void perrorf (const char *, ...)
127   __attribute__((noreturn, format(printf,1,2)));
128
129 /* Symbols exported from the scanner and parser. */
130 extern FILE *yyin, *yyout;
131 extern int yyparse (void);
132 extern int yylineno;
133 extern int yydebug;
134
135 #endif /* RPCGEN_INT_H */