Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Build backend/parser/scan.l and interfaces/ecpg/preproc/pgc.l standalone.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 11 Dec 2016 22:44:17 +0000 (17:44 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 11 Dec 2016 22:44:17 +0000 (17:44 -0500)
Back-patch commit 72b1e3a21 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

src/backend/parser/Makefile
src/backend/parser/gram.y
src/backend/parser/scan.l
src/interfaces/ecpg/preproc/Makefile
src/interfaces/ecpg/preproc/ecpg.trailer
src/interfaces/ecpg/preproc/pgc.l

index 00e8e88e9c2e6b2c66bd445a0a8c33690d60f527..c8fba3bbb0cb025eb1f9ff5b553e886a326da704 100644 (file)
@@ -12,7 +12,7 @@ include $(top_builddir)/src/Makefile.global
 
 override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
 
-OBJS= analyze.o gram.o keywords.o kwlookup.o parser.o \
+OBJS= analyze.o gram.o scan.o keywords.o kwlookup.o parser.o \
       parse_agg.o parse_clause.o parse_coerce.o parse_collate.o parse_cte.o \
       parse_expr.o parse_func.o parse_node.o parse_oper.o parse_param.o \
       parse_relation.o parse_target.o parse_type.o parse_utilcmd.o scansup.o
@@ -22,12 +22,9 @@ FLEXFLAGS = -CF -b -p -p
 include $(top_srcdir)/src/backend/common.mk
 
 
-# scan is compiled as part of gram
-gram.o: scan.c
-
 # Latest flex causes warnings in this file.
 ifeq ($(GCC),yes)
-gram.o: CFLAGS += -Wno-error
+scan.o: CFLAGS += -Wno-error
 endif
 
 
@@ -58,7 +55,7 @@ endif
 
 
 # Force these dependencies to be known even without dependency info built:
-gram.o keywords.o parser.o: gram.h
+gram.o scan.o keywords.o parser.o: gram.h
 
 
 # gram.c, gram.h, and scan.c are in the distribution tarball, so they
index 1d4d942f0246698b768994be75050cc00341b6ac..1a08ea47fdd8ac6ba424baea96c83934160e6186 100644 (file)
@@ -13374,13 +13374,3 @@ parser_init(base_yy_extra_type *yyext)
 {
    yyext->parsetree = NIL;     /* in case grammar forgets to set it */
 }
-
-/*
- * Must undefine this stuff before including scan.c, since it has different
- * definitions for these macros.
- */
-#undef yyerror
-#undef yylval
-#undef yylloc
-
-#include "scan.c"
index cde8fae620f9aa82f401784581253d1f9b8148ed..2a2895bac0d00529158862ab2e4b5815d26d61c2 100644 (file)
@@ -1,4 +1,4 @@
-%{
+%top{
 /*-------------------------------------------------------------------------
  *
  * scan.l
@@ -6,7 +6,7 @@
  *
  * NOTE NOTE NOTE:
  *
- * The rules in this file must be kept in sync with psql's lexer!!!
+ * The rules in this file must be kept in sync with psql's psqlscan.l!
  *
  * The rules are designed so that the scanner never has to backtrack,
  * in the sense that there is always a rule that can match the input
 #include <ctype.h>
 #include <unistd.h>
 
+#include "parser/gramparse.h"
 #include "parser/parser.h"             /* only needed for GUC variables */
-#include "parser/scanner.h"
 #include "parser/scansup.h"
 #include "mb/pg_wchar.h"
+}
 
-
+%{
 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
 #undef fprintf
 #define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))
index dd1e070625d1b87b802d3fb500570ee6fc8f83d7..df83e29fc46363bdb3871702c630ed11dcb00684 100644 (file)
@@ -26,7 +26,7 @@ override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
 
 override CFLAGS += $(PTHREAD_CFLAGS) -DECPG_COMPILE
 
-OBJS=  preproc.o type.o ecpg.o output.o parser.o \
+OBJS=  preproc.o pgc.o type.o ecpg.o output.o parser.o \
    keywords.o c_keywords.o ecpg_keywords.o kwlookup.o ../ecpglib/typename.o descriptor.o variable.o \
    $(WIN32RES)
 
@@ -38,9 +38,6 @@ ecpg: $(OBJS) | submake-libpgport
 ../ecpglib/typename.o: ../ecpglib/typename.c
    $(MAKE) -C $(dir $@) $(notdir $@)
 
-# pgc is compiled as part of preproc
-preproc.o: pgc.c
-
 preproc.h: preproc.c ;
 
 preproc.c: preproc.y
@@ -61,7 +58,7 @@ preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.
    $(PERL) $(srcdir)/parse.pl $(srcdir) < $< > $@
    $(PERL) $(srcdir)/check_rules.pl $(srcdir) $<
 
-ecpg_keywords.o c_keywords.o keywords.o preproc.o parser.o: preproc.h
+ecpg_keywords.o c_keywords.o keywords.o preproc.o pgc.o parser.o: preproc.h
 
 kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
    rm -f $@ && $(LN_S) $< .
index 422013c934d1cce428e86eec03d7263fdbf7ba98..8ed2eb4861266156b2d560277250bf95852ba473 100644 (file)
@@ -1912,11 +1912,3 @@ void parser_init(void)
 {
  /* This function is empty. It only exists for compatibility with the backend parser right now. */
 }
-
-/*
- * Must undefine base_yylex before including pgc.c, since we want it
- * to create the function base_yylex not filtered_base_yylex.
- */
-#undef base_yylex
-
-#include "pgc.c"
index ef0fed7ab68cb738ebe73916034318708ff303e5..c8455b88d8b4cf3f2c8ffb80f3bbafe89df18972 100644 (file)
@@ -1,4 +1,4 @@
-%{
+%top{
 /*-------------------------------------------------------------------------
  *
  * pgc.l
 #include <limits.h>
 
 #include "extern.h"
+#include "preproc.h"
+
+/*
+ * Change symbol names as expected by preproc.y.  It'd be better to do this
+ * with %option prefix="base_yy", but that affects some other names that
+ * various files expect *not* to be prefixed with "base_".  Cleaning it up
+ * is not worth the trouble right now.
+ */
+#define yylex           base_yylex
+#define yylval          base_yylval
+}
 
+%{
 extern YYSTYPE yylval;
 
 static int     xcdepth = 0;    /* depth of nesting in slash-star comments */