Skip to content

Commit dac048f

Browse files
committed
Build all Flex files standalone
The proposed Meson build system will need a way to ignore certain generated files in order to coexist with the autoconf build system, and C files generated by Flex which are #include'd into .y files make this more difficult. In similar vein to 72b1e3a, arrange for all Flex C files to compile to their own .o targets. Reviewed by Andres Freund Discussion: https://www.postgresql.org/message-id/20220810171935.7k5zgnjwqzalzmtm%40awork3.anarazel.de Discussion: https://www.postgresql.org/message-id/CAFBsxsF8Gc2StS3haXofshHCzqNMRXiSxvQEYGwnFsTmsdwNeg@mail.gmail.com
1 parent 80e8450 commit dac048f

38 files changed

+307
-190
lines changed

contrib/cube/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/cubeparse.h
12
/cubeparse.c
23
/cubescan.c
34
# Generated subdirectories

contrib/cube/Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ MODULE_big = cube
44
OBJS = \
55
$(WIN32RES) \
66
cube.o \
7-
cubeparse.o
7+
cubeparse.o \
8+
cubescan.o
89

910
EXTENSION = cube
1011
DATA = cube--1.2.sql cube--1.2--1.3.sql cube--1.3--1.4.sql cube--1.4--1.5.sql \
@@ -15,8 +16,6 @@ HEADERS = cubedata.h
1516

1617
REGRESS = cube cube_sci
1718

18-
EXTRA_CLEAN = y.tab.c y.tab.h
19-
2019
SHLIB_LINK += $(filter -lm, $(LIBS))
2120

2221
ifdef USE_PGXS
@@ -30,11 +29,16 @@ include $(top_builddir)/src/Makefile.global
3029
include $(top_srcdir)/contrib/contrib-global.mk
3130
endif
3231

32+
# See notes in src/backend/parser/Makefile about the following two rules
33+
cubeparse.h: cubeparse.c
34+
touch $@
35+
36+
cubeparse.c: BISONFLAGS += -d
3337

34-
# cubescan is compiled as part of cubeparse
35-
cubeparse.o: cubescan.c
38+
# Force these dependencies to be known even without dependency info built:
39+
cubeparse.o cubescan.o: cubeparse.h
3640

3741
distprep: cubeparse.c cubescan.c
3842

3943
maintainer-clean:
40-
rm -f cubeparse.c cubescan.c
44+
rm -f cubeparse.h cubeparse.c cubescan.c

contrib/cube/cube.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ cube_in(PG_FUNCTION_ARGS)
119119
{
120120
char *str = PG_GETARG_CSTRING(0);
121121
NDBOX *result;
122+
Size scanbuflen;
122123

123-
cube_scanner_init(str);
124+
cube_scanner_init(str, &scanbuflen);
124125

125-
if (cube_yyparse(&result) != 0)
126-
cube_yyerror(&result, "cube parser failed");
126+
cube_yyparse(&result, scanbuflen);
127127

128128
cube_scanner_finish();
129129

contrib/cube/cubedata.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ typedef struct NDBOX
6161

6262
/* in cubescan.l */
6363
extern int cube_yylex(void);
64-
extern void cube_yyerror(NDBOX **result, const char *message) pg_attribute_noreturn();
65-
extern void cube_scanner_init(const char *str);
64+
extern void cube_yyerror(NDBOX **result, Size scanbuflen, const char *message) pg_attribute_noreturn();
65+
extern void cube_scanner_init(const char *str, Size *scanbuflen);
6666
extern void cube_scanner_finish(void);
6767

6868
/* in cubeparse.y */
69-
extern int cube_yyparse(NDBOX **result);
69+
extern int cube_yyparse(NDBOX **result, Size scanbuflen);

contrib/cube/cubeparse.y

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
#define YYMALLOC palloc
2424
#define YYFREE pfree
2525

26-
static char *scanbuf;
27-
static int scanbuflen;
28-
2926
static int item_count(const char *s, char delim);
3027
static NDBOX *write_box(int dim, char *str1, char *str2);
3128
static NDBOX *write_point_as_box(int dim, char *str);
@@ -34,6 +31,7 @@ static NDBOX *write_point_as_box(int dim, char *str);
3431

3532
/* BISON Declarations */
3633
%parse-param {NDBOX **result}
34+
%parse-param {Size scanbuflen}
3735
%expect 0
3836
%name-prefix="cube_yy"
3937

@@ -265,5 +263,3 @@ write_point_as_box(int dim, char *str)
265263

266264
return bp;
267265
}
268-
269-
#include "cubescan.c"

contrib/cube/cubescan.l

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
%{
1+
%top{
22
/*
33
* A scanner for EMP-style numeric ranges
44
* contrib/cube/cubescan.l
55
*/
66

7+
#include "postgres.h"
8+
9+
/*
10+
* NB: include cubeparse.h only AFTER defining YYSTYPE (to match cubeparse.y)
11+
* and cubedata.h for NDBOX.
12+
*/
13+
#include "cubedata.h"
14+
#define YYSTYPE char *
15+
#include "cubeparse.h"
16+
}
17+
18+
%{
719
/* LCOV_EXCL_START */
820

921
/* No reason to constrain amount of data slurped */
@@ -21,9 +33,7 @@ fprintf_to_ereport(const char *fmt, const char *msg)
2133

2234
/* Handles to the buffer that the lexer uses internally */
2335
static YY_BUFFER_STATE scanbufhandle;
24-
/* this is now declared in cubeparse.y: */
25-
/* static char *scanbuf; */
26-
/* static int scanbuflen; */
36+
static char *scanbuf;
2737
%}
2838

2939
%option 8bit
@@ -45,24 +55,24 @@ NaN [nN][aA][nN]
4555

4656
%%
4757

48-
{float} yylval = yytext; return CUBEFLOAT;
49-
{infinity} yylval = yytext; return CUBEFLOAT;
50-
{NaN} yylval = yytext; return CUBEFLOAT;
51-
\[ yylval = "("; return O_BRACKET;
52-
\] yylval = ")"; return C_BRACKET;
53-
\( yylval = "("; return O_PAREN;
54-
\) yylval = ")"; return C_PAREN;
55-
\, yylval = ","; return COMMA;
58+
{float} cube_yylval = yytext; return CUBEFLOAT;
59+
{infinity} cube_yylval = yytext; return CUBEFLOAT;
60+
{NaN} cube_yylval = yytext; return CUBEFLOAT;
61+
\[ cube_yylval = "("; return O_BRACKET;
62+
\] cube_yylval = ")"; return C_BRACKET;
63+
\( cube_yylval = "("; return O_PAREN;
64+
\) cube_yylval = ")"; return C_PAREN;
65+
\, cube_yylval = ","; return COMMA;
5666
[ \t\n\r\f]+ /* discard spaces */
5767
. return yytext[0]; /* alert parser of the garbage */
5868

5969
%%
6070

6171
/* LCOV_EXCL_STOP */
6272

63-
/* result is not used, but Bison expects this signature */
73+
/* result and scanbuflen are not used, but Bison expects this signature */
6474
void
65-
yyerror(NDBOX **result, const char *message)
75+
cube_yyerror(NDBOX **result, Size scanbuflen, const char *message)
6676
{
6777
if (*yytext == YY_END_OF_BUFFER_CHAR)
6878
{
@@ -87,9 +97,9 @@ yyerror(NDBOX **result, const char *message)
8797
* Called before any actual parsing is done
8898
*/
8999
void
90-
cube_scanner_init(const char *str)
100+
cube_scanner_init(const char *str, Size *scanbuflen)
91101
{
92-
Size slen = strlen(str);
102+
Size slen = strlen(str);
93103

94104
/*
95105
* Might be left over after ereport()
@@ -100,7 +110,7 @@ cube_scanner_init(const char *str)
100110
/*
101111
* Make a scan buffer with special termination needed by flex.
102112
*/
103-
scanbuflen = slen;
113+
*scanbuflen = slen;
104114
scanbuf = palloc(slen + 2);
105115
memcpy(scanbuf, str, slen);
106116
scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR;

contrib/seg/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/segparse.h
12
/segparse.c
23
/segscan.c
34
# Generated subdirectories

contrib/seg/Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ MODULE_big = seg
44
OBJS = \
55
$(WIN32RES) \
66
seg.o \
7-
segparse.o
7+
segparse.o \
8+
segscan.o
89

910
EXTENSION = seg
1011
DATA = seg--1.1.sql seg--1.1--1.2.sql seg--1.2--1.3.sql seg--1.3--1.4.sql \
@@ -29,10 +30,16 @@ include $(top_srcdir)/contrib/contrib-global.mk
2930
endif
3031

3132

32-
# segscan is compiled as part of segparse
33-
segparse.o: segscan.c
33+
# See notes in src/backend/parser/Makefile about the following two rules
34+
segparse.h: segparse.c
35+
touch $@
36+
37+
segparse.c: BISONFLAGS += -d
38+
39+
# Force these dependencies to be known even without dependency info built:
40+
segparse.o segscan.o: segparse.h
3441

3542
distprep: segparse.c segscan.c
3643

3744
maintainer-clean:
38-
rm -f segparse.c segscan.c
45+
rm -f segparse.h segparse.c segscan.c

contrib/seg/segparse.y

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,3 @@ seg_atof(const char *value)
160160
datum = DirectFunctionCall1(float4in, CStringGetDatum(value));
161161
return DatumGetFloat4(datum);
162162
}
163-
164-
165-
#include "segscan.c"

contrib/seg/segscan.l

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
%{
1+
%top{
22
/*
33
* A scanner for EMP-style numeric ranges
44
*/
5+
#include "postgres.h"
6+
7+
/*
8+
* NB: include segparse.h only AFTER including segdata.h, because segdata.h
9+
* contains the definition for SEG.
10+
*/
11+
#include "segdata.h"
12+
#include "segparse.h"
13+
}
514

15+
%{
616
/* LCOV_EXCL_START */
717

818
/* No reason to constrain amount of data slurped */
@@ -21,7 +31,6 @@ fprintf_to_ereport(const char *fmt, const char *msg)
2131
/* Handles to the buffer that the lexer uses internally */
2232
static YY_BUFFER_STATE scanbufhandle;
2333
static char *scanbuf;
24-
static int scanbuflen;
2534
%}
2635

2736
%option 8bit
@@ -42,12 +51,12 @@ float ({integer}|{real})([eE]{integer})?
4251

4352
%%
4453

45-
{range} yylval.text = yytext; return RANGE;
46-
{plumin} yylval.text = yytext; return PLUMIN;
47-
{float} yylval.text = yytext; return SEGFLOAT;
48-
\< yylval.text = "<"; return EXTENSION;
49-
\> yylval.text = ">"; return EXTENSION;
50-
\~ yylval.text = "~"; return EXTENSION;
54+
{range} seg_yylval.text = yytext; return RANGE;
55+
{plumin} seg_yylval.text = yytext; return PLUMIN;
56+
{float} seg_yylval.text = yytext; return SEGFLOAT;
57+
\< seg_yylval.text = "<"; return EXTENSION;
58+
\> seg_yylval.text = ">"; return EXTENSION;
59+
\~ seg_yylval.text = "~"; return EXTENSION;
5160
[ \t\n\r\f]+ /* discard spaces */
5261
. return yytext[0]; /* alert parser of the garbage */
5362

@@ -56,7 +65,7 @@ float ({integer}|{real})([eE]{integer})?
5665
/* LCOV_EXCL_STOP */
5766

5867
void
59-
yyerror(SEG *result, const char *message)
68+
seg_yyerror(SEG *result, const char *message)
6069
{
6170
if (*yytext == YY_END_OF_BUFFER_CHAR)
6271
{
@@ -94,7 +103,6 @@ seg_scanner_init(const char *str)
94103
/*
95104
* Make a scan buffer with special termination needed by flex.
96105
*/
97-
scanbuflen = slen;
98106
scanbuf = palloc(slen + 2);
99107
memcpy(scanbuf, str, slen);
100108
scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy