Move keywords.c/kwlookup.c into src/common/.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 Mar 2016 00:22:08 +0000 (20:22 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 Mar 2016 00:22:08 +0000 (20:22 -0400)
Now that we have src/common/ for code shared between frontend and backend,
we can get rid of (most of) the klugy ways that the keyword table and
keyword lookup code were formerly shared between different uses.
This is a first step towards a more general plan of getting rid of
special-purpose kluges for sharing code in src/bin/.

I chose to merge kwlookup.c back into keywords.c, as it once was, and
always has been so far as keywords.h is concerned.  We could have
kept them separate, but there is noplace that uses ScanKeywordLookup
without also wanting access to the backend's keyword list, so there
seems little point.

ecpg is still a bit weird, but at least now the trickiness is documented.

I think that the MSVC build script should require no adjustments beyond
what's done here ... but we'll soon find out.

23 files changed:
src/backend/parser/Makefile
src/backend/parser/README
src/backend/parser/keywords.c [deleted file]
src/backend/utils/adt/misc.c
src/backend/utils/adt/ruleutils.c
src/bin/pg_dump/.gitignore
src/bin/pg_dump/Makefile
src/bin/pg_dump/dumputils.c
src/bin/pg_dump/keywords.c [deleted file]
src/bin/psql/.gitignore
src/bin/psql/Makefile
src/bin/scripts/.gitignore
src/bin/scripts/Makefile
src/common/Makefile
src/common/keywords.c [moved from src/backend/parser/kwlookup.c with 73% similarity]
src/include/common/keywords.h [moved from src/include/parser/keywords.h with 96% similarity]
src/include/parser/gramparse.h
src/include/parser/scanner.h
src/interfaces/ecpg/preproc/.gitignore
src/interfaces/ecpg/preproc/Makefile
src/interfaces/ecpg/preproc/extern.h
src/interfaces/ecpg/preproc/keywords.c
src/tools/msvc/Mkvcbuild.pm

index 9cc8946fa1bc3480b68ae0eedf0e8a77691187bd..fdd8485cec5f3ebfc576aca95e8c2a34badabdc5 100644 (file)
@@ -12,7 +12,7 @@ include $(top_builddir)/src/Makefile.global
 
 override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
 
-OBJS= analyze.o gram.o scan.o keywords.o kwlookup.o parser.o \
+OBJS= analyze.o gram.o scan.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
@@ -44,7 +44,7 @@ scan.c: FLEX_NO_BACKUP=yes
 
 
 # Force these dependencies to be known even without dependency info built:
-gram.o scan.o keywords.o parser.o: gram.h
+gram.o scan.o parser.o: gram.h
 
 
 # gram.c, gram.h, and scan.c are in the distribution tarball, so they
index 08625e427d2baa6682df0ca4af3a2e19a43b4f09..6d8f19b5ca060ce729d6c049aa90ef3689b69a14 100644 (file)
@@ -10,8 +10,6 @@ to the optimizer and then executor.
 parser.c       things start here
 scan.l         break query into tokens
 scansup.c      handle escapes in input strings
-kwlookup.c     turn keywords into specific tokens
-keywords.c     table of standard keywords (passed to kwlookup.c)
 gram.y         parse the tokens and produce a "raw" parse tree
 analyze.c      top level of parse analysis for optimizable queries
 parse_agg.c    handle aggregates, like SUM(col1),  AVG(col2), ...
@@ -28,3 +26,7 @@ parse_relation.c support routines for tables and column handling
 parse_target.c handle the result list of the query
 parse_type.c   support routines for data type handling
 parse_utilcmd.c        parse analysis for utility commands (done at execution time)
+
+See also src/common/keywords.c, which contains the table of standard
+keywords and the keyword lookup function.  We separated that out because
+various frontend code wants to use it too.
diff --git a/src/backend/parser/keywords.c b/src/backend/parser/keywords.c
deleted file mode 100644 (file)
index 7a4f128..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * keywords.c
- *       lexical token lookup for key words in PostgreSQL
- *
- *
- * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- *       src/backend/parser/keywords.c
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres.h"
-
-#include "parser/gramparse.h"
-
-#define PG_KEYWORD(a,b,c) {a,b,c},
-
-
-const ScanKeyword ScanKeywords[] = {
-#include "parser/kwlist.h"
-};
-
-const int      NumScanKeywords = lengthof(ScanKeywords);
index 4dcc5a63be772b581464c1a93fc89ba90c7986c4..faa8ef3c9131d055694a280784cc1b65a58b4bbf 100644 (file)
 #include "catalog/pg_tablespace.h"
 #include "catalog/pg_type.h"
 #include "commands/dbcommands.h"
+#include "common/keywords.h"
 #include "funcapi.h"
 #include "miscadmin.h"
 #include "parser/scansup.h"
-#include "parser/keywords.h"
 #include "postmaster/syslogger.h"
 #include "rewrite/rewriteHandler.h"
 #include "storage/fd.h"
index 490a0906e8ed50b488fcbaaaab9aedb262a3937c..2b47e95a687a601e0a51529087f8194a487889ac 100644 (file)
@@ -38,6 +38,7 @@
 #include "catalog/pg_type.h"
 #include "commands/defrem.h"
 #include "commands/tablespace.h"
+#include "common/keywords.h"
 #include "executor/spi.h"
 #include "funcapi.h"
 #include "mb/pg_wchar.h"
@@ -45,7 +46,6 @@
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
 #include "optimizer/tlist.h"
-#include "parser/keywords.h"
 #include "parser/parse_node.h"
 #include "parser/parse_agg.h"
 #include "parser/parse_func.h"
index c2c8677bd80e4bf598bb5c6b7d5a64bba726d6dc..ae4cf3ce428251946cdd33f8329962eb4ecf142c 100644 (file)
@@ -1,5 +1,3 @@
-/kwlookup.c
-
 /pg_dump
 /pg_dumpall
 /pg_restore
index 4162c8e564535d5e47758a9c9bcd2be8e85c0e2d..ddf940210ab1513626e1165cdad6448b616688b5 100644 (file)
@@ -22,21 +22,16 @@ OBJS=       pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
        pg_backup_null.o pg_backup_tar.o pg_backup_directory.o \
        pg_backup_utils.o parallel.o compress_io.o dumputils.o $(WIN32RES)
 
-KEYWRDOBJS = keywords.o kwlookup.o
-
-kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
-       rm -f $@ && $(LN_S) $< .
-
 all: pg_dump pg_restore pg_dumpall
 
-pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
-       $(CC) $(CFLAGS) pg_dump.o common.o pg_dump_sort.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) | submake-libpq submake-libpgport
+       $(CC) $(CFLAGS) pg_dump.o common.o pg_dump_sort.o $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
 
-pg_restore: pg_restore.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
-       $(CC) $(CFLAGS) pg_restore.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+pg_restore: pg_restore.o $(OBJS) | submake-libpq submake-libpgport
+       $(CC) $(CFLAGS) pg_restore.o $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
 
-pg_dumpall: pg_dumpall.o dumputils.o $(KEYWRDOBJS) | submake-libpq submake-libpgport
-       $(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(KEYWRDOBJS) $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
+pg_dumpall: pg_dumpall.o dumputils.o | submake-libpq submake-libpgport
+       $(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
 
 install: all installdirs
        $(INSTALL_PROGRAM) pg_dump$(X) '$(DESTDIR)$(bindir)'/pg_dump$(X)
@@ -50,4 +45,4 @@ uninstall:
        rm -f $(addprefix '$(DESTDIR)$(bindir)'/, pg_dump$(X) pg_restore$(X) pg_dumpall$(X))
 
 clean distclean maintainer-clean:
-       rm -f pg_dump$(X) pg_restore$(X) pg_dumpall$(X) $(OBJS) pg_dump.o common.o pg_dump_sort.o pg_restore.o pg_dumpall.o kwlookup.c $(KEYWRDOBJS)
+       rm -f pg_dump$(X) pg_restore$(X) pg_dumpall$(X) $(OBJS) pg_dump.o common.o pg_dump_sort.o pg_restore.o pg_dumpall.o
index 24ba5c8755c11bcabef3ec94ca9b17fc00808b0e..a685d28d6009dc063e67cc523579e38c305c1745 100644 (file)
 
 #include "dumputils.h"
 
-#include "parser/keywords.h"
+#include "common/keywords.h"
 
 
-/* Globals from keywords.c */
-extern const ScanKeyword FEScanKeywords[];
-extern const int NumFEScanKeywords;
-
 #define supports_grant_options(version) ((version) >= 70400)
 
 static bool parseAclItem(const char *item, const char *type,
@@ -116,8 +112,8 @@ fmtId(const char *rawid)
                 * that's fine, since we already know we have all-lower-case.
                 */
                const ScanKeyword *keyword = ScanKeywordLookup(rawid,
-                                                                                                          FEScanKeywords,
-                                                                                                          NumFEScanKeywords);
+                                                                                                          ScanKeywords,
+                                                                                                          NumScanKeywords);
 
                if (keyword != NULL && keyword->category != UNRESERVED_KEYWORD)
                        need_quotes = true;
diff --git a/src/bin/pg_dump/keywords.c b/src/bin/pg_dump/keywords.c
deleted file mode 100644 (file)
index 6f3a2d7..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * keywords.c
- *       lexical token lookup for key words in PostgreSQL
- *
- *
- * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- *       src/bin/pg_dump/keywords.c
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres_fe.h"
-
-#include "parser/keywords.h"
-
-/*
- * We don't need the token number, so leave it out to avoid requiring other
- * backend headers.
- */
-#define PG_KEYWORD(a,b,c) {a,0,c},
-
-const ScanKeyword FEScanKeywords[] = {
-#include "parser/kwlist.h"
-};
-
-const int      NumFEScanKeywords = lengthof(FEScanKeywords);
index dc88807f52e3f42ed9d988382b91766bca1f6942..ce881f45ad25b4d4ed5403847b3d83c3d6966048 100644 (file)
@@ -3,7 +3,5 @@
 /sql_help.h
 /sql_help.c
 /dumputils.c
-/keywords.c
-/kwlookup.c
 
 /psql
index 5f4038e2cb6c66042cf8ee788424da1271b3ba31..75a9b395b4a13609f7d5594ad83c3b580f4f8799 100644 (file)
@@ -22,7 +22,7 @@ override CPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir) -I$(top_srcdir)/src/bin/p
 
 OBJS=  command.o common.o help.o input.o stringutils.o mainloop.o copy.o \
        startup.o prompt.o variables.o large_obj.o print.o describe.o \
-       tab-complete.o mbprint.o dumputils.o keywords.o kwlookup.o \
+       tab-complete.o mbprint.o dumputils.o \
        sql_help.o psqlscan.o psqlscanslash.o \
        $(WIN32RES)
 
@@ -34,10 +34,7 @@ psql: $(OBJS) | submake-libpq submake-libpgport
 
 help.o: sql_help.h
 
-dumputils.c keywords.c: % : $(top_srcdir)/src/bin/pg_dump/%
-       rm -f $@ && $(LN_S) $< .
-
-kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
+dumputils.c: % : $(top_srcdir)/src/bin/pg_dump/%
        rm -f $@ && $(LN_S) $< .
 
 sql_help.c: sql_help.h ;
@@ -70,7 +67,7 @@ uninstall:
        rm -f '$(DESTDIR)$(bindir)/psql$(X)' '$(DESTDIR)$(datadir)/psqlrc.sample'
 
 clean distclean:
-       rm -f psql$(X) $(OBJS) dumputils.c keywords.c kwlookup.c lex.backup
+       rm -f psql$(X) $(OBJS) dumputils.c lex.backup
 
 # files removed here are supposed to be in the distribution tarball,
 # so do not clean them in the clean/distclean rules
index 1056b2870c0f15f378ace25a0c440bfb34e6e4e5..e12d27a2f1b08a989f61c46575671b52538c3a41 100644 (file)
@@ -10,8 +10,6 @@
 /pg_isready
 
 /dumputils.c
-/keywords.c
-/kwlookup.c
 /mbprint.c
 /print.c
 
index c4e04c9aa8ad9e842531365c25a1e2ff3451a558..ad34d42d682364250ed7b710b6d1a66c0310cae1 100644 (file)
@@ -25,26 +25,23 @@ all: $(PROGRAMS)
 %: %.o $(WIN32RES)
        $(CC) $(CFLAGS) $^ $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
 
-createdb: createdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq submake-libpgport
+createdb: createdb.o common.o dumputils.o | submake-libpq submake-libpgport
 createlang: createlang.o common.o print.o mbprint.o | submake-libpq submake-libpgport
-createuser: createuser.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq submake-libpgport
-dropdb: dropdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq submake-libpgport
+createuser: createuser.o common.o dumputils.o | submake-libpq submake-libpgport
+dropdb: dropdb.o common.o dumputils.o | submake-libpq submake-libpgport
 droplang: droplang.o common.o print.o mbprint.o | submake-libpq submake-libpgport
-dropuser: dropuser.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq submake-libpgport
-clusterdb: clusterdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq submake-libpgport
-vacuumdb: vacuumdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq submake-libpgport
-reindexdb: reindexdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq submake-libpgport
+dropuser: dropuser.o common.o dumputils.o | submake-libpq submake-libpgport
+clusterdb: clusterdb.o common.o dumputils.o | submake-libpq submake-libpgport
+vacuumdb: vacuumdb.o common.o dumputils.o | submake-libpq submake-libpgport
+reindexdb: reindexdb.o common.o dumputils.o | submake-libpq submake-libpgport
 pg_isready: pg_isready.o common.o | submake-libpq submake-libpgport
 
-dumputils.c keywords.c: % : $(top_srcdir)/src/bin/pg_dump/%
+dumputils.c: % : $(top_srcdir)/src/bin/pg_dump/%
        rm -f $@ && $(LN_S) $< .
 
 print.c mbprint.c : % : $(top_srcdir)/src/bin/psql/%
        rm -f $@ && $(LN_S) $< .
 
-kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
-       rm -f $@ && $(LN_S) $< .
-
 install: all installdirs
        $(INSTALL_PROGRAM) createdb$(X)   '$(DESTDIR)$(bindir)'/createdb$(X)
        $(INSTALL_PROGRAM) dropdb$(X)     '$(DESTDIR)$(bindir)'/dropdb$(X)
@@ -65,8 +62,8 @@ uninstall:
 
 clean distclean maintainer-clean:
        rm -f $(addsuffix $(X), $(PROGRAMS)) $(addsuffix .o, $(PROGRAMS))
-       rm -f common.o dumputils.o kwlookup.o keywords.o print.o mbprint.o $(WIN32RES)
-       rm -f dumputils.c print.c mbprint.c kwlookup.c keywords.c
+       rm -f common.o dumputils.o print.o mbprint.o $(WIN32RES)
+       rm -f dumputils.c print.c mbprint.c
        rm -rf tmp_check
 
 check:
index f7a4a4d099a21dc5eb69a61a73b29d232792c7cf..72b73697a8cbac361673dc1bc6f39711027342a5 100644 (file)
@@ -36,8 +36,9 @@ override CPPFLAGS += -DVAL_LDFLAGS_EX="\"$(LDFLAGS_EX)\""
 override CPPFLAGS += -DVAL_LDFLAGS_SL="\"$(LDFLAGS_SL)\""
 override CPPFLAGS += -DVAL_LIBS="\"$(LIBS)\""
 
-OBJS_COMMON = config_info.o controldata_utils.o exec.o pg_lzcompress.o \
-       pgfnames.o psprintf.o relpath.o rmtree.o string.o username.o wait_error.o
+OBJS_COMMON = config_info.o controldata_utils.o exec.o keywords.o \
+       pg_lzcompress.o pgfnames.o psprintf.o relpath.o rmtree.o \
+       string.o username.o wait_error.o
 
 OBJS_FRONTEND = $(OBJS_COMMON) fe_memutils.o restricted_token.o
 
@@ -83,5 +84,14 @@ $(OBJS_SRV): | submake-errcodes
 submake-errcodes:
        $(MAKE) -C ../backend submake-errcodes
 
+# Dependencies of keywords.o need to be managed explicitly to make sure
+# that you don't get broken parsing code, even in a non-enable-depend build.
+# Note that gram.h isn't required for the frontend version of keywords.o.
+$(top_builddir)/src/include/parser/gram.h: $(top_srcdir)/src/backend/parser/gram.y
+       $(MAKE) -C $(top_builddir)/src/backend $(top_builddir)/src/include/parser/gram.h
+
+keywords.o: $(top_srcdir)/src/include/parser/kwlist.h
+keywords_srv.o: $(top_builddir)/src/include/parser/gram.h $(top_srcdir)/src/include/parser/kwlist.h
+
 clean distclean maintainer-clean:
        rm -f libpgcommon.a libpgcommon_srv.a $(OBJS_FRONTEND) $(OBJS_SRV)
similarity index 73%
rename from src/backend/parser/kwlookup.c
rename to src/common/keywords.c
index 4406fef37f4959ebe74da0abcd079458696e5220..485dd02e89dc5ddaa1729792442696d7d17be581 100644 (file)
@@ -1,31 +1,56 @@
 /*-------------------------------------------------------------------------
  *
- * kwlookup.c
+ * keywords.c
  *       lexical token lookup for key words in PostgreSQL
  *
- * NB - this file is also used by ECPG and several frontend programs in
- * src/bin/ including pg_dump and psql
  *
  * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       src/backend/parser/kwlookup.c
+ *       src/common/keywords.c
  *
  *-------------------------------------------------------------------------
  */
+#ifndef FRONTEND
+#include "postgres.h"
+#else
+#include "postgres_fe.h"
+#endif
 
-/* use c.h so this can be built as either frontend or backend */
-#include "c.h"
+#ifndef FRONTEND
 
-#include <ctype.h>
+#include "parser/gramparse.h"
+
+#define PG_KEYWORD(a,b,c) {a,b,c},
+
+#else
+
+#include "common/keywords.h"
+
+/*
+ * We don't need the token number for frontend uses, so leave it out to avoid
+ * requiring backend headers that won't compile cleanly here.
+ */
+#define PG_KEYWORD(a,b,c) {a,0,c},
+
+#endif   /* FRONTEND */
+
+
+const ScanKeyword ScanKeywords[] = {
+#include "parser/kwlist.h"
+};
+
+const int      NumScanKeywords = lengthof(ScanKeywords);
 
-#include "parser/keywords.h"
 
 /*
  * ScanKeywordLookup - see if a given word is a keyword
  *
+ * The table to be searched is passed explicitly, so that this can be used
+ * to search keyword lists other than the standard list appearing above.
+ *
  * Returns a pointer to the ScanKeyword table entry, or NULL if no match.
  *
  * The match is done case-insensitively.  Note that we deliberately use a
similarity index 96%
rename from src/include/parser/keywords.h
rename to src/include/common/keywords.h
index 4ac861646d620ad8ca340a550ea67ae7524037ad..577100d1b95debd80231acae72d9c61262c99d01 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * src/include/parser/keywords.h
+ * src/include/common/keywords.h
  *
  *-------------------------------------------------------------------------
  */
@@ -31,6 +31,7 @@ typedef struct ScanKeyword
 extern PGDLLIMPORT const ScanKeyword ScanKeywords[];
 extern PGDLLIMPORT const int NumScanKeywords;
 
+
 extern const ScanKeyword *ScanKeywordLookup(const char *text,
                                  const ScanKeyword *keywords,
                                  int num_keywords);
index c3ec1992c655d62f73b4b4c6f121987533e6b087..6d8e4937ee06809817b4e5cb830fda06bf9f1105 100644 (file)
@@ -4,8 +4,8 @@
  *             Shared definitions for the "raw" parser (flex and bison phases only)
  *
  * NOTE: this file is only meant to be included in the core parsing files,
- * ie, parser.c, gram.y, scan.l, and keywords.c.  Definitions that are needed
- * outside the core parser should be in parser.h.
+ * ie, parser.c, gram.y, scan.l, and src/common/keywords.c.
+ * Definitions that are needed outside the core parser should be in parser.h.
  *
  *
  * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
index 0060501937fb686dee73871c848d1434667b61fa..b885e67a83b3504086980067b2fd9625d7d387d7 100644 (file)
@@ -19,7 +19,7 @@
 #ifndef SCANNER_H
 #define SCANNER_H
 
-#include "parser/keywords.h"
+#include "common/keywords.h"
 
 /*
  * The scanner returns extra data about scanned tokens in this union type.
index 6fca9aff590627a777202d667335349c7fafbe07..aacfb844bda0ef43e1433a30732a4f2bf1877f50 100644 (file)
@@ -4,4 +4,3 @@
 /pgc.c
 
 /ecpg
-/kwlookup.c
index ee3b13a4afa0762547fbfe07ebd9110a65142906..30db5a049af3cbc657d20f7dd5bc1f75cbc7814c 100644 (file)
@@ -27,7 +27,7 @@ override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
 override CFLAGS += $(PTHREAD_CFLAGS) -DECPG_COMPILE
 
 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 \
+       keywords.o c_keywords.o ecpg_keywords.o ../ecpglib/typename.o descriptor.o variable.o \
        $(WIN32RES)
 
 # Suppress parallel build to avoid a bug in GNU make 3.82
@@ -53,9 +53,6 @@ preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.
 
 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) $< .
-
 distprep: preproc.y preproc.c preproc.h pgc.c
 
 install: all installdirs
@@ -68,7 +65,7 @@ uninstall:
        rm -f '$(DESTDIR)$(bindir)/ecpg$(X)'
 
 clean distclean:
-       rm -f kwlookup.c *.o ecpg$(X)
+       rm -f *.o ecpg$(X)
 # garbage from development
        @rm -f core a.out
 
index ea8fd8ed98c865335ec9f7228f64c1901294c9bd..f6841726e4a5ca81437f617f17be05419249d8ea 100644 (file)
@@ -4,7 +4,8 @@
 #define _ECPG_PREPROC_EXTERN_H
 
 #include "type.h"
-#include "parser/keywords.h"
+
+#include "common/keywords.h"
 
 #include <errno.h>
 #ifndef CHAR_BIT
index 2f17f0c5c0232aa4ff05597926fce06e85168e96..cffdaed67b06f0a9a50ba3d2f85d060aa5fe1bd6 100644 (file)
  */
 #include "postgres_fe.h"
 
-#include "parser/keywords.h"
-#include "type.h"
+/*
+ * This is much trickier than it looks.  We are #include'ing kwlist.h
+ * but the "value" numbers that go into the table are from preproc.h
+ * not the backend's gram.h.  Therefore this table will recognize all
+ * keywords known to the backend, but will supply the token numbers used
+ * by ecpg's grammar, which is what we need.  The ecpg grammar must
+ * define all the same token names the backend does, else we'll get
+ * undefined-symbol failures in this compile.
+ */
+
+#include "common/keywords.h"
+
 #include "extern.h"
 #include "preproc.h"
 
-#define PG_KEYWORD(a,b,c) {a,b,c},
 
+#define PG_KEYWORD(a,b,c) {a,b,c},
 
 const ScanKeyword SQLScanKeywords[] = {
 #include "parser/kwlist.h"
index 012b327d9d292ff4a654f9be78a56e1b6fb4746a..8716642847ae2a0fe21595d554ffd5688956e2cd 100644 (file)
@@ -108,8 +108,9 @@ sub mkvcbuild
        }
 
        our @pgcommonallfiles = qw(
-         config_info.c controldata_utils.c exec.c pg_lzcompress.c pgfnames.c
-         psprintf.c relpath.c rmtree.c string.c username.c wait_error.c);
+         config_info.c controldata_utils.c exec.c keywords.c
+         pg_lzcompress.c pgfnames.c psprintf.c relpath.c rmtree.c
+         string.c username.c wait_error.c);
 
        our @pgcommonfrontendfiles = (
                @pgcommonallfiles, qw(fe_memutils.c
@@ -343,8 +344,6 @@ sub mkvcbuild
        $pgdump->AddFile('src/bin/pg_dump/pg_dump.c');
        $pgdump->AddFile('src/bin/pg_dump/common.c');
        $pgdump->AddFile('src/bin/pg_dump/pg_dump_sort.c');
-       $pgdump->AddFile('src/bin/pg_dump/keywords.c');
-       $pgdump->AddFile('src/backend/parser/kwlookup.c');
        $pgdump->AddLibrary('ws2_32.lib');
 
        my $pgdumpall = AddSimpleFrontend('pg_dump', 1);
@@ -360,16 +359,12 @@ sub mkvcbuild
        $pgdumpall->AddIncludeDir('src/backend');
        $pgdumpall->AddFile('src/bin/pg_dump/pg_dumpall.c');
        $pgdumpall->AddFile('src/bin/pg_dump/dumputils.c');
-       $pgdumpall->AddFile('src/bin/pg_dump/keywords.c');
-       $pgdumpall->AddFile('src/backend/parser/kwlookup.c');
        $pgdumpall->AddLibrary('ws2_32.lib');
 
        my $pgrestore = AddSimpleFrontend('pg_dump', 1);
        $pgrestore->{name} = 'pg_restore';
        $pgrestore->AddIncludeDir('src/backend');
        $pgrestore->AddFile('src/bin/pg_dump/pg_restore.c');
-       $pgrestore->AddFile('src/bin/pg_dump/keywords.c');
-       $pgrestore->AddFile('src/backend/parser/kwlookup.c');
        $pgrestore->AddLibrary('ws2_32.lib');
 
        my $zic = $solution->AddProject('zic', 'exe', 'utils');
@@ -618,15 +613,7 @@ sub mkvcbuild
                foreach my $f (@files)
                {
                        $f =~ s/\.o$/\.c/;
-                       if ($f eq 'keywords.c')
-                       {
-                               $proj->AddFile('src/bin/pg_dump/keywords.c');
-                       }
-                       elsif ($f eq 'kwlookup.c')
-                       {
-                               $proj->AddFile('src/backend/parser/kwlookup.c');
-                       }
-                       elsif ($f eq 'dumputils.c')
+                       if ($f eq 'dumputils.c')
                        {
                                $proj->AddFile('src/bin/pg_dump/dumputils.c');
                        }