From 9944db6d736160d5bf571794d1b9c6f5556efeba Mon Sep 17 00:00:00 2001 From: John Keiser Date: Tue, 2 Mar 2021 18:27:16 -0800 Subject: [PATCH] Move json_type to ondemand to prevent target mismatch inline errors --- include/simdjson.h | 2 -- include/simdjson/generic/ondemand-inl.h | 1 + include/simdjson/generic/ondemand.h | 1 + .../simdjson/generic/ondemand/document-inl.h | 2 +- include/simdjson/generic/ondemand/document.h | 2 +- .../simdjson/generic/ondemand/json_type-inl.h | 35 +++++++++++++++++++ .../{ => generic/ondemand}/json_type.h | 22 ++++++++---- include/simdjson/generic/ondemand/value-inl.h | 2 +- include/simdjson/generic/ondemand/value.h | 2 +- include/simdjson/json_type-inl.h | 29 --------------- tests/ondemand/ondemand_array_tests.cpp | 1 + tests/ondemand/ondemand_object_tests.cpp | 1 + tests/ondemand/ondemand_scalar_tests.cpp | 2 ++ 13 files changed, 61 insertions(+), 41 deletions(-) create mode 100644 include/simdjson/generic/ondemand/json_type-inl.h rename include/simdjson/{ => generic/ondemand}/json_type.h (61%) delete mode 100644 include/simdjson/json_type-inl.h diff --git a/include/simdjson.h b/include/simdjson.h index 3d94962b..a1a9426a 100644 --- a/include/simdjson.h +++ b/include/simdjson.h @@ -43,14 +43,12 @@ SIMDJSON_DISABLE_UNDESIRED_WARNINGS // Public API #include "simdjson/simdjson_version.h" #include "simdjson/error.h" -#include "simdjson/json_type.h" #include "simdjson/minify.h" #include "simdjson/padded_string.h" #include "simdjson/implementation.h" // Inline functions #include "simdjson/error-inl.h" -#include "simdjson/json_type-inl.h" #include "simdjson/padded_string-inl.h" // DOM diff --git a/include/simdjson/generic/ondemand-inl.h b/include/simdjson/generic/ondemand-inl.h index 38ca933d..814b97f6 100644 --- a/include/simdjson/generic/ondemand-inl.h +++ b/include/simdjson/generic/ondemand-inl.h @@ -1,3 +1,4 @@ +#include "simdjson/generic/ondemand/json_type-inl.h" #include "simdjson/generic/ondemand/logger-inl.h" #include "simdjson/generic/ondemand/raw_json_string-inl.h" #include "simdjson/generic/ondemand/token_iterator-inl.h" diff --git a/include/simdjson/generic/ondemand.h b/include/simdjson/generic/ondemand.h index 0aede0ed..8ed29e0a 100644 --- a/include/simdjson/generic/ondemand.h +++ b/include/simdjson/generic/ondemand.h @@ -14,6 +14,7 @@ using depth_t = int32_t; } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson +#include "simdjson/generic/ondemand/json_type.h" #include "simdjson/generic/ondemand/token_position.h" #include "simdjson/generic/ondemand/logger.h" #include "simdjson/generic/ondemand/raw_json_string.h" diff --git a/include/simdjson/generic/ondemand/document-inl.h b/include/simdjson/generic/ondemand/document-inl.h index 271551b9..d584c35a 100644 --- a/include/simdjson/generic/ondemand/document-inl.h +++ b/include/simdjson/generic/ondemand/document-inl.h @@ -243,7 +243,7 @@ template<> simdjson_really_inline error_code simdjson_result simdjson_result::type() noexcept { +simdjson_really_inline simdjson_result simdjson_result::type() noexcept { if (error()) { return error(); } return first.type(); } diff --git a/include/simdjson/generic/ondemand/document.h b/include/simdjson/generic/ondemand/document.h index 5943247e..5f671a81 100644 --- a/include/simdjson/generic/ondemand/document.h +++ b/include/simdjson/generic/ondemand/document.h @@ -349,7 +349,7 @@ public: simdjson_really_inline simdjson_result find_field_unordered(std::string_view key) & noexcept; simdjson_really_inline simdjson_result find_field_unordered(const char *key) & noexcept; - simdjson_really_inline simdjson_result type() noexcept; + simdjson_really_inline simdjson_result type() noexcept; }; } // namespace simdjson diff --git a/include/simdjson/generic/ondemand/json_type-inl.h b/include/simdjson/generic/ondemand/json_type-inl.h new file mode 100644 index 00000000..f1dca11a --- /dev/null +++ b/include/simdjson/generic/ondemand/json_type-inl.h @@ -0,0 +1,35 @@ +namespace simdjson { +namespace SIMDJSON_IMPLEMENTATION { +namespace ondemand { + +inline std::ostream& operator<<(std::ostream& out, json_type type) noexcept { + switch (type) { + case json_type::array: out << "array"; break; + case json_type::object: out << "object"; break; + case json_type::number: out << "number"; break; + case json_type::string: out << "string"; break; + case json_type::boolean: out << "boolean"; break; + case json_type::null: out << "null"; break; + default: SIMDJSON_UNREACHABLE(); + } + return out; +} + +#if SIMDJSON_EXCEPTIONS +inline std::ostream& operator<<(std::ostream& out, simdjson_result &type) noexcept(false) { + return out << type.value(); +} +#endif + +} // namespace ondemand +} // namespace SIMDJSON_IMPLEMENTATION +} // namespace simdjson + +namespace simdjson { + +simdjson_really_inline simdjson_result::simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::json_type &&value) noexcept + : implementation_simdjson_result_base(std::forward(value)) {} +simdjson_really_inline simdjson_result::simdjson_result(error_code error) noexcept + : implementation_simdjson_result_base(error) {} + +} // namespace simdjson diff --git a/include/simdjson/json_type.h b/include/simdjson/generic/ondemand/json_type.h similarity index 61% rename from include/simdjson/json_type.h rename to include/simdjson/generic/ondemand/json_type.h index 2c1bbd57..0d2e9fff 100644 --- a/include/simdjson/json_type.h +++ b/include/simdjson/generic/ondemand/json_type.h @@ -1,9 +1,6 @@ -#ifndef SIMDJSON_JSON_TYPE_H -#define SIMDJSON_JSON_TYPE_H - -#include "simdjson/common_defs.h" - namespace simdjson { +namespace SIMDJSON_IMPLEMENTATION { +namespace ondemand { /** * The type of a JSON value. @@ -39,6 +36,19 @@ inline std::ostream& operator<<(std::ostream& out, json_type type) noexcept; inline std::ostream& operator<<(std::ostream& out, simdjson_result &type) noexcept(false); #endif +} // namespace ondemand +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -#endif // SIMDJSON_JSON_TYPE_H +namespace simdjson { + +template<> +struct simdjson_result : public SIMDJSON_IMPLEMENTATION::implementation_simdjson_result_base { +public: + simdjson_really_inline simdjson_result(SIMDJSON_IMPLEMENTATION::ondemand::json_type &&value) noexcept; ///< @private + simdjson_really_inline simdjson_result(error_code error) noexcept; ///< @private + simdjson_really_inline simdjson_result() noexcept = default; + simdjson_really_inline ~simdjson_result() noexcept = default; ///< @private +}; + +} // namespace simdjson diff --git a/include/simdjson/generic/ondemand/value-inl.h b/include/simdjson/generic/ondemand/value-inl.h index 16764ce6..60ba9038 100644 --- a/include/simdjson/generic/ondemand/value-inl.h +++ b/include/simdjson/generic/ondemand/value-inl.h @@ -234,7 +234,7 @@ template<> simdjson_really_inline error_code simdjson_result simdjson_result::type() noexcept { +simdjson_really_inline simdjson_result simdjson_result::type() noexcept { if (error()) { return error(); } return first.type(); } diff --git a/include/simdjson/generic/ondemand/value.h b/include/simdjson/generic/ondemand/value.h index c5877b1e..41bb7c47 100644 --- a/include/simdjson/generic/ondemand/value.h +++ b/include/simdjson/generic/ondemand/value.h @@ -413,7 +413,7 @@ public: * better to just call .get_double, .get_string, etc. and check for INCORRECT_TYPE (or just * let it throw an exception). */ - simdjson_really_inline simdjson_result type() noexcept; + simdjson_really_inline simdjson_result type() noexcept; }; } // namespace simdjson diff --git a/include/simdjson/json_type-inl.h b/include/simdjson/json_type-inl.h deleted file mode 100644 index 20363707..00000000 --- a/include/simdjson/json_type-inl.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef SIMDJSON_JSON_TYPE_INL_H -#define SIMDJSON_JSON_TYPE_INL_H - -#include "simdjson/json_type.h" - -namespace simdjson { - -inline std::ostream& operator<<(std::ostream& out, json_type type) noexcept { - switch (type) { - case json_type::array: out << "array"; break; - case json_type::object: out << "object"; break; - case json_type::number: out << "number"; break; - case json_type::string: out << "string"; break; - case json_type::boolean: out << "boolean"; break; - case json_type::null: out << "null"; break; - default: SIMDJSON_UNREACHABLE(); - } - return out; -} - -#if SIMDJSON_EXCEPTIONS -inline std::ostream& operator<<(std::ostream& out, simdjson_result &type) noexcept(false) { - return out << type.value(); -} -#endif - -} // namespace simdjson - -#endif // SIMDJSON_JSON_TYPE_INL_H diff --git a/tests/ondemand/ondemand_array_tests.cpp b/tests/ondemand/ondemand_array_tests.cpp index 245d5411..d09fc85f 100644 --- a/tests/ondemand/ondemand_array_tests.cpp +++ b/tests/ondemand/ondemand_array_tests.cpp @@ -5,6 +5,7 @@ using namespace simdjson; namespace array_tests { using namespace std; + using simdjson::ondemand::json_type; bool iterate_document_array() { TEST_START(); diff --git a/tests/ondemand/ondemand_object_tests.cpp b/tests/ondemand/ondemand_object_tests.cpp index 4d1c448d..b0b73e0c 100644 --- a/tests/ondemand/ondemand_object_tests.cpp +++ b/tests/ondemand/ondemand_object_tests.cpp @@ -5,6 +5,7 @@ using namespace simdjson; namespace object_tests { using namespace std; + using simdjson::ondemand::json_type; bool iterate_object() { TEST_START(); diff --git a/tests/ondemand/ondemand_scalar_tests.cpp b/tests/ondemand/ondemand_scalar_tests.cpp index 5e2bb4ab..8bc188e2 100644 --- a/tests/ondemand/ondemand_scalar_tests.cpp +++ b/tests/ondemand/ondemand_scalar_tests.cpp @@ -5,6 +5,8 @@ using namespace simdjson; namespace scalar_tests { using namespace std; + using simdjson::ondemand::json_type; + template json_type expected_json_type(); template<> json_type expected_json_type() { return json_type::string; } template<> json_type expected_json_type() { return json_type::number; }