From 4d16b395978e8bc830e91d363cf9cadda0c00365 Mon Sep 17 00:00:00 2001 From: John Naylor Date: Sat, 13 Aug 2022 12:35:55 +0700 Subject: [PATCH v201 8/9] Build jsonpath_scan.c standalone XXX: warnings about missing jsonpath_yylex --- src/backend/utils/adt/.gitignore | 1 + src/backend/utils/adt/Makefile | 11 +++++++++-- src/backend/utils/adt/jsonpath_gram.y | 23 ----------------------- src/backend/utils/adt/jsonpath_scan.l | 25 +++++++++++++++---------- src/include/utils/jsonpath.h | 13 +++++++++++++ 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/backend/utils/adt/.gitignore b/src/backend/utils/adt/.gitignore index 48cf941a52..7fab054407 100644 --- a/src/backend/utils/adt/.gitignore +++ b/src/backend/utils/adt/.gitignore @@ -1,2 +1,3 @@ +/jsonpath_gram.h /jsonpath_gram.c /jsonpath_scan.c diff --git a/src/backend/utils/adt/Makefile b/src/backend/utils/adt/Makefile index 7c722ea2ce..d03f897478 100644 --- a/src/backend/utils/adt/Makefile +++ b/src/backend/utils/adt/Makefile @@ -57,6 +57,7 @@ OBJS = \ jsonpath.o \ jsonpath_exec.o \ jsonpath_gram.o \ + jsonpath_scan.o \ like.o \ like_support.o \ lockfuncs.o \ @@ -119,11 +120,17 @@ OBJS = \ xid8funcs.o \ xml.o +# See notes in src/backend/parser/Makefile about the following two rules +jsonpath_gram.h: jsonpath_gram.c + touch $@ + +jsonpath_gram.c: BISONFLAGS += -d + jsonpath_scan.c: FLEXFLAGS = -CF -p -p jsonpath_scan.c: FLEX_NO_BACKUP=yes -# jsonpath_scan is compiled as part of jsonpath_gram -jsonpath_gram.o: jsonpath_scan.c +# Force these dependencies to be known even without dependency info built: +jsonpath_gram.o jsonpath_gram.o jsonpath_parser.o: jsonpath_gram.h # jsonpath_gram.c and jsonpath_scan.c are in the distribution tarball, # so they are not cleaned here. diff --git a/src/backend/utils/adt/jsonpath_gram.y b/src/backend/utils/adt/jsonpath_gram.y index f903dba3e3..a7557d325e 100644 --- a/src/backend/utils/adt/jsonpath_gram.y +++ b/src/backend/utils/adt/jsonpath_gram.y @@ -24,21 +24,8 @@ #include "utils/builtins.h" #include "utils/jsonpath.h" -/* struct JsonPathString is shared between scan and gram */ -typedef struct JsonPathString -{ - char *val; - int len; - int total; -} JsonPathString; - union YYSTYPE; -/* flex 2.5.4 doesn't bother with a decl for this */ -int jsonpath_yylex(union YYSTYPE *yylval_param); -int jsonpath_yyparse(JsonPathParseResult **result); -void jsonpath_yyerror(JsonPathParseResult **result, const char *message); - static JsonPathParseItem *makeItemType(JsonPathItemType type); static JsonPathParseItem *makeItemString(JsonPathString *s); static JsonPathParseItem *makeItemVariable(JsonPathString *s); @@ -593,13 +580,3 @@ jspConvertRegexFlags(uint32 xflags) return cflags; } - -/* - * jsonpath_scan.l is compiled as part of jsonpath_gram.y. Currently, this is - * unavoidable because jsonpath_gram does not create a .h file to export its - * token symbols. If these files ever grow large enough to be worth compiling - * separately, that could be fixed; but for now it seems like useless - * complication. - */ - -#include "jsonpath_scan.c" diff --git a/src/backend/utils/adt/jsonpath_scan.l b/src/backend/utils/adt/jsonpath_scan.l index 4351f6ec98..edd9d1c706 100644 --- a/src/backend/utils/adt/jsonpath_scan.l +++ b/src/backend/utils/adt/jsonpath_scan.l @@ -1,4 +1,4 @@ -%{ +%top{ /*------------------------------------------------------------------------- * * jsonpath_scan.l @@ -17,9 +17,14 @@ #include "postgres.h" +#include "utils/jsonpath.h" #include "mb/pg_wchar.h" #include "nodes/pg_list.h" +#include "jsonpath_gram.h" +} + +%{ static JsonPathString scanstring; /* Handles to the buffer that the lexer uses internally */ @@ -142,9 +147,9 @@ hex_fail \\x{hex_dig}{0,1} {hex_char} { parseHexChar(yytext); } -{unicode}*{unicodefail} { yyerror(NULL, "invalid unicode sequence"); } +{unicode}*{unicodefail} { jsonpath_yyerror(NULL, "invalid unicode sequence"); } -{hex_fail} { yyerror(NULL, "invalid hex character sequence"); } +{hex_fail} { jsonpath_yyerror(NULL, "invalid hex character sequence"); } {unicode}+\\ { /* throw back the \\, and treat as unicode */ @@ -154,9 +159,9 @@ hex_fail \\x{hex_dig}{0,1} \\. { addchar(false, yytext[1]); } -\\ { yyerror(NULL, "unexpected end after backslash"); } +\\ { jsonpath_yyerror(NULL, "unexpected end after backslash"); } -<> { yyerror(NULL, "unexpected end of quoted string"); } +<> { jsonpath_yyerror(NULL, "unexpected end of quoted string"); } \" { yylval->str = scanstring; @@ -178,7 +183,7 @@ hex_fail \\x{hex_dig}{0,1} \* { } -<> { yyerror(NULL, "unexpected end of comment"); } +<> { jsonpath_yyerror(NULL, "unexpected end of comment"); } \&\& { return AND_P; } @@ -244,10 +249,10 @@ hex_fail \\x{hex_dig}{0,1} return INT_P; } -{realfail} { yyerror(NULL, "invalid numeric literal"); } -{integer_junk} { yyerror(NULL, "trailing junk after numeric literal"); } -{decimal_junk} { yyerror(NULL, "trailing junk after numeric literal"); } -{real_junk} { yyerror(NULL, "trailing junk after numeric literal"); } +{realfail} { jsonpath_yyerror(NULL, "invalid numeric literal"); } +{integer_junk} { jsonpath_yyerror(NULL, "trailing junk after numeric literal"); } +{decimal_junk} { jsonpath_yyerror(NULL, "trailing junk after numeric literal"); } +{real_junk} { jsonpath_yyerror(NULL, "trailing junk after numeric literal"); } \" { addchar(true, '\0'); diff --git a/src/include/utils/jsonpath.h b/src/include/utils/jsonpath.h index 8e79b8dc9f..b9b56209b2 100644 --- a/src/include/utils/jsonpath.h +++ b/src/include/utils/jsonpath.h @@ -21,6 +21,14 @@ #include "utils/jsonb.h" #include "utils/jsonfuncs.h" +/* struct JsonPathString is shared between scan and gram */ +typedef struct JsonPathString +{ + char *val; + int len; + int total; +} JsonPathString; + typedef struct { int32 vl_len_; /* varlena header (do not touch directly!) */ @@ -250,6 +258,11 @@ typedef struct JsonPathParseResult extern JsonPathParseResult *parsejsonpath(const char *str, int len); +/* flex 2.5.4 doesn't bother with a decl for this */ +//int jsonpath_yylex(union YYSTYPE *yylval_param); +//int jsonpath_yyparse(JsonPathParseResult **result); +void jsonpath_yyerror(JsonPathParseResult **result, const char *message); + extern int jspConvertRegexFlags(uint32 xflags); /* -- 2.36.1