Commit 328d2355 authored by Alvaro Herrera's avatar Alvaro Herrera

Separate the key word list that lived in keywords.c into a new header file

kwlist.h, to avoid having to link the backend object file into other programs
like pg_dump.  We can now simply symlink a single source file from the backend
(kwlookup.c, containing the shared routine ScanKeywordLookup) and compile it
locally, which is a lot cleaner.
parent 00ce7377
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# #
# Makefile for parser # Makefile for parser
# #
# $PostgreSQL: pgsql/src/backend/parser/Makefile,v 1.48 2008/10/04 21:56:54 tgl Exp $ # $PostgreSQL: pgsql/src/backend/parser/Makefile,v 1.49 2009/03/07 00:13:57 alvherre Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -14,7 +14,7 @@ override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) ...@@ -14,7 +14,7 @@ override CPPFLAGS := -I$(srcdir) $(CPPFLAGS)
OBJS= analyze.o gram.o keywords.o parser.o parse_agg.o parse_cte.o parse_clause.o \ OBJS= analyze.o gram.o keywords.o parser.o parse_agg.o parse_cte.o parse_clause.o \
parse_expr.o parse_func.o parse_node.o parse_oper.o parse_relation.o \ parse_expr.o parse_func.o parse_node.o parse_oper.o parse_relation.o \
parse_type.o parse_coerce.o parse_target.o parse_utilcmd.o scansup.o parse_type.o parse_coerce.o parse_target.o parse_utilcmd.o scansup.o kwlookup.o
FLEXFLAGS = -CF FLEXFLAGS = -CF
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.659 2009/02/24 10:06:33 petere Exp $ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.660 2009/03/07 00:13:57 alvherre Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -423,7 +423,7 @@ static TypeName *TableFuncTypeName(List *columns); ...@@ -423,7 +423,7 @@ static TypeName *TableFuncTypeName(List *columns);
/* /*
* If you make any token changes, update the keyword table in * If you make any token changes, update the keyword table in
* parser/keywords.c and add new keywords to the appropriate one of * src/include/parser/kwlist.h and add new keywords to the appropriate one of
* the reserved-or-not-so-reserved keyword lists, below; search * the reserved-or-not-so-reserved keyword lists, below; search
* this file for "Name classification hierarchy". * this file for "Name classification hierarchy".
*/ */
...@@ -516,7 +516,7 @@ static TypeName *TableFuncTypeName(List *columns); ...@@ -516,7 +516,7 @@ static TypeName *TableFuncTypeName(List *columns);
ZONE ZONE
/* The grammar thinks these are keywords, but they are not in the keywords.c /* The grammar thinks these are keywords, but they are not in the kwlist.h
* list and so can never be entered directly. The filter in parser.c * list and so can never be entered directly. The filter in parser.c
* creates these tokens when required. * creates these tokens when required.
*/ */
......
This diff is collapsed.
/*-------------------------------------------------------------------------
*
* kwlookup.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-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/kwlookup.c,v 2.1 2009/03/07 00:13:58 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
/* use c.h so this can be built as either frontend or backend */
#include "c.h"
#include <ctype.h>
#include "parser/keywords.h"
/*
* ScanKeywordLookup - see if a given word is a keyword
*
* 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
* dumbed-down case conversion that will only translate 'A'-'Z' into 'a'-'z',
* even if we are in a locale where tolower() would produce more or different
* translations. This is to conform to the SQL99 spec, which says that
* keywords are to be matched in this way even though non-keyword identifiers
* receive a different case-normalization mapping.
*/
const ScanKeyword *
ScanKeywordLookup(const char *text)
{
int len,
i;
char word[NAMEDATALEN];
const ScanKeyword *low;
const ScanKeyword *high;
len = strlen(text);
/* We assume all keywords are shorter than NAMEDATALEN. */
if (len >= NAMEDATALEN)
return NULL;
/*
* Apply an ASCII-only downcasing. We must not use tolower() since it may
* produce the wrong translation in some locales (eg, Turkish).
*/
for (i = 0; i < len; i++)
{
char ch = text[i];
if (ch >= 'A' && ch <= 'Z')
ch += 'a' - 'A';
word[i] = ch;
}
word[len] = '\0';
/*
* Now do a binary search using plain strcmp() comparison.
*/
low = &ScanKeywords[0];
high = LastScanKeyword - 1;
while (low <= high)
{
const ScanKeyword *middle;
int difference;
middle = low + (high - low) / 2;
difference = strcmp(middle->name, word);
if (difference == 0)
return middle;
else if (difference < 0)
low = middle + 1;
else
high = middle - 1;
}
return NULL;
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $PostgreSQL: pgsql/src/bin/pg_dump/Makefile,v 1.66 2009/01/01 17:23:54 momjian Exp $ # $PostgreSQL: pgsql/src/bin/pg_dump/Makefile,v 1.67 2009/03/07 00:13:58 alvherre Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -20,23 +20,21 @@ OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \ ...@@ -20,23 +20,21 @@ OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
pg_backup_files.o pg_backup_null.o pg_backup_tar.o \ pg_backup_files.o pg_backup_null.o pg_backup_tar.o \
dumputils.o $(WIN32RES) dumputils.o $(WIN32RES)
EXTRA_OBJS = $(top_builddir)/src/backend/parser/keywords.o KEYWRDOBJS = keywords.o kwlookup.o
all: submake-libpq submake-libpgport submake-backend pg_dump pg_restore pg_dumpall kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
rm -f $@ && $(LN_S) $< .
pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) $(libpq_builddir)/libpq.a all: submake-libpq submake-libpgport pg_dump pg_restore pg_dumpall
$(CC) $(CFLAGS) pg_dump.o common.o pg_dump_sort.o $(OBJS) $(EXTRA_OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X)
pg_restore: pg_restore.o $(OBJS) $(libpq_builddir)/libpq.a pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) $(KEYWRDOBJS) $(libpq_builddir)/libpq.a
$(CC) $(CFLAGS) pg_restore.o $(OBJS) $(EXTRA_OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) pg_dump.o common.o pg_dump_sort.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X)
pg_dumpall: pg_dumpall.o dumputils.o $(libpq_builddir)/libpq.a pg_restore: pg_restore.o $(OBJS) $(KEYWRDOBJS) $(libpq_builddir)/libpq.a
$(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(EXTRA_OBJS) $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) pg_restore.o $(KEYWRDOBJS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X)
.PHONY: submake-backend
submake-backend:
$(MAKE) -C $(top_builddir)/src/backend/parser keywords.o
pg_dumpall: pg_dumpall.o dumputils.o $(KEYWRDOBJS) $(libpq_builddir)/libpq.a
$(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(KEYWRDOBJS) $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X)
install: all installdirs install: all installdirs
$(INSTALL_PROGRAM) pg_dump$(X) '$(DESTDIR)$(bindir)'/pg_dump$(X) $(INSTALL_PROGRAM) pg_dump$(X) '$(DESTDIR)$(bindir)'/pg_dump$(X)
...@@ -50,4 +48,4 @@ uninstall: ...@@ -50,4 +48,4 @@ uninstall:
rm -f $(addprefix '$(DESTDIR)$(bindir)'/, pg_dump$(X) pg_restore$(X) pg_dumpall$(X)) rm -f $(addprefix '$(DESTDIR)$(bindir)'/, pg_dump$(X) pg_restore$(X) pg_dumpall$(X))
clean distclean maintainer-clean: 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 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)
/*-------------------------------------------------------------------------
*
* keywords.c
* lexical token lookup for key words in PostgreSQL
*
*
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/keywords.c,v 1.1 2009/03/07 00:13:58 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
#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 ScanKeywords[] = {
#include "parser/kwlist.h"
};
/* End of ScanKeywords, for use elsewhere */
const ScanKeyword *LastScanKeyword = endof(ScanKeywords);
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.61 2009/01/01 17:23:54 momjian Exp $ # $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.62 2009/03/07 00:13:58 alvherre Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -21,21 +21,23 @@ override CPPFLAGS := -I$(srcdir) -I$(libpq_srcdir) -I$(top_srcdir)/src/bin/pg_du ...@@ -21,21 +21,23 @@ override CPPFLAGS := -I$(srcdir) -I$(libpq_srcdir) -I$(top_srcdir)/src/bin/pg_du
OBJS= command.o common.o help.o input.o stringutils.o mainloop.o copy.o \ 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 \ startup.o prompt.o variables.o large_obj.o print.o describe.o \
psqlscan.o tab-complete.o mbprint.o dumputils.o $(WIN32RES) psqlscan.o tab-complete.o mbprint.o dumputils.o keywords.o kwlookup.o \
$(WIN32RES)
EXTRA_OBJS = $(top_builddir)/src/backend/parser/keywords.o
FLEXFLAGS = -Cfe FLEXFLAGS = -Cfe
all: submake-libpq submake-libpgport submake-backend psql all: submake-libpq submake-libpgport psql
psql: $(OBJS) $(libpq_builddir)/libpq.a psql: $(OBJS) $(libpq_builddir)/libpq.a
$(CC) $(CFLAGS) $(OBJS) $(EXTRA_OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X)
help.o: $(srcdir)/sql_help.h help.o: $(srcdir)/sql_help.h
dumputils.c: % : $(top_srcdir)/src/bin/pg_dump/% dumputils.c keywords.c: % : $(top_srcdir)/src/bin/pg_dump/%
rm -f $@ && $(LN_S) $< .
kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
rm -f $@ && $(LN_S) $< . rm -f $@ && $(LN_S) $< .
ifdef PERL ifdef PERL
...@@ -53,10 +55,6 @@ else ...@@ -53,10 +55,6 @@ else
@$(missing) flex $< $@ @$(missing) flex $< $@
endif endif
.PHONY: submake-backend
submake-backend:
$(MAKE) -C $(top_builddir)/src/backend/parser keywords.o
distprep: $(srcdir)/sql_help.h $(srcdir)/psqlscan.c distprep: $(srcdir)/sql_help.h $(srcdir)/psqlscan.c
install: all installdirs install: all installdirs
...@@ -71,7 +69,7 @@ uninstall: ...@@ -71,7 +69,7 @@ uninstall:
# psqlscan.c is in the distribution tarball, so is not cleaned here # psqlscan.c is in the distribution tarball, so is not cleaned here
clean distclean: clean distclean:
rm -f psql$(X) $(OBJS) dumputils.c rm -f psql$(X) $(OBJS) dumputils.c keywords.c kwlookup.c
maintainer-clean: distclean maintainer-clean: distclean
rm -f $(srcdir)/sql_help.h $(srcdir)/psqlscan.c rm -f $(srcdir)/sql_help.h $(srcdir)/psqlscan.c
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $PostgreSQL: pgsql/src/bin/scripts/Makefile,v 1.40 2009/01/01 17:23:55 momjian Exp $ # $PostgreSQL: pgsql/src/bin/scripts/Makefile,v 1.41 2009/03/07 00:13:58 alvherre Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -18,31 +18,31 @@ PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vac ...@@ -18,31 +18,31 @@ PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vac
override CPPFLAGS := -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS) override CPPFLAGS := -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)
all: submake-libpq submake-backend $(PROGRAMS) all: submake-libpq $(PROGRAMS)
%: %.o $(WIN32RES) %: %.o $(WIN32RES)
$(CC) $(CFLAGS) $^ $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) $^ $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X)
createdb: createdb.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o DUMPUTILSOBJS = dumputils.o kwlookup.o keywords.o
createdb: createdb.o common.o $(DUMPUTILSOBJS)
createlang: createlang.o common.o print.o mbprint.o createlang: createlang.o common.o print.o mbprint.o
createuser: createuser.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o createuser: createuser.o common.o $(DUMPUTILSOBJS)
dropdb: dropdb.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o dropdb: dropdb.o common.o $(DUMPUTILSOBJS)
droplang: droplang.o common.o print.o mbprint.o droplang: droplang.o common.o print.o mbprint.o
dropuser: dropuser.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o dropuser: dropuser.o common.o $(DUMPUTILSOBJS)
clusterdb: clusterdb.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o clusterdb: clusterdb.o common.o $(DUMPUTILSOBJS)
vacuumdb: vacuumdb.o common.o vacuumdb: vacuumdb.o common.o
reindexdb: reindexdb.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o reindexdb: reindexdb.o common.o $(DUMPUTILSOBJS)
dumputils.c: % : $(top_srcdir)/src/bin/pg_dump/% dumputils.c keywords.c: % : $(top_srcdir)/src/bin/pg_dump/%
rm -f $@ && $(LN_S) $< . rm -f $@ && $(LN_S) $< .
print.c mbprint.c : % : $(top_srcdir)/src/bin/psql/% print.c mbprint.c : % : $(top_srcdir)/src/bin/psql/%
rm -f $@ && $(LN_S) $< . rm -f $@ && $(LN_S) $< .
.PHONY: submake-backend kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
submake-backend: rm -f $@ && $(LN_S) $< .
$(MAKE) -C $(top_builddir)/src/backend/parser keywords.o
install: all installdirs install: all installdirs
$(INSTALL_PROGRAM) createdb$(X) '$(DESTDIR)$(bindir)'/createdb$(X) $(INSTALL_PROGRAM) createdb$(X) '$(DESTDIR)$(bindir)'/createdb$(X)
...@@ -64,5 +64,5 @@ uninstall: ...@@ -64,5 +64,5 @@ uninstall:
clean distclean maintainer-clean: clean distclean maintainer-clean:
rm -f $(addsuffix $(X), $(PROGRAMS)) $(addsuffix .o, $(PROGRAMS)) rm -f $(addsuffix $(X), $(PROGRAMS)) $(addsuffix .o, $(PROGRAMS))
rm -f common.o dumputils.o print.o mbprint.o $(WIN32RES) rm -f common.o $(DUMPUTILSOBJS) print.o mbprint.o $(WIN32RES)
rm -f dumputils.c print.c mbprint.c rm -f dumputils.c print.c mbprint.c kwlookup.c keywords.c
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# #
# Copyright (c) 1998-2009, PostgreSQL Global Development Group # Copyright (c) 1998-2009, PostgreSQL Global Development Group
# #
# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.141 2009/01/01 17:24:02 momjian Exp $ # $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.142 2009/03/07 00:13:58 alvherre Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -25,7 +25,7 @@ override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \ ...@@ -25,7 +25,7 @@ override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
override CFLAGS += $(PTHREAD_CFLAGS) -DECPG_COMPILE override CFLAGS += $(PTHREAD_CFLAGS) -DECPG_COMPILE
OBJS= preproc.o type.o ecpg.o output.o parser.o \ OBJS= preproc.o type.o ecpg.o output.o parser.o \
keywords.o c_keywords.o ecpg_keywords.o ../ecpglib/typename.o descriptor.o variable.o \ keywords.o c_keywords.o ecpg_keywords.o kwlookup.o ../ecpglib/typename.o descriptor.o variable.o \
$(WIN32RES) $(WIN32RES)
all: submake-libpgport ecpg all: submake-libpgport ecpg
...@@ -57,8 +57,7 @@ $(srcdir)/preproc.y: $(top_srcdir)/src/backend/parser/gram.y parse.pl ecpg.addon ...@@ -57,8 +57,7 @@ $(srcdir)/preproc.y: $(top_srcdir)/src/backend/parser/gram.y parse.pl ecpg.addon
ecpg_keywords.o c_keywords.o keywords.o preproc.o parser.o: preproc.h ecpg_keywords.o c_keywords.o keywords.o preproc.o parser.o: preproc.h
# instead of maintaining our own list, take the one from the backend kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
keywords.c: % : $(top_srcdir)/src/backend/parser/%
rm -f $@ && $(LN_S) $< . rm -f $@ && $(LN_S) $< .
distprep: $(srcdir)/preproc.y $(srcdir)/preproc.c $(srcdir)/preproc.h $(srcdir)/pgc.c distprep: $(srcdir)/preproc.y $(srcdir)/preproc.c $(srcdir)/preproc.h $(srcdir)/pgc.c
...@@ -73,7 +72,7 @@ uninstall: ...@@ -73,7 +72,7 @@ uninstall:
rm -f '$(DESTDIR)$(bindir)/ecpg$(X)' rm -f '$(DESTDIR)$(bindir)/ecpg$(X)'
clean distclean: clean distclean:
rm -f keywords.c *.o ecpg$(X) rm -f kwlookup.c *.o ecpg$(X)
# garbage from development # garbage from development
@rm -f core a.out @rm -f core a.out
......
/*-------------------------------------------------------------------------
*
* keywords.c
* lexical token lookup for key words in PostgreSQL
*
*
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.87 2009/03/07 00:13:58 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "parser/keywords.h"
#include "type.h"
#include "preproc.h"
#define PG_KEYWORD(a,b,c) {a,b,c},
const ScanKeyword ScanKeywords[] = {
#include "parser/kwlist.h"
};
/* End of ScanKeywords, for use elsewhere */
const ScanKeyword *LastScanKeyword = endof(ScanKeywords);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment