diff --git a/CMakeLists.txt b/CMakeLists.txt index c997491858..ee8f0841cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,63 +99,6 @@ scylla_generate_thrift( OUT_DIR ${scylla_gen_build_dir} SERVICE Cassandra) -# Parse antlr3 grammar files and generate C++ sources -function(scylla_generate_antlr3) - set(one_value_args TARGET VAR IN_FILE OUT_DIR) - cmake_parse_arguments(args "" "${one_value_args}" "" ${ARGN}) - - get_filename_component(in_file_pure_name ${args_IN_FILE} NAME) - get_filename_component(stem ${in_file_pure_name} NAME_WE) - - set(outputs - "${args_OUT_DIR}/${stem}Lexer.hpp" - "${args_OUT_DIR}/${stem}Lexer.cpp" - "${args_OUT_DIR}/${stem}Parser.hpp" - "${args_OUT_DIR}/${stem}Parser.cpp") - - add_custom_command( - DEPENDS - ${args_IN_FILE} - OUTPUT ${outputs} - # Remove #ifdef'ed code from the grammar source code - COMMAND sed -e "/^#if 0/,/^#endif/d" "${args_IN_FILE}" > "${args_OUT_DIR}/${in_file_pure_name}" - COMMAND antlr3 "${args_OUT_DIR}/${in_file_pure_name}" - # We replace many local `ExceptionBaseType* ex` variables with a single function-scope one. - # Because we add such a variable to every function, and because `ExceptionBaseType` is not a global - # name, we also add a global typedef to avoid compilation errors. - COMMAND sed -i -e "/^.*On :.*$/d" "${args_OUT_DIR}/${stem}Lexer.hpp" - COMMAND sed -i -e "/^.*On :.*$/d" "${args_OUT_DIR}/${stem}Lexer.cpp" - COMMAND sed -i -e "/^.*On :.*$/d" "${args_OUT_DIR}/${stem}Parser.hpp" - COMMAND sed -i - -e "s/^\\( *\\)\\(ImplTraits::CommonTokenType\\* [a-zA-Z0-9_]* = NULL;\\)$/\\1const \\2/" - -e "/^.*On :.*$/d" - -e "1i using ExceptionBaseType = int;" - -e "s/^{/{ ExceptionBaseType\\* ex = nullptr;/; s/ExceptionBaseType\\* ex = new/ex = new/; s/exceptions::syntax_exception e/exceptions::syntax_exception\\& e/" - "${args_OUT_DIR}/${stem}Parser.cpp" - VERBATIM) - - add_custom_target(${args_TARGET} - DEPENDS ${outputs}) - - set(${args_VAR} ${outputs} PARENT_SCOPE) -endfunction() - -set(antlr3_grammar_files - cql3/Cql.g - alternator/expressions.g) - -set(antlr3_gen_files) - -foreach(f ${antlr3_grammar_files}) - get_filename_component(grammar_file_name "${f}" NAME_WE) - get_filename_component(f_dir "${f}" DIRECTORY) - scylla_generate_antlr3( - TARGET scylla_antlr3_gen_${grammar_file_name} - VAR scylla_antlr3_gen_${grammar_file_name}_files - IN_FILE "${CMAKE_SOURCE_DIR}/${f}" - OUT_DIR ${scylla_gen_build_dir}/${f_dir}) - list(APPEND antlr3_gen_files "${scylla_antlr3_gen_${grammar_file_name}_files}") -endforeach() # Generate C++ sources from ragel grammar files seastar_generate_ragel( @@ -270,15 +213,6 @@ endforeach() set(scylla_sources absl-flat_hash_map.cc - alternator/auth.cc - alternator/conditions.cc - alternator/controller.cc - alternator/executor.cc - alternator/expressions.cc - alternator/serialization.cc - alternator/server.cc - alternator/stats.cc - alternator/streams.cc api/api.cc api/cache_service.cc api/collectd.cc @@ -337,101 +271,6 @@ set(scylla_sources compress.cc converting_mutation_partition_applier.cc counters.cc - cql3/abstract_marker.cc - cql3/attributes.cc - cql3/cf_name.cc - cql3/column_condition.cc - cql3/column_identifier.cc - cql3/column_specification.cc - cql3/constants.cc - cql3/cql3_type.cc - cql3/expr/expression.cc - cql3/expr/prepare_expr.cc - cql3/expr/restrictions.cc - cql3/functions/aggregate_fcts.cc - cql3/functions/castas_fcts.cc - cql3/functions/error_injection_fcts.cc - cql3/functions/functions.cc - cql3/functions/user_function.cc - cql3/index_name.cc - cql3/keyspace_element_name.cc - cql3/lists.cc - cql3/maps.cc - cql3/operation.cc - cql3/prepare_context.cc - cql3/query_options.cc - cql3/query_processor.cc - cql3/restrictions/statement_restrictions.cc - cql3/result_set.cc - cql3/role_name.cc - cql3/selection/abstract_function_selector.cc - cql3/selection/selectable.cc - cql3/selection/selection.cc - cql3/selection/selector.cc - cql3/selection/selector_factories.cc - cql3/selection/simple_selector.cc - cql3/sets.cc - cql3/statements/alter_keyspace_statement.cc - cql3/statements/alter_service_level_statement.cc - cql3/statements/alter_table_statement.cc - cql3/statements/alter_type_statement.cc - cql3/statements/alter_view_statement.cc - cql3/statements/attach_service_level_statement.cc - cql3/statements/authentication_statement.cc - cql3/statements/authorization_statement.cc - cql3/statements/batch_statement.cc - cql3/statements/cas_request.cc - cql3/statements/cf_prop_defs.cc - cql3/statements/cf_statement.cc - cql3/statements/create_aggregate_statement.cc - cql3/statements/create_function_statement.cc - cql3/statements/create_index_statement.cc - cql3/statements/create_keyspace_statement.cc - cql3/statements/create_service_level_statement.cc - cql3/statements/create_table_statement.cc - cql3/statements/create_type_statement.cc - cql3/statements/create_view_statement.cc - cql3/statements/delete_statement.cc - cql3/statements/detach_service_level_statement.cc - cql3/statements/drop_aggregate_statement.cc - cql3/statements/drop_function_statement.cc - cql3/statements/drop_index_statement.cc - cql3/statements/drop_keyspace_statement.cc - cql3/statements/drop_service_level_statement.cc - cql3/statements/drop_table_statement.cc - cql3/statements/drop_type_statement.cc - cql3/statements/drop_view_statement.cc - cql3/statements/function_statement.cc - cql3/statements/grant_statement.cc - cql3/statements/index_prop_defs.cc - cql3/statements/index_target.cc - cql3/statements/ks_prop_defs.cc - cql3/statements/list_permissions_statement.cc - cql3/statements/list_service_level_attachments_statement.cc - cql3/statements/list_service_level_statement.cc - cql3/statements/list_users_statement.cc - cql3/statements/modification_statement.cc - cql3/statements/permission_altering_statement.cc - cql3/statements/property_definitions.cc - cql3/statements/raw/parsed_statement.cc - cql3/statements/revoke_statement.cc - cql3/statements/role-management-statements.cc - cql3/statements/schema_altering_statement.cc - cql3/statements/select_statement.cc - cql3/statements/service_level_statement.cc - cql3/statements/sl_prop_defs.cc - cql3/statements/truncate_statement.cc - cql3/statements/update_statement.cc - cql3/statements/strongly_consistent_modification_statement.cc - cql3/statements/strongly_consistent_select_statement.cc - cql3/statements/use_statement.cc - cql3/type_json.cc - cql3/untyped_result_set.cc - cql3/update_parameters.cc - cql3/user_types.cc - cql3/util.cc - cql3/ut_name.cc - cql3/values.cc data_dictionary/data_dictionary.cc db/batchlog_manager.cc db/commitlog/commitlog.cc @@ -680,13 +519,19 @@ set(scylla_gen_sources "${scylla_thrift_gen_cassandra_files}" "${scylla_ragel_gen_protocol_parser_file}" "${swagger_gen_files}" - "${idl_gen_files}" - "${antlr3_gen_files}") + "${idl_gen_files}") + +add_subdirectory(alternator) +add_subdirectory(cql3) add_executable(scylla ${scylla_sources} ${scylla_gen_sources}) +target_link_libraries(scylla PRIVATE + alternator + cql3) + target_link_libraries(scylla PRIVATE seastar # Boost dependencies diff --git a/alternator/CMakeLists.txt b/alternator/CMakeLists.txt new file mode 100644 index 0000000000..1395515ea4 --- /dev/null +++ b/alternator/CMakeLists.txt @@ -0,0 +1,19 @@ +include(generate_cql_grammar) +generate_cql_grammar( + GRAMMAR expressions.g + SOURCES cql_grammar_srcs) + +add_library(alternator STATIC) +target_sources(alternator + PRIVATE + controller.cc + server.cc + executor.cc + stats.cc + serialization.cc + expressions.cc + conditions.cc + auth.cc + streams.cc + ttl.cc + ${cql_grammar_srcs}) diff --git a/cmake/generate_cql_grammar.cmake b/cmake/generate_cql_grammar.cmake new file mode 100644 index 0000000000..44f4d14121 --- /dev/null +++ b/cmake/generate_cql_grammar.cmake @@ -0,0 +1,49 @@ +find_program (ANTLR3 antlr3) +if(NOT ANTLR3) + message(FATAL "antlr3 is required") +endif() + +# Parse antlr3 grammar files and generate C++ sources +function(generate_cql_grammar) + cmake_parse_arguments(parsed_args "" "GRAMMAR;OUTPUT_DIR;SOURCES" "" ${ARGN}) + if(IS_ABSOLUTE ${parsed_args_GRAMMAR}) + set(grammar ${parsed_args_GRAMMAR}) + else() + set(grammar ${CMAKE_CURRENT_SOURCE_DIR}/${parsed_args_GRAMMAR}) + endif() + if(parsed_args_OUTPUT_DIR) + set(gen_dir "${parsed_args_OUTPUT_DIR}") + else() + set(gen_dir "${CMAKE_CURRENT_BINARY_DIR}") + endif() + get_filename_component(name "${grammar}" NAME) + set(grammar_processed ${gen_dir}/${name}) + + get_filename_component(stem "${grammar}" NAME_WE) + foreach (postfix "Lexer.hpp" "Lexer.cpp" "Parser.hpp" "Parser.cpp") + set(filename "${stem}${postfix}") + list(APPEND outputs "${filename}") + list(APPEND remove_timestamps COMMAND sed -i -e "/^.*On : .*$/d" ${filename}) + endforeach() + + add_custom_command( + DEPENDS ${grammar} + OUTPUT ${outputs} + # Remove #ifdef'ed code from the grammar source code + COMMAND sed -e "/^#if 0/,/^#endif/d" ${grammar} > ${grammar_processed} + COMMAND ${ANTLR3} "${grammar_processed}" + ${remove_timestamps} + # We replace many local `ExceptionBaseType* ex` variables with a single function-scope one. + # Because we add such a variable to every function, and because `ExceptionBaseType` is not a global + # name, we also add a global typedef to avoid compilation errors. + COMMAND sed -i -e "s/^\\( *\\)\\(ImplTraits::CommonTokenType\\* [a-zA-Z0-9_]* = NULL;\\)$/\\1const \\2/" + -e "1i using ExceptionBaseType = int;" + -e "s/^{{/{{ ExceptionBaseType\* ex = nullptr;/" + -e "s/ExceptionBaseType\* ex = new/ex = new/" + -e "s/exceptions::syntax_exception e/exceptions::syntax_exception\& e/" + ${gen_dir}/${stem}Parser.cpp + COMMENT "Generating sources from ${grammar}" + VERBATIM) + + set(${parsed_args_SOURCES} ${outputs} PARENT_SCOPE) +endfunction(generate_cql_grammar) diff --git a/cql3/CMakeLists.txt b/cql3/CMakeLists.txt new file mode 100644 index 0000000000..f17b3d6328 --- /dev/null +++ b/cql3/CMakeLists.txt @@ -0,0 +1,110 @@ +find_program (ANTLR3 antlr3) +if(NOT ANTLR3) + message(FATAL "antlr3 is required") +endif() + +generate_cql_grammar( + GRAMMAR Cql.g + SOURCES cql_grammar_srcs) + +add_library(cql3 STATIC) +target_sources(cql3 + PRIVATE + type_json.cc + abstract_marker.cc + attributes.cc + cf_name.cc + cql3_type.cc + operation.cc + index_name.cc + keyspace_element_name.cc + lists.cc + sets.cc + maps.cc + values.cc + expr/expression.cc + expr/restrictions.cc + expr/prepare_expr.cc + functions/user_function.cc + functions/functions.cc + functions/aggregate_fcts.cc + functions/castas_fcts.cc + functions/error_injection_fcts.cc + statements/cf_prop_defs.cc + statements/cf_statement.cc + statements/authentication_statement.cc + statements/create_keyspace_statement.cc + statements/create_table_statement.cc + statements/create_view_statement.cc + statements/create_type_statement.cc + statements/create_function_statement.cc + statements/create_aggregate_statement.cc + statements/drop_index_statement.cc + statements/drop_keyspace_statement.cc + statements/drop_table_statement.cc + statements/drop_view_statement.cc + statements/drop_type_statement.cc + statements/drop_function_statement.cc + statements/drop_aggregate_statement.cc + statements/schema_altering_statement.cc + statements/ks_prop_defs.cc + statements/function_statement.cc + statements/modification_statement.cc + statements/cas_request.cc + statements/raw/parsed_statement.cc + statements/property_definitions.cc + statements/update_statement.cc + statements/strongly_consistent_modification_statement.cc + statements/strongly_consistent_select_statement.cc + statements/delete_statement.cc + statements/prune_materialized_view_statement.cc + statements/batch_statement.cc + statements/select_statement.cc + statements/use_statement.cc + statements/index_prop_defs.cc + statements/index_target.cc + statements/create_index_statement.cc + statements/truncate_statement.cc + statements/alter_table_statement.cc + statements/alter_view_statement.cc + statements/list_users_statement.cc + statements/authorization_statement.cc + statements/permission_altering_statement.cc + statements/list_permissions_statement.cc + statements/grant_statement.cc + statements/revoke_statement.cc + statements/alter_type_statement.cc + statements/alter_keyspace_statement.cc + statements/role-management-statements.cc + statements/service_level_statement.cc + statements/create_service_level_statement.cc + statements/alter_service_level_statement.cc + statements/sl_prop_defs.cc + statements/drop_service_level_statement.cc + statements/attach_service_level_statement.cc + statements/detach_service_level_statement.cc + statements/list_service_level_statement.cc + statements/list_service_level_attachments_statement.cc + statements/describe_statement.cc + update_parameters.cc + util.cc + ut_name.cc + role_name.cc + column_identifier.cc + column_specification.cc + constants.cc + query_processor.cc + query_options.cc + column_condition.cc + user_types.cc + untyped_result_set.cc + selection/abstract_function_selector.cc + selection/simple_selector.cc + selection/selectable.cc + selection/selector_factories.cc + selection/selection.cc + selection/selector.cc + restrictions/statement_restrictions.cc + result_set.cc + prepare_context.cc + ${cql_grammar_srcs})