Skip to content

Commit 2c6af4f

Browse files
committed
Move keywords.c/kwlookup.c into src/common/.
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.
1 parent 3df9c37 commit 2c6af4f

File tree

23 files changed

+102
-148
lines changed

23 files changed

+102
-148
lines changed

src/backend/parser/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include $(top_builddir)/src/Makefile.global
1212

1313
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
1414

15-
OBJS= analyze.o gram.o scan.o keywords.o kwlookup.o parser.o \
15+
OBJS= analyze.o gram.o scan.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
@@ -44,7 +44,7 @@ scan.c: FLEX_NO_BACKUP=yes
4444

4545

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

4949

5050
# gram.c, gram.h, and scan.c are in the distribution tarball, so they

src/backend/parser/README

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ to the optimizer and then executor.
1010
parser.c things start here
1111
scan.l break query into tokens
1212
scansup.c handle escapes in input strings
13-
kwlookup.c turn keywords into specific tokens
14-
keywords.c table of standard keywords (passed to kwlookup.c)
1513
gram.y parse the tokens and produce a "raw" parse tree
1614
analyze.c top level of parse analysis for optimizable queries
1715
parse_agg.c handle aggregates, like SUM(col1), AVG(col2), ...
@@ -28,3 +26,7 @@ parse_relation.c support routines for tables and column handling
2826
parse_target.c handle the result list of the query
2927
parse_type.c support routines for data type handling
3028
parse_utilcmd.c parse analysis for utility commands (done at execution time)
29+
30+
See also src/common/keywords.c, which contains the table of standard
31+
keywords and the keyword lookup function. We separated that out because
32+
various frontend code wants to use it too.

src/backend/parser/keywords.c

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/backend/utils/adt/misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
#include "catalog/pg_tablespace.h"
2626
#include "catalog/pg_type.h"
2727
#include "commands/dbcommands.h"
28+
#include "common/keywords.h"
2829
#include "funcapi.h"
2930
#include "miscadmin.h"
3031
#include "parser/scansup.h"
31-
#include "parser/keywords.h"
3232
#include "postmaster/syslogger.h"
3333
#include "rewrite/rewriteHandler.h"
3434
#include "storage/fd.h"

src/backend/utils/adt/ruleutils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
#include "catalog/pg_type.h"
3939
#include "commands/defrem.h"
4040
#include "commands/tablespace.h"
41+
#include "common/keywords.h"
4142
#include "executor/spi.h"
4243
#include "funcapi.h"
4344
#include "mb/pg_wchar.h"
4445
#include "miscadmin.h"
4546
#include "nodes/makefuncs.h"
4647
#include "nodes/nodeFuncs.h"
4748
#include "optimizer/tlist.h"
48-
#include "parser/keywords.h"
4949
#include "parser/parse_node.h"
5050
#include "parser/parse_agg.h"
5151
#include "parser/parse_func.h"

src/bin/pg_dump/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/kwlookup.c
2-
31
/pg_dump
42
/pg_dumpall
53
/pg_restore

src/bin/pg_dump/Makefile

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,16 @@ OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
2222
pg_backup_null.o pg_backup_tar.o pg_backup_directory.o \
2323
pg_backup_utils.o parallel.o compress_io.o dumputils.o $(WIN32RES)
2424

25-
KEYWRDOBJS = keywords.o kwlookup.o
26-
27-
kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
28-
rm -f $@ && $(LN_S) $< .
29-
3025
all: pg_dump pg_restore pg_dumpall
3126

32-
pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
33-
$(CC) $(CFLAGS) pg_dump.o common.o pg_dump_sort.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
27+
pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) | submake-libpq submake-libpgport
28+
$(CC) $(CFLAGS) pg_dump.o common.o pg_dump_sort.o $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
3429

35-
pg_restore: pg_restore.o $(OBJS) $(KEYWRDOBJS) | submake-libpq submake-libpgport
36-
$(CC) $(CFLAGS) pg_restore.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
30+
pg_restore: pg_restore.o $(OBJS) | submake-libpq submake-libpgport
31+
$(CC) $(CFLAGS) pg_restore.o $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
3732

38-
pg_dumpall: pg_dumpall.o dumputils.o $(KEYWRDOBJS) | submake-libpq submake-libpgport
39-
$(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(KEYWRDOBJS) $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
33+
pg_dumpall: pg_dumpall.o dumputils.o | submake-libpq submake-libpgport
34+
$(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
4035

4136
install: all installdirs
4237
$(INSTALL_PROGRAM) pg_dump$(X) '$(DESTDIR)$(bindir)'/pg_dump$(X)
@@ -50,4 +45,4 @@ uninstall:
5045
rm -f $(addprefix '$(DESTDIR)$(bindir)'/, pg_dump$(X) pg_restore$(X) pg_dumpall$(X))
5146

5247
clean distclean maintainer-clean:
53-
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)
48+
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

src/bin/pg_dump/dumputils.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@
1818

1919
#include "dumputils.h"
2020

21-
#include "parser/keywords.h"
21+
#include "common/keywords.h"
2222

2323

24-
/* Globals from keywords.c */
25-
extern const ScanKeyword FEScanKeywords[];
26-
extern const int NumFEScanKeywords;
27-
2824
#define supports_grant_options(version) ((version) >= 70400)
2925

3026
static bool parseAclItem(const char *item, const char *type,
@@ -116,8 +112,8 @@ fmtId(const char *rawid)
116112
* that's fine, since we already know we have all-lower-case.
117113
*/
118114
const ScanKeyword *keyword = ScanKeywordLookup(rawid,
119-
FEScanKeywords,
120-
NumFEScanKeywords);
115+
ScanKeywords,
116+
NumScanKeywords);
121117

122118
if (keyword != NULL && keyword->category != UNRESERVED_KEYWORD)
123119
need_quotes = true;

src/bin/pg_dump/keywords.c

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/bin/psql/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
/sql_help.h
44
/sql_help.c
55
/dumputils.c
6-
/keywords.c
7-
/kwlookup.c
86

97
/psql

0 commit comments

Comments
 (0)