Skip to content

Commit 73ae395

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 79e1a9e commit 73ae395

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,20 +12,17 @@ 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
1919

2020
include $(top_srcdir)/src/backend/common.mk
2121

2222

23-
# scan is compiled as part of gram
24-
gram.o: scan.c
25-
2623
# Latest flex causes warnings in this file.
2724
ifeq ($(GCC),yes)
28-
gram.o: CFLAGS += -Wno-error
25+
scan.o: CFLAGS += -Wno-error
2926
endif
3027

3128

@@ -47,7 +44,7 @@ scan.c: FLEX_NO_BACKUP=yes
4744

4845

4946
# Force these dependencies to be known even without dependency info built:
50-
gram.o keywords.o parser.o: gram.h
47+
gram.o scan.o keywords.o parser.o: gram.h
5148

5249

5350
# 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
@@ -13848,13 +13848,3 @@ parser_init(base_yy_extra_type *yyext)
1384813848
{
1384913849
yyext->parsetree = NIL; /* in case grammar forgets to set it */
1385013850
}
13851-
13852-
/*
13853-
* Must undefine this stuff before including scan.c, since it has different
13854-
* definitions for these macros.
13855-
*/
13856-
#undef yyerror
13857-
#undef yylval
13858-
#undef yylloc
13859-
13860-
#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) fprintf_to_ereport(fmt, 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

@@ -44,17 +44,14 @@ ecpg: $(OBJS) | submake-libpgport
4444
../ecpglib/typename.o: ../ecpglib/typename.c
4545
$(MAKE) -C $(dir $@) $(notdir $@)
4646

47-
# pgc is compiled as part of preproc
48-
preproc.o: pgc.c
49-
5047
preproc.h: preproc.c ;
5148
preproc.c: BISONFLAGS += -d
5249

5350
preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type
5451
$(PERL) $(srcdir)/parse.pl $(srcdir) < $< > $@
5552
$(PERL) $(srcdir)/check_rules.pl $(srcdir) $<
5653

57-
ecpg_keywords.o c_keywords.o keywords.o preproc.o parser.o: preproc.h
54+
ecpg_keywords.o c_keywords.o keywords.o preproc.o pgc.o parser.o: preproc.h
5855

5956
kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
6057
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)