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
# 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
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), ...
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.
+++ /dev/null
-/*-------------------------------------------------------------------------
- *
- * 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);
#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"
#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"
#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"
-/kwlookup.c
-
/pg_dump
/pg_dumpall
/pg_restore
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)
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
#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,
* 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;
+++ /dev/null
-/*-------------------------------------------------------------------------
- *
- * 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);
/sql_help.h
/sql_help.c
/dumputils.c
-/keywords.c
-/kwlookup.c
/psql
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)
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 ;
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
/pg_isready
/dumputils.c
-/keywords.c
-/kwlookup.c
/mbprint.c
/print.c
%: %.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)
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:
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
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)
/*-------------------------------------------------------------------------
*
- * 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
* 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
*
*-------------------------------------------------------------------------
*/
extern PGDLLIMPORT const ScanKeyword ScanKeywords[];
extern PGDLLIMPORT const int NumScanKeywords;
+
extern const ScanKeyword *ScanKeywordLookup(const char *text,
const ScanKeyword *keywords,
int num_keywords);
* 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
#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.
/pgc.c
/ecpg
-/kwlookup.c
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
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
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
#define _ECPG_PREPROC_EXTERN_H
#include "type.h"
-#include "parser/keywords.h"
+
+#include "common/keywords.h"
#include <errno.h>
#ifndef CHAR_BIT
*/
#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"
}
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
$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);
$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');
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');
}