rpc_cout.c (7c478bd9) | rpc_cout.c (61961e0f) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 5 unchanged lines hidden (view full) --- 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 5 unchanged lines hidden (view full) --- 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ |
22 |
|
22/* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 27/* All Rights Reserved */ 28/* 29 * University Copyright- Copyright (c) 1982, 1986, 1988 --- 6 unchanged lines hidden (view full) --- 36 */ 37 38#pragma ident "%Z%%M% %I% %E% SMI" 39 40/* 41 * rpc_cout.c, XDR routine outputter for the RPC protocol compiler 42 */ 43#include <stdio.h> | 23/* 24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28/* All Rights Reserved */ 29/* 30 * University Copyright- Copyright (c) 1982, 1986, 1988 --- 6 unchanged lines hidden (view full) --- 37 */ 38 39#pragma ident "%Z%%M% %I% %E% SMI" 40 41/* 42 * rpc_cout.c, XDR routine outputter for the RPC protocol compiler 43 */ 44#include <stdio.h> |
45#include <stdlib.h> |
|
44#include <string.h> | 46#include <string.h> |
47#include <ctype.h> |
|
45#include "rpc_parse.h" 46#include "rpc_util.h" 47 | 48#include "rpc_parse.h" 49#include "rpc_util.h" 50 |
51extern void crash(void); 52 53static void print_header(definition *); 54static void print_trailer(void); 55static void emit_enum(definition *); 56static void emit_program(definition *); 57static void emit_union(definition *); 58static void emit_struct(definition *); 59static void emit_typedef(definition *); 60static void print_stat(int, declaration *); 61static void emit_inline(int, declaration *, int); 62static void emit_inline64(int, declaration *, int); 63static void emit_single_in_line(int, declaration *, int, relation); 64static void emit_single_in_line64(int, declaration *, int, relation); 65static char *upcase(char *); 66 |
|
48/* 49 * Emit the C-routine for the given definition 50 */ 51void | 67/* 68 * Emit the C-routine for the given definition 69 */ 70void |
52emit(def) 53 definition *def; | 71emit(definition *def) |
54{ | 72{ |
55 if (def->def_kind == DEF_CONST) { | 73 if (def->def_kind == DEF_CONST) |
56 return; | 74 return; |
57 } | |
58 if (def->def_kind == DEF_PROGRAM) { 59 emit_program(def); 60 return; 61 } 62 if (def->def_kind == DEF_TYPEDEF) { 63 /* 64 * now we need to handle declarations like 65 * struct typedef foo foo; --- 17 unchanged lines hidden (view full) --- 83 break; 84 case DEF_TYPEDEF: 85 emit_typedef(def); 86 break; 87 } 88 print_trailer(); 89} 90 | 75 if (def->def_kind == DEF_PROGRAM) { 76 emit_program(def); 77 return; 78 } 79 if (def->def_kind == DEF_TYPEDEF) { 80 /* 81 * now we need to handle declarations like 82 * struct typedef foo foo; --- 17 unchanged lines hidden (view full) --- 100 break; 101 case DEF_TYPEDEF: 102 emit_typedef(def); 103 break; 104 } 105 print_trailer(); 106} 107 |
91static 92findtype(def, type) 93 definition *def; 94 char *type; | 108static int 109findtype(definition *def, char *type) |
95{ 96 | 110{ 111 |
97 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) { | 112 if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) |
98 return (0); | 113 return (0); |
99 } else { 100 return (streq(def->def_name, type)); 101 } | 114 return (streq(def->def_name, type)); |
102} 103 | 115} 116 |
104static 105undefined(type) 106 char *type; | 117static int 118undefined(char *type) |
107{ 108 definition *def; 109 | 119{ 120 definition *def; 121 |
110 def = (definition *) FINDVAL(defined, type, findtype); | 122 def = (definition *)FINDVAL(defined, type, findtype); |
111 return (def == NULL); 112} 113 114 | 123 return (def == NULL); 124} 125 126 |
115static 116print_generic_header(procname, pointerp) 117 char *procname; 118 int pointerp; | 127static void 128print_generic_header(char *procname, int pointerp) |
119{ 120 f_print(fout, "\n"); 121 f_print(fout, "bool_t\n"); 122 if (Cflag) { | 129{ 130 f_print(fout, "\n"); 131 f_print(fout, "bool_t\n"); 132 if (Cflag) { |
123 f_print(fout, "xdr_%s(", procname); 124 f_print(fout, "register XDR *xdrs, "); 125 f_print(fout, "%s ", procname); 126 if (pointerp) 127 f_print(fout, "*"); 128 f_print(fout, "objp)\n{\n\n"); | 133 f_print(fout, "xdr_%s(", procname); 134 f_print(fout, "XDR *xdrs, "); 135 f_print(fout, "%s ", procname); 136 if (pointerp) 137 f_print(fout, "*"); 138 f_print(fout, "objp)\n{\n\n"); |
129 } else { | 139 } else { |
130 f_print(fout, "xdr_%s(xdrs, objp)\n", procname); 131 f_print(fout, "\tregister XDR *xdrs;\n"); 132 f_print(fout, "\t%s ", procname); 133 if (pointerp) 134 f_print(fout, "*"); 135 f_print(fout, "objp;\n{\n\n"); | 140 f_print(fout, "xdr_%s(xdrs, objp)\n", procname); 141 f_print(fout, "\tXDR *xdrs;\n"); 142 f_print(fout, "\t%s ", procname); 143 if (pointerp) 144 f_print(fout, "*"); 145 f_print(fout, "objp;\n{\n\n"); |
136 } 137} 138 | 146 } 147} 148 |
139static 140print_header(def) 141 definition *def; | 149static void 150print_header(definition *def) |
142{ | 151{ |
143 144 decl_list *dl; 145 bas_type *ptr; 146 int i; 147 | |
148 print_generic_header(def->def_name, 149 def->def_kind != DEF_TYPEDEF || 150 !isvectordef(def->def.ty.old_type, 151 def->def.ty.rel)); 152 /* Now add Inline support */ 153 154 if (inlinelen == 0) 155 return; 156 /* May cause lint to complain. but ... */ | 152 print_generic_header(def->def_name, 153 def->def_kind != DEF_TYPEDEF || 154 !isvectordef(def->def.ty.old_type, 155 def->def.ty.rel)); 156 /* Now add Inline support */ 157 158 if (inlinelen == 0) 159 return; 160 /* May cause lint to complain. but ... */ |
157 f_print(fout, "#if defined(_LP64) || defined(_KERNEL)\n"); 158 f_print(fout, "\tregister int *buf;\n"); 159 f_print(fout, "#else\n"); 160 f_print(fout, "\tregister long *buf;\n"); 161 f_print(fout, "#endif\n\n"); | 161 f_print(fout, "\trpc_inline_t *buf;\n\n"); |
162} 163 | 162} 163 |
164static 165print_prog_header(plist) 166 proc_list *plist; | 164static void 165print_prog_header(proc_list *plist) |
167{ 168 print_generic_header(plist->args.argname, 1); 169} 170 | 166{ 167 print_generic_header(plist->args.argname, 1); 168} 169 |
171static 172print_trailer() | 170static void 171print_trailer(void) |
173{ 174 f_print(fout, "\treturn (TRUE);\n"); 175 f_print(fout, "}\n"); 176} 177 178 | 172{ 173 f_print(fout, "\treturn (TRUE);\n"); 174 f_print(fout, "}\n"); 175} 176 177 |
179static 180print_ifopen(indent, name) 181 int indent; 182 char *name; | 178static void 179print_ifopen(int indent, char *name) |
183{ 184 tabify(fout, indent); 185 if (streq(name, "rpcprog_t") || | 180{ 181 tabify(fout, indent); 182 if (streq(name, "rpcprog_t") || |
186 streq(name, "rpcvers_t") || 187 streq(name, "rpcproc_t") || 188 streq(name, "rpcprot_t") || 189 streq(name, "rpcport_t")) 190 strtok(name, "_"); | 183 streq(name, "rpcvers_t") || 184 streq(name, "rpcproc_t") || 185 streq(name, "rpcprot_t") || 186 streq(name, "rpcport_t")) 187 (void) strtok(name, "_"); |
191 f_print(fout, "if (!xdr_%s(xdrs", name); 192} 193 | 188 f_print(fout, "if (!xdr_%s(xdrs", name); 189} 190 |
194static 195print_ifarg(arg) 196 char *arg; | 191static void 192print_ifarg(char *arg) |
197{ 198 f_print(fout, ", %s", arg); 199} 200 | 193{ 194 f_print(fout, ", %s", arg); 195} 196 |
201static 202print_ifsizeof(indent, prefix, type) 203 int indent; 204 char *prefix; 205 char *type; | 197static void 198print_ifsizeof(int indent, char *prefix, char *type) |
206{ 207 if (indent) { 208 f_print(fout, ",\n"); 209 tabify(fout, indent); | 199{ 200 if (indent) { 201 f_print(fout, ",\n"); 202 tabify(fout, indent); |
210 } else { | 203 } else { |
211 f_print(fout, ", "); 212 } 213 if (streq(type, "bool")) { | 204 f_print(fout, ", "); 205 } 206 if (streq(type, "bool")) { |
214 f_print(fout, "sizeof (bool_t), (xdrproc_t) xdr_bool"); | 207 f_print(fout, "sizeof (bool_t), (xdrproc_t)xdr_bool"); |
215 } else { 216 f_print(fout, "sizeof ("); 217 if (undefined(type) && prefix) { 218 f_print(fout, "%s ", prefix); 219 } | 208 } else { 209 f_print(fout, "sizeof ("); 210 if (undefined(type) && prefix) { 211 f_print(fout, "%s ", prefix); 212 } |
220 f_print(fout, "%s), (xdrproc_t) xdr_%s", type, type); | 213 f_print(fout, "%s), (xdrproc_t)xdr_%s", type, type); |
221 } 222} 223 | 214 } 215} 216 |
224static 225print_ifclose(indent) 226 int indent; | 217static void 218print_ifclose(int indent) |
227{ 228 f_print(fout, "))\n"); 229 tabify(fout, indent); 230 f_print(fout, "\treturn (FALSE);\n"); 231} 232 | 219{ 220 f_print(fout, "))\n"); 221 tabify(fout, indent); 222 f_print(fout, "\treturn (FALSE);\n"); 223} 224 |
233static 234print_ifstat(indent, prefix, type, rel, amax, objname, name) 235 int indent; 236 char *prefix; 237 char *type; 238 relation rel; 239 char *amax; 240 char *objname; 241 char *name; | 225static void 226print_ifstat(int indent, char *prefix, char *type, relation rel, 227 char *amax, char *objname, char *name) |
242{ 243 char *alt = NULL; 244 245 switch (rel) { 246 case REL_POINTER: 247 print_ifopen(indent, "pointer"); 248 print_ifarg("(char **)"); 249 f_print(fout, "%s", objname); 250 print_ifsizeof(0, prefix, type); 251 break; 252 case REL_VECTOR: | 228{ 229 char *alt = NULL; 230 231 switch (rel) { 232 case REL_POINTER: 233 print_ifopen(indent, "pointer"); 234 print_ifarg("(char **)"); 235 f_print(fout, "%s", objname); 236 print_ifsizeof(0, prefix, type); 237 break; 238 case REL_VECTOR: |
253 if (streq(type, "string")) { | 239 if (streq(type, "string")) |
254 alt = "string"; | 240 alt = "string"; |
255 } else if (streq(type, "opaque")) { | 241 else if (streq(type, "opaque")) |
256 alt = "opaque"; | 242 alt = "opaque"; |
257 } | |
258 if (alt) { 259 print_ifopen(indent, alt); 260 print_ifarg(objname); 261 } else { 262 print_ifopen(indent, "vector"); 263 print_ifarg("(char *)"); 264 f_print(fout, "%s", objname); 265 } 266 print_ifarg(amax); | 243 if (alt) { 244 print_ifopen(indent, alt); 245 print_ifarg(objname); 246 } else { 247 print_ifopen(indent, "vector"); 248 print_ifarg("(char *)"); 249 f_print(fout, "%s", objname); 250 } 251 print_ifarg(amax); |
267 if (!alt) { | 252 if (!alt) |
268 print_ifsizeof(indent + 1, prefix, type); | 253 print_ifsizeof(indent + 1, prefix, type); |
269 } | |
270 break; 271 case REL_ARRAY: | 254 break; 255 case REL_ARRAY: |
272 if (streq(type, "string")) { | 256 if (streq(type, "string")) |
273 alt = "string"; | 257 alt = "string"; |
274 } else if (streq(type, "opaque")) { | 258 else if (streq(type, "opaque")) |
275 alt = "bytes"; | 259 alt = "bytes"; |
276 } | |
277 if (streq(type, "string")) { 278 print_ifopen(indent, alt); 279 print_ifarg(objname); 280 } else { | 260 if (streq(type, "string")) { 261 print_ifopen(indent, alt); 262 print_ifarg(objname); 263 } else { |
281 if (alt) { | 264 if (alt) |
282 print_ifopen(indent, alt); | 265 print_ifopen(indent, alt); |
283 } else { | 266 else |
284 print_ifopen(indent, "array"); | 267 print_ifopen(indent, "array"); |
285 } | |
286 print_ifarg("(char **)"); | 268 print_ifarg("(char **)"); |
287 if (*objname == '&') { | 269 if (*objname == '&') |
288 f_print(fout, "%s.%s_val, (u_int *) %s.%s_len", 289 objname, name, objname, name); | 270 f_print(fout, "%s.%s_val, (u_int *) %s.%s_len", 271 objname, name, objname, name); |
290 } else { | 272 else |
291 f_print(fout, 292 "&%s->%s_val, (u_int *) &%s->%s_len", 293 objname, name, objname, name); | 273 f_print(fout, 274 "&%s->%s_val, (u_int *) &%s->%s_len", 275 objname, name, objname, name); |
294 } | |
295 } 296 print_ifarg(amax); | 276 } 277 print_ifarg(amax); |
297 if (!alt) { | 278 if (!alt) |
298 print_ifsizeof(indent + 1, prefix, type); | 279 print_ifsizeof(indent + 1, prefix, type); |
299 } | |
300 break; 301 case REL_ALIAS: 302 print_ifopen(indent, type); 303 print_ifarg(objname); 304 break; 305 } 306 print_ifclose(indent); 307} 308 309/* ARGSUSED */ | 280 break; 281 case REL_ALIAS: 282 print_ifopen(indent, type); 283 print_ifarg(objname); 284 break; 285 } 286 print_ifclose(indent); 287} 288 289/* ARGSUSED */ |
310static 311emit_enum(def) 312 definition *def; | 290static void 291emit_enum(definition *def) |
313{ 314 print_ifopen(1, "enum"); 315 print_ifarg("(enum_t *)objp"); 316 print_ifclose(1); 317} 318 | 292{ 293 print_ifopen(1, "enum"); 294 print_ifarg("(enum_t *)objp"); 295 print_ifclose(1); 296} 297 |
319static 320emit_program(def) 321 definition *def; | 298static void 299emit_program(definition *def) |
322{ 323 decl_list *dl; 324 version_list *vlist; 325 proc_list *plist; 326 327 for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next) 328 for (plist = vlist->procs; plist != NULL; plist = plist->next) { 329 if (!newstyle || plist->arg_num < 2) 330 continue; /* old style, or single argument */ 331 print_prog_header(plist); 332 for (dl = plist->args.decls; dl != NULL; 333 dl = dl->next) 334 print_stat(1, &dl->decl); 335 print_trailer(); 336 } 337} 338 339 | 300{ 301 decl_list *dl; 302 version_list *vlist; 303 proc_list *plist; 304 305 for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next) 306 for (plist = vlist->procs; plist != NULL; plist = plist->next) { 307 if (!newstyle || plist->arg_num < 2) 308 continue; /* old style, or single argument */ 309 print_prog_header(plist); 310 for (dl = plist->args.decls; dl != NULL; 311 dl = dl->next) 312 print_stat(1, &dl->decl); 313 print_trailer(); 314 } 315} 316 317 |
340static 341emit_union(def) 342 definition *def; | 318static void 319emit_union(definition *def) |
343{ 344 declaration *dflt; 345 case_list *cl; 346 declaration *cs; 347 char *object; | 320{ 321 declaration *dflt; 322 case_list *cl; 323 declaration *cs; 324 char *object; |
348 char *vecformat = "objp->%s_u.%s"; 349 char *format = "&objp->%s_u.%s"; | |
350 351 print_stat(1, &def->def.un.enum_decl); 352 f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name); 353 for (cl = def->def.un.cases; cl != NULL; cl = cl->next) { 354 355 f_print(fout, "\tcase %s:\n", cl->case_name); 356 if (cl->contflag == 1) /* a continued case statement */ 357 continue; 358 cs = &cl->case_decl; 359 if (!streq(cs->type, "void")) { | 325 326 print_stat(1, &def->def.un.enum_decl); 327 f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name); 328 for (cl = def->def.un.cases; cl != NULL; cl = cl->next) { 329 330 f_print(fout, "\tcase %s:\n", cl->case_name); 331 if (cl->contflag == 1) /* a continued case statement */ 332 continue; 333 cs = &cl->case_decl; 334 if (!streq(cs->type, "void")) { |
360 object = alloc(strlen(def->def_name) + strlen(format) + 361 strlen(cs->name) + 1); 362 if (isvectordef(cs->type, cs->rel)) { 363 s_print(object, vecformat, def->def_name, 364 cs->name); 365 } else { 366 s_print(object, format, def->def_name, 367 cs->name); 368 } | 335 size_t len = strlen(def->def_name) + 336 strlen("&objp->%s_u.%s") + 337 strlen(cs->name) + 1; 338 object = malloc(len); 339 if (isvectordef(cs->type, cs->rel)) 340 (void) snprintf(object, len, "objp->%s_u.%s", 341 def->def_name, cs->name); 342 else 343 (void) snprintf(object, len, "&objp->%s_u.%s", 344 def->def_name, cs->name); |
369 print_ifstat(2, cs->prefix, cs->type, cs->rel, 370 cs->array_max, object, cs->name); 371 free(object); 372 } 373 f_print(fout, "\t\tbreak;\n"); 374 } 375 dflt = def->def.un.default_decl; 376 if (dflt != NULL) { 377 if (!streq(dflt->type, "void")) { | 345 print_ifstat(2, cs->prefix, cs->type, cs->rel, 346 cs->array_max, object, cs->name); 347 free(object); 348 } 349 f_print(fout, "\t\tbreak;\n"); 350 } 351 dflt = def->def.un.default_decl; 352 if (dflt != NULL) { 353 if (!streq(dflt->type, "void")) { |
354 size_t len = strlen(def->def_name) + 355 strlen("&objp->%s_u.%s") + 356 strlen(dflt->name) + 1; |
|
378 f_print(fout, "\tdefault:\n"); | 357 f_print(fout, "\tdefault:\n"); |
379 object = alloc(strlen(def->def_name) + strlen(format) + 380strlen(dflt->name) + 1); 381 if (isvectordef(dflt->type, dflt->rel)) { 382 s_print(object, vecformat, def->def_name, 383 dflt->name); 384 } else { 385 s_print(object, format, def->def_name, 386 dflt->name); 387 } | 358 object = malloc(len); 359 if (isvectordef(dflt->type, dflt->rel)) 360 (void) snprintf(object, len, "objp->%s_u.%s", 361 def->def_name, dflt->name); 362 else 363 (void) snprintf(object, len, "&objp->%s_u.%s", 364 def->def_name, dflt->name); |
388 389 print_ifstat(2, dflt->prefix, dflt->type, dflt->rel, 390 dflt->array_max, object, dflt->name); 391 free(object); 392 f_print(fout, "\t\tbreak;\n"); 393 } 394 } else { 395 f_print(fout, "\tdefault:\n"); --- 84 unchanged lines hidden (view full) --- 480arraysize(char *sz, declaration *dc, int elsize) 481{ 482 int len; 483 int elsz = elsize; 484 int digits; 485 int slen = 0; 486 char *plus = ""; 487 char *tmp; | 365 366 print_ifstat(2, dflt->prefix, dflt->type, dflt->rel, 367 dflt->array_max, object, dflt->name); 368 free(object); 369 f_print(fout, "\t\tbreak;\n"); 370 } 371 } else { 372 f_print(fout, "\tdefault:\n"); --- 84 unchanged lines hidden (view full) --- 457arraysize(char *sz, declaration *dc, int elsize) 458{ 459 int len; 460 int elsz = elsize; 461 int digits; 462 int slen = 0; 463 char *plus = ""; 464 char *tmp; |
465 size_t tlen; |
|
488 489 /* 490 * Calculate the size of a string to hold the size of all arrays 491 * to be inlined. 492 * 493 * We have the string representation of the total size that has already 494 * been seen. (Null if this is the first array). 495 * We have the string representation of array max from the declaration, --- 10 unchanged lines hidden (view full) --- 506 elsz /= 10; 507 508 /* 509 * If elsize != 1 the allocate 3 extra bytes for the times 510 * string, " * ", the "()" below, and the digits. One extra 511 * for the trailing NULL 512 */ 513 len = strlen(dc->array_max) + (elsize == 1 ? 0 : digits + 5) + 1; | 466 467 /* 468 * Calculate the size of a string to hold the size of all arrays 469 * to be inlined. 470 * 471 * We have the string representation of the total size that has already 472 * been seen. (Null if this is the first array). 473 * We have the string representation of array max from the declaration, --- 10 unchanged lines hidden (view full) --- 484 elsz /= 10; 485 486 /* 487 * If elsize != 1 the allocate 3 extra bytes for the times 488 * string, " * ", the "()" below, and the digits. One extra 489 * for the trailing NULL 490 */ 491 len = strlen(dc->array_max) + (elsize == 1 ? 0 : digits + 5) + 1; |
514 tmp = realloc(sz, slen + len + strlen(plus)); | 492 tlen = slen + len + strlen(plus); 493 tmp = realloc(sz, tlen); |
515 if (tmp == NULL) { 516 f_print(stderr, "Fatal error : no memory\n"); 517 crash(); 518 } 519 520 if (elsize == 1) | 494 if (tmp == NULL) { 495 f_print(stderr, "Fatal error : no memory\n"); 496 crash(); 497 } 498 499 if (elsize == 1) |
521 s_print(tmp + slen, "%s%s", plus, dc->array_max); | 500 (void) snprintf(tmp + slen, tlen - slen, "%s%s", 501 plus, dc->array_max); |
522 else | 502 else |
523 s_print(tmp + slen, "%s(%s) * %d", plus, dc->array_max, elsize); | 503 (void) snprintf(tmp + slen, tlen - slen, "%s(%s) * %d", 504 plus, dc->array_max, elsize); |
524 525 return (tmp); 526} 527 528static void 529inline_struct(decl_list *dl, decl_list *last, int flag, int indent) 530{ 531 int size, tsize; | 505 506 return (tmp); 507} 508 509static void 510inline_struct(decl_list *dl, decl_list *last, int flag, int indent) 511{ 512 int size, tsize; |
532 decl_list *cur, *psav; 533 char *sizestr, *plus; 534 char ptemp[256]; | 513 decl_list *cur; 514 char *sizestr; |
535 536 cur = NULL; 537 tsize = 0; 538 sizestr = NULL; 539 for (; dl != last; dl = dl->next) { 540 if (inline_type(&dl->decl, &size)) { 541 if (cur == NULL) 542 cur = dl; --- 22 unchanged lines hidden (view full) --- 565 } 566 tsize = 0; 567 cur = NULL; 568 sizestr = NULL; 569 print_stat(indent + 1, &dl->decl); 570 } 571 } 572 | 515 516 cur = NULL; 517 tsize = 0; 518 sizestr = NULL; 519 for (; dl != last; dl = dl->next) { 520 if (inline_type(&dl->decl, &size)) { 521 if (cur == NULL) 522 cur = dl; --- 22 unchanged lines hidden (view full) --- 545 } 546 tsize = 0; 547 cur = NULL; 548 sizestr = NULL; 549 print_stat(indent + 1, &dl->decl); 550 } 551 } 552 |
573 if (cur != NULL) 574 if (sizestr == NULL && tsize < inlinelen) { 575 /* don't expand into inline code if tsize < inlinelen */ 576 while (cur != dl) { 577 print_stat(indent + 1, &cur->decl); 578 cur = cur->next; 579 } 580 } else { 581 expand_inline(indent, sizestr, tsize, flag, dl, cur); | 553 if (cur == NULL) 554 return; 555 if (sizestr == NULL && tsize < inlinelen) { 556 /* don't expand into inline code if tsize < inlinelen */ 557 while (cur != dl) { 558 print_stat(indent + 1, &cur->decl); 559 cur = cur->next; |
582 } | 560 } |
561 } else { 562 expand_inline(indent, sizestr, tsize, flag, dl, cur); 563 } |
|
583} 584 585/* 586 * Check if we can inline this structure. While we are at it check if the 587 * declaration list has any vectors defined of "basic" types. 588 */ 589static int 590check_inline(decl_list *dl, int inlinelen, int *have_vector) 591{ 592 int tsize = 0; 593 int size; 594 int doinline = 0; 595 596 *have_vector = 0; 597 if (inlinelen == 0) 598 return (0); 599 600 for (; dl != NULL; dl = dl->next) { | 564} 565 566/* 567 * Check if we can inline this structure. While we are at it check if the 568 * declaration list has any vectors defined of "basic" types. 569 */ 570static int 571check_inline(decl_list *dl, int inlinelen, int *have_vector) 572{ 573 int tsize = 0; 574 int size; 575 int doinline = 0; 576 577 *have_vector = 0; 578 if (inlinelen == 0) 579 return (0); 580 581 for (; dl != NULL; dl = dl->next) { |
601 if (inline_type(&dl->decl, &size)) { 602 if (dl->decl.rel == REL_VECTOR) { 603 *have_vector = 1; 604 doinline = 1; 605 break; 606 } else { 607 tsize += size; 608 if (tsize >= inlinelen) 609 doinline = 1; 610 } 611 } else { | 582 if (!inline_type(&dl->decl, &size)) { |
612 tsize = 0; | 583 tsize = 0; |
584 continue; |
|
613 } | 585 } |
586 if (dl->decl.rel == REL_VECTOR) { 587 *have_vector = 1; 588 return (1); 589 } 590 tsize += size; 591 if (tsize >= inlinelen) 592 doinline = 1; |
|
614 } 615 616 return (doinline); 617} 618 619 620static void 621emit_struct_tail_recursion(definition *defp, int can_inline) --- 76 unchanged lines hidden (view full) --- 698 f_print(fout, "\t\t\t\tmem_free(tmp_%s, sizeof (%s));\n", 699 defp->def_name, defp->def_name); 700 701 f_print(fout, "\t\t\telse\n\t\t\t\tfirst_objp = FALSE;\n\t\t}\n"); 702 703 f_print(fout, "\n\t}\n"); 704} 705 | 593 } 594 595 return (doinline); 596} 597 598 599static void 600emit_struct_tail_recursion(definition *defp, int can_inline) --- 76 unchanged lines hidden (view full) --- 677 f_print(fout, "\t\t\t\tmem_free(tmp_%s, sizeof (%s));\n", 678 defp->def_name, defp->def_name); 679 680 f_print(fout, "\t\t\telse\n\t\t\t\tfirst_objp = FALSE;\n\t\t}\n"); 681 682 f_print(fout, "\n\t}\n"); 683} 684 |
706static 707emit_struct(def) 708 definition *def; | 685static void 686emit_struct(definition *def) |
709{ 710 decl_list *dl = def->def.st.decls; 711 int can_inline, have_vector; 712 713 714 can_inline = check_inline(dl, inlinelen, &have_vector); 715 if (have_vector) 716 f_print(fout, "\tint i;\n"); --- 19 unchanged lines hidden (view full) --- 736 737 /* now take care of XDR_FREE inline case or the non-inline cases */ 738 739 for (dl = def->def.st.decls; dl != NULL; dl = dl->next) 740 print_stat(1, &dl->decl); 741 742} 743 | 687{ 688 decl_list *dl = def->def.st.decls; 689 int can_inline, have_vector; 690 691 692 can_inline = check_inline(dl, inlinelen, &have_vector); 693 if (have_vector) 694 f_print(fout, "\tint i;\n"); --- 19 unchanged lines hidden (view full) --- 714 715 /* now take care of XDR_FREE inline case or the non-inline cases */ 716 717 for (dl = def->def.st.decls; dl != NULL; dl = dl->next) 718 print_stat(1, &dl->decl); 719 720} 721 |
744static 745emit_typedef(def) 746 definition *def; | 722static void 723emit_typedef(definition *def) |
747{ 748 char *prefix = def->def.ty.old_prefix; 749 char *type = def->def.ty.old_type; 750 char *amax = def->def.ty.array_max; 751 relation rel = def->def.ty.rel; 752 753 print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name); 754} 755 | 724{ 725 char *prefix = def->def.ty.old_prefix; 726 char *type = def->def.ty.old_type; 727 char *amax = def->def.ty.array_max; 728 relation rel = def->def.ty.rel; 729 730 print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name); 731} 732 |
756static 757print_stat(indent, dec) 758 int indent; 759 declaration *dec; | 733static void 734print_stat(int indent, declaration *dec) |
760{ 761 char *prefix = dec->prefix; 762 char *type = dec->type; 763 char *amax = dec->array_max; 764 relation rel = dec->rel; 765 char name[256]; 766 | 735{ 736 char *prefix = dec->prefix; 737 char *type = dec->type; 738 char *amax = dec->array_max; 739 relation rel = dec->rel; 740 char name[256]; 741 |
767 if (isvectordef(type, rel)) { 768 s_print(name, "objp->%s", dec->name); 769 } else { 770 s_print(name, "&objp->%s", dec->name); 771 } | 742 if (isvectordef(type, rel)) 743 (void) snprintf(name, sizeof (name), "objp->%s", dec->name); 744 else 745 (void) snprintf(name, sizeof (name), "&objp->%s", dec->name); |
772 print_ifstat(indent, prefix, type, rel, amax, name, dec->name); 773} 774 775 | 746 print_ifstat(indent, prefix, type, rel, amax, name, dec->name); 747} 748 749 |
776char *upcase(); 777 778emit_inline(indent, decl, flag) 779int indent; 780declaration *decl; 781int flag; | 750static void 751emit_inline(int indent, declaration *decl, int flag) |
782{ 783 switch (decl->rel) { 784 case REL_ALIAS : 785 emit_single_in_line(indent, decl, flag, REL_ALIAS); 786 break; 787 case REL_VECTOR : 788 tabify(fout, indent); 789 f_print(fout, "{\n"); 790 tabify(fout, indent + 1); | 752{ 753 switch (decl->rel) { 754 case REL_ALIAS : 755 emit_single_in_line(indent, decl, flag, REL_ALIAS); 756 break; 757 case REL_VECTOR : 758 tabify(fout, indent); 759 f_print(fout, "{\n"); 760 tabify(fout, indent + 1); |
791 f_print(fout, "register %s *genp;\n\n", decl->type); | 761 f_print(fout, "%s *genp;\n\n", decl->type); |
792 tabify(fout, indent + 1); 793 f_print(fout, 794 "for (i = 0, genp = objp->%s;\n", decl->name); 795 tabify(fout, indent + 2); 796 f_print(fout, "i < %s; i++) {\n", decl->array_max); 797 emit_single_in_line(indent + 2, decl, flag, REL_VECTOR); 798 tabify(fout, indent + 1); 799 f_print(fout, "}\n"); 800 tabify(fout, indent); 801 f_print(fout, "}\n"); 802 } 803} 804 | 762 tabify(fout, indent + 1); 763 f_print(fout, 764 "for (i = 0, genp = objp->%s;\n", decl->name); 765 tabify(fout, indent + 2); 766 f_print(fout, "i < %s; i++) {\n", decl->array_max); 767 emit_single_in_line(indent + 2, decl, flag, REL_VECTOR); 768 tabify(fout, indent + 1); 769 f_print(fout, "}\n"); 770 tabify(fout, indent); 771 f_print(fout, "}\n"); 772 } 773} 774 |
805emit_inline64(indent, decl, flag) 806int indent; 807declaration *decl; 808int flag; | 775static void 776emit_inline64(int indent, declaration *decl, int flag) |
809{ 810 switch (decl->rel) { 811 case REL_ALIAS : 812 emit_single_in_line64(indent, decl, flag, REL_ALIAS); 813 break; 814 case REL_VECTOR : 815 tabify(fout, indent); 816 f_print(fout, "{\n"); 817 tabify(fout, indent + 1); | 777{ 778 switch (decl->rel) { 779 case REL_ALIAS : 780 emit_single_in_line64(indent, decl, flag, REL_ALIAS); 781 break; 782 case REL_VECTOR : 783 tabify(fout, indent); 784 f_print(fout, "{\n"); 785 tabify(fout, indent + 1); |
818 f_print(fout, "register %s *genp;\n\n", decl->type); | 786 f_print(fout, "%s *genp;\n\n", decl->type); |
819 tabify(fout, indent + 1); 820 f_print(fout, 821 "for (i = 0, genp = objp->%s;\n", decl->name); 822 tabify(fout, indent + 2); 823 f_print(fout, "i < %s; i++) {\n", decl->array_max); 824 emit_single_in_line64(indent + 2, decl, flag, REL_VECTOR); 825 tabify(fout, indent + 1); 826 f_print(fout, "}\n"); 827 tabify(fout, indent); 828 f_print(fout, "}\n"); 829 } 830} 831 | 787 tabify(fout, indent + 1); 788 f_print(fout, 789 "for (i = 0, genp = objp->%s;\n", decl->name); 790 tabify(fout, indent + 2); 791 f_print(fout, "i < %s; i++) {\n", decl->array_max); 792 emit_single_in_line64(indent + 2, decl, flag, REL_VECTOR); 793 tabify(fout, indent + 1); 794 f_print(fout, "}\n"); 795 tabify(fout, indent); 796 f_print(fout, "}\n"); 797 } 798} 799 |
832emit_single_in_line(indent, decl, flag, rel) 833int indent; 834declaration *decl; 835int flag; 836relation rel; | 800static void 801emit_single_in_line(int indent, declaration *decl, int flag, relation rel) |
837{ 838 char *upp_case; 839 int freed = 0; 840 841 tabify(fout, indent); 842 if (flag == PUT) 843 f_print(fout, "IXDR_PUT_"); 844 else 845 if (rel == REL_ALIAS) 846 f_print(fout, "objp->%s = IXDR_GET_", decl->name); 847 else 848 f_print(fout, "*genp++ = IXDR_GET_"); 849 850 upp_case = upcase(decl->type); 851 852 /* hack - XX */ | 802{ 803 char *upp_case; 804 int freed = 0; 805 806 tabify(fout, indent); 807 if (flag == PUT) 808 f_print(fout, "IXDR_PUT_"); 809 else 810 if (rel == REL_ALIAS) 811 f_print(fout, "objp->%s = IXDR_GET_", decl->name); 812 else 813 f_print(fout, "*genp++ = IXDR_GET_"); 814 815 upp_case = upcase(decl->type); 816 817 /* hack - XX */ |
853 if (strcmp(upp_case, "INT") == 0) 854 { | 818 if (strcmp(upp_case, "INT") == 0) { |
855 free(upp_case); 856 freed = 1; 857 upp_case = "LONG"; 858 } 859 if ((strcmp(upp_case, "U_INT") == 0) || | 819 free(upp_case); 820 freed = 1; 821 upp_case = "LONG"; 822 } 823 if ((strcmp(upp_case, "U_INT") == 0) || |
860 (strcmp(upp_case, "RPCPROG") == 0) || 861 (strcmp(upp_case, "RPCVERS") == 0) || 862 (strcmp(upp_case, "RPCPROC") == 0) || 863 (strcmp(upp_case, "RPCPROT") == 0) || 864 (strcmp(upp_case, "RPCPORT") == 0)) 865 { | 824 (strcmp(upp_case, "RPCPROG") == 0) || 825 (strcmp(upp_case, "RPCVERS") == 0) || 826 (strcmp(upp_case, "RPCPROC") == 0) || 827 (strcmp(upp_case, "RPCPROT") == 0) || 828 (strcmp(upp_case, "RPCPORT") == 0)) { |
866 free(upp_case); 867 freed = 1; 868 upp_case = "U_LONG"; 869 } 870 871 if (flag == PUT) 872 if (rel == REL_ALIAS) 873 f_print(fout, 874 "%s(buf, objp->%s);\n", upp_case, decl->name); 875 else 876 f_print(fout, "%s(buf, *genp++);\n", upp_case); 877 878 else 879 f_print(fout, "%s(buf);\n", upp_case); 880 if (!freed) 881 free(upp_case); 882} 883 | 829 free(upp_case); 830 freed = 1; 831 upp_case = "U_LONG"; 832 } 833 834 if (flag == PUT) 835 if (rel == REL_ALIAS) 836 f_print(fout, 837 "%s(buf, objp->%s);\n", upp_case, decl->name); 838 else 839 f_print(fout, "%s(buf, *genp++);\n", upp_case); 840 841 else 842 f_print(fout, "%s(buf);\n", upp_case); 843 if (!freed) 844 free(upp_case); 845} 846 |
884emit_single_in_line64(indent, decl, flag, rel) 885int indent; 886declaration *decl; 887int flag; 888relation rel; | 847static void 848emit_single_in_line64(int indent, declaration *decl, int flag, relation rel) |
889{ 890 char *upp_case; 891 int freed = 0; 892 893 tabify(fout, indent); 894 if (flag == PUT) 895 f_print(fout, "IXDR_PUT_"); 896 else 897 if (rel == REL_ALIAS) 898 f_print(fout, "objp->%s = IXDR_GET_", decl->name); 899 else 900 f_print(fout, "*genp++ = IXDR_GET_"); 901 902 upp_case = upcase(decl->type); 903 904 /* hack - XX */ | 849{ 850 char *upp_case; 851 int freed = 0; 852 853 tabify(fout, indent); 854 if (flag == PUT) 855 f_print(fout, "IXDR_PUT_"); 856 else 857 if (rel == REL_ALIAS) 858 f_print(fout, "objp->%s = IXDR_GET_", decl->name); 859 else 860 f_print(fout, "*genp++ = IXDR_GET_"); 861 862 upp_case = upcase(decl->type); 863 864 /* hack - XX */ |
905 if ((strcmp(upp_case, "INT") == 0)||(strcmp(upp_case, "LONG") == 0)) 906 { | 865 if ((strcmp(upp_case, "INT") == 0)||(strcmp(upp_case, "LONG") == 0)) { |
907 free(upp_case); 908 freed = 1; 909 upp_case = "INT32"; 910 } 911 if ((strcmp(upp_case, "U_INT") == 0) || | 866 free(upp_case); 867 freed = 1; 868 upp_case = "INT32"; 869 } 870 if ((strcmp(upp_case, "U_INT") == 0) || |
912 (strcmp(upp_case, "U_LONG") == 0) || 913 (strcmp(upp_case, "RPCPROG") == 0) || 914 (strcmp(upp_case, "RPCVERS") == 0) || 915 (strcmp(upp_case, "RPCPROC") == 0) || 916 (strcmp(upp_case, "RPCPROT") == 0) || 917 (strcmp(upp_case, "RPCPORT") == 0)) 918 { | 871 (strcmp(upp_case, "U_LONG") == 0) || 872 (strcmp(upp_case, "RPCPROG") == 0) || 873 (strcmp(upp_case, "RPCVERS") == 0) || 874 (strcmp(upp_case, "RPCPROC") == 0) || 875 (strcmp(upp_case, "RPCPROT") == 0) || 876 (strcmp(upp_case, "RPCPORT") == 0)) { |
919 free(upp_case); 920 freed = 1; 921 upp_case = "U_INT32"; 922 } 923 924 if (flag == PUT) 925 if (rel == REL_ALIAS) 926 f_print(fout, 927 "%s(buf, objp->%s);\n", upp_case, decl->name); 928 else 929 f_print(fout, "%s(buf, *genp++);\n", upp_case); 930 931 else 932 f_print(fout, "%s(buf);\n", upp_case); 933 if (!freed) 934 free(upp_case); 935} 936 | 877 free(upp_case); 878 freed = 1; 879 upp_case = "U_INT32"; 880 } 881 882 if (flag == PUT) 883 if (rel == REL_ALIAS) 884 f_print(fout, 885 "%s(buf, objp->%s);\n", upp_case, decl->name); 886 else 887 f_print(fout, "%s(buf, *genp++);\n", upp_case); 888 889 else 890 f_print(fout, "%s(buf);\n", upp_case); 891 if (!freed) 892 free(upp_case); 893} 894 |
937char * 938upcase(str) 939char *str; | 895static char * 896upcase(char *str) |
940{ 941 char *ptr, *hptr; 942 | 897{ 898 char *ptr, *hptr; 899 |
943 ptr = (char *)malloc(strlen(str)+1); 944 if (ptr == (char *)NULL) 945 { | 900 ptr = malloc(strlen(str)+1); 901 if (ptr == NULL) { |
946 f_print(stderr, "malloc failed\n"); 947 exit(1); 948 }; 949 950 hptr = ptr; 951 while (*str != '\0') 952 *ptr++ = toupper(*str++); 953 954 *ptr = '\0'; 955 return (hptr); 956} | 902 f_print(stderr, "malloc failed\n"); 903 exit(1); 904 }; 905 906 hptr = ptr; 907 while (*str != '\0') 908 *ptr++ = toupper(*str++); 909 910 *ptr = '\0'; 911 return (hptr); 912} |