1 /* @(#)rpc_parse.c 2.1 88/08/01 4.0 RPCSRC */
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
28 * Mountain View, California 94043
31 static char sccsid
[] = "@(#)rpc_parse.c 1.4 87/04/28 (C) 1987 SMI";
35 * rpc_parse.c, Parser for the RPC protocol compiler
36 * Copyright (C) 1987 Sun Microsystems, Inc.
41 #include "rpc_parse.h"
44 * return the next definition you see
52 defp
= ALLOC(definition
);
77 error("definition keyword expected");
79 scan(TOK_SEMICOLON
, &tok
);
88 STOREVAL(&defined
, defp
);
101 defp
->def_kind
= DEF_STRUCT
;
103 scan(TOK_IDENT
, &tok
);
104 defp
->def_name
= tok
.str
;
105 scan(TOK_LBRACE
, &tok
);
106 tailp
= &defp
->def
.st
.decls
;
108 get_declaration(&dec
, DEF_STRUCT
);
109 decls
= ALLOC(decl_list
);
112 tailp
= &decls
->next
;
113 scan(TOK_SEMICOLON
, &tok
);
115 } while (tok
.kind
!= TOK_RBRACE
);
126 version_list
**vtailp
;
130 defp
->def_kind
= DEF_PROGRAM
;
131 scan(TOK_IDENT
, &tok
);
132 defp
->def_name
= tok
.str
;
133 scan(TOK_LBRACE
, &tok
);
134 vtailp
= &defp
->def
.pr
.versions
;
135 scan(TOK_VERSION
, &tok
);
137 scan(TOK_IDENT
, &tok
);
138 vlist
= ALLOC(version_list
);
139 vlist
->vers_name
= tok
.str
;
140 scan(TOK_LBRACE
, &tok
);
141 ptailp
= &vlist
->procs
;
143 plist
= ALLOC(proc_list
);
144 get_type(&plist
->res_prefix
, &plist
->res_type
, DEF_PROGRAM
);
145 if (streq(plist
->res_type
, "opaque")) {
146 error("illegal result type");
148 scan(TOK_IDENT
, &tok
);
149 plist
->proc_name
= tok
.str
;
150 scan(TOK_LPAREN
, &tok
);
151 get_type(&plist
->arg_prefix
, &plist
->arg_type
, DEF_PROGRAM
);
152 if (streq(plist
->arg_type
, "opaque")) {
153 error("illegal argument type");
155 scan(TOK_RPAREN
, &tok
);
156 scan(TOK_EQUAL
, &tok
);
158 scan(TOK_SEMICOLON
, &tok
);
159 plist
->proc_num
= tok
.str
;
161 ptailp
= &plist
->next
;
163 } while (tok
.kind
!= TOK_RBRACE
);
165 vtailp
= &vlist
->next
;
166 scan(TOK_RBRACE
, &tok
);
167 scan(TOK_EQUAL
, &tok
);
169 vlist
->vers_num
= tok
.str
;
170 scan(TOK_SEMICOLON
, &tok
);
171 scan2(TOK_VERSION
, TOK_RBRACE
, &tok
);
172 } while (tok
.kind
== TOK_VERSION
);
173 scan(TOK_EQUAL
, &tok
);
175 defp
->def
.pr
.prog_num
= tok
.str
;
185 enumval_list
**tailp
;
187 defp
->def_kind
= DEF_ENUM
;
188 scan(TOK_IDENT
, &tok
);
189 defp
->def_name
= tok
.str
;
190 scan(TOK_LBRACE
, &tok
);
191 tailp
= &defp
->def
.en
.vals
;
193 scan(TOK_IDENT
, &tok
);
194 elist
= ALLOC(enumval_list
);
195 elist
->name
= tok
.str
;
196 elist
->assignment
= NULL
;
197 scan3(TOK_COMMA
, TOK_RBRACE
, TOK_EQUAL
, &tok
);
198 if (tok
.kind
== TOK_EQUAL
) {
200 elist
->assignment
= tok
.str
;
201 scan2(TOK_COMMA
, TOK_RBRACE
, &tok
);
204 tailp
= &elist
->next
;
205 } while (tok
.kind
!= TOK_RBRACE
);
215 defp
->def_kind
= DEF_CONST
;
216 scan(TOK_IDENT
, &tok
);
217 defp
->def_name
= tok
.str
;
218 scan(TOK_EQUAL
, &tok
);
219 scan2(TOK_IDENT
, TOK_STRCONST
, &tok
);
220 defp
->def
.co
= tok
.str
;
232 defp
->def_kind
= DEF_UNION
;
233 scan(TOK_IDENT
, &tok
);
234 defp
->def_name
= tok
.str
;
235 scan(TOK_SWITCH
, &tok
);
236 scan(TOK_LPAREN
, &tok
);
237 get_declaration(&dec
, DEF_UNION
);
238 defp
->def
.un
.enum_decl
= dec
;
239 tailp
= &defp
->def
.un
.cases
;
240 scan(TOK_RPAREN
, &tok
);
241 scan(TOK_LBRACE
, &tok
);
242 scan(TOK_CASE
, &tok
);
243 while (tok
.kind
== TOK_CASE
) {
244 scan(TOK_IDENT
, &tok
);
245 cases
= ALLOC(case_list
);
246 cases
->case_name
= tok
.str
;
247 scan(TOK_COLON
, &tok
);
248 get_declaration(&dec
, DEF_UNION
);
249 cases
->case_decl
= dec
;
251 tailp
= &cases
->next
;
252 scan(TOK_SEMICOLON
, &tok
);
253 scan3(TOK_CASE
, TOK_DEFAULT
, TOK_RBRACE
, &tok
);
256 if (tok
.kind
== TOK_DEFAULT
) {
257 scan(TOK_COLON
, &tok
);
258 get_declaration(&dec
, DEF_UNION
);
259 defp
->def
.un
.default_decl
= ALLOC(declaration
);
260 *defp
->def
.un
.default_decl
= dec
;
261 scan(TOK_SEMICOLON
, &tok
);
262 scan(TOK_RBRACE
, &tok
);
264 defp
->def
.un
.default_decl
= NULL
;
275 defp
->def_kind
= DEF_TYPEDEF
;
276 get_declaration(&dec
, DEF_TYPEDEF
);
277 defp
->def_name
= dec
.name
;
278 defp
->def
.ty
.old_prefix
= dec
.prefix
;
279 defp
->def
.ty
.old_type
= dec
.type
;
280 defp
->def
.ty
.rel
= dec
.rel
;
281 defp
->def
.ty
.array_max
= dec
.array_max
;
286 get_declaration(dec
, dkind
)
292 get_type(&dec
->prefix
, &dec
->type
, dkind
);
293 dec
->rel
= REL_ALIAS
;
294 if (streq(dec
->type
, "void")) {
297 scan2(TOK_STAR
, TOK_IDENT
, &tok
);
298 if (tok
.kind
== TOK_STAR
) {
299 dec
->rel
= REL_POINTER
;
300 scan(TOK_IDENT
, &tok
);
303 if (peekscan(TOK_LBRACKET
, &tok
)) {
304 if (dec
->rel
== REL_POINTER
) {
305 error("no array-of-pointer declarations -- use typedef");
307 dec
->rel
= REL_VECTOR
;
309 dec
->array_max
= tok
.str
;
310 scan(TOK_RBRACKET
, &tok
);
311 } else if (peekscan(TOK_LANGLE
, &tok
)) {
312 if (dec
->rel
== REL_POINTER
) {
313 error("no array-of-pointer declarations -- use typedef");
315 dec
->rel
= REL_ARRAY
;
316 if (peekscan(TOK_RANGLE
, &tok
)) {
317 dec
->array_max
= "~0"; /* unspecified size, use max */
320 dec
->array_max
= tok
.str
;
321 scan(TOK_RANGLE
, &tok
);
324 if (streq(dec
->type
, "opaque")) {
325 if (dec
->rel
!= REL_ARRAY
&& dec
->rel
!= REL_VECTOR
) {
326 error("array declaration expected");
328 } else if (streq(dec
->type
, "string")) {
329 if (dec
->rel
!= REL_ARRAY
) {
330 error("variable-length array declaration expected");
337 get_type(prefixp
, typep
, dkind
)
354 scan(TOK_IDENT
, &tok
);
362 (void) peekscan(TOK_INT
, &tok
);
366 (void) peekscan(TOK_INT
, &tok
);
369 if (dkind
!= DEF_UNION
&& dkind
!= DEF_PROGRAM
) {
370 error("voids allowed only inside union and program definitions");
384 error("expected type specifier");
404 (void) peekscan(TOK_INT
, &tok
);
409 (void) peekscan(TOK_INT
, &tok
);