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
68 /* This is sometimes lumped together with the other types, but
69 * the special keyword void can only occur after "default:" in
89 stmt : ENUM IDENT '{' enum_values '}'
91 struct cons *enums = list_rev ($4);
96 | STRUCT IDENT '{' decls '}'
98 struct cons *decls = list_rev ($4);
99 gen_struct ($2, decls);
103 | UNION IDENT SWITCH '(' decl ')' '{' union_cases '}'
105 struct cons *cases = list_rev ($8);
106 gen_union ($2, $5, cases);
116 | CONST IDENT '=' const
124 error ("PortableXDR does not support SunRPC program statements");
128 /* Declarations used inside structs and unions. eg. "int foo;" */
130 { $$ = new_cons (NULL, $1, (free_fn) free_decl); }
132 { $$ = new_cons ($1, $2, (free_fn) free_decl); }
139 | variable_array_decl
144 : STRING IDENT '<' const '>'
146 $$ = new_decl (decl_type_string, NULL, $2, $4);
148 | STRING IDENT '<' '>'
150 $$ = new_decl (decl_type_string, NULL, $2, NULL);
155 : OPAQUE IDENT '[' const ']'
157 $$ = new_decl (decl_type_opaque_fixed, NULL, $2, $4);
159 | OPAQUE IDENT '<' const '>'
161 $$ = new_decl (decl_type_opaque_variable, NULL, $2, $4);
167 { $$ = new_decl (decl_type_simple, $1, $2, NULL); }
171 : type_ident IDENT '[' const ']'
172 { $$ = new_decl (decl_type_fixed_array, $1, $2, $4); }
176 : type_ident IDENT '<' const '>'
177 { $$ = new_decl (decl_type_variable_array, $1, $2, $4); }
178 | type_ident IDENT '<' '>'
179 { $$ = new_decl (decl_type_variable_array, $1, $2, NULL); }
183 : type_ident '*' IDENT
184 { $$ = new_decl (decl_type_pointer, $1, $3, NULL); }
190 { $$ = new_cons (NULL, $1, (free_fn) free_enum_value); }
191 | enum_values ',' enum_value
192 { $$ = new_cons ($1, $3, (free_fn) free_enum_value); }
197 { $$ = new_enum_value ($1, NULL); }
199 { $$ = new_enum_value ($1, $3); }
202 /* Case list inside a union. */
205 { $$ = new_cons (NULL, $1, (free_fn) free_union_case); }
206 | union_cases union_case ';'
207 { $$ = new_cons ($1, $2, (free_fn) free_union_case); }
211 : CASE const ':' decl
212 { $$ = new_union_case (union_case_normal, $2, $4); }
214 { $$ = new_union_case (union_case_default_void, NULL, NULL); }
216 { $$ = new_union_case (union_case_default_decl, NULL, $3); }
219 /* Constants, which may be integer literals or refer to previously
220 * defined constants (using "const" keyword).
221 * XXX In future we should probably allow computed constants.
227 /* Types. Note 'string', 'opaque' and 'void' are handled by
228 * special cases above.
232 /* NB: Unlike SunRPC we make char explicitly signed. This
233 * will give some warnings in GCC if you mix PortableXDR
234 * code with SunRPC headers or vice versa.
236 { $$ = new_type (type_char, 1, NULL); }
238 { $$ = new_type (type_char, 1, NULL); }
240 { $$ = new_type (type_char, 0, NULL); }
242 { $$ = new_type (type_short, 1, NULL); }
244 { $$ = new_type (type_short, 1, NULL); }
246 { $$ = new_type (type_short, 0, NULL); }
248 { $$ = new_type (type_int, 1, NULL); }
250 { $$ = new_type (type_int, 1, NULL); }
252 { $$ = new_type (type_int, 0, NULL); }
254 { $$ = new_type (type_hyper, 1, NULL); }
256 { $$ = new_type (type_hyper, 1, NULL); }
258 { $$ = new_type (type_hyper, 0, NULL); }
260 { $$ = new_type (type_int, 1, NULL); }
262 { $$ = new_type (type_int, 0, NULL); }
264 { $$ = new_type (type_float, 0, NULL); }
266 { $$ = new_type (type_double, 0, NULL); }
268 { $$ = new_type (type_bool, 0, NULL); }
270 { $$ = new_type (type_ident, 0, $1); }
276 yyerror (const char *str)