1 /* @(#)rpc_parse.c 1.1 87/11/04 3.9 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
32 * rpc_parse.c, Parser for the RPC protocol compiler
33 * Copyright (C) 1987 Sun Microsystems, Inc.
35 #include <afsconfig.h>
36 #include <afs/param.h>
43 #include "rpc_parse.h"
46 list *proc_defined[MAX_PACKAGES], *special_defined, *typedef_defined,
47 *uniondef_defined, *complex_defined;
48 char *SplitStart = NULL;
49 char *SplitEnd = NULL;
50 char *MasterPrefix = NULL;
51 char *ServerPrefix = "";
52 char *PackagePrefix[MAX_PACKAGES];
53 char *PackageStatIndex[MAX_PACKAGES];
54 int no_of_stat_funcs = 0; /*
55 * current function number in client interface
58 int no_of_stat_funcs_header[MAX_PACKAGES]; /*
59 * Total number of functions in client
62 int no_of_opcodes[MAX_PACKAGES], master_no_of_opcodes = 0;
63 int lowest_opcode[MAX_PACKAGES], master_lowest_opcode = 99999;
64 int highest_opcode[MAX_PACKAGES], master_highest_opcode = 0;
65 int master_opcodenumber = 99999;
66 int opcodesnotallowed[MAX_PACKAGES];
67 int combinepackages = 0;
68 int PackageIndex = -1;
69 int PerProcCounter = 0;
74 * Character arrays to keep list of function names as we process the file
77 char function_list[MAX_PACKAGES]
78 [MAX_FUNCTIONS_PER_PACKAGE]
79 [MAX_FUNCTION_NAME_LEN];
80 int function_list_index;
82 /* static prototypes */
83 static void isdefined(definition * defp);
84 static void def_struct(definition * defp);
85 static void def_enum(definition * defp);
86 static void def_const(definition * defp);
87 static void def_union(definition * defp);
88 static void def_typedef(definition * defp);
89 static void get_declaration(declaration * dec, defkind dkind);
90 static void get_type(char **prefixp, char **typep, defkind dkind);
91 static void unsigned_dec(char **typep);
92 static void def_package(definition * defp);
93 static void def_prefix(definition * defp);
94 static void def_statindex(definition * defp);
95 static void def_startingopcode(definition * defp);
96 static void def_split(definition * defp);
97 static void customize_struct(definition * defp);
98 static char *structname(char *name);
99 static void def_special(declaration * dec, definition * defp);
100 static void check_proc(definition * defp, token * tokp, int noname);
101 static int InvalidConstant(char *name);
102 static int opcodenum_is_defined(int opcode_num);
103 static void analyze_ProcParams(definition * defp, token * tokp);
104 static void generate_code(definition * defp, int proc_split_flag,
106 static void handle_split_proc(definition * defp, int multi_flag);
107 static void do_split(definition * defp, int direction, int *numofparams,
108 defkind param_kind, int restore_flag);
109 static void hdle_param_tok(definition * defp, declaration * dec, token * tokp,
111 static void get1_param_type(definition * defp, declaration * dec,
113 static void get_param_type(definition * defp, declaration * dec,
114 char **param_type, char **typename);
115 static void cs_Proc_CodeGeneration(definition * defp, int split_flag,
117 static void cs_ProcName_setup(definition * defp, char *procheader,
119 static void cs_ProcParams_setup(definition * defp, int split_flag);
120 static void cs_ProcMarshallInParams_setup(definition * defp, int split_flag);
121 static void cs_ProcSendPacket_setup(definition * defp, int split_flag);
122 static void cs_ProcUnmarshallOutParams_setup(definition * defp);
123 static void cs_ProcTail_setup(definition * defp, int split_flag);
124 static void ucs_ProcCallback_setup(definition * defp, char *cbheader);
125 static void ucs_ProcName_setup(definition * defp, char *procheader,
127 static void ucs_ProcParams_setup(definition * defp, int split_flag);
128 static void ucs_ProcTail_setup(definition * defp, char *cbheader,
130 static void ss_Proc_CodeGeneration(definition * defp);
131 static void ss_ProcName_setup(definition * defp);
132 static void ss_ProcParams_setup(definition * defp);
133 static void ss_ProcSpecial_setup(definition * defp);
134 static void ss_ProcUnmarshallInParams_setup(definition * defp);
135 static void ss_ProcCallRealProc_setup(definition * defp);
136 static void ss_ProcMarshallOutParams_setup(definition * defp);
137 static void ss_ProcTail_setup(definition * defp);
138 static int opcode_holes_exist(void);
139 static void er_ProcDeclExterns_setup(void);
140 static void er_ProcProcsArray_setup(void);
141 static void er_ProcMainBody_setup(void);
142 static void er_HeadofOldStyleProc_setup(void);
143 static void er_HeadofOldStyleProc_setup2(void);
144 static void er_BodyofOldStyleProc_setup(void);
145 static void er_BodyofOldStyleProc_setup2(void);
146 static void proc_er_case(definition * defp);
147 static void er_TailofOldStyleProc_setup(void);
148 static void er_TailofOldStyleProc_setup2(void);
153 * return the next definition you see
161 defp = ALLOC(definition);
162 memset(defp, 0, sizeof(definition));
195 def_special(&dec, defp);
198 case TOK_STARTINGOPCODE:
199 def_startingopcode(defp);
204 customize_struct(defp);
206 case TOK_SPLITPREFIX:
211 if (tok.kind == TOK_LPAREN) {
213 check_proc(defp, &tok, 1);
215 check_proc(defp, &tok, 0);
218 check_proc(defp, &tok, 0);
222 check_proc(defp, &tok, 1);
225 error("definition keyword expected");
227 if (!IsRxgenToken(&tok)) {
228 scan(TOK_SEMICOLON, &tok);
236 isdefined(definition * defp)
238 STOREVAL(&defined, defp);
243 def_struct(definition * defp)
251 defp->def_kind = DEF_STRUCT;
253 scan(TOK_IDENT, &tok);
254 defp->def_name = tok.str;
255 scan(TOK_LBRACE, &tok);
256 tailp = &defp->def.st.decls;
258 get_declaration(&dec, DEF_STRUCT);
259 /* If a structure contains an array, then we're going
260 * to need to be clever about freeing it */
261 if (dec.rel == REL_ARRAY) {
264 decls = ALLOC(decl_list);
267 tailp = &decls->next;
268 scan(TOK_SEMICOLON, &tok);
270 } while (tok.kind != TOK_RBRACE);
275 STOREVAL(&complex_defined, defp);
279 def_enum(definition * defp)
283 enumval_list **tailp;
285 defp->def_kind = DEF_ENUM;
286 scan(TOK_IDENT, &tok);
287 defp->def_name = tok.str;
288 scan(TOK_LBRACE, &tok);
289 tailp = &defp->def.en.vals;
291 scan(TOK_IDENT, &tok);
292 elist = ALLOC(enumval_list);
293 elist->name = tok.str;
294 elist->assignment = NULL;
295 scan3(TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
296 if (tok.kind == TOK_EQUAL) {
298 elist->assignment = tok.str;
299 scan2(TOK_COMMA, TOK_RBRACE, &tok);
302 tailp = &elist->next;
303 } while (tok.kind != TOK_RBRACE);
308 def_const(definition * defp)
312 defp->def_kind = DEF_CONST;
313 scan(TOK_IDENT, &tok);
314 defp->def_name = tok.str;
315 scan(TOK_EQUAL, &tok);
316 scan2(TOK_IDENT, TOK_STRCONST, &tok);
317 defp->def.co = tok.str;
321 def_union(definition * defp)
328 defp->def_kind = DEF_UNION;
329 scan(TOK_IDENT, &tok);
330 defp->def_name = tok.str;
331 scan(TOK_SWITCH, &tok);
332 scan(TOK_LPAREN, &tok);
333 get_declaration(&dec, DEF_UNION);
334 defp->def.un.enum_decl = dec;
335 tailp = &defp->def.un.cases;
336 scan(TOK_RPAREN, &tok);
337 scan(TOK_LBRACE, &tok);
338 scan(TOK_CASE, &tok);
339 while (tok.kind == TOK_CASE) {
340 scan(TOK_IDENT, &tok);
341 cases = ALLOC(case_list);
342 cases->case_name = tok.str;
343 scan(TOK_COLON, &tok);
344 get_declaration(&dec, DEF_UNION);
345 cases->case_decl = dec;
347 tailp = &cases->next;
348 scan(TOK_SEMICOLON, &tok);
349 scan3(TOK_CASE, TOK_DEFAULT, TOK_RBRACE, &tok);
352 if (tok.kind == TOK_DEFAULT) {
353 scan(TOK_COLON, &tok);
354 get_declaration(&dec, DEF_UNION);
355 defp->def.un.default_decl = ALLOC(declaration);
356 *defp->def.un.default_decl = dec;
357 scan(TOK_SEMICOLON, &tok);
358 scan(TOK_RBRACE, &tok);
360 defp->def.un.default_decl = NULL;
366 def_typedef(definition * defp)
370 memset(&dec, 0, sizeof(dec));
372 defp->def_kind = DEF_TYPEDEF;
373 get_declaration(&dec, DEF_TYPEDEF);
374 defp->def_name = dec.name;
375 defp->def.ty.old_prefix = dec.prefix;
376 defp->def.ty.old_type = dec.type;
377 defp->def.ty.rel = dec.rel;
378 defp->def.ty.array_max = dec.array_max;
383 get_declaration(declaration * dec, defkind dkind)
387 get_type(&dec->prefix, &dec->type, dkind);
388 dec->rel = REL_ALIAS;
389 if (streq(dec->type, "void")) {
392 scan2(TOK_STAR, TOK_IDENT, &tok);
393 if (tok.kind == TOK_STAR) {
394 dec->rel = REL_POINTER;
395 scan(TOK_IDENT, &tok);
398 if (peekscan(TOK_LBRACKET, &tok)) {
399 if (dec->rel == REL_POINTER) {
400 error("no array-of-pointer declarations -- use typedef");
402 dec->rel = REL_VECTOR;
404 dec->array_max = tok.str;
405 scan(TOK_RBRACKET, &tok);
406 } else if (peekscan(TOK_LANGLE, &tok)) {
407 if (dec->rel == REL_POINTER) {
408 error("no array-of-pointer declarations -- use typedef");
410 dec->rel = REL_ARRAY;
411 if (peekscan(TOK_RANGLE, &tok)) {
412 if ((dkind == DEF_INPARAM) || (dkind == DEF_INOUTPARAM)) {
413 error("input arrays must specify a max size");
415 dec->array_max = "~0u"; /* unspecified size, use max */
418 dec->array_max = tok.str;
419 scan(TOK_RANGLE, &tok);
422 if (streq(dec->type, "opaque")) {
423 if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) {
424 error("array declaration expected");
426 } else if (streq(dec->type, "string")) {
427 if (dec->rel != REL_ARRAY) {
428 error(" variable-length array declaration expected");
435 get_type(char **prefixp, char **typep, defkind dkind)
449 scan(TOK_IDENT, &tok);
457 (void)peekscan(TOK_INT, &tok);
460 *typep = "afs_int32";
461 (void)peekscan(TOK_INT, &tok);
464 if (dkind != DEF_UNION) {
465 error("voids allowed only inside union definitions");
480 error("expected type specifier");
486 unsigned_dec(char **typep)
499 (void)peekscan(TOK_INT, &tok);
503 *typep = "afs_uint32";
504 (void)peekscan(TOK_INT, &tok);
518 def_package(definition * defp)
522 defp->def_kind = DEF_PACKAGE;
523 scan(TOK_IDENT, &tok);
524 defp->def_name = tok.str;
525 no_of_stat_funcs = 0;
528 if (PackageIndex >= MAX_PACKAGES)
529 error("Exceeded upper limit of package statements\n");
531 function_list_index = 0;
532 PackagePrefix[PackageIndex] = tok.str;
533 if (MasterPrefix == NULL)
534 MasterPrefix = tok.str;
535 no_of_opcodes[PackageIndex] = highest_opcode[PackageIndex] =
536 opcodesnotallowed[PackageIndex] = 0;
537 lowest_opcode[PackageIndex] = 99999;
538 proc_defined[PackageIndex] = NULL;
539 PackageStatIndex[PackageIndex] = NULL;
543 def_prefix(definition * defp)
547 defp->def_kind = DEF_PREFIX;
548 scan(TOK_IDENT, &tok);
549 defp->def_name = tok.str;
550 ServerPrefix = tok.str;
554 def_statindex(definition * defp)
559 defp->def_kind = DEF_CONST;
561 if (PackageIndex < 0)
562 error("'statindex' command must follow 'package' command!\n");
563 if (PackageStatIndex[PackageIndex])
564 error("Cannot have more then one 'statindex' per package!\n");
565 if (InvalidConstant(tok.str))
566 error("Index in 'statindex' command must be a constant!");
568 alloc(strlen(PackagePrefix[PackageIndex]) + strlen("STATINDEX") + 1);
569 strcpy(name, PackagePrefix[PackageIndex]);
570 strcat(name, "STATINDEX");
571 defp->def_name = name;
572 defp->def.co = tok.str;
573 PackageStatIndex[PackageIndex] = name;
574 StatIndex = atoi(tok.str);
578 def_startingopcode(definition * defp)
582 defp->def_kind = DEF_STARTINGOPCODE;
583 scan(TOK_IDENT, &tok);
584 defp->def_name = tok.str;
585 if (InvalidConstant(defp->def_name))
586 error("Opcode in 'startingopcode' command must be a constant!");
587 lowest_opcode[PackageIndex] = master_lowest_opcode = atoi(tok.str);
588 if (lowest_opcode[PackageIndex] < 0
589 || lowest_opcode[PackageIndex] > 99999)
591 ("startingopcode number is out of bounds (must be >= 0 < 100000)");
592 master_opcodenumber = lowest_opcode[PackageIndex];
593 opcodesnotallowed[PackageIndex] = 1;
597 def_split(definition * defp)
601 defp->def_kind = DEF_SPLITPREFIX;
606 scan(TOK_EQUAL, &tok);
607 scan(TOK_IDENT, &tok);
608 SplitStart = tok.str;
611 scan(TOK_EQUAL, &tok);
612 scan(TOK_IDENT, &tok);
618 error("syntax error in the 'splitprefix' line");
620 } while (tok.kind != TOK_SEMICOLON);
621 if (!SplitStart && !SplitEnd)
622 error("At least one param should be passed to 'splitprefix' cmd");
627 customize_struct(definition * defp)
631 definition *defp1 = ALLOC(definition);
632 spec_list *specs, **tailp;
634 defp->def_kind = DEF_CUSTOMIZED;
635 defp1->def_kind = DEF_SPECIAL;
636 tailp = &defp1->def.sd.specs;
637 for (listp = defp->def.st.decls; listp; listp = listp->next) {
639 if (streq(dec->type, "string") || (dec->rel == REL_POINTER)) {
640 specs = ALLOC(spec_list);
641 specs->sdef.string_name = dec->name;
642 specs->sdef.string_value = defp->def_name;
644 tailp = &specs->next;
648 STOREVAL(&special_defined, defp1);
652 structname(char *name)
654 static char namecontents[150];
657 strcpy(namecontents, name);
659 if (!strncmp(pnt, "struct", 6))
661 while (isspace(*pnt))
664 while (*pnt != ' ' && *pnt != '\0')
672 def_special(declaration * dec, definition * defp)
675 spec_list *specs, **tailp;
678 defp->def_kind = DEF_SPECIAL;
679 get_type(&dec->prefix, &dec->type, DEF_SPECIAL);
680 dec->rel = REL_POINTER;
681 scan(TOK_IDENT, &tok);
682 tailp = &defp->def.sd.specs;
684 specs = ALLOC(spec_list);
685 specs->sdef.string_name = tok.str;
686 get_param_type(defp, dec, &specs->sdef.string_value, &typename);
688 tailp = &specs->next;
689 scan2(TOK_COMMA, TOK_SEMICOLON, &tok);
690 if (tok.kind == TOK_SEMICOLON)
693 } while (tok.kind == TOK_IDENT);
695 STOREVAL(&special_defined, defp);
699 proc1_list *Proc_list, **Proc_listp;
702 check_proc(definition * defp, token * tokp, int noname)
708 if (PackageIndex < 0)
709 error("Procedure must be in a package!\n");
711 tokp->kind = TOK_PROC;
712 defp->def_kind = DEF_PROC;
714 defp->pc.proc_name = "";
716 defp->pc.proc_name = tokp->str;
718 defp->pc.proc_prefix = alloc(strlen(PackagePrefix[PackageIndex]) + 1);
719 strcpy(defp->pc.proc_prefix, PackagePrefix[PackageIndex]);
720 scan2(TOK_LPAREN, TOK_IDENT, &tok);
721 defp->pc.proc_serverstub = NULL;
722 if (tok.kind == TOK_IDENT) {
723 defp->pc.proc_serverstub = tok.str;
724 scan(TOK_LPAREN, &tok);
726 analyze_ProcParams(defp, &tok);
727 defp->pc.proc_opcodenum = -1;
728 scan4(TOK_SPLIT, TOK_MULTI, TOK_EQUAL, TOK_SEMICOLON, &tok);
729 if (tok.kind == TOK_MULTI) {
731 defp->pc.multi_flag = 1;
732 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
734 defp->pc.multi_flag = 0;
736 if (tok.kind == TOK_SPLIT) {
738 defp->pc.split_flag = 1;
739 scan2(TOK_EQUAL, TOK_SEMICOLON, &tok);
741 defp->pc.split_flag = 0;
743 if (tok.kind == TOK_EQUAL) {
744 if (opcodesnotallowed[PackageIndex])
745 error("Opcode assignment isn't allowed here!");
747 if (InvalidConstant(tok.str))
748 error("Illegal Opcode assignment (Must be a constant opcode!)");
749 if (opcodenum_is_defined(atoi(tok.str)))
750 error("The opcode number is already used by a previous proc");
751 defp->pc.proc_opcodename = tok.str;
752 defp->pc.proc_opcodenum = atoi(tok.str);
753 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
754 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
755 if (defp->pc.proc_opcodenum < master_lowest_opcode)
756 master_lowest_opcode = defp->pc.proc_opcodenum;
757 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
758 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
759 if (defp->pc.proc_opcodenum > master_highest_opcode)
760 master_highest_opcode = defp->pc.proc_opcodenum;
761 scan(TOK_SEMICOLON, &tok);
763 if (master_opcodenumber == 99999)
764 master_opcodenumber = 0;
765 defp->pc.proc_opcodenum = master_opcodenumber++;
766 if (defp->pc.proc_opcodenum < lowest_opcode[PackageIndex])
767 lowest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
768 if (defp->pc.proc_opcodenum > highest_opcode[PackageIndex])
769 highest_opcode[PackageIndex] = defp->pc.proc_opcodenum;
770 if (defp->pc.proc_opcodenum > master_highest_opcode)
771 master_highest_opcode = defp->pc.proc_opcodenum;
772 opcodesnotallowed[PackageIndex] = 1; /* force it */
774 no_of_opcodes[PackageIndex]++, master_no_of_opcodes++;
776 generate_code(defp, 0, 1);
777 if (Cflag || cflag) {
778 generate_code(defp, 1, 1);
780 generate_multi_macros(defp);
782 generate_code(defp, proc_split, 0);
785 if (function_list_index >= MAX_FUNCTIONS_PER_INTERFACE) {
786 error("too many functions in interface, "
787 "increase MAX_FUNCTIONS_PER_INTERFACE");
789 sprintf(function_list[PackageIndex][function_list_index], "%s%s%s",
790 prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
792 function_list_index++;
793 defp->statindex = no_of_stat_funcs;
794 no_of_stat_funcs_header[PackageIndex]++;
800 #define LEGALNUMS "0123456789"
802 InvalidConstant(char *name)
808 slen = (int)strlen(name);
809 return (slen != strspn(name, map));
813 opcodenum_is_defined(int opcode_num)
818 for (listp = proc_defined[PackageIndex]; listp != NULL;
819 listp = listp->next) {
820 defp = (definition *) listp->val;
821 if (opcode_num == defp->pc.proc_opcodenum)
829 analyze_ProcParams(definition * defp, token * tokp)
832 decl_list *decls, **tailp;
834 Proc_listp = &defp->pc.plists;
835 tailp = &defp->def.st.decls;
838 Proc_list = ALLOC(proc1_list);
839 memset(Proc_list, 0, sizeof(proc1_list));
840 Proc_list->pl.param_flag = 0;
841 switch (tokp->kind) {
843 hdle_param_tok(defp, &dec, tokp, DEF_INPARAM);
846 hdle_param_tok(defp, &dec, tokp, DEF_OUTPARAM);
849 hdle_param_tok(defp, &dec, tokp, DEF_INOUTPARAM);
855 hdle_param_tok(defp, &dec, tokp, DEF_NULL);
858 *Proc_listp = Proc_list;
859 Proc_listp = &Proc_list->next;
860 decls = ALLOC(decl_list);
861 memset(decls, 0, sizeof(decl_list));
862 if (tokp->kind != TOK_RPAREN)
865 tailp = &decls->next;
866 } while (tokp->kind != TOK_RPAREN);
872 generate_code(definition * defp, int proc_split_flag, int multi_flag)
875 handle_split_proc(defp, multi_flag);
877 if (Cflag || cflag) {
878 cs_Proc_CodeGeneration(defp, 0, "");
881 ss_Proc_CodeGeneration(defp);
883 if (Sflag || (cflag && xflag && !proc_split_flag) || hflag)
884 STOREVAL(&proc_defined[PackageIndex], defp);
889 handle_split_proc(definition * defp, int multi_flag)
891 char *startname = SplitStart, *endname = SplitEnd;
898 if (Cflag || cflag) {
900 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
902 cs_Proc_CodeGeneration(defp, 1, startname);
904 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
905 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
907 cs_Proc_CodeGeneration(defp, (multi_flag ? 3 : 2), endname);
909 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
913 ss_Proc_CodeGeneration(defp);
918 do_split(definition * defp, int direction, int *numofparams,
919 defkind param_kind, int restore_flag)
924 defp->pc.paramtypes[direction] = *numofparams;
925 for (plist = defp->pc.plists; plist; plist = plist->next) {
926 if (plist->component_kind == DEF_NULL
927 && plist->pl.param_kind == param_kind)
928 plist->component_kind = DEF_PARAM;
931 *numofparams = defp->pc.paramtypes[direction];
932 defp->pc.paramtypes[direction] = 0;
933 for (plist = defp->pc.plists; plist; plist = plist->next) {
934 if (plist->component_kind == DEF_PARAM
935 && plist->pl.param_kind == param_kind)
936 plist->component_kind = DEF_NULL;
943 hdle_param_tok(definition * defp, declaration * dec, token * tokp,
946 static defkind last_param_kind = DEF_NULL;
948 if (par_kind == DEF_NULL)
949 Proc_list->pl.param_kind = last_param_kind;
951 Proc_list->pl.param_kind = par_kind;
952 last_param_kind = Proc_list->pl.param_kind;
953 defp->pc.paramtypes[(int)last_param_kind]++;
954 Proc_list->component_kind = DEF_PARAM;
955 Proc_list->code = alloc(250);
956 Proc_list->scode = alloc(250);
957 get_declaration(dec, par_kind);
958 Proc_list->pl.param_name = dec->name;
959 get1_param_type(defp, dec, &Proc_list->pl.param_type);
961 scan2(TOK_COMMA, TOK_RPAREN, tokp);
962 if (tokp->kind == TOK_COMMA)
968 get1_param_type(definition * defp, declaration * dec, char **param_type)
970 char typecontents[100];
972 if (streq(dec->type, "string")) {
973 *param_type = "char *";
976 strcpy(typecontents, dec->prefix);
977 strcat(typecontents, " ");
978 strcat(typecontents, dec->type);
979 strcat(typecontents, " *");
980 } else if (dec->rel == REL_POINTER) {
981 strcpy(typecontents, dec->type);
982 strcat(typecontents, " *");
984 strcpy(typecontents, dec->type);
985 *param_type = alloc(100);
986 strcpy(*param_type, typecontents);
992 get_param_type(definition * defp, declaration * dec, char **param_type,
995 char typecontents[100];
997 if (streq(dec->type, "string")) {
998 *typename = "wrapstring";
999 *param_type = "char *";
1001 *typename = dec->type;
1003 strcpy(typecontents, dec->prefix);
1004 strcat(typecontents, " ");
1005 strcat(typecontents, dec->type);
1006 strcat(typecontents, " *");
1007 dec->rel = REL_POINTER;
1008 } else if (dec->rel == REL_POINTER) {
1009 strcpy(typecontents, dec->type);
1010 strcat(typecontents, " *");
1012 strcpy(typecontents, dec->type);
1013 *param_type = alloc(100);
1014 strcpy(*param_type, typecontents);
1020 cs_Proc_CodeGeneration(definition * defp, int split_flag, char *procheader)
1023 cs_ProcName_setup(defp, procheader, split_flag);
1025 cs_ProcParams_setup(defp, split_flag);
1026 cs_ProcMarshallInParams_setup(defp, split_flag);
1027 if (split_flag != 1) {
1028 cs_ProcSendPacket_setup(defp, split_flag);
1029 cs_ProcUnmarshallOutParams_setup(defp);
1031 cs_ProcTail_setup(defp, split_flag);
1034 if (!kflag && !split_flag && uflag) {
1036 ucs_ProcCallback_setup(defp, "ubik_call_");
1038 ucs_ProcName_setup(defp, "ubik_", split_flag);
1040 ucs_ProcParams_setup(defp, split_flag);
1041 ucs_ProcTail_setup(defp, "ubik_call_", split_flag);
1047 cs_ProcName_setup(definition * defp, char *procheader, int split_flag)
1054 first_arg = "struct rx_call *z_call";
1056 first_arg = "struct rx_connection *z_conn";
1060 first_arg = "z_call";
1062 first_arg = "z_conn";
1067 f_print(fout, "int %s%s%s%s(%s", procheader, prefix,
1068 PackagePrefix[PackageIndex], defp->pc.proc_name, first_arg);
1070 if ((strlen(procheader) + strlen(prefix) +
1071 strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >=
1072 MAX_FUNCTION_NAME_LEN) {
1073 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1076 for (plist = defp->pc.plists; plist; plist = plist->next) {
1077 if (plist->component_kind == DEF_PARAM) {
1080 if (plist->pl.param_kind == DEF_INPARAM &&
1081 strcmp(plist->pl.param_type, "char *") == 0) {
1082 f_print(fout, "const ");
1084 if (plist->pl.param_flag & OUT_STRING) {
1085 f_print(fout, "%s *%s", plist->pl.param_type,
1086 plist->pl.param_name);
1088 f_print(fout, "%s %s", plist->pl.param_type,
1089 plist->pl.param_name);
1092 f_print(fout, " %s", plist->pl.param_name);
1093 plist->pl.param_flag &= ~PROCESSED_PARAM;
1097 f_print(fout, ")\n");
1102 cs_ProcParams_setup(definition * defp, int split_flag)
1104 proc1_list *plist, *plist1;
1110 f_print(fout, "\tstruct rx_connection *z_conn;\n");
1112 f_print(fout, "\tstruct rx_call *z_call;\n");
1114 for (plist = defp->pc.plists; plist; plist = plist->next) {
1115 if (plist->component_kind == DEF_PARAM
1116 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1117 if (plist->pl.param_flag & OUT_STRING) {
1118 f_print(fout, "\t%s *%s", plist->pl.param_type,
1119 plist->pl.param_name);
1121 f_print(fout, "\t%s %s", plist->pl.param_type,
1122 plist->pl.param_name);
1124 plist->pl.param_flag |= PROCESSED_PARAM;
1125 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1126 if ((plist1->component_kind == DEF_PARAM)
1127 && streq(plist->pl.param_type, plist1->pl.param_type)
1128 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1130 char *pntr = strchr(plist1->pl.param_type, '*');
1133 if (plist1->pl.param_flag & OUT_STRING) {
1134 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1136 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1138 plist1->pl.param_flag |= PROCESSED_PARAM;
1141 f_print(fout, ";\n");
1148 cs_ProcMarshallInParams_setup(definition * defp, int split_flag)
1150 int noofparams, i = 0;
1154 defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT] +
1155 defp->pc.paramtypes[OUT];
1157 f_print(fout, "{\n");
1159 f_print(fout, "\tstruct rx_call *z_call = rx_NewCall(z_conn);\n");
1160 if ((!split_flag) || (split_flag == 1)) {
1161 if (opcodesnotallowed[PackageIndex]) {
1162 f_print(fout, "\tstatic int z_op = %d;\n",
1163 defp->pc.proc_opcodenum);
1165 f_print(fout, "\tstatic int z_op = %s;\n",
1166 defp->pc.proc_opcodename);
1169 f_print(fout, "\tint z_result;\n");
1170 if (!(split_flag > 1) || (noofallparams != 0)) {
1171 f_print(fout, "\tXDR z_xdrs;\n");
1174 if ((!split_flag) || (split_flag == 1)) {
1175 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_ENCODE);\n");
1176 f_print(fout, "\n\t/* Marshal the arguments */\n");
1177 f_print(fout, "\tif ((!xdr_int(&z_xdrs, &z_op))");
1178 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1179 for (plist = defp->pc.plists, dl = defp->def.st.decls; plist;
1180 plist = plist->next, dl = dl->next) {
1181 if (plist->component_kind == DEF_PARAM
1182 && (plist->pl.param_kind == DEF_INPARAM
1183 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1184 f_print(fout, "\n\t || (!%s)", plist->code);
1185 if (++i == noofparams) {
1187 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1194 ") {\n\t\tz_result = RXGEN_CC_MARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1202 cs_ProcSendPacket_setup(definition * defp, int split_flag)
1204 int noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1206 if (noofoutparams) {
1207 f_print(fout, "\t/* Un-marshal the reply arguments */\n");
1209 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1211 f_print(fout, "\tz_xdrs.x_op = XDR_DECODE;\n");
1218 cs_ProcUnmarshallOutParams_setup(definition * defp)
1224 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1226 for (plist = defp->pc.plists, dl = defp->def.st.decls, i = 0; plist;
1227 plist = plist->next, dl = dl->next) {
1228 if (plist->component_kind == DEF_PARAM
1229 && (plist->pl.param_kind == DEF_OUTPARAM
1230 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1232 f_print(fout, "\tif ((!%s)", plist->code);
1234 f_print(fout, "\n\t || (!%s)", plist->code);
1236 if (++i == noofparams) {
1238 ") {\n\t\tz_result = RXGEN_CC_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1247 cs_ProcTail_setup(definition * defp, int split_flag)
1249 f_print(fout, "\tz_result = RXGEN_SUCCESS;\n");
1250 if (defp->can_fail) {
1251 f_print(fout, "fail:\n");
1254 f_print(fout, "\tz_result = rx_EndCall(z_call, z_result);\n");
1256 if (xflag && split_flag != 1) {
1257 f_print(fout, "\tif (rx_enable_stats) {\n");
1258 if (PackageStatIndex[PackageIndex]) {
1260 "\t rx_RecordCallStatistics(z_call, %s,\n",
1261 PackageStatIndex[PackageIndex]);
1264 "\t rx_RecordCallStatistics(z_call, \n"
1265 "\t\t(((afs_uint32)(ntohs(rx_ServiceIdOf(rx_ConnectionOf(z_call))) << 16)) |\n"
1266 "\t\t((afs_uint32)ntohs(rx_PortOf(rx_PeerOf(rx_ConnectionOf(z_call)))))),\n");
1268 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, 1);\n",
1269 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1270 f_print(fout, "\t}\n\n");
1272 f_print(fout, "\treturn z_result;\n}\n\n");
1277 ss_Proc_CodeGeneration(definition * defp)
1285 ss_ProcName_setup(defp);
1287 ss_ProcParams_setup(defp);
1288 ss_ProcSpecial_setup(defp);
1289 ss_ProcUnmarshallInParams_setup(defp);
1290 ss_ProcCallRealProc_setup(defp);
1291 ss_ProcMarshallOutParams_setup(defp);
1292 ss_ProcTail_setup(defp);
1298 ss_ProcName_setup(definition * defp)
1302 if ((strlen(prefix) + strlen(PackagePrefix[PackageIndex]) +
1303 strlen(defp->pc.proc_name)) >= MAX_FUNCTION_NAME_LEN) {
1304 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1308 f_print(fout, "static afs_int32 _%s%s%s(", prefix,
1309 PackagePrefix[PackageIndex], defp->pc.proc_name);
1310 f_print(fout, "struct rx_call *z_call, XDR *z_xdrs)\n{\n");
1311 f_print(fout, "\t" "afs_int32 z_result;\n");
1313 for (plist = defp->pc.plists; plist; plist = plist->next)
1314 if (plist->component_kind == DEF_PARAM) {
1315 plist->pl.param_flag &= ~(PROCESSED_PARAM);
1316 plist->pl.string_name = NULL;
1323 ss_ProcParams_setup(definition * defp)
1325 proc1_list *plist, *plist1;
1329 for (plist = defp->pc.plists; plist; plist = plist->next) {
1330 if ((plist->component_kind == DEF_PARAM)
1331 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1332 if (plist->pl.param_flag & INDIRECT_PARAM) {
1333 char pres = '\0', *pntr = strchr(plist->pl.param_type, '*');
1339 f_print(fout, "\t%s %s", plist->pl.param_type,
1340 plist->pl.param_name);
1343 } else if (strchr(plist->pl.param_type, '*') == 0) {
1344 f_print(fout, "\t%s %s", plist->pl.param_type,
1345 plist->pl.param_name);
1347 plist->pl.param_flag |= FREETHIS_PARAM;
1348 f_print(fout, "\t%s %s=(%s)0", plist->pl.param_type,
1349 plist->pl.param_name, plist->pl.param_type);
1351 plist->pl.param_flag |= PROCESSED_PARAM;
1352 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1353 if ((plist1->component_kind == DEF_PARAM)
1354 && streq(plist->pl.param_type, plist1->pl.param_type)
1355 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1356 if (plist1->pl.param_flag & INDIRECT_PARAM) {
1357 f_print(fout, ", %s", plist1->pl.param_name);
1358 } else if (strchr(plist1->pl.param_type, '*') == 0) {
1359 f_print(fout, ", %s", plist1->pl.param_name);
1361 plist1->pl.param_flag |= FREETHIS_PARAM;
1362 f_print(fout, ", *%s=(%s)0", plist1->pl.param_name,
1363 plist1->pl.param_type);
1365 plist1->pl.param_flag |= PROCESSED_PARAM;
1368 f_print(fout, ";\n");
1371 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1372 defp1 = (definition *) listp->val;
1373 for (plist = defp->pc.plists; plist; plist = plist->next) {
1374 if (plist->component_kind == DEF_PARAM
1375 && (plist->pl.param_kind == DEF_OUTPARAM
1376 || plist->pl.param_kind == DEF_INOUTPARAM)
1377 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1378 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1379 switch (defp1->pc.rel) {
1389 fprintf(fout, "\n");
1394 ss_ProcSpecial_setup(definition * defp)
1400 for (listp = special_defined; listp != NULL; listp = listp->next) {
1401 defp1 = (definition *) listp->val;
1403 for (plist = defp->pc.plists; plist; plist = plist->next) {
1404 if (plist->component_kind == DEF_PARAM
1405 && (plist->pl.param_kind == DEF_INPARAM
1406 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1407 spec_list *spec = defp1->def.sd.specs;
1409 strcpy(string, structname(spec->sdef.string_value));
1410 if (streq(string, structname(plist->pl.param_type))) {
1411 plist->pl.string_name = spec->sdef.string_name;
1412 plist->pl.param_flag |= FREETHIS_PARAM;
1417 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1418 defp1 = (definition *) listp->val;
1419 for (plist = defp->pc.plists; plist; plist = plist->next) {
1420 if (plist->component_kind == DEF_PARAM) {
1421 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1422 plist->pl.param_flag |= FREETHIS_PARAM;
1423 switch (defp1->pc.rel) {
1425 plist->pl.string_name = alloc(40);
1427 s_print(plist->pl.string_name, "val");
1429 s_print(plist->pl.string_name, "%s_val",
1434 plist->pl.string_name = NULL;
1443 for (listp = complex_defined; listp != NULL; listp = listp->next) {
1444 defp1 = (definition *) listp->val;
1445 for (plist = defp->pc.plists; plist; plist = plist->next) {
1446 if (plist->component_kind == DEF_PARAM) {
1447 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1448 plist->pl.param_flag |= FREETHIS_PARAM;
1454 for (plist = defp->pc.plists; plist; plist = plist->next) {
1455 if (plist->component_kind == DEF_PARAM) {
1456 fprintf(fout, "\n\tmemset(&%s, 0, sizeof(%s));",
1457 plist->pl.param_name,
1458 plist->pl.param_name);
1462 f_print(fout, "\n");
1467 ss_ProcUnmarshallInParams_setup(definition * defp)
1469 int noofparams, noofoutparams, i;
1472 noofparams = defp->pc.paramtypes[IN] + defp->pc.paramtypes[INOUT];
1473 noofoutparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1474 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1475 if (plist->component_kind == DEF_PARAM
1476 && (plist->pl.param_kind == DEF_INPARAM
1477 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1479 f_print(fout, "\n\tif ((!%s)",
1480 (plist->scode ? plist->scode : plist->code));
1482 f_print(fout, "\n\t || (!%s)",
1483 (plist->scode ? plist->scode : plist->code));
1485 if (++i == noofparams) {
1486 if (!noofoutparams) {
1487 f_print(fout, ") {\n");
1489 f_print(fout, ") {\n");
1492 "\t\tz_result = RXGEN_SS_UNMARSHAL;\n\t\tgoto fail;\n\t}\n\n");
1501 ss_ProcCallRealProc_setup(definition * defp)
1506 f_print(fout, "\tz_result = %s%s%s%s(z_call", prefix, ServerPrefix,
1507 PackagePrefix[PackageIndex], defp->pc.proc_name);
1508 for (plist = defp->pc.plists; plist; plist = plist->next) {
1509 if (plist->component_kind == DEF_PARAM) {
1510 if (plist->pl.param_flag & INDIRECT_PARAM) {
1511 f_print(fout, ", &%s", plist->pl.param_name);
1513 if (plist->pl.param_flag & OUT_STRING) {
1514 f_print(fout, ", &%s", plist->pl.param_name);
1516 f_print(fout, ", %s", plist->pl.param_name);
1521 f_print(fout, ");\n");
1523 f_print(fout, "\tif (z_result)\n\t\treturn z_result;\n");
1525 f_print(fout, "\tif (z_result)\n\t\tgoto fail;\n");
1531 ss_ProcMarshallOutParams_setup(definition * defp)
1536 noofparams = defp->pc.paramtypes[INOUT] + defp->pc.paramtypes[OUT];
1538 f_print(fout, "\tz_xdrs->x_op = XDR_ENCODE;\n");
1540 for (plist = defp->pc.plists, i = 0; plist; plist = plist->next) {
1541 if (plist->component_kind == DEF_PARAM
1542 && (plist->pl.param_kind == DEF_OUTPARAM
1543 || plist->pl.param_kind == DEF_INOUTPARAM)) {
1545 f_print(fout, "\tif ((!%s)",
1546 (plist->scode ? plist->scode : plist->code));
1548 f_print(fout, "\n\t || (!%s)",
1549 (plist->scode ? plist->scode : plist->code));
1551 if (++i == noofparams) {
1552 f_print(fout, ")\n\t\tz_result = RXGEN_SS_MARSHAL;\n");
1560 ss_ProcTail_frees(char *xdrfunc, int *somefrees) {
1562 f_print(fout, "\tz_xdrs->x_op = XDR_FREE;\n");
1563 f_print(fout, "\tif ((!%s)", xdrfunc);
1566 f_print(fout, "\n\t || (!%s)", xdrfunc);
1572 ss_ProcTail_setup(definition * defp)
1579 if (defp->can_fail) {
1580 f_print(fout, "fail:\n");
1583 for (plist = defp->pc.plists; plist; plist = plist->next) {
1584 if (plist->component_kind == DEF_PARAM
1585 && (plist->pl.param_flag & FREETHIS_PARAM))
1586 ss_ProcTail_frees(plist->scode, &somefrees);
1589 for (listp = typedef_defined; listp != NULL; listp = listp->next) {
1590 defp1 = (definition *) listp->val;
1591 for (plist = defp->pc.plists; plist; plist = plist->next) {
1592 if (plist->component_kind == DEF_PARAM
1593 && (plist->pl.param_kind == DEF_OUTPARAM
1594 || plist->pl.param_kind == DEF_INOUTPARAM)
1595 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1596 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1597 switch (defp1->pc.rel) {
1600 ss_ProcTail_frees(plist->scode, &somefrees);
1610 for (listp = uniondef_defined; listp != NULL; listp = listp->next) {
1611 defp1 = (definition *) listp->val;
1612 for (plist = defp->pc.plists; plist; plist = plist->next) {
1613 if (plist->component_kind == DEF_PARAM
1614 && (plist->pl.param_kind == DEF_OUTPARAM
1615 || plist->pl.param_kind == DEF_INOUTPARAM)
1616 && !(plist->pl.param_flag & FREETHIS_PARAM)) {
1617 if (streq(defp1->def_name, structname(plist->pl.param_type))) {
1618 if (plist->pl.param_flag & INDIRECT_PARAM) {
1619 ss_ProcTail_frees(plist->scode, &somefrees);
1627 f_print(fout, ")\n");
1628 f_print(fout, "\t\tz_result = RXGEN_SS_XDRFREE;\n\n");
1632 f_print(fout, "\tif (rx_enable_stats) {\n");
1633 f_print(fout, "\t rx_RecordCallStatistics(z_call,");
1634 if (PackageStatIndex[PackageIndex]) {
1635 f_print(fout, " %s,\n", PackageStatIndex[PackageIndex]);
1638 "\n\t\t(((afs_uint32)(ntohs(rx_ServiceIdOf(rx_ConnectionOf(z_call))) << 16)) |\n"
1639 "\t\t((afs_uint32)ntohs(rx_ServiceOf(rx_ConnectionOf(z_call))->servicePort))),\n");
1641 f_print(fout, "\t\t%d, %sNO_OF_STAT_FUNCS, 0);\n",
1642 no_of_stat_funcs, PackagePrefix[PackageIndex]);
1643 f_print(fout, "\t}\n\n");
1646 f_print(fout, "\treturn z_result;\n");
1647 f_print(fout, "}\n\n");
1651 ucs_ProcCallback_setup(definition * defp, char *cbheader)
1656 for (plist = defp->pc.plists; plist; plist = plist->next) {
1657 if (plist->component_kind == DEF_PARAM) {
1664 f_print(fout, "struct args_%s%s%s {\n", prefix,
1665 PackagePrefix[PackageIndex], defp->pc.proc_name);
1667 for (plist = defp->pc.plists; plist; plist = plist->next) {
1668 if (plist->component_kind == DEF_PARAM) {
1669 f_print(fout, "\t");
1670 if (plist->pl.param_kind == DEF_INPARAM &&
1671 strcmp(plist->pl.param_type, "char *") == 0) {
1672 f_print(fout, "const ");
1674 if ((plist->pl.param_flag & OUT_STRING) != 0) {
1675 f_print(fout, "%s *%s", plist->pl.param_type,
1676 plist->pl.param_name);
1678 f_print(fout, "%s %s", plist->pl.param_type,
1679 plist->pl.param_name);
1681 f_print(fout, ";\n");
1685 f_print(fout, "};\n");
1688 f_print(fout, "static int\n"
1689 "%s%s%s%s(struct ubik_callrock_info *info, void *z_rock)\n"
1691 cbheader, prefix, PackagePrefix[PackageIndex],
1692 defp->pc.proc_name);
1695 f_print(fout, "\tstruct args_%s%s%s *z_args = z_rock;\n", prefix,
1696 PackagePrefix[PackageIndex], defp->pc.proc_name);
1699 f_print(fout, "\treturn %s%s%s(info->conn", prefix, PackagePrefix[PackageIndex],
1700 defp->pc.proc_name);
1702 for (plist = defp->pc.plists; plist; plist = plist->next) {
1703 if (plist->component_kind == DEF_PARAM) {
1704 f_print(fout, ",\n\t\t\tz_args->%s", plist->pl.param_name);
1708 f_print(fout, ");\n"
1714 ucs_ProcName_setup(definition * defp, char *procheader, int split_flag)
1720 f_print(fout, "int %s%s%s%s(struct ubik_client *aclient, afs_int32 aflags",
1721 procheader, prefix, PackagePrefix[PackageIndex],
1722 defp->pc.proc_name);
1724 f_print(fout, "int %s%s%s%s(aclient, aflags", procheader, prefix,
1725 PackagePrefix[PackageIndex], defp->pc.proc_name);
1728 if ((strlen(procheader) + strlen(prefix) +
1729 strlen(PackagePrefix[PackageIndex]) + strlen(defp->pc.proc_name)) >=
1730 MAX_FUNCTION_NAME_LEN) {
1731 error("function name is too long, increase MAX_FUNCTION_NAME_LEN");
1734 for (plist = defp->pc.plists; plist; plist = plist->next) {
1735 if (plist->component_kind == DEF_PARAM) {
1738 if (plist->pl.param_kind == DEF_INPARAM &&
1739 strcmp(plist->pl.param_type, "char *") == 0) {
1740 f_print(fout, "const ");
1742 if (plist->pl.param_flag & OUT_STRING) {
1743 f_print(fout, "%s *%s", plist->pl.param_type,
1744 plist->pl.param_name);
1746 f_print(fout, "%s %s", plist->pl.param_type,
1747 plist->pl.param_name);
1750 plist->pl.param_flag &= ~PROCESSED_PARAM;
1751 f_print(fout, " %s", plist->pl.param_name);
1755 f_print(fout, ")\n");
1761 ucs_ProcParams_setup(definition * defp, int split_flag)
1763 proc1_list *plist, *plist1;
1768 f_print(fout, "\tstruct ubik_client *aclient;\n\tafs_int32 aflags;\n");
1769 for (plist = defp->pc.plists; plist; plist = plist->next) {
1770 if (plist->component_kind == DEF_PARAM
1771 && !(plist->pl.param_flag & PROCESSED_PARAM)) {
1772 if (plist->pl.param_flag & OUT_STRING) {
1773 f_print(fout, "\t%s *%s", plist->pl.param_type,
1774 plist->pl.param_name);
1776 f_print(fout, "\t%s %s", plist->pl.param_type,
1777 plist->pl.param_name);
1779 plist->pl.param_flag |= PROCESSED_PARAM;
1780 for (plist1 = defp->pc.plists; plist1; plist1 = plist1->next) {
1781 if ((plist1->component_kind == DEF_PARAM)
1782 && streq(plist->pl.param_type, plist1->pl.param_type)
1783 && !(plist1->pl.param_flag & PROCESSED_PARAM)) {
1785 char *pntr = strchr(plist1->pl.param_type, '*');
1788 if (plist1->pl.param_flag & OUT_STRING) {
1789 f_print(fout, ", *%s%s", star, plist1->pl.param_name);
1791 f_print(fout, ", %s%s", star, plist1->pl.param_name);
1793 plist1->pl.param_flag |= PROCESSED_PARAM;
1796 f_print(fout, ";\n");
1802 ucs_ProcTail_setup(definition * defp, char *cbheader, int split_flag)
1807 f_print(fout, "{\n");
1809 for (plist = defp->pc.plists; plist; plist = plist->next) {
1810 if (plist->component_kind == DEF_PARAM) {
1817 f_print(fout, "\tstruct args_%s%s%s args;\n", prefix,
1818 PackagePrefix[PackageIndex], defp->pc.proc_name);
1819 f_print(fout, "\tmemset(&args, 0, sizeof(args));\n\n");
1821 for (plist = defp->pc.plists; plist; plist = plist->next) {
1822 if (plist->component_kind == DEF_PARAM) {
1823 plist->pl.param_flag &= ~PROCESSED_PARAM;
1824 f_print(fout, "\targs.%s = %s;\n", plist->pl.param_name,
1825 plist->pl.param_name);
1829 f_print(fout, "\n\treturn ubik_CallRock(aclient, aflags, %s%s%s%s, &args);\n",
1830 cbheader, prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1832 f_print(fout, "\treturn ubik_CallRock(aclient, aflags, %s%s%s%s, NULL);\n",
1833 cbheader, prefix, PackagePrefix[PackageIndex], defp->pc.proc_name);
1836 f_print(fout, "}\n\n");
1841 opcode_holes_exist(void)
1845 for (i = lowest_opcode[PackageIndex]; i < highest_opcode[PackageIndex];
1847 if (!opcodenum_is_defined(i))
1855 er_Proc_CodeGeneration(void)
1859 temp = PackageIndex;
1860 if (!combinepackages)
1862 for (; PackageIndex <= temp; PackageIndex++) {
1863 if (proc_defined[PackageIndex] == NULL)
1865 if (combinepackages || opcode_holes_exist()) {
1866 er_HeadofOldStyleProc_setup();
1867 er_BodyofOldStyleProc_setup();
1868 er_TailofOldStyleProc_setup();
1869 er_HeadofOldStyleProc_setup2();
1870 er_BodyofOldStyleProc_setup2();
1871 er_TailofOldStyleProc_setup2();
1873 er_ProcDeclExterns_setup();
1874 er_ProcProcsArray_setup();
1875 er_ProcMainBody_setup();
1878 PackageIndex = temp;
1883 er_ProcDeclExterns_setup(void)
1891 f_print(fout, "\n");
1892 for (listp = proc_defined[PackageIndex]; listp != NULL;
1893 listp = listp->next) {
1894 defp = (definition *) listp->val;
1895 if (defp->pc.proc_serverstub) {
1896 f_print(fout, "afs_int32 %s();\n", defp->pc.proc_serverstub);
1903 er_ProcProcsArray_setup(void)
1908 if ((listp = proc_defined[PackageIndex])) {
1909 defp = (definition *) listp->val;
1911 f_print(fout, "\nstatic char *opnames%d[] = {\"%s%s\"",
1912 PackageIndex, defp->pc.proc_prefix, defp->pc.proc_name);
1915 if (defp->pc.proc_serverstub) {
1916 f_print(fout, "\nstatic afs_int32 (*StubProcsArray%d[])() = {%s",
1917 PackageIndex, defp->pc.proc_serverstub);
1920 "\nstatic afs_int32 (*StubProcsArray%d[])(struct rx_call *z_call, XDR *z_xdrs) = {_%s%s%s",
1921 PackageIndex, prefix, defp->pc.proc_prefix,
1922 ((definition *) listp->val)->pc.proc_name);
1925 listp = listp->next;
1927 for (; listp != NULL; listp = listp->next) {
1928 defp = (definition *) listp->val;
1930 f_print(fout, ", \"%s%s\"",defp->pc.proc_prefix,defp->pc.proc_name);
1933 if (defp->pc.proc_serverstub) {
1934 f_print(fout, ",%s", defp->pc.proc_serverstub);
1936 f_print(fout, ", _%s%s%s", prefix, defp->pc.proc_prefix,
1937 defp->pc.proc_name);
1941 f_print(fout, "};\n\n");
1946 er_ProcMainBody_setup(void)
1949 f_print(fout, "char *%sTranslateOpCode(int op)\n{\n",
1950 PackagePrefix[PackageIndex]);
1951 f_print(fout, "\tif (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\treturn NULL;\n",
1952 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
1953 f_print(fout, "\treturn opnames%d[op - %sLOWEST_OPCODE];\n}\n",
1954 PackageIndex, PackagePrefix[PackageIndex]);
1955 f_print(fout, "struct %sstats *%sOpCodeStats(int op)\n{\n",
1956 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
1957 f_print(fout, "\tif (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\treturn NULL;\n",
1958 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
1959 f_print(fout, "\treturn NULL;/*%d %s*/\n}\n",
1960 PackageIndex, PackagePrefix[PackageIndex]);
1964 f_print(fout, "int %s%sExecuteRequest(struct rx_call *z_call)\n",
1965 prefix, PackagePrefix[PackageIndex]);
1966 f_print(fout, "{\n\tint op;\n");
1967 f_print(fout, "\tXDR z_xdrs;\n");
1968 f_print(fout, "\t" "afs_int32 z_result;\n\n");
1969 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
1971 "\tif (!xdr_int(&z_xdrs, &op))\n\t\tz_result = RXGEN_DECODE;\n");
1973 "\telse if (op < %sLOWEST_OPCODE || op > %sHIGHEST_OPCODE)\n\t\tz_result = RXGEN_OPCODE;\n",
1974 PackagePrefix[PackageIndex], PackagePrefix[PackageIndex]);
1976 "\telse\n\t\tz_result = (*StubProcsArray%d[op - %sLOWEST_OPCODE])(z_call, &z_xdrs);\n",
1977 PackageIndex, PackagePrefix[PackageIndex]);
1978 f_print(fout, "\treturn hton_syserr_conv(z_result);\n}\n");
1982 er_HeadofOldStyleProc_setup2(void)
1985 f_print(fout, "int %sOpCodeIndex(int op)\n{\n", (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
1986 f_print(fout, "\tswitch (op) {\n");
1991 er_HeadofOldStyleProc_setup(void)
1994 f_print(fout, "char *%sTranslateOpCode(int op)\n{\n",
1995 (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
1999 "\nint %s%sExecuteRequest (struct rx_call *z_call)\n",
2001 (combinepackages ? MasterPrefix : PackagePrefix[PackageIndex]));
2002 f_print(fout, "{\n");
2003 f_print(fout, "\tint op;\n");
2004 f_print(fout, "\tXDR z_xdrs;\n");
2005 f_print(fout, "\t" "afs_int32 z_result;\n\n");
2006 f_print(fout, "\txdrrx_create(&z_xdrs, z_call, XDR_DECODE);\n");
2007 f_print(fout, "\tz_result = RXGEN_DECODE;\n");
2008 f_print(fout, "\tif (!xdr_int(&z_xdrs, &op)) goto fail;\n");
2010 f_print(fout, "\tswitch (op) {\n");
2014 er_BodyofOldStyleProc_setup(void)
2018 if (combinepackages) {
2019 int temp = PackageIndex;
2020 for (PackageIndex = 0; PackageIndex <= temp; PackageIndex++) {
2021 for (listp = proc_defined[PackageIndex]; listp != NULL;
2022 listp = listp->next)
2023 proc_er_case((definition *) listp->val);
2025 PackageIndex = temp;
2027 for (listp = proc_defined[PackageIndex]; listp != NULL;
2028 listp = listp->next)
2029 proc_er_case((definition *) listp->val);
2035 proc_er_case(definition * defp)
2038 f_print(fout, "\t\tcase %d:", defp->pc.proc_opcodenum);
2039 f_print(fout, "\treturn \"%s%s\";\n",
2040 defp->pc.proc_prefix, defp->pc.proc_name);
2043 if (opcodesnotallowed[PackageIndex]) {
2044 f_print(fout, "\t\tcase %d:\n", defp->pc.proc_opcodenum);
2046 f_print(fout, "\t\tcase %s:\n", defp->pc.proc_opcodename);
2048 if (defp->pc.proc_serverstub) {
2049 f_print(fout, "\t\t\tz_result = %s(z_call, &z_xdrs);\n",
2050 defp->pc.proc_serverstub);
2052 f_print(fout, "\t\t\tz_result = _%s%s%s(z_call, &z_xdrs);\n", prefix,
2053 defp->pc.proc_prefix, defp->pc.proc_name);
2055 f_print(fout, "\t\t\tbreak;\n");
2059 proc_op_case(definition * defp)
2061 f_print(fout, "\t\tcase %d:", defp->pc.proc_opcodenum);
2062 f_print(fout, "\treturn %d;\n",
2067 er_BodyofOldStyleProc_setup2(void)
2073 if (combinepackages) {
2074 int temp = PackageIndex;
2075 for (PackageIndex = 0; PackageIndex <= temp; PackageIndex++) {
2076 for (listp = proc_defined[PackageIndex]; listp != NULL;
2077 listp = listp->next)
2078 proc_op_case((definition *) listp->val);
2080 PackageIndex = temp;
2082 for (listp = proc_defined[PackageIndex]; listp != NULL;
2083 listp = listp->next)
2084 proc_op_case((definition *) listp->val);
2089 er_TailofOldStyleProc_setup2(void)
2092 f_print(fout, "\t\tdefault:\n");
2093 f_print(fout, "\t\t\treturn -1;\n\t}\n}\n");
2098 er_TailofOldStyleProc_setup(void)
2100 f_print(fout, "\t\tdefault:\n");
2102 f_print(fout, "\t\t\treturn NULL;\n\t}\n}\n");
2105 f_print(fout, "\t\t\tz_result = RXGEN_OPCODE;\n");
2106 f_print(fout, "\t\t\tbreak;\n\t}\n");
2107 f_print(fout, "fail:\n");
2108 f_print(fout, "\treturn z_result;\n}\n");
2112 h_ProcMainBody_setup(void)
2114 f_print(fout,"\nextern int %s%sExecuteRequest(struct rx_call *);\n",
2115 prefix, PackagePrefix[PackageIndex]);
2119 h_HeadofOldStyleProc_setup(void)
2121 char *pprefix = (combinepackages ? MasterPrefix :
2122 PackagePrefix[PackageIndex]);
2123 f_print(fout,"\nstruct %sstats{\n\tint statsver;\n};", pprefix);
2124 f_print(fout,"\nextern int %s%sExecuteRequest(struct rx_call *);\n",
2126 f_print(fout,"\nextern int %sOpCodeIndex(int op);\n", PackagePrefix[PackageIndex]);
2130 h_Proc_CodeGeneration(void)
2134 temp = PackageIndex;
2135 if (!combinepackages)
2137 for (; PackageIndex <= temp; PackageIndex++) {
2138 if (combinepackages || opcode_holes_exist()) {
2139 h_HeadofOldStyleProc_setup();
2141 h_ProcMainBody_setup();
2144 PackageIndex = temp;
2148 proc_h_case(definition * defp)
2150 f_print(fout, "#define opcode_%s%s \t((afs_uint64)((%uLL << 32) + %sOpCodeIndex(%u)))\n",
2151 defp->pc.proc_prefix, defp->pc.proc_name, StatIndex,
2152 defp->pc.proc_prefix, defp->pc.proc_opcodenum);
2156 h_opcode_stats_pkg(char *pprefix, int lowest, int highest, int nops,
2157 int statfuncs, char *ptype, list *proclist)
2165 "\n/* Opcode-related useful stats for %spackage: %s */\n",
2167 f_print(fout, "#define %sLOWEST_OPCODE %d\n", pprefix, lowest);
2168 f_print(fout, "#define %sHIGHEST_OPCODE %d\n", pprefix, highest);
2169 f_print(fout, "#define %sNUMBER_OPCODES %d\n\n", pprefix, nops);
2171 for (listp = proclist; listp != NULL;
2172 listp = listp->next)
2173 proc_h_case((definition *) listp->val);
2176 f_print(fout, "#define %sNO_OF_STAT_FUNCS\t%d\n\n",
2177 pprefix, statfuncs);
2178 f_print(fout, "AFS_RXGEN_EXPORT\n");
2179 f_print(fout, "extern const char *%sfunction_names[];\n\n",
2185 h_opcode_stats(void)
2187 if (combinepackages) {
2188 h_opcode_stats_pkg(MasterPrefix, master_lowest_opcode, master_highest_opcode, master_no_of_opcodes, no_of_stat_funcs_header[0], "Master ", proc_defined[0]);
2191 for (i = 0; i <= PackageIndex; i++) {
2192 h_opcode_stats_pkg(PackagePrefix[i], lowest_opcode[i], highest_opcode[i], no_of_opcodes[i], no_of_stat_funcs_header[i], "", proc_defined[i]);
2199 generate_multi_macros(definition * defp)
2201 char *startname = SplitStart, *endname = SplitEnd;
2210 f_print(fout, "\n#include <rx/rx_multi.h>");
2212 f_print(fout, "\n#define multi_%s%s(", PackagePrefix[PackageIndex],
2213 defp->pc.proc_name);
2214 for (plist = defp->pc.plists; plist; plist = plist->next) {
2215 if (plist->component_kind == DEF_PARAM) {
2218 f_print(fout, "%s", plist->pl.param_name);
2220 f_print(fout, ", %s", plist->pl.param_name);
2224 f_print(fout, ") \\\n");
2226 startname = "Start";
2229 f_print(fout, "\tmulti_Body(%s%s%s(multi_call", startname,
2230 PackagePrefix[PackageIndex], defp->pc.proc_name);
2231 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 0);
2232 for (plist = defp->pc.plists; plist; plist = plist->next) {
2233 if (plist->component_kind == DEF_PARAM)
2234 f_print(fout, ", %s", plist->pl.param_name);
2236 do_split(defp, OUT, &numofparams, DEF_OUTPARAM, 1);
2237 f_print(fout, "), %s%s%s(multi_call", endname,
2238 PackagePrefix[PackageIndex], defp->pc.proc_name);
2239 do_split(defp, IN, &numofparams, DEF_INPARAM, 0);
2240 for (plist = defp->pc.plists; plist; plist = plist->next) {
2241 if (plist->component_kind == DEF_PARAM) {
2242 f_print(fout, ", %s", plist->pl.param_name);
2245 do_split(defp, IN, &numofparams, DEF_INPARAM, 1);
2246 f_print(fout, "))\n\n");
2251 IsRxgenToken(token * tokp)
2253 if (tokp->kind == TOK_PACKAGE || tokp->kind == TOK_PREFIX
2254 || tokp->kind == TOK_SPECIAL || tokp->kind == TOK_STARTINGOPCODE
2255 || tokp->kind == TOK_SPLITPREFIX || tokp->kind == TOK_PROC
2256 || tokp->kind == TOK_STATINDEX)
2262 IsRxgenDefinition(definition * def)
2264 if (def->def_kind == DEF_PACKAGE || def->def_kind == DEF_PREFIX
2265 || def->def_kind == DEF_SPECIAL || def->def_kind == DEF_STARTINGOPCODE
2266 || def->def_kind == DEF_SPLITPREFIX || def->def_kind == DEF_PROC)