%.c: %.l
$(FLEX) $(if $(FLEX_NO_BACKUP),-b) $(FLEXFLAGS) -o'$@' $<
@$(if $(FLEX_NO_BACKUP),if [ `wc -l <lex.backup` -eq 1 ]; then rm lex.backup; else echo "Scanner requires backup; see lex.backup." 1>&2; exit 1; fi)
- $(if $(FLEX_FIX_WARNING),$(PERL) $(top_srcdir)/src/tools/fix-old-flex-code.pl '$@')
%.c: %.y
$(if $(BISON_CHECK_CMD),$(BISON_CHECK_CMD))
scan.c: FLEXFLAGS = -CF -p -p
scan.c: FLEX_NO_BACKUP=yes
-scan.c: FLEX_FIX_WARNING=yes
# Force these dependencies to be known even without dependency info built:
backend_scanner = custom_target('scan',
input: 'scan.l',
output: 'scan.c',
- command: [flex_cmd, '--no-backup', '--fix-warnings', '--', '-CF', '-p', '-p'],
+ command: [flex_cmd, '--no-backup', '--', '-CF', '-p', '-p'],
)
generated_sources += backend_scanner
parser_sources += backend_scanner
static void check_string_escape_warning(unsigned char ychar, core_yyscan_t yyscanner);
static void check_escape_warning(core_yyscan_t yyscanner);
-/*
- * Work around a bug in flex 2.5.35: it emits a couple of functions that
- * it forgets to emit declarations for. Since we use -Wmissing-s,
- * this would cause warnings. Providing our own declarations should be
- * harmless even when the bug gets fixed.
- */
-extern int core_yyget_column(yyscan_t yyscanner);
-extern void core_yyset_column(int column_no, yyscan_t yyscanner);
-
%}
%option reentrant
/* indicates whether last yylex() call read a newline */
static bool last_was_newline = false;
-/*
- * Work around a bug in flex 2.5.35: it emits a couple of functions that
- * it forgets to emit declarations for. Since we use -Wmissing-s,
- * this would cause warnings. Providing our own declarations should be
- * harmless even when the bug gets fixed.
- */
-extern int expr_yyget_column(yyscan_t yyscanner);
-extern void expr_yyset_column(int column_no, yyscan_t yyscanner);
-
/* LCOV_EXCL_START */
%}
psqlscanslash.c: FLEXFLAGS = -Cfe -p -p
psqlscanslash.c: FLEX_NO_BACKUP=yes
-psqlscanslash.c: FLEX_FIX_WARNING=yes
tab-complete.c: gen_tabcomplete.pl tab-complete.in.c
$(PERL) $^ --outfile $@
psqlscanslash = custom_target('psqlscanslash',
input: 'psqlscanslash.l',
output: 'psqlscanslash.c',
- command: [flex_cmd, '--no-backup', '--fix-warnings', '--', '-Cfe', '-p', '-p'])
+ command: [flex_cmd, '--no-backup', '--', '-Cfe', '-p', '-p'])
generated_sources += psqlscanslash
psql_sources += psqlscanslash
#define ECHO psqlscan_emit(cur_state, yytext, yyleng)
-/*
- * Work around a bug in flex 2.5.35: it emits a couple of functions that
- * it forgets to emit declarations for. Since we use -Wmissing-s,
- * this would cause warnings. Providing our own declarations should be
- * harmless even when the bug gets fixed.
- */
-extern int slash_yyget_column(yyscan_t yyscanner);
-extern void slash_yyset_column(int column_no, yyscan_t yyscanner);
-
/* LCOV_EXCL_START */
%}
psqlscan.c: FLEXFLAGS = -Cfe -p -p
psqlscan.c: FLEX_NO_BACKUP=yes
-psqlscan.c: FLEX_FIX_WARNING=yes
# libpgfeutils could be useful to contrib, so install it
install: all installdirs
psqlscan = custom_target('psqlscan',
input: 'psqlscan.l',
output: 'psqlscan.c',
- command: [flex_cmd, '--no-backup', '--fix-warnings', '--', '-Cfe', '-p', '-p'],
+ command: [flex_cmd, '--no-backup', '--', '-Cfe', '-p', '-p'],
)
generated_sources += psqlscan
fe_utils_sources += psqlscan
#define ECHO psqlscan_emit(cur_state, yytext, yyleng)
-/*
- * Work around a bug in flex 2.5.35: it emits a couple of functions that
- * it forgets to emit declarations for. Since we use -Wmissing-s,
- * this would cause warnings. Providing our own declarations should be
- * harmless even when the bug gets fixed.
- */
-extern int psql_yyget_column(yyscan_t yyscanner);
-extern void psql_yyset_column(int column_no, yyscan_t yyscanner);
-
%}
%option reentrant
+++ /dev/null
-#!/usr/bin/perl
-#----------------------------------------------------------------------
-#
-# fix-old-flex-code.pl
-#
-# flex versions before 2.5.36, with certain option combinations, produce
-# code that causes an "unused variable" warning. That's annoying, so
-# let's suppress it by inserting a dummy reference to the variable.
-# (That's exactly what 2.5.36 and later do ...)
-#
-# Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
-# Portions Copyright (c) 1994, Regents of the University of California
-#
-# src/tools/fix-old-flex-code.pl
-#
-#----------------------------------------------------------------------
-
-use strict;
-use warnings FATAL => 'all';
-
-# Get command line argument.
-usage() if $#ARGV != 0;
-my $filename = shift;
-
-# Suck in the whole file.
-local $/ = undef;
-my $cfile;
-open($cfile, '<', $filename) || die "opening $filename for reading: $!";
-my $ccode = <$cfile>;
-close($cfile);
-
-# No need to do anything if it's not flex 2.5.x for x < 36.
-exit 0 if $ccode !~ m/^#define YY_FLEX_MAJOR_VERSION 2$/m;
-exit 0 if $ccode !~ m/^#define YY_FLEX_MINOR_VERSION 5$/m;
-exit 0 if $ccode !~ m/^#define YY_FLEX_SUBMINOR_VERSION (\d+)$/m;
-exit 0 if $1 >= 36;
-
-# Apply the desired .
-$ccode =~
- s|(struct yyguts_t \* yyg = \(struct yyguts_t\*\)yyscanner; /\* This var may be unused depending upon options. \*/
-.*?)
- return yy_is_jam \? 0 : yy_current_state;
-|$1
- (void) yyg;
- return yy_is_jam ? 0 : yy_current_state;
-|s;
-
-# Write the modified file back out.
-open($cfile, '>', $filename) || die "opening $filename for writing: $!";
-print $cfile $ccode;
-close($cfile);
-
-exit 0;
-
-
-sub usage
-{
- die <<EOM;
-Usage: fix-old-flex-code.pl c-file-name
-
-fix-old-flex-code.pl modifies a flex output file to suppress
-an unused-variable warning that occurs with older flex versions.
-
-Report bugs to <pgsql-bugs\@lists.postgresql.org>.
-EOM
-}
# Wrapper around flex that:
# - ensures lex.backup is created in a private directory
# - can error out if lex.backup is created (--no-backup)
-# - can fix warnings (--fix-warnings)
# - works around concurrency issues with win_flex.exe:
# https://.com/lexxmark/winflexbison/issues/86
parser.add_argument('-i', dest='input_file', type=abspath, help='input file')
-parser.add_argument('--fix-warnings', action='store_true',
- help='whether to fix warnings in generated file')
parser.add_argument('--no-backup', action='store_true',
help='whether no_backup is enabled or not')
sys.exit('Scanner requires backup; see lex.backup.')
os.remove('lex.backup')
-# fix warnings
-if args.fix_warnings:
- fix_warning_script = os.path.join(args.srcdir,
- 'src/tools/fix-old-flex-code.pl')
-
- command = [args.perl, fix_warning_script, args.output_file]
- sp = subprocess.run(command)
- if sp.returncode != 0:
- sys.exit(sp.returncode)
-
sys.exit(0)