1 /* rpcgen - Generate XDR bindings automatically. -*- text -*-
2 * Copyright (C) 2008 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "rpcgen_int.h"
25 extern void yyerror (const char *str);
32 struct enum_value *enum_value;
33 struct union_case *union_case;
37 %type <type> type_ident
40 %type <decl> simple_decl fixed_array_decl variable_array_decl pointer_decl
41 %type <decl> string_decl opaque_decl
42 %type <enum_value> enum_value
43 %type <union_case> union_case
44 %type <list> decls enum_values union_cases
67 /* This is sometimes lumped together with the other types, but
68 * the special keyword void can only occur after "default:" in
88 stmt : ENUM IDENT '{' enum_values '}'
90 struct cons *enums = list_rev ($4);
95 | STRUCT IDENT '{' decls '}'
97 struct cons *decls = list_rev ($4);
98 gen_struct ($2, decls);
102 | UNION IDENT SWITCH '(' decl ')' '{' union_cases '}'
104 struct cons *cases = list_rev ($8);
105 gen_union ($2, $5, cases);
115 | CONST IDENT '=' const
123 error ("PortableXDR does not support SunRPC program statements");
127 /* Declarations used inside structs and unions. eg. "int foo;" */
129 { $$ = new_cons (NULL, $1, (free_fn) free_decl); }
131 { $$ = new_cons ($1, $2, (free_fn) free_decl); }
138 | variable_array_decl
143 : STRING IDENT '<' const '>'
145 $$ = new_decl (decl_type_string, NULL, $2, $4);
147 | STRING IDENT '<' '>'
149 $$ = new_decl (decl_type_string, NULL, $2, NULL);
154 : OPAQUE IDENT '[' const ']'
156 $$ = new_decl (decl_type_opaque_fixed, NULL, $2, $4);
158 | OPAQUE IDENT '<' const '>'
160 $$ = new_decl (decl_type_opaque_variable, NULL, $2, $4);
166 { $$ = new_decl (decl_type_simple, $1, $2, NULL); }
170 : type_ident IDENT '[' const ']'
171 { $$ = new_decl (decl_type_fixed_array, $1, $2, $4); }
175 : type_ident IDENT '<' const '>'
176 { $$ = new_decl (decl_type_variable_array, $1, $2, $4); }
177 | type_ident IDENT '<' '>'
178 { $$ = new_decl (decl_type_variable_array, $1, $2, NULL); }
182 : type_ident '*' IDENT
183 { $$ = new_decl (decl_type_pointer, $1, $3, NULL); }
189 { $$ = new_cons (NULL, $1, (free_fn) free_enum_value); }
190 | enum_values ',' enum_value
191 { $$ = new_cons ($1, $3, (free_fn) free_enum_value); }
196 { $$ = new_enum_value ($1, NULL); }
198 { $$ = new_enum_value ($1, $3); }
201 /* Case list inside a union. */
204 { $$ = new_cons (NULL, $1, (free_fn) free_union_case); }
205 | union_cases union_case ';'
206 { $$ = new_cons ($1, $2, (free_fn) free_union_case); }
210 : CASE const ':' decl
211 { $$ = new_union_case (union_case_normal, $2, $4); }
213 { $$ = new_union_case (union_case_default_void, NULL, NULL); }
215 { $$ = new_union_case (union_case_default_decl, NULL, $3); }
218 /* Constants, which may be integer literals or refer to previously
219 * defined constants (using "const" keyword).
220 * XXX In future we should probably allow computed constants.
226 /* Types. Note 'string', 'opaque' and 'void' are handled by
227 * special cases above.
231 /* NB: Unlike SunRPC we make char explicitly signed. This
232 * will give some warnings in GCC if you mix PortableXDR
233 * code with SunRPC headers or vice versa.
235 { $$ = new_type (type_char, 1, NULL); }
237 { $$ = new_type (type_char, 1, NULL); }
239 { $$ = new_type (type_char, 0, NULL); }
241 { $$ = new_type (type_short, 1, NULL); }
243 { $$ = new_type (type_short, 1, NULL); }
245 { $$ = new_type (type_short, 0, NULL); }
247 { $$ = new_type (type_int, 1, NULL); }
249 { $$ = new_type (type_int, 1, NULL); }
251 { $$ = new_type (type_int, 0, NULL); }
253 { $$ = new_type (type_hyper, 1, NULL); }
255 { $$ = new_type (type_hyper, 1, NULL); }
257 { $$ = new_type (type_hyper, 0, NULL); }
259 { $$ = new_type (type_int, 1, NULL); }
261 { $$ = new_type (type_int, 0, NULL); }
263 { $$ = new_type (type_double, 0, NULL); }
265 { $$ = new_type (type_bool, 0, NULL); }
267 { $$ = new_type (type_ident, 0, $1); }
273 yyerror (const char *str)