diff options
author | John Naylor | 2022-09-04 04:33:31 +0000 |
---|---|---|
committer | John Naylor | 2022-09-04 05:09:01 +0000 |
commit | dac048f71ebbcf2f980d280711f8ff8001331c5d (patch) | |
tree | 48311f22d4636b6fb12cf2bb43925622521e758a /contrib | |
parent | 80e8450a744b1f6fa75663f37f1db3388995dc67 (diff) |
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 72b1e3a21, 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
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/cube/.gitignore | 1 | ||||
-rw-r--r-- | contrib/cube/Makefile | 16 | ||||
-rw-r--r-- | contrib/cube/cube.c | 6 | ||||
-rw-r--r-- | contrib/cube/cubedata.h | 6 | ||||
-rw-r--r-- | contrib/cube/cubeparse.y | 6 | ||||
-rw-r--r-- | contrib/cube/cubescan.l | 44 | ||||
-rw-r--r-- | contrib/seg/.gitignore | 1 | ||||
-rw-r--r-- | contrib/seg/Makefile | 15 | ||||
-rw-r--r-- | contrib/seg/segparse.y | 3 | ||||
-rw-r--r-- | contrib/seg/segscan.l | 28 |
10 files changed, 75 insertions, 51 deletions
diff --git a/contrib/cube/.gitignore b/contrib/cube/.gitignore index cb4c989fff1..f788440c796 100644 --- a/contrib/cube/.gitignore +++ b/contrib/cube/.gitignore @@ -1,3 +1,4 @@ +/cubeparse.h /cubeparse.c /cubescan.c # Generated subdirectories diff --git a/contrib/cube/Makefile b/contrib/cube/Makefile index cf195506c71..4fd19aac359 100644 --- a/contrib/cube/Makefile +++ b/contrib/cube/Makefile @@ -4,7 +4,8 @@ MODULE_big = cube OBJS = \ $(WIN32RES) \ cube.o \ - cubeparse.o + cubeparse.o \ + cubescan.o EXTENSION = cube 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 REGRESS = cube cube_sci -EXTRA_CLEAN = y.tab.c y.tab.h - SHLIB_LINK += $(filter -lm, $(LIBS)) ifdef USE_PGXS @@ -30,11 +29,16 @@ include $(top_builddir)/src/Makefile.global include $(top_srcdir)/contrib/contrib-global.mk endif +# See notes in src/backend/parser/Makefile about the following two rules +cubeparse.h: cubeparse.c + touch $@ + +cubeparse.c: BISONFLAGS += -d -# cubescan is compiled as part of cubeparse -cubeparse.o: cubescan.c +# Force these dependencies to be known even without dependency info built: +cubeparse.o cubescan.o: cubeparse.h distprep: cubeparse.c cubescan.c maintainer-clean: - rm -f cubeparse.c cubescan.c + rm -f cubeparse.h cubeparse.c cubescan.c diff --git a/contrib/cube/cube.c b/contrib/cube/cube.c index a5d1ba67335..6e01800a4a8 100644 --- a/contrib/cube/cube.c +++ b/contrib/cube/cube.c @@ -119,11 +119,11 @@ cube_in(PG_FUNCTION_ARGS) { char *str = PG_GETARG_CSTRING(0); NDBOX *result; + Size scanbuflen; - cube_scanner_init(str); + cube_scanner_init(str, &scanbuflen); - if (cube_yyparse(&result) != 0) - cube_yyerror(&result, "cube parser failed"); + cube_yyparse(&result, scanbuflen); cube_scanner_finish(); diff --git a/contrib/cube/cubedata.h b/contrib/cube/cubedata.h index dbe7d4f7429..640a7ca5800 100644 --- a/contrib/cube/cubedata.h +++ b/contrib/cube/cubedata.h @@ -61,9 +61,9 @@ typedef struct NDBOX /* in cubescan.l */ extern int cube_yylex(void); -extern void cube_yyerror(NDBOX **result, const char *message) pg_attribute_noreturn(); -extern void cube_scanner_init(const char *str); +extern void cube_yyerror(NDBOX **result, Size scanbuflen, const char *message) pg_attribute_noreturn(); +extern void cube_scanner_init(const char *str, Size *scanbuflen); extern void cube_scanner_finish(void); /* in cubeparse.y */ -extern int cube_yyparse(NDBOX **result); +extern int cube_yyparse(NDBOX **result, Size scanbuflen); diff --git a/contrib/cube/cubeparse.y b/contrib/cube/cubeparse.y index 7577c4515c6..6cceae8e996 100644 --- a/contrib/cube/cubeparse.y +++ b/contrib/cube/cubeparse.y @@ -23,9 +23,6 @@ #define YYMALLOC palloc #define YYFREE pfree -static char *scanbuf; -static int scanbuflen; - static int item_count(const char *s, char delim); static NDBOX *write_box(int dim, char *str1, char *str2); static NDBOX *write_point_as_box(int dim, char *str); @@ -34,6 +31,7 @@ static NDBOX *write_point_as_box(int dim, char *str); /* BISON Declarations */ %parse-param {NDBOX **result} +%parse-param {Size scanbuflen} %expect 0 %name-prefix="cube_yy" @@ -265,5 +263,3 @@ write_point_as_box(int dim, char *str) return bp; } - -#include "cubescan.c" diff --git a/contrib/cube/cubescan.l b/contrib/cube/cubescan.l index bd400e36842..6b316f2d545 100644 --- a/contrib/cube/cubescan.l +++ b/contrib/cube/cubescan.l @@ -1,9 +1,21 @@ -%{ +%top{ /* * A scanner for EMP-style numeric ranges * contrib/cube/cubescan.l */ +#include "postgres.h" + +/* + * NB: include cubeparse.h only AFTER defining YYSTYPE (to match cubeparse.y) + * and cubedata.h for NDBOX. + */ +#include "cubedata.h" +#define YYSTYPE char * +#include "cubeparse.h" +} + +%{ /* LCOV_EXCL_START */ /* No reason to constrain amount of data slurped */ @@ -21,9 +33,7 @@ fprintf_to_ereport(const char *fmt, const char *msg) /* Handles to the buffer that the lexer uses internally */ static YY_BUFFER_STATE scanbufhandle; -/* this is now declared in cubeparse.y: */ -/* static char *scanbuf; */ -/* static int scanbuflen; */ +static char *scanbuf; %} %option 8bit @@ -45,14 +55,14 @@ NaN [nN][aA][nN] %% -{float} yylval = yytext; return CUBEFLOAT; -{infinity} yylval = yytext; return CUBEFLOAT; -{NaN} yylval = yytext; return CUBEFLOAT; -\[ yylval = "("; return O_BRACKET; -\] yylval = ")"; return C_BRACKET; -\( yylval = "("; return O_PAREN; -\) yylval = ")"; return C_PAREN; -\, yylval = ","; return COMMA; +{float} cube_yylval = yytext; return CUBEFLOAT; +{infinity} cube_yylval = yytext; return CUBEFLOAT; +{NaN} cube_yylval = yytext; return CUBEFLOAT; +\[ cube_yylval = "("; return O_BRACKET; +\] cube_yylval = ")"; return C_BRACKET; +\( cube_yylval = "("; return O_PAREN; +\) cube_yylval = ")"; return C_PAREN; +\, cube_yylval = ","; return COMMA; [ \t\n\r\f]+ /* discard spaces */ . return yytext[0]; /* alert parser of the garbage */ @@ -60,9 +70,9 @@ NaN [nN][aA][nN] /* LCOV_EXCL_STOP */ -/* result is not used, but Bison expects this signature */ +/* result and scanbuflen are not used, but Bison expects this signature */ void -yyerror(NDBOX **result, const char *message) +cube_yyerror(NDBOX **result, Size scanbuflen, const char *message) { if (*yytext == YY_END_OF_BUFFER_CHAR) { @@ -87,9 +97,9 @@ yyerror(NDBOX **result, const char *message) * Called before any actual parsing is done */ void -cube_scanner_init(const char *str) +cube_scanner_init(const char *str, Size *scanbuflen) { - Size slen = strlen(str); + Size slen = strlen(str); /* * Might be left over after ereport() @@ -100,7 +110,7 @@ cube_scanner_init(const char *str) /* * Make a scan buffer with special termination needed by flex. */ - scanbuflen = slen; + *scanbuflen = slen; scanbuf = palloc(slen + 2); memcpy(scanbuf, str, slen); scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR; diff --git a/contrib/seg/.gitignore b/contrib/seg/.gitignore index 69e73d20966..fa247a4e67b 100644 --- a/contrib/seg/.gitignore +++ b/contrib/seg/.gitignore @@ -1,3 +1,4 @@ +/segparse.h /segparse.c /segscan.c # Generated subdirectories diff --git a/contrib/seg/Makefile b/contrib/seg/Makefile index bb63e835067..c6c134b8f15 100644 --- a/contrib/seg/Makefile +++ b/contrib/seg/Makefile @@ -4,7 +4,8 @@ MODULE_big = seg OBJS = \ $(WIN32RES) \ seg.o \ - segparse.o + segparse.o \ + segscan.o EXTENSION = seg 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 endif -# segscan is compiled as part of segparse -segparse.o: segscan.c +# See notes in src/backend/parser/Makefile about the following two rules +segparse.h: segparse.c + touch $@ + +segparse.c: BISONFLAGS += -d + +# Force these dependencies to be known even without dependency info built: +segparse.o segscan.o: segparse.h distprep: segparse.c segscan.c maintainer-clean: - rm -f segparse.c segscan.c + rm -f segparse.h segparse.c segscan.c diff --git a/contrib/seg/segparse.y b/contrib/seg/segparse.y index 33e3a9f35f2..637eacd1a65 100644 --- a/contrib/seg/segparse.y +++ b/contrib/seg/segparse.y @@ -160,6 +160,3 @@ seg_atof(const char *value) datum = DirectFunctionCall1(float4in, CStringGetDatum(value)); return DatumGetFloat4(datum); } - - -#include "segscan.c" diff --git a/contrib/seg/segscan.l b/contrib/seg/segscan.l index 5f6595e9eb2..4744fd5e9e8 100644 --- a/contrib/seg/segscan.l +++ b/contrib/seg/segscan.l @@ -1,8 +1,18 @@ -%{ +%top{ /* * A scanner for EMP-style numeric ranges */ +#include "postgres.h" + +/* + * NB: include segparse.h only AFTER including segdata.h, because segdata.h + * contains the definition for SEG. + */ +#include "segdata.h" +#include "segparse.h" +} +%{ /* LCOV_EXCL_START */ /* No reason to constrain amount of data slurped */ @@ -21,7 +31,6 @@ fprintf_to_ereport(const char *fmt, const char *msg) /* Handles to the buffer that the lexer uses internally */ static YY_BUFFER_STATE scanbufhandle; static char *scanbuf; -static int scanbuflen; %} %option 8bit @@ -42,12 +51,12 @@ float ({integer}|{real})([eE]{integer})? %% -{range} yylval.text = yytext; return RANGE; -{plumin} yylval.text = yytext; return PLUMIN; -{float} yylval.text = yytext; return SEGFLOAT; -\< yylval.text = "<"; return EXTENSION; -\> yylval.text = ">"; return EXTENSION; -\~ yylval.text = "~"; return EXTENSION; +{range} seg_yylval.text = yytext; return RANGE; +{plumin} seg_yylval.text = yytext; return PLUMIN; +{float} seg_yylval.text = yytext; return SEGFLOAT; +\< seg_yylval.text = "<"; return EXTENSION; +\> seg_yylval.text = ">"; return EXTENSION; +\~ seg_yylval.text = "~"; return EXTENSION; [ \t\n\r\f]+ /* discard spaces */ . return yytext[0]; /* alert parser of the garbage */ @@ -56,7 +65,7 @@ float ({integer}|{real})([eE]{integer})? /* LCOV_EXCL_STOP */ void -yyerror(SEG *result, const char *message) +seg_yyerror(SEG *result, const char *message) { if (*yytext == YY_END_OF_BUFFER_CHAR) { @@ -94,7 +103,6 @@ seg_scanner_init(const char *str) /* * Make a scan buffer with special termination needed by flex. */ - scanbuflen = slen; scanbuf = palloc(slen + 2); memcpy(scanbuf, str, slen); scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR; |