Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c6af4f

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 andkeyword lookup code were formerly shared between different uses.This is a first step towards a more general plan of getting rid ofspecial-purpose kluges for sharing code in src/bin/.I chose to merge kwlookup.c back into keywords.c, as it once was, andalways has been so far as keywords.h is concerned. We could havekept them separate, but there is noplace that uses ScanKeywordLookupwithout also wanting access to the backend's keyword list, so thereseems 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 beyondwhat's done here ... but we'll soon find out.
1 parent3df9c37 commit2c6af4f

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
overrideCPPFLAGS := -I. -I$(srcdir)$(CPPFLAGS)
1414

15-
OBJS= analyze.o gram.o scan.okeywords.o kwlookup.oparser.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.oscan.okeywords.oparser.o: gram.h
47+
gram.oscan.oparser.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.cthings start here
1111
scan.lbreak query into tokens
1212
scansup.chandle escapes in input strings
13-
kwlookup.cturn keywords into specific tokens
14-
keywords.ctable of standard keywords (passed to kwlookup.c)
1513
gram.yparse the tokens and produce a "raw" parse tree
1614
analyze.ctop level of parse analysis for optimizable queries
1715
parse_agg.chandle aggregates, like SUM(col1), AVG(col2), ...
@@ -28,3 +26,7 @@ parse_relation.c support routines for tables and column handling
2826
parse_target.chandle the result list of the query
2927
parse_type.csupport routines for data type handling
3028
parse_utilcmd.cparse 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
cleandistcleanmaintainer-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-
externconstScanKeywordFEScanKeywords[];
26-
externconstintNumFEScanKeywords;
27-
2824
#definesupports_grant_options(version) ((version) >= 70400)
2925

3026
staticboolparseAclItem(constchar*item,constchar*type,
@@ -116,8 +112,8 @@ fmtId(const char *rawid)
116112
* that's fine, since we already know we have all-lower-case.
117113
*/
118114
constScanKeyword*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

‎src/bin/psql/Makefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ override CPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir) -I$(top_srcdir)/src/bin/p
2222

2323
OBJS=command.o common.o help.o input.o stringutils.o mainloop.o copy.o\
2424
startup.o prompt.o variables.o large_obj.o print.o describe.o\
25-
tab-complete.o mbprint.o dumputils.okeywords.o kwlookup.o\
25+
tab-complete.o mbprint.o dumputils.o\
2626
sql_help.o psqlscan.o psqlscanslash.o\
2727
$(WIN32RES)
2828

@@ -34,10 +34,7 @@ psql: $(OBJS) | submake-libpq submake-libpgport
3434

3535
help.o: sql_help.h
3636

37-
dumputils.ckeywords.c:% :$(top_srcdir)/src/bin/pg_dump/%
38-
rm -f$@&&$(LN_S)$<.
39-
40-
kwlookup.c:% :$(top_srcdir)/src/backend/parser/%
37+
dumputils.c:% :$(top_srcdir)/src/bin/pg_dump/%
4138
rm -f$@&&$(LN_S)$<.
4239

4340
sql_help.c: sql_help.h ;
@@ -70,7 +67,7 @@ uninstall:
7067
rm -f'$(DESTDIR)$(bindir)/psql$(X)''$(DESTDIR)$(datadir)/psqlrc.sample'
7168

7269
cleandistclean:
73-
rm -f psql$(X)$(OBJS) dumputils.ckeywords.c kwlookup.clex.backup
70+
rm -f psql$(X)$(OBJS) dumputils.c lex.backup
7471

7572
# files removed here are supposed to be in the distribution tarball,
7673
# so do not clean them in the clean/distclean rules

‎src/bin/scripts/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
/pg_isready
1111

1212
/dumputils.c
13-
/keywords.c
14-
/kwlookup.c
1513
/mbprint.c
1614
/print.c
1715

‎src/bin/scripts/Makefile

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,23 @@ all: $(PROGRAMS)
2525
%:%.o$(WIN32RES)
2626
$(CC)$(CFLAGS)$^$(libpq_pgport)$(LDFLAGS)$(LDFLAGS_EX)$(LIBS) -o$@$(X)
2727

28-
createdb: createdb.o common.o dumputils.okwlookup.o keywords.o| submake-libpq submake-libpgport
28+
createdb: createdb.o common.o dumputils.o | submake-libpq submake-libpgport
2929
createlang: createlang.o common.o print.o mbprint.o | submake-libpq submake-libpgport
30-
createuser: createuser.o common.o dumputils.okwlookup.o keywords.o| submake-libpq submake-libpgport
31-
dropdb: dropdb.o common.o dumputils.okwlookup.o keywords.o| submake-libpq submake-libpgport
30+
createuser: createuser.o common.o dumputils.o | submake-libpq submake-libpgport
31+
dropdb: dropdb.o common.o dumputils.o | submake-libpq submake-libpgport
3232
droplang: droplang.o common.o print.o mbprint.o | submake-libpq submake-libpgport
33-
dropuser: dropuser.o common.o dumputils.okwlookup.o keywords.o| submake-libpq submake-libpgport
34-
clusterdb: clusterdb.o common.o dumputils.okwlookup.o keywords.o| submake-libpq submake-libpgport
35-
vacuumdb: vacuumdb.o common.o dumputils.okwlookup.o keywords.o| submake-libpq submake-libpgport
36-
reindexdb: reindexdb.o common.o dumputils.okwlookup.o keywords.o| submake-libpq submake-libpgport
33+
dropuser: dropuser.o common.o dumputils.o | submake-libpq submake-libpgport
34+
clusterdb: clusterdb.o common.o dumputils.o | submake-libpq submake-libpgport
35+
vacuumdb: vacuumdb.o common.o dumputils.o | submake-libpq submake-libpgport
36+
reindexdb: reindexdb.o common.o dumputils.o | submake-libpq submake-libpgport
3737
pg_isready: pg_isready.o common.o | submake-libpq submake-libpgport
3838

39-
dumputils.ckeywords.c:% :$(top_srcdir)/src/bin/pg_dump/%
39+
dumputils.c:% :$(top_srcdir)/src/bin/pg_dump/%
4040
rm -f$@&&$(LN_S)$<.
4141

4242
print.cmbprint.c :% :$(top_srcdir)/src/bin/psql/%
4343
rm -f$@&&$(LN_S)$<.
4444

45-
kwlookup.c:% :$(top_srcdir)/src/backend/parser/%
46-
rm -f$@&&$(LN_S)$<.
47-
4845
install: all installdirs
4946
$(INSTALL_PROGRAM) createdb$(X)'$(DESTDIR)$(bindir)'/createdb$(X)
5047
$(INSTALL_PROGRAM) dropdb$(X)'$(DESTDIR)$(bindir)'/dropdb$(X)
@@ -65,8 +62,8 @@ uninstall:
6562

6663
cleandistcleanmaintainer-clean:
6764
rm -f$(addsuffix$(X),$(PROGRAMS))$(addsuffix .o,$(PROGRAMS))
68-
rm -f common.o dumputils.okwlookup.o keywords.oprint.o mbprint.o$(WIN32RES)
69-
rm -f dumputils.c print.c mbprint.c kwlookup.c keywords.c
65+
rm -f common.o dumputils.o print.o mbprint.o$(WIN32RES)
66+
rm -f dumputils.c print.c mbprint.c
7067
rm -rf tmp_check
7168

7269
check:

‎src/common/Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ override CPPFLAGS += -DVAL_LDFLAGS_EX="\"$(LDFLAGS_EX)\""
3636
overrideCPPFLAGS += -DVAL_LDFLAGS_SL="\"$(LDFLAGS_SL)\""
3737
overrideCPPFLAGS += -DVAL_LIBS="\"$(LIBS)\""
3838

39-
OBJS_COMMON = config_info.o controldata_utils.o exec.o pg_lzcompress.o\
40-
pgfnames.o psprintf.o relpath.o rmtree.o string.o username.o wait_error.o
39+
OBJS_COMMON = config_info.o controldata_utils.o exec.o keywords.o\
40+
pg_lzcompress.o pgfnames.o psprintf.o relpath.o rmtree.o\
41+
string.o username.o wait_error.o
4142

