17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*a2f144d1SJordan Brown * Common Development and Distribution License (the "License").
6*a2f144d1SJordan Brown * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
2161961e0fSrobinson
227c478bd9Sstevel@tonic-gate /*
23*a2f144d1SJordan Brown * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
307c478bd9Sstevel@tonic-gate * The Regents of the University of California
317c478bd9Sstevel@tonic-gate * All Rights Reserved
327c478bd9Sstevel@tonic-gate *
337c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
347c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
357c478bd9Sstevel@tonic-gate * contributors.
367c478bd9Sstevel@tonic-gate */
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate * rpc_parse.c, Parser for the RPC protocol compiler
407c478bd9Sstevel@tonic-gate */
417c478bd9Sstevel@tonic-gate #include <stdio.h>
4261961e0fSrobinson #include <stdlib.h>
437c478bd9Sstevel@tonic-gate #include <string.h>
447c478bd9Sstevel@tonic-gate #include "rpc/types.h"
457c478bd9Sstevel@tonic-gate #include "rpc_scan.h"
467c478bd9Sstevel@tonic-gate #include "rpc_parse.h"
477c478bd9Sstevel@tonic-gate #include "rpc_util.h"
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate #define ARGNAME "arg"
507c478bd9Sstevel@tonic-gate
5161961e0fSrobinson extern char *make_argname(char *, char *);
5261961e0fSrobinson
5361961e0fSrobinson static void isdefined(definition *);
5461961e0fSrobinson static void def_struct(definition *);
5561961e0fSrobinson static void def_program(definition *);
5661961e0fSrobinson static void def_enum(definition *);
5761961e0fSrobinson static void def_const(definition *);
5861961e0fSrobinson static void def_union(definition *);
5961961e0fSrobinson static void def_typedef(definition *);
6061961e0fSrobinson static void get_declaration(declaration *, defkind);
6161961e0fSrobinson static void get_prog_declaration(declaration *, defkind, int);
6261961e0fSrobinson static void get_type(char **, char **, defkind);
6361961e0fSrobinson static void unsigned_dec(char **);
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate * return the next definition you see
677c478bd9Sstevel@tonic-gate */
687c478bd9Sstevel@tonic-gate definition *
get_definition(void)6961961e0fSrobinson get_definition(void)
707c478bd9Sstevel@tonic-gate {
717c478bd9Sstevel@tonic-gate definition *defp;
727c478bd9Sstevel@tonic-gate token tok;
737c478bd9Sstevel@tonic-gate
7461961e0fSrobinson defp = calloc(1, sizeof (definition));
757c478bd9Sstevel@tonic-gate get_token(&tok);
767c478bd9Sstevel@tonic-gate switch (tok.kind) {
777c478bd9Sstevel@tonic-gate case TOK_STRUCT:
787c478bd9Sstevel@tonic-gate def_struct(defp);
797c478bd9Sstevel@tonic-gate break;
807c478bd9Sstevel@tonic-gate case TOK_UNION:
817c478bd9Sstevel@tonic-gate def_union(defp);
827c478bd9Sstevel@tonic-gate break;
837c478bd9Sstevel@tonic-gate case TOK_TYPEDEF:
847c478bd9Sstevel@tonic-gate def_typedef(defp);
857c478bd9Sstevel@tonic-gate break;
867c478bd9Sstevel@tonic-gate case TOK_ENUM:
877c478bd9Sstevel@tonic-gate def_enum(defp);
887c478bd9Sstevel@tonic-gate break;
897c478bd9Sstevel@tonic-gate case TOK_PROGRAM:
907c478bd9Sstevel@tonic-gate def_program(defp);
917c478bd9Sstevel@tonic-gate break;
927c478bd9Sstevel@tonic-gate case TOK_CONST:
937c478bd9Sstevel@tonic-gate def_const(defp);
947c478bd9Sstevel@tonic-gate break;
957c478bd9Sstevel@tonic-gate case TOK_EOF:
967c478bd9Sstevel@tonic-gate return (NULL);
977c478bd9Sstevel@tonic-gate default:
987c478bd9Sstevel@tonic-gate error("definition keyword expected");
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate scan(TOK_SEMICOLON, &tok);
1017c478bd9Sstevel@tonic-gate isdefined(defp);
1027c478bd9Sstevel@tonic-gate return (defp);
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate
10561961e0fSrobinson static void
isdefined(definition * defp)10661961e0fSrobinson isdefined(definition *defp)
1077c478bd9Sstevel@tonic-gate {
1087c478bd9Sstevel@tonic-gate STOREVAL(&defined, defp);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate * We treat s == NULL the same as *s == '\0'
1137c478bd9Sstevel@tonic-gate */
11461961e0fSrobinson static int
streqn(const char * s1,const char * s2)1157c478bd9Sstevel@tonic-gate streqn(const char *s1, const char *s2)
1167c478bd9Sstevel@tonic-gate {
1177c478bd9Sstevel@tonic-gate if (s1 == NULL)
1187c478bd9Sstevel@tonic-gate s1 = "";
1197c478bd9Sstevel@tonic-gate if (s2 == NULL)
1207c478bd9Sstevel@tonic-gate s2 = "";
1217c478bd9Sstevel@tonic-gate if (s1 == s2)
1227c478bd9Sstevel@tonic-gate return (1);
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate return (strcmp(s1, s2) == 0);
1257c478bd9Sstevel@tonic-gate }
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate static int
cmptype(definition * defp,char * type)1287c478bd9Sstevel@tonic-gate cmptype(definition *defp, char *type)
1297c478bd9Sstevel@tonic-gate {
1307c478bd9Sstevel@tonic-gate /* We only want typedef definitions */
1317c478bd9Sstevel@tonic-gate if (streq(defp->def_name, type) && defp->def_kind == DEF_TYPEDEF)
1327c478bd9Sstevel@tonic-gate return (1);
1337c478bd9Sstevel@tonic-gate return (0);
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate static int
check_self_reference(const char * name,const declaration * decp,int first)1377c478bd9Sstevel@tonic-gate check_self_reference(const char *name, const declaration *decp, int first)
1387c478bd9Sstevel@tonic-gate {
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate * Now check for the following special case if first is true:
1417c478bd9Sstevel@tonic-gate *
1427c478bd9Sstevel@tonic-gate * struct foo {
1437c478bd9Sstevel@tonic-gate * ...
1447c478bd9Sstevel@tonic-gate * foo *next;
1457c478bd9Sstevel@tonic-gate * };
1467c478bd9Sstevel@tonic-gate *
1477c478bd9Sstevel@tonic-gate *
1487c478bd9Sstevel@tonic-gate * In the above cases foo has not yet been entered in the type list,
1497c478bd9Sstevel@tonic-gate * defined. So there is no typedef entry. The prefix in that case
1507c478bd9Sstevel@tonic-gate * could be empty.
1517c478bd9Sstevel@tonic-gate */
1527c478bd9Sstevel@tonic-gate if (decp->rel == REL_POINTER &&
1537c478bd9Sstevel@tonic-gate (streqn(decp->prefix, "struct") ||
1547c478bd9Sstevel@tonic-gate (first && streqn(decp->prefix, ""))) &&
1557c478bd9Sstevel@tonic-gate streqn(name, decp->type))
1567c478bd9Sstevel@tonic-gate return (1);
1577c478bd9Sstevel@tonic-gate return (0);
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate static int
is_self_reference(definition * defp,declaration * decp)1617c478bd9Sstevel@tonic-gate is_self_reference(definition *defp, declaration *decp)
1627c478bd9Sstevel@tonic-gate {
1637c478bd9Sstevel@tonic-gate declaration current;
1647c478bd9Sstevel@tonic-gate definition *dp;
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate if (check_self_reference(defp->def_name, decp, 1))
1677c478bd9Sstevel@tonic-gate return (1);
1687c478bd9Sstevel@tonic-gate
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate * Check for valid declaration:
1717c478bd9Sstevel@tonic-gate * Only prefixes allowed are none and struct.
1727c478bd9Sstevel@tonic-gate * Only relations allowed are pointer or alias.
1737c478bd9Sstevel@tonic-gate */
1747c478bd9Sstevel@tonic-gate if (!streqn(decp->prefix, "struct") && !streqn(decp->prefix, ""))
1757c478bd9Sstevel@tonic-gate return (0);
1767c478bd9Sstevel@tonic-gate if (decp->rel != REL_POINTER && decp->rel != REL_ALIAS)
1777c478bd9Sstevel@tonic-gate return (0);
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate current.rel = decp->rel;
1807c478bd9Sstevel@tonic-gate current.prefix = decp->prefix;
1817c478bd9Sstevel@tonic-gate current.type = decp->type;
1827c478bd9Sstevel@tonic-gate current.name = decp->name;
1837c478bd9Sstevel@tonic-gate decp = ¤t;
1847c478bd9Sstevel@tonic-gate while (!check_self_reference(defp->def_name, decp, 0)) {
1857c478bd9Sstevel@tonic-gate dp = FINDVAL(defined, decp->type, cmptype);
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate * Check if we found a definition.
1897c478bd9Sstevel@tonic-gate */
1907c478bd9Sstevel@tonic-gate if (dp == NULL)
1917c478bd9Sstevel@tonic-gate return (0);
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate * Check for valid prefix. We eventually need to see one
1957c478bd9Sstevel@tonic-gate * and only one struct.
1967c478bd9Sstevel@tonic-gate */
1977c478bd9Sstevel@tonic-gate if (streqn(decp->prefix, "")) {
1987c478bd9Sstevel@tonic-gate /*
1997c478bd9Sstevel@tonic-gate * If the current declaration prefix in empty
2007c478bd9Sstevel@tonic-gate * then the definition found must have an empty
2017c478bd9Sstevel@tonic-gate * prefix or a struct prefix
2027c478bd9Sstevel@tonic-gate */
2037c478bd9Sstevel@tonic-gate if (!streqn(dp->def.ty.old_prefix, "") &&
2047c478bd9Sstevel@tonic-gate !streqn(dp->def.ty.old_prefix, "struct"))
2057c478bd9Sstevel@tonic-gate return (0);
2067c478bd9Sstevel@tonic-gate } else if (streqn(decp->prefix, "struct") &&
2077c478bd9Sstevel@tonic-gate !streqn(dp->def.ty.old_prefix, ""))
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate * if the current prefix is struct tne new prefix
2107c478bd9Sstevel@tonic-gate * must be empty
2117c478bd9Sstevel@tonic-gate */
2127c478bd9Sstevel@tonic-gate return (0);
2137c478bd9Sstevel@tonic-gate else if (!streqn(decp->prefix, "struct"))
2147c478bd9Sstevel@tonic-gate /* Should never get here */
2157c478bd9Sstevel@tonic-gate return (0);
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate * Check for valid relation. We need to see one and
2197c478bd9Sstevel@tonic-gate * only one REL_POINTER. The only valid relation types
2207c478bd9Sstevel@tonic-gate * are REL_POINTER and REL_ALIAS.
2217c478bd9Sstevel@tonic-gate */
2227c478bd9Sstevel@tonic-gate if (decp->rel == REL_POINTER && dp->def.ty.rel != REL_ALIAS)
2237c478bd9Sstevel@tonic-gate return (0);
22461961e0fSrobinson if (decp->rel == REL_ALIAS &&
2257c478bd9Sstevel@tonic-gate (dp->def.ty.rel != REL_ALIAS &&
2267c478bd9Sstevel@tonic-gate dp->def.ty.rel != REL_POINTER))
2277c478bd9Sstevel@tonic-gate return (0);
22861961e0fSrobinson if (decp->rel != REL_ALIAS && decp->rel != REL_POINTER)
2297c478bd9Sstevel@tonic-gate /* Should never get here */
2307c478bd9Sstevel@tonic-gate return (0);
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate /* Set up the current declaration */
2337c478bd9Sstevel@tonic-gate if (streqn(decp->prefix, ""))
2347c478bd9Sstevel@tonic-gate decp->prefix = dp->def.ty.old_prefix;
2357c478bd9Sstevel@tonic-gate decp->type = dp->def.ty.old_type;
2367c478bd9Sstevel@tonic-gate if (decp->rel == REL_ALIAS)
2377c478bd9Sstevel@tonic-gate decp->rel = dp->def.ty.rel;
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate /* We have a self reference type */
2417c478bd9Sstevel@tonic-gate return (1);
2427c478bd9Sstevel@tonic-gate }
2437c478bd9Sstevel@tonic-gate
24461961e0fSrobinson static void
def_struct(definition * defp)24561961e0fSrobinson def_struct(definition *defp)
2467c478bd9Sstevel@tonic-gate {
2477c478bd9Sstevel@tonic-gate token tok;
2487c478bd9Sstevel@tonic-gate declaration dec;
2497c478bd9Sstevel@tonic-gate decl_list *decls;
2507c478bd9Sstevel@tonic-gate decl_list **tailp, *endp;
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate defp->def_kind = DEF_STRUCT;
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate scan(TOK_IDENT, &tok);
2557c478bd9Sstevel@tonic-gate defp->def_name = tok.str;
2567c478bd9Sstevel@tonic-gate scan(TOK_LBRACE, &tok);
2577c478bd9Sstevel@tonic-gate tailp = &defp->def.st.decls;
2587c478bd9Sstevel@tonic-gate defp->def.st.tail = NULL;
2597c478bd9Sstevel@tonic-gate do {
2607c478bd9Sstevel@tonic-gate get_declaration(&dec, DEF_STRUCT);
26161961e0fSrobinson decls = calloc(1, sizeof (decl_list));
2627c478bd9Sstevel@tonic-gate decls->decl = dec;
2637c478bd9Sstevel@tonic-gate /*
2647c478bd9Sstevel@tonic-gate * Keep a referenct to the last declaration to check for
2657c478bd9Sstevel@tonic-gate * tail recurrsion.
2667c478bd9Sstevel@tonic-gate */
2677c478bd9Sstevel@tonic-gate endp = *tailp = decls;
2687c478bd9Sstevel@tonic-gate tailp = &decls->next;
2697c478bd9Sstevel@tonic-gate scan(TOK_SEMICOLON, &tok);
2707c478bd9Sstevel@tonic-gate peek(&tok);
2717c478bd9Sstevel@tonic-gate } while (tok.kind != TOK_RBRACE);
2727c478bd9Sstevel@tonic-gate *tailp = NULL;
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate * Check for tail recurse. If the last declaration refers to this
2757c478bd9Sstevel@tonic-gate * structure then mark this stucture to convert the tail recursion
2767c478bd9Sstevel@tonic-gate * to itteration.
2777c478bd9Sstevel@tonic-gate */
2787c478bd9Sstevel@tonic-gate defp->def.st.self_pointer = is_self_reference(defp, &endp->decl);
2797c478bd9Sstevel@tonic-gate get_token(&tok);
2807c478bd9Sstevel@tonic-gate defp->def.st.tail = endp;
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate
28361961e0fSrobinson static void
def_program(definition * defp)28461961e0fSrobinson def_program(definition *defp)
2857c478bd9Sstevel@tonic-gate {
2867c478bd9Sstevel@tonic-gate token tok;
2877c478bd9Sstevel@tonic-gate declaration dec;
2887c478bd9Sstevel@tonic-gate decl_list *decls;
2897c478bd9Sstevel@tonic-gate decl_list **tailp;
2907c478bd9Sstevel@tonic-gate version_list *vlist;
2917c478bd9Sstevel@tonic-gate version_list **vtailp;
2927c478bd9Sstevel@tonic-gate proc_list *plist;
2937c478bd9Sstevel@tonic-gate proc_list **ptailp;
2947c478bd9Sstevel@tonic-gate int num_args;
2957c478bd9Sstevel@tonic-gate bool_t isvoid = FALSE; /* whether first argument is void */
2967c478bd9Sstevel@tonic-gate defp->def_kind = DEF_PROGRAM;
2977c478bd9Sstevel@tonic-gate scan(TOK_IDENT, &tok);
2987c478bd9Sstevel@tonic-gate defp->def_name = tok.str;
2997c478bd9Sstevel@tonic-gate scan(TOK_LBRACE, &tok);
3007c478bd9Sstevel@tonic-gate vtailp = &defp->def.pr.versions;
3017c478bd9Sstevel@tonic-gate tailp = &defp->def.st.decls;
3027c478bd9Sstevel@tonic-gate scan(TOK_VERSION, &tok);
3037c478bd9Sstevel@tonic-gate do {
3047c478bd9Sstevel@tonic-gate scan(TOK_IDENT, &tok);
30561961e0fSrobinson vlist = calloc(1, sizeof (version_list));
3067c478bd9Sstevel@tonic-gate vlist->vers_name = tok.str;
3077c478bd9Sstevel@tonic-gate scan(TOK_LBRACE, &tok);
3087c478bd9Sstevel@tonic-gate ptailp = &vlist->procs;
3097c478bd9Sstevel@tonic-gate do {
3107c478bd9Sstevel@tonic-gate /* get result type */
31161961e0fSrobinson plist = calloc(1, sizeof (proc_list));
3127c478bd9Sstevel@tonic-gate get_type(&plist->res_prefix, &plist->res_type,
3137c478bd9Sstevel@tonic-gate DEF_RESULT);
3147c478bd9Sstevel@tonic-gate if (streq(plist->res_type, "opaque")) {
3157c478bd9Sstevel@tonic-gate error("illegal result type");
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate scan(TOK_IDENT, &tok);
3187c478bd9Sstevel@tonic-gate plist->proc_name = tok.str;
3197c478bd9Sstevel@tonic-gate scan(TOK_LPAREN, &tok);
3207c478bd9Sstevel@tonic-gate /* get args - first one */
3217c478bd9Sstevel@tonic-gate num_args = 1;
3227c478bd9Sstevel@tonic-gate isvoid = FALSE;
3237c478bd9Sstevel@tonic-gate /*
3247c478bd9Sstevel@tonic-gate * type of DEF_PROGRAM in the first
3257c478bd9Sstevel@tonic-gate * get_prog_declaration and DEF_STURCT in the next
3267c478bd9Sstevel@tonic-gate * allows void as argument if it is the only argument
3277c478bd9Sstevel@tonic-gate */
3287c478bd9Sstevel@tonic-gate get_prog_declaration(&dec, DEF_PROGRAM, num_args);
3297c478bd9Sstevel@tonic-gate if (streq(dec.type, "void"))
3307c478bd9Sstevel@tonic-gate isvoid = TRUE;
33161961e0fSrobinson decls = calloc(1, sizeof (decl_list));
3327c478bd9Sstevel@tonic-gate plist->args.decls = decls;
3337c478bd9Sstevel@tonic-gate decls->decl = dec;
3347c478bd9Sstevel@tonic-gate tailp = &decls->next;
3357c478bd9Sstevel@tonic-gate /* get args */
3367c478bd9Sstevel@tonic-gate while (peekscan(TOK_COMMA, &tok)) {
3377c478bd9Sstevel@tonic-gate num_args++;
3387c478bd9Sstevel@tonic-gate get_prog_declaration(&dec, DEF_STRUCT,
3397c478bd9Sstevel@tonic-gate num_args);
34061961e0fSrobinson decls = calloc(1, sizeof (decl_list));
3417c478bd9Sstevel@tonic-gate decls->decl = dec;
3427c478bd9Sstevel@tonic-gate *tailp = decls;
3437c478bd9Sstevel@tonic-gate if (streq(dec.type, "void"))
3447c478bd9Sstevel@tonic-gate isvoid = TRUE;
3457c478bd9Sstevel@tonic-gate tailp = &decls->next;
3467c478bd9Sstevel@tonic-gate }
3477c478bd9Sstevel@tonic-gate /* multiple arguments are only allowed in newstyle */
3487c478bd9Sstevel@tonic-gate if (!newstyle && num_args > 1) {
3497c478bd9Sstevel@tonic-gate error("only one argument is allowed");
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate if (isvoid && num_args > 1) {
3527c478bd9Sstevel@tonic-gate error("illegal use of void "
3537c478bd9Sstevel@tonic-gate "in program definition");
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate *tailp = NULL;
3567c478bd9Sstevel@tonic-gate scan(TOK_RPAREN, &tok);
3577c478bd9Sstevel@tonic-gate scan(TOK_EQUAL, &tok);
3587c478bd9Sstevel@tonic-gate scan_num(&tok);
3597c478bd9Sstevel@tonic-gate scan(TOK_SEMICOLON, &tok);
3607c478bd9Sstevel@tonic-gate plist->proc_num = tok.str;
3617c478bd9Sstevel@tonic-gate plist->arg_num = num_args;
3627c478bd9Sstevel@tonic-gate *ptailp = plist;
3637c478bd9Sstevel@tonic-gate ptailp = &plist->next;
3647c478bd9Sstevel@tonic-gate peek(&tok);
3657c478bd9Sstevel@tonic-gate } while (tok.kind != TOK_RBRACE);
3667c478bd9Sstevel@tonic-gate *ptailp = NULL;
3677c478bd9Sstevel@tonic-gate *vtailp = vlist;
3687c478bd9Sstevel@tonic-gate vtailp = &vlist->next;
3697c478bd9Sstevel@tonic-gate scan(TOK_RBRACE, &tok);
3707c478bd9Sstevel@tonic-gate scan(TOK_EQUAL, &tok);
3717c478bd9Sstevel@tonic-gate scan_num(&tok);
3727c478bd9Sstevel@tonic-gate vlist->vers_num = tok.str;
3737c478bd9Sstevel@tonic-gate /* make the argument structure name for each arg */
37461961e0fSrobinson for (plist = vlist->procs; plist != NULL; plist = plist->next) {
3757c478bd9Sstevel@tonic-gate plist->args.argname = make_argname(plist->proc_name,
3767c478bd9Sstevel@tonic-gate vlist->vers_num);
3777c478bd9Sstevel@tonic-gate /* free the memory ?? */
3787c478bd9Sstevel@tonic-gate }
3797c478bd9Sstevel@tonic-gate scan(TOK_SEMICOLON, &tok);
3807c478bd9Sstevel@tonic-gate scan2(TOK_VERSION, TOK_RBRACE, &tok);
3817c478bd9Sstevel@tonic-gate } while (tok.kind == TOK_VERSION);
3827c478bd9Sstevel@tonic-gate scan(TOK_EQUAL, &tok);
3837c478bd9Sstevel@tonic-gate scan_num(&tok);
3847c478bd9Sstevel@tonic-gate defp->def.pr.prog_num = tok.str;
3857c478bd9Sstevel@tonic-gate *vtailp = NULL;
3867c478bd9Sstevel@tonic-gate }
3877c478bd9Sstevel@tonic-gate
38861961e0fSrobinson static void
def_enum(definition * defp)38961961e0fSrobinson def_enum(definition *defp)
3907c478bd9Sstevel@tonic-gate {
3917c478bd9Sstevel@tonic-gate token tok;
3927c478bd9Sstevel@tonic-gate enumval_list *elist;
3937c478bd9Sstevel@tonic-gate enumval_list **tailp;
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate defp->def_kind = DEF_ENUM;
3967c478bd9Sstevel@tonic-gate scan(TOK_IDENT, &tok);
3977c478bd9Sstevel@tonic-gate defp->def_name = tok.str;
3987c478bd9Sstevel@tonic-gate scan(TOK_LBRACE, &tok);
3997c478bd9Sstevel@tonic-gate tailp = &defp->def.en.vals;
4007c478bd9Sstevel@tonic-gate do {
4017c478bd9Sstevel@tonic-gate scan(TOK_IDENT, &tok);
40261961e0fSrobinson elist = calloc(1, sizeof (enumval_list));
4037c478bd9Sstevel@tonic-gate elist->name = tok.str;
4047c478bd9Sstevel@tonic-gate elist->assignment = NULL;
4057c478bd9Sstevel@tonic-gate scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
4067c478bd9Sstevel@tonic-gate if (tok.kind == TOK_EQUAL) {
4077c478bd9Sstevel@tonic-gate scan_num(&tok);
4087c478bd9Sstevel@tonic-gate elist->assignment = tok.str;
4097c478bd9Sstevel@tonic-gate scan2(TOK_COMMA, TOK_RBRACE, &tok);
4107c478bd9Sstevel@tonic-gate }
4117c478bd9Sstevel@tonic-gate *tailp = elist;
4127c478bd9Sstevel@tonic-gate tailp = &elist->next;
4137c478bd9Sstevel@tonic-gate } while (tok.kind != TOK_RBRACE);
4147c478bd9Sstevel@tonic-gate *tailp = NULL;
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate
41761961e0fSrobinson static void
def_const(definition * defp)41861961e0fSrobinson def_const(definition *defp)
4197c478bd9Sstevel@tonic-gate {
4207c478bd9Sstevel@tonic-gate token tok;
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate defp->def_kind = DEF_CONST;
4237c478bd9Sstevel@tonic-gate scan(TOK_IDENT, &tok);
4247c478bd9Sstevel@tonic-gate defp->def_name = tok.str;
4257c478bd9Sstevel@tonic-gate scan(TOK_EQUAL, &tok);
4267c478bd9Sstevel@tonic-gate scan2(TOK_IDENT, TOK_STRCONST, &tok);
4277c478bd9Sstevel@tonic-gate defp->def.co = tok.str;
4287c478bd9Sstevel@tonic-gate }
4297c478bd9Sstevel@tonic-gate
43061961e0fSrobinson static void
def_union(definition * defp)43161961e0fSrobinson def_union(definition *defp)
4327c478bd9Sstevel@tonic-gate {
4337c478bd9Sstevel@tonic-gate token tok;
4347c478bd9Sstevel@tonic-gate declaration dec;
43561961e0fSrobinson case_list *cases;
4367c478bd9Sstevel@tonic-gate case_list **tailp;
4377c478bd9Sstevel@tonic-gate int flag;
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate defp->def_kind = DEF_UNION;
4407c478bd9Sstevel@tonic-gate scan(TOK_IDENT, &tok);
4417c478bd9Sstevel@tonic-gate defp->def_name = tok.str;
4427c478bd9Sstevel@tonic-gate scan(TOK_SWITCH, &tok);
4437c478bd9Sstevel@tonic-gate scan(TOK_LPAREN, &tok);
4447c478bd9Sstevel@tonic-gate get_declaration(&dec, DEF_UNION);
4457c478bd9Sstevel@tonic-gate defp->def.un.enum_decl = dec;
4467c478bd9Sstevel@tonic-gate tailp = &defp->def.un.cases;
4477c478bd9Sstevel@tonic-gate scan(TOK_RPAREN, &tok);
4487c478bd9Sstevel@tonic-gate scan(TOK_LBRACE, &tok);
4497c478bd9Sstevel@tonic-gate scan(TOK_CASE, &tok);
4507c478bd9Sstevel@tonic-gate while (tok.kind == TOK_CASE) {
4517c478bd9Sstevel@tonic-gate scan2(TOK_IDENT, TOK_CHARCONST, &tok);
45261961e0fSrobinson cases = calloc(1, sizeof (case_list));
4537c478bd9Sstevel@tonic-gate cases->case_name = tok.str;
4547c478bd9Sstevel@tonic-gate scan(TOK_COLON, &tok);
4557c478bd9Sstevel@tonic-gate /* now peek at next token */
4567c478bd9Sstevel@tonic-gate flag = 0;
4577c478bd9Sstevel@tonic-gate if (peekscan(TOK_CASE, &tok)) {
4587c478bd9Sstevel@tonic-gate do {
4597c478bd9Sstevel@tonic-gate scan2(TOK_IDENT, TOK_CHARCONST, &tok);
4607c478bd9Sstevel@tonic-gate cases->contflag = 1;
4617c478bd9Sstevel@tonic-gate /* continued case statement */
4627c478bd9Sstevel@tonic-gate *tailp = cases;
4637c478bd9Sstevel@tonic-gate tailp = &cases->next;
46461961e0fSrobinson cases = calloc(1, sizeof (case_list));
4657c478bd9Sstevel@tonic-gate cases->case_name = tok.str;
4667c478bd9Sstevel@tonic-gate scan(TOK_COLON, &tok);
4677c478bd9Sstevel@tonic-gate } while (peekscan(TOK_CASE, &tok));
46861961e0fSrobinson } else if (flag) {
4697c478bd9Sstevel@tonic-gate *tailp = cases;
4707c478bd9Sstevel@tonic-gate tailp = &cases->next;
47161961e0fSrobinson cases = calloc(1, sizeof (case_list));
47261961e0fSrobinson }
4737c478bd9Sstevel@tonic-gate
4747c478bd9Sstevel@tonic-gate get_declaration(&dec, DEF_UNION);
4757c478bd9Sstevel@tonic-gate cases->case_decl = dec;
4767c478bd9Sstevel@tonic-gate cases->contflag = 0; /* no continued case statement */
4777c478bd9Sstevel@tonic-gate *tailp = cases;
4787c478bd9Sstevel@tonic-gate tailp = &cases->next;
4797c478bd9Sstevel@tonic-gate scan(TOK_SEMICOLON, &tok);
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
4827c478bd9Sstevel@tonic-gate }
4837c478bd9Sstevel@tonic-gate *tailp = NULL;
4847c478bd9Sstevel@tonic-gate if (tok.kind == TOK_DEFAULT) {
4857c478bd9Sstevel@tonic-gate scan(TOK_COLON, &tok);
4867c478bd9Sstevel@tonic-gate get_declaration(&dec, DEF_UNION);
48761961e0fSrobinson defp->def.un.default_decl = calloc(1, sizeof (declaration));
4887c478bd9Sstevel@tonic-gate *defp->def.un.default_decl = dec;
4897c478bd9Sstevel@tonic-gate scan(TOK_SEMICOLON, &tok);
4907c478bd9Sstevel@tonic-gate scan(TOK_RBRACE, &tok);
4917c478bd9Sstevel@tonic-gate } else {
4927c478bd9Sstevel@tonic-gate defp->def.un.default_decl = NULL;
4937c478bd9Sstevel@tonic-gate }
4947c478bd9Sstevel@tonic-gate }
4957c478bd9Sstevel@tonic-gate
49661961e0fSrobinson static char *reserved_words[] = {
4977c478bd9Sstevel@tonic-gate "array",
4987c478bd9Sstevel@tonic-gate "bytes",
4997c478bd9Sstevel@tonic-gate "destroy",
5007c478bd9Sstevel@tonic-gate "free",
5017c478bd9Sstevel@tonic-gate "getpos",
5027c478bd9Sstevel@tonic-gate "inline",
5037c478bd9Sstevel@tonic-gate "pointer",
5047c478bd9Sstevel@tonic-gate "reference",
5057c478bd9Sstevel@tonic-gate "setpos",
5067c478bd9Sstevel@tonic-gate "sizeof",
5077c478bd9Sstevel@tonic-gate "union",
5087c478bd9Sstevel@tonic-gate "vector",
5097c478bd9Sstevel@tonic-gate NULL
5107c478bd9Sstevel@tonic-gate };
5117c478bd9Sstevel@tonic-gate
51261961e0fSrobinson static char *reserved_types[] = {
5137c478bd9Sstevel@tonic-gate "opaque",
5147c478bd9Sstevel@tonic-gate "string",
5157c478bd9Sstevel@tonic-gate NULL
5167c478bd9Sstevel@tonic-gate };
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate /*
5197c478bd9Sstevel@tonic-gate * check that the given name is not one that would eventually result in
5207c478bd9Sstevel@tonic-gate * xdr routines that would conflict with internal XDR routines.
5217c478bd9Sstevel@tonic-gate */
52261961e0fSrobinson static void
check_type_name(char * name,int new_type)52361961e0fSrobinson check_type_name(char *name, int new_type)
5247c478bd9Sstevel@tonic-gate {
5257c478bd9Sstevel@tonic-gate int i;
5267c478bd9Sstevel@tonic-gate char tmp[100];
5277c478bd9Sstevel@tonic-gate
5287c478bd9Sstevel@tonic-gate for (i = 0; reserved_words[i] != NULL; i++) {
5297c478bd9Sstevel@tonic-gate if (strcmp(name, reserved_words[i]) == 0) {
53061961e0fSrobinson (void) snprintf(tmp, sizeof (tmp),
5317c478bd9Sstevel@tonic-gate "illegal (reserved) name :\'%s\' "
5327c478bd9Sstevel@tonic-gate "in type definition",
5337c478bd9Sstevel@tonic-gate name);
5347c478bd9Sstevel@tonic-gate error(tmp);
5357c478bd9Sstevel@tonic-gate }
5367c478bd9Sstevel@tonic-gate }
5377c478bd9Sstevel@tonic-gate if (new_type) {
5387c478bd9Sstevel@tonic-gate for (i = 0; reserved_types[i] != NULL; i++) {
5397c478bd9Sstevel@tonic-gate if (strcmp(name, reserved_types[i]) == 0) {
54061961e0fSrobinson (void) snprintf(tmp, sizeof (tmp),
5417c478bd9Sstevel@tonic-gate "illegal (reserved) name :\'%s\' "
5427c478bd9Sstevel@tonic-gate "in type definition",
5437c478bd9Sstevel@tonic-gate name);
5447c478bd9Sstevel@tonic-gate error(tmp);
5457c478bd9Sstevel@tonic-gate }
5467c478bd9Sstevel@tonic-gate }
5477c478bd9Sstevel@tonic-gate }
5487c478bd9Sstevel@tonic-gate }
5497c478bd9Sstevel@tonic-gate
55061961e0fSrobinson static void
def_typedef(definition * defp)55161961e0fSrobinson def_typedef(definition *defp)
5527c478bd9Sstevel@tonic-gate {
5537c478bd9Sstevel@tonic-gate declaration dec;
5547c478bd9Sstevel@tonic-gate
5557c478bd9Sstevel@tonic-gate defp->def_kind = DEF_TYPEDEF;
5567c478bd9Sstevel@tonic-gate get_declaration(&dec, DEF_TYPEDEF);
5577c478bd9Sstevel@tonic-gate defp->def_name = dec.name;
5587c478bd9Sstevel@tonic-gate check_type_name(dec.name, 1);
5597c478bd9Sstevel@tonic-gate defp->def.ty.old_prefix = dec.prefix;
5607c478bd9Sstevel@tonic-gate defp->def.ty.old_type = dec.type;
5617c478bd9Sstevel@tonic-gate defp->def.ty.rel = dec.rel;
5627c478bd9Sstevel@tonic-gate defp->def.ty.array_max = dec.array_max;
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate
56561961e0fSrobinson static void
get_declaration(declaration * dec,defkind dkind)56661961e0fSrobinson get_declaration(declaration *dec, defkind dkind)
5677c478bd9Sstevel@tonic-gate {
5687c478bd9Sstevel@tonic-gate token tok;
5697c478bd9Sstevel@tonic-gate
5707c478bd9Sstevel@tonic-gate get_type(&dec->prefix, &dec->type, dkind);
5717c478bd9Sstevel@tonic-gate dec->rel = REL_ALIAS;
57261961e0fSrobinson if (streq(dec->type, "void"))
5737c478bd9Sstevel@tonic-gate return;
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate check_type_name(dec->type, 0);
5767c478bd9Sstevel@tonic-gate scan2(TOK_STAR, TOK_IDENT, &tok);
5777c478bd9Sstevel@tonic-gate if (tok.kind == TOK_STAR) {
5787c478bd9Sstevel@tonic-gate dec->rel = REL_POINTER;
5797c478bd9Sstevel@tonic-gate scan(TOK_IDENT, &tok);
5807c478bd9Sstevel@tonic-gate }
5817c478bd9Sstevel@tonic-gate dec->name = tok.str;
5827c478bd9Sstevel@tonic-gate if (peekscan(TOK_LBRACKET, &tok)) {
58361961e0fSrobinson if (dec->rel == REL_POINTER)
5847c478bd9Sstevel@tonic-gate error("no array-of-pointer declarations "
5857c478bd9Sstevel@tonic-gate "-- use typedef");
5867c478bd9Sstevel@tonic-gate dec->rel = REL_VECTOR;
5877c478bd9Sstevel@tonic-gate scan_num(&tok);
5887c478bd9Sstevel@tonic-gate dec->array_max = tok.str;
5897c478bd9Sstevel@tonic-gate scan(TOK_RBRACKET, &tok);
5907c478bd9Sstevel@tonic-gate } else if (peekscan(TOK_LANGLE, &tok)) {
59161961e0fSrobinson if (dec->rel == REL_POINTER)
5927c478bd9Sstevel@tonic-gate error("no array-of-pointer declarations "
5937c478bd9Sstevel@tonic-gate "-- use typedef");
5947c478bd9Sstevel@tonic-gate dec->rel = REL_ARRAY;
5957c478bd9Sstevel@tonic-gate if (peekscan(TOK_RANGLE, &tok)) {
5967c478bd9Sstevel@tonic-gate dec->array_max = "~0"; /* unspecified size, use max */
5977c478bd9Sstevel@tonic-gate } else {
5987c478bd9Sstevel@tonic-gate scan_num(&tok);
5997c478bd9Sstevel@tonic-gate dec->array_max = tok.str;
6007c478bd9Sstevel@tonic-gate scan(TOK_RANGLE, &tok);
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate }
6037c478bd9Sstevel@tonic-gate if (streq(dec->type, "opaque")) {
6047c478bd9Sstevel@tonic-gate if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) {
6057c478bd9Sstevel@tonic-gate error("array declaration expected");
6067c478bd9Sstevel@tonic-gate }
6077c478bd9Sstevel@tonic-gate } else if (streq(dec->type, "string")) {
6087c478bd9Sstevel@tonic-gate if (dec->rel != REL_ARRAY) {
6097c478bd9Sstevel@tonic-gate error("variable-length array declaration expected");
6107c478bd9Sstevel@tonic-gate }
6117c478bd9Sstevel@tonic-gate }
6127c478bd9Sstevel@tonic-gate }
6137c478bd9Sstevel@tonic-gate
61461961e0fSrobinson static void
get_prog_declaration(declaration * dec,defkind dkind,int num)61561961e0fSrobinson get_prog_declaration(declaration *dec, defkind dkind, int num)
6167c478bd9Sstevel@tonic-gate {
6177c478bd9Sstevel@tonic-gate token tok;
6187c478bd9Sstevel@tonic-gate char name[sizeof (ARGNAME) + 10];
6197c478bd9Sstevel@tonic-gate
6207c478bd9Sstevel@tonic-gate if (dkind == DEF_PROGRAM) {
6217c478bd9Sstevel@tonic-gate peek(&tok);
6227c478bd9Sstevel@tonic-gate if (tok.kind == TOK_RPAREN) { /* no arguments */
6237c478bd9Sstevel@tonic-gate dec->rel = REL_ALIAS;
6247c478bd9Sstevel@tonic-gate dec->type = "void";
6257c478bd9Sstevel@tonic-gate dec->prefix = NULL;
6267c478bd9Sstevel@tonic-gate dec->name = NULL;
6277c478bd9Sstevel@tonic-gate return;
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate }
6307c478bd9Sstevel@tonic-gate get_type(&dec->prefix, &dec->type, dkind);
6317c478bd9Sstevel@tonic-gate dec->rel = REL_ALIAS;
6327c478bd9Sstevel@tonic-gate if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */
6337c478bd9Sstevel@tonic-gate dec->name = strdup(tok.str);
6347c478bd9Sstevel@tonic-gate else {
6357c478bd9Sstevel@tonic-gate /* default name of argument */
63661961e0fSrobinson (void) snprintf(name, sizeof (name), "%s%d", ARGNAME, num);
6377c478bd9Sstevel@tonic-gate dec->name = strdup(name);
6387c478bd9Sstevel@tonic-gate }
6397c478bd9Sstevel@tonic-gate if (dec->name == NULL)
6407c478bd9Sstevel@tonic-gate error("internal error -- out of memory");
6417c478bd9Sstevel@tonic-gate
64261961e0fSrobinson if (streq(dec->type, "void"))
6437c478bd9Sstevel@tonic-gate return;
6447c478bd9Sstevel@tonic-gate
64561961e0fSrobinson if (streq(dec->type, "opaque"))
6467c478bd9Sstevel@tonic-gate error("opaque -- illegal argument type");
6477c478bd9Sstevel@tonic-gate if (peekscan(TOK_STAR, &tok)) {
6487c478bd9Sstevel@tonic-gate if (streq(dec->type, "string")) {
6497c478bd9Sstevel@tonic-gate error("pointer to string not allowed "
6507c478bd9Sstevel@tonic-gate "in program arguments\n");
6517c478bd9Sstevel@tonic-gate }
6527c478bd9Sstevel@tonic-gate dec->rel = REL_POINTER;
6537c478bd9Sstevel@tonic-gate if (peekscan(TOK_IDENT, &tok))
6547c478bd9Sstevel@tonic-gate /* optional name of argument */
6557c478bd9Sstevel@tonic-gate dec->name = strdup(tok.str);
6567c478bd9Sstevel@tonic-gate }
6577c478bd9Sstevel@tonic-gate if (peekscan(TOK_LANGLE, &tok)) {
6587c478bd9Sstevel@tonic-gate if (!streq(dec->type, "string")) {
6597c478bd9Sstevel@tonic-gate error("arrays cannot be declared as arguments "
6607c478bd9Sstevel@tonic-gate "to procedures -- use typedef");
6617c478bd9Sstevel@tonic-gate }
6627c478bd9Sstevel@tonic-gate dec->rel = REL_ARRAY;
6637c478bd9Sstevel@tonic-gate if (peekscan(TOK_RANGLE, &tok)) {
6647c478bd9Sstevel@tonic-gate dec->array_max = "~0";
6657c478bd9Sstevel@tonic-gate /* unspecified size, use max */
6667c478bd9Sstevel@tonic-gate } else {
6677c478bd9Sstevel@tonic-gate scan_num(&tok);
6687c478bd9Sstevel@tonic-gate dec->array_max = tok.str;
6697c478bd9Sstevel@tonic-gate scan(TOK_RANGLE, &tok);
6707c478bd9Sstevel@tonic-gate }
6717c478bd9Sstevel@tonic-gate }
6727c478bd9Sstevel@tonic-gate if (streq(dec->type, "string")) {
6737c478bd9Sstevel@tonic-gate if (dec->rel != REL_ARRAY) {
6747c478bd9Sstevel@tonic-gate /*
6757c478bd9Sstevel@tonic-gate * .x specifies just string as
6767c478bd9Sstevel@tonic-gate * type of argument
6777c478bd9Sstevel@tonic-gate * - make it string<>
6787c478bd9Sstevel@tonic-gate */
6797c478bd9Sstevel@tonic-gate dec->rel = REL_ARRAY;
6807c478bd9Sstevel@tonic-gate dec->array_max = "~0"; /* unspecified size, use max */
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate }
6837c478bd9Sstevel@tonic-gate }
6847c478bd9Sstevel@tonic-gate
68561961e0fSrobinson static void
get_type(char ** prefixp,char ** typep,defkind dkind)68661961e0fSrobinson get_type(char **prefixp, char **typep, defkind dkind)
6877c478bd9Sstevel@tonic-gate {
6887c478bd9Sstevel@tonic-gate token tok;
6897c478bd9Sstevel@tonic-gate
6907c478bd9Sstevel@tonic-gate *prefixp = NULL;
6917c478bd9Sstevel@tonic-gate get_token(&tok);
6927c478bd9Sstevel@tonic-gate switch (tok.kind) {
6937c478bd9Sstevel@tonic-gate case TOK_IDENT:
6947c478bd9Sstevel@tonic-gate *typep = tok.str;
6957c478bd9Sstevel@tonic-gate break;
6967c478bd9Sstevel@tonic-gate case TOK_STRUCT:
6977c478bd9Sstevel@tonic-gate case TOK_ENUM:
6987c478bd9Sstevel@tonic-gate case TOK_UNION:
6997c478bd9Sstevel@tonic-gate *prefixp = tok.str;
7007c478bd9Sstevel@tonic-gate scan(TOK_IDENT, &tok);
7017c478bd9Sstevel@tonic-gate *typep = tok.str;
7027c478bd9Sstevel@tonic-gate break;
7037c478bd9Sstevel@tonic-gate case TOK_UNSIGNED:
7047c478bd9Sstevel@tonic-gate unsigned_dec(typep);
7057c478bd9Sstevel@tonic-gate break;
7067c478bd9Sstevel@tonic-gate case TOK_SHORT:
7077c478bd9Sstevel@tonic-gate *typep = "short";
7087c478bd9Sstevel@tonic-gate (void) peekscan(TOK_INT, &tok);
7097c478bd9Sstevel@tonic-gate break;
7107c478bd9Sstevel@tonic-gate case TOK_LONG:
7117c478bd9Sstevel@tonic-gate *typep = "long";
7127c478bd9Sstevel@tonic-gate (void) peekscan(TOK_INT, &tok);
7137c478bd9Sstevel@tonic-gate break;
7147c478bd9Sstevel@tonic-gate case TOK_HYPER:
7157c478bd9Sstevel@tonic-gate *typep = "longlong_t";
7167c478bd9Sstevel@tonic-gate (void) peekscan(TOK_INT, &tok);
7177c478bd9Sstevel@tonic-gate break;
7187c478bd9Sstevel@tonic-gate
7197c478bd9Sstevel@tonic-gate case TOK_VOID:
7207c478bd9Sstevel@tonic-gate if (dkind != DEF_UNION && dkind != DEF_PROGRAM &&
7217c478bd9Sstevel@tonic-gate dkind != DEF_RESULT) {
7227c478bd9Sstevel@tonic-gate error("voids allowed only inside union and "
7237c478bd9Sstevel@tonic-gate "program definitions with one argument");
7247c478bd9Sstevel@tonic-gate }
7257c478bd9Sstevel@tonic-gate *typep = tok.str;
7267c478bd9Sstevel@tonic-gate break;
7277c478bd9Sstevel@tonic-gate case TOK_ONEWAY:
7287c478bd9Sstevel@tonic-gate if (dkind != DEF_RESULT) {
7297c478bd9Sstevel@tonic-gate error("oneways allowed only inside result definitions");
7307c478bd9Sstevel@tonic-gate }
7317c478bd9Sstevel@tonic-gate *typep = tok.str;
7327c478bd9Sstevel@tonic-gate break;
7337c478bd9Sstevel@tonic-gate case TOK_STRING:
7347c478bd9Sstevel@tonic-gate case TOK_OPAQUE:
7357c478bd9Sstevel@tonic-gate case TOK_CHAR:
7367c478bd9Sstevel@tonic-gate case TOK_INT:
7377c478bd9Sstevel@tonic-gate case TOK_FLOAT:
7387c478bd9Sstevel@tonic-gate case TOK_DOUBLE:
7397c478bd9Sstevel@tonic-gate case TOK_BOOL:
7407c478bd9Sstevel@tonic-gate case TOK_QUAD:
7417c478bd9Sstevel@tonic-gate *typep = tok.str;
7427c478bd9Sstevel@tonic-gate break;
7437c478bd9Sstevel@tonic-gate default:
7447c478bd9Sstevel@tonic-gate error("expected type specifier");
7457c478bd9Sstevel@tonic-gate }
7467c478bd9Sstevel@tonic-gate }
7477c478bd9Sstevel@tonic-gate
74861961e0fSrobinson static void
unsigned_dec(char ** typep)74961961e0fSrobinson unsigned_dec(char **typep)
7507c478bd9Sstevel@tonic-gate {
7517c478bd9Sstevel@tonic-gate token tok;
7527c478bd9Sstevel@tonic-gate
7537c478bd9Sstevel@tonic-gate peek(&tok);
7547c478bd9Sstevel@tonic-gate switch (tok.kind) {
7557c478bd9Sstevel@tonic-gate case TOK_CHAR:
7567c478bd9Sstevel@tonic-gate get_token(&tok);
7577c478bd9Sstevel@tonic-gate *typep = "u_char";
7587c478bd9Sstevel@tonic-gate break;
7597c478bd9Sstevel@tonic-gate case TOK_SHORT:
7607c478bd9Sstevel@tonic-gate get_token(&tok);
7617c478bd9Sstevel@tonic-gate *typep = "u_short";
7627c478bd9Sstevel@tonic-gate (void) peekscan(TOK_INT, &tok);
7637c478bd9Sstevel@tonic-gate break;
7647c478bd9Sstevel@tonic-gate case TOK_LONG:
7657c478bd9Sstevel@tonic-gate get_token(&tok);
7667c478bd9Sstevel@tonic-gate *typep = "u_long";
7677c478bd9Sstevel@tonic-gate (void) peekscan(TOK_INT, &tok);
7687c478bd9Sstevel@tonic-gate break;
7697c478bd9Sstevel@tonic-gate case TOK_HYPER:
7707c478bd9Sstevel@tonic-gate get_token(&tok);
7717c478bd9Sstevel@tonic-gate *typep = "u_longlong_t";
7727c478bd9Sstevel@tonic-gate (void) peekscan(TOK_INT, &tok);
7737c478bd9Sstevel@tonic-gate break;
7747c478bd9Sstevel@tonic-gate case TOK_INT:
7757c478bd9Sstevel@tonic-gate get_token(&tok);
7767c478bd9Sstevel@tonic-gate *typep = "u_int";
7777c478bd9Sstevel@tonic-gate break;
7787c478bd9Sstevel@tonic-gate default:
7797c478bd9Sstevel@tonic-gate *typep = "u_int";
7807c478bd9Sstevel@tonic-gate break;
7817c478bd9Sstevel@tonic-gate }
7827c478bd9Sstevel@tonic-gate }
783