Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation issues with clang #202

Closed
6 changes: 4 additions & 2 deletions cpp/CMakeLists.txt
Expand Up @@ -4,21 +4,23 @@ project(gherkin-cpp VERSION 1.0.0 LANGUAGES C CXX)


include(GNUInstallDirs) include(GNUInstallDirs)


set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)


find_package(nlohmann_json CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED)
find_package(cucumber-messages CONFIG REQUIRED) find_package(cucumber-messages CONFIG REQUIRED)


add_subdirectory(include)
add_subdirectory(src/lib/gherkin) add_subdirectory(src/lib/gherkin)
add_subdirectory(src/bin/gherkin) add_subdirectory(src/bin/gherkin)
add_subdirectory(src/bin/gherkin-generate-tokens) add_subdirectory(src/bin/gherkin-generate-tokens)


install( install(
TARGETS TARGETS
gherkin-cpp gherkin-cpp
gherkin-cpp-include
gherkin-bin gherkin-bin
gherkin-generate-tokens-bin gherkin-generate-tokens-bin
EXPORT gherkin-cpp-config EXPORT gherkin-cpp-config
Expand All @@ -28,7 +30,7 @@ install(
) )


install( install(
DIRECTORY "${CMAKE_SOURCE_DIR}/include/" DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gherkin DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gherkin
) )


Expand Down
27 changes: 27 additions & 0 deletions cpp/include/CMakeLists.txt
@@ -0,0 +1,27 @@
add_library(gherkin-cpp-include INTERFACE)
add_library(gherkin::gherkin-cpp-include ALIAS gherkin-cpp-include)

set(INC_DIR "${CMAKE_CURRENT_LIST_DIR}")

# We prefer it that way...
file(GLOB_RECURSE GHERKIN_CPP_HEADERS ${INC_DIR}/*.[ch]pp)

target_sources(
gherkin-cpp-include
PRIVATE
${GHERKIN_CPP_HEADERS}
)

target_include_directories(
gherkin-cpp-include
INTERFACE
$<BUILD_INTERFACE:${INC_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/gherkin>
)

target_link_libraries(
gherkin-cpp-include
INTERFACE
cucumber::messages
nlohmann_json::nlohmann_json
)
4 changes: 2 additions & 2 deletions cpp/include/gherkin/ast_node.hpp
Expand Up @@ -120,7 +120,7 @@ class ast_node
{ {
using type = std::decay_t<T>; using type = std::decay_t<T>;


if constexpr (is_container_v<std::vector, type>) { if constexpr (is_container_v<type>) {
using value_type = typename type::value_type; using value_type = typename type::value_type;
using vector_type = std::vector<value_type>; using vector_type = std::vector<value_type>;


Expand All @@ -147,7 +147,7 @@ class ast_node
{ {
using type = std::decay_t<T>; using type = std::decay_t<T>;


if constexpr (is_container_v<std::optional, type>) { if constexpr (is_optional_v<type>) {
using value_type = typename type::value_type; using value_type = typename type::value_type;


set_value<value_type>(rule_type, v); set_value<value_type>(rule_type, v);
Expand Down
24 changes: 0 additions & 24 deletions cpp/include/gherkin/demangle.hpp

This file was deleted.

3 changes: 1 addition & 2 deletions cpp/include/gherkin/regex.hpp
Expand Up @@ -6,7 +6,6 @@
#include <gherkin/utils.hpp> #include <gherkin/utils.hpp>
#include <gherkin/types.hpp> #include <gherkin/types.hpp>
#include <gherkin/log.hpp> #include <gherkin/log.hpp>
#include <gherkin/demangle.hpp>


namespace gherkin { namespace gherkin {


Expand Down Expand Up @@ -136,7 +135,7 @@ full_match(
{ {
std::cmatch m; std::cmatch m;


bool match = std::regex_match(e.begin(), e.end(), m, re); bool match = std::regex_match(e.data(), e.data() + e.size(), m, re);


if (match) { if (match) {
detail::extract_submatches<CharT>(m, std::forward<Args>(args)...); detail::extract_submatches<CharT>(m, std::forward<Args>(args)...);
Expand Down
44 changes: 27 additions & 17 deletions cpp/include/gherkin/type_traits.hpp
@@ -1,38 +1,48 @@
#include <type_traits> #include <optional>
#include <vector>


namespace gherkin { namespace gherkin {


namespace detail {

template < template <
template <typename> class Container,
template <typename> class Other,
typename T typename T
> >
std::is_same<Container<T>, Other<T>> struct is_cont {
test_is_container(Other<T>*); static const bool value = false;
};

template <
typename T,
typename Alloc
>
struct is_cont<std::vector<T,Alloc> > {
static const bool value = true;
};



template < template <
template <typename> class Container,
typename T typename T
> >
std::false_type test_is_container(T*); struct is_optional {
static const bool value = false;
};


} // namespace detail template <
typename T
>
struct is_optional<std::optional<T> > {
static const bool value = true;
};


template < template <
template <typename> class C,
typename T typename T
> >
using is_container = decltype( inline
detail::test_is_container<C>(static_cast<T*>(nullptr)) constexpr bool is_container_v = is_cont<T>::value;
);


template < template <
template <typename> class C,
typename T typename T
> >
inline inline
constexpr bool is_container_v = is_container<C, T>::value; constexpr bool is_optional_v = is_optional<T>::value;


} }
7 changes: 4 additions & 3 deletions cpp/include/gherkin/utils.hpp
@@ -1,6 +1,7 @@
#pragma once #pragma once


#include <codecvt> #include <codecvt>
#include <locale>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <regex> #include <regex>
Expand All @@ -24,7 +25,7 @@ inline
std::wstring std::wstring
to_wide(const std::string& s) to_wide(const std::string& s)
{ {
std::wstring_convert<std::codecvt_utf8<char32_t>,char32_t> cv; std::wstring_convert<std::codecvt_utf8<std::wstring::value_type>, std::wstring::value_type> cv;


auto ws = cv.from_bytes(s); auto ws = cv.from_bytes(s);


Expand All @@ -35,9 +36,9 @@ inline
std::string std::string
to_narrow(const std::wstring& ws) to_narrow(const std::wstring& ws)
{ {
std::wstring_convert<std::codecvt_utf8<char32_t>,char32_t> cv; std::wstring_convert<std::codecvt_utf8<std::wstring::value_type>, std::wstring::value_type> cv;


std::u32string s{ws.begin(), ws.end()}; std::wstring s{ws.begin(), ws.end()};


return cv.to_bytes(s); return cv.to_bytes(s);
} }
Expand Down
5 changes: 2 additions & 3 deletions cpp/src/bin/gherkin-generate-tokens/CMakeLists.txt
Expand Up @@ -3,14 +3,13 @@ add_executable(gherkin-generate-tokens-bin)
target_sources( target_sources(
gherkin-generate-tokens-bin gherkin-generate-tokens-bin
PRIVATE PRIVATE
${CMAKE_SOURCE_DIR}/src/bin/gherkin-generate-tokens/gherkin-generate-tokens.cpp gherkin-generate-tokens.cpp
) )


target_include_directories( target_include_directories(
gherkin-generate-tokens-bin gherkin-generate-tokens-bin
PRIVATE PRIVATE
${CMAKE_SOURCE_DIR}/ ./
${CMAKE_SOURCE_DIR}/src/bin/gherkin-generate-tokens
) )


target_link_libraries( target_link_libraries(
Expand Down
5 changes: 2 additions & 3 deletions cpp/src/bin/gherkin/CMakeLists.txt
Expand Up @@ -3,14 +3,13 @@ add_executable(gherkin-bin)
target_sources( target_sources(
gherkin-bin gherkin-bin
PRIVATE PRIVATE
${CMAKE_SOURCE_DIR}/src/bin/gherkin/gherkin.cpp gherkin.cpp
) )


target_include_directories( target_include_directories(
gherkin-bin gherkin-bin
PRIVATE PRIVATE
${CMAKE_SOURCE_DIR}/ ./
${CMAKE_SOURCE_DIR}/src/bin/gherkin
) )


target_link_libraries( target_link_libraries(
Expand Down
15 changes: 2 additions & 13 deletions cpp/src/lib/gherkin/CMakeLists.txt
Expand Up @@ -4,35 +4,24 @@ add_library(gherkin::gherkin-cpp ALIAS gherkin-cpp)
set(INC_DIR "${CMAKE_SOURCE_DIR}/include") set(INC_DIR "${CMAKE_SOURCE_DIR}/include")


# We prefer it that way... # We prefer it that way...
file(GLOB_RECURSE GHERKIN_CPP_HEADERS ${INC_DIR}/*.[ch]pp)
file(GLOB_RECURSE GHERKIN_CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.[ch]pp) file(GLOB_RECURSE GHERKIN_CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.[ch]pp)


target_sources( target_sources(
gherkin-cpp gherkin-cpp
PRIVATE PRIVATE
${GHERKIN_CPP_HEADERS}
${GHERKIN_CPP_SOURCES} ${GHERKIN_CPP_SOURCES}
) )


target_include_directories(
gherkin-cpp
PUBLIC
$<BUILD_INTERFACE:${INC_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/gherkin>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries( target_link_libraries(
gherkin-cpp gherkin-cpp
PUBLIC PUBLIC
cucumber::cucumber-messages cucumber::messages
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
gherkin::gherkin-cpp-include
) )


set_target_properties( set_target_properties(
gherkin-cpp gherkin-cpp
PROPERTIES PROPERTIES
OUTPUT_NAME gherkin-cpp OUTPUT_NAME gherkin-cpp
) )

27 changes: 0 additions & 27 deletions cpp/src/lib/gherkin/demangle.cpp

This file was deleted.