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

Commitc115641

Browse files
committed
Move psql's psqlscan.l into src/fe_utils.
This completes (at least for now) the project of getting rid of ad-hoclinkages among the src/bin/ subdirectories. Everything they share is nowin src/fe_utils/ and is included from a static library at link time.A side benefit is that we can restore the FLEX_NO_BACKUP check forpsqlscanslash.l. We might need to think of another way to do that checkif we ever need to build two lexers with that property in the same sourcedirectory, but there's no foreseeable reason to need that.
1 parentd65bea2 commitc115641

File tree

20 files changed

+120
-90
lines changed

20 files changed

+120
-90
lines changed

‎src/backend/parser/scan.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* NOTE NOTE NOTE:
88
*
9-
* The rules in this file must be kept in sync withpsql'spsqlscan.l!
9+
* The rules in this file must be kept in sync withsrc/fe_utils/psqlscan.l!
1010
*
1111
* The rules are designed so that the scanner never has to backtrack,
1212
* in the sense that there is always a rule that can match the input

‎src/bin/pgbench/Makefile

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ subdir = src/bin/pgbench
77
top_builddir = ../../..
88
include$(top_builddir)/src/Makefile.global
99

10-
OBJS = pgbench.o exprparse.opsqlscan.o$(WIN32RES)
10+
OBJS = pgbench.o exprparse.o$(WIN32RES)
1111

12-
overrideCPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir)\
13-
-I$(top_srcdir)/src/bin/psql$(CPPFLAGS)
12+
overrideCPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir)$(CPPFLAGS)
13+
LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils
1414

1515
ifneq ($(PORTNAME), win32)
1616
overrideCFLAGS +=$(PTHREAD_CFLAGS)
@@ -19,21 +19,12 @@ endif
1919

2020
all: pgbench
2121

22-
pgbench:$(OBJS) | submake-libpq submake-libpgport
22+
pgbench:$(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils
2323
$(CC)$(CFLAGS)$^$(libpq_pgport)$(PTHREAD_LIBS)$(LDFLAGS)$(LDFLAGS_EX)$(LIBS) -o$@$(X)
2424

2525
# exprscan is compiled as part of exprparse
2626
exprparse.o: exprscan.c
2727

28-
# we import psqlscan.o as-is from psql
29-
submake-psqlscan:
30-
$(MAKE) -C$(top_builddir)/src/bin/psql psqlscan.o
31-
32-
psqlscan.o: | submake-psqlscan
33-
rm -f$@&&$(LN_S)$(top_builddir)/src/bin/psql/psqlscan.o.
34-
35-
.PHONY: submake-psqlscan
36-
3728
distprep: exprparse.c exprscan.c
3829

3930
install: all installdirs

‎src/bin/pgbench/exprscan.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*-------------------------------------------------------------------------
2424
*/
2525

26-
#include"psqlscan_int.h"
26+
#include"fe_utils/psqlscan_int.h"
2727

2828
/* context information for reporting errors in expressions*/
2929
staticconstchar *expr_source =NULL;

‎src/bin/pgbench/pgbench.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#ifndefPGBENCH_H
1212
#definePGBENCH_H
1313

14-
#include"psqlscan.h"
14+
#include"fe_utils/psqlscan.h"
1515

1616
/*
1717
* This file is included outside exprscan.l, in places where we can't see

‎src/bin/psql/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/psqlscan.c
21
/psqlscanslash.c
32
/sql_help.h
43
/sql_help.c

‎src/bin/psql/Makefile

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils
2424
OBJS=command.o common.o help.o input.o stringutils.o mainloop.o copy.o\
2525
startup.o prompt.o variables.o large_obj.o describe.o\
2626
tab-complete.o\
27-
sql_help.opsqlscan.opsqlscanslash.o\
27+
sql_help.o psqlscanslash.o\
2828
$(WIN32RES)
2929

3030

@@ -39,20 +39,15 @@ sql_help.c: sql_help.h ;
3939
sql_help.h: create_help.pl$(wildcard$(REFDOCDIR)/*.sgml)
4040
$(PERL)$<$(REFDOCDIR)$*
4141

42-
psqlscan.c: FLEXFLAGS = -Cfe -p -p
43-
psqlscan.c: FLEX_NO_BACKUP=yes
44-
4542
psqlscanslash.c: FLEXFLAGS = -Cfe -p -p
46-
# Ideally we'd check this, but parallel make causes problems:
47-
# psqlscanslash.c: FLEX_NO_BACKUP=yes
43+
psqlscanslash.c: FLEX_NO_BACKUP=yes
4844

49-
# Latest flex causes warnings inthese files.
45+
# Latest flex causes warnings inthis file.
5046
ifeq ($(GCC),yes)
51-
psqlscan.o: CFLAGS += -Wno-error
5247
psqlscanslash.o: CFLAGS += -Wno-error
5348
endif
5449

55-
distprep: sql_help.hpsqlscan.cpsqlscanslash.c
50+
distprep: sql_help.h psqlscanslash.c
5651

5752
install: all installdirs
5853
$(INSTALL_PROGRAM) psql$(X)'$(DESTDIR)$(bindir)/psql$(X)'
@@ -70,4 +65,4 @@ clean distclean:
7065
# files removed here are supposed to be in the distribution tarball,
7166
# so do not clean them in the clean/distclean rules
7267
maintainer-clean: distclean
73-
rm -f sql_help.h sql_help.cpsqlscan.cpsqlscanslash.c
68+
rm -f sql_help.h sql_help.c psqlscanslash.c

‎src/bin/psql/command.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#defineCOMMAND_H
1010

1111
#include"fe_utils/print.h"
12-
#include"psqlscan.h"
12+
#include"fe_utils/psqlscan.h"
1313

1414

1515
typedefenum_backslashResult

‎src/bin/psql/mainloop.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include"command.h"
1212
#include"common.h"
1313
#include"input.h"
14+
#include"prompt.h"
1415
#include"settings.h"
1516

1617
#include"mb/pg_wchar.h"

‎src/bin/psql/mainloop.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndefMAINLOOP_H
99
#defineMAINLOOP_H
1010

11-
#include"psqlscan.h"
11+
#include"fe_utils/psqlscan.h"
1212

1313
externconstPsqlScanCallbackspsqlscan_callbacks;
1414

‎src/bin/psql/nls.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
CATALOG_NAME = psql
33
AVAIL_LANGUAGES = cs de es fr it ja pl pt_BR ru zh_CN zh_TW
44
GETTEXT_FILES = command.c common.c copy.c help.c input.c large_obj.c\
5-
mainloop.cpsqlscan.cpsqlscanslash.c startup.c\
5+
mainloop.c psqlscanslash.c startup.c\
66
describe.c sql_help.h sql_help.c\
77
tab-complete.c variables.c\
8-
../../fe_utils/print.c\
8+
../../fe_utils/print.c../../fe_utils/psqlscan.c\
99
../../common/exec.c ../../common/fe_memutils.c ../../common/username.c\
1010
../../common/wait_error.c
1111
GETTEXT_TRIGGERS = N_ psql_error simple_prompt

‎src/bin/psql/prompt.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,8 @@
88
#ifndefPROMPT_H
99
#definePROMPT_H
1010

11-
typedefenum_promptStatus
12-
{
13-
PROMPT_READY,
14-
PROMPT_CONTINUE,
15-
PROMPT_COMMENT,
16-
PROMPT_SINGLEQUOTE,
17-
PROMPT_DOUBLEQUOTE,
18-
PROMPT_DOLLARQUOTE,
19-
PROMPT_PAREN,
20-
PROMPT_COPY
21-
}promptStatus_t;
11+
/* enum promptStatus_t is now defined by psqlscan.h */
12+
#include"fe_utils/psqlscan.h"
2213

2314
char*get_prompt(promptStatus_tstatus);
2415

‎src/bin/psql/psqlscanslash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndefPSQLSCANSLASH_H
99
#definePSQLSCANSLASH_H
1010

11-
#include"psqlscan.h"
11+
#include"fe_utils/psqlscan.h"
1212

1313

1414
/* Different ways for scan_slash_option to handle parameter words */

‎src/bin/psql/psqlscanslash.l

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* XXX Avoid creating backtracking cases --- see the backend lexer for info.
88
*
9-
* See psqlscan_int.h for additional commentary.
9+
* Seefe_utils/psqlscan_int.h for additional commentary.
1010
*
1111
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
@@ -24,7 +24,7 @@
2424
}
2525

2626
%{
27-
#include"psqlscan_int.h"
27+
#include"fe_utils/psqlscan_int.h"
2828

2929
/*
3030
* We must have a typedef YYSTYPE for yylex's first argument, but this lexer

‎src/fe_utils/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/psqlscan.c

‎src/fe_utils/Makefile

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#-------------------------------------------------------------------------
22
#
3-
# Makefile
4-
# Makefile for src/fe_utils
3+
# Makefile for src/fe_utils
54
#
65
# This makefile generates a static library, libpgfeutils.a,
76
# for use by client applications
87
#
8+
# Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
9+
# Portions Copyright (c) 1994, Regents of the University of California
10+
#
911
# IDENTIFICATION
1012
# src/fe_utils/Makefile
1113
#
@@ -17,14 +19,24 @@ include $(top_builddir)/src/Makefile.global
1719

1820
overrideCPPFLAGS := -DFRONTEND -I$(libpq_srcdir)$(CPPFLAGS)
1921

20-
OBJS = mbprint.o print.o simple_list.o string_utils.o
22+
OBJS = mbprint.o print.opsqlscan.osimple_list.o string_utils.o
2123

2224
all: libpgfeutils.a
2325

2426
libpgfeutils.a:$(OBJS)
2527
rm -f$@
2628
$(AR)$(AROPT)$@$^
2729

30+
psqlscan.c: FLEXFLAGS = -Cfe -p -p
31+
psqlscan.c: FLEX_NO_BACKUP=yes
32+
33+
# Latest flex causes warnings in this file.
34+
ifeq ($(GCC),yes)
35+
psqlscan.o: CFLAGS += -Wno-error
36+
endif
37+
38+
distprep: psqlscan.c
39+
2840
# libpgfeutils could be useful to contrib, so install it
2941
install: all installdirs
3042
$(INSTALL_STLIB) libpgfeutils.a'$(DESTDIR)$(libdir)/libpgfeutils.a'
@@ -35,5 +47,10 @@ installdirs:
3547
uninstall:
3648
rm -f'$(DESTDIR)$(libdir)/libpgfeutils.a'
3749

38-
cleandistcleanmaintainer-clean:
39-
rm -f libpgfeutils.a$(OBJS)
50+
cleandistclean:
51+
rm -f libpgfeutils.a$(OBJS) lex.backup
52+
53+
# psqlscan.c is supposed to be in the distribution tarball,
54+
# so do not clean it in the clean/distclean rules
55+
maintainer-clean: distclean
56+
rm -f psqlscan.c

‎src/bin/psql/psqlscan.lrenamed to‎src/fe_utils/psqlscan.l

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
/*-------------------------------------------------------------------------
33
*
44
* psqlscan.l
5-
* lexical scanner forpsql (and other frontend programs)
5+
* lexical scanner forSQL commands
66
*
7-
* This code is mainly needed to determine where the end of a SQL statement
8-
* is: we are looking for semicolons that are not within quotes, comments,
9-
* or parentheses. The most reliable way to handle this is to borrow the
10-
* backend's flex lexer rules, lock, stock, and barrel. The rules below
11-
* are (except for a few) the same as the backend's, but their actions are
12-
* just ECHO whereas the backend's actions generally do other things.
7+
* This lexer used to be part of psql, and that heritage is reflected in
8+
* the file name as well as function and typedef names, though it can now
9+
* be used by other frontend programs as well. It's also possible to extend
10+
* this lexer with a compatible add-on lexer to handle program-specific
11+
* backslash commands.
12+
*
13+
* This code is mainly concerned with determining where the end of a SQL
14+
* statement is: we are looking for semicolons that are not within quotes,
15+
* comments, or parentheses. The most reliable way to handle this is to
16+
* borrow the backend's flex lexer rules, lock, stock, and barrel. The rules
17+
* below are (except for a few) the same as the backend's, but their actions
18+
* are just ECHO whereas the backend's actions generally do other things.
1319
*
1420
* XXX The rules in this file must be kept in sync with the backend lexer!!!
1521
*
@@ -21,19 +27,19 @@
2127
* Portions Copyright (c) 1994, Regents of the University of California
2228
*
2329
* IDENTIFICATION
24-
* src/bin/psql/psqlscan.l
30+
* src/fe_utils/psqlscan.l
2531
*
2632
*-------------------------------------------------------------------------
2733
*/
2834
#include "postgres_fe.h"
2935

30-
#include "psqlscan.h"
36+
#include "fe_utils/psqlscan.h"
3137

3238
#include "libpq-fe.h"
3339
}
3440

3541
%{
36-
#include"psqlscan_int.h"
42+
#include"fe_utils/psqlscan_int.h"
3743

3844
/*
3945
* We must have a typedef YYSTYPE for yylex's first argument, but this lexer
@@ -54,8 +60,6 @@ typedef int YYSTYPE;
5460
#defineLEXRES_BACKSLASH2/* backslash command start*/
5561

5662

57-
staticboolvar_is_current_source(PsqlScanState state,constchar *varname);
58-
5963
#defineECHOpsqlscan_emit(cur_state, yytext, yyleng)
6064

6165
/*
@@ -703,7 +707,7 @@ other.
703707
if (value)
704708
{
705709
/* It is a variable, check for recursion */
706-
if (var_is_current_source(cur_state, varname))
710+
if (psqlscan_var_is_current_source(cur_state, varname))
707711
{
708712
/* Recursive expansion --- don't go there */
709713
cur_state->callbacks->write_error("skipping recursive expansion of variable\"%s\"\n",
@@ -1264,8 +1268,8 @@ psqlscan_select_top_buffer(PsqlScanState state)
12641268
* Check if specified variable name is the source for any string
12651269
* currently being scanned
12661270
*/
1267-
staticbool
1268-
var_is_current_source(PsqlScanState state,constchar *varname)
1271+
bool
1272+
psqlscan_var_is_current_source(PsqlScanState state,constchar *varname)
12691273
{
12701274
StackElem *stackelem;
12711275

‎src/bin/psql/psqlscan.hrenamed to‎src/include/fe_utils/psqlscan.h

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
/*
2-
* psql - the PostgreSQL interactive terminal
1+
/*-------------------------------------------------------------------------
32
*
4-
* Copyright (c) 2000-2016, PostgreSQL Global Development Group
3+
* psqlscan.h
4+
* lexical scanner for SQL commands
55
*
6-
* src/bin/psql/psqlscan.h
6+
* This lexer used to be part of psql, and that heritage is reflected in
7+
* the file name as well as function and typedef names, though it can now
8+
* be used by other frontend programs as well. It's also possible to extend
9+
* this lexer with a compatible add-on lexer to handle program-specific
10+
* backslash commands.
11+
*
12+
*
13+
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
14+
* Portions Copyright (c) 1994, Regents of the University of California
15+
*
16+
* src/include/fe_utils/psqlscan.h
17+
*
18+
*-------------------------------------------------------------------------
719
*/
820
#ifndefPSQLSCAN_H
921
#definePSQLSCAN_H
1022

1123
#include"pqexpbuffer.h"
1224

13-
#include"prompt.h"
14-
1525

1626
/* Abstract type for lexer's internal state */
1727
typedefstructPsqlScanStateData*PsqlScanState;
@@ -25,6 +35,19 @@ typedef enum
2535
PSCAN_EOL/* end of line, SQL possibly complete */
2636
}PsqlScanResult;
2737

38+
/* Prompt type returned by psql_scan() */
39+
typedefenum_promptStatus
40+
{
41+
PROMPT_READY,
42+
PROMPT_CONTINUE,
43+
PROMPT_COMMENT,
44+
PROMPT_SINGLEQUOTE,
45+
PROMPT_DOUBLEQUOTE,
46+
PROMPT_DOLLARQUOTE,
47+
PROMPT_PAREN,
48+
PROMPT_COPY
49+
}promptStatus_t;
50+
2851
/* Callback functions to be used by the lexer */
2952
typedefstructPsqlScanCallbacks
3053
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp