PostgreSQL Source Code git master
Loading...
Searching...
No Matches
type.c File Reference
#include "postgres_fe.h"
#include "preproc_extern.h"
Include dependency graph for type.c:

Go to the source code of this file.

Macros

#define indicator_set   ind_type != NULL && ind_type->type != ECPGt_NO_INDICATOR
 

Functions

struct ECPGstruct_memberECPGstruct_member_dup (struct ECPGstruct_member *rm)
 
void ECPGmake_struct_member (const char *name, struct ECPGtype *type, struct ECPGstruct_member **start)
 
struct ECPGtypeECPGmake_simple_type (enum ECPGttype type, const char *size, int counter)
 
struct ECPGtypeECPGmake_array_type (struct ECPGtype *type, const char *size)
 
struct ECPGtypeECPGmake_struct_type (struct ECPGstruct_member *rm, enum ECPGttype type, const char *type_name, const char *struct_sizeof)
 
static const charget_type (enum ECPGttype type)
 
static void ECPGdump_a_simple (FILE *o, const char *name, enum ECPGttype type, char *varcharsize, char *arrsize, const char *size, const char *prefix, int counter)
 
static void 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)
 
void ECPGdump_a_type (FILE *o, const char *name, struct ECPGtype *type, const int brace_level, const char *ind_name, struct ECPGtype *ind_type, const int ind_brace_level, const char *prefix, const char *ind_prefix, char *arr_str_size, const char *struct_sizeof, const char *ind_struct_sizeof)
 
void ECPGfree_struct_member (struct ECPGstruct_member *rm)
 
void ECPGfree_type (struct ECPGtype *type)
 
const charget_dtype (enum ECPGdtype type)
 

Variables

static struct ECPGstruct_member struct_no_indicator = {"no_indicator", &ecpg_no_indicator, NULL}
 

Macro Definition Documentation

◆ indicator_set

#define indicator_set   ind_type != NULL && ind_type->type != ECPGt_NO_INDICATOR

Definition at line 7 of file type.c.

Function Documentation

◆ ECPGdump_a_simple()

static void ECPGdump_a_simple ( FILE o,
const char name,
enum ECPGttype  type,
char varcharsize,
char arrsize,
const char size,
const char prefix,
int  counter 
)
static

Definition at line 391 of file type.c.

397{
399 fprintf(o, "\n\tECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ");
400 else if (type == ECPGt_descriptor)
401 /* remember that name here already contains quotes (if needed) */
402 fprintf(o, "\n\tECPGt_descriptor, %s, 1L, 1L, 1L, ", name);
403 else if (type == ECPGt_sqlda)
404 fprintf(o, "\n\tECPGt_sqlda, &%s, 0L, 0L, 0L, ", name);
405 else
406 {
407 char *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
408 char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize) + sizeof(int) * CHAR_BIT * 10 / 3);
409 char *struct_name;
410
411 switch (type)
412 {
413 /*
414 * we have to use the & operator except for arrays and
415 * pointers
416 */
417
418 case ECPGt_varchar:
419 case ECPGt_bytea:
420
421 /*
422 * we have to use the pointer except for arrays with given
423 * bounds
424 */
425 if (((atoi(arrsize) > 0) ||
426 (atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0)) &&
427 size == NULL)
428 sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
429 else
430 sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
431
432 /*
433 * If we created a varchar structure automatically, counter is
434 * greater than 0.
435 */
436 if (type == ECPGt_varchar)
437 struct_name = "struct varchar";
438 else
439 struct_name = "struct bytea";
440
441 if (counter)
442 sprintf(offset, "sizeof(%s_%d)", struct_name, counter);
443 else
444 sprintf(offset, "sizeof(%s)", struct_name);
445 break;
446 case ECPGt_char:
449 case ECPGt_string:
450 {
451 char *sizeof_name = "char";
452
453 /*
454 * we have to use the pointer except for arrays with given
455 * bounds, ecpglib will distinguish between * and []
456 */
457 if ((atoi(varcharsize) > 1 ||
458 (atoi(arrsize) > 0) ||
459 (atoi(varcharsize) == 0 && strcmp(varcharsize, "0") != 0) ||
460 (atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0))
461 && size == NULL)
462 {
463 sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
464 if ((type == ECPGt_char || type == ECPGt_unsigned_char) &&
465 strcmp(varcharsize, "0") == 0)
466 {
467 /*
468 * If this is an array of char *, the offset would
469 * be sizeof(char *) and not sizeof(char).
470 */
471 sizeof_name = "char *";
472 }
473 }
474 else
475 sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
476
477 sprintf(offset, "(%s)*sizeof(%s)", strcmp(varcharsize, "0") == 0 ? "1" : varcharsize, sizeof_name);
478 break;
479 }
480 case ECPGt_numeric:
481
482 /*
483 * we have to use a pointer here
484 */
485 sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
486 sprintf(offset, "sizeof(numeric)");
487 break;
488 case ECPGt_interval:
489
490 /*
491 * we have to use a pointer here
492 */
493 sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
494 sprintf(offset, "sizeof(interval)");
495 break;
496 case ECPGt_date:
497
498 /*
499 * we have to use a pointer and translate the variable type
500 */
501 sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
502 sprintf(offset, "sizeof(date)");
503 break;
504 case ECPGt_timestamp:
505
506 /*
507 * we have to use a pointer and translate the variable type
508 */
509 sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
510 sprintf(offset, "sizeof(timestamp)");
511 break;
512 case ECPGt_const:
513
514 /*
515 * just dump the const as string
516 */
517 sprintf(variable, "\"%s\"", name);
518 sprintf(offset, "strlen(\"%s\")", name);
519 break;
520 default:
521
522 /*
523 * we have to use the pointer except for arrays with given
524 * bounds
525 */
526 if (((atoi(arrsize) > 0) ||
527 (atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0)) &&
528 size == NULL)
529 sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
530 else
531 sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
532
533 sprintf(offset, "sizeof(%s)", ecpg_type_name(type));
534 break;
535 }
536
537 /*
538 * Array size would be -1 for addresses of members within structure,
539 * when pointer to structure is being dumped.
540 */
541 if (atoi(arrsize) < 0 && !size)
542 strcpy(arrsize, "1");
543
544 /*
545 * If size i.e. the size of structure of which this variable is part
546 * of, that gives the offset to the next element, if required
547 */
548 if (size == NULL || strlen(size) == 0)
549 fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, offset);
550 else
551 fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, size);
552
553 free(variable);
554 free(offset);
555 }
556}
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
const char * ecpg_type_name(enum ECPGttype typ)
Definition typename.c:17
@ ECPGt_sqlda
Definition ecpgtype.h:66
@ ECPGt_char_variable
Definition ecpgtype.h:60
@ ECPGt_bytea
Definition ecpgtype.h:67
@ ECPGt_numeric
Definition ecpgtype.h:49
@ ECPGt_varchar
Definition ecpgtype.h:48
@ ECPGt_timestamp
Definition ecpgtype.h:54
@ ECPGt_unsigned_char
Definition ecpgtype.h:43
@ ECPGt_NO_INDICATOR
Definition ecpgtype.h:64
@ ECPGt_date
Definition ecpgtype.h:53
@ ECPGt_interval
Definition ecpgtype.h:55
@ ECPGt_const
Definition ecpgtype.h:61
@ ECPGt_descriptor
Definition ecpgtype.h:59
@ ECPGt_char
Definition ecpgtype.h:43
@ ECPGt_string
Definition ecpgtype.h:65
#define sprintf
Definition port.h:263
static int fb(int x)
void * mm_alloc(size_t size)
Definition util.c:85
#define free(a)
static const char * get_type(enum ECPGttype type)
Definition type.c:110
const char * type
const char * name

References variable::arrsize, ecpg_type_name(), ECPGt_bytea, ECPGt_char, ECPGt_char_variable, ECPGt_const, ECPGt_date, ECPGt_descriptor, ECPGt_interval, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGt_sqlda, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_varchar, fb(), fprintf, free, get_type(), mm_alloc(), name, variable::offset, sprintf, type, and variable::varcharsize.

Referenced by ECPGdump_a_type().

◆ ECPGdump_a_struct()

static void 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 
)
static

Definition at line 561 of file type.c.

562{
563 /*
564 * If offset is NULL, then this is the first recursive level. If not then
565 * we are in a struct and the offset is used as offset.
566 */
567 struct ECPGstruct_member *p,
568 *ind_p = NULL;
569 char *pbuf = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 3);
570 char *ind_pbuf = (char *) mm_alloc(strlen(ind_name) + ((ind_prefix == NULL) ? 0 : strlen(ind_prefix)) + 3);
571
572 if (atoi(arrsize) == 1)
573 sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
574 else
575 sprintf(pbuf, "%s%s->", prefix ? prefix : "", name);
576
577 prefix = pbuf;
578
579 if (ind_type == &ecpg_no_indicator)
581 else if (ind_type != NULL)
582 {
583 if (atoi(arrsize) == 1)
584 sprintf(ind_pbuf, "%s%s.", ind_prefix ? ind_prefix : "", ind_name);
585 else
586 sprintf(ind_pbuf, "%s%s->", ind_prefix ? ind_prefix : "", ind_name);
587
589 ind_p = ind_type->u.members;
590 }
591
592 for (p = type->u.members; p; p = p->next)
593 {
594 ECPGdump_a_type(o, p->name, p->type, -1,
595 (ind_p != NULL) ? ind_p->name : NULL,
596 (ind_p != NULL) ? ind_p->type : NULL,
597 -1,
598 prefix, ind_prefix, arrsize, type->struct_sizeof,
599 (ind_p != NULL) ? ind_type->struct_sizeof : NULL);
600 if (ind_p != NULL && ind_p != &struct_no_indicator)
601 {
602 ind_p = ind_p->next;
603 if (ind_p == NULL && p->next != NULL)
604 {
605 mmerror(PARSE_ERROR, ET_WARNING, "indicator struct \"%s\" has too few members", ind_name);
607 }
608 }
609 }
610
611 if (ind_type != NULL && ind_p != NULL && ind_p != &struct_no_indicator)
612 {
613 mmerror(PARSE_ERROR, ET_WARNING, "indicator struct \"%s\" has too many members", ind_name);
614 }
615
616 free(pbuf);
617 free(ind_pbuf);
618}
void mmerror(int error_code, enum errortype type, const char *error,...) pg_attribute_printf(3
#define PARSE_ERROR
struct ECPGtype ecpg_no_indicator
char * name
Definition type.h:12
struct ECPGtype * type
Definition type.h:13
struct ECPGstruct_member * next
Definition type.h:14
union ECPGtype::@181 u
struct ECPGstruct_member * members
Definition type.h:30
void ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype *type, const int brace_level, const char *ind_name, struct ECPGtype *ind_type, const int ind_brace_level, const char *prefix, const char *ind_prefix, char *arr_str_size, const char *struct_sizeof, const char *ind_struct_sizeof)
Definition type.c:219
static struct ECPGstruct_member struct_no_indicator
Definition type.c:9
@ ET_WARNING
Definition type.h:221

References ecpg_no_indicator, ECPGdump_a_type(), ET_WARNING, fb(), free, ECPGtype::members, mm_alloc(), mmerror(), name, ECPGstruct_member::name, ECPGstruct_member::next, PARSE_ERROR, sprintf, struct_no_indicator, ECPGtype::struct_sizeof, type, ECPGstruct_member::type, and ECPGtype::u.

Referenced by ECPGdump_a_type().

◆ ECPGdump_a_type()

void ECPGdump_a_type ( FILE o,
const char name,
struct ECPGtype type,
const int  brace_level,
const char ind_name,
struct ECPGtype ind_type,
const int  ind_brace_level,
const char prefix,
const char ind_prefix,
char arr_str_size,
const char struct_sizeof,
const char ind_struct_sizeof 
)

Definition at line 219 of file type.c.

224{
225 struct variable *var;
226
227 if (type->type != ECPGt_descriptor && type->type != ECPGt_sqlda &&
228 type->type != ECPGt_char_variable && type->type != ECPGt_const &&
229 brace_level >= 0)
230 {
231 char *str;
232
233 str = mm_strdup(name);
234 var = find_variable(str);
235 free(str);
236
237 if ((var->type->type != type->type) ||
238 (var->type->type_name && !type->type_name) ||
239 (!var->type->type_name && type->type_name) ||
240 (var->type->type_name && type->type_name && strcmp(var->type->type_name, type->type_name) != 0))
241 mmerror(PARSE_ERROR, ET_ERROR, "variable \"%s\" is hidden by a local variable of a different type", name);
242 else if (var->brace_level != brace_level)
243 mmerror(PARSE_ERROR, ET_WARNING, "variable \"%s\" is hidden by a local variable", name);
244
246 {
248 var = find_variable(str);
249 free(str);
250
251 if ((var->type->type != ind_type->type) ||
252 (var->type->type_name && !ind_type->type_name) ||
253 (!var->type->type_name && ind_type->type_name) ||
254 (var->type->type_name && ind_type->type_name && strcmp(var->type->type_name, ind_type->type_name) != 0))
255 mmerror(PARSE_ERROR, ET_ERROR, "indicator variable \"%s\" is hidden by a local variable of a different type", ind_name);
256 else if (var->brace_level != ind_brace_level)
257 mmerror(PARSE_ERROR, ET_WARNING, "indicator variable \"%s\" is hidden by a local variable", ind_name);
258 }
259 }
260
261 switch (type->type)
262 {
263 case ECPGt_array:
264 if (indicator_set && ind_type->type != ECPGt_array)
265 mmfatal(INDICATOR_NOT_ARRAY, "indicator for array/pointer has to be array/pointer");
266 switch (type->u.element->type)
267 {
268 case ECPGt_array:
269 mmerror(PARSE_ERROR, ET_ERROR, "nested arrays are not supported (except strings)"); /* array of array */
270 break;
271 case ECPGt_struct:
272 case ECPGt_union:
274 ind_name,
275 type->size,
276 type->u.element,
278 prefix, ind_prefix);
279 break;
280 default:
281 if (!IS_SIMPLE_TYPE(type->u.element->type))
282 base_yyerror("internal error: unknown datatype, please report this to <" PACKAGE_BUGREPORT ">");
283
285 type->u.element->type,
286 type->u.element->size, type->size, struct_sizeof ? struct_sizeof : NULL,
287 prefix, type->u.element->counter);
288
289 if (ind_type != NULL)
290 {
291 if (ind_type->type == ECPGt_NO_INDICATOR)
292 {
293 char *str_neg_one = mm_strdup("-1");
294
297 }
298 else
299 {
300 ECPGdump_a_simple(o, ind_name, ind_type->u.element->type,
301 ind_type->u.element->size, ind_type->size, NULL, ind_prefix, 0);
302 }
303 }
304 }
305 break;
306 case ECPGt_struct:
307 {
308 char *str_one = mm_strdup("1");
309
310 if (indicator_set && ind_type->type != ECPGt_struct)
311 mmfatal(INDICATOR_NOT_STRUCT, "indicator for struct has to be a struct");
312
314 free(str_one);
315 }
316 break;
317 case ECPGt_union: /* cannot dump a complete union */
318 base_yyerror("type of union has to be specified");
319 break;
321 {
322 /*
323 * Allocate for each, as there are code-paths where the values
324 * get stomped on.
325 */
326 char *str_varchar_one = mm_strdup("1");
327 char *str_arr_one = mm_strdup("1");
328 char *str_neg_one = mm_strdup("-1");
329
330 if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
331 mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
332
333 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);
334 if (ind_type != NULL)
336
340 }
341 break;
342 case ECPGt_descriptor:
343 {
344 /*
345 * Allocate for each, as there are code-paths where the values
346 * get stomped on.
347 */
348 char *str_neg_one = mm_strdup("-1");
349 char *ind_type_neg_one = mm_strdup("-1");
350
351 if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
352 mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
353
354 ECPGdump_a_simple(o, name, type->type, NULL, str_neg_one, NULL, prefix, 0);
355 if (ind_type != NULL)
357
360 }
361 break;
362 default:
363 {
364 /*
365 * Allocate for each, as there are code-paths where the values
366 * get stomped on.
367 */
368 char *str_neg_one = mm_strdup("-1");
369 char *ind_type_neg_one = mm_strdup("-1");
370
371 if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
372 mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
373
374 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);
375 if (ind_type != NULL)
377
380 }
381 break;
382 }
383}
@ ECPGt_union
Definition ecpgtype.h:58
@ ECPGt_struct
Definition ecpgtype.h:57
@ ECPGt_array
Definition ecpgtype.h:56
#define IS_SIMPLE_TYPE(type)
Definition ecpgtype.h:92
const char * str
char * mm_strdup(const char *string)
Definition util.c:97
void base_yyerror(const char *error)
void pg_noreturn void mmfatal(int error_code, const char *error,...) pg_attribute_printf(2
#define INDICATOR_NOT_SIMPLE
#define INDICATOR_NOT_STRUCT
#define INDICATOR_NOT_ARRAY
struct variable * find_variable(const char *name)
Definition variable.c:235
static chr element(struct vars *v, const chr *startp, const chr *endp)
enum ECPGttype type
int brace_level
Definition type.h:194
enum ECPGttype ind_type
static void 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)
Definition type.c:561
static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, char *varcharsize, char *arrsize, const char *size, const char *prefix, int counter)
Definition type.c:391
#define indicator_set
Definition type.c:7
@ ET_ERROR
Definition type.h:221

References base_yyerror(), variable::brace_level, ECPGdump_a_simple(), ECPGdump_a_struct(), ECPGt_array, ECPGt_char_variable, ECPGt_const, ECPGt_descriptor, ECPGt_NO_INDICATOR, ECPGt_sqlda, ECPGt_struct, ECPGt_union, ET_ERROR, ET_WARNING, fb(), find_variable(), free, variable::ind_type, INDICATOR_NOT_ARRAY, INDICATOR_NOT_SIMPLE, INDICATOR_NOT_STRUCT, indicator_set, IS_SIMPLE_TYPE, mm_strdup(), mmerror(), mmfatal(), name, PARSE_ERROR, str, type, and variable::type.

Referenced by dump_variables(), ECPGdump_a_struct(), output_get_descr(), and output_set_descr().

◆ ECPGfree_struct_member()

void ECPGfree_struct_member ( struct ECPGstruct_member rm)

Definition at line 621 of file type.c.

622{
623 while (rm)
624 {
625 struct ECPGstruct_member *p = rm;
626
627 rm = rm->next;
628 free(p->name);
630 free(p);
631 }
632}
void ECPGfree_type(struct ECPGtype *type)
Definition type.c:635

References ECPGfree_type(), free, ECPGstruct_member::name, ECPGstruct_member::next, and ECPGstruct_member::type.

Referenced by ECPGfree_type(), main(), and remove_typedefs().

◆ ECPGfree_type()

void ECPGfree_type ( struct ECPGtype type)

Definition at line 635 of file type.c.

636{
637 if (!IS_SIMPLE_TYPE(type->type))
638 {
639 switch (type->type)
640 {
641 case ECPGt_array:
642 switch (type->u.element->type)
643 {
644 case ECPGt_array:
645 base_yyerror("internal error: found multidimensional array\n");
646 break;
647 case ECPGt_struct:
648 case ECPGt_union:
649 /* Array of structs. */
650 ECPGfree_type(type->u.element);
651 break;
652 default:
653 if (!IS_SIMPLE_TYPE(type->u.element->type))
654 base_yyerror("internal error: unknown datatype, please report this to <" PACKAGE_BUGREPORT ">");
655
656 ECPGfree_type(type->u.element);
657 }
658 break;
659 case ECPGt_struct:
660 case ECPGt_union:
661 ECPGfree_struct_member(type->u.members);
662 break;
663 default:
664 mmerror(PARSE_ERROR, ET_ERROR, "unrecognized variable type code %d", type->type);
665 break;
666 }
667 }
668 free(type->type_name);
669 free(type->size);
670 free(type->struct_sizeof);
671 free(type);
672}
void ECPGfree_struct_member(struct ECPGstruct_member *rm)
Definition type.c:621

References base_yyerror(), ECPGfree_struct_member(), ECPGfree_type(), ECPGt_array, ECPGt_struct, ECPGt_union, ET_ERROR, fb(), free, IS_SIMPLE_TYPE, mmerror(), PARSE_ERROR, and type.

Referenced by ECPGfree_struct_member(), ECPGfree_type(), and remove_variables().

◆ ECPGmake_array_type()

struct ECPGtype * ECPGmake_array_type ( struct ECPGtype type,
const char size 
)

Definition at line 87 of file type.c.

88{
90
91 ne->u.element = type;
92
93 return ne;
94}
char * size
Definition type.h:22
struct ECPGtype * ECPGmake_simple_type(enum ECPGttype type, const char *size, int counter)
Definition type.c:72

References ECPGmake_simple_type(), ECPGt_array, fb(), ECPGtype::size, and type.

Referenced by ECPGstruct_member_dup(), find_struct_member(), and find_variable().

◆ ECPGmake_simple_type()

struct ECPGtype * ECPGmake_simple_type ( enum ECPGttype  type,
const char size,
int  counter 
)

Definition at line 72 of file type.c.

73{
74 struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
75
76 ne->type = type;
77 ne->type_name = NULL;
78 ne->size = mm_strdup(size);
79 ne->u.element = NULL;
80 ne->struct_sizeof = NULL;
81 ne->counter = counter; /* only needed for varchar and bytea */
82
83 return ne;
84}
enum ECPGttype type
Definition type.h:19
int counter
Definition type.h:32

References ECPGtype::counter, fb(), mm_alloc(), mm_strdup(), ECPGtype::size, type, and ECPGtype::type.

Referenced by ECPGmake_array_type(), ECPGmake_struct_type(), ECPGstruct_member_dup(), find_struct_member(), and find_variable().

◆ ECPGmake_struct_member()

void ECPGmake_struct_member ( const char name,
struct ECPGtype type,
struct ECPGstruct_member **  start 
)

Definition at line 53 of file type.c.

54{
55 struct ECPGstruct_member *ptr,
56 *ne =
57 (struct ECPGstruct_member *) mm_alloc(sizeof(struct ECPGstruct_member));
58
60 ne->type = type;
61 ne->next = NULL;
62
63 for (ptr = *start; ptr && ptr->next; ptr = ptr->next);
64
65 if (ptr)
66 ptr->next = ne;
67 else
68 *start = ne;
69}
return str start

References fb(), mm_alloc(), mm_strdup(), name, ECPGstruct_member::name, ECPGstruct_member::next, start, and type.

Referenced by ECPGstruct_member_dup().

◆ ECPGmake_struct_type()

struct ECPGtype * ECPGmake_struct_type ( struct ECPGstruct_member rm,
enum ECPGttype  type,
const char type_name,
const char struct_sizeof 
)

Definition at line 97 of file type.c.

99{
100 struct ECPGtype *ne = ECPGmake_simple_type(type, "1", 0);
101
102 ne->type_name = mm_strdup(type_name);
103 ne->u.members = ECPGstruct_member_dup(rm);
104 ne->struct_sizeof = mm_strdup(struct_sizeof);
105
106 return ne;
107}
char * type_name
Definition type.h:20
char * struct_sizeof
Definition type.h:24
struct ECPGstruct_member * ECPGstruct_member_dup(struct ECPGstruct_member *rm)
Definition type.c:13

References ECPGmake_simple_type(), ECPGstruct_member_dup(), fb(), mm_strdup(), ECPGtype::struct_sizeof, type, and ECPGtype::type_name.

Referenced by ECPGstruct_member_dup(), find_struct_member(), and find_variable().

◆ ECPGstruct_member_dup()

struct ECPGstruct_member * ECPGstruct_member_dup ( struct ECPGstruct_member rm)

Definition at line 13 of file type.c.

14{
15 struct ECPGstruct_member *new = NULL;
16
17 while (rm)
18 {
19 struct ECPGtype *type;
20
21 switch (rm->type->type)
22 {
23 case ECPGt_struct:
24 case ECPGt_union:
26 break;
27 case ECPGt_array:
28
29 /*
30 * if this array does contain a struct again, we have to
31 * create the struct too
32 */
33 if (rm->type->u.element->type == ECPGt_struct || rm->type->u.element->type == ECPGt_union)
35 else
37 break;
38 default:
40 break;
41 }
42
44
45 rm = rm->next;
46 }
47
48 return new;
49}
struct ECPGtype * element
Definition type.h:28
void ECPGmake_struct_member(const char *name, struct ECPGtype *type, struct ECPGstruct_member **start)
Definition type.c:53
struct ECPGtype * ECPGmake_array_type(struct ECPGtype *type, const char *size)
Definition type.c:87
struct ECPGtype * ECPGmake_struct_type(struct ECPGstruct_member *rm, enum ECPGttype type, const char *type_name, const char *struct_sizeof)
Definition type.c:97

References ECPGtype::counter, ECPGmake_array_type(), ECPGmake_simple_type(), ECPGmake_struct_member(), ECPGmake_struct_type(), ECPGt_array, ECPGt_struct, ECPGt_union, ECPGtype::element, fb(), ECPGtype::members, ECPGstruct_member::name, ECPGstruct_member::next, ECPGtype::size, ECPGtype::struct_sizeof, type, ECPGstruct_member::type, ECPGtype::type, ECPGtype::type_name, and ECPGtype::u.

Referenced by ECPGmake_struct_type().

◆ get_dtype()

const char * get_dtype ( enum ECPGdtype  type)

Definition at line 675 of file type.c.

676{
677 switch (type)
678 {
679 case ECPGd_count:
680 return "ECPGd_count";
681 break;
682 case ECPGd_data:
683 return "ECPGd_data";
684 break;
685 case ECPGd_di_code:
686 return "ECPGd_di_code";
687 break;
689 return "ECPGd_di_precision";
690 break;
691 case ECPGd_indicator:
692 return "ECPGd_indicator";
693 break;
694 case ECPGd_key_member:
695 return "ECPGd_key_member";
696 break;
697 case ECPGd_length:
698 return "ECPGd_length";
699 break;
700 case ECPGd_name:
701 return "ECPGd_name";
702 break;
703 case ECPGd_nullable:
704 return "ECPGd_nullable";
705 break;
706 case ECPGd_octet:
707 return "ECPGd_octet";
708 break;
709 case ECPGd_precision:
710 return "ECPGd_precision";
711 break;
712 case ECPGd_ret_length:
713 return "ECPGd_ret_length";
714 case ECPGd_ret_octet:
715 return "ECPGd_ret_octet";
716 break;
717 case ECPGd_scale:
718 return "ECPGd_scale";
719 break;
720 case ECPGd_type:
721 return "ECPGd_type";
722 break;
724 return "ECPGd_cardinality";
725 default:
726 mmerror(PARSE_ERROR, ET_ERROR, "unrecognized descriptor item code %d", type);
727 }
728
729 return NULL;
730}
@ ECPGd_scale
Definition ecpgtype.h:86
@ ECPGd_precision
Definition ecpgtype.h:83
@ ECPGd_length
Definition ecpgtype.h:79
@ ECPGd_nullable
Definition ecpgtype.h:81
@ ECPGd_di_precision
Definition ecpgtype.h:76
@ ECPGd_type
Definition ecpgtype.h:87
@ ECPGd_cardinality
Definition ecpgtype.h:89
@ ECPGd_indicator
Definition ecpgtype.h:77
@ ECPGd_ret_length
Definition ecpgtype.h:84
@ ECPGd_di_code
Definition ecpgtype.h:75
@ ECPGd_count
Definition ecpgtype.h:73
@ ECPGd_name
Definition ecpgtype.h:80
@ ECPGd_key_member
Definition ecpgtype.h:78
@ ECPGd_octet
Definition ecpgtype.h:82
@ ECPGd_ret_octet
Definition ecpgtype.h:85
@ ECPGd_data
Definition ecpgtype.h:74

