From 5a5f0a6168d60c5c161634afc2309ce41ebdfbcd Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Tue, 23 Sep 2003 12:56:35 +0000 Subject: [PATCH] - Changed struct definition handling so "struct foo {}" always gets defined. --- src/interfaces/ecpg/ChangeLog | 5 ++ src/interfaces/ecpg/preproc/preproc.y | 104 ++++++++++---------------- 2 files changed, 45 insertions(+), 64 deletions(-) diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index 3ac58aae4c..742cd66c86 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -1651,6 +1651,11 @@ Mon Sep 22 15:13:02 CEST 2003 - Fixed order mismatch in processing "using" arguments. - Fixed some minor things in test cases. - Use defines for Informix error codes. + +Tue Sep 23 14:50:45 CEST 2003 + + - Changed struct definition handling so "struct foo {}" always gets + defined. - Set ecpg version to 3.0.0 - Set ecpg library to 4.0.0 - Set pgtypes library to 1.0.0 diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index eebd1930b9..78c4a30825 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.258 2003/09/22 13:19:39 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.259 2003/09/23 12:56:35 meskes Exp $ */ /* Copyright comment */ %{ @@ -540,7 +540,7 @@ add_additional_variables(char *name, bool insert) %type col_name_keyword func_name_keyword precision opt_scale %type ECPGTypeName using_list ECPGColLabelCommon UsingConst %type inf_val_list inf_col_list using_descriptor into_descriptor -%type ecpg_into_using prepared_name +%type ecpg_into_using prepared_name struct_union_type_with_symbol %type s_struct_union_symbol @@ -551,7 +551,6 @@ add_additional_variables(char *name, bool insert) %type descriptor_item desc_header_item %type var_type common_type single_vt_type -%type struct_union_type_with_symbol %type action @@ -4441,34 +4440,7 @@ single_var_declaration: storage_declaration } | struct_union_type_with_symbol ';' { - /* this is essantially a typedef but needs the keyword struct/union as well */ - struct typedefs *ptr, *this; - - for (ptr = types; ptr != NULL; ptr = ptr->next) - { - if (strcmp($1.type_str, ptr->name) == 0) - { - /* re-definition is a bug */ - snprintf(errortext, sizeof(errortext), "Type %s already defined", $1.type_str); - mmerror(PARSE_ERROR, ET_ERROR, errortext); - } - } - - this = (struct typedefs *) mm_alloc(sizeof(struct typedefs)); - - /* initial definition */ - this->next = types; - this->name = $1.type_str; - this->type = (struct this_type *) mm_alloc(sizeof(struct this_type)); - this->type->type_enum = $1.type_enum; - this->type->type_str = mm_strdup($1.type_str); - this->type->type_dimension = make_str("-1"); /* dimension of array */ - this->type->type_index = make_str("-1"); /* length of string */ - this->type->type_sizeof = ECPGstruct_sizeof; - this->struct_member_list = struct_member_list[struct_level]; - - types = this; - $$ = cat2_str($1.type_sizeof, make_str(";")); + $$ = cat2_str($1, make_str(";")); } ; @@ -4658,6 +4630,7 @@ type_declaration: S_TYPEDEF char * dimension = $6.index1; char * length = $6.index2; +printf("MM: %s\n", $5); if (($3.type_enum == ECPGt_struct || $3.type_enum == ECPGt_union) && initializer == 1) @@ -4735,34 +4708,7 @@ var_declaration: storage_declaration } | struct_union_type_with_symbol ';' { - /* this is essantially a typedef but needs the keyword struct/union as well */ - struct typedefs *ptr, *this; - - for (ptr = types; ptr != NULL; ptr = ptr->next) - { - if (strcmp($1.type_str, ptr->name) == 0) - { - /* re-definition is a bug */ - snprintf(errortext, sizeof(errortext), "Type %s already defined", $1.type_str); - mmerror(PARSE_ERROR, ET_ERROR, errortext); - } - } - - this = (struct typedefs *) mm_alloc(sizeof(struct typedefs)); - - /* initial definition */ - this->next = types; - this->name = $1.type_str; - this->type = (struct this_type *) mm_alloc(sizeof(struct this_type)); - this->type->type_enum = $1.type_enum; - this->type->type_str = mm_strdup($1.type_str); - this->type->type_dimension = make_str("-1"); /* dimension of array */ - this->type->type_index = make_str("-1"); /* length of string */ - this->type->type_sizeof = ECPGstruct_sizeof; - this->struct_member_list = struct_member_list[struct_level]; - - types = this; - $$ = cat2_str($1.type_sizeof, make_str(";")); + $$ = cat2_str($1, make_str(";")); } ; @@ -4996,21 +4942,51 @@ struct_union_type_with_symbol: s_struct_union_symbol } '{' variable_declarations '}' { + struct typedefs *ptr, *this; + struct this_type su_type; + ECPGfree_struct_member(struct_member_list[struct_level]); struct_member_list[struct_level] = NULL; free(actual_storage[struct_level--]); if (strncmp($1.su, "struct", sizeof("struct")-1) == 0) - $$.type_enum = ECPGt_struct; + su_type.type_enum = ECPGt_struct; else - $$.type_enum = ECPGt_union; - $$.type_str = cat2_str($1.su, $1.symbol); - $$.type_sizeof = cat_str(4, mm_strdup($$.type_str), make_str("{"), $4, make_str("}")); + su_type.type_enum = ECPGt_union; + su_type.type_str = cat2_str($1.su, $1.symbol); free(forward_name); forward_name = NULL; + + /* This is essantially a typedef but needs the keyword struct/union as well. + * So we create the typedef for each struct definition with symbol */ + for (ptr = types; ptr != NULL; ptr = ptr->next) + { + if (strcmp(su_type.type_str, ptr->name) == 0) + { + /* re-definition is a bug */ + snprintf(errortext, sizeof(errortext), "Type %s already defined", su_type.type_str); + mmerror(PARSE_ERROR, ET_ERROR, errortext); + } + } + + this = (struct typedefs *) mm_alloc(sizeof(struct typedefs)); + + /* initial definition */ + this->next = types; + this->name = mm_strdup(su_type.type_str); + this->type = (struct this_type *) mm_alloc(sizeof(struct this_type)); + this->type->type_enum = su_type.type_enum; + this->type->type_str = mm_strdup(su_type.type_str); + this->type->type_dimension = make_str("-1"); /* dimension of array */ + this->type->type_index = make_str("-1"); /* length of string */ + this->type->type_sizeof = ECPGstruct_sizeof; + this->struct_member_list = struct_member_list[struct_level]; + + types = this; + $$ = cat_str(4, su_type.type_str, make_str("{"), $4, make_str("}")); } ; -struct_union_type: struct_union_type_with_symbol { $$ = $1.type_sizeof; } +struct_union_type: struct_union_type_with_symbol { $$ = $1; } | s_struct_union { struct_member_list[struct_level++] = NULL;