92713263b180b71a91f87924d2da41ae5f3d389c
[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_double,
40   type_string, type_opaque, 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   char *len;                    /* length (only for strings) */
49 };
50
51 extern struct type *new_type (enum type_enum, int, char *, char *);
52 extern void free_type (struct type *);
53
54 enum decl_type {
55   decl_type_simple,             /* type ident; */
56   decl_type_fixed_array,        /* type ident[len]; */
57   decl_type_variable_array,     /* type ident<len>; (len is optional) */
58   decl_type_pointer,            /* type *ident; */
59 };
60
61 struct decl {
62   enum decl_type decl_type;
63   struct type *type;
64   char *ident;
65   char *len;
66 };
67
68 extern struct decl *new_decl (enum decl_type, struct type *, char *, char *);
69 extern void free_decl (struct decl *);
70
71 struct enum_value {
72   char *ident;
73   char *value;
74 };
75
76 extern struct enum_value *new_enum_value (char *, char *);
77 extern void free_enum_value (struct enum_value *);
78
79 enum union_case_type {
80   union_case_normal,            /* case const: decl; */
81   union_case_default_void,      /* default: void; */
82   union_case_default_decl,      /* default: decl; */
83 };
84
85 struct union_case {
86   enum union_case_type type;
87   char *const_;
88   struct decl *decl;
89 };
90
91 extern struct union_case *new_union_case (enum union_case_type, char *, struct decl *);
92 extern void free_union_case (struct union_case *);
93
94 typedef void (*free_fn) (void *);
95
96 struct cons {
97   struct cons *next; /* cdr/tail */
98   void *ptr; /* car/head */
99   free_fn free; /* free the head element */
100 };
101
102 extern struct cons *new_cons (struct cons *, void *, free_fn);
103 extern struct cons *list_rev (struct cons *);
104 extern void list_free (struct cons *);
105
106 /* Code generator functions. */
107 extern void gen_prologue (const char *filename);
108 extern void gen_epilogue (void);
109 extern void gen_const (const char *name, const char *value);
110 extern void gen_enum (const char *name, const struct cons *enum_values);
111 extern void gen_struct (const char *name, const struct cons *decls);
112 extern void gen_union (const char *name, const struct decl *discrim, const struct cons *union_cases);
113 extern void gen_typedef (const struct decl *decl);
114
115 /* Global functions used by the scanner. */
116 extern void start_string (void);
117 extern char *end_string (void);
118 extern void add_char (int);
119 extern void add_string (const char *);
120
121 /* These functions print an error and then exit. */
122 extern void error (const char *, ...)
123   __attribute__((noreturn, format(printf,1,2)));
124 extern void perrorf (const char *, ...)
125   __attribute__((noreturn, format(printf,1,2)));
126
127 /* Symbols exported from the scanner and parser. */
128 extern FILE *yyin, *yyout;
129 extern int yyparse (void);
130 extern int yylineno;
131 extern int yydebug;
132
133 #endif /* RPCGEN_INT_H */