Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c31a80f

Browse files
committed
From: Michael Meskes <meskes@topsystem.de> +Wed May 20 10:46:48 CEST 1998 + + - Fixed handling of preprocessor directives and variable + initialization. + - Added enum datatype. - Set version to 2.3.2
1 parent b15b768 commit c31a80f

File tree

9 files changed

+95
-44
lines changed

9 files changed

+95
-44
lines changed

src/interfaces/ecpg/ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,10 @@ Tue May 19 11:49:34 CEST 1998
232232

233233
- Tested (and fixed) 'set connection'
234234
- Fixed string notation in C
235+
236+
Wed May 20 10:46:48 CEST 1998
237+
238+
- Fixed handling of preprocessor directives and variable
239+
initialization.
240+
- Added enum datatype.
235241
- Set version to 2.3.2

src/interfaces/ecpg/TODO

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
ecpg does not understand enum datatypes.
2-
31
The complete structure definition has to be listed inside the declare
42
section of the structure variable for ecpg to be able to understand it.
53

src/interfaces/ecpg/lib/typename.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ ECPGtype_name(enum ECPGttype typ)
88
{
99
switch (typ)
1010
{
11-
case ECPGt_char:return "char";
11+
case ECPGt_char:
12+
return "char";
1213
case ECPGt_unsigned_char:
1314
return "unsigned char";
1415
case ECPGt_short:
@@ -29,6 +30,8 @@ ECPGtype_name(enum ECPGttype typ)
2930
return "double";
3031
case ECPGt_bool:
3132
return "bool";
33+
case ECPGt_varchar:
34+
return "varchar";
3235
default:
3336
abort();
3437
}

src/interfaces/ecpg/preproc/c_keywords.c

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static ScanKeyword ScanKeywords[] = {
2727
{"char", S_CHAR},
2828
{"const", S_CONST},
2929
{"double", S_DOUBLE},
30+
{"enum", S_ENUM},
3031
{"extern", S_EXTERN},
3132
{"float", S_FLOAT},
3233
{"int", S_INT},

src/interfaces/ecpg/preproc/ecpg_keywords.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
#include "postgres.h"
1212
#include "type.h"
13-
#include "y.tab.h"
1413
#include "extern.h"
14+
#include "y.tab.h"
1515

1616
/*
1717
* List of (keyword-name, keyword-token-value) pairs.

src/interfaces/ecpg/preproc/pgc.l

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
#include "parser/gramparse.h"
2626
#include "parser/scansup.h"
2727
#include "type.h"
28+
#include "extern.h"
2829
#include "y.tab.h"
2930
#include "utils/builtins.h"
3031

31-
#include "extern.h"
32-
3332
/* some versions of lex define this as a macro */
3433
#if defined(yywrap)
3534
#undef yywrap
@@ -160,6 +159,8 @@ exec [eE][xX][eE][cC]
160159
include [iI][nN][cC][lL][uU][dD][eE]
161160
sql [sS][qQ][lL]
162161

162+
cppline {space}*#.*(\\{space}*\n)*\n*
163+
163164
/* DO NOT PUT ANY COMMENTS IN THE FOLLOWING SECTION.
164165
* AT&T lex does not properly handle C-style comments in this second lex block.
165166
* So, put comments here. tgl - 1997-09-08
@@ -281,7 +282,7 @@ sql [sS][qQ][lL]
281282
memcpy(literal+llen, yytext, yyleng+1);
282283
llen += yyleng;
283284
}
284-
<C>{xdstart} {
285+
{xdstart} {
285286
BEGIN(xdc);
286287
llen = 0;
287288
*literal = '\0';
@@ -442,6 +443,10 @@ sql [sS][qQ][lL]
442443

443444
<C>{exec}{space}{sql} { BEGIN SQL; return SQL_START; }
444445
<C>{ccomment} { /* ignore */ }
446+
<C>{cppline} {
447+
yylval.str = strdup((char*)yytext);
448+
return(CPP_LINE);
449+
}
445450
<C>{identifier} {
446451
ScanKeyword *keyword;
447452

src/interfaces/ecpg/preproc/preproc.y

+67-34
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ output_statement(char * stmt, int mode)
500500
whenever_action(mode);
501501
free(stmt);
502502
}
503+
503504
%}
504505

