PostgreSQL Source Code  git master
type.h File Reference
#include "ecpgtype.h"
Include dependency graph for type.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ECPGstruct_member
 
struct  ECPGtype
 
struct  ECPGtemp_type
 
struct  when
 
struct  index
 
struct  su_symbol
 
struct  prep
 
struct  exec
 
struct  this_type
 
struct  _include_path
 
struct  cursor
 
struct  typedefs
 
struct  _defines
 
struct  variable
 
struct  arguments
 
struct  descriptor
 
struct  assignment
 
struct  fetch_desc
 

Enumerations

enum  WHEN_TYPE {
  W_NOTHING, W_CONTINUE, W_BREAK, W_SQLPRINT,
  W_GOTO, W_DO, W_STOP
}
 
enum  errortype { ET_WARNING, ET_ERROR }
 

Functions

void ECPGmake_struct_member (const char *, struct ECPGtype *, struct ECPGstruct_member **)
 
struct ECPGtypeECPGmake_simple_type (enum ECPGttype, char *, int)
 
struct ECPGtypeECPGmake_array_type (struct ECPGtype *, char *)
 
struct ECPGtypeECPGmake_struct_type (struct ECPGstruct_member *, enum ECPGttype, char *, char *)
 
struct ECPGstruct_memberECPGstruct_member_dup (struct ECPGstruct_member *)
 
void ECPGfree_struct_member (struct ECPGstruct_member *)
 
void ECPGfree_type (struct ECPGtype *)
 
void ECPGdump_a_type (FILE *, const char *, struct ECPGtype *, const int, const char *, struct ECPGtype *, const int, const char *, const char *, char *, const char *, const char *)
 
const char * ecpg_type_name (enum ECPGttype type)
 

Enumeration Type Documentation

◆ errortype

enum errortype
Enumerator
ET_WARNING 
ET_ERROR 

Definition at line 192 of file type.h.

193 {
195 };
Definition: type.h:194

◆ WHEN_TYPE

enum WHEN_TYPE
Enumerator
W_NOTHING 
W_CONTINUE 
W_BREAK 
W_SQLPRINT 
W_GOTO 
W_DO 
W_STOP 

Definition at line 71 of file type.h.

72 {
73  W_NOTHING,
74  W_CONTINUE,
75  W_BREAK,
76  W_SQLPRINT,
77  W_GOTO,
78  W_DO,
79  W_STOP
80 };
Definition: type.h:73
Definition: type.h:79
Definition: type.h:78
Definition: type.h:75
Definition: type.h:77

Function Documentation

◆ ecpg_type_name()

const char* ecpg_type_name ( enum ECPGttype  type)

Definition at line 17 of file typename.c.

References ECPGt_bool, ECPGt_bytea, ECPGt_char, ECPGt_char_variable, ECPGt_const, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, and ECPGt_varchar.

18 {
19  switch (typ)
20  {
21  case ECPGt_char:
22  case ECPGt_string:
23  return "char";
25  return "unsigned char";
26  case ECPGt_short:
27  return "short";
29  return "unsigned short";
30  case ECPGt_int:
31  return "int";
32  case ECPGt_unsigned_int:
33  return "unsigned int";
34  case ECPGt_long:
35  return "long";
37  return "unsigned long";
38  case ECPGt_long_long:
39  return "long long";
41  return "unsigned long long";
42  case ECPGt_float:
43  return "float";
44  case ECPGt_double:
45  return "double";
46  case ECPGt_bool:
47  return "bool";
48  case ECPGt_varchar:
49  return "varchar";
50  case ECPGt_bytea:
51  return "bytea";
53  return "char";
54  case ECPGt_decimal:
55  return "decimal";
56  case ECPGt_numeric:
57  return "numeric";
58  case ECPGt_date:
59  return "date";
60  case ECPGt_timestamp:
61  return "timestamp";
62  case ECPGt_interval:
63  return "interval";
64  case ECPGt_const:
65  return "Const";
66  default:
67  abort();
68  }
69  return ""; /* keep MSC compiler happy */
70 }

