Use build time strings for pretty function names if supported.

This doesn't really do much until I have build time hashing.
This commit is contained in:
King_DuckZ 2015-06-09 00:00:41 +02:00
parent fd8a1cbabc
commit dba88117e4
6 changed files with 174 additions and 10 deletions

View file

@ -1,7 +1,23 @@
#ifndef id4E5F8A0ABA6047BA988D512351B9DD2D #ifndef id4E5F8A0ABA6047BA988D512351B9DD2D
#define id4E5F8A0ABA6047BA988D512351B9DD2D #define id4E5F8A0ABA6047BA988D512351B9DD2D
//#include "doorkeeper/implem/string_bt.hpp" #include "doorkeeper/implem/doorkeeper_conf.h"
#if (defined(__clang__) && \
(__clang_major__ == 3 && __clang_minor__ > 5) || (__clang_major__ > 3) \
) || (defined(IS_ORIGINAL_GNUC) && \
(__GNUC__ == 5 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 5) \
)
# define IS_PRETTY_FUNC_CONSTEXPR
#elif defined(__GNUC__)
//uhm.. nothing :p
#else
# error "Unknown compiler"
#endif
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
# include "doorkeeper/implem/string_bt.hpp"
#endif
#include "doorkeeper/implem/compatibility.h" #include "doorkeeper/implem/compatibility.h"
#include <cstdint> #include <cstdint>
#include <ciso646> #include <ciso646>
@ -27,4 +43,8 @@ namespace dk {
#include "doorkeeper/implem/hashing.inl" #include "doorkeeper/implem/hashing.inl"
#if defined(IS_PRETTY_FUNC_CONSTEXPR)
# undef IS_PRETTY_FUNC_CONSTEXPR
#endif
#endif #endif

View file

@ -1,15 +1,13 @@
namespace dk { namespace dk {
template <typename T, uint32_t D> template <typename T, uint32_t D>
HashType make_signature_hash() { HashType make_signature_hash() {
#if defined(__GNUC__) #if IS_PRETTY_FUNC_CONSTEXPR
//TODO: use bt::string if possible constexpr bt::string<sizeof(__PRETTY_FUNCTION__)-1> func_pretty(__PRETTY_FUNCTION__);
return implem::hash_string(func_pretty.data(), func_pretty.size());
#else
const char* const pf = __PRETTY_FUNCTION__; const char* const pf = __PRETTY_FUNCTION__;
const std::size_t len = sizeof(__PRETTY_FUNCTION__) - 1; const std::size_t len = sizeof(__PRETTY_FUNCTION__) - 1;
//constexpr bt::string<sizeof(__PRETTY_FUNCTION__)-1> func_pretty(pf);
#else
# error "Unknown compiler"
#endif
//return implem::hash_string(func_pretty.data(), func_pretty.size());
return implem::hash_string(pf, len); return implem::hash_string(pf, len);
#endif
} }
} //namespace dk } //namespace dk

View file

@ -0,0 +1,31 @@
#ifndef id4FAEF395B9ED47CB9D6B50B54C9A289A
#define id4FAEF395B9ED47CB9D6B50B54C9A289A
#include <cstddef>
namespace dk {
namespace bt {
template <std::size_t... I>
struct index_seq {
};
namespace implem {
template <std::size_t MIN, std::size_t MAX, std::size_t... I>
struct range_builder;
template <std::size_t MIN, std::size_t... I>
struct range_builder<MIN, MIN, I...> {
typedef index_seq<I...> type;
};
template <std::size_t MIN, std::size_t N, std::size_t... I>
struct range_builder : public range_builder<MIN, N - 1, N - 1, I...> {
};
} //namespace implem
template <std::size_t MIN, std::size_t MAX>
using index_range = typename implem::range_builder<MIN, MAX>::type;
} //namespace bt
} //namespace dk
#endif

View file

@ -0,0 +1,95 @@
#ifndef id170B0E6C34D14EBA9B92A35977BDBFB3
#define id170B0E6C34D14EBA9B92A35977BDBFB3
#include "doorkeeper/implem/sequence_bt.hpp"
#include <cstddef>
#include <iostream>
#include <stdexcept>
namespace dk {
namespace bt {
template <std::size_t S>
class string;
template <std::size_t S>
std::ostream& operator<< ( std::ostream& parStream, const string<S>& parString );
template <std::size_t S>
class string {
public:
friend std::ostream& operator<< <>( std::ostream& parStream, const string<S>& parString );
constexpr string ( const char* parString );
constexpr std::size_t size ( void ) const { return S - 1; }
template <std::size_t S2>
constexpr string<S + S2 - 1> operator+ ( const string<S2>& parOther ) const;
constexpr char operator[] ( std::size_t parIndex ) const;
template <typename... Args>
constexpr string ( Args... );
constexpr const char (&data_arr() const)[S] { return m_data; }
constexpr const char* data() const { return m_data; }
private:
template <std::size_t... I>
constexpr string ( const index_seq<I...>&, const char* parString );
const char m_data[S];
};
namespace implem {
template <std::size_t S, std::size_t S2, std::size_t... I>
constexpr string<S + S2 - 1> concat ( const index_seq<I...>&, const string<S>& parLeft, const string<S2>& parRight ) {
return string<S + S2 - 1>(
(I < S - 1 ? parLeft[I] : (I < S + S2 - 2 ? parRight[I - (S - 1)] : '\0'))...
);
}
} //namespace implem
template <std::size_t S>
template <std::size_t... I>
constexpr string<S>::string (const index_seq<I...>&, const char* parString) :
m_data{parString[I]...}
{
}
template <std::size_t S>
inline constexpr string<S>::string (const char* parString) :
string(index_range<0, S>(), parString)
{
}
template <std::size_t S>
template <typename... Args>
inline constexpr string<S>::string (Args... parArgs) :
m_data{parArgs...}
{
}
template <std::size_t S>
template <std::size_t S2>
constexpr inline string<S + S2 - 1> string<S>::operator+ (const string<S2>& parOther) const {
return implem::concat(index_range<0, S + S2 - 1>(), string<S>(m_data), parOther);
}
template <std::size_t S>
inline std::ostream& operator<< (std::ostream& parStream, const string<S>& parString) {
parStream << parString.m_data;
return parStream;
}
template <std::size_t S>
constexpr char string<S>::operator[] (std::size_t parIndex) const {
return (parIndex < S ? m_data[parIndex] : throw std::out_of_range(""));
}
template <std::size_t S>
constexpr string<S> make_string (const char (&parData)[S]) {
return string<S>(parData);
}
} //namespace bt
} //namespace dk
#endif

View file

@ -1,8 +1,15 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR) cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(doorkeeper CXX C) project(doorkeeper CXX C)
include_directories( if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
. set(ID_IS_ORIGINAL_GNUC "1")
else()
set(ID_IS_ORIGINAL_GNUC "0")
endif()
configure_file(
${PROJECT_NAME}_conf.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/doorkeeper/implem/${PROJECT_NAME}_conf.h
) )
add_library(${PROJECT_NAME} add_library(${PROJECT_NAME}
@ -11,3 +18,8 @@ add_library(${PROJECT_NAME}
tiger.c tiger.c
hashing.cpp hashing.cpp
) )
target_include_directories(${PROJECT_NAME}
PRIVATE .
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include
)

8
src/doorkeeper_conf.h.in Normal file
View file

@ -0,0 +1,8 @@
#ifndef idB523F14441E649E089C21CDE8189640C
#define idB523F14441E649E089C21CDE8189640C
#if @ID_IS_ORIGINAL_GNUC@ != 0
# define IS_ORIGINAL_GNUC
#endif
#endif