505506
%union {
@@ -509,6 +510,7 @@ output_statement(char * stmt, int mode)
509510
struct when action;
510511
struct index index;
511512
int tagname;
513+
struct this_type type;
512514
enum ECPGttype type_enum;
513515
}
514516

@@ -520,8 +522,8 @@ output_statement(char * stmt, int mode)
520522
%token SQL_STOP SQL_WHENEVER
521523

522524
/* C token */
523-
%token S_ANYTHING S_AUTO S_BOOL S_CHAR S_CONST S_DOUBLE S_EXTERN
524-
%token S_FLOAT S_INT
525+
%token S_ANYTHING S_AUTO S_BOOL S_CHAR S_CONST S_DOUBLE S_ENUM S_EXTERN
526+
%token S_FLOAT S_INT S
525527
%token S_LONG S_REGISTER S_SHORT S_SIGNED S_STATIC S_STRUCT
526528
%token S_UNSIGNED S_VARCHAR
527529

@@ -582,7 +584,7 @@ output_statement(char * stmt, int mode)
582584
%token PASSWORD, CREATEDB, NOCREATEDB, CREATEUSER, NOCREATEUSER, VALID, UNTIL
583585

584586
/* Special keywords, not in the query language - see the "lex" file */
585-
%token <str> IDENT SCONST Op CSTRING CVARIABLE
587+
%token <str> IDENT SCONST Op CSTRING CVARIABLE CPP_LINE
586588
%token <ival> ICONST PARAM
587589
%token <dval> FCONST
588590

@@ -676,12 +678,15 @@ output_statement(char * stmt, int mode)
676678
%type <str> blockend variable_list variable var_anything do_anything
677679
%type <str> opt_pointer cvariable ECPGDisconnect dis_name
678680
%type <str> stmt symbol opt_symbol ECPGRelease execstring server_name
679-
%type <str> connection_object opt_server opt_port
681+
%type <str> connection_object opt_server opt_port c_thing
680682
%type <str> user_name opt_user char_variable ora_user ident
681683
%type <str> db_prefix server opt_options opt_connection_name
682-
%type <str> ECPGSetConnection
684+
%type <str> ECPGSetConnection c_line cpp_line s_enum
685+
%type <str> enum_type
686+
687+
%type <type_enum> simple_type
683688

684-
%type <type_enum> simple_type type struct_type
689+
%type <type> type
685690

686691
%type <action> action
687692

@@ -694,7 +699,8 @@ statements: /* empty */
694699

695700
statement: ecpgstart stmt SQL_SEMI
696701
| ECPGDeclaration
697-
| c_anything { fputs($1, yyout); free($1); }
702+
| c_thing { fprintf(yyout, "%s", $1); free($1); }
703+
| cpp_line { fprintf(yyout, "%s", $1); free($1); }
698704
| blockstart { fputs($1, yyout); free($1); }
699705
| blockend { fputs($1, yyout); free($1); }
700706

@@ -3795,29 +3801,49 @@ variable_declarations: /* empty */
37953801
declaration: storage_clause type
37963802
{
37973803
actual_storage[struct_level] = $1;
3798-
actual_type[struct_level] = $2;
3799-
if ($2 != ECPGt_varchar && $2 != ECPGt_struct)
3800-
fprintf(yyout, "%s %s", $1, ECPGtype_name($2));
3804+
actual_type[struct_level] = $2.type_enum;
3805+
if ($2.type_enum != ECPGt_varchar && $2.type_enum != ECPGt_struct)
3806+
fprintf(yyout, "%s %s", $1, $2.type_str);
3807+
free($2.type_str);
38013808
}
38023809
variable_list ';' { fputc(';', yyout); }
38033810

