2020-12-23 21:41:14 +01:00
|
|
|
#!/usr/bin/env python3
|
2025-11-01 19:14:56 +01:00
|
|
|
# mypy: disallow-untyped-defs
|
2021-03-06 04:52:39 +01:00
|
|
|
# pylint: disable=C0114,C0301
|
2006-08-26 13:35:28 +02:00
|
|
|
######################################################################
|
|
|
|
|
#
|
2025-01-01 14:30:25 +01:00
|
|
|
# Copyright 2002-2025 by Wilson Snyder. This program is free software; you
|
2009-05-04 23:07:57 +02:00
|
|
|
# can redistribute it and/or modify it under the terms of either the GNU
|
|
|
|
|
# Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
# Version 2.0.
|
2020-03-21 16:24:24 +01:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2008-06-10 03:25:10 +02:00
|
|
|
#
|
2006-08-26 13:35:28 +02:00
|
|
|
######################################################################
|
2007-05-12 17:31:04 +02:00
|
|
|
# DESCRIPTION: Edits flex output to get around various broken flex issues.
|
2006-08-26 13:35:28 +02:00
|
|
|
|
2020-12-23 21:41:14 +01:00
|
|
|
import re
|
|
|
|
|
import sys
|
2020-01-10 02:01:12 +01:00
|
|
|
|
2020-12-23 21:41:14 +01:00
|
|
|
for line in sys.stdin:
|
2018-02-08 00:58:21 +01:00
|
|
|
# Fix flex 2.6.1 warning
|
2024-08-27 03:43:34 +02:00
|
|
|
line = re.sub(r'for \( i = 0; i < _yybytes_len; \+\+i \)',
|
|
|
|
|
r'for ( i = 0; (yy_size_t)(i) < (yy_size_t)(_yybytes_len); ++i )', line)
|
2025-07-03 04:56:10 +02:00
|
|
|
# Fix flex 2.6.0+ sign comparison warnings
|
2020-12-23 21:41:14 +01:00
|
|
|
line = re.sub(
|
|
|
|
|
r'\(\(int\) \(\(yy_n_chars\) \+ number_to_move\) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size\)',
|
|
|
|
|
r'((int) ((yy_n_chars) + number_to_move) > (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size)',
|
|
|
|
|
line)
|
2024-08-27 03:43:34 +02:00
|
|
|
line = re.sub(r' number_to_move == YY_MORE_ADJ ', r' (int)number_to_move == (int)YY_MORE_ADJ ',
|
|
|
|
|
line)
|
2025-07-03 04:56:10 +02:00
|
|
|
line = re.sub(
|
|
|
|
|
r'\(\(\(yy_n_chars\) \+ number_to_move\) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size\)',
|
|
|
|
|
r'(((int)(yy_n_chars) + (int)number_to_move) > (int)YY_CURRENT_BUFFER_LVALUE->yy_buf_size)',
|
|
|
|
|
line)
|
2006-08-26 13:35:28 +02:00
|
|
|
# Fix flex 2.5.4 namespace omission
|
2024-08-27 03:43:34 +02:00
|
|
|
line = re.sub(r'^class istream;', '#include <iostream>\nusing namespace std;\n', line)
|
2006-08-26 13:35:28 +02:00
|
|
|
# Fix flex 2.5.31 redefinition
|
2024-08-27 03:43:34 +02:00
|
|
|
line = re.sub(r'(\#define\s+yyFlexLexer\s+yyFlexLexer)', r'//flexfix: \1', line)
|
2006-08-26 13:35:28 +02:00
|
|
|
# Fix flex 2.5.1 yytext_ptr undef
|
2020-12-23 21:41:14 +01:00
|
|
|
line = re.sub(r'(\#undef\s+yytext_ptr)', r'//flexfix: \1', line)
|
2007-05-12 17:31:04 +02:00
|
|
|
# Fix flex 2.5.4 and GCC 4.1.0 warn_unused_result
|
2020-12-23 21:41:14 +01:00
|
|
|
line = re.sub(r'\(void\) *fwrite\((.*)\)', r'if (fwrite(\1)) {}', line)
|
2007-05-12 17:31:04 +02:00
|
|
|
# Fix flex 2.5.33 and GCC 4.1.2 "warning: comparison between signed and unsigned integer expressions" in YY_INPUT
|
2020-12-23 21:41:14 +01:00
|
|
|
line = re.sub(r'for \( n = 0; n < max_size && ',
|
|
|
|
|
r'for ( n = 0; ((size_t)n < (size_t)max_size) && ', line)
|
2009-10-31 04:17:56 +01:00
|
|
|
# Fix flex 2.5.4 and GCC 4.0.2 under FLEX_DEBUG
|
2024-08-27 03:43:34 +02:00
|
|
|
line = re.sub(r'--accepting rule at line %d ', r'--accepting rule at line %ld ', line)
|
2010-02-27 01:50:44 +01:00
|
|
|
# Fix compiler warning filenames
|
2020-12-23 21:41:14 +01:00
|
|
|
line = re.sub(r'(#line \d+ ".*)_pretmp', r'\1', line)
|
2020-08-18 14:02:50 +02:00
|
|
|
# Fix 'register' storage class specifier is deprecated and incompatible with C++17
|
2020-12-23 21:41:14 +01:00
|
|
|
line = re.sub(r'register ', '', line)
|
2009-10-31 04:17:56 +01:00
|
|
|
|
2020-12-23 21:41:14 +01:00
|
|
|
print(line, end='')
|