PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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  declared_list
 
struct  typedefs
 
struct  _defines
 
struct  variable
 
struct  arguments
 
struct  descriptor
 
struct  assignment
 
struct  fetch_desc
 
struct  describe
 

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 *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)
 
struct ECPGstruct_memberECPGstruct_member_dup (struct ECPGstruct_member *rm)
 
void ECPGfree_struct_member (struct ECPGstruct_member *rm)
 
void ECPGfree_type (struct ECPGtype *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)
 
const char * ecpg_type_name (enum ECPGttype type)
 

Enumeration Type Documentation

◆ errortype

enum errortype
Enumerator
ET_WARNING 
ET_ERROR 

Definition at line 217 of file type.h.

218 {
220 };
@ ET_WARNING
Definition: type.h:219
@ ET_ERROR
Definition: type.h:219

◆ WHEN_TYPE

enum WHEN_TYPE
Enumerator
W_NOTHING 
W_CONTINUE 
W_BREAK 
W_SQLPRINT 
W_GOTO 
W_DO 
W_STOP 

Definition at line 76 of file type.h.

77 {
78  W_NOTHING,
79  W_CONTINUE,
80  W_BREAK,
81  W_SQLPRINT,
82  W_GOTO,
83  W_DO,
84  W_STOP
85 };
@ W_STOP
Definition: type.h:84
@ W_GOTO
Definition: type.h:82
@ W_SQLPRINT
Definition: type.h:81
@ W_BREAK
Definition: type.h:80
@ W_CONTINUE
Definition: type.h:79
@ W_DO
Definition: type.h:83
@ W_NOTHING
Definition: type.h:78

Function Documentation

◆ ecpg_type_name()

const char* ecpg_type_name ( enum ECPGttype  type)

Definition at line 17 of file typename.c.

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 }
@ 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_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_short
Definition: ecpgtype.h:43
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_long
Definition: ecpgtype.h:44
@ ECPGt_unsigned_char
Definition: ecpgtype.h:43
@ ECPGt_double
Definition: ecpgtype.h:47
@ ECPGt_date
Definition: ecpgtype.h:53
@ ECPGt_interval
Definition: ecpgtype.h:55
@ ECPGt_unsigned_long
Definition: ecpgtype.h:44
@ ECPGt_const
Definition: ecpgtype.h:61
@ ECPGt_bool
Definition: ecpgtype.h:46
@ ECPGt_unsigned_long_long
Definition: ecpgtype.h:45
@ ECPGt_unsigned_int
Definition: ecpgtype.h:44
@ ECPGt_char
Definition: ecpgtype.h:43
@ ECPGt_string
Definition: ecpgtype.h:65

◆ 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_sqlda
Definition: ecpgtype.h:66
@ ECPGt_union
Definition: ecpgtype.h:58
@ ECPGt_struct
Definition: ecpgtype.h:57
@ ECPGt_array
Definition: ecpgtype.h:56
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_descriptor
Definition: ecpgtype.h:59
#define IS_SIMPLE_TYPE(type)
Definition: ecpgtype.h:92
const char * str
#define free(a)
Definition: header.h:65
void base_yyerror(const char *error)
void mmerror(int error_code, enum errortype type, const char *error,...) pg_attribute_printf(3
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
#define PARSE_ERROR
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
const char * type
const char * name

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 }
char * name
Definition: type.h:12
struct ECPGtype * type
Definition: type.h:13
struct ECPGstruct_member * next
Definition: type.h:14

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 }
static pg_noinline void Size size
Definition: slab.c:607
Definition: type.h:18
union ECPGtype::@164 u
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 }
void * mm_alloc(size_t size)
Definition: util.c:85
char * type_name
Definition: type.h:20
char * struct_sizeof
Definition: type.h:24
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 * members
Definition: type.h:30
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().