4243
OBJS_FRONTEND =$(OBJS_COMMON) fe_memutils.o restricted_token.o
4344

@@ -83,5 +84,14 @@ $(OBJS_SRV): | submake-errcodes
8384
submake-errcodes:
8485
$(MAKE) -C ../backend submake-errcodes
8586

87+
# Dependencies of keywords.o need to be managed explicitly to make sure
88+
# that you don't get broken parsing code, even in a non-enable-depend build.
89+
# Note that gram.h isn't required for the frontend version of keywords.o.
90+
$(top_builddir)/src/include/parser/gram.h:$(top_srcdir)/src/backend/parser/gram.y
91+
$(MAKE) -C$(top_builddir)/src/backend$(top_builddir)/src/include/parser/gram.h
92+
93+
keywords.o:$(top_srcdir)/src/include/parser/kwlist.h
94+
keywords_srv.o:$(top_builddir)/src/include/parser/gram.h$(top_srcdir)/src/include/parser/kwlist.h
95+
8696
cleandistcleanmaintainer-clean:
8797
rm -f libpgcommon.a libpgcommon_srv.a$(OBJS_FRONTEND)$(OBJS_SRV)

‎src/backend/parser/kwlookup.crenamed to‎src/common/keywords.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,56 @@
11
/*-------------------------------------------------------------------------
22
*
3-
*kwlookup.c
3+
*keywords.c
44
* lexical token lookup for key words in PostgreSQL
55
*
6-
* NB - this file is also used by ECPG and several frontend programs in
7-
* src/bin/ including pg_dump and psql
86
*
97
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
108
* Portions Copyright (c) 1994, Regents of the University of California
119
*
1210
*
1311
* IDENTIFICATION
14-
* src/backend/parser/kwlookup.c
12+
* src/common/keywords.c
1513
*
1614
*-------------------------------------------------------------------------
1715
*/
16+
#ifndefFRONTEND
17+
#include"postgres.h"
18+
#else
19+
#include"postgres_fe.h"
20+
#endif
1821

19-
/* use c.h so this can be built as either frontend or backend */
20-
#include"c.h"
22+
#ifndefFRONTEND
2123

22-
#include<ctype.h>
24+
#include"parser/gramparse.h"
25+
26+
#definePG_KEYWORD(a,b,c) {a,b,c},
27+
28+
#else
29+
30+
#include"common/keywords.h"
31+
32+
/*
33+
* We don't need the token number for frontend uses, so leave it out to avoid
34+
* requiring backend headers that won't compile cleanly here.
35+
*/
36+
#definePG_KEYWORD(a,b,c) {a,0,c},
37+
38+
#endif/* FRONTEND */
39+
40+
41+
constScanKeywordScanKeywords[]= {
42+
#include"parser/kwlist.h"
43+
};
44+
45+
constintNumScanKeywords=lengthof(ScanKeywords);
2346

24-
#include"parser/keywords.h"
2547

2648
/*
2749
* ScanKeywordLookup - see if a given word is a keyword
2850
*
51+
* The table to be searched is passed explicitly, so that this can be used
52+
* to search keyword lists other than the standard list appearing above.
53+
*
2954
* Returns a pointer to the ScanKeyword table entry, or NULL if no match.
3055
*
3156
* The match is done case-insensitively. Note that we deliberately use a

‎src/include/parser/keywords.hrenamed to‎src/include/common/keywords.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* src/include/parser/keywords.h
10+
* src/include/common/keywords.h
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,6 +31,7 @@ typedef struct ScanKeyword
3131
externPGDLLIMPORTconstScanKeywordScanKeywords[];
3232
externPGDLLIMPORTconstintNumScanKeywords;
3333

34+
3435
externconstScanKeyword*ScanKeywordLookup(constchar*text,
3536
constScanKeyword*keywords,
3637
intnum_keywords);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp