PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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, char *type_name, char *struct_sizeof)
 
static const char * get_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 char * get_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 387 of file type.c.

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

558 {
559  /*
560  * If offset is NULL, then this is the first recursive level. If not then
561  * we are in a struct and the offset is used as offset.
562  */
563  struct ECPGstruct_member *p,
564  *ind_p = NULL;
565  char *pbuf = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 3);
566  char *ind_pbuf = (char *) mm_alloc(strlen(ind_name) + ((ind_prefix == NULL) ? 0 : strlen(ind_prefix)) + 3);
567 
568  if (atoi(arrsize) == 1)
569  sprintf(pbuf, "%s%s.", prefix ? prefix : "", name);
570  else
571  sprintf(pbuf, "%s%s->", prefix ? prefix : "", name);
572 
573  prefix = pbuf;
574 
575  if (ind_type == &ecpg_no_indicator)
576  ind_p = &struct_no_indicator;
577  else if (ind_type != NULL)
578  {
579  if (atoi(arrsize) == 1)
580  sprintf(ind_pbuf, "%s%s.", ind_prefix ? ind_prefix : "", ind_name);
581  else
582  sprintf(ind_pbuf, "%s%s->", ind_prefix ? ind_prefix : "", ind_name);
583 
584  ind_prefix = ind_pbuf;
585  ind_p = ind_type->u.members;
586  }
587 
588  for (p = type->u.members; p; p = p->next)
589  {
590  ECPGdump_a_type(o, p->name, p->type, -1,
591  (ind_p != NULL) ? ind_p->name : NULL,
592  (ind_p != NULL) ? ind_p->type : NULL,
593  -1,
594  prefix, ind_prefix, arrsize, type->struct_sizeof,
595  (ind_p != NULL) ? ind_type->struct_sizeof : NULL);
596  if (ind_p != NULL && ind_p != &struct_no_indicator)
597  {
598  ind_p = ind_p->next;
599  if (ind_p == NULL && p->next != NULL)
600  {
601  mmerror(PARSE_ERROR, ET_WARNING, "indicator struct \"%s\" has too few members", ind_name);
602  ind_p = &struct_no_indicator;
603  }
604  }
605  }
606 
607  if (ind_type != NULL && ind_p != NULL && ind_p != &struct_no_indicator)
608  {
609  mmerror(PARSE_ERROR, ET_WARNING, "indicator struct \"%s\" has too many members", ind_name);
610  }
611 
612  free(pbuf);
613  free(ind_pbuf);
614 }
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::@164 u
char * struct_sizeof
Definition: type.h:24
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:217
static struct ECPGstruct_member struct_no_indicator
Definition: type.c:9
@ ET_WARNING
Definition: type.h:219

References ecpg_no_indicator, ECPGdump_a_type(), ET_WARNING, 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 217 of file type.c.

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

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, 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 617 of file type.c.

618 {
619  while (rm)
620  {
621  struct ECPGstruct_member *p = rm;
622 
623  rm = rm->next;
624  free(p->name);
625  free(p->type);
626  free(p);
627  }
628 }

References free, ECPGstruct_member::name, ECPGstruct_member::next, and ECPGstruct_member::type.

Referenced by ECPGfree_type(), and main().

◆ ECPGfree_type()

void ECPGfree_type ( struct ECPGtype type)

Definition at line 631 of file type.c.

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

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

Referenced by 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 }
Definition: type.h:18
struct ECPGtype * element
Definition: type.h:28
struct ECPGtype * ECPGmake_simple_type(enum ECPGttype type, const char *size, int counter)
Definition: type.c:72

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

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 }
char * type_name
Definition: type.h:20
enum ECPGttype type
Definition: type.h:19
char * size
Definition: type.h:22
int counter
Definition: type.h:32

References ECPGtype::counter, ECPGtype::element, mm_alloc(), mm_strdup(), size, ECPGtype::size, ECPGtype::struct_sizeof, type, ECPGtype::type, ECPGtype::type_name, and ECPGtype::u.

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 
59  ne->name = mm_strdup(name);
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 mm_alloc(), mm_strdup(), name, ECPGstruct_member::name, ECPGstruct_member::next, start, type, and ECPGstruct_member::type.

Referenced by ECPGstruct_member_dup().

◆ ECPGmake_struct_type()

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

Definition at line 97 of file type.c.

98 {
99  struct ECPGtype *ne = ECPGmake_simple_type(type, "1", 0);
100 
102  ne->u.members = ECPGstruct_member_dup(rm);
104 
105  return ne;
106 }
struct ECPGstruct_member * ECPGstruct_member_dup(struct ECPGstruct_member *rm)
Definition: type.c:13

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

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:
39  type = ECPGmake_simple_type(rm->type->type, rm->type->size, rm->type->counter);
40  break;
41  }
42 
43  ECPGmake_struct_member(rm->name, type, &new);
44 
45  rm = rm->next;
46  }
47 
48  return new;
49 }
void ECPGmake_struct_member(const char *name, struct ECPGtype *type, struct ECPGstruct_member **start)
Definition: type.c:53
struct ECPGtype * ECPGmake_struct_type(struct ECPGstruct_member *rm, enum ECPGttype type, char *type_name, char *struct_sizeof)
Definition: type.c:97
struct ECPGtype * ECPGmake_array_type(struct ECPGtype *type, const char *size)
Definition: type.c:87

References ECPGtype::counter, ECPGmake_array_type(), ECPGmake_simple_type(), ECPGmake_struct_member(), ECPGmake_struct_type(), ECPGt_array, ECPGt_struct, ECPGt_union, ECPGtype::element, 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 669 of file type.c.

670 {
671  switch (type)
672  {
673  case ECPGd_count:
674  return "ECPGd_count";
675  break;
676  case ECPGd_data:
677  return "ECPGd_data";
678  break;
679  case ECPGd_di_code:
680  return "ECPGd_di_code";
681  break;
682  case ECPGd_di_precision:
683  return "ECPGd_di_precision";
684  break;
685  case ECPGd_indicator:
686  return "ECPGd_indicator";
687  break;
688  case ECPGd_key_member:
689  return "ECPGd_key_member";
690  break;
691  case ECPGd_length:
692  return "ECPGd_length";
693  break;
694  case ECPGd_name:
695  return "ECPGd_name";
696  break;
697  case ECPGd_nullable:
698  return "ECPGd_nullable";
699  break;
700  case ECPGd_octet:
701  return "ECPGd_octet";
702  break;
703  case ECPGd_precision:
704  return "ECPGd_precision";
705  break;
706  case ECPGd_ret_length:
707  return "ECPGd_ret_length";
708  case ECPGd_ret_octet:
709  return "ECPGd_ret_octet";
710  break;
711  case ECPGd_scale:
712  return "ECPGd_scale";
713  break;
714  case ECPGd_type:
715  return "ECPGd_type";
716  break;
717  case ECPGd_cardinality:
718  return "ECPGd_cardinality";
719  default:
720  mmerror(PARSE_ERROR, ET_ERROR, "unrecognized descriptor item code %d", type);
721  }
722 
723  return NULL;
724 }
@ 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, 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 109 of file type.c.

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

Referenced by ECPGdump_a_struct().