From 13ae3de3f6ce5de2395823ee5f862a863caf2e51 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Sun, 14 Feb 2010 10:01:14 +0000 Subject: [PATCH] Add "brief" option to rxgen Add a new -b option to rxgen that turns on "brief" output. This makes a number of changes to the data definitions produced by rxgen so they can be more easily used by the calling code. The changes are: *) Use the new struct rx_opaque structure for all opaque data definitions, rather than defining each as a unique structure. This permits moving opaque data between rxgen structures to be performed by simple assignment. *) Use anonymous structures for internal definitions. Currently rxgen also uses the field name as the structure name, which prevents the use of a field name more than once within a source file. *) Don't embed the structure name within the names of the elements within the structure. This significantly reduces the length of assignment code, and makes for more readable callers. Change-Id: I8cad7e6051f12238a77cf006b0854fb38b54f61a Reviewed-on: http://gerrit.openafs.org/2585 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/rxgen/rpc_cout.c | 36 ++++++++++++++++++++++++++------- src/rxgen/rpc_hout.c | 55 +++++++++++++++++++++++++++++++++++++++------------ src/rxgen/rpc_main.c | 27 ++++++++++++++++++++++++- src/rxgen/rpc_parse.c | 20 +++++++++++++------ src/rxgen/rpc_util.h | 1 + 5 files changed, 112 insertions(+), 27 deletions(-) diff --git a/src/rxgen/rpc_cout.c b/src/rxgen/rpc_cout.c index 8698eb0..2b874a5 100644 --- a/src/rxgen/rpc_cout.c +++ b/src/rxgen/rpc_cout.c @@ -250,11 +250,20 @@ print_ifstat(int indent, char *prefix, char *type, relation rel, char *amax, print_ifarg("(caddr_t *)"); } if (*objname == '&') { - f_print(fout, "%s.%s_val, (u_int *)%s.%s_len", objname, name, - objname, name); + if (brief_flag) { + f_print(fout, "%s.val, (u_int *)%s.len", objname, objname); + } else { + f_print(fout, "%s.%s_val, (u_int *)%s.%s_len", + objname, name, objname, name); + } } else { - f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len", objname, - name, objname, name); + if (brief_flag) { + f_print(fout, "&%s->val, (u_int *)&%s->len", + objname, objname); + } else { + f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len", + objname, name, objname, name); + } } } print_ifarg(amax); @@ -288,6 +297,7 @@ emit_union(definition * def) declaration *cs; char *object; char *format = "&objp->%s_u.%s"; + char *briefformat = "&objp->u.%s"; print_stat(&def->def.un.enum_decl); f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name); @@ -298,7 +308,12 @@ emit_union(definition * def) object = alloc(strlen(def->def_name) + strlen(format) + strlen(cs->name) + 1); - s_print(object, format, def->def_name, cs->name); + + if (brief_flag) + s_print(object, briefformat, cs->name); + else + s_print(object, format, def->def_name, cs->name); + print_ifstat(2, cs->prefix, cs->type, cs->rel, cs->array_max, object, cs->name); free(object); @@ -386,8 +401,15 @@ print_hout(declaration * dec) switch (dec->rel) { case REL_ARRAY: f_print(fout, "struct %s {\n", dec->name); - f_print(fout, "\tu_int %s_len;\n", dec->name); - f_print(fout, "\t%s%s *%s_val;\n", prefix, dec->type, dec->name); + if (brief_flag) { + f_print(fout, "\tu_int %s_len;\n", dec->name); + f_print(fout, "\t%s%s *%s_val;\n", prefix, + dec->type, dec->name); + } else { + f_print(fout, "\tu_int %s_len;\n", dec->name); + f_print(fout, "\t%s%s *%s_val;\n", prefix, + dec->type, dec->name); + } f_print(fout, "} %s", dec->name); break; default: diff --git a/src/rxgen/rpc_hout.c b/src/rxgen/rpc_hout.c index 50d8c1e..ac73b2c 100644 --- a/src/rxgen/rpc_hout.c +++ b/src/rxgen/rpc_hout.c @@ -157,7 +157,11 @@ puniondef(definition * def) if (decl && !streq(decl->type, "void")) { pdeclaration(name, decl, 2); } - f_print(fout, "\t} %s_u;\n", name); + if (brief_flag) { + f_print(fout, "\t} u;\n"); + } else { + f_print(fout, "\t} %s_u;\n", name); + } f_print(fout, "};\n"); f_print(fout, "typedef struct %s %s;\n", name, name); STOREVAL(&uniondef_defined, def); @@ -345,7 +349,7 @@ ptypedef(definition * def) if (streq(old, "string")) { old = "char"; rel = REL_POINTER; - } else if (streq(old, "opaque")) { + } else if (!brief_flag && streq(old, "opaque")) { old = "char"; } else if (streq(old, "bool")) { old = "bool_t"; @@ -358,10 +362,21 @@ ptypedef(definition * def) f_print(fout, "typedef "); switch (rel) { case REL_ARRAY: - f_print(fout, "struct %s {\n", name); - f_print(fout, "\tu_int %s_len;\n", name); - f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name); - f_print(fout, "} %s", name); + if (brief_flag) { + if (streq(old, "opaque")) { + f_print(fout, "struct rx_opaque %s", name); + } else { + f_print(fout, "struct {\n"); + f_print(fout, "\tu_int len;\n"); + f_print(fout, "\t%s%s *val;\n", prefix, old); + f_print(fout, "} %s", name); + } + } else { + f_print(fout, "struct %s {\n", name); + f_print(fout, "\tu_int %s_len;\n", name); + f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name); + f_print(fout, "} %s", name); + } break; case REL_POINTER: f_print(fout, "%s%s *%s", prefix, old, name); @@ -422,13 +437,27 @@ pdeclaration(char *name, declaration * dec, int tab) f_print(fout, "%s%s *%s", prefix, type, dec->name); break; case REL_ARRAY: - f_print(fout, "struct %s {\n", dec->name); - tabify(fout, tab); - f_print(fout, "\tu_int %s_len;\n", dec->name); - tabify(fout, tab); - f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name); - tabify(fout, tab); - f_print(fout, "} %s", dec->name); + if (brief_flag) { + if (streq(dec->type, "opaque")) { + f_print(fout, "struct rx_opaque %s",dec->name); + } else { + f_print(fout, "struct {\n"); + tabify(fout, tab); + f_print(fout, "\tu_int len;\n"); + tabify(fout, tab); + f_print(fout, "\t%s%s *val;\n", prefix, type); + tabify(fout, tab); + f_print(fout, "} %s", dec->name); + } + } else { + f_print(fout, "struct %s {\n", dec->name); + tabify(fout, tab); + f_print(fout, "\tu_int %s_len;\n", dec->name); + tabify(fout, tab); + f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name); + tabify(fout, tab); + f_print(fout, "} %s", dec->name); + } break; } } diff --git a/src/rxgen/rpc_main.c b/src/rxgen/rpc_main.c index 374fb32..0825d34 100644 --- a/src/rxgen/rpc_main.c +++ b/src/rxgen/rpc_main.c @@ -59,6 +59,7 @@ struct commandline { int ansic_flag; + int brief_flag; int cflag; int hflag; int lflag; @@ -87,6 +88,7 @@ char *OutFileFlag = ""; char OutFile[256]; char Sflag = 0, Cflag = 0, hflag = 0, cflag = 0, kflag = 0, uflag = 0; char ansic_flag = 0; /* If set, build ANSI C style prototypes */ +char brief_flag = 0; /* If set, shorten names */ char zflag = 0; /* If set, abort server stub if rpc call returns non-zero */ char xflag = 0; /* if set, add stats code to stubs */ char yflag = 0; /* if set, only emit function name arrays to xdr file */ @@ -173,7 +175,7 @@ main(int argc, char *argv[]) if (!parseargs(argc, argv, &cmd)) { f_print(stderr, "usage: %s infile\n", cmdname); f_print(stderr, - " %s [-c | -h | -l | -m | -C | -S | -r | -k | -R | -p | -d | -z | -u] [-Pprefix] [-Idir] [-o outfile] [infile]\n", + " %s [-c | -h | -l | -m | -C | -S | -r | -b | -k | -R | -p | -d | -z | -u] [-Pprefix] [-Idir] [-o outfile] [infile]\n", cmdname); f_print(stderr, " %s [-s udp|tcp]* [-o outfile] [infile]\n", cmdname); @@ -475,6 +477,9 @@ h_output(char *infile, char *define, int extend, char *outfile, int append) if (xflag) { f_print(fout, "#include \"rx/rx_globals.h\"\n"); } + if (brief_flag) { + f_print(fout, "#include \"rx/rx_opaque.h\"\n"); + } if (uflag) f_print(fout, "#include \n"); f_print(fout, "#else /* UKERNEL */\n"); @@ -519,6 +524,9 @@ h_output(char *infile, char *define, int extend, char *outfile, int append) if (xflag) { f_print(fout, "#include \"rx/rx_globals.h\"\n"); } + if (brief_flag) { + f_print(fout, "#include \"rx/rx_opaque.h\"\n"); + } f_print(fout, "#else /* KERNEL */\n"); f_print(fout, "#include \n"); f_print(fout, "#include \n"); @@ -528,6 +536,9 @@ h_output(char *infile, char *define, int extend, char *outfile, int append) if (xflag) { f_print(fout, "#include \n"); } + if (brief_flag) { + f_print(fout, "#include \n"); + } f_print(fout, "#include \n"); if (uflag) f_print(fout, "#include \n"); @@ -682,6 +693,9 @@ C_output(char *infile, char *define, int extend, char *outfile, int append) if (xflag) { f_print(fout, "#include \"rx/rx_globals.h\"\n"); } + if (brief_flag) { + f_print(fout, "#include \"rx/rx_opaque.h\"\n"); + } } else { f_print(fout, "#include \n"); f_print(fout, "#include \n"); @@ -689,6 +703,9 @@ C_output(char *infile, char *define, int extend, char *outfile, int append) if (xflag) { f_print(fout, "#include \n"); } + if (brief_flag) { + f_print(fout, "#include \n"); } } @@ -750,6 +767,9 @@ S_output(char *infile, char *define, int extend, char *outfile, int append) if (xflag) { f_print(fout, "#include \"rx/rx_globals.h\"\n"); } + if (brief_flag) { + f_print(fout, "#include \"rx/rx_opaque.h\"\n"); + } } else { f_print(fout, "#include \n"); f_print(fout, "#include \n"); @@ -757,6 +777,9 @@ S_output(char *infile, char *define, int extend, char *outfile, int append) if (xflag) { f_print(fout, "#include \n"); } + if (brief_flag) { + f_print(fout, "#include \n"); + } f_print(fout, "#include \n"); } } @@ -826,6 +849,7 @@ parseargs(int argc, char *argv[], struct commandline *cmd) case 'm': case 'C': case 'S': + case 'b': case 'r': case 'R': case 'k': @@ -879,6 +903,7 @@ parseargs(int argc, char *argv[], struct commandline *cmd) } } cmd->ansic_flag = ansic_flag = flag['A']; + cmd->brief_flag = brief_flag = flag['b']; cmd->cflag = cflag = flag['c']; cmd->hflag = hflag = flag['h']; cmd->sflag = flag['s']; diff --git a/src/rxgen/rpc_parse.c b/src/rxgen/rpc_parse.c index eb46021..782477d 100644 --- a/src/rxgen/rpc_parse.c +++ b/src/rxgen/rpc_parse.c @@ -1524,13 +1524,21 @@ ss_ProcSpecial_setup(definition * defp, int *somefrees) *somefrees = 1; switch (defp1->pc.rel) { case REL_ARRAY: - f_print(fout, "\n\t%s.%s_val = 0;", - plist->pl.param_name, defp1->def_name); - f_print(fout, "\n\t%s.%s_len = 0;", - plist->pl.param_name, defp1->def_name); plist->pl.string_name = alloc(40); - s_print(plist->pl.string_name, "%s_val", - defp1->def_name); + if (brief_flag) { + f_print(fout, "\n\t%s.val = 0;", + plist->pl.param_name); + f_print(fout, "\n\t%s.len = 0;", + plist->pl.param_name); + s_print(plist->pl.string_name, "val"); + } else { + f_print(fout, "\n\t%s.%s_val = 0;", + plist->pl.param_name, defp1->def_name); + f_print(fout, "\n\t%s.%s_len = 0;", + plist->pl.param_name, defp1->def_name); + s_print(plist->pl.string_name, "%s_val", + defp1->def_name); + } break; case REL_POINTER: f_print(fout, "\n\t%s = 0;", plist->pl.param_name); diff --git a/src/rxgen/rpc_util.h b/src/rxgen/rpc_util.h index 342c45a..2e316ea 100644 --- a/src/rxgen/rpc_util.h +++ b/src/rxgen/rpc_util.h @@ -58,6 +58,7 @@ extern char *OutFileFlag; extern char OutFile[]; extern char Sflag, Cflag, hflag, cflag, kflag, uflag; extern char ansic_flag; +extern char brief_flag; extern char zflag; extern char xflag; extern char yflag; -- 1.9.4