1- /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.223 2003/05/27 11:31:52 meskes Exp $*/
1+ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.224 2003/05/29 12:00:21 meskes Exp $*/
22
33/* Copyright comment*/
44%{
@@ -27,6 +27,9 @@ struct ECPGstruct_member *struct_member_list[STRUCT_DEPTH] = { NULL };
2727/* also store struct type so we can do a sizeof() later*/
2828static char *ECPGstruct_sizeof =NULL ;
2929
30+ /* for forward declarations we have to store some data as well*/
31+ static char *forward_name =NULL ;
32+
3033struct ECPGtype ecpg_no_indicator = {ECPGt_NO_INDICATOR,0L ,NULL , {NULL }};
3134struct variable no_indicator = {" no_indicator" , &ecpg_no_indicator,0 ,NULL };
3235
@@ -196,6 +199,7 @@ create_questionmarks(char *name, bool array)
196199enum ECPGttypetype_enum;
197200enum ECPGdtypedtype_enum;
198201struct fetch_desc descriptor;
202+ struct su_symbol struct_union;
199203}
200204
201205/* special embedded SQL token*/
@@ -440,7 +444,9 @@ create_questionmarks(char *name, bool array)
440444%type <str> reserved_keyword unreserved_keyword ecpg_interval
441445%type <str> col_name_keyword func_name_keyword precision opt_scale
442446%type <str> ECPGTypeName variablelist ECPGColLabelCommon c_variable
443- %type <str> s_struct_union_symbol inf_val_list inf_col_list
447+ %type <str> inf_val_list inf_col_list
448+
449+ %type <struct_union> s_struct_union_symbol
444450
445451%type <descriptor> ECPGGetDescriptor
446452
@@ -4039,7 +4045,6 @@ connection_target: database_name opt_server opt_port
40394045}
40404046| StringConst
40414047{
4042- printf (" MM: %s\n " , $1 );
40434048if ($1 [0 ] ==' \" ' )
40444049$$ =$1 ;
40454050else if (strcmp($1 ," ?" ) ==0 )/* variable*/
@@ -4425,16 +4430,34 @@ single_vt_type: common_type
44254430| s_struct_union_symbol
44264431{
44274432/* this is for named structs/unions*/
4428- char *name =$1 ;
4429- struct typedefs *this = get_typedef(name);
4430-
4431- $$ .type_str = mm_strdup(this ->name);
4432- $$ .type_enum =this ->type->type_enum;
4433- $$ .type_dimension =this ->type->type_dimension;
4434- $$ .type_index =this ->type->type_index;
4435- $$ .type_sizeof =this ->type->type_sizeof;
4436- struct_member_list[struct_level] = ECPGstruct_member_dup(this ->struct_member_list);
4437- free (name);
4433+ char *name;
4434+ struct typedefs *this ;
4435+ bool forward = (strcmp($1 .symbol, forward_name) ==0 && strcmp($1 .su," struct" ) ==0 );
4436+
4437+ name = cat2_str($1 .su,$1 .symbol);
4438+ /* Do we have a forward definition?*/
4439+ if (!forward)
4440+ {
4441+ /* No*/
4442+
4443+ this = get_typedef(name);
4444+ $$ .type_str = mm_strdup(this ->name);
4445+ $$ .type_enum =this ->type->type_enum;
4446+ $$ .type_dimension =this ->type->type_dimension;
4447+ $$ .type_index =this ->type->type_index;
4448+ $$ .type_sizeof =this ->type->type_sizeof;
4449+ struct_member_list[struct_level] = ECPGstruct_member_dup(this ->struct_member_list);
4450+ free (name);
4451+ }
4452+ else
4453+ {
4454+ $$ .type_str = name;
4455+ $$ .type_enum = ECPGt_long;
4456+ $$ .type_dimension = make_str(" -1" );
4457+ $$ .type_index = make_str(" -1" );
4458+ $$ .type_sizeof = make_str(" " );
4459+ struct_member_list[struct_level] =NULL ;
4460+ }
44384461}
44394462;
44404463
@@ -4761,15 +4784,34 @@ var_type:common_type
47614784| s_struct_union_symbol
47624785{
47634786/* this is for named structs/unions*/
4764- char *name =$1 ;
4765- struct typedefs *this = get_typedef(name);
4766- $$ .type_str = mm_strdup(this ->name);
4767- $$ .type_enum =this ->type->type_enum;
4768- $$ .type_dimension =this ->type->type_dimension;
4769- $$ .type_index =this ->type->type_index;
4770- $$ .type_sizeof =this ->type->type_sizeof;
4771- struct_member_list[struct_level] = ECPGstruct_member_dup(this ->struct_member_list);
4772- free (name);
4787+ char *name;
4788+ struct typedefs *this ;
4789+ bool forward = (strcmp($1 .symbol, forward_name) ==0 && strcmp($1 .su," struct" ) ==0 );
4790+
4791+ name = cat2_str($1 .su,$1 .symbol);
4792+ /* Do we have a forward definition?*/
4793+ if (!forward)
4794+ {
4795+ /* No*/
4796+
4797+ this = get_typedef(name);
4798+ $$ .type_str = mm_strdup(this ->name);
4799+ $$ .type_enum =this ->type->type_enum;
4800+ $$ .type_dimension =this ->type->type_dimension;
4801+ $$ .type_index =this ->type->type_index;
4802+ $$ .type_sizeof =this ->type->type_sizeof;
4803+ struct_member_list[struct_level] = ECPGstruct_member_dup(this ->struct_member_list);
4804+ free (name);
4805+ }
4806+ else
4807+ {
4808+ $$ .type_str = name;
4809+ $$ .type_enum = ECPGt_long;
4810+ $$ .type_dimension = make_str(" -1" );
4811+ $$ .type_index = make_str(" -1" );
4812+ $$ .type_sizeof = make_str(" " );
4813+ struct_member_list[struct_level] =NULL ;
4814+ }
47734815}
47744816;
47754817
@@ -4789,18 +4831,21 @@ struct_union_type_with_symbol: s_struct_union_symbol
47894831struct_member_list[struct_level++] =NULL ;
47904832if (struct_level >= STRUCT_DEPTH)
47914833mmerror (PARSE_ERROR, ET_ERROR," Too many levels in nested structure/union definition" );
4834+ forward_name = mm_strdup($1 .symbol);
47924835}
47934836' {' variable_declarations ' }'
47944837{
47954838ECPGfree_struct_member (struct_member_list[struct_level]);
47964839struct_member_list[struct_level] =NULL ;
47974840free (actual_storage[struct_level--]);
4798- if (strncmp($1 ," struct" ,sizeof (" struct" )-1 ) ==0 )
4841+ if (strncmp($1 .su ," struct" ,sizeof (" struct" )-1 ) ==0 )
47994842$$ .type_enum = ECPGt_struct;
48004843else
48014844$$ .type_enum = ECPGt_union;
4802- $$ .type_str = mm_strdup($1 );
4803- $$ .type_sizeof = cat_str(4 ,$1 , make_str(" {" ),$4 , make_str(" }" ));
4845+ $$ .type_str = cat2_str($1 .su,$1 .symbol);
4846+ $$ .type_sizeof = cat_str(4 , mm_strdup($$ .type_str), make_str(" {" ),$4 , make_str(" }" ));
4847+ free (forward_name);
4848+ forward_name =NULL ;
48044849}
48054850;
48064851
@@ -4822,12 +4867,14 @@ struct_union_type: struct_union_type_with_symbol{ $$ = $1.type_sizeof; }
48224867
48234868s_struct_union_symbol :SQL_STRUCT symbol
48244869{
4825- $$ = cat2_str(make_str(" struct" ),$2 );
4826- ECPGstruct_sizeof = cat_str(3 , make_str(" sizeof(" ), strdup($$ ), make_str(" )" ));
4870+ $$ .su = make_str(" struct" );
4871+ $$ .symbol =$2 ;
4872+ ECPGstruct_sizeof = cat_str(3 , make_str(" sizeof(" ), cat2_str(mm_strdup($$ .su), mm_strdup($$ .symbol)), make_str(" )" ));
48274873}
48284874| UNION symbol
48294875{
4830- $$ = cat2_str(make_str(" union" ),$2 );
4876+ $$ .su = make_str(" union" );
4877+ $$ .symbol =$2 ;
48314878}
48324879;
48334880