Skip to content

Commit b1ef489

Browse files
committed
flex code modernization: Replace YY_EXTRA_TYPE define with flex option
Replace #define YY_EXTRA_TYPE with %option extra-type. The latter is the way recommended by the flex manual (available since flex 2.5.34). Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Discussion: https://www.postgresql.org/message-id/flat/eb6faeac-2a8a-4b69-9189-c33c520e5b7b@eisentraut.org
1 parent 632384d commit b1ef489

File tree

6 files changed

+16
-21
lines changed

6 files changed

+16
-21
lines changed

src/backend/parser/scan.l

+1-6
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ const uint16 ScanKeywordTokens[] = {
8989
*/
9090
#define YYSTYPE core_YYSTYPE
9191

92-
/*
93-
* Set the type of yyextra. All state variables used by the scanner should
94-
* be in yyextra, *not* statically allocated.
95-
*/
96-
#define YY_EXTRA_TYPE core_yy_extra_type *
97-
9892
/*
9993
* Each call to yylex must set yylloc to the location of the found token
10094
* (expressed as a byte offset from the start of the input text).
@@ -161,6 +155,7 @@ extern void core_yyset_column(int column_no, yyscan_t yyscanner);
161155
%option noyyfree
162156
%option warn
163157
%option prefix="core_yy"
158+
%option extra-type="core_yy_extra_type *"
164159

165160
/*
166161
* OK, here is a short description of lex/flex rules behavior.

src/backend/replication/repl_scanner.l

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ struct replication_yy_extra_type
4646
/* Work area for collecting literals */
4747
StringInfoData litbuf;
4848
};
49-
#define YY_EXTRA_TYPE struct replication_yy_extra_type *
5049

5150
static void startlit(yyscan_t yyscanner);
5251
static char *litbufdup(yyscan_t yyscanner);
@@ -70,6 +69,7 @@ static void addlitchar(unsigned char ychar, yyscan_t yyscanner);
7069
%option noyyfree
7170
%option warn
7271
%option prefix="replication_yy"
72+
%option extra-type="struct replication_yy_extra_type *"
7373

7474
/*
7575
* Exclusive states:

src/backend/replication/syncrep_scanner.l

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ struct syncrep_yy_extra_type
4141
{
4242
StringInfoData xdbuf;
4343
};
44-
#define YY_EXTRA_TYPE struct syncrep_yy_extra_type *
4544

4645
/* LCOV_EXCL_START */
4746

@@ -60,6 +59,7 @@ struct syncrep_yy_extra_type
6059
%option noyyfree
6160
%option warn
6261
%option prefix="syncrep_yy"
62+
%option extra-type="struct syncrep_yy_extra_type *"
6363

6464
/*
6565
* <xd> delimited identifiers (double-quoted identifiers)

src/backend/utils/adt/jsonpath_scan.l

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ struct jsonpath_yy_extra_type
3434
{
3535
JsonPathString scanstring;
3636
};
37-
#define YY_EXTRA_TYPE struct jsonpath_yy_extra_type *
3837

3938
static void addstring(bool init, char *s, int l, yyscan_t yyscanner);
4039
static void addchar(bool init, char c, yyscan_t yyscanner);
@@ -64,6 +63,7 @@ fprintf_to_ereport(const char *fmt, const char *msg)
6463
%option noyywrap
6564
%option warn
6665
%option prefix="jsonpath_yy"
66+
%option extra-type="struct jsonpath_yy_extra_type *"
6767
%option reentrant
6868
%option bison-bridge
6969
%option noyyalloc

src/bin/psql/psqlscanslash.l

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@
3838
*/
3939
typedef int YYSTYPE;
4040

41-
/*
42-
* Set the type of yyextra; we use it as a pointer back to the containing
43-
* PsqlScanState.
44-
*/
45-
#define YY_EXTRA_TYPE PsqlScanState
46-
4741
/*
4842
* These variables do not need to be saved across calls. Yeah, it's a bit
4943
* of a hack, but putting them into PsqlScanStateData would be klugy too.
@@ -88,6 +82,12 @@ extern void slash_yyset_column(int column_no, yyscan_t yyscanner);
8882
%option warn
8983
%option prefix="slash_yy"
9084

85+
/*
86+
* Set the type of yyextra; we use it as a pointer back to the containing
87+
* PsqlScanState.
88+
*/
89+
%option extra-type="PsqlScanState"
90+
9191
/*
9292
* OK, here is a short description of lex/flex rules behavior.
9393
* The longest pattern which matches an input string is always chosen.

src/fe_utils/psqlscan.l

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@
5252
*/
5353
typedef int YYSTYPE;
5454

55-
/*
56-
* Set the type of yyextra; we use it as a pointer back to the containing
57-
* PsqlScanState.
58-
*/
59-
#define YY_EXTRA_TYPE PsqlScanState
60-
6155

6256
/* Return values from yylex() */
6357
#define LEXRES_EOL 0 /* end of input */
@@ -89,6 +83,12 @@ extern void psql_yyset_column(int column_no, yyscan_t yyscanner);
8983
%option warn
9084
%option prefix="psql_yy"
9185

86+
/*
87+
* Set the type of yyextra; we use it as a pointer back to the containing
88+
* PsqlScanState.
89+
*/
90+
%option extra-type="PsqlScanState"
91+
9292
/*
9393
* All of the following definitions and rules should exactly match
9494
* src/backend/parser/scan.l so far as the flex patterns are concerned.

0 commit comments

Comments
 (0)