From a13c1edb570a79181712ace9eb5c7d1a696003f1 Mon Sep 17 00:00:00 2001
From: Michael Meskes <meskes@postgresql.org>
Date: Sat, 4 Feb 2006 20:54:44 +0000
Subject: [PATCH] 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

---
 src/interfaces/ecpg/ChangeLog         |  6 ++++++
 src/interfaces/ecpg/ecpglib/prepare.c |  4 +++-
 src/interfaces/ecpg/preproc/pgc.l     | 19 ++++++++++++++----
 src/interfaces/ecpg/preproc/preproc.y | 29 ++++++++++++++++-----------
 src/interfaces/ecpg/test/Makefile     |  8 +++++++-
 src/interfaces/ecpg/test/test4.pgc    | 25 +++++++++++++++++++----
 6 files changed, 69 insertions(+), 22 deletions(-)

diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog
index eed803e50ed..6f447bc9792 100644
--- a/src/interfaces/ecpg/ChangeLog
+++ b/src/interfaces/ecpg/ChangeLog
@@ -1976,6 +1976,12 @@ Tu Jan 24 10:59:21 CET 2006
 
 	- Synced parser and keyword list.
 	- 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 version to 4.2.1.
 
diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c
index 555c981c024..0401fe55651 100644
--- a/src/interfaces/ecpg/ecpglib/prepare.c
+++ b/src/interfaces/ecpg/ecpglib/prepare.c
@@ -1,4 +1,4 @@
-/* $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
 #include "postgres_fe.h"
@@ -100,6 +100,8 @@ ECPGprepare(int lineno, const char *name, const char *variable)
 	/* add prepared statement to our list */
 	this->name = ECPGstrdup(name, lineno);
 	this->stmt = stmt;
+	ECPGlog("ECPGprepare line %d: QUERY: %s\n", stmt->lineno, stmt->command);
+		
 
 	if (prep_stmts == NULL)
 		this->next = NULL;
diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l
index b9a6cfa60b1..d89bbad9782 100644
--- a/src/interfaces/ecpg/preproc/pgc.l
+++ b/src/interfaces/ecpg/preproc/pgc.l
@@ -12,7 +12,7 @@
  *
  *
  * 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}
 							}
 						}
 					}
+<C>":"				{ return(':'); }
 <C>";"				{ return(';'); }
 <C>","				{ return(','); }
 <C>"*"				{ return('*'); }
@@ -1001,8 +1002,7 @@ cppline			{space}*#(.*\\{space})*.*{newline}
 
 						for (defptr = defines;
 							 defptr != NULL && strcmp(yytext, defptr->old) != 0;
-							 defptr = defptr->next)
-							;
+							 defptr = defptr->next);
 
 						preproc_tos++;
 						stacked_if_value[preproc_tos].else_branch = FALSE;
@@ -1016,11 +1016,19 @@ cppline			{space}*#(.*\\{space})*.*{newline}
 						BEGIN(xskip);
 				}
 
+<xcond>{other}	{
+			mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL IFDEF' command");
+			yyterminate();
+		}
 <def_ident>{identifier} {
 				old = mm_strdup(yytext);
 				BEGIN(def);
 				startlit();
 			}
+<def_ident>{other}	{
+			mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL DEFINE' command");
+			yyterminate();
+		}
 <def>{space}*";"	{
 						struct _defines *ptr, *this;
 
@@ -1048,10 +1056,13 @@ cppline			{space}*#(.*\\{space})*.*{newline}
 						BEGIN(C);
 					}
 <def>[^;]			{ addlit(yytext, yyleng); }
-
 <incl>\<[^\>]+\>{space}*";"?		{	parse_include(); }
 <incl>{dquote}{xdinside}{dquote}{space}*";"?	{	parse_include(); }
 <incl>[^;\<\>\"]+";"		{ parse_include(); }
+<incl>{other}	{
+			mmerror(PARSE_ERROR, ET_FATAL, "Incorrect 'EXEC SQL INCLUDE' command");
+			yyterminate();
+		}
 
 <<EOF>>				{
 			  		if (yy_buffer == NULL)
diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y
index 3fe88a8a749..63b18a1ae8e 100644
--- a/src/interfaces/ecpg/preproc/preproc.y
+++ b/src/interfaces/ecpg/preproc/preproc.y
@@ -1,4 +1,4 @@
-/* $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 */
 %{
@@ -575,7 +575,7 @@ add_additional_variables(char *name, bool insert)
 %type  <str>	ECPGTypeName using_list ECPGColLabelCommon UsingConst
 %type  <str>	inf_val_list inf_col_list using_descriptor into_descriptor
 %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>	DropTableSpaceStmt indirection indirection_el ECPGSetDescriptorHeader
 %type  <str>	AlterDatabaseStmt CreateRoleStmt OptRoleList AlterRoleStmt AlterRoleSetStmt
@@ -4740,9 +4740,9 @@ single_var_declaration: storage_declaration
 
 			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
 		{
@@ -4753,9 +4753,9 @@ single_var_declaration: storage_declaration
 
 			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 ';'
 		{
@@ -4875,9 +4875,9 @@ var_declaration: storage_declaration
 
 			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
 		{
@@ -4888,9 +4888,9 @@ var_declaration: storage_declaration
 
 			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 ';'
 		{
@@ -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
 			{$$ = cat2_str ($1, $2); }
 		| storage_clause		{$$ = $1; }
@@ -5808,13 +5812,13 @@ ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action
 		{
 			when_error.code = $<action>3.code;
 			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
 		{
 			when_nf.code = $<action>4.code;
 			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
 		{
@@ -6531,6 +6535,7 @@ c_thing:	c_anything	{ $$ = $1; }
 		|	')'			{ $$ = make_str(")"); }
 		|	','			{ $$ = make_str(","); }
 		|	';'			{ $$ = make_str(";"); }
+		|	':'			{ $$ = make_str(":"); }
 		;
 
 c_anything:  IDENT			{ $$ = $1; }
diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile
index ad146549215..b1f51eeae88 100644
--- a/src/interfaces/ecpg/test/Makefile
+++ b/src/interfaces/ecpg/test/Makefile
@@ -1,4 +1,4 @@
-# $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
 top_builddir = ../../../..
@@ -27,6 +27,9 @@ test_informix: test_informix.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 $@
 	
+test4: test4.o
+	$(CC) $(CFLAGS) $(LDFLAGS) -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lpq $(PTHREAD_LIBS) -o $@
+
 %.c: %.pgc
 	$(ECPG) -o $@ -I$(srcdir) $<
 
@@ -36,5 +39,8 @@ test_informix.c: test_informix.pgc
 test_informix2.c: test_informix2.pgc
 	$(ECPG) -o $@ -C INFORMIX  $<
 
+test4.c: test4.pgc
+	$(ECPG) -o $@ -c  $<
+
 clean:
 	rm -f $(TESTS) $(TESTS:%=%.o) $(TESTS:%=%.c) log
diff --git a/src/interfaces/ecpg/test/test4.pgc b/src/interfaces/ecpg/test/test4.pgc
index 3e5fae096d5..ae7d90a91fb 100644
--- a/src/interfaces/ecpg/test/test4.pgc
+++ b/src/interfaces/ecpg/test/test4.pgc
@@ -6,10 +6,22 @@ exec sql whenever sqlerror sqlprint;
 
 exec sql include sqlca;
 
+EXEC SQL type errtype is enum
+{
+	OK   = 0,
+	ERR  = 1,
+	WARN = 2
+};
+
 int
 main (void)
 {
 EXEC SQL BEGIN DECLARE SECTION;
+	struct 
+	{
+		errtype e :2;
+		int code :14;
+	} error = {1, 147};
 	int i = 1;
 	int *did = &i;
 	int a[10] = {9,8,7,6,5,4,3,2,1,0};
@@ -34,13 +46,18 @@ EXEC SQL END DECLARE SECTION;
 
  	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;
 
-- 
GitLab