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 $*/
2
2
3
3
/* Copyright comment*/
4
4
%{
@@ -27,6 +27,9 @@ struct ECPGstruct_member *struct_member_list[STRUCT_DEPTH] = { NULL };
27
27
/* also store struct type so we can do a sizeof() later*/
28
28
static char *ECPGstruct_sizeof =NULL ;
29
29
30
+ /* for forward declarations we have to store some data as well*/
31
+ static char *forward_name =NULL ;
32
+
30
33
struct ECPGtype ecpg_no_indicator = {ECPGt_NO_INDICATOR,0L ,NULL , {NULL }};
31
34
struct variable no_indicator = {" no_indicator" , &ecpg_no_indicator,0 ,NULL };
32
35
@@ -196,6 +199,7 @@ create_questionmarks(char *name, bool array)
196
199
enum ECPGttypetype_enum;
197
200
enum ECPGdtypedtype_enum;
198
201
struct fetch_desc descriptor;
202
+ struct su_symbol struct_union;
199
203
}
200
204
201
205
/* special embedded SQL token*/
@@ -440,7 +444,9 @@ create_questionmarks(char *name, bool array)
440
444
%type <str> reserved_keyword unreserved_keyword ecpg_interval
441
445
%type <str> col_name_keyword func_name_keyword precision opt_scale
442
446
%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
444
450
445
451
%type <descriptor> ECPGGetDescriptor
446
452
@@ -4039,7 +4045,6 @@ connection_target: database_name opt_server opt_port
4039
4045
}
4040
4046
| StringConst
4041
4047
{
4042
- printf (" MM: %s\n " , $1 );
4043
4048
if ($1 [0 ] ==' \" ' )
4044
4049
$$ =$1 ;
4045
4050
else if (strcmp($1 ," ?" ) ==0 )/* variable*/
@@ -4425,16 +4430,34 @@ single_vt_type: common_type
4425
4430
| s_struct_union_symbol
4426
4431
{
4427
4432
/* 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
+ }
4438
4461
}
4439
4462
;
4440
4463
@@ -4761,15 +4784,34 @@ var_type:common_type
4761
4784
| s_struct_union_symbol
4762
4785
{
4763
4786
/* 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
+ }
4773
4815
}
4774
4816
;
4775
4817
@@ -4789,18 +4831,21 @@ struct_union_type_with_symbol: s_struct_union_symbol
4789
4831
struct_member_list[struct_level++] =NULL ;
4790
4832
if (struct_level >= STRUCT_DEPTH)
4791
4833
mmerror (PARSE_ERROR, ET_ERROR," Too many levels in nested structure/union definition" );
4834
+ forward_name = mm_strdup($1 .symbol);
4792
4835
}
4793
4836
' {' variable_declarations ' }'
4794
4837
{
4795
4838
ECPGfree_struct_member (struct_member_list[struct_level]);
4796
4839
struct_member_list[struct_level] =NULL ;
4797
4840
free (actual_storage[struct_level--]);
4798
- if (strncmp($1 ," struct" ,sizeof (" struct" )-1 ) ==0 )
4841
+ if (strncmp($1 .su ," struct" ,sizeof (" struct" )-1 ) ==0 )
4799
4842
$$ .type_enum = ECPGt_struct;
4800
4843
else
4801
4844
$$ .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 ;
4804
4849
}
4805
4850
;
4806
4851
@@ -4822,12 +4867,14 @@ struct_union_type: struct_union_type_with_symbol{ $$ = $1.type_sizeof; }
4822
4867
4823
4868
s_struct_union_symbol :SQL_STRUCT symbol
4824
4869
{
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(" )" ));
4827
4873
}
4828
4874
| UNION symbol
4829
4875
{
4830
- $$ = cat2_str(make_str(" union" ),$2 );
4876
+ $$ .su = make_str(" union" );
4877
+ $$ .symbol =$2 ;
4831
4878
}
4832
4879
;
4833
4880