◆ ECPGdump_a_type()

void ECPGdump_a_type ( FILE *  ,
const char *  ,
struct ECPGtype ,
const int  ,
const char *  ,
struct ECPGtype ,
const int  ,
const char *  ,
const char *  ,
char *  ,
const char *  ,
const char *   
)

Definition at line 241 of file type.c.

References base_yyerror(), variable::brace_level, ECPGtype::counter, ECPGdump_a_simple(), ECPGdump_a_struct(), ECPGt_array, ECPGt_char_variable, ECPGt_const, ECPGt_descriptor, ECPGt_NO_INDICATOR, ECPGt_sqlda, ECPGt_struct, ECPGt_union, ECPGtype::element, ET_ERROR, ET_WARNING, find_variable(), free, INDICATOR_NOT_ARRAY, INDICATOR_NOT_SIMPLE, INDICATOR_NOT_STRUCT, indicator_set, IS_SIMPLE_TYPE, mm_strdup(), mmerror(), mmfatal(), PARSE_ERROR, ECPGtype::size, generate_unaccent_rules::str, ECPGtype::type, variable::type, ECPGtype::type_name, and ECPGtype::u.

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

246 {
247  struct variable *var;
248 
249  if (type->type != ECPGt_descriptor && type->type != ECPGt_sqlda &&
250  type->type != ECPGt_char_variable && type->type != ECPGt_const &&
251  brace_level >= 0)
252  {
253  char *str;
254 
255  str = mm_strdup(name);
256  var = find_variable(str);
257  free(str);
258 
259  if ((var->type->type != type->type) ||
260  (var->type->type_name && !type->type_name) ||
261  (!var->type->type_name && type->type_name) ||
262  (var->type->type_name && type->type_name && strcmp(var->type->type_name, type->type_name) != 0))
263  mmerror(PARSE_ERROR, ET_ERROR, "variable \"%s\" is hidden by a local variable of a different type", name);
264  else if (var->brace_level != brace_level)
265  mmerror(PARSE_ERROR, ET_WARNING, "variable \"%s\" is hidden by a local variable", name);
266 
267  if (ind_name && ind_type && ind_type->type != ECPGt_NO_INDICATOR && ind_brace_level >= 0)
268  {
269  str = mm_strdup(ind_name);
270  var = find_variable(str);
271  free(str);
272 
273  if ((var->type->type != ind_type->type) ||
274  (var->type->type_name && !ind_type->type_name) ||
275  (!var->type->type_name && ind_type->type_name) ||
276  (var->type->type_name && ind_type->type_name && strcmp(var->type->type_name, ind_type->type_name) != 0))
277  mmerror(PARSE_ERROR, ET_ERROR, "indicator variable \"%s\" is hidden by a local variable of a different type", ind_name);
278  else if (var->brace_level != ind_brace_level)
279  mmerror(PARSE_ERROR, ET_WARNING, "indicator variable \"%s\" is hidden by a local variable", ind_name);
280  }
281  }
282 
283  switch (type->type)
284  {
285  case ECPGt_array:
286  if (indicator_set && ind_type->type != ECPGt_array)
287  mmfatal(INDICATOR_NOT_ARRAY, "indicator for array/pointer has to be array/pointer");
288  switch (type->u.element->type)
289  {
290  case ECPGt_array:
291  mmerror(PARSE_ERROR, ET_ERROR, "nested arrays are not supported (except strings)"); /* array of array */
292  break;
293  case ECPGt_struct:
294  case ECPGt_union:
296  ind_name,
297  type->size,
298  type->u.element,
299  (ind_type == NULL) ? NULL : ((ind_type->type == ECPGt_NO_INDICATOR) ? ind_type : ind_type->u.element),
300  prefix, ind_prefix);
301  break;
302  default:
303  if (!IS_SIMPLE_TYPE(type->u.element->type))
304  base_yyerror("internal error: unknown datatype, please report this to <" PACKAGE_BUGREPORT ">");
305 
307  type->u.element->type,
308  type->u.element->size, type->size, struct_sizeof ? struct_sizeof : NULL,
309  prefix, type->u.element->counter);
310 
311  if (ind_type != NULL)
312  {
313  if (ind_type->type == ECPGt_NO_INDICATOR)
314  {
315  char *str_neg_one = mm_strdup("-1");
316 
317  ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, str_neg_one, NULL, ind_prefix, 0);
318  free(str_neg_one);
319  }
320  else
321  {
322  ECPGdump_a_simple(o, ind_name, ind_type->u.element->type,
323  ind_type->u.element->size, ind_type->size, NULL, ind_prefix, 0);
324  }
325  }
326  }
327  break;
328  case ECPGt_struct:
329  {
330  char *str_one = mm_strdup("1");
331 
332  if (indicator_set && ind_type->type != ECPGt_struct)
333  mmfatal(INDICATOR_NOT_STRUCT, "indicator for struct has to be a struct");
334 
335  ECPGdump_a_struct(o, name, ind_name, str_one, type, ind_type, prefix, ind_prefix);
336  free(str_one);
337  }
338  break;
339  case ECPGt_union: /* cannot dump a complete union */
340  base_yyerror("type of union has to be specified");
341  break;
342  case ECPGt_char_variable:
343  {
344  /*
345  * Allocate for each, as there are code-paths where the values
346  * get stomped on.
347  */
348  char *str_varchar_one = mm_strdup("1");
349  char *str_arr_one = mm_strdup("1");
350  char *str_neg_one = mm_strdup("-1");
351 
352  if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
353  mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
354 
355  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);
356  if (ind_type != NULL)
357  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);
358 
359  free(str_varchar_one);
360  free(str_arr_one);
361  free(str_neg_one);
362  }
363  break;
364  case ECPGt_descriptor:
365  {
366  /*
367  * Allocate for each, as there are code-paths where the values
368  * get stomped on.
369  */
370  char *str_neg_one = mm_strdup("-1");
371  char *ind_type_neg_one = mm_strdup("-1");
372 
373  if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
374  mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
375 
376  ECPGdump_a_simple(o, name, type->type, NULL, str_neg_one, NULL, prefix, 0);
377  if (ind_type != NULL)
378  ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, ind_type_neg_one, NULL, ind_prefix, 0);
379 
380  free(str_neg_one);
381  free(ind_type_neg_one);
382  }
383  break;
384  default:
385  {
386  /*
387  * Allocate for each, as there are code-paths where the values
388  * get stomped on.
389  */
390  char *str_neg_one = mm_strdup("-1");
391  char *ind_type_neg_one = mm_strdup("-1");
392 
393  if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
394  mmfatal(INDICATOR_NOT_SIMPLE, "indicator for simple data type has to be simple");
395 
396  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);
397  if (ind_type != NULL)
398  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);
399 
400  free(str_neg_one);
401  free(ind_type_neg_one);
402  }
403  break;
404  }
405 }
int brace_level
Definition: type.h:167
#define IS_SIMPLE_TYPE(type)
Definition: ecpgtype.h:92
void void mmfatal(int errorcode, const char *error,...) pg_attribute_printf(2
Definition: type.h:194
char * mm_strdup(const char *string)
Definition: type.c:25
enum ECPGttype type
void base_yyerror(const char *)
#define indicator_set
Definition: type.c:7
#define INDICATOR_NOT_STRUCT
#define PARSE_ERROR
#define INDICATOR_NOT_ARRAY
struct variable * find_variable(char *)
Definition: variable.c:194
static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, char *varcharsize, char *arrsize, const char *size, const char *prefix, int)
Definition: type.c:411
#define free(a)
Definition: header.h:65
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:581
enum ECPGttype ind_type
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
const char * name
Definition: encode.c:555
#define INDICATOR_NOT_SIMPLE

