Skip to content

Commit

Permalink
pw_tokenizer: Remove unsupported C++11 and C++14 code
Browse files Browse the repository at this point in the history
Pigweed requires C++17 or newer. Remove code for C++11/14 compatibility
since it is never compiled or tested.

If C++14 or C++11 support is needed for pw_tokenizer, projects can use
the C implementation or check out an older version of pw_tokenizer (e.g.
before 0132da5).

Change-Id: Id839a5ee56cd4036183a1e1a46b46a6d8e4b0c21
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/222432
Lint: Lint 🤖 <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Reviewed-by: Dave Roth <[email protected]>
Pigweed-Auto-Submit: Wyatt Hepler <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
  • Loading branch information
255 authored and CQ Bot Account committed Aug 14, 2024
1 parent cc28da1 commit 52eee72
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 86 deletions.
6 changes: 2 additions & 4 deletions pw_tokenizer/encode_args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ static_assert((PW_TOKENIZER_CFG_ARG_TYPES_SIZE_BYTES == 4) ||
(PW_TOKENIZER_CFG_ARG_TYPES_SIZE_BYTES == 8),
"PW_TOKENIZER_CFG_ARG_TYPES_SIZE_BYTES must be 4 or 8");

namespace pw {
namespace tokenizer {
namespace pw::tokenizer {
namespace {

// Declare the types as an enum for convenience.
Expand Down Expand Up @@ -141,5 +140,4 @@ extern "C" size_t pw_tokenizer_EncodeArgs(pw_tokenizer_ArgTypes types,
output_buffer_size));
}

} // namespace tokenizer
} // namespace pw
} // namespace pw::tokenizer
6 changes: 2 additions & 4 deletions pw_tokenizer/encode_args_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

#include "pw_unit_test/framework.h"

namespace pw {
namespace tokenizer {
namespace pw::tokenizer {

static_assert(MinEncodingBufferSizeBytes<>() == 4);
static_assert(MinEncodingBufferSizeBytes<bool>() == 4 + 2);
Expand Down Expand Up @@ -50,5 +49,4 @@ TEST(TokenizerCEncodingFunctions, EncodeInt64) {
EXPECT_EQ(buffer[0], 2); // 1 encodes to 2 with ZigZag
}

} // namespace tokenizer
} // namespace pw
} // namespace pw::tokenizer
4 changes: 0 additions & 4 deletions pw_tokenizer/hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

#include "pw_tokenizer/hash.h"

#if PW_CXX_STANDARD_IS_SUPPORTED(17)

namespace pw::tokenizer {

extern "C" uint32_t pw_tokenizer_65599FixedLengthHash(const char* string,
Expand All @@ -26,5 +24,3 @@ extern "C" uint32_t pw_tokenizer_65599FixedLengthHash(const char* string,
}

} // namespace pw::tokenizer

#endif // PW_CXX_STANDARD_IS_SUPPORTED(17)
4 changes: 2 additions & 2 deletions pw_tokenizer/public/pw_tokenizer/encode_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "pw_tokenizer/internal/argument_types.h"
#include "pw_varint/varint.h"

#if PW_CXX_STANDARD_IS_SUPPORTED(17)
#ifdef __cplusplus

#include <cstring>

Expand Down Expand Up @@ -138,7 +138,7 @@ class EncodedMessage {

} // namespace pw::tokenizer

#endif // PW_CXX_STANDARD_IS_SUPPORTED(17)
#endif // __cplusplus

PW_EXTERN_C_START

Expand Down
6 changes: 2 additions & 4 deletions pw_tokenizer/public/pw_tokenizer/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
#include "pw_polyfill/standard.h"
#include "pw_preprocessor/util.h"

// The hash implementation uses std::string_view. Use the C implementation when
// compiling with older C++ standards.
#if PW_CXX_STANDARD_IS_SUPPORTED(17)
#ifdef __cplusplus

#include <string_view>

Expand Down Expand Up @@ -108,7 +106,7 @@ constexpr uint32_t PwTokenizer65599FixedLengthHash(

} // namespace pw::tokenizer

#endif // PW_CXX_STANDARD_IS_SUPPORTED(17)
#endif // __cplusplus

// C version of the fixed-length hash. Can be used to calculate hashes
// equivalent to the hashing macros at runtime in C.
Expand Down
44 changes: 2 additions & 42 deletions pw_tokenizer/public/pw_tokenizer/internal/argument_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ typedef uint64_t pw_tokenizer_ArgTypes;

#define _PW_VARARGS_TYPE(arg) ::pw::tokenizer::VarargsType<decltype(arg)>()

namespace pw {
namespace tokenizer {

#ifdef __cpp_if_constexpr // C++17 version
namespace pw::tokenizer {

// This function selects the matching type enum for supported argument types.
template <typename T>
Expand All @@ -105,44 +102,7 @@ constexpr pw_tokenizer_ArgTypes VarargsType() {
}
}

#else // C++14 version

template <typename T,
bool kIsDouble = std::is_floating_point<T>(),
bool kIsString = !std::is_null_pointer<T>() &&
std::is_convertible<T, const char*>(),
bool kIsInt64 = sizeof(T) == sizeof(int64_t)>
struct SelectVarargsType;

template <typename T, bool kDontCare1, bool kDontCare2>
struct SelectVarargsType<T, true, kDontCare1, kDontCare2> {
static constexpr pw_tokenizer_ArgTypes kValue = PW_TOKENIZER_ARG_TYPE_DOUBLE;
};

template <typename T, bool kDontCare>
struct SelectVarargsType<T, false, true, kDontCare> {
static constexpr pw_tokenizer_ArgTypes kValue = PW_TOKENIZER_ARG_TYPE_STRING;
};

template <typename T>
struct SelectVarargsType<T, false, false, true> {
static constexpr pw_tokenizer_ArgTypes kValue = PW_TOKENIZER_ARG_TYPE_INT64;
};

template <typename T>
struct SelectVarargsType<T, false, false, false> {
static constexpr pw_tokenizer_ArgTypes kValue = PW_TOKENIZER_ARG_TYPE_INT;
};

template <typename T>
constexpr pw_tokenizer_ArgTypes VarargsType() {
return SelectVarargsType<typename std::decay<T>::type>::kValue;
}

#endif // __cpp_if_constexpr

} // namespace tokenizer
} // namespace pw
} // namespace pw::tokenizer

