Skip to content

Commit a13c1ed

Browse files
author
Michael Meskes
committed
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
1 parent f8b54fe commit a13c1ed

File tree

6 files changed

+69
-22
lines changed

6 files changed

+69
-22
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,12 @@ Tu Jan 24 10:59:21 CET 2006
19761976

19771977
- Synced parser and keyword list.
19781978
- Added another test case.
1979+
1980+
Sa Feb 4 21:35:03 CET 2006
1981+
1982+
- Added C bit fields to ecpg parser.
1983+
- Added some default rules to lexer.
1984+
- Added log output to prepare statement.
19791985
- Set ecpg library version to 5.2.
19801986
- Set ecpg version to 4.2.1.
19811987

src/interfaces/ecpg/ecpglib/prepare.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.15 2005/11/30 12:49:49 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.16 2006/02/04 20:54:42 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -100,6 +100,8 @@ ECPGprepare(int lineno, const char *name, const char *variable)
100100
/* add prepared statement to our list */
101101
this->name = ECPGstrdup(name, lineno);
102102
this->stmt = stmt;
103+
ECPGlog("ECPGprepare line %d: QUERY: %s\n", stmt->lineno, stmt->command);
104+
103105

104106
if (prep_stmts == NULL)
105107
this->next = NULL;

src/interfaces/ecpg/preproc/pgc.l

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.141 2006/02/04 02:32:38 momjian Exp $
15+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.142 2006/02/04 20:54:42 meskes Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -787,6 +787,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
787787
}
788788
}
789789
}
790+
<C>":" { return(':'); }
790791
<C>";" { return(';'); }
791792
<C>"," { return(','); }
792793
<C>"*" { return('*'); }
@@ -1001,8 +1002,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
10011002

10021003
for (defptr = defines;
10031004
defptr != NULL && strcmp(yytext, defptr->old) != 0;
1004-
defptr = defptr->next)
1005-
;
1005+
defptr = defptr->next);
10061006

10071007
preproc_tos++;
10081008
stacked_if_value[preproc_tos].else_branch = FALSE;
@@ -1016,11 +1016,19 @@ cppline {space}*#(.*\\{space})*.*{newline}
10161016
BEGIN(xskip);
10171017
}
10181018