◆ ECPGfree_struct_member()

void ECPGfree_struct_member ( struct ECPGstruct_member )

Definition at line 641 of file type.c.

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

Referenced by ECPGfree_type(), and main().

642 {
643  while (rm)
644  {
645  struct ECPGstruct_member *p = rm;
646 
647  rm = rm->next;
648  free(p->name);
649  free(p->type);
650  free(p);
651  }
652 }
char * name
Definition: type.h:12
struct ECPGtype * type
Definition: type.h:13
#define free(a)
Definition: header.h:65
struct ECPGstruct_member * next
Definition: type.h:14

◆ ECPGfree_type()

void ECPGfree_type ( struct ECPGtype )

Definition at line 655 of file type.c.

References base_yyerror(), ECPGfree_struct_member(), ECPGt_array, ECPGt_struct, ECPGt_union, ECPGtype::element, ET_ERROR, free, IS_SIMPLE_TYPE, ECPGtype::members, mmerror(), PARSE_ERROR, ECPGtype::type, and ECPGtype::u.

Referenced by remove_variables().

656 {
657  if (!IS_SIMPLE_TYPE(type->type))
658  {
659  switch (type->type)
660  {
661  case ECPGt_array:
662  switch (type->u.element->type)
663  {
664  case ECPGt_array:
665  base_yyerror("internal error: found multidimensional array\n");
666  break;
667  case ECPGt_struct:
668  case ECPGt_union:
669  /* Array of structs. */
670  ECPGfree_struct_member(type->u.element->u.members);
671  free(type->u.element);
672  break;
673  default:
674  if (!IS_SIMPLE_TYPE(type->u.element->type))
675  base_yyerror("internal error: unknown datatype, please report this to <" PACKAGE_BUGREPORT ">");
676 
677  free(type->u.element);
678  }
679  break;
680  case ECPGt_struct:
681  case ECPGt_union:
682  ECPGfree_struct_member(type->u.members);
683  break;
684  default:
685  mmerror(PARSE_ERROR, ET_ERROR, "unrecognized variable type code %d", type->type);
686  break;
687  }
688  }
689  free(type);
690 }
#define IS_SIMPLE_TYPE(type)
Definition: ecpgtype.h:92
Definition: type.h:194
void base_yyerror(const char *)
#define PARSE_ERROR
void ECPGfree_struct_member(struct ECPGstruct_member *rm)
Definition: type.c:641
#define free(a)
Definition: header.h:65
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3

◆ ECPGmake_array_type()

struct ECPGtype* ECPGmake_array_type ( struct ECPGtype ,
char *   
)

Definition at line 111 of file type.c.

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

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

112 {
113  struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, size, 0);
114 
115  ne->u.element = type;
116 
117  return ne;
118 }
union ECPGtype::@147 u
Definition: type.h:17
struct ECPGtype * ECPGmake_simple_type(enum ECPGttype type, char *size, int counter)
Definition: type.c:96
struct ECPGtype * element
Definition: type.h:28
char * size
Definition: type.h:22

◆ ECPGmake_simple_type()

struct ECPGtype* ECPGmake_simple_type ( enum  ECPGttype,
char *  ,
int   
)

Definition at line 96 of file type.c.

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

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

97 {
98  struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
99 
100  ne->type = type;
101  ne->type_name = NULL;
102  ne->size = size;
103  ne->u.element = NULL;
104  ne->struct_sizeof = NULL;
105  ne->counter = counter; /* only needed for varchar and bytea */
106 
107  return ne;
108 }
union ECPGtype::@147 u
Definition: type.h:17
struct ECPGtype * element
Definition: type.h:28
char * size
Definition: type.h:22
int counter
Definition: type.h:32
void * mm_alloc(size_t size)
Definition: type.c:13
char * type_name
Definition: type.h:20
enum ECPGttype type
Definition: type.h:19
char * struct_sizeof
Definition: type.h:24

◆ ECPGmake_struct_member()

