Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 72b1e3a

Browse files
committed
Build backend/parser/scan.l and interfaces/ecpg/preproc/pgc.l standalone.
Now that we know about the %top{} trick, we can revert to building flex lexers as separate .o files. This is worth doing for a couple of reasons besides sheer cleanliness. 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. We have quite a few other .l files that could be changed likewise, but the above arguments don't apply to them, so the benefit of fixing them seems pretty minimal. Leave the rest for some other day.
1 parent 7bafffe commit 72b1e3a

File tree

6 files changed

+23
-34
lines changed

6 files changed

+23
-34
lines changed

src/backend/parser/Makefile

+3-6
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

-10
Original file line numberDiff line numberDiff line change
@@ -14908,13 +14908,3 @@ parser_init(base_yy_extra_type *yyext)
1490814908
{
1490914909
yyext->parsetree = NIL; /* in case grammar forgets to set it */
1491014910
}
14911-
14912-
/*
14913-
* Must undefine this stuff before including scan.c, since it has different
14914-
* definitions for these macros.
14915-
*/
14916-
#undef yyerror
14917-
#undef yylval
14918-
#undef yylloc
14919-
14920-
#include "scan.c"

src/backend/parser/scan.l

+5-4
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

+2-5
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

-8
Original file line numberDiff line numberDiff line change
@@ -1916,11 +1916,3 @@ void parser_init(void)
19161916
{
19171917
/* This function is empty. It only exists for compatibility with the backend parser right now. */
19181918
}
1919-
1920-
/*
1921-
* Must undefine base_yylex before including pgc.c, since we want it
1922-
* to create the function base_yylex not filtered_base_yylex.
1923-
*/
1924-
#undef base_yylex
1925-
1926-
#include "pgc.c"

src/interfaces/ecpg/preproc/pgc.l

+13-1
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.l. 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)