MDEV-25726 get rid of cmake comment hack in sql_yacc.yy

and replace it with equally unsightly %ifdef/%endif hack
also, support %else, it's nice
This commit is contained in:
Sergei Golubchik 2021-05-22 17:47:42 +02:00
parent 288b801696
commit dfbeddaa11
7 changed files with 84 additions and 44 deletions

1
.gitignore vendored
View file

@ -198,6 +198,7 @@ sql/mysqld
sql/sql_builtin.cc
sql/sql_yacc.cc
sql/sql_yacc.hh
sql/sql_yacc_mariadb.yy
sql/sql_yacc_ora.cc
sql/sql_yacc_ora.hh
sql/sql_yacc_ora.yy

View file

@ -66,16 +66,17 @@ ADD_CUSTOM_COMMAND(
)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.yy
COMMAND ${CMAKE_COMMAND}
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_mariadb.yy
${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.yy
COMMAND ${CMAKE_COMMAND} "-DVAL1=ORACLE" "-DVAL2=MARIADB"
"-DOUT1=${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.yy"
"-DOUT2=${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_mariadb.yy"
"-DIN=${CMAKE_CURRENT_SOURCE_DIR}/sql_yacc.yy"
"-DOUT=${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.yy"
-P ${CMAKE_CURRENT_SOURCE_DIR}/gen_sql_yacc_ora_yy.cmake
-P ${CMAKE_CURRENT_SOURCE_DIR}/gen_yy_files.cmake
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/sql_yacc.yy
${CMAKE_CURRENT_SOURCE_DIR}/gen_yy_files.cmake
)
ADD_CUSTOM_TARGET(gen_sql_yacc_ora_yy DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.yy)
ADD_DEFINITIONS(-DMYSQL_SERVER -DHAVE_EVENT_SCHEDULER)
IF(SSL_DEFINES)
@ -350,10 +351,13 @@ IF (NOT BISON_FOUND)
MESSAGE(FATAL_ERROR ${ERRMSG})
ENDIF()
ELSE()
BISON_TARGET(gen_sql_yacc ${CMAKE_CURRENT_SOURCE_DIR}/sql_yacc.yy ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
COMPILE_FLAGS "-p MYSQL")
BISON_TARGET(gen_sql_yacc_ora ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.yy ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.cc
COMPILE_FLAGS "-p ORA")
BISON_TARGET(gen_mariadb_cc_hh ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_mariadb.yy
${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.hh
COMPILE_FLAGS "-p MYSQL -S ${CMAKE_CURRENT_SOURCE_DIR}/myskel.m4")
BISON_TARGET(gen_oracle_cc_hh ${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.yy
${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.cc
COMPILE_FLAGS "-p ORA -S ${CMAKE_CURRENT_SOURCE_DIR}/myskel.m4")
ENDIF()
IF(NOT CMAKE_CROSSCOMPILING OR DEFINED CMAKE_CROSSCOMPILING_EMULATOR)
@ -377,11 +381,10 @@ ADD_CUSTOM_TARGET(
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/lex_hash.h
${CMAKE_CURRENT_BINARY_DIR}/lex_token.h
${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
${CMAKE_CURRENT_BINARY_DIR}/sql_yacc_ora.cc
)
ADD_DEPENDENCIES(GenServerSource gen_sql_yacc_ora_yy)
IF(WIN32 OR HAVE_DLOPEN AND NOT DISABLE_SHARED)
ADD_LIBRARY(udf_example MODULE udf_example.c udf_example.def)
SET_TARGET_PROPERTIES(udf_example PROPERTIES PREFIX "")

View file

@ -1,15 +0,0 @@
file(READ "${IN}" yytmp)
# Comment out sql_mode=DEFAULT rules and directives (e.g. %expect, %type)
string(REPLACE "/* Start SQL_MODE_DEFAULT_SPECIFIC */"
"/* Start SQL_MODE_DEFAULT_SPECIFIC" yytmp "${yytmp}")
string(REPLACE "/* End SQL_MODE_DEFAULT_SPECIFIC */"
"End SQL_MODE_DEFAULT_SPECIFIC */" yytmp "${yytmp}")
# Uncomment sql_mode=ORACLE rules and directives
string(REPLACE "/* Start SQL_MODE_ORACLE_SPECIFIC"
"/* Start SQL_MODE_ORACLE_SPECIFIC */" yytmp "${yytmp}")
string(REPLACE "End SQL_MODE_ORACLE_SPECIFIC */"
"/* End SQL_MODE_ORACLE_SPECIFIC */" yytmp "${yytmp}")
file(WRITE "${OUT}" "${yytmp}")

39
sql/gen_yy_files.cmake Normal file
View file

@ -0,0 +1,39 @@
if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
file(READ "${IN}" data)
file(WRITE "${OUT1}" "")
file(WRITE "${OUT2}" "")
set(where 0)
string(REGEX REPLACE "/\\* sql_yacc\\.yy \\*/" "/* DON'T EDIT THIS FILE. IT'S GENERATED. EDIT sql_yacc.yy INSTEAD */" data "${data}")
while(NOT data STREQUAL "")
string(REGEX MATCH "^(%[ie][^\n]*\n)|((%[^ie\n]|[^%\n])[^\n]*\n)+|\n+" line "${data}")
string(LENGTH "${line}" ll)
string(SUBSTRING "${data}" ${ll} -1 data)
if (line MATCHES "^%ifdef +${VAL1} *\n")
set(where 1)
set(line "\n")
elseif(line MATCHES "^%ifdef +${VAL2} *\n")
set(where 2)
set(line "\n")
elseif(line MATCHES "^%else( *| +.*)\n" AND where GREATER 0)
math(EXPR where "3-${where}")
set(line "\n")
elseif(line MATCHES "^%endif( *| +.*)\n")
set(where 0)
set(line "\n")
endif()
if(where STREQUAL 1)
file(APPEND "${OUT1}" "${line}")
string(REGEX REPLACE "[^\n]+" "" line "${line}")
file(APPEND "${OUT2}" "${line}")
elseif(where STREQUAL 2)
file(APPEND "${OUT2}" "${line}")
string(REGEX REPLACE "[^\n]+" "" line "${line}")
file(APPEND "${OUT1}" "${line}")
else()
file(APPEND "${OUT1}" "${line}")
file(APPEND "${OUT2}" "${line}")
endif()
endwhile()

18
sql/myskel.m4 Normal file
View file

@ -0,0 +1,18 @@
#
# fix the #line directives in the generated .cc files
# to refer to the original sql_yacc.yy
#
m4_define([yyfile],m4_bpatsubst(__file__,[[a-z.0-9]+$],sql_yacc.yy))
m4_define([b4_syncline],
[m4_if(m4_index([$2],[.yy]),[-1],
[b4_sync_start([$1], [$2])[]dnl
],[b4_sync_start([$1], ["yyfile"])[]dnl
])])
# try both paths for different bison versions
m4_sinclude(skeletons/c-skel.m4)
m4_sinclude(c-skel.m4)

View file

@ -355,7 +355,7 @@ void binlog_unsafe_map_init();
#ifdef MYSQL_SERVER
/*
The following hack is needed because mysql_yacc.cc does not define
The following hack is needed because sql_yacc.cc does not define
YYSTYPE before including this file
*/
#ifdef MYSQL_YACC

View file

@ -341,14 +341,11 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
We should not introduce any further shift/reduce conflicts.
*/
/* Start SQL_MODE_DEFAULT_SPECIFIC */
%ifdef MARIADB
%expect 67
/* End SQL_MODE_DEFAULT_SPECIFIC */
/* Start SQL_MODE_ORACLE_SPECIFIC
%else
%expect 69
End SQL_MODE_ORACLE_SPECIFIC */
%endif
/*
@ -1766,7 +1763,7 @@ End SQL_MODE_ORACLE_SPECIFIC */
%type <vers_history_point> history_point
%type <vers_column_versioning> with_or_without_system
/* Start SQL_MODE_DEFAULT_SPECIFIC */
%ifdef MARIADB
%type <NONE> sp_tail_standalone
%type <NONE> sp_unlabeled_block_not_atomic
%type <NONE> sp_proc_stmt_in_returns_clause
@ -1778,10 +1775,7 @@ End SQL_MODE_ORACLE_SPECIFIC */
%type <spblock> sp_decl_variable_list
%type <spblock> sp_decl_variable_list_anchored
%type <kwd> reserved_keyword_udt_param_type
/* End SQL_MODE_DEFAULT_SPECIFIC */
/* Start SQL_MODE_ORACLE_SPECIFIC
%else
%type <NONE> set_assign
%type <spvar_mode> sp_opt_inout
%type <NONE> sp_tail_standalone
@ -1816,7 +1810,7 @@ End SQL_MODE_ORACLE_SPECIFIC */
%type <lex> package_routine_lex
%type <lex> package_specification_function
%type <lex> package_specification_procedure
End SQL_MODE_ORACLE_SPECIFIC */
%endif ORACLE
%%
@ -17809,7 +17803,7 @@ _empty:
/* Empty */
;
/* Start SQL_MODE_DEFAULT_SPECIFIC */
%ifdef MARIADB
statement:
@ -18208,10 +18202,10 @@ sp_unlabeled_block_not_atomic:
;
/* End SQL_MODE_DEFAULT_SPECIFIC */
%endif MARIADB
/* Start SQL_MODE_ORACLE_SPECIFIC
%ifdef ORACLE
statement:
verb_clause
@ -19220,7 +19214,7 @@ sp_block_statements_and_exceptions:
}
;
End SQL_MODE_ORACLE_SPECIFIC */
%endif ORACLE
/**
@} (end of group Parser)