void ECPGmake_struct_member ( const char *  ,
struct ECPGtype ,
struct ECPGstruct_member **   
)

Definition at line 77 of file type.c.

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

Referenced by ECPGstruct_member_dup().

78 {
79  struct ECPGstruct_member *ptr,
80  *ne =
81  (struct ECPGstruct_member *) mm_alloc(sizeof(struct ECPGstruct_member));
82 
83  ne->name = mm_strdup(name);
84  ne->type = type;
85  ne->next = NULL;
86 
87  for (ptr = *start; ptr && ptr->next; ptr = ptr->next);
88 
89  if (ptr)
90  ptr->next = ne;
91  else
92  *start = ne;
93 }
char * name
Definition: type.h:12
char * mm_strdup(const char *string)
Definition: type.c:25
struct ECPGtype * type
Definition: type.h:13
void * mm_alloc(size_t size)
Definition: type.c:13
const char * name
Definition: encode.c:555
struct ECPGstruct_member * next
Definition: type.h:14

◆ ECPGmake_struct_type()

struct ECPGtype* ECPGmake_struct_type ( struct ECPGstruct_member ,
enum  ECPGttype,
char *  ,
char *   
)

Definition at line 121 of file type.c.

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

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

122 {
123  struct ECPGtype *ne = ECPGmake_simple_type(type, mm_strdup("1"), 0);
124 
126  ne->u.members = ECPGstruct_member_dup(rm);
128 
129  return ne;
130 }
union ECPGtype::@147 u
struct ECPGstruct_member * members
Definition: type.h:30
char * mm_strdup(const char *string)
Definition: type.c:25
Definition: type.h:17
struct ECPGtype * ECPGmake_simple_type(enum ECPGttype type, char *size, int counter)
Definition: type.c:96
struct ECPGstruct_member * ECPGstruct_member_dup(struct ECPGstruct_member *rm)
Definition: type.c:37
char * type_name
Definition: type.h:20
char * struct_sizeof
Definition: type.h:24

◆ ECPGstruct_member_dup()

struct ECPGstruct_member* ECPGstruct_member_dup ( struct ECPGstruct_member )

Definition at line 37 of file type.c.

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, ECPGstruct_member::type, ECPGtype::type, generate_unaccent_rules::type, ECPGtype::type_name, and ECPGtype::u.

Referenced by ECPGmake_struct_type().

38 {
39  struct ECPGstruct_member *new = NULL;
40 
41  while (rm)
42  {
43  struct ECPGtype *type;
44 
45  switch (rm->type->type)
46  {
47  case ECPGt_struct:
48  case ECPGt_union:
49  type = ECPGmake_struct_type(rm->type->u.members, rm->type->type, rm->type->type_name, rm->type->struct_sizeof);
50  break;
51  case ECPGt_array:
52 
53  /*
54  * if this array does contain a struct again, we have to
55  * create the struct too
56  */
57  if (rm->type->u.element->type == ECPGt_struct || rm->type->u.element->type == ECPGt_union)
58  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);
59  else
60  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);
61  break;
62  default:
63  type = ECPGmake_simple_type(rm->type->type, rm->type->size, rm->type->counter);
64  break;
65  }
66 
67  ECPGmake_struct_member(rm->name, type, &new);
68 
69  rm = rm->next;
70  }
71 
72  return new;
73 }
void ECPGmake_struct_member(const char *name, struct ECPGtype *type, struct ECPGstruct_member **start)
Definition: type.c:77
struct ECPGtype * ECPGmake_array_type(struct ECPGtype *type, char *size)
Definition: type.c:111
Definition: type.h:17
struct ECPGtype * ECPGmake_simple_type(enum ECPGttype type, char *size, int counter)
Definition: type.c:96
struct ECPGtype * ECPGmake_struct_type(struct ECPGstruct_member *rm, enum ECPGttype type, char *type_name, char *struct_sizeof)
Definition: type.c:121
enum ECPGttype type
Definition: type.h:19