#else // C version

Expand Down
8 changes: 2 additions & 6 deletions pw_tokenizer/public/pw_tokenizer/internal/tokenize_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ typedef struct {
#include "pw_containers/to_array.h"
#include "pw_preprocessor/compiler.h"

namespace pw {
namespace tokenizer {
namespace internal {
namespace pw::tokenizer::internal {

static_assert(sizeof(_pw_tokenizer_EntryHeader) == 4 * sizeof(uint32_t));

Expand Down Expand Up @@ -89,9 +87,7 @@ constexpr Entry<kDomainSize, kStringSize> MakeEntry(
return {token, domain, string};
}

} // namespace internal
} // namespace tokenizer
} // namespace pw
} // namespace pw::tokenizer::internal

#else // In C, define a struct inline with appropriately-sized string members.

Expand Down
6 changes: 2 additions & 4 deletions pw_tokenizer/public/pw_tokenizer/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,11 @@ PW_EXTERN_C_END
_pw_tokenizer_string_entry_) = \
::pw::tokenizer::internal::MakeEntry(token, domain, string)

namespace pw {
namespace tokenizer {
namespace pw::tokenizer {

using Token = ::pw_tokenizer_Token;

} // namespace tokenizer
} // namespace pw
} // namespace pw::tokenizer

#else

Expand Down
6 changes: 2 additions & 4 deletions pw_tokenizer/simple_tokenize_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#include "pw_tokenizer/tokenize.h"
#include "pw_unit_test/framework.h"

namespace pw {
namespace tokenizer {
namespace pw::tokenizer {
namespace {

template <size_t kSize>
Expand Down Expand Up @@ -73,5 +72,4 @@ class TokenizeToBuffer : public ::testing::Test {
};

} // namespace
} // namespace tokenizer
} // namespace pw
} // namespace pw::tokenizer
14 changes: 2 additions & 12 deletions pw_tokenizer/tokenize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
#include "pw_span/span.h"
#include "pw_tokenizer/encode_args.h"

namespace pw {
namespace tokenizer {
namespace pw::tokenizer {
namespace {

static_assert(sizeof(PW_TOKENIZER_NESTED_PREFIX_STR) == 2,
Expand Down Expand Up @@ -81,23 +80,14 @@ extern "C" void _pw_tokenizer_ToBuffer(void* buffer,

va_list args;
va_start(args, types);
#if PW_CXX_STANDARD_IS_SUPPORTED(17)
const size_t encoded_bytes = EncodeArgs(
types,
args,
span<std::byte>(static_cast<std::byte*>(buffer) + sizeof(token),
*buffer_size_bytes - sizeof(token)));
#else
const size_t encoded_bytes =
pw_tokenizer_EncodeArgs(types,
args,
static_cast<std::byte*>(buffer) + sizeof(token),
*buffer_size_bytes - sizeof(token));
#endif // PW_CXX_STANDARD_IS_SUPPORTED(17)
va_end(args);

*buffer_size_bytes = sizeof(token) + encoded_bytes;
}

} // namespace tokenizer
} // namespace pw
} // namespace pw::tokenizer

0 comments on commit 52eee72

Please sign in to comment.