3804-
storage_clause : S_EXTERN { $$ = make1_str("extern"); }
3805-
| S_STATIC { $$ = make1_str("static"); }
3806-
| S_SIGNED { $$ = make1_str("signed"); }
3807-
| S_CONST { $$ = make1_str("const"); }
3808-
| S_REGISTER { $$ = make1_str("register"); }
3809-
| S_AUTO { $$ = make1_str("auto"); }
3810-
| /* empty */ { $$ = make1_str("") ; }
3811+
storage_clause : S_EXTERN { $$ = "extern"; }
3812+
| S_STATIC { $$ = "static"; }
3813+
| S_SIGNED { $$ = "signed"; }
3814+
| S_CONST { $$ = "const"; }
3815+
| S_REGISTER { $$ = "register"; }
3816+
| S_AUTO { $$ = "auto"; }
3817+
| /* empty */ { $$ = ""; }
38113818

38123819
type: simple_type
3820+
{
3821+
$$.type_enum = $1;
3822+
$$.type_str = strdup(ECPGtype_name($1));
3823+
}
38133824
| struct_type
3825+
{
3826+
$$.type_enum = ECPGt_struct;
3827+
$$.type_str = make1_str("");
3828+
}
3829+
| enum_type
3830+
{
3831+
$$.type_str = $1;
3832+
$$.type_enum = ECPGt_int;
3833+
}
3834+
3835+
enum_type: s_enum '{' c_line '}'
3836+
{
3837+
$$ = cat4_str($1, make1_str("{"), $3, make1_str("}"));
3838+
}
3839+
3840+
s_enum: S_ENUM opt_symbol { $$ = cat2_str(make1_str("enum"), $2); }
38143841

38153842
struct_type: s_struct '{' variable_declarations '}'
38163843
{
38173844
ECPGfree_struct_member(struct_member_list[struct_level]);
38183845
free(actual_storage[struct_level--]);
38193846
fputs("} ", yyout);
3820-
$$ = ECPGt_struct;
38213847
}
38223848

38233849
s_struct : S_STRUCT opt_symbol
@@ -3957,7 +3983,7 @@ variable: opt_pointer symbol opt_array_bounds opt_initializer
39573983
if (struct_level == 0)
39583984
new_variable($2, type);
39593985
else
3960-
ECPGmake_struct_member($2, type, &(struct_member_list[struct_level - 1]))->typ;
3986+
ECPGmake_struct_member($2, type, &(struct_member_list[struct_level - 1]));
39613987

39623988
free($1);
39633989
free($2);
@@ -4562,27 +4588,36 @@ civariableonly : cvariable name {
45624588
add_variable(&argsinsert, find_variable($1), &no_indicator);
45634589
}
45644590

4565-
cvariable: CVARIABLE { $$ = make1_str($1); }
4591+
cvariable: CVARIABLE { $$ = $1; }
45664592

45674593
indicator: /* empty */ { $$ = NULL; }
45684594
| cvariable { check_indicator((find_variable($1))->type); $$ = $1; }
45694595
| SQL_INDICATOR cvariable { check_indicator((find_variable($2))->type); $$ = $2; }
45704596
| SQL_INDICATOR name { check_indicator((find_variable($2))->type); $$ = $2; }
45714597

4572-
ident: IDENT { $$ = make1_str($1); }
4598+
ident: IDENT { $$ = $1; }
45734599
| CSTRING { $$ = $1; }
45744600
/*
45754601
* C stuff
45764602
*/
45774603

4578-
symbol: IDENT { $$ = make1_str($1); }
4604+
symbol: IDENT { $$ = $1; }
4605+
4606+
cpp_line: CPP_LINE { $$ = $1; }
4607+
4608+
c_line: c_anything { $$ = $1; }
4609+
| c_line c_anything
4610+
{
4611+
$$ = make2_str($1, $2);
4612+
}
4613+
4614+
c_thing: c_anything | ';' { $$ = make1_str(";"); }
45794615

4580-
c_anything: IDENT { $$ = make1_str($1); }
4616+
c_anything: IDENT { $$ = $1; }
45814617
| CSTRING { $$ = make3_str(make1_str("\""), $1, make1_str("\"")); }
45824618
| Iconst { $$ = $1; }
45834619
| FCONST { $$ = make_name(); }
4584-
| '*' { $$ = make1_str("*"); }
4585-
| ';' { $$ = make1_str(";"); }
4620+
| '*' { $$ = make1_str("*"); }
45864621
| S_AUTO { $$ = make1_str("auto"); }
45874622
| S_BOOL { $$ = make1_str("bool"); }
45884623
| S_CHAR { $$ = make1_str("char"); }
@@ -4607,19 +4642,17 @@ c_anything: IDENT { $$ = make1_str($1); }
46074642
| '=' { $$ = make1_str("="); }
46084643
| ',' { $$ = make1_str(","); }
46094644

4610-
do_anything: IDENT { $$ = make1_str($1); }
4645+
do_anything: IDENT { $$ = $1; }
46114646
| CSTRING { $$ = make3_str(make1_str("\""), $1, make1_str("\""));}
46124647
| Iconst { $$ = $1; }
46134648
| FCONST { $$ = make_name(); }
46144649
| ',' { $$ = make1_str(","); }
46154650

4616-
var_anything: IDENT { $$ = make1_str($1); }
4617-
| CSTRING { $$ = make3_str(make1_str("\""), $1, make1_str("\"")); }
4618-
| Iconst { $$ = $1; }
4619-
| FCONST { $$ = make_name(); }
4620-
/*FIXME: | ',' { $$ = make1_str(","); }*/
4621-
| '{' { $$ = make1_str("{"); }
4622-
| '}' { $$ = make1_str("}"); }
4651+
var_anything: IDENT { $$ = $1; }
4652+
| CSTRING { $$ = make3_str(make1_str("\""), $1, make1_str("\"")); }
4653+
| Iconst { $$ = $1; }
4654+
| FCONST { $$ = make_name(); }
4655+
| '{' c_line '}' { $$ = make3_str(make1_str("{"), $2, make1_str("}")); }
46234656

46244657
blockstart : '{' {
46254658
braces_open++;
@@ -4635,6 +4668,6 @@ blockend : '}' {
46354668

46364669
void yyerror(char * error)
46374670
{
4638-
fprintf(stderr, "%s in line %d\n", error, yylineno);
4671+
fprintf(stderr, "%s in line %d of file %s\n", error, yylineno, input_filename);
46394672
exit(PARSE_ERROR);
46404673
}

src/interfaces/ecpg/preproc/type.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct_member_dup(struct ECPGstruct_member * rm)
5252
}
5353

5454
/* The NAME argument is copied. The type argument is preserved as a pointer. */
55-
struct ECPGstruct_member *
55+
void
5656
ECPGmake_struct_member(char *name, struct ECPGtype * type, struct ECPGstruct_member ** start)
5757
{
5858
struct ECPGstruct_member *ptr,
@@ -69,7 +69,6 @@ ECPGmake_struct_member(char *name, struct ECPGtype * type, struct ECPGstruct_mem
6969
ptr->next = ne;
7070
else
7171
*start = ne;
72-
return ne;
7372
}
7473

7574
struct ECPGtype *

src/interfaces/ecpg/preproc/type.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct ECPGtype
2525
};
2626

2727
/* Everything is malloced. */
28-
struct ECPGstruct_member *ECPGmake_struct_member(char *, struct ECPGtype *, struct ECPGstruct_member **);
28+
void ECPGmake_struct_member(char *, struct ECPGtype *, struct ECPGstruct_member **);
2929
struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, long);
3030
struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long);
3131
struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, long);
@@ -81,3 +81,9 @@ struct index
8181
int index2;
8282
char *str;
8383
};
84+
85+
struct this_type
86+
{
87+
enum ECPGttype type_enum;
88+
char *type_str;
89+
};

0 commit comments

Comments
 (0)