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 <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
This commit is contained in:
Simon Wilkinson 2010-02-14 10:01:14 +00:00 committed by Derrick Brashear
parent b114faf52f
commit 13ae3de3f6
5 changed files with 112 additions and 27 deletions

View File

@ -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:

View File

@ -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;
}
}

View File

@ -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 <ubik.h>\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 <afs/param.h>\n");
f_print(fout, "#include <afs/stds.h>\n");
@ -528,6 +536,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, "#include <afs/rxgen_consts.h>\n");
if (uflag)
f_print(fout, "#include <ubik.h>\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 <sys/types.h>\n");
f_print(fout, "#include <rx/xdr.h>\n");
@ -689,6 +703,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");
}
f_print(fout, "#include <afs/rxgen_consts.h>\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 <sys/types.h>\n");
f_print(fout, "#include <rx/xdr.h>\n");
@ -757,6 +777,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");
}
f_print(fout, "#include <afs/rxgen_consts.h>\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'];

View File

@ -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);

View File

@ -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;