8000 Build backend/parser/scan.l and interfaces/ecpg/preproc/pgc.l standal… · phan-pivotal/postgres@329361c · GitHub
[go: up one dir, main page]

Skip to content

Commit 329361c

Browse files
committed
Build backend/parser/scan.l and interfaces/ecpg/preproc/pgc.l standalone.
Back-patch commit 72b1e3a into the pre-9.6 branches. As noted in the original commit, this has some extra benefits: we can narrow the scope of the -Wno-error flag that's forced on scan.c. Also, since these grammar and lexer files are so large, splitting them into separate build targets should have some advantages in build speed, particularly in parallel or ccache'd builds. However, the real reason for doing this now is that it avoids symbol- redefinition warnings (or worse) with the latest version of flex. It's not unreasonable that people would want to compile our old branches with recent tools. Per report from Дилян Палаузов. Discussion: https://postgr.es/m/d845c1af-e18d-6651-178f-9f08cdf37e10@aegee.org
1 parent f4ccee4 commit 329361c

File tree

6 files changed

+23
-34
lines changed

6 files changed

+23
-34
lines changed

src/backend/parser/Makefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include $(top_builddir)/src/Makefile.global
1212

1313
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
1414

15-
OBJS= analyze.o gram.o keywords.o kwlookup.o parser.o \
15+
OBJS= analyze.o gram.o scan.o keywords.o kwlookup.o parser.o \
1616
parse_agg.o parse_clause.o parse_coerce.o parse_collate.o parse_cte.o \
1717
parse_expr.o parse_func.o parse_node.o parse_oper.o parse_param.o \
1818
parse_relation.o parse_target.o parse_type.o parse_utilcmd.o scansup.o
@@ -22,12 +22,9 @@ FLEXFLAGS = -CF -b -p -p
2222
include $(top_srcdir)/src/backend/common.mk
2323

2424

25-
# scan is compiled as part of gram
26-
gram.o: scan.c
27-
2825
# Latest flex causes warnings in this file.
2926
ifeq ($(GCC),yes)
30-
gram.o: CFLAGS += -Wno-error
27+
scan.o: CFLAGS += -Wno-error
3128
endif
3229

3330

@@ -58,7 +55,7 @@ endif
5855

5956

6057
# Force these dependencies to be known even without dependency info built:
61-
gram.o keywords.o parser.o: gram.h
58+
gram.o scan.o keywords.o parser.o: gram.h
6259

6360

6461
# gram.c, gram.h, and scan.c are in the distribution tarball, so they

src/backend/parser/gram.y

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13374,13 +13374,3 @@ parser_init(base_yy_extra_type *yyext)
1337413374
{
1337513375
yyext->parsetree = NIL; /* in case grammar forgets to set it */
1337613376
}
13377-
13378-
/*
13379-
* Must undefine this stuff before including scan.c, since it has different
13380-
* definitions for these macros.
13381-
*/
13382-
#undef yyerror
13383-
#undef yylval
13384-
#undef yylloc
13385-
13386-
#include "scan.c"

src/backend/parser/scan.l

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
%{
1+
%top{
22
/*-------------------------------------------------------------------------
33
*
44
* scan.l
55
* lexical scanner for PostgreSQL
66
*
77
* NOTE NOTE NOTE:
88
*
9-
* The rules in this file must be kept in sync with psql's lexer!!!
9+
* The rules in this file must be kept in sync with psql's psqlscan.l!
1010
*
1111
* The rules are designed so that the scanner never has to backtrack,
1212
* in the sense that there is always a rule that can match the input
@@ -34,12 +34,13 @@
3434
#include <ctype.h>
3535
#include <unistd.h>
3636

37+
#include "parser/gramparse.h"
3738
#include "parser/parser.h" /* only needed for GUC variables */
38-
#include "parser/scanner.h"
3939
#include "parser/scansup.h"
4040
#include "mb/pg_wchar.h"
41+
}
4142

42-
43+
%{
4344
/* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
4445
#undef fprintf
4546
#define fprintf(file, fmt, msg) ereport(ERROR, (errmsg_internal("%s", msg)))

src/interfaces/ecpg/preproc/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
2626

2727
override CFLAGS += $(PTHREAD_CFLAGS) -DECPG_COMPILE
2828

29-
OBJS= preproc.o type.o ecpg.o output.o parser.o \
29+
OBJS= preproc.o pgc.o type.o ecpg.o output.o parser.o \
3030
keywords.o c_keywords.o ecpg_keywords.o kwlookup.o ../ecpglib/typename.o descriptor.o variable.o \
3131
$(WIN32RES)
3232

@@ -38,9 +38,6 @@ ecpg: $(OBJS) | submake-libpgport
3838
../ecpglib/typename.o: ../ecpglib/typename.c
3939
$(MAKE) -C $(dir $@) $(notdir $@)
4040

41-
# pgc is compiled as part of preproc
42-
preproc.o: pgc.c
43-
4441
preproc.h: preproc.c ;
4542

4643
preproc.c: preproc.y
@@ -61,7 +58,7 @@ preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.
6158
$(PERL) $(srcdir)/parse.pl $(srcdir) < $< > $@
6259
$(PERL) $(srcdir)/check_rules.pl $(srcdir) $<
6360

64-
ecpg_keywords.o c_keywords.o keywords.o preproc.o parser.o: preproc.h
61+
ecpg_keywords.o c_keywords.o keywords.o preproc.o pgc.o parser.o: preproc.h
6562

6663
kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
6764
rm -f $@ && $(LN_S) $< .

src/interfaces/ecpg/preproc/ecpg.trailer

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,11 +1912,3 @@ void parser_init(void)
19121912
{
19131913
/* This function is empty. It only exists for compatibility with the backend parser right now. */
19141914
}
1915-
1916-
/*
1917-
* Must undefine base_yylex before including pgc.c, since we want it
1918-
* to create the function base_yylex not filtered_base_yylex.
1919-
*/
1920-
#undef base_yylex
1921-
1922-
#include "pgc.c"

src/interfaces/ecpg/preproc/pgc.l

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%{
1+
%top{
22
/*-------------------------------------------------------------------------
33
*
44
* pgc.l
@@ -23,7 +23,19 @@
2323
#include <limits.h>
2424

2525
#include "extern.h"
26+
#include "preproc.h"
27+
28+
/*
29+
* Change symbol names as expected by preproc.y. It'd be better to do this
30+
* with %option prefix="base_yy", but that affects some other names that
31+
* various files expect *not* to be prefixed with "base_". Cleaning it up
32+
* is not worth the trouble right now.
33+
*/
34+
#define yylex base_yylex
35+
#define yylval base_yylval
36+
}
2637

38+
%{
2739
extern YYSTYPE yylval;
2840

2941
static int xcdepth = 0; /* depth of nesting in slash-star comments */

0 commit comments

Comments
 (0)
0