Line data Source code
1 : /* src/interfaces/ecpg/preproc/type.c */
2 :
3 : #include "postgres_fe.h"
4 :
5 : #include "preproc_extern.h"
6 :
7 : #define indicator_set ind_type != NULL && ind_type->type != ECPGt_NO_INDICATOR
8 :
9 : static struct ECPGstruct_member struct_no_indicator = {"no_indicator", &ecpg_no_indicator, NULL};
10 :
11 : /* duplicate memberlist */
12 : struct ECPGstruct_member *
13 178 : ECPGstruct_member_dup(struct ECPGstruct_member *rm)
14 : {
15 178 : struct ECPGstruct_member *new = NULL;
16 :
17 574 : while (rm)
18 : {
19 : struct ECPGtype *type;
20 :
21 396 : switch (rm->type->type)
22 : {
23 12 : case ECPGt_struct:
24 : case ECPGt_union:
25 12 : type = ECPGmake_struct_type(rm->type->u.members, rm->type->type, rm->type->type_name, rm->type->struct_sizeof);
26 12 : break;
27 0 : case ECPGt_array:
28 :
29 : /*
30 : * if this array does contain a struct again, we have to
31 : * create the struct too
32 : */
33 0 : if (rm->type->u.element->type == ECPGt_struct || rm->type->u.element->type == ECPGt_union)
34 0 : type = ECPGmake_struct_type(rm->type->u.element->u.members, rm->type->u.element->type, rm->type->u.element->type_name, rm->type->u.element->struct_sizeof);
35 : else
36 0 : type = ECPGmake_array_type(ECPGmake_simple_type(rm->type->u.element->type, rm->type->u.element->size, rm->type->u.element->counter), rm->type->size);
37 0 : break;
38 384 : default:
39 384 : type = ECPGmake_simple_type(rm->type->type, rm->type->size, rm->type->counter);
40 384 : break;
41 : }
42 :
43 396 : ECPGmake_struct_member(rm->name, type, &new);
44 :
45 396 : rm = rm->next;
46 : }
47 :
48 178 : return new;
49 : }
50 :
51 : /* The NAME argument is copied. The type argument is preserved as a pointer. */
52 : void
53 504 : ECPGmake_struct_member(const char *name, struct ECPGtype *type, struct ECPGstruct_member **start)
54 : {
55 : struct ECPGstruct_member *ptr,
56 : *ne =
57 504 : (struct ECPGstruct_member *) mm_alloc(sizeof(struct ECPGstruct_member));
58 :
59 504 : ne->name = mm_strdup(name);
60 504 : ne->type = type;
61 504 : ne->next = NULL;
62 :
63 708 : for (ptr = *start; ptr && ptr->next; ptr = ptr->next);
64 :
65 504 : if (ptr)
66 304 : ptr->next = ne;
67 : else
68 200 : *start = ne;
69 504 : }
70 :
71 : struct ECPGtype *
72 1616 : ECPGmake_simple_type(enum ECPGttype type, const char *size, int counter)
73 : {
74 1616 : struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
75 :
76 1616 : ne->type = type;
77 1616 : ne->type_name = NULL;
78 1616 : ne->size = mm_strdup(size);
79 1616 : ne->u.element = NULL;
80 1616 : ne->struct_sizeof = NULL;
81 1616 : ne->counter = counter; /* only needed for varchar and bytea */
82 :
83 1616 : return ne;
84 : }
85 :
86 : struct ECPGtype *
87 144 : ECPGmake_array_type(struct ECPGtype *type, const char *size)
88 : {
89 144 : struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, size, 0);
90 :
91 144 : ne->u.element = type;
92 :
93 144 : return ne;
94 : }
95 :
96 : struct ECPGtype *
97 70 : ECPGmake_struct_type(struct ECPGstruct_member *rm, enum ECPGttype type,
98 : const char *type_name, const char *struct_sizeof)
99 : {
100 70 : struct ECPGtype *ne = ECPGmake_simple_type(type, "1", 0);
101 :
102 70 : ne->type_name = mm_strdup(type_name);
103 70 : ne->u.members = ECPGstruct_member_dup(rm);
104 70 : ne->struct_sizeof = mm_strdup(struct_sizeof);
105 :
106 70 : return ne;
107 : }
108 :
109 : static const char *
110 1212 : get_type(enum ECPGttype type)
111 : {
112 1212 : switch (type)
113 : {
114 390 : case ECPGt_char:
115 390 : return "ECPGt_char";
116 : break;
117 0 : case ECPGt_unsigned_char:
118 0 : return "ECPGt_unsigned_char";
119 : break;
120 64 : case ECPGt_short:
121 64 : return "ECPGt_short";
122 : break;
123 0 : case ECPGt_unsigned_short:
124 0 : return "ECPGt_unsigned_short";
125 : break;
126 424 : case ECPGt_int:
127 424 : return "ECPGt_int";
128 : break;
129 0 : case ECPGt_unsigned_int:
130 0 : return "ECPGt_unsigned_int";
131 : break;
132 24 : case ECPGt_long:
133 24 : return "ECPGt_long";
134 : break;
135 0 : case ECPGt_unsigned_long:
136 0 : return "ECPGt_unsigned_long";
137 : break;
138 0 : case ECPGt_long_long:
139 0 : return "ECPGt_long_long";
140 : break;
141 0 : case ECPGt_unsigned_long_long:
142 0 : return "ECPGt_unsigned_long_long";
143 : break;
144 12 : case ECPGt_float:
145 12 : return "ECPGt_float";
146 : break;
147 32 : case ECPGt_double:
148 32 : return "ECPGt_double";
149 : break;
150 26 : case ECPGt_bool:
151 26 : return "ECPGt_bool";
152 : break;
153 40 : case ECPGt_varchar:
154 40 : return "ECPGt_varchar";
155 42 : case ECPGt_bytea:
156 42 : return "ECPGt_bytea";
157 0 : case ECPGt_NO_INDICATOR: /* no indicator */
158 0 : return "ECPGt_NO_INDICATOR";
159 : break;
160 40 : case ECPGt_char_variable: /* string that should not be quoted */
161 40 : return "ECPGt_char_variable";
162 : break;
163 32 : case ECPGt_const: /* constant string quoted */
164 32 : return "ECPGt_const";
165 : break;
166 12 : case ECPGt_decimal:
167 12 : return "ECPGt_decimal";
168 : break;
169 18 : case ECPGt_numeric:
170 18 : return "ECPGt_numeric";
171 : break;
172 8 : case ECPGt_interval:
173 8 : return "ECPGt_interval";
174 : break;
175 0 : case ECPGt_descriptor:
176 0 : return "ECPGt_descriptor";
177 : break;
178 0 : case ECPGt_sqlda:
179 0 : return "ECPGt_sqlda";
180 : break;
181 20 : case ECPGt_date:
182 20 : return "ECPGt_date";
183 : break;
184 26 : case ECPGt_timestamp:
185 26 : return "ECPGt_timestamp";
186 : break;
187 2 : case ECPGt_string:
188 2 : return "ECPGt_string";
189 : break;
190 0 : default:
191 0 : mmerror(PARSE_ERROR, ET_ERROR, "unrecognized variable type code %d", type);
192 : }
193 :
194 0 : return NULL;
195 : }
196 :
197 : /* Dump a type.
198 : The type is dumped as:
199 : type-tag <comma> - enum ECPGttype
200 : reference-to-variable <comma> - char *
201 : size <comma> - long size of this field (if varchar)
202 : arrsize <comma> - long number of elements in the arr
203 : offset <comma> - offset to the next element
204 : Where:
205 : type-tag is one of the simple types or varchar.
206 : reference-to-variable can be a reference to a struct element.
207 : arrsize is the size of the array in case of array fetches. Otherwise 0.
208 : size is the maxsize in case it is a varchar. Otherwise it is the size of
209 : the variable (required to do array fetches of structs).
210 : */
211 : static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
212 : char *varcharsize,
213 : char *arrsize, const char *size, const char *prefix, int counter);
214 : static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsize,
215 : struct ECPGtype *type, struct ECPGtype *ind_type, const char *prefix, const char *ind_prefix);
216 :
217 : void
218 1234 : ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *type, const int brace_level,
219 : const char *ind_name, struct ECPGtype *ind_type, const int ind_brace_level,
220 : const char *prefix, const char *ind_prefix,
221 : char *arr_str_size, const char *struct_sizeof,
222 : const char *ind_struct_sizeof)
223 : {
224 : struct variable *var;
225 :
226 1234 : if (type->type != ECPGt_descriptor && type->type != ECPGt_sqlda &&
227 1140 : type->type != ECPGt_char_variable && type->type != ECPGt_const &&
228 : brace_level >= 0)
229 : {
230 : char *str;
231 :
232 996 : str = mm_strdup(name);
233 996 : var = find_variable(str);
234 996 : free(str);
235 :
236 996 : if ((var->type->type != type->type) ||
237 996 : (var->type->type_name && !type->type_name) ||
238 996 : (!var->type->type_name && type->type_name) ||
239 996 : (var->type->type_name && type->type_name && strcmp(var->type->type_name, type->type_name) != 0))
240 0 : mmerror(PARSE_ERROR, ET_ERROR, "variable \"%s\" is hidden by a local variable of a different type", name);
241 996 : else if (var->brace_level != brace_level)
242 0 : mmerror(PARSE_ERROR, ET_WARNING, "variable \"%s\" is hidden by a local variable", name);
243 :
244 996 : if (ind_name && ind_type && ind_type->type != ECPGt_NO_INDICATOR && ind_brace_level >= 0)
245 : {
246 64 : str = mm_strdup(ind_name);
247 64 : var = find_variable(str);
248 64 : free(str);
249 :
250 64 : if ((var->type->type != ind_type->type) ||
251 64 : (var->type->type_name && !ind_type->type_name) ||
252 64 : (!var->type->type_name && ind_type->type_name) ||
253 64 : (var->type->type_name && ind_type->type_name && strcmp(var->type->type_name, ind_type->type_name) != 0))
254 0 : mmerror(PARSE_ERROR, ET_ERROR, "indicator variable \"%s\" is hidden by a local variable of a different type", ind_name);
255 64 : else if (var->brace_level != ind_brace_level)
256 0 : mmerror(PARSE_ERROR, ET_WARNING, "indicator variable \"%s\" is hidden by a local variable", ind_name);
257 : }
258 : }
259 :
260 1234 : switch (type->type)
261 : {
262 166 : case ECPGt_array:
263 166 : if (indicator_set && ind_type->type != ECPGt_array)
264 0 : mmfatal(INDICATOR_NOT_ARRAY, "indicator for array/pointer has to be array/pointer");
265 166 : switch (type->u.element->type)
266 : {
267 0 : case ECPGt_array:
268 0 : mmerror(PARSE_ERROR, ET_ERROR, "nested arrays are not supported (except strings)"); /* array of array */
269 0 : break;
270 16 : case ECPGt_struct:
271 : case ECPGt_union:
272 32 : ECPGdump_a_struct(o, name,
273 : ind_name,
274 : type->size,
275 : type->u.element,
276 16 : (ind_type == NULL) ? NULL : ((ind_type->type == ECPGt_NO_INDICATOR) ? ind_type : ind_type->u.element),
277 : prefix, ind_prefix);
278 16 : break;
279 150 : default:
280 150 : if (!IS_SIMPLE_TYPE(type->u.element->type))
281 0 : base_yyerror("internal error: unknown datatype, please report this to <" PACKAGE_BUGREPORT ">");
282 :
283 150 : ECPGdump_a_simple(o, name,
284 150 : type->u.element->type,
285 150 : type->u.element->size, type->size, struct_sizeof ? struct_sizeof : NULL,
286 150 : prefix, type->u.element->counter);
287 :
288 150 : if (ind_type != NULL)
289 : {
290 110 : if (ind_type->type == ECPGt_NO_INDICATOR)
291 : {
292 106 : char *str_neg_one = mm_strdup("-1");
293 :
294 106 : ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, str_neg_one, NULL, ind_prefix, 0);
295 106 : free(str_neg_one);
296 : }
297 : else
298 : {
299 4 : ECPGdump_a_simple(o, ind_name, ind_type->u.element->type,
300 4 : ind_type->u.element->size, ind_type->size, NULL, ind_prefix, 0);
301 : }
302 : }
303 : }
304 166 : break;
305 12 : case ECPGt_struct:
306 : {
307 12 : char *str_one = mm_strdup("1");
308 :
309 12 : if (indicator_set && ind_type->type != ECPGt_struct)
310 0 : mmfatal(INDICATOR_NOT_STRUCT, "indicator for struct has to be a struct");
311 :
312 12 : ECPGdump_a_struct(o, name, ind_name, str_one, type, ind_type, prefix, ind_prefix);
313 12 : free(str_one);
314 : }
315 12 : break;
316 0 : case ECPGt_union: /* cannot dump a complete union */
317 0 : base_yyerror("type of union has to be specified");
318 0 : break;
319 40 : case ECPGt_char_variable:
320 : {
321 : /*
322 : * Allocate for each, as there are code-paths where the values
323 : * get stomped on.
324 : */
325 40 : char *str_varchar_one = mm_strdup("1");
326 40 : char *str_arr_one = mm_strdup("1");
327 40 : char *str_neg_one = mm_strdup("-1");
328 :
329 40 : if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
330 0 : mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
331 :
332 40 : ECPGdump_a_simple(o, name, type->type, str_varchar_one, (arr_str_size && strcmp(arr_str_size, "0") != 0) ? arr_str_size : str_arr_one, struct_sizeof, prefix, 0);
333 40 : if (ind_type != NULL)
334 40 : ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_size && strcmp(arr_str_size, "0") != 0) ? arr_str_size : str_neg_one, ind_struct_sizeof, ind_prefix, 0);
335 :
336 40 : free(str_varchar_one);
337 40 : free(str_arr_one);
338 40 : free(str_neg_one);
339 : }
340 40 : break;
341 44 : case ECPGt_descriptor:
342 : {
343 : /*
344 : * Allocate for each, as there are code-paths where the values
345 : * get stomped on.
346 : */
347 44 : char *str_neg_one = mm_strdup("-1");
348 44 : char *ind_type_neg_one = mm_strdup("-1");
349 :
350 44 : if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
351 0 : mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
352 :
353 44 : ECPGdump_a_simple(o, name, type->type, NULL, str_neg_one, NULL, prefix, 0);
354 44 : if (ind_type != NULL)
355 44 : ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, ind_type_neg_one, NULL, ind_prefix, 0);
356 :
357 44 : free(str_neg_one);
358 44 : free(ind_type_neg_one);
359 : }
360 44 : break;
361 972 : default:
362 : {
363 : /*
364 : * Allocate for each, as there are code-paths where the values
365 : * get stomped on.
366 : */
367 972 : char *str_neg_one = mm_strdup("-1");
368 972 : char *ind_type_neg_one = mm_strdup("-1");
369 :
370 972 : if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
371 0 : mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
372 :
373 972 : ECPGdump_a_simple(o, name, type->type, type->size, (arr_str_size && strcmp(arr_str_size, "0") != 0) ? arr_str_size : str_neg_one, struct_sizeof, prefix, type->counter);
374 972 : if (ind_type != NULL)
375 880 : ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_size && strcmp(arr_str_size, "0") != 0) ? arr_str_size : ind_type_neg_one, ind_struct_sizeof, ind_prefix, 0);
376 :
377 972 : free(str_neg_one);
378 972 : free(ind_type_neg_one);
379 : }
380 972 : break;
381 : }
382 1234 : }
383 :
384 :
385 : /* If size is NULL, then the offset is 0, if not use size as a
386 : string, it represents the offset needed if we are in an array of structs. */
387 : static void
388 2280 : ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
389 : char *varcharsize,
390 : char *arrsize,
391 : const char *size,
392 : const char *prefix,
393 : int counter)
394 : {
395 2280 : if (type == ECPGt_NO_INDICATOR)
396 974 : fprintf(o, "\n\tECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ");
397 1306 : else if (type == ECPGt_descriptor)
398 : /* remember that name here already contains quotes (if needed) */
399 44 : fprintf(o, "\n\tECPGt_descriptor, %s, 1L, 1L, 1L, ", name);
400 1262 : else if (type == ECPGt_sqlda)
401 50 : fprintf(o, "\n\tECPGt_sqlda, &%s, 0L, 0L, 0L, ", name);
402 : else
403 : {
404 1212 : char *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
405 1212 : char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize) + sizeof(int) * CHAR_BIT * 10 / 3);
406 : char *struct_name;
407 :
408 1212 : switch (type)
409 : {
410 : /*
411 : * we have to use the & operator except for arrays and
412 : * pointers
413 : */
414 :
415 82 : case ECPGt_varchar:
416 : case ECPGt_bytea:
417 :
418 : /*
419 : * we have to use the pointer except for arrays with given
420 : * bounds
421 : */
422 82 : if (((atoi(arrsize) > 0) ||
423 82 : (atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0)) &&
424 : size == NULL)
425 4 : sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
426 : else
427 78 : sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
428 :
429 : /*
430 : * If we created a varchar structure automatically, counter is
431 : * greater than 0.
432 : */
433 82 : if (type == ECPGt_varchar)
434 40 : struct_name = "struct varchar";
435 : else
436 42 : struct_name = "struct bytea";
437 :
438 82 : if (counter)
439 80 : sprintf(offset, "sizeof(%s_%d)", struct_name, counter);
440 : else
441 2 : sprintf(offset, "sizeof(%s)", struct_name);
442 82 : break;
443 432 : case ECPGt_char:
444 : case ECPGt_unsigned_char:
445 : case ECPGt_char_variable:
446 : case ECPGt_string:
447 : {
448 432 : char *sizeof_name = "char";
449 :
450 : /*
451 : * we have to use the pointer except for arrays with given
452 : * bounds, ecpglib will distinguish between * and []
453 : */
454 432 : if ((atoi(varcharsize) > 1 ||
455 170 : (atoi(arrsize) > 0) ||
456 118 : (atoi(varcharsize) == 0 && strcmp(varcharsize, "0") != 0) ||
457 102 : (atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0))
458 330 : && size == NULL)
459 : {
460 316 : sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
461 316 : if ((type == ECPGt_char || type == ECPGt_unsigned_char) &&
462 274 : strcmp(varcharsize, "0") == 0)
463 : {
464 : /*
465 : * If this is an array of char *, the offset would
466 : * be sizeof(char *) and not sizeof(char).
467 : */
468 0 : sizeof_name = "char *";
469 : }
470 : }
471 : else
472 116 : sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
473 :
474 432 : sprintf(offset, "(%s)*sizeof(%s)", strcmp(varcharsize, "0") == 0 ? "1" : varcharsize, sizeof_name);
475 432 : break;
476 : }
477 18 : case ECPGt_numeric:
478 :
479 : /*
480 : * we have to use a pointer here
481 : */
482 18 : sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
483 18 : sprintf(offset, "sizeof(numeric)");
484 18 : break;
485 8 : case ECPGt_interval:
486 :
487 : /*
488 : * we have to use a pointer here
489 : */
490 8 : sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
491 8 : sprintf(offset, "sizeof(interval)");
492 8 : break;
493 20 : case ECPGt_date:
494 :
495 : /*
496 : * we have to use a pointer and translate the variable type
497 : */
498 20 : sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
499 20 : sprintf(offset, "sizeof(date)");
500 20 : break;
501 26 : case ECPGt_timestamp:
502 :
503 : /*
504 : * we have to use a pointer and translate the variable type
505 : */
506 26 : sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
507 26 : sprintf(offset, "sizeof(timestamp)");
508 26 : break;
509 32 : case ECPGt_const:
510 :
511 : /*
512 : * just dump the const as string
513 : */
514 32 : sprintf(variable, "\"%s\"", name);
515 32 : sprintf(offset, "strlen(\"%s\")", name);
516 32 : break;
517 594 : default:
518 :
519 : /*
520 : * we have to use the pointer except for arrays with given
521 : * bounds
522 : */
523 594 : if (((atoi(arrsize) > 0) ||
524 594 : (atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0)) &&
525 : size == NULL)
526 36 : sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
527 : else
528 558 : sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
529 :
530 594 : sprintf(offset, "sizeof(%s)", ecpg_type_name(type));
531 594 : break;
532 : }
533 :
534 : /*
535 : * Array size would be -1 for addresses of members within structure,
536 : * when pointer to structure is being dumped.
537 : */
538 1212 : if (atoi(arrsize) < 0 && !size)
539 890 : strcpy(arrsize, "1");
540 :
541 : /*
542 : * If size i.e. the size of structure of which this variable is part
543 : * of, that gives the offset to the next element, if required
544 : */
545 1212 : if (size == NULL || strlen(size) == 0)
546 1090 : fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, offset);
547 : else
548 122 : fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, size);
549 :
550 1212 : free(variable);
551 1212 : free(offset);
552 : }
553 2280 : }
554 :
555 :
556 : /* Penetrate a struct and dump the contents. */
557 : static void
558 28 : ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsize, struct ECPGtype *type, struct ECPGtype *ind_type, const char *prefix, const char *ind_prefix)
559 : {
560 : /*
561 : * If offset is NULL, then this is the first recursive level. If not then
562 : * we are in a struct and the offset is used as offset.
563 : */
564 : struct ECPGstruct_member *p,
565 28 : *ind_p = NULL;
566 28 : char *pbuf = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 3);
567 28 : char *ind_pbuf = (char *) mm_alloc(strlen(ind_name) + ((ind_prefix == NULL) ? 0 : strlen(ind_prefix)) + 3);
568 :
569 28 : if (atoi(arrsize) == 1)
570 12 : sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
571 : else
572 16 : sprintf(pbuf, "%s%s->", prefix ? prefix : "", name);
573 :
574 28 : prefix = pbuf;
575 :
576 28 : if (ind_type == &ecpg_no_indicator)
577 4 : ind_p = &struct_no_indicator;
578 24 : else if (ind_type != NULL)
579 : {
580 24 : if (atoi(arrsize) == 1)
581 8 : sprintf(ind_pbuf, "%s%s.", ind_prefix ? ind_prefix : "", ind_name);
582 : else
583 16 : sprintf(ind_pbuf, "%s%s->", ind_prefix ? ind_prefix : "", ind_name);
584 :
585 24 : ind_prefix = ind_pbuf;
586 24 : ind_p = ind_type->u.members;
587 : }
588 :
589 100 : for (p = type->u.members; p; p = p->next)
590 : {
591 144 : ECPGdump_a_type(o, p->name, p->type, -1,
592 : (ind_p != NULL) ? ind_p->name : NULL,
593 : (ind_p != NULL) ? ind_p->type : NULL,
594 : -1,
595 72 : prefix, ind_prefix, arrsize, type->struct_sizeof,
596 : (ind_p != NULL) ? ind_type->struct_sizeof : NULL);
597 72 : if (ind_p != NULL && ind_p != &struct_no_indicator)
598 : {
599 60 : ind_p = ind_p->next;
600 60 : if (ind_p == NULL && p->next != NULL)
601 : {
602 0 : mmerror(PARSE_ERROR, ET_WARNING, "indicator struct \"%s\" has too few members", ind_name);
603 0 : ind_p = &struct_no_indicator;
604 : }
605 : }
606 : }
607 :
608 28 : if (ind_type != NULL && ind_p != NULL && ind_p != &struct_no_indicator)
609 : {
610 0 : mmerror(PARSE_ERROR, ET_WARNING, "indicator struct \"%s\" has too many members", ind_name);
611 : }
612 :
613 28 : free(pbuf);
614 28 : free(ind_pbuf);
615 28 : }
616 :
617 : void
618 238 : ECPGfree_struct_member(struct ECPGstruct_member *rm)
619 : {
620 592 : while (rm)
621 : {
622 354 : struct ECPGstruct_member *p = rm;
623 :
624 354 : rm = rm->next;
625 354 : free(p->name);
626 354 : ECPGfree_type(p->type);
627 354 : free(p);
628 : }
629 238 : }
630 :
631 : void
632 1278 : ECPGfree_type(struct ECPGtype *type)
633 : {
634 1278 : if (!IS_SIMPLE_TYPE(type->type))
635 : {
636 202 : switch (type->type)
637 : {
638 136 : case ECPGt_array:
639 136 : switch (type->u.element->type)
640 : {
641 0 : case ECPGt_array:
642 0 : base_yyerror("internal error: found multidimensional array\n");
643 0 : break;
644 26 : case ECPGt_struct:
645 : case ECPGt_union:
646 : /* Array of structs. */
647 26 : ECPGfree_type(type->u.element);
648 26 : break;
649 110 : default:
650 110 : if (!IS_SIMPLE_TYPE(type->u.element->type))
651 0 : base_yyerror("internal error: unknown datatype, please report this to <" PACKAGE_BUGREPORT ">");
652 :
653 110 : ECPGfree_type(type->u.element);
654 : }
655 136 : break;
656 66 : case ECPGt_struct:
657 : case ECPGt_union:
658 66 : ECPGfree_struct_member(type->u.members);
659 66 : break;
660 0 : default:
661 0 : mmerror(PARSE_ERROR, ET_ERROR, "unrecognized variable type code %d", type->type);
662 0 : break;
663 : }
664 1076 : }
665 1278 : free(type->type_name);
666 1278 : free(type->size);
667 1278 : free(type->struct_sizeof);
668 1278 : free(type);
669 1278 : }
670 :
671 : const char *
672 132 : get_dtype(enum ECPGdtype type)
673 : {
674 132 : switch (type)
675 : {
676 0 : case ECPGd_count:
677 0 : return "ECPGd_count";
678 : break;
679 62 : case ECPGd_data:
680 62 : return "ECPGd_data";
681 : break;
682 4 : case ECPGd_di_code:
683 4 : return "ECPGd_di_code";
684 : break;
685 0 : case ECPGd_di_precision:
686 0 : return "ECPGd_di_precision";
687 : break;
688 34 : case ECPGd_indicator:
689 34 : return "ECPGd_indicator";
690 : break;
691 0 : case ECPGd_key_member:
692 0 : return "ECPGd_key_member";
693 : break;
694 4 : case ECPGd_length:
695 4 : return "ECPGd_length";
696 : break;
697 18 : case ECPGd_name:
698 18 : return "ECPGd_name";
699 : break;
700 0 : case ECPGd_nullable:
701 0 : return "ECPGd_nullable";
702 : break;
703 2 : case ECPGd_octet:
704 2 : return "ECPGd_octet";
705 : break;
706 2 : case ECPGd_precision:
707 2 : return "ECPGd_precision";
708 : break;
709 0 : case ECPGd_ret_length:
710 0 : return "ECPGd_ret_length";
711 2 : case ECPGd_ret_octet:
712 2 : return "ECPGd_ret_octet";
713 : break;
714 2 : case ECPGd_scale:
715 2 : return "ECPGd_scale";
716 : break;
717 2 : case ECPGd_type:
718 2 : return "ECPGd_type";
719 : break;
720 0 : case ECPGd_cardinality:
721 0 : return "ECPGd_cardinality";
722 0 : default:
723 0 : mmerror(PARSE_ERROR, ET_ERROR, "unrecognized descriptor item code %d", type);
724 : }
725 :
726 0 : return NULL;
727 : }
|