References ECPGd_cardinality, ECPGd_count, ECPGd_data, ECPGd_di_code, ECPGd_di_precision, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ET_ERROR, fb(), mmerror(), PARSE_ERROR, and type.

Referenced by output_get_descr(), and output_set_descr().

◆ get_type()

static const char * get_type ( enum ECPGttype  type)
static

Definition at line 110 of file type.c.

111{
112 switch (type)
113 {
114 case ECPGt_char:
115 return "ECPGt_char";
116 break;
118 return "ECPGt_unsigned_char";
119 break;
120 case ECPGt_short:
121 return "ECPGt_short";
122 break;
124 return "ECPGt_unsigned_short";
125 break;
126 case ECPGt_int:
127 return "ECPGt_int";
128 break;
130 return "ECPGt_unsigned_int";
131 break;
132 case ECPGt_long:
133 return "ECPGt_long";
134 break;
136 return "ECPGt_unsigned_long";
137 break;
138 case ECPGt_long_long:
139 return "ECPGt_long_long";
140 break;
142 return "ECPGt_unsigned_long_long";
143 break;
144 case ECPGt_float:
145 return "ECPGt_float";
146 break;
147 case ECPGt_double:
148 return "ECPGt_double";
149 break;
150 case ECPGt_bool:
151 return "ECPGt_bool";
152 break;
153 case ECPGt_varchar:
154 return "ECPGt_varchar";
155 case ECPGt_bytea:
156 return "ECPGt_bytea";
157 case ECPGt_NO_INDICATOR: /* no indicator */
158 return "ECPGt_NO_INDICATOR";
159 break;
160 case ECPGt_char_variable: /* string that should not be quoted */
161 return "ECPGt_char_variable";
162 break;
163 case ECPGt_const: /* constant string quoted */
164 return "ECPGt_const";
165 break;
166 case ECPGt_decimal:
167 return "ECPGt_decimal";
168 break;
169 case ECPGt_numeric:
170 return "ECPGt_numeric";
171 break;
172 case ECPGt_interval:
173 return "ECPGt_interval";
174 break;
175 case ECPGt_descriptor:
176 return "ECPGt_descriptor";
177 break;
178 case ECPGt_sqlda:
179 return "ECPGt_sqlda";
180 break;
181 case ECPGt_date:
182 return "ECPGt_date";
183 break;
184 case ECPGt_timestamp:
185 return "ECPGt_timestamp";
186 break;
187 case ECPGt_string:
188 return "ECPGt_string";
189 break;
190 default:
191 mmerror(PARSE_ERROR, ET_ERROR, "unrecognized variable type code %d", type);
192 }
193
194 return NULL;
195}
@ ECPGt_float
Definition ecpgtype.h:47
@ ECPGt_long_long
Definition ecpgtype.h:45
@ ECPGt_short
Definition ecpgtype.h:43
@ ECPGt_decimal
Definition ecpgtype.h:51
@ ECPGt_unsigned_short
Definition ecpgtype.h:43
@ ECPGt_int
Definition ecpgtype.h:44
@ ECPGt_long
Definition ecpgtype.h:44
@ ECPGt_double
Definition ecpgtype.h:47
@ ECPGt_unsigned_long
Definition ecpgtype.h:44
@ ECPGt_bool
Definition ecpgtype.h:46
@ ECPGt_unsigned_long_long
Definition ecpgtype.h:45
@ ECPGt_unsigned_int
Definition ecpgtype.h:44

References ECPGt_bool, ECPGt_bytea, ECPGt_char, ECPGt_char_variable, ECPGt_const, ECPGt_date, ECPGt_decimal, ECPGt_descriptor, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGt_short, ECPGt_sqlda, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, ECPGt_varchar, ET_ERROR, fb(), mmerror(), PARSE_ERROR, and type.

Referenced by ECPGdump_a_simple().

Variable Documentation

◆ struct_no_indicator

struct ECPGstruct_member struct_no_indicator = {"no_indicator", &ecpg_no_indicator, NULL}
static

Definition at line 9 of file type.c.

9{"no_indicator", &ecpg_no_indicator, NULL};

Referenced by ECPGdump_a_struct().