1019+
<xcond>{other} {
1020+
mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL IFDEF' command");
1021+
yyterminate();
1022+
}
10191023
<def_ident>{identifier} {
10201024
old = mm_strdup(yytext);
10211025
BEGIN(def);
10221026
startlit();
10231027
}
1028+
<def_ident>{other} {
1029+
mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL DEFINE' command");
1030+
yyterminate();
1031+
}
10241032
<def>{space}*";" {
10251033
struct _defines *ptr, *this;
10261034

@@ -1048,10 +1056,13 @@ cppline {space}*#(.*\\{space})*.*{newline}
10481056
BEGIN(C);
10491057
}
10501058
<def>[^;] { addlit(yytext, yyleng); }
1051-
10521059
<incl>\<[^\>]+\>{space}*";"? { parse_include(); }
10531060
<incl>{dquote}{xdinside}{dquote}{space}*";"? { parse_include(); }
10541061
<incl>[^;\<\>\"]+";" { parse_include(); }
1062+
<incl>{other} {
1063+
mmerror(PARSE_ERROR, ET_FATAL, "Incorrect 'EXEC SQL INCLUDE' command");
1064+
yyterminate();
1065+
}
10551066

10561067
<<EOF>> {
10571068
if (yy_buffer == NULL)

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.318 2006/02/03 05:38:35 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.319 2006/02/04 20:54:42 meskes Exp $ */
22

33
/* Copyright comment */
44
%{
@@ -575,7 +575,7 @@ add_additional_variables(char *name, bool insert)
575575
%type <str> ECPGTypeName using_list ECPGColLabelCommon UsingConst
576576
%type <str> inf_val_list inf_col_list using_descriptor into_descriptor
577577
%type <str> prepared_name struct_union_type_with_symbol OptConsTableSpace
578-
%type <str> ECPGunreserved ECPGunreserved_interval cvariable
578+
%type <str> ECPGunreserved ECPGunreserved_interval cvariable opt_bit_field
579579
%type <str> AlterOwnerStmt OptTableSpaceOwner CreateTableSpaceStmt
580580
%type <str> DropTableSpaceStmt indirection indirection_el ECPGSetDescriptorHeader
581581
%type <str> AlterDatabaseStmt CreateRoleStmt OptRoleList AlterRoleStmt AlterRoleSetStmt
@@ -4740,9 +4740,9 @@ single_var_declaration: storage_declaration
47404740

47414741
actual_startline[struct_level] = hashline_number();
47424742
}
4743-
variable_list ';'
4743+
variable_list opt_bit_field';'
47444744
{
4745-
$$ = cat_str(5, actual_startline[struct_level], $1, $2.type_str, $4, make_str(";\n"));
4745+
$$ = cat_str(6, actual_startline[struct_level], $1, $2.type_str, $4, $5, make_str(";\n"));
47464746
}
47474747
| var_type
47484748
{
@@ -4753,9 +4753,9 @@ single_var_declaration: storage_declaration
47534753

47544754
actual_startline[struct_level] = hashline_number();
47554755
}
4756-
variable_list ';'
4756+
variable_list opt_bit_field';'
47574757
{
4758-
$$ = cat_str(4, actual_startline[struct_level], $1.type_str, $3, make_str(";\n"));
4758+
$$ = cat_str(5, actual_startline[struct_level], $1.type_str, $3, $4, make_str(";\n"));
47594759
}
47604760
| struct_union_type_with_symbol ';'
47614761
{
@@ -4875,9 +4875,9 @@ var_declaration: storage_declaration
48754875

48764876
actual_startline[struct_level] = hashline_number();
48774877
}
4878-
variable_list ';'
4878+
variable_list opt_bit_field';'
48794879
{
4880-
$$ = cat_str(5, actual_startline[struct_level], $1, $2.type_str, $4, make_str(";\n"));
4880+
$$ = cat_str(6, actual_startline[struct_level], $1, $2.type_str, $4, $5, make_str(";\n"));
48814881
}
48824882
| var_type
48834883
{
@@ -4888,16 +4888,20 @@ var_declaration: storage_declaration
48884888

48894889
actual_startline[struct_level] = hashline_number();
48904890
}
4891-
variable_list ';'
4891+
variable_list opt_bit_field';'
48924892
{
4893-
$$ = cat_str(4, actual_startline[struct_level], $1.type_str, $3, make_str(";\n"));
4893+
$$ = cat_str(5, actual_startline[struct_level], $1.type_str, $3, $4, make_str(";\n"));
48944894
}
48954895
| struct_union_type_with_symbol ';'
48964896
{
48974897
$$ = cat2_str($1, make_str(";"));
48984898
}
48994899
;
49004900

4901+
opt_bit_field: ':' Iconst { $$ =cat2_str(make_str(":"), $2); }
4902+
| /* EMPTY */ { $$ = EMPTY; }
4903+
;
4904+
49014905
storage_declaration: storage_clause storage_modifier
49024906
{$$ = cat2_str ($1, $2); }
49034907
| storage_clause {$$ = $1; }
@@ -5808,13 +5812,13 @@ ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action
58085812
{
58095813
when_error.code = $<action>3.code;
58105814
when_error.command = $<action>3.command;
5811-
$$ = cat_str(3, make_str("/* exec sql whenever sqlerror "), $3.str, make_str("; */\n"));
5815+
$$ = cat_str(3, make_str("/* exec sql whenever sqlerror "), $3.str, make_str("; */"));
58125816
}
58135817
| SQL_WHENEVER NOT SQL_FOUND action
58145818
{
58155819
when_nf.code = $<action>4.code;
58165820
when_nf.command = $<action>4.command;
5817-
$$ = cat_str(3, make_str("/* exec sql whenever not found "), $4.str, make_str("; */\n"));
5821+
$$ = cat_str(3, make_str("/* exec sql whenever not found "), $4.str, make_str("; */"));
58185822
}
58195823
| SQL_WHENEVER SQL_SQLWARNING action
58205824
{
@@ -6531,6 +6535,7 @@ c_thing: c_anything { $$ = $1; }
65316535
| ')' { $$ = make_str(")"); }
65326536
| ',' { $$ = make_str(","); }
65336537
| ';' { $$ = make_str(";"); }
6538+
| ':' { $$ = make_str(":"); }
65346539
;
65356540

65366541
c_anything: IDENT { $$ = $1; }

src/interfaces/ecpg/test/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.51 2006/01/24 11:01:38 meskes Exp $
1+
# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.52 2006/02/04 20:54:44 meskes Exp $
22

33
subdir = src/interfaces/ecpg/test
44
top_builddir = ../../../..
@@ -27,6 +27,9 @@ test_informix: test_informix.o
2727
test_informix2: test_informix2.o
2828
$(CC) $(CFLAGS) $(LDFLAGS) -L../compatlib -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lecpg_compat -lpq $(PTHREAD_LIBS) -o $@
2929

30+
test4: test4.o
31+
$(CC) $(CFLAGS) $(LDFLAGS) -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lpq $(PTHREAD_LIBS) -o $@
32+
3033
%.c: %.pgc
3134
$(ECPG) -o $@ -I$(srcdir) $<
3235

@@ -36,5 +39,8 @@ test_informix.c: test_informix.pgc
3639
test_informix2.c: test_informix2.pgc
3740
$(ECPG) -o $@ -C INFORMIX $<
3841

42+
test4.c: test4.pgc
43+
$(ECPG) -o $@ -c $<
44+
3945
clean:
4046
rm -f $(TESTS) $(TESTS:%=%.o) $(TESTS:%=%.c) log

src/interfaces/ecpg/test/test4.pgc

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@ exec sql whenever sqlerror sqlprint;
66

77
exec sql include sqlca;
88

9+
EXEC SQL type errtype is enum
10+
{
11+
OK = 0,
12+
ERR = 1,
13+
WARN = 2
14+
};
15+
916
int
1017
main (void)
1118
{
1219
EXEC SQL BEGIN DECLARE SECTION;
20+
struct
21+
{
22+
errtype e :2;
23+
int code :14;
24+
} error = {1, 147};
1325
int i = 1;
1426
int *did = &i;
1527
int a[10] = {9,8,7,6,5,4,3,2,1,0};
@@ -34,13 +46,18 @@ EXEC SQL END DECLARE SECTION;
3446

3547
EXEC SQL BEGIN WORK;
3648

37-
EXEC SQL CREATE TABLE test (f float, i int, a int[10], text char(10), b bool);
49+
EXEC SQL CREATE TABLE test (f float, i int, a int[10], text char(10), b bool, t int, err int);
3850

39-
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');
51+
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);
4052

41-
EXEC SQL INSERT INTO test(f,i,a,text,b) VALUES(140787.0,2,:a,:text,'t');
53+
EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(140787.0,2,:a,:text,'t',2,14);
4254

43-
EXEC SQL INSERT INTO test(f,i,a,text,b) VALUES(14.07,:did,:a,:t,:b);
55+
EXEC SQL IFDEF BIT_FIELD_IS_NOT_ACCESSIBLE;
56+
EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(14.07,:did,:a,:t,:b,:error);
57+
EXEC SQL ELSE;
58+
EXEC SQL INSERT INTO test(f,i,a,text,b,t,err) VALUES(14.07,:did,:a,:t,:b,1,147);
59+
error.code=0;
60+
EXEC SQL ENDIF;
4461

4562
EXEC SQL COMMIT;
4663

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy