1- /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.206 2003/01/21 20:01:12 meskes Exp $*/
1+ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.207 2003/02/13 20:37:28 meskes Exp $*/
22
33/* Copyright comment*/
44%{
@@ -376,7 +376,7 @@ make_name(void)
376376%type <str> storage_clause opt_initializer c_anything
377377%type <str> variable_list variable c_thing c_term
378378%type <str> opt_pointer ECPGDisconnect dis_name storage_modifier
379- %type <str> stmt ECPGRelease execstring server_name
379+ %type <str> ECPGRelease execstring server_name ECPGVarDeclaration
380380%type <str> connection_object opt_server opt_port c_stuff c_stuff_item
381381%type <str> user_name opt_user char_variable ora_user ident opt_reference
382382%type <str> var_type_declarations quoted_ident_stringvar
@@ -385,21 +385,21 @@ make_name(void)
385385%type <str> enum_type civar civarind ECPGCursorStmt ECPGDeallocate
386386%type <str> ECPGFree ECPGDeclare ECPGVar opt_at enum_definition
387387%type <str> struct_type s_struct vt_declarations variable_declarations
388- %type <str> var_declaration type_declaration
388+ %type <str> var_declaration type_declaration single_vt_declaration
389389%type <str> s_union union_type ECPGSetAutocommit on_off
390390%type <str> ECPGAllocateDescr ECPGDeallocateDescr symbol opt_symbol
391- %type <str> ECPGGetDescriptorHeader ECPGColLabel
391+ %type <str> ECPGGetDescriptorHeader ECPGColLabel single_var_declaration
392392%type <str> reserved_keyword unreserved_keyword
393393%type <str> col_name_keyword func_name_keyword
394- %type <str> ECPGTypeName variablelist
394+ %type <str> ECPGTypeName variablelist ECPGColLabelCommon
395395
396396%type <descriptor> ECPGGetDescriptor
397397
398398%type <type_enum> simple_type signed_type unsigned_type
399399
400400%type <dtype_enum> descriptor_item desc_header_item
401401
402- %type <type> type
402+ %type <type> type common_type single_vt_type
403403
404404%type <action> action
405405
@@ -652,6 +652,12 @@ stmt: AlterDatabaseSetStmt { output_statement($1, 0, connection); }
652652
653653output_simple_statement ($1 );
654654}
655+ | ECPGVarDeclaration
656+ {
657+ fprintf (yyout," %s" , $1 );
658+ free ($1 );
659+ output_line_number ();
660+ }
655661| ECPGWhenever
656662{
657663if (connection)
@@ -4125,8 +4131,89 @@ ECPGDeallocate: DEALLOCATE PREPARE ident
41254131{$$ = cat_str(2 , make_str(" ECPGdeallocate(__LINE__,\" " ),$2 , make_str(" \" );" )); }
41264132;
41274133
4134+ /*
4135+ * variable decalartion outside exec sql declare block
4136+ */
4137+ ECPGVarDeclaration :single_vt_declaration ;
4138+
4139+ single_vt_declaration :type_declaration {$$ =$1 ; }
4140+ | single_var_declaration {$$ =$1 ; }
4141+ ;
4142+
4143+ single_var_declaration :storage_clause storage_modifier
4144+ {
4145+ actual_storage[struct_level] = cat2_str(mm_strdup($1 ), mm_strdup($2 ));
4146+ actual_startline[struct_level] = hashline_number();
4147+ }
4148+ single_vt_type
4149+ {
4150+ actual_type[struct_level].type_enum =$4 .type_enum;
4151+ actual_type[struct_level].type_dimension =$4 .type_dimension;
4152+ actual_type[struct_level].type_index =$4 .type_index;
4153+ actual_type[struct_level].type_sizeof =$4 .type_sizeof;
4154+
4155+ /* we do not need the string "varchar" for output*/
4156+ /* so replace it with an empty string*/
4157+ if ($4 .type_enum == ECPGt_varchar)
4158+ {
4159+ free ($4 .type_str);
4160+ $4 .type_str=EMPTY;
4161+ }
4162+ }
4163+ variable_list
4164+ {
4165+ $$ = cat_str(6 , actual_startline[struct_level],$1 ,$2 ,$4 .type_str,$6 , make_str(" ;\n " ));
4166+ }
4167+ ;
4168+
4169+ single_vt_type :common_type
4170+ | ECPGColLabelCommon
4171+ {
4172+ /*
4173+ * Check for type names that the SQL grammar treats as
4174+ * unreserved keywords
4175+ */
4176+ if (strcmp($1 ," varchar" ) ==0 )
4177+ {
4178+ $$ .type_enum = ECPGt_varchar;
4179+ $$ .type_str = make_str(" varchar" );
4180+ $$ .type_dimension = -1 ;
4181+ $$ .type_index = -1 ;
4182+ $$ .type_sizeof =NULL ;
4183+ }
4184+ else if (strcmp($1 ," float" ) ==0 )
4185+ {
4186+ $$ .type_enum = ECPGt_float;
4187+ $$ .type_str = make_str(" float" );
4188+ $$ .type_dimension = -1 ;
4189+ $$ .type_index = -1 ;
4190+ $$ .type_sizeof =NULL ;
4191+ }
4192+ else if (strcmp($1 ," double" ) ==0 )
4193+ {
4194+ $$ .type_enum = ECPGt_double;
4195+ $$ .type_str = make_str(" double" );
4196+ $$ .type_dimension = -1 ;
4197+ $$ .type_index = -1 ;
4198+ $$ .type_sizeof =NULL ;
4199+ }
4200+ else
4201+ {
4202+ /* this is for typedef'ed types*/
4203+ struct typedefs *this = get_typedef($1 );
4204+
4205+ $$ .type_str = (this ->type->type_enum == ECPGt_varchar) ? EMPTY : mm_strdup(this ->name);
4206+ $$ .type_enum =this ->type->type_enum;
4207+ $$ .type_dimension =this ->type->type_dimension;
4208+ $$ .type_index =this ->type->type_index;
4209+ $$ .type_sizeof =this ->type->type_sizeof;
4210+ struct_member_list[struct_level] = ECPGstruct_member_dup(this ->struct_member_list);
4211+ }
4212+ }
4213+ ;
4214+
41284215/*
4129- * variable declaration insidethe exec sql declare block
4216+ * variable declaration inside exec sql declare block
41304217*/
41314218ECPGDeclaration :sql_startdeclare
41324219{ fputs(" /* exec sql begin declare section */" , yyout); }
@@ -4256,7 +4343,7 @@ storage_modifier : S_CONST{ $$ = make_str("const"); }
42564343| /* EMPTY*/ {$$ = EMPTY; }
42574344;
42584345
4259- type :simple_type
4346+ common_type :simple_type
42604347{
42614348$$ .type_enum =$1 ;
42624349$$ .type_str = mm_strdup(ECPGtype_name($1 ));
@@ -4288,6 +4375,9 @@ type: simple_type
42884375$$ .type_index = -1 ;
42894376$$ .type_sizeof =NULL ;
42904377}
4378+ ;
4379+
4380+ type :common_type
42914381| ECPGColLabel
42924382{
42934383/*
@@ -5108,15 +5198,17 @@ ColLabel: ECPGColLabel{ $$ = $1; }
51085198| UNION {$$ = make_str(" union" ); }
51095199;
51105200
5111- ECPGColLabel :ident {$$ =$1 ; }
5201+ ECPGColLabelCommon :ident {$$ =$1 ; }
5202+ | col_name_keyword {$$ =$1 ; }
5203+ | func_name_keyword {$$ =$1 ; }
5204+ ;
5205+
5206+ ECPGColLabel :ECPGColLabelCommon {$$ =$1 ; }
51125207| unreserved_keyword {$$ =$1 ; }
5113- | col_name_keyword {$$ =$1 ; }
5114- | func_name_keyword {$$ =$1 ; }
5115- | reserved_keyword {$$ =$1 ; }
5116- | ECPGKeywords {$$ =$1 ; }
5208+ | reserved_keyword {$$ =$1 ; }
5209+ | ECPGKeywords {$$ =$1 ; }
51175210;
51185211
5119-
51205212/*
51215213 * Keyword classification lists. Generally, every keyword present in
51225214 * the Postgres grammar should appear in exactly one of these lists.