Skip to content

Commit 462227d

Browse files
committed
Avoid having backend-only code compiled into ecpg. Per Zdenek Kotala
1 parent 8164fb8 commit 462227d

File tree

4 files changed

+142
-9
lines changed

4 files changed

+142
-9
lines changed

src/interfaces/ecpg/preproc/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1998-2007, PostgreSQL Global Development Group
66
#
7-
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.128 2007/08/22 08:20:58 meskes Exp $
7+
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.129 2007/10/26 14:17:53 tgl Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -59,9 +59,6 @@ endif
5959

6060
c_keywords.o keywords.o preproc.o parser.o: preproc.h
6161

62-
parser.c: $(top_srcdir)/src/backend/parser/parser.c
63-
rm -f $@ && $(LN_S) $< .
64-
6562
distprep: $(srcdir)/preproc.c $(srcdir)/preproc.h $(srcdir)/pgc.c
6663

6764
install: all installdirs
@@ -74,7 +71,7 @@ uninstall:
7471
rm -f '$(DESTDIR)$(bindir)/ecpg$(X)'
7572

7673
clean distclean:
77-
rm -f *.o ecpg$(X) parser.c
74+
rm -f *.o ecpg$(X)
7875
# garbage from partial builds
7976
@rm -f y.tab.c y.tab.h
8077
# garbage from development

src/interfaces/ecpg/preproc/parser.c

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* parser.c
4+
* Main entry point/driver for PostgreSQL grammar
5+
*
6+
* Note that the grammar is not allowed to perform any table access
7+
* (since we need to be able to do basic parsing even while inside an
8+
* aborted transaction). Therefore, the data structures returned by
9+
* the grammar are "raw" parsetrees that still need to be analyzed by
10+
* analyze.c and related files.
11+
*
12+
*
13+
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
14+
* Portions Copyright (c) 1994, Regents of the University of California
15+
*
16+
* IDENTIFICATION
17+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parser.c,v 1.1 2007/10/26 14:17:53 tgl Exp $
18+
*
19+
*-------------------------------------------------------------------------
20+
*/
21+
22+
#include "postgres_fe.h"
23+
24+
#include "extern.h"
25+
#include "preproc.h"
26+
27+
28+
static bool have_lookahead; /* is lookahead info valid? */
29+
static int lookahead_token; /* one-token lookahead */
30+
static YYSTYPE lookahead_yylval; /* yylval for lookahead token */
31+
static YYLTYPE lookahead_yylloc; /* yylloc for lookahead token */
32+
33+
34+
/*
35+
* Intermediate filter between parser and base lexer (base_yylex in scan.l).
36+
*
37+
* The filter is needed because in some cases the standard SQL grammar
38+
* requires more than one token lookahead. We reduce these cases to one-token
39+
* lookahead by combining tokens here, in order to keep the grammar LALR(1).
40+
*
41+
* Using a filter is simpler than trying to recognize multiword tokens
42+
* directly in scan.l, because we'd have to allow for comments between the
43+
* words. Furthermore it's not clear how to do it without re-introducing
44+
* scanner backtrack, which would cost more performance than this filter
45+
* layer does.
46+
*/
47+
int
48+
filtered_base_yylex(void)
49+
{
50+
int cur_token;
51+
int next_token;
52+
YYSTYPE cur_yylval;
53+
YYLTYPE cur_yylloc;
54+
55+
/* Get next token --- we might already have it */
56+
if (have_lookahead)
57+
{
58+
cur_token = lookahead_token;
59+
base_yylval = lookahead_yylval;
60+
base_yylloc = lookahead_yylloc;
61+
have_lookahead = false;
62+
}
63+
else
64+
cur_token = base_yylex();
65+
66+
/* Do we need to look ahead for a possible multiword token? */
67+
switch (cur_token)
68+
{
69+
case NULLS_P:
70+
/*
71+
* NULLS FIRST and NULLS LAST must be reduced to one token
72+
*/
73+
cur_yylval = base_yylval;
74+
cur_yylloc = base_yylloc;
75+
next_token = base_yylex();
76+
switch (next_token)
77+
{
78+
case FIRST_P:
79+
cur_token = NULLS_FIRST;
80+
break;
81+
case LAST_P:
82+
cur_token = NULLS_LAST;
83+
break;
84+
default:
85+
/* save the lookahead token for next time */
86+
lookahead_token = next_token;
87+
lookahead_yylval = base_yylval;
88+
lookahead_yylloc = base_yylloc;
89+
have_lookahead = true;
90+
/* and back up the output info to cur_token */
91+
base_yylval = cur_yylval;
92+
base_yylloc = cur_yylloc;
93+
break;
94+
}
95+
break;
96+
97+
case WITH:
98+
/*
99+
* WITH CASCADED, LOCAL, or CHECK must be reduced to one token
100+
*
101+
* XXX an alternative way is to recognize just WITH_TIME and put
102+
* the ugliness into the datetime datatype productions instead of
103+
* WITH CHECK OPTION. However that requires promoting WITH to a
104+
* fully reserved word. If we ever have to do that anyway
105+
* (perhaps for SQL99 recursive queries), come back and simplify
106+
* this code.
107+
*/
108+
cur_yylval = base_yylval;
109+
cur_yylloc = base_yylloc;
110+
next_token = base_yylex();
111+
switch (next_token)
112+
{
113+
case CASCADED:
114+
cur_token = WITH_CASCADED;
115+
break;
116+
case LOCAL:
117+
cur_token = WITH_LOCAL;
118+
break;
119+
case CHECK:
120+
cur_token = WITH_CHECK;
121+
break;
122+
default:
123+
/* save the lookahead token for next time */
124+
lookahead_token = next_token;
125+
lookahead_yylval = base_yylval;
126+
lookahead_yylloc = base_yylloc;
127+
have_lookahead = true;
128+
/* and back up the output info to cur_token */
129+
base_yylval = cur_yylval;
130+
base_yylloc = cur_yylloc;
131+
break;
132+
}
133+
break;
134+
135+
default:
136+
break;
137+
}
138+
139+
return cur_token;
140+
}

src/interfaces/ecpg/preproc/parser/README

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/interfaces/ecpg/preproc/parser/parse.h

Lines changed: 0 additions & 3 deletions
This file was deleted.

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