Skip to content

Commit e102aa1

Browse files
committed
Bug#29348962: WARNING: POSIX YACC DOES NOT SUPPORT %YACC [-WYACC]
The modern Bison parser generator has started to output warnings on the usage of some Bison extensions while the %yacc directive (or the --yacc command line option) is enabled. The current patch has neutralized that issue by disabling the warning with --warnings=no-yacc. Note: --yacc is still enabled, since this is necessary for the generation of non-conflicting header files. With --yacc, generated header files contain `#define` directives for each token, while without --yacc there is the `enum yytokentype` declaration, and two generated header files can conflict, since both contain yytokentype. In modern Bison releases, the name of yytokentype can be altered with the `%define api.prefix {...}` directive, however releases prior to 2.6 don't support that feature. Other changes: * %yacc directives have beed removed from *.yy files to not duplicate the command line option --yacc (there was a Bison warning). * All warnings have been enabled with --warning=all where applicable. Change-Id: Ibee86ae996906dce25f30c755c5f9dfe3ea5bf00
1 parent 2a4017e commit e102aa1

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

cmake/bison.cmake

+33-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,
@@ -27,17 +27,37 @@ IF(NOT BISON_EXECUTABLE)
2727
MESSAGE(WARNING "Bison executable not found in PATH")
2828
ELSEIF(BISON_EXECUTABLE AND NOT BISON_USABLE)
2929
# Check version as well
30-
EXEC_PROGRAM(${BISON_EXECUTABLE} ARGS --version OUTPUT_VARIABLE BISON_VERSION_STR)
31-
# Get first line in case it's multiline
32-
STRING(REGEX REPLACE "([^\n]+).*" "\\1" FIRST_LINE "${BISON_VERSION_STR}")
33-
# get version information
34-
STRING(REGEX REPLACE ".* ([0-9]+)\\.([0-9]+)" "\\1" BISON_VERSION_MAJOR "${FIRST_LINE}")
35-
STRING(REGEX REPLACE ".* ([0-9]+)\\.([0-9]+)" "\\2" BISON_VERSION_MINOR "${FIRST_LINE}")
36-
IF (BISON_VERSION_MAJOR LESS 2)
37-
MESSAGE(WARNING "Bison version is old. please update to version 2")
38-
ELSE()
39-
SET(BISON_USABLE 1 CACHE INTERNAL "Bison version 2 or higher")
40-
ENDIF()
30+
EXEC_PROGRAM(${BISON_EXECUTABLE} ARGS --version OUTPUT_VARIABLE BISON_OUTPUT)
31+
# get version information
32+
STRING(REGEX REPLACE
33+
"^bison \\(GNU Bison\\) ([0-9]+\\.[0-9]+(\\.[0-9]+)?).*" "\\1"
34+
BISON_VERSION "${BISON_OUTPUT}")
35+
MESSAGE(STATUS
36+
"Found Bison: ${BISON_EXECUTABLE} (found version is ${BISON_VERSION})")
37+
IF (BISON_VERSION VERSION_LESS "2.1")
38+
MESSAGE(WARNING "Bison version ${BISON_VERSION} is old. \
39+
Please update to version 2.1 or higher")
40+
ELSE()
41+
SET(BISON_USABLE 1 CACHE INTERNAL "Bison version 2 or higher")
42+
IF(BISON_VERSION VERSION_LESS "2.4")
43+
# Don't use --warnings since unsupported
44+
SET(BISON_FLAGS_WARNINGS "" CACHE INTERNAL "BISON 2.x flags")
45+
ELSEIF(BISON_VERSION VERSION_LESS "3.0")
46+
# Enable all warnings
47+
SET(BISON_FLAGS_WARNINGS
48+
"--warnings=all"
49+
CACHE INTERNAL "BISON 2.x flags")
50+
ELSE()
51+
# TODO: replace with "--warnings=all"
52+
# For the backward compatibility with 2.x, suppress warnings:
53+
# * no-yacc: for --yacc
54+
# * no-empty-rule: for empty rules without %empty
55+
# * no-precedence: for useless precedence or/and associativity rules
56+
SET(BISON_FLAGS_WARNINGS
57+
"--warnings=all,no-yacc,no-empty-rule,no-precedence"
58+
CACHE INTERNAL "BISON 3.x flags")
59+
ENDIF()
60+
ENDIF()
4161
ENDIF()
4262

4363

@@ -61,6 +81,7 @@ MACRO (RUN_BISON input_yy output_cc output_h name_prefix)
6181
COMMAND ${BISON_EXECUTABLE}
6282
--name-prefix=${name_prefix}
6383
--yacc
84+
${BISON_FLAGS_WARNINGS}
6485
--output=${output_cc}
6586
--defines=${output_h}
6687
${input_yy}

sql/sql_hints.yy

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ static bool parse_int(longlong *to, const char *from, size_t from_length)
4747
%}
4848

4949
%pure-parser
50-
%yacc
5150

5251
%parse-param { class THD *thd }
5352
%parse-param { class Hint_scanner *scanner }

sql/sql_yacc.yy

-2
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,6 @@ void warn_about_deprecated_national(THD *thd)
433433

434434
%}
435435

436-
%yacc
437-
438436
%start start_entry
439437

440438
%parse-param { class THD *YYTHD }

0 commit comments

Comments
 (0)