Commit a13c1edb authored by Michael Meskes's avatar Michael Meskes

Added C bit fields to ecpg parser

Added some default rules to lexer
Added log output to prepare statement
Added some more stuff to a test case
parent f8b54fe6
...@@ -1976,6 +1976,12 @@ Tu Jan 24 10:59:21 CET 2006 ...@@ -1976,6 +1976,12 @@ Tu Jan 24 10:59:21 CET 2006
- Synced parser and keyword list. - Synced parser and keyword list.
- Added another test case. - Added another test case.
Sa Feb 4 21:35:03 CET 2006
- Added C bit fields to ecpg parser.
- Added some default rules to lexer.
- Added log output to prepare statement.
- Set ecpg library version to 5.2. - Set ecpg library version to 5.2.
- Set ecpg version to 4.2.1. - Set ecpg version to 4.2.1.
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.15 2005/11/30 12:49:49 meskes Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.16 2006/02/04 20:54:42 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL #define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -100,6 +100,8 @@ ECPGprepare(int lineno, const char *name, const char *variable) ...@@ -100,6 +100,8 @@ ECPGprepare(int lineno, const char *name, const char *variable)
/* add prepared statement to our list */ /* add prepared statement to our list */
this->name = ECPGstrdup(name, lineno); this->name = ECPGstrdup(name, lineno);
this->stmt = stmt; this->stmt = stmt;
ECPGlog("ECPGprepare line %d: QUERY: %s\n", stmt->lineno, stmt->command);
if (prep_stmts == NULL) if (prep_stmts == NULL)
this->next = NULL; this->next = NULL;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.141 2006/02/04 02:32:38 momjian Exp $ * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.142 2006/02/04 20:54:42 meskes Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -787,6 +787,7 @@ cppline {space}*#(.*\\{space})*.*{newline} ...@@ -787,6 +787,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
} }
} }
} }
<C>":" { return(':'); }
<C>";" { return(';'); } <C>";" { return(';'); }
<C>"," { return(','); } <C>"," { return(','); }
<C>"*" { return('*'); } <C>"*" { return('*'); }
...@@ -1001,8 +1002,7 @@ cppline {space}*#(.*\\{space})*.*{newline} ...@@ -1001,8 +1002,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
for (defptr = defines; for (defptr = defines;
defptr != NULL && strcmp(yytext, defptr->old) != 0; defptr != NULL && strcmp(yytext, defptr->old) != 0;
defptr = defptr->next) defptr = defptr->next);
;
preproc_tos++; preproc_tos++;
stacked_if_value[preproc_tos].else_branch = FALSE; stacked_if_value[preproc_tos].else_branch = FALSE;
...@@ -1016,11 +1016,19 @@ cppline {space}*#(.*\\{space})*.*{newline} ...@@ -1016,11 +1016,19 @@ cppline {space}*#(.*\\{space})*.*{newline}
BEGIN(xskip); BEGIN(xskip);
} }
<xcond>{other} {
mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL IFDEF' command");
yyterminate();
}
<def_ident>{identifier} { <def_ident>{identifier} {
old = mm_strdup(yytext); old = mm_strdup(yytext);
BEGIN(def); BEGIN(def);
startlit(); startlit();
} }
<def_ident>{other} {
mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL DEFINE' command");
yyterminate();
}
<def>{space}*";" { <def>{space}*";" {
struct _defines *ptr, *this; struct _defines *ptr, *this;
...@@ -1048,10 +1056,13 @@ cppline {space}*#(.*\\{space})*.*{newline} ...@@ -1048,10 +1056,13 @@ cppline {space}*#(.*\\{space})*.*{newline}
BEGIN(C); BEGIN(C);
} }
<def>[^;] { addlit(yytext, yyleng); } <def>[^;] { addlit(yytext, yyleng); }
<incl>\<[^\>]+\>{space}*";"? { parse_include(); } <incl>\<[^\>]+\>{space}*";"? { parse_include(); }
<incl>{dquote}{xdinside}{dquote}{space}*";"? { parse_include(); } <incl>{dquote}{xdinside}{dquote}{space}*";"? { parse_include(); }
<incl>[^;\<\>\"]+";" { parse_include(); } <incl>[^;\<\>\"]+";" { parse_include(); }
<incl>{other} {
mmerror(PARSE_ERROR, ET_FATAL, "Incorrect 'EXEC SQL INCLUDE' command");
yyterminate();
}
<<EOF>> { <<EOF>> {
if (yy_buffer == NULL) if (yy_buffer == NULL)
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.318 2006/02/03 05:38:35 momjian Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.319 2006/02/04 20:54:42 meskes Exp $ */
/* Copyright comment */ /* Copyright comment */
%{ %{
...@@ -575,7 +575,7 @@ add_additional_variables(char *name, bool insert) ...@@ -575,7 +575,7 @@ add_additional_variables(char *name, bool insert)
%type <str> ECPGTypeName using_list ECPGColLabelCommon UsingConst %type <str> ECPGTypeName using_list ECPGColLabelCommon UsingConst
%type <str> inf_val_list inf_col_list using_descriptor into_descriptor %type <str> inf_val_list inf_col_list using_descriptor into_descriptor
%type <str> prepared_name struct_union_type_with_symbol OptConsTableSpace %type <str> prepared_name struct_union_type_with_symbol OptConsTableSpace
%type <str> ECPGunreserved ECPGunreserved_interval cvariable %type <str> ECPGunreserved ECPGunreserved_interval cvariable opt_bit_field
%type <str> AlterOwnerStmt OptTableSpaceOwner CreateTableSpaceStmt %type <str> AlterOwnerStmt OptTableSpaceOwner CreateTableSpaceStmt
%type <str> DropTableSpaceStmt indirection indirection_el ECPGSetDescriptorHeader %type <str> DropTableSpaceStmt indirection indirection_el ECPGSetDescriptorHeader
%type <str> AlterDatabaseStmt CreateRoleStmt OptRoleList AlterRoleStmt AlterRoleSetStmt %type <str> AlterDatabaseStmt CreateRoleStmt OptRoleList AlterRoleStmt AlterRoleSetStmt
...@@ -4740,9 +4740,9 @@ single_var_declaration: storage_declaration ...@@ -4740,9 +4740,9 @@ single_var_declaration: storage_declaration
actual_startline[struct_level] = hashline_number(); actual_startline[struct_level] = hashline_number();
} }
variable_list ';' variable_list opt_bit_field';'
{ {
$$ = cat_str(5, actual_startline[struct_level], $1, $2.type_str, $4, make_str(";\n")); $$ = cat_str(6, actual_startline[struct_level], $1, $2.type_str, $4, $5, make_str(";\n"));
} }
| var_type | var_type
{ {
...@@ -4753,9 +4753,9 @@ single_var_declaration: storage_declaration ...@@ -4753,9 +4753,9 @@ single_var_declaration: storage_declaration
actual_startline[struct_level] = hashline_number(); actual_startline[struct_level] = hashline_number();
} }
variable_list ';' variable_list opt_bit_field';'
{ {
$$ = cat_str(4, actual_startline[struct_level], $1.type_str, $3, make_str(";\n")); $$ = cat_str(5, actual_startline[struct_level], $1.type_str, $3, $4, make_str(";\n"));
} }
| struct_union_type_with_symbol ';' | struct_union_type_with_symbol ';'
{ {
...@@ -4875,9 +4875,9 @@ var_declaration: storage_declaration ...@@ -4875,9 +4875,9 @@ var_declaration: storage_declaration
actual_startline[struct_level] = hashline_number(); actual_startline[struct_level] = hashline_number();
} }
variable_list ';' variable_list opt_bit_field';'
{ {
$$ = cat_str(5, actual_startline[struct_level], $1, $2.type_str, $4, make_str(";\n")); $$ = cat_str(6, actual_startline[struct_level], $1, $2.type_str, $4, $5, make_str(";\n"));
} }
| var_type | var_type
{ {
...@@ -4888,9 +4888,9 @@ var_declaration: storage_declaration ...@@ -4888,9 +4888,9 @@ var_declaration: storage_declaration
actual_startline[struct_level] = hashline_number(); actual_startline[struct_level] = hashline_number();
} }
variable_list ';' variable_list opt_bit_field';'
{ {
$$ = cat_str(4, actual_startline[struct_level], $1.type_str, $3, make_str(";\n")); $$ = cat_str(5, actual_startline[struct_level], $1.type_str, $3, $4, make_str(";\n"));
} }
| struct_union_type_with_symbol ';' | struct_union_type_with_symbol ';'
{ {
...@@ -4898,6 +4898,10 @@ var_declaration: storage_declaration ...@@ -4898,6 +4898,10 @@ var_declaration: storage_declaration
} }
; ;
opt_bit_field: ':' Iconst { $$ =cat2_str(make_str(":"), $2); }
| /* EMPTY */ { $$ = EMPTY; }
;
storage_declaration: storage_clause storage_modifier storage_declaration: storage_clause storage_modifier
{$$ = cat2_str ($1, $2); } {$$ = cat2_str ($1, $2); }
| storage_clause {$$ = $1; } | storage_clause {$$ = $1; }
...@@ -5808,13 +5812,13 @@ ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action ...@@ -5808,13 +5812,13 @@ ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action
{ {
when_error.code = $<action>3.code; when_error.code = $<action>3.code;
when_error.command = $<action>3.command; when_error.command = $<action>3.command;
$$ = cat_str(3, make_str("/* exec sql whenever sqlerror "), $3.str, make_str("; */\n")); $$ = cat_str(3, make_str("/* exec sql whenever sqlerror "), $3.str, make_str("; */"));
} }
| SQL_WHENEVER NOT SQL_FOUND action | SQL_WHENEVER NOT SQL_FOUND action
{ {
when_nf.code = $<action>4.code; when_nf.code = $<action>4.code;
when_nf.command = $<action>4.command; when_nf.command = $<action>4.command;
$$ = cat_str(3, make_str("/* exec sql whenever not found "), $4.str, make_str("; */\n")); $$ = cat_str(3, make_str("/* exec sql whenever not found "), $4.str, make_str("; */"));
} }
| SQL_WHENEVER SQL_SQLWARNING action | SQL_WHENEVER SQL_SQLWARNING action
{ {
...@@ -6531,6 +6535,7 @@ c_thing: c_anything { $$ = $1; } ...@@ -6531,6 +6535,7 @@ c_thing: c_anything { $$ = $1; }
| ')' { $$ = make_str(")"); } | ')' { $$ = make_str(")"); }
| ',' { $$ = make_str(","); } | ',' { $$ = make_str(","); }
| ';' { $$ = make_str(";"); } | ';' { $$ = make_str(";"); }
| ':' { $$ = make_str(":"); }
; ;
c_anything: IDENT { $$ = $1; } c_anything: IDENT { $$ = $1; }
......
# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.51 2006/01/24 11:01:38 meskes Exp $ # $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.52 2006/02/04 20:54:44 meskes Exp $
subdir = src/interfaces/ecpg/test subdir = src/interfaces/ecpg/test
top_builddir = ../../../.. top_builddir = ../../../..
...@@ -27,6 +27,9 @@ test_informix: test_informix.o ...@@ -27,6 +27,9 @@ test_informix: test_informix.o
test_informix2: test_informix2.o test_informix2: test_informix2.o
$(CC) $(CFLAGS) $(LDFLAGS) -L../compatlib -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lecpg_compat -lpq $(PTHREAD_LIBS) -o $@ $(CC) $(CFLAGS) $(LDFLAGS) -L../compatlib -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lecpg_compat -lpq $(PTHREAD_LIBS) -o $@
test4: test4.o
$(CC) $(CFLAGS) $(LDFLAGS) -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lpq $(PTHREAD_LIBS) -o $@
%.c: %.pgc %.c: %.pgc
$(ECPG) -o $@ -I$(srcdir) $< $(ECPG) -o $@ -I$(srcdir) $<
...@@ -36,5 +39,8 @@ test_informix.c: test_informix.pgc ...@@ -36,5 +39,8 @@ test_informix.c: test_informix.pgc
test_informix2.c: test_informix2.pgc test_informix2.c: test_informix2.pgc
$(ECPG) -o $@ -C INFORMIX $< $(ECPG) -o $@ -C INFORMIX $<
test4.c: test4.pgc
$(ECPG) -o $@ -c $<
clean: clean:
rm -f $(TESTS) $(TESTS:%=%.o) $(TESTS:%=%.c) log rm -f $(TESTS) $(TESTS:%=%.o) $(TESTS:%=%.c) log
...@@ -6,10 +6,22 @@ exec sql whenever sqlerror sqlprint; ...@@ -6,10 +6,22 @@ exec sql whenever sqlerror sqlprint;
exec sql include sqlca; exec sql include sqlca;
EXEC SQL type errtype is enum
{
OK = 0,
ERR = 1,
WARN = 2
};
int int
main (void) main (void)
{ {
EXEC SQL BEGIN DECLARE SECTION; EXEC SQL BEGIN DECLARE SECTION;
struct
{
errtype e :2;
int code :14;
} error = {1, 147};
int i = 1; int i = 1;
int *did = &i; int *did = &i;
int a[10] = {9,8,7,6,5,4,3,2,1,0}; int a[10] = {9,8,7,6,5,4,3,2,1,0};
...@@ -34,13 +46,18 @@ EXEC SQL END DECLARE SECTION; ...@@ -34,13 +46,18 @@ EXEC SQL END DECLARE SECTION;
EXEC SQL BEGIN WORK; EXEC SQL BEGIN WORK;
EXEC SQL CREATE TABLE test (f float, i int, a int[10], text char(10), b bool); EXEC SQL CREATE TABLE test (f float, i int, a int[10], text char(10), b bool, t int, err int);
EXEC SQL INSERT INTO test(f,i,a,text,b) VALUES(404.90,3,'{0,1,2,3,4,5,6,7,8,9}','abcdefghij', 'f'); EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(404.90,3,'{0,1,2,3,4,5,6,7,8,9}','abcdefghij','f',0,0);
EXEC SQL INSERT INTO test(f,i,a,text,b) VALUES(140787.0,2,:a,:text,'t'); EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(140787.0,2,:a,:text,'t',2,14);
EXEC SQL INSERT INTO test(f,i,a,text,b) VALUES(14.07,:did,:a,:t,:b); EXEC SQL IFDEF BIT_FIELD_IS_NOT_ACCESSIBLE;
EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(14.07,:did,:a,:t,:b,:error);
EXEC SQL ELSE;
EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(14.07,:did,:a,:t,:b,1,147);
error.code=0;
EXEC SQL ENDIF;
EXEC SQL COMMIT; EXEC SQL COMMIT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment