From 4e1ed3da9b3be389875f63e6c5656856290a72b3 Mon Sep 17 00:00:00 2001 From: Michael Meskes <meskes@postgresql.org> Date: Wed, 14 May 2003 14:37:36 +0000 Subject: [PATCH] - Added more compatibility functions. - Accept CPP defines for type definitions. - Do not parse system include files automatically for Informix mode --- src/interfaces/ecpg/ChangeLog | 6 + src/interfaces/ecpg/compatlib/informix.c | 36 +++- src/interfaces/ecpg/include/datetime.h | 2 +- src/interfaces/ecpg/include/ecpg_informix.h | 5 +- src/interfaces/ecpg/preproc/descriptor.c | 2 +- src/interfaces/ecpg/preproc/ecpg.c | 4 +- src/interfaces/ecpg/preproc/extern.h | 2 +- src/interfaces/ecpg/preproc/preproc.y | 206 +++++++++----------- src/interfaces/ecpg/preproc/type.c | 72 ++++--- src/interfaces/ecpg/preproc/type.h | 38 ++-- src/interfaces/ecpg/preproc/variable.c | 40 ++-- src/interfaces/ecpg/test/test2.pgc | 3 +- 12 files changed, 225 insertions(+), 191 deletions(-) diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index 429af1cd88e..bb9e2ecf24f 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -1408,6 +1408,12 @@ Tue May 6 11:51:33 CEST 2003 Tue May 13 13:34:12 CEST 2003 - Fixed order of include search path. + +Wed May 14 13:05:49 CEST 2003 + + - Added more compatibility functions. + - Accept CPP defines for type definitions. + - Do not parse system include files automatically for Informix mode - Set ecpg version to 2.12.0. - Set ecpg library to 3.4.2. - Set pgtypes library to 1.0.0 diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.c index 2f8087fefcc..27d2f9acd79 100644 --- a/src/interfaces/ecpg/compatlib/informix.c +++ b/src/interfaces/ecpg/compatlib/informix.c @@ -609,6 +609,28 @@ rfmtlong(long lng_val, char *fmt, char *outbuf) return 0; } +void +rupshift(char *str) +{ + for (; *str != '\0'; str++) + if (islower(*str)) *str = toupper(*str); + return; +} + +int +byleng(char *str, int len) +{ + for (len--; str[len] && str[len] == ' '; len--); + return (len+1); +} + +void +ldchar(char *src, int len, char *dest) +{ + memmove(dest, src, len); + dest[len]=0; +} + int rgetmsg(int msgnum, char *s, int maxsize) { @@ -639,13 +661,15 @@ rtypmsize(int type, int len) return 0; } -void -rupshift(char *str) +int +rtypwidth(int sqltype, int sqllen) { - for (; *str != '\0'; str++) - if (islower(*str)) *str = toupper(*str); - return; + return 0; } - +int +dtcvfmtasc (char *inbuf, char *fmtstr, dtime_t *dtvalue) +{ + return 0; +} diff --git a/src/interfaces/ecpg/include/datetime.h b/src/interfaces/ecpg/include/datetime.h index 94ef5d28ad4..da16faa4855 100644 --- a/src/interfaces/ecpg/include/datetime.h +++ b/src/interfaces/ecpg/include/datetime.h @@ -15,4 +15,4 @@ extern int dtsub (dtime_t *, dtime_t *, intrvl_t *); extern int dttoasc (dtime_t *, char *); extern int dttofmtasc (dtime_t *, char *, int, char *); extern int intoasc(intrvl_t *, char *); - +extern int dtcvfmtasc(char *, char *, dtime_t *); diff --git a/src/interfaces/ecpg/include/ecpg_informix.h b/src/interfaces/ecpg/include/ecpg_informix.h index 46df5a2d32a..ff757598374 100644 --- a/src/interfaces/ecpg/include/ecpg_informix.h +++ b/src/interfaces/ecpg/include/ecpg_informix.h @@ -26,6 +26,9 @@ extern int risnull(int, char *); extern int rsetnull(int, char *); extern int rtypalign(int, int); extern int rtypmsize(int, int); +extern int rtypwidth(int, int); extern void rupshift(char *); - +extern int byleng(char *, int); +extern void ldchar(char *, int, char *); + diff --git a/src/interfaces/ecpg/preproc/descriptor.c b/src/interfaces/ecpg/preproc/descriptor.c index c6bfa01c2fd..742002b4c0f 100644 --- a/src/interfaces/ecpg/preproc/descriptor.c +++ b/src/interfaces/ecpg/preproc/descriptor.c @@ -192,7 +192,7 @@ output_get_descr(char *desc_name, char *index) break; } fprintf(yyout, "%s,", get_dtype(results->value)); - ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL, 0L, NULL, NULL); + ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL, make_str("0"), NULL, NULL); } drop_assignments(); fputs("ECPGd_EODT);\n", yyout); diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index 6dfdac82719..d40779b1120 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.69 2003/05/13 11:29:14 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.70 2003/05/14 14:37:35 meskes Exp $ */ /* New main for ecpg, the PostgreSQL embedded SQL precompiler. */ /* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */ @@ -162,7 +162,7 @@ main(int argc, char *const argv[]) if (strcmp(optarg, "INFORMIX") == 0) { compat = ECPG_COMPAT_INFORMIX; - system_includes = true; + /* system_includes = true; */ add_preprocessor_define("dec_t=Numeric"); add_preprocessor_define("intrvl_t=Interval"); } diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h index 73a00067e85..bc0cceaae99 100644 --- a/src/interfaces/ecpg/preproc/extern.h +++ b/src/interfaces/ecpg/preproc/extern.h @@ -77,7 +77,7 @@ extern void add_variable(struct arguments **, struct variable *, struct variable extern void append_variable(struct arguments **, struct variable *, struct variable *); extern void dump_variables(struct arguments *, int); extern struct typedefs *get_typedef(char *); -extern void adjust_array(enum ECPGttype, int *, int *, int, int, int); +extern void adjust_array(enum ECPGttype, char **, char **, char *, char *, int); extern void reset_variables(void); extern void check_indicator(struct ECPGtype *); extern void remove_variables(int); diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index 1448d3757c6..4e9374f3d02 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.216 2003/05/02 14:43:25 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.217 2003/05/14 14:37:35 meskes Exp $ */ /* Copyright comment */ %{ @@ -139,8 +139,8 @@ make_name(void) %union { double dval; - int ival; char *str; + int ival; struct when action; struct index index; int tagname; @@ -289,7 +289,7 @@ make_name(void) %type <str> CreateAsElement OptCreateAs CreateAsList CreateAsStmt %type <str> comment_text ConstraintDeferrabilitySpec TableElementList %type <str> key_match ColLabel SpecialRuleRelation ColId columnDef -%type <str> ColConstraint ColConstraintElem drop_type Bconst +%type <str> ColConstraint ColConstraintElem drop_type Bconst Iresult %type <str> TableConstraint OptTableElementList Xconst opt_transaction %type <str> ConstraintElem key_actions ColQualList type_name %type <str> target_list target_el update_target_list alias_clause @@ -405,8 +405,6 @@ make_name(void) %type <index> opt_array_bounds -%type <ival> Iresult - %% prog: statements; @@ -2955,34 +2953,33 @@ Typename: SimpleTypename opt_array_bounds opt_array_bounds: '[' ']' opt_array_bounds { - $$.index1 = 0; + $$.index1 = make_str("0"); $$.index2 = $3.index1; $$.str = cat2_str(make_str("[]"), $3.str); } | '[' Iresult ']' opt_array_bounds { - char *txt = mm_alloc(20L); - - sprintf (txt, "%d", $2); - $$.index1 = $2; + $$.index1 = strdup($2); $$.index2 = $4.index1; - $$.str = cat_str(4, make_str("["), txt, make_str("]"), $4.str); + $$.str = cat_str(4, make_str("["), $2, make_str("]"), $4.str); } | /* EMPTY */ { - $$.index1 = -1; - $$.index2 = -1; + $$.index1 = make_str("-1"); + $$.index2 = make_str("-1"); $$.str= EMPTY; } ; -Iresult: PosIntConst { $$ = atol($1); } - | '(' Iresult ')' { $$ = $2; } - | Iresult '+' Iresult { $$ = $1 + $3; } - | Iresult '-' Iresult { $$ = $1 - $3; } - | Iresult '*' Iresult { $$ = $1 * $3; } - | Iresult '/' Iresult { $$ = $1 / $3; } - | Iresult '%' Iresult { $$ = $1 % $3; } +Iresult: PosIntConst { $$ = $1; } + | '(' Iresult ')' { $$ = cat_str(3, make_str("("), $2, make_str(")")); } + | Iresult '+' Iresult { $$ = cat_str(3, $1, make_str("+"), $3); } + | Iresult '-' Iresult { $$ = cat_str(3, $1, make_str("-"), $3); } + | Iresult '*' Iresult { $$ = cat_str(3, $1, make_str("*"), $3); } + | Iresult '/' Iresult { $$ = cat_str(3, $1, make_str("/"), $3); } + | Iresult '%' Iresult { $$ = cat_str(3, $1, make_str("%"), $3); } + | Sconst { $$ = $1; } + | ColId { $$ = $1; } ; SimpleTypename: GenericType { $$ = $1; } @@ -4199,72 +4196,72 @@ single_vt_type: common_type { $$.type_enum = ECPGt_varchar; $$.type_str = EMPTY; - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "float") == 0) { $$.type_enum = ECPGt_float; $$.type_str = make_str("float"); - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "double") == 0) { $$.type_enum = ECPGt_double; $$.type_str = make_str("double"); - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "numeric") == 0) { $$.type_enum = ECPGt_numeric; $$.type_str = EMPTY; - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "decimal") == 0) { $$.type_enum = ECPGt_numeric; $$.type_str = EMPTY; - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "date") == 0) { $$.type_enum = ECPGt_date; $$.type_str = make_str("Date"); - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "timestamp") == 0) { $$.type_enum = ECPGt_timestamp; $$.type_str = make_str("Timestamp"); - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "datetime") == 0) { $$.type_enum = ECPGt_timestamp; $$.type_str = make_str("Timestamp"); - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "interval") == 0) { $$.type_enum = ECPGt_interval; $$.type_str = EMPTY; - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else @@ -4323,8 +4320,8 @@ type_declaration: S_TYPEDEF { /* add entry to list */ struct typedefs *ptr, *this; - int dimension = $6.index1; - int length = $6.index2; + char * dimension = $6.index1; + char * length = $6.index2; if (($3.type_enum == ECPGt_struct || $3.type_enum == ECPGt_union) && @@ -4364,7 +4361,7 @@ type_declaration: S_TYPEDEF if ($3.type_enum != ECPGt_varchar && $3.type_enum != ECPGt_char && $3.type_enum != ECPGt_unsigned_char && - this->type->type_index >= 0) + atoi(this->type->type_index) >= 0) mmerror(PARSE_ERROR, ET_ERROR, "No multi-dimensional array support for simple data types"); types = this; @@ -4420,32 +4417,32 @@ common_type: simple_type { $$.type_enum = $1; $$.type_str = mm_strdup(ECPGtype_name($1)); - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } | struct_type { $$.type_enum = ECPGt_struct; $$.type_str = $1; - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = ECPGstruct_sizeof; } | union_type { $$.type_enum = ECPGt_union; $$.type_str = $1; - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } | enum_type { $$.type_str = $1; $$.type_enum = ECPGt_int; - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } | ECPGColLabelCommon '(' precision opt_scale ')' @@ -4455,8 +4452,8 @@ common_type: simple_type $$.type_enum = ECPGt_numeric; $$.type_str = EMPTY; - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } ; @@ -4475,72 +4472,72 @@ var_type: common_type { $$.type_enum = ECPGt_varchar; $$.type_str = EMPTY; /*make_str("varchar");*/ - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "float") == 0) { $$.type_enum = ECPGt_float; $$.type_str = make_str("float"); - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "double") == 0) { $$.type_enum = ECPGt_double; $$.type_str = make_str("double"); - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "numeric") == 0) { $$.type_enum = ECPGt_numeric; $$.type_str = EMPTY; - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "decimal") == 0) { $$.type_enum = ECPGt_numeric; $$.type_str = EMPTY; - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "date") == 0) { $$.type_enum = ECPGt_date; $$.type_str = make_str("Date"); - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "timestamp") == 0) { $$.type_enum = ECPGt_timestamp; $$.type_str = make_str("Timestamp"); - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "interval") == 0) { $$.type_enum = ECPGt_interval; $$.type_str = EMPTY; - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else if (strcmp($1, "datetime") == 0) { $$.type_enum = ECPGt_timestamp; $$.type_str = make_str("Timestamp"); - $$.type_dimension = -1; - $$.type_index = -1; + $$.type_dimension = make_str("-1"); + $$.type_index = make_str("-1"); $$.type_sizeof = NULL; } else @@ -4672,8 +4669,8 @@ variable_list: variable variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer { struct ECPGtype * type; - int dimension = $3.index1; /* dimension of array */ - int length = $3.index2; /* lenght of string */ + char *dimension = $3.index1; /* dimension of array */ + char *length = $3.index2; /* lenght of string */ char dim[14L], ascii_len[12]; adjust_array(actual_type[struct_level].type_enum, &dimension, &length, actual_type[struct_level].type_dimension, actual_type[struct_level].type_index, strlen($1)); @@ -4682,7 +4679,7 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer { case ECPGt_struct: case ECPGt_union: - if (dimension < 0) + if (atoi(dimension) < 0) type = ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum, actual_type[struct_level].type_sizeof); else type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], actual_type[struct_level].type_enum, actual_type[struct_level].type_sizeof), dimension); @@ -4691,36 +4688,27 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer break; case ECPGt_varchar: - if (dimension < 0) + if (atoi(dimension) < 0) type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length); else type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension); - switch(dimension) - { - case 0: - case -1: - case 1: + if (strcmp(dimension, "0") == 0 || abs(atoi(dimension)) == 1) *dim = '\0'; - break; - default: - sprintf(dim, "[%d]", dimension); - break; - } - sprintf(ascii_len, "%d", length); - - if (length == 0) + else + sprintf(dim, "[%s]", dimension); + if (strcmp(length, "0") == 0) mmerror(PARSE_ERROR, ET_ERROR, "pointer to varchar are not implemented"); - if (dimension == 0) - $$ = cat_str(7, mm_strdup(actual_storage[struct_level]), make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(ascii_len), make_str("]; } *"), mm_strdup($2), $4); + if (strcmp(dimension, "0") == 0) + $$ = cat_str(7, mm_strdup(actual_storage[struct_level]), make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } *"), mm_strdup($2), $4); else - $$ = cat_str(8, mm_strdup(actual_storage[struct_level]), make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(ascii_len), make_str("]; } "), mm_strdup($2), mm_strdup(dim), $4); + $$ = cat_str(8, mm_strdup(actual_storage[struct_level]), make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } "), mm_strdup($2), mm_strdup(dim), $4); break; case ECPGt_char: case ECPGt_unsigned_char: - if (dimension == -1) + if (atoi(dimension) == -1) type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length); else type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension); @@ -4729,34 +4717,34 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer break; case ECPGt_numeric: - if (dimension < 0) + if (atoi(dimension) < 0) type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length); else type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension); - if (dimension < 0) + if (atoi(dimension) < 0) $$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("Numeric"), mm_strdup($2), $4); else $$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("Numeric"), mm_strdup($2), mm_strdup(dim), $4); break; case ECPGt_interval: - if (dimension < 0) + if (atoi(dimension) < 0) type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length); else type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension); - if (dimension < 0) + if (atoi(dimension) < 0) $$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("Interval"), mm_strdup($2), $4); else $$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("Interval"), mm_strdup($2), mm_strdup(dim), $4); break; default: - if (dimension < 0) - type = ECPGmake_simple_type(actual_type[struct_level].type_enum, 1); + if (atoi(dimension) < 0) + type = ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1")); else - type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, 1), dimension); + type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1")), dimension); $$ = cat_str(4, $1, mm_strdup($2), $3.str, $4); break; @@ -5026,8 +5014,8 @@ ECPGTypedef: TYPE_P { /* add entry to list */ struct typedefs *ptr, *this; - int dimension = $6.index1; - int length = $6.index2; + char *dimension = $6.index1; + char *length = $6.index2; if (($5.type_enum == ECPGt_struct || $5.type_enum == ECPGt_union) && @@ -5064,7 +5052,7 @@ ECPGTypedef: TYPE_P if ($5.type_enum != ECPGt_varchar && $5.type_enum != ECPGt_char && $5.type_enum != ECPGt_unsigned_char && - this->type->type_index >= 0) + atoi(this->type->type_index) >= 0) mmerror(PARSE_ERROR, ET_ERROR, "No multi-dimensional array support for simple data types"); types = this; @@ -5093,8 +5081,8 @@ ECPGVar: SQL_VAR ColLabel IS var_type opt_array_bounds opt_reference { struct variable *p = find_variable($3); - int dimension = $6.index1; - int length = $6.index2; + char *dimension = $6.index1; + char *length = $6.index2; struct ECPGtype * type; if (($5.type_enum == ECPGt_struct || @@ -5109,14 +5097,14 @@ ECPGVar: SQL_VAR { case ECPGt_struct: case ECPGt_union: - if (dimension < 0) + if (atoi(dimension) < 0) type = ECPGmake_struct_type(struct_member_list[struct_level], $5.type_enum, $5.type_sizeof); else type = ECPGmake_array_type(ECPGmake_struct_type(struct_member_list[struct_level], $5.type_enum,$5.type_sizeof), dimension); break; case ECPGt_varchar: - if (dimension == -1) + if (atoi(dimension) == -1) type = ECPGmake_simple_type($5.type_enum, length); else type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length), dimension); @@ -5124,20 +5112,20 @@ ECPGVar: SQL_VAR case ECPGt_char: case ECPGt_unsigned_char: - if (dimension == -1) + if (atoi(dimension) == -1) type = ECPGmake_simple_type($5.type_enum, length); else type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length), dimension); break; default: - if (length >= 0) + if (atoi(length) >= 0) mmerror(PARSE_ERROR, ET_ERROR, "No multi-dimensional array support for simple data types"); - if (dimension < 0) - type = ECPGmake_simple_type($5.type_enum, 1); + if (atoi(dimension) < 0) + type = ECPGmake_simple_type($5.type_enum, make_str("1")); else - type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, 1), dimension); + type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, make_str("1")), dimension); break; } diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c index fe0c76b9572..365a92f48a6 100644 --- a/src/interfaces/ecpg/preproc/type.c +++ b/src/interfaces/ecpg/preproc/type.c @@ -83,7 +83,7 @@ ECPGmake_struct_member(char *name, struct ECPGtype * type, struct ECPGstruct_mem } struct ECPGtype * -ECPGmake_simple_type(enum ECPGttype type, long size) +ECPGmake_simple_type(enum ECPGttype type, char *size) { struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype)); @@ -96,7 +96,7 @@ ECPGmake_simple_type(enum ECPGttype type, long size) } struct ECPGtype * -ECPGmake_array_type(struct ECPGtype * type, long size) +ECPGmake_array_type(struct ECPGtype * type, char *size) { struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, size); @@ -108,7 +108,7 @@ ECPGmake_array_type(struct ECPGtype * type, long size) struct ECPGtype * ECPGmake_struct_type(struct ECPGstruct_member * rm, enum ECPGttype type, char *struct_sizeof) { - struct ECPGtype *ne = ECPGmake_simple_type(type, 1); + struct ECPGtype *ne = ECPGmake_simple_type(type, make_str("1")); ne->u.members = ECPGstruct_member_dup(rm); ne->struct_sizeof = struct_sizeof; @@ -207,13 +207,17 @@ get_type(enum ECPGttype type) the variable (required to do array fetches of structs). */ static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, - long varcharsize, - long arrsiz, const char *siz, const char *prefix); -static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, + char *varcharsize, + char *arrsiz, const char *siz, const char *prefix); +static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz, struct ECPGtype * type, struct ECPGtype * ind_type, const char *offset, const char *prefix, const char *ind_prefix); void -ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *ind_name, struct ECPGtype * ind_type, const char *prefix, const char *ind_prefix, const long arr_str_siz, const char *struct_sizeof, const char *ind_struct_sizeof) +ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, + const char *ind_name, struct ECPGtype * ind_type, + const char *prefix, const char *ind_prefix, + char *arr_str_siz, const char *struct_sizeof, + const char *ind_struct_sizeof) { switch (type->type) { @@ -239,7 +243,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i if (ind_type != NULL) { if (ind_type->type == ECPGt_NO_INDICATOR) - ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, -1, NULL, ind_prefix); + ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix); else ECPGdump_a_simple(o, ind_name, ind_type->u.element->type, ind_type->u.element->size, ind_type->size, NULL, prefix); @@ -250,7 +254,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i if (indicator_set && ind_type->type != ECPGt_struct) mmerror(INDICATOR_NOT_STRUCT, ET_FATAL, "Indicator for struct has to be struct.\n"); - ECPGdump_a_struct(o, name, ind_name, 1, type, ind_type, NULL, prefix, ind_prefix); + ECPGdump_a_struct(o, name, ind_name, make_str("1"), type, ind_type, NULL, prefix, ind_prefix); break; case ECPGt_union: /* cannot dump a complete union */ yyerror("Type of union has to be specified"); @@ -259,23 +263,23 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array)) mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n"); - ECPGdump_a_simple(o, name, type->type, 1, arr_str_siz ? arr_str_siz : 1, struct_sizeof, prefix); - ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, arr_str_siz ? arr_str_siz : -1, ind_struct_sizeof, ind_prefix); + ECPGdump_a_simple(o, name, type->type, make_str("1"), (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("1"), struct_sizeof, prefix); + ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix); break; case ECPGt_descriptor: if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array)) mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n"); - ECPGdump_a_simple(o, name, type->type, 0, -1, NULL, prefix); - ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, -1, NULL, ind_prefix); + ECPGdump_a_simple(o, name, type->type, 0, make_str("-1"), NULL, prefix); + ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix); break; default: if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array)) mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n"); - ECPGdump_a_simple(o, name, type->type, type->size, arr_str_siz ? arr_str_siz : -1, struct_sizeof, prefix); + ECPGdump_a_simple(o, name, type->type, type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), struct_sizeof, prefix); if (ind_type != NULL) - ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, arr_str_siz ? arr_str_siz : -1, ind_struct_sizeof, ind_prefix); + ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix); break; } } @@ -285,8 +289,8 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const char *i string, it represents the offset needed if we are in an array of structs. */ static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, - long varcharsize, - long arrsize, + char *varcharsize, + char *arrsize, const char *siz, const char *prefix ) @@ -309,7 +313,9 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, * we have to use the pointer except for arrays with given * bounds */ - if (arrsize > 0 && siz == NULL) + if (((atoi(arrsize) > 0) || + (atoi(arrsize) == 0) && strcmp(arrsize, "0") != 0) && + siz == NULL) sprintf(variable, "(%s%s)", prefix ? prefix : "", name); else sprintf(variable, "&(%s%s)", prefix ? prefix : "", name); @@ -324,12 +330,16 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, * we have to use the pointer except for arrays with given * bounds */ - if ((varcharsize > 1 || arrsize > 0) && siz == NULL) + if ((atoi(varcharsize) > 1 || + (atoi(arrsize) > 0) || + (atoi(varcharsize) == 0 && strcmp(varcharsize, "0") != 0) || + (atoi(arrsize) == 0 && strcmp(arrsize, "0") != 0)) + && siz == NULL) sprintf(variable, "(%s%s)", prefix ? prefix : "", name); else sprintf(variable, "&(%s%s)", prefix ? prefix : "", name); - sprintf(offset, "%ld*sizeof(char)", varcharsize == 0 ? 1 : varcharsize); + sprintf(offset, "%s*sizeof(char)", strcmp(varcharsize, "0") == 0 ? "1" : varcharsize); break; case ECPGt_numeric: @@ -369,7 +379,9 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, * we have to use the pointer except for arrays with given * bounds */ - if (arrsize > 0 && siz == NULL) + if (((atoi(arrsize) > 0) || + (atoi(arrsize) == 0) && strcmp(arrsize, "0") != 0) && + siz == NULL) sprintf(variable, "(%s%s)", prefix ? prefix : "", name); else sprintf(variable, "&(%s%s)", prefix ? prefix : "", name); @@ -378,13 +390,13 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, break; } - if (arrsize < 0) - arrsize = 1; - - if (siz == NULL || arrsize <= 1) - fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(type), variable, varcharsize, arrsize, offset); + if (atoi(arrsize) < 0) + strcpy(arrsize, "1"); + + if (siz == NULL || strcmp(arrsize, "0") == 0 || strcmp(arrsize, "1") == 0) + fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, offset); else - fprintf(o, "\n\t%s,%s,%ldL,%ldL,%s, ", get_type(type), variable, varcharsize, arrsize, siz); + fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, siz); free(variable); free(offset); @@ -394,7 +406,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, /* Penetrate a struct and dump the contents. */ static void -ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, struct ECPGtype * type, struct ECPGtype * ind_type, const char *offsetarg, const char *prefix, const char *ind_prefix) +ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz, struct ECPGtype * type, struct ECPGtype * ind_type, const char *offsetarg, const char *prefix, const char *ind_prefix) { /* * If offset is NULL, then this is the first recursive level. If not @@ -416,7 +428,7 @@ ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, else offset = offsetarg; - if (arrsiz == 1) + if (atoi(arrsiz) == 1) sprintf(pbuf, "%s%s.", prefix ? prefix : "", name); else sprintf(pbuf, "%s%s->", prefix ? prefix : "", name); @@ -427,7 +439,7 @@ ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, ind_p = &struct_no_indicator; else if (ind_type != NULL) { - if (arrsiz == 1) + if (atoi(arrsiz) == 1) sprintf(ind_pbuf, "%s%s.", ind_prefix ? ind_prefix : "", ind_name); else sprintf(ind_pbuf, "%s%s->", ind_prefix ? ind_prefix : "", ind_name); diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h index fd74a1336df..5c74b27cf9e 100644 --- a/src/interfaces/ecpg/preproc/type.h +++ b/src/interfaces/ecpg/preproc/type.h @@ -14,26 +14,24 @@ struct ECPGstruct_member struct ECPGtype { enum ECPGttype type; - long size; /* For array it is the number of elements. - * For varchar it is the maxsize of the - * area. */ - char *struct_sizeof; /* For a struct this is the sizeof() type - * as string */ + char *size; /* For array it is the number of elements. + * For varchar it is the maxsize of the + * area. */ + char *struct_sizeof; /* For a struct this is the sizeof() type + * as string */ union { struct ECPGtype *element; /* For an array this is the type - * of the element */ - - struct ECPGstruct_member *members; - /* A pointer to a list of members. */ + * of the element */ + struct ECPGstruct_member *members; /* A pointer to a list of members. */ } u; }; /* Everything is malloced. */ void ECPGmake_struct_member(char *, struct ECPGtype *, struct ECPGstruct_member **); -struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, long); +struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, char *); struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long); -struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, long); +struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, char *); struct ECPGtype *ECPGmake_struct_type(struct ECPGstruct_member *, enum ECPGttype, char *); struct ECPGstruct_member *ECPGstruct_member_dup(struct ECPGstruct_member *); @@ -51,7 +49,9 @@ void ECPGfree_type(struct ECPGtype *); size is the maxsize in case it is a varchar. Otherwise it is the size of the variable (required to do array fetches of structs). */ -void ECPGdump_a_type(FILE *, const char *, struct ECPGtype *, const char *, struct ECPGtype *, const char *, const char *, const long, const char *, const char *); +void ECPGdump_a_type(FILE *, const char *, struct ECPGtype *, const char *, + struct ECPGtype *, const char *, const char *, char *, + const char *, const char *); /* A simple struct to keep a variable and its type. */ struct ECPGtemp_type @@ -83,18 +83,18 @@ struct when struct index { - int index1; - int index2; - char *str; + char *index1; + char *index2; + char *str; }; struct this_type { enum ECPGttype type_enum; - char *type_str; - int type_dimension; - int type_index; - char *type_sizeof; + char *type_str; + char *type_dimension; + char *type_index; + char *type_sizeof; }; struct _include_path diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c index 34504ccfece..e545ade5295 100644 --- a/src/interfaces/ecpg/preproc/variable.c +++ b/src/interfaces/ecpg/preproc/variable.c @@ -298,22 +298,22 @@ get_typedef(char *name) } void -adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dimension, int type_index, int pointer_len) +adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *type_dimension, char *type_index, int pointer_len) { - if (type_index >= 0) + if (atoi(type_index) >= 0) { - if (*length >= 0) + if (atoi(*length) >= 0) mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support"); *length = type_index; } - if (type_dimension >= 0) + if (atoi(type_dimension) >= 0) { - if (*dimension >= 0 && *length >= 0) + if (atoi(*dimension) >= 0 && atoi(*length) >= 0) mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support"); - if (*dimension >= 0) + if (atoi(*dimension) >= 0) *length = *dimension; *dimension = type_dimension; @@ -328,10 +328,10 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char) mmerror(PARSE_ERROR, ET_FATAL, "No pointer to pointer supported for this type"); - if (pointer_len > 1 && (*length >= 0 || *dimension >= 0)) + if (pointer_len > 1 && (atoi(*length) >= 0 || atoi(*dimension) >= 0)) mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support"); - if (*length >= 0 && *dimension >= 0 && pointer_len) + if (atoi(*length) >= 0 && atoi(*dimension) >= 0 && pointer_len) mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support"); switch (type_enum) @@ -342,23 +342,23 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim if (pointer_len) { *length = *dimension; - *dimension = 0; + *dimension = make_str("0"); } - if (*length >= 0) + if (atoi(*length) >= 0) mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support for structures"); break; case ECPGt_varchar: /* pointer has to get dimension 0 */ if (pointer_len) - *dimension = 0; + *dimension = make_str("0"); /* one index is the string length */ - if (*length < 0) + if (atoi(*length) < 0) { *length = *dimension; - *dimension = -1; + *dimension = make_str("-1"); } break; @@ -367,19 +367,19 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim /* char ** */ if (pointer_len == 2) { - *length = *dimension = 0; + *length = *dimension = make_str("0"); break; } /* pointer has to get length 0 */ if (pointer_len == 1) - *length = 0; + *length = make_str("0"); /* one index is the string length */ - if (*length < 0) + if (atoi(*length) < 0) { - *length = (*dimension < 0) ? 1 : *dimension; - *dimension = -1; + *length = (atoi(*dimension) < 0) ? make_str("1") : *dimension; + *dimension = make_str("-1"); } break; default: @@ -387,10 +387,10 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim if (pointer_len) { *length = *dimension; - *dimension = 0; + *dimension = make_str("0"); } - if (*length >= 0) + if (atoi(*length) >= 0) mmerror(PARSE_ERROR, ET_FATAL, "No multi-dimensional array support for simple data types"); break; diff --git a/src/interfaces/ecpg/test/test2.pgc b/src/interfaces/ecpg/test/test2.pgc index b11ce408925..28b7c5c0e48 100644 --- a/src/interfaces/ecpg/test/test2.pgc +++ b/src/interfaces/ecpg/test/test2.pgc @@ -9,7 +9,8 @@ typedef char* c; exec sql type ind is union { int integer; short smallint; }; typedef union { int integer; short smallint; } ind; -exec sql type str is varchar[8]; +#define BUFSIZ 8 +exec sql type str is varchar[BUFSIZ]; int main () -- GitLab