From 74e015916eaa670f8986a13cf523a9bd59b55595 Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Wed, 18 Feb 1998 01:28:03 +0000 Subject: [PATCH] Update the preprocessor code From: Michael Meskes --- src/interfaces/ecpg/ChangeLog | 20 +++-- src/interfaces/ecpg/preproc/Makefile | 8 +- src/interfaces/ecpg/preproc/pgc.l | 10 +++ src/interfaces/ecpg/preproc/preproc.y | 104 ++++++++++++++++++++------ 4 files changed, 107 insertions(+), 35 deletions(-) diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index bee83ee51d..017314777e 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -8,18 +8,24 @@ Wed Feb 11 10:58:13 CET 1998 Thu Feb 12 14:45:07 CET 1998 - - Changed parser to correctly handle local variables. - - Allow static and extern variable definitions. - - free() variable structure completely. + - changed parser to correctly handle local variables. + +Thu Feb 12 15:55:37 CET 1998 + + - allow static and extern variable definitions. + - free() variable structure completely. Fri Feb 13 12:35:58 CET 1998 - - ecpg can use structs to store data, but only if the complete - definition of the struct lies inside the sql declare section - and only simple types used. + - ecpg can use structs to store data, but only if the complete + definition of the struct lies inside the sql declare section + and only simple types used. Fre Feb 13 14:12:41 CET 1998 - - Structure now work completely. + - struct definitions now work completely. +Mon Feb 16 16:17:21 CET 1998 + - enable initialisation in declare section. + - connect call accepts a variable as well. diff --git a/src/interfaces/ecpg/preproc/Makefile b/src/interfaces/ecpg/preproc/Makefile index 5526e6ef45..f7e7304777 100644 --- a/src/interfaces/ecpg/preproc/Makefile +++ b/src/interfaces/ecpg/preproc/Makefile @@ -2,16 +2,16 @@ SRCDIR= ../../.. include $(SRCDIR)/Makefile.global -MAJOR_VERSION=0 -MINOR_VERSION=5 -PATCHLEVEL=1 +MAJOR_VERSION=1 +MINOR_VERSION=0 +PATCHLEVEL=0 CFLAGS=-I../include -O2 -g -Wall -DMAJOR_VERSION=$(MAJOR_VERSION) -DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL) all:: ecpg clean: - rm -f *.o core a.out ecpg preproc.tab.h y.tab.c *~ + rm -f *.o core a.out ecpg y.tab.h y.tab.c *~ install: all install -c -m 755 ecpg $(DESTDIR)$(BINDIR) diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l index 63e9f8d6e8..2f87d6ffd4 100644 --- a/src/interfaces/ecpg/preproc/pgc.l +++ b/src/interfaces/ecpg/preproc/pgc.l @@ -18,6 +18,7 @@ symbol {letter}({letter}|{digit})* string '[^']*' exec [eE][xX][eE][cC] +execute [eE][xX][eE][cC][uU][tT][eE] sql [sS][qQ][lL] varchar [vV][aA][rR][cC][hH][aA][rR] varchar2 [vV][aA][rR][cC][hH][aA][rR]2 @@ -30,18 +31,25 @@ include [iI][nN][cC][lL][uU][dD][eE] connect [cC][oO][nN][nN][eE][cC][tT] open [oO][pP][eE][nN] commit [cC][oO][mM][mM][iI][tT] +immediate [iI][mM][mM][eE][dD][iI][aA][tT][eE] +release [rR][eE][lL][eE][aA][sS][eE] rollback [rR][oO][lL][lL][bB][aA][cC][kK] +work [wW][oO][rR][kK] %% {exec}{ws}{sql} { BEGIN SQL; dbg(SQL_START); return SQL_START; } ";" { BEGIN C; dbg(SQL_SEMI); return SQL_SEMI; } {begin} { dbg(SQL_BEGIN); return SQL_BEGIN; } {end} { dbg(SQL_END); return SQL_END; } {declare} { dbg(SQL_DECLARE); return SQL_DECLARE; } +{execute} { dbg(SQL_EXECUTE); return SQL_EXECUTE; } +{immediate} { dbg(SQL_IMMEDIATE); return SQL_IMMEDIATE; } {section} { dbg(SQL_SECTION); return SQL_SECTION; } {include} { dbg(SQL_INCLUDE); return SQL_INCLUDE; } {connect} { dbg(SQL_CONNECT); return SQL_CONNECT; } {open} { dbg(SQL_OPEN); return SQL_OPEN; } {commit} { dbg(SQL_COMMIT); return SQL_COMMIT; } +{release} { dbg(SQL_RELEASE); return SQL_RELEASE; } +{work} { dbg(SQL_WORK); return SQL_WORK; } {rollback} { dbg(SQL_ROLLBACK); return SQL_ROLLBACK; } {into} { dbg(SQL_INTO); return SQL_INTO; } @@ -104,9 +112,11 @@ struct { dbg(S_STRUCT); return S_STRUCT; } "[" { dbg([); return '['; } "]" { dbg(]); return ']'; } ";" { dbg(;); return ';'; } +"=" { dbg(=); return '='; } "," { dbg(komma); return ','; } \{ { dbg(blockstart); return '{'; } \} { dbg(blockend); return'}'; } +\* { dbg(*); return('*'); } ":" { dbg(:); return ':'; } diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index 79eec60af1..670ea9b8c6 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -180,22 +180,22 @@ dump_variables(struct arguments * list) %token SQL_START SQL_SEMI SQL_STRING SQL_INTO %token SQL_BEGIN SQL_END SQL_DECLARE SQL_SECTION SQL_INCLUDE -%token SQL_CONNECT SQL_OPEN -%token SQL_COMMIT SQL_ROLLBACK +%token SQL_CONNECT SQL_OPEN SQL_EXECUTE SQL_IMMEDIATE +%token SQL_COMMIT SQL_ROLLBACK SQL_RELEASE SQL_WORK %token S_SYMBOL S_LENGTH S_ANYTHING %token S_VARCHAR S_VARCHAR2 %token S_EXTERN S_STATIC S_AUTO S_CONST S_REGISTER S_STRUCT %token S_UNSIGNED S_SIGNED %token S_LONG S_SHORT S_INT S_CHAR S_FLOAT S_DOUBLE S_BOOL -%token '[' ']' ';' ',' '{' '}' +%token '[' ']' ';' ',' '{' '}' '=' '*' %type type type_detailed varchar_type simple_type array_type struct_type %type symbol -%type maybe_storage_clause varchar_tag +%type maybe_storage_clause varchar_tag db_name %type simple_tag %type index length -%type canything sqlanything both_anything +%type canything sqlanything both_anything vartext commit_release %% @@ -210,6 +210,7 @@ statement : sqldeclaration | sqlopen | sqlcommit | sqlrollback + | sqlexecute | sqlstatement | cthing | blockstart @@ -222,17 +223,18 @@ sqldeclaration : sql_startdeclare sql_startdeclare : SQL_START SQL_BEGIN SQL_DECLARE SQL_SECTION SQL_SEMI { fprintf(yyout, "/* exec sql begin declare section */\n"); output_line_number(); -}; +} + sql_enddeclare : SQL_START SQL_END SQL_DECLARE SQL_SECTION SQL_SEMI { fprintf(yyout,"/* exec sql end declare section */\n"); output_line_number(); -}; +} variable_declarations : /* empty */ - | variable_declarations variable_declaration ; + | variable_declarations variable_declaration; /* Here is where we can enter support for typedef. */ -variable_declaration : type ';' { +variable_declaration : type initializer ';' { /* don't worry about our list when we're working on a struct */ if (struct_level == 0) { @@ -242,6 +244,12 @@ variable_declaration : type ';' { fprintf(yyout, ";"); } +initializer : /*empty */ + | '=' {fwrite(yytext, yyleng, 1, yyout);} vartext; + +vartext : both_anything {fwrite(yytext, yyleng, 1, yyout);} + | vartext both_anything {fwrite(yytext, yyleng, 1, yyout);} + symbol : S_SYMBOL { char * name = (char *)malloc(yyleng + 1); @@ -255,10 +263,14 @@ type : maybe_storage_clause type_detailed { $$ = $2; }; type_detailed : varchar_type { $$ = $1; } | simple_type { $$ = $1; } | array_type {$$ = $1; } + | pointer_type {$$ = $1; } | struct_type {$$ = $1; }; varchar_type : varchar_tag symbol index { - fprintf(yyout, "struct varchar_%s { int len; char arr[%d]; } %s", $2, $3, $2); + if ($3 > 0) + fprintf(yyout, "struct varchar_%s { int len; char arr[%d]; } %s", $2, $3, $2); + else + fprintf(yyout, "struct varchar_%s { int len; char arr[%d]; } %s", $2, $3, $2); if (struct_level == 0) { $$.name = $2; @@ -283,7 +295,10 @@ simple_type : simple_tag symbol { } array_type : simple_tag symbol index { - fprintf(yyout, "%s %s [%d]", ECPGtype_name($1), $2, $3); + if ($3 > 0) + fprintf(yyout, "%s %s [%d]", ECPGtype_name($1), $2, $3); + else + fprintf(yyout, "%s %s []", ECPGtype_name($1), $2); if (struct_level == 0) { $$.name = $2; @@ -293,6 +308,17 @@ array_type : simple_tag symbol index { ECPGmake_record_member($2, ECPGmake_array_type(ECPGmake_simple_type($1), $3), &(record_member_list[struct_level-1])); } +pointer_type : simple_tag '*' symbol { + fprintf(yyout, "%s * %s", ECPGtype_name($1), $3); + if (struct_level == 0) + { + $$.name = $3; + $$.typ = ECPGmake_array_type(ECPGmake_simple_type($1), 0); + } + else + ECPGmake_record_member($3, ECPGmake_array_type(ECPGmake_simple_type($1), 0), &(record_member_list[struct_level-1])); +} + s_struct : S_STRUCT symbol { struct_level++; fprintf(yyout, "struct %s {", $2); @@ -330,9 +356,8 @@ maybe_storage_clause : S_EXTERN { fwrite(yytext, yyleng, 1, yyout); } | S_AUTO { fwrite(yytext, yyleng, 1, yyout); } | /* empty */ { }; -index : '[' length ']' { - $$ = $2; -}; +index : '[' length ']' { $$ = $2; } + | '[' ']' { $$ = 0; } length : S_LENGTH { $$ = atoi(yytext); } @@ -342,9 +367,24 @@ sqlinclude : SQL_START SQL_INCLUDE { fprintf(yyout, "#include \""); } filename : cthing | filename cthing; -sqlconnect : SQL_START SQL_CONNECT { fprintf(yyout, "ECPGconnect(\""); } - SQL_STRING { fwrite(yytext + 1, yyleng - 2, 1, yyout); } - SQL_SEMI { fprintf(yyout, "\");"); output_line_number(); }; +sqlconnect : SQL_START SQL_CONNECT { fprintf(yyout, "ECPGconnect("); } + db_name + SQL_SEMI { fprintf(yyout, ");"); output_line_number();} + +db_name : SQL_STRING { fprintf(yyout, "\""); fwrite(yytext + 1, yyleng - 2, 1, yyout); fprintf(yyout, "\""); } + | ':' symbol { /* check if we have a char variabnle */ + struct variable *p = find_variable($2); + enum ECPGttype typ = p->type->typ; + + /* if array see what's inside */ + if (typ == ECPGt_array) + typ = p->type->u.element->typ; + + if (typ != ECPGt_char && typ != ECPGt_unsigned_char) + yyerror("invalid datatype"); + + fprintf(yyout, "%s", $2); + } /* Open is an open cursor. Removed. */ sqlopen : SQL_START SQL_OPEN sqlgarbage SQL_SEMI { output_line_number(); }; @@ -353,21 +393,37 @@ sqlgarbage : /* Empty */ | sqlgarbage sqlanything; -sqlcommit : SQL_START SQL_COMMIT SQL_SEMI { +sqlcommit : SQL_START commit_release SQL_SEMI { fprintf(yyout, "ECPGcommit(__LINE__);"); output_line_number(); -}; +} + +commit_release : SQL_COMMIT + | SQL_COMMIT SQL_RELEASE + | SQL_COMMIT SQL_WORK SQL_RELEASE; + sqlrollback : SQL_START SQL_ROLLBACK SQL_SEMI { fprintf(yyout, "ECPGrollback(__LINE__);"); output_line_number(); }; +sqlexecute : SQL_START { /* Reset stack */ + reset_variables(); + fprintf(yyout, "ECPGdo(__LINE__, \""); +} SQL_EXECUTE SQL_IMMEDIATE sqlstatement_words SQL_SEMI { + /* Dump */ + fprintf(yyout, "\", "); + dump_variables(argsinsert); + fprintf(yyout, "ECPGt_EOIT, "); + dump_variables(argsresult); + fprintf(yyout, "ECPGt_EORT );"); + output_line_number(); +}; + sqlstatement : SQL_START { /* Reset stack */ reset_variables(); fprintf(yyout, "ECPGdo(__LINE__, \""); -} - sqlstatement_words - SQL_SEMI { +} sqlstatement_words SQL_SEMI { /* Dump */ fprintf(yyout, "\", "); dump_variables(argsinsert); @@ -416,7 +472,7 @@ canything : both_anything sqlanything : both_anything; both_anything : S_LENGTH | S_VARCHAR | S_VARCHAR2 - | S_LONG | S_SHORT | S_INT | S_CHAR | S_FLOAT | S_DOUBLE | S_BOOL + | S_LONG | S_SHORT | S_INT | S_CHAR | S_FLOAT | S_DOUBLE | S_BOOL | SQL_OPEN | SQL_CONNECT | SQL_STRING | SQL_BEGIN | SQL_END @@ -424,7 +480,7 @@ both_anything : S_LENGTH | S_VARCHAR | S_VARCHAR2 | SQL_INCLUDE | S_SYMBOL | S_STATIC | S_EXTERN | S_AUTO | S_CONST | S_REGISTER | S_STRUCT - | '[' | ']' | ',' + | '[' | ']' | ',' | '=' | '*' | S_ANYTHING; blockstart : '{' { -- 2.40.0