Skip to content

Commit

Permalink
MDEV-25726 get rid of cmake comment hack in sql_yacc.yy
Browse files Browse the repository at this point in the history
and replace it with equally unsightly %ifdef/%endif hack
also, support %else, it's nice
  • Loading branch information
vuvova committed May 26, 2021
1 parent 288b801 commit dfbedda
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 15 additions & 12 deletions sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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 "")
Expand Down
15 changes: 0 additions & 15 deletions sql/gen_sql_yacc_ora_yy.cmake

This file was deleted.

39 changes: 39 additions & 0 deletions sql/gen_yy_files.cmake
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions sql/myskel.m4
Original file line number Diff line number Diff line change
@@ -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)

2 changes: 1 addition & 1 deletion sql/sql_lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 10 additions & 16 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -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


/*
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

%%

Expand Down Expand Up @@ -17809,7 +17803,7 @@ _empty:
/* Empty */
;

/* Start SQL_MODE_DEFAULT_SPECIFIC */
%ifdef MARIADB


statement:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -19220,7 +19214,7 @@ sp_block_statements_and_exceptions:
}
;

End SQL_MODE_ORACLE_SPECIFIC */
%endif ORACLE

/**
@} (end of group Parser)
Expand Down

0 comments on commit dfbedda

Please sign in to comment.