diff options
-rw-r--r-- | Jamroot.jam | 2 | ||||
-rw-r--r-- | slicer/slicer/enum-test.cpp | 36 | ||||
-rw-r--r-- | slicer/slicer/enumMap.h | 8 | ||||
-rw-r--r-- | slicer/slicer/hook-test.cpp | 93 | ||||
-rw-r--r-- | slicer/slicer/hookMap.h | 29 | ||||
-rw-r--r-- | slicer/slicer/metadata-test.cpp | 26 | ||||
-rw-r--r-- | slicer/slicer/metadata.h | 17 | ||||
-rw-r--r-- | slicer/slicer/modelParts.h | 2 | ||||
-rw-r--r-- | slicer/tool/icemetadata.cpp | 1 | ||||
-rw-r--r-- | slicer/tool/icemetadata.h | 11 | ||||
-rw-r--r-- | slicer/tool/parser.cpp | 5 | ||||
-rw-r--r-- | slicer/tool/parser.h | 7 |
12 files changed, 124 insertions, 113 deletions
diff --git a/Jamroot.jam b/Jamroot.jam index b878832..292cefc 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -28,11 +28,13 @@ project <toolset>tidy:<xcheckxx>clang-analyzer-cplusplus.NewDeleteLeaks <toolset>tidy:<checkxx>misc-* <toolset>tidy:<xcheckxx>misc-non-private-member-variables-in-classes + <toolset>tidy:<xcheckxx>misc-no-recursion <toolset>tidy:<checkxx>modernize-* <toolset>tidy:<xcheckxx>modernize-use-trailing-return-type <toolset>tidy:<checkxx>hicpp-* <toolset>tidy:<xcheckxx>hicpp-no-array-decay <toolset>tidy:<xcheckxx>hicpp-vararg + <toolset>tidy:<xcheckxx>hicpp-named-parameter <toolset>tidy:<checkxx>performance-* <toolset>tidy:<exclude>test/bin/tidy/debug/checker-none/cxxstd-17-iso/classes.h <toolset>tidy:<exclude>test/bin/tidy/debug/checker-none/cxxstd-17-iso/classtype.h diff --git a/slicer/slicer/enum-test.cpp b/slicer/slicer/enum-test.cpp index 166804f..43e191a 100644 --- a/slicer/slicer/enum-test.cpp +++ b/slicer/slicer/enum-test.cpp @@ -1,22 +1,24 @@ #include "enumMap.h" -enum class Es { one, two, three }; -const std::string one {"one"}, two {"two"}, three {"three"}; +namespace test { + enum class Es { one, two, three }; + const std::string one {"one"}, two {"two"}, three {"three"}; -constexpr Slicer::EnumMapImpl<Es, 3> em {{{ - {Es::one, "one", &one}, - {Es::two, "two", &two}, - {Es::three, "three", &three}, -}}}; + constexpr Slicer::EnumMapImpl<Es, 3> em {{{ + {Es::one, "one", &one}, + {Es::two, "two", &two}, + {Es::three, "three", &three}, + }}}; -static_assert(em.arr.size() == 3); -static_assert(em.arr[0].value == Es::one); -static_assert(em.arr[1].name == "two"); -static_assert(em.arr[1].nameStr == &two); -static_assert(em.arr[2].value == Es::three); + static_assert(em.arr.size() == 3); + static_assert(em.arr[0].value == Es::one); + static_assert(em.arr[1].name == "two"); + static_assert(em.arr[1].nameStr == &two); + static_assert(em.arr[2].value == Es::three); -static_assert(em.find<Slicer::EnumMapKey::Name>("one")->value == Es::one); -static_assert(em.find<Slicer::EnumMapKey::Name>("three")->value == Es::three); -static_assert(em.find<Slicer::EnumMapKey::Value>(Es::one)->name == "one"); -static_assert(em.find<Slicer::EnumMapKey::Value>(Es::three)->name == "three"); -static_assert(!em.find<Slicer::EnumMapKey::Name>("four")); + static_assert(em.find<Slicer::EnumMapKey::Name>("one")->value == Es::one); + static_assert(em.find<Slicer::EnumMapKey::Name>("three")->value == Es::three); + static_assert(em.find<Slicer::EnumMapKey::Value>(Es::one)->name == "one"); + static_assert(em.find<Slicer::EnumMapKey::Value>(Es::three)->name == "three"); + static_assert(!em.find<Slicer::EnumMapKey::Name>("four")); +} diff --git a/slicer/slicer/enumMap.h b/slicer/slicer/enumMap.h index a6f941d..8f63819 100644 --- a/slicer/slicer/enumMap.h +++ b/slicer/slicer/enumMap.h @@ -14,9 +14,9 @@ namespace Slicer { template<typename E> class EnumMap { public: struct Node { - E value; - std::string_view name; - const std::string * nameStr; + E value {}; + std::string_view name {}; + const std::string * nameStr {}; }; template<EnumMapKey Key, typename T> @@ -48,7 +48,7 @@ namespace Slicer { using NodeType = typename EnumMap<E>::Node; template<std::size_t n> using Arr = std::array<NodeType, n>; - inline constexpr EnumMapImpl(Arr<N> a) : arr(std::move(a)) + inline constexpr explicit EnumMapImpl(Arr<N> a) : arr(std::move(a)) { EnumMap<E>::begin = arr.begin(); EnumMap<E>::end = arr.end(); diff --git a/slicer/slicer/hook-test.cpp b/slicer/slicer/hook-test.cpp index d478beb..abde1c5 100644 --- a/slicer/slicer/hook-test.cpp +++ b/slicer/slicer/hook-test.cpp @@ -3,53 +3,56 @@ #include <string> -struct S { - int aa; - int aA; - int Aa; - int AA; - std::string b; -}; -const std::string aa {"aa"}, aA {"aA"}, Aa {"Aa"}, AA {"AA"}, b {"b"}; +namespace test { + struct S { + S(); + int aa; + int aA; + int Aa; + int AA; + std::string b; + }; + const std::string aa {"aa"}, aA {"aA"}, Aa {"Aa"}, AA {"AA"}, b {"b"}; -using C = Slicer::ModelPartForComplex<S>; -constexpr C::Hook<int, Slicer::ModelPartForSimple<int>, 0> haa {&S::aa, "aa", "aa", &aa}; -constexpr C::Hook<int, Slicer::ModelPartForSimple<int>, 1> haA {&S::aA, "aA", "aa", &aA, "md1"}; -constexpr C::Hook<int, Slicer::ModelPartForSimple<int>, 3> hAa {&S::Aa, "Aa", "aa", &Aa, "md2", "md3", "md4"}; -constexpr C::Hook<int, Slicer::ModelPartForSimple<int>> hAA {&S::AA, "AA", "aa", &AA}; -constexpr C::Hook<std::string, Slicer::ModelPartForSimple<std::string>, 0> hb {&S::b, "b", "b", &b}; -constexpr Slicer::HooksImpl<S, 5> h {{{&haa, &haA, &hAa, &hAA, &hb}}}; + using C = Slicer::ModelPartForComplex<S>; + constexpr C::Hook<int, Slicer::ModelPartForSimple<int>, 0> haa {&S::aa, "aa", "aa", &aa}; + constexpr C::Hook<int, Slicer::ModelPartForSimple<int>, 1> haA {&S::aA, "aA", "aa", &aA, "md1"}; + constexpr C::Hook<int, Slicer::ModelPartForSimple<int>, 3> hAa {&S::Aa, "Aa", "aa", &Aa, "md2", "md3", "md4"}; + constexpr C::Hook<int, Slicer::ModelPartForSimple<int>> hAA {&S::AA, "AA", "aa", &AA}; + constexpr C::Hook<std::string, Slicer::ModelPartForSimple<std::string>, 0> hb {&S::b, "b", "b", &b}; + constexpr Slicer::HooksImpl<S, 5> h {{{&haa, &haA, &hAa, &hAA, &hb}}}; -static_assert(h.arr.size() == 5); -static_assert(h.arr[0]->name == "aa"); -static_assert(h.arr[0]->nameLower == "aa"); -static_assert(h.arr[0]->nameStr == &aa); -static_assert(h.arr[1]->name == "aA"); -static_assert(h.arr[1]->nameLower == "aa"); -static_assert(h.arr[1]->nameStr == &aA); -static_assert(h.arr[4]->name == "b"); -static_assert(h.arr[4]->nameLower == "b"); -static_assert(h.arr[4]->nameStr == &b); + static_assert(h.arr.size() == 5); + static_assert(h.arr[0]->name == "aa"); + static_assert(h.arr[0]->nameLower == "aa"); + static_assert(h.arr[0]->nameStr == &aa); + static_assert(h.arr[1]->name == "aA"); + static_assert(h.arr[1]->nameLower == "aa"); + static_assert(h.arr[1]->nameStr == &aA); + static_assert(h.arr[4]->name == "b"); + static_assert(h.arr[4]->nameLower == "b"); + static_assert(h.arr[4]->nameStr == &b); -constexpr auto aas = h.equal_range("aa"); -constexpr auto bbs = h.equal_range("bb"); -static_assert(aas.begin() != aas.end()); -static_assert(bbs.begin() == bbs.end()); -static_assert(aas.begin()->name == "aa"); + constexpr auto aas = h.equal_range("aa"); + constexpr auto bbs = h.equal_range("bb"); + static_assert(aas.begin() != aas.end()); + static_assert(bbs.begin() == bbs.end()); + static_assert(aas.begin()->name == "aa"); -constexpr auto aa0 = aas.begin(); -static_assert(aa0->name == "aa"); -constexpr auto aa1 = aa0 + 1; -static_assert(aa1 == aas.end()); -static_assert(std::distance(aas.begin(), aas.end()) == 1); -static_assert(std::distance(bbs.begin(), bbs.end()) == 0); + constexpr auto aa0 = aas.begin(); + static_assert(aa0->name == "aa"); + constexpr auto aa1 = aa0 + 1; + static_assert(aa1 == aas.end()); + static_assert(std::distance(aas.begin(), aas.end()) == 1); + static_assert(std::distance(bbs.begin(), bbs.end()) == 0); -constexpr auto laas = h.equal_range_lower("aa"); -constexpr auto lAAs = h.equal_range_lower("AA"); -static_assert(std::distance(laas.begin(), laas.end()) == 4); -static_assert(std::distance(lAAs.begin(), lAAs.end()) == 0); -static_assert(laas.begin()->name == "aa"); -static_assert((laas.begin() + 1)->name == "aA"); -static_assert((laas.begin() + 2)->name == "Aa"); -static_assert((laas.begin() + 3)->name == "AA"); -static_assert((laas.begin() + 4) == laas.end()); + constexpr auto laas = h.equal_range_lower("aa"); + constexpr auto lAAs = h.equal_range_lower("AA"); + static_assert(std::distance(laas.begin(), laas.end()) == 4); + static_assert(std::distance(lAAs.begin(), lAAs.end()) == 0); + static_assert(laas.begin()->name == "aa"); + static_assert((laas.begin() + 1)->name == "aA"); + static_assert((laas.begin() + 2)->name == "Aa"); + static_assert((laas.begin() + 3)->name == "AA"); + static_assert((laas.begin() + 4) == laas.end()); +} diff --git a/slicer/slicer/hookMap.h b/slicer/slicer/hookMap.h index 8eba5f5..a362a18 100644 --- a/slicer/slicer/hookMap.h +++ b/slicer/slicer/hookMap.h @@ -15,18 +15,18 @@ namespace Slicer { template<typename K> class iter : public std::iterator<std::bidirectional_iterator_tag, HookPtr> { public: - constexpr inline iter(const eq<K> * const r, const HookPtr * c) : range(r), cur(c) + [[nodiscard]] constexpr inline iter(const eq<K> * const r, const HookPtr * c) : range(r), cur(c) { moveMatch(); } - constexpr inline HookPtr + [[nodiscard]] constexpr inline HookPtr operator*() const { return *cur; } - constexpr inline HookPtr + [[nodiscard]] constexpr inline HookPtr operator->() const { return *cur; @@ -40,7 +40,7 @@ namespace Slicer { } } - constexpr inline iter + [[nodiscard]] constexpr inline iter operator+(std::size_t n) const { auto i {*this}; @@ -50,13 +50,13 @@ namespace Slicer { return i; } - constexpr inline bool + [[nodiscard]] constexpr inline bool operator!=(const iter & other) const { return cur != other.cur; } - constexpr inline bool + [[nodiscard]] constexpr inline bool operator==(const iter & other) const { return cur == other.cur; @@ -77,13 +77,13 @@ namespace Slicer { template<typename K> class eq { public: - constexpr inline iter<K> + [[nodiscard]] constexpr inline iter<K> begin() const { return {this, b}; } - constexpr inline iter<K> + [[nodiscard]] constexpr inline iter<K> end() const { return {this, e}; @@ -95,21 +95,21 @@ namespace Slicer { }; template<typename K> - constexpr inline eq<K> + [[nodiscard]] constexpr inline eq<K> equal_range(K && k) const { return {std::forward<K>(k), &HookCommon::name, _begin, _end}; } template<typename K> - constexpr inline eq<K> + [[nodiscard]] constexpr inline eq<K> equal_range_lower(K && k) const { return {std::forward<K>(k), &HookCommon::nameLower, _begin, _end}; } template<typename K> - inline auto + [[nodiscard]] inline auto equal_range_nocase(const K & k) const { std::string i {k}; @@ -117,12 +117,13 @@ namespace Slicer { return equal_range_lower(std::move(i)); } - constexpr inline auto + [[nodiscard]] constexpr inline auto begin() const { return _begin; } - constexpr inline auto + + [[nodiscard]] constexpr inline auto end() const { return _end; @@ -138,7 +139,7 @@ namespace Slicer { using HookPtr = typename Hooks<T>::HookPtr; template<std::size_t n> using Arr = std::array<HookPtr, n>; - inline constexpr HooksImpl(Arr<N> a) : arr(std::move(a)) + inline constexpr explicit HooksImpl(Arr<N> a) : arr(std::move(a)) { Hooks<T>::_begin = arr.begin(); Hooks<T>::_end = arr.end(); diff --git a/slicer/slicer/metadata-test.cpp b/slicer/slicer/metadata-test.cpp index 2d3215a..a2cd6ec 100644 --- a/slicer/slicer/metadata-test.cpp +++ b/slicer/slicer/metadata-test.cpp @@ -1,15 +1,17 @@ #include "metadata.h" -constexpr Slicer::MetaDataImpl<4> md {{{ - "slicer:yes", - "slicer:no", - "slicer:sub:scope", - "notslicer:dontcare", -}}}; +namespace test { + constexpr Slicer::MetaDataImpl<4> md {{{ + "slicer:yes", + "slicer:no", + "slicer:sub:scope", + "notslicer:dontcare", + }}}; -static_assert(md.flagSet("slicer:yes")); -static_assert(md.flagSet("slicer:no")); -static_assert(md.flagNotSet("slicer:chickens")); -static_assert(md.value("slicer:").has_value()); -static_assert(md.value("slicer:").value() == "yes"); -static_assert(!md.value("nope:").has_value()); + static_assert(md.flagSet("slicer:yes")); + static_assert(md.flagSet("slicer:no")); + static_assert(md.flagNotSet("slicer:chickens")); + static_assert(md.value("slicer:").has_value()); + static_assert(md.value("slicer:").value() == "yes"); + static_assert(!md.value("nope:").has_value()); +} diff --git a/slicer/slicer/metadata.h b/slicer/slicer/metadata.h index ced234f..5ca3781 100644 --- a/slicer/slicer/metadata.h +++ b/slicer/slicer/metadata.h @@ -16,20 +16,20 @@ namespace Slicer { constexpr MetaData() = default; // Flags - constexpr inline bool + [[nodiscard]] constexpr inline bool flagSet(std::string_view flag) const { return find(flag) != _end; } - constexpr inline bool + [[nodiscard]] constexpr inline bool flagNotSet(std::string_view flag) const { return find(flag) == _end; } // Values - constexpr std::optional<std::string_view> + [[nodiscard]] constexpr std::optional<std::string_view> value(std::string_view prefix) const { for (auto mditr = _begin; mditr != _end; mditr++) { @@ -41,7 +41,7 @@ namespace Slicer { return {}; } - std::vector<std::string_view> + [[nodiscard]] std::vector<std::string_view> values(std::string_view prefix) const { std::vector<std::string_view> mds; @@ -54,12 +54,13 @@ namespace Slicer { return mds; } - constexpr auto + [[nodiscard]] constexpr auto begin() const { return _begin; } - constexpr auto + + [[nodiscard]] constexpr auto end() const { return _end; @@ -69,7 +70,7 @@ namespace Slicer { Iter _begin {}; Iter _end {}; - constexpr Iter + [[nodiscard]] constexpr Iter find(Value v) const { for (auto mdptr = _begin; mdptr != _end; mdptr++) { @@ -84,7 +85,7 @@ namespace Slicer { template<std::size_t N> class DLL_PUBLIC MetaDataImpl : public MetaData<> { public: using Arr = std::array<Value, N>; - constexpr inline MetaDataImpl(Arr a) : arr(std::move(a)) + constexpr inline explicit MetaDataImpl(Arr a) : arr(std::move(a)) { _begin = arr.begin(); _end = arr.end(); diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 6af9344..6b283a4 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -112,7 +112,7 @@ namespace Slicer { { } - bool filter(const HookFilter & flt) const; + [[nodiscard]] bool filter(const HookFilter & flt) const; void apply(const ChildHandler & ch, const ModelPartPtr & modelPart) const; [[nodiscard]] virtual const Metadata & GetMetadata() const = 0; diff --git a/slicer/tool/icemetadata.cpp b/slicer/tool/icemetadata.cpp index 422b17e..60bd5a3 100644 --- a/slicer/tool/icemetadata.cpp +++ b/slicer/tool/icemetadata.cpp @@ -2,7 +2,6 @@ #include <boost/algorithm/string/predicate.hpp> namespace Slicer { - IceMetaData::IceMetaData() { } IceMetaData::IceMetaData(Slice::StringList && a) : arr {std::forward<Slice::StringList>(a)} { _begin = arr.begin(); diff --git a/slicer/tool/icemetadata.h b/slicer/tool/icemetadata.h index 90bfe5e..07d4db2 100644 --- a/slicer/tool/icemetadata.h +++ b/slicer/tool/icemetadata.h @@ -11,22 +11,23 @@ namespace Slicer { public: static constexpr std::string_view slicer_prefix {"slicer:"}; - explicit IceMetaData(); + explicit IceMetaData() = default; explicit IceMetaData(Slice::StringList && arr); + ~IceMetaData() = default; SPECIAL_MEMBERS_DELETE(IceMetaData); [[nodiscard]] static std::vector<std::string_view> split(std::string_view metaData); - bool hasSlicerMetaData() const; - size_t countSlicerMetaData() const; + [[nodiscard]] bool hasSlicerMetaData() const; + [[nodiscard]] size_t countSlicerMetaData() const; - constexpr bool static isSlicerMetaData(std::string_view md) + [[nodiscard]] constexpr bool static isSlicerMetaData(std::string_view md) { return md.substr(0, slicer_prefix.length()) == slicer_prefix; } - auto + [[nodiscard]] auto getSlicerMetaData() const { return values(slicer_prefix); diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 98a41e7..e1cc988 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -417,7 +417,7 @@ namespace Slicer { fprintbf(cpp, " %s, ", Slice::typeToString(type, dm->optional())); createNewModelPartPtrFor(type, dm, md); fprintbf(cpp, ", %d", md.countSlicerMetaData()); - fprintbf(cpp, " > hook_C%d_%s {&%s, \"%s\", \"%s\", &hstr_C%d_%s", components, name, dm->scoped(), name, + fprintbf(cpp, R"( > hook_C%d_%s {&%s, "%s", "%s", &hstr_C%d_%s)", components, name, dm->scoped(), name, lname, components, name); if (md.hasSlicerMetaData()) { fprintbf(cpp, ","); @@ -669,7 +669,8 @@ namespace Slicer { if (split.size() < 3) { throw CompilerError("conversion needs at least 3 parts type:toModelFunc:toExchangeFunc[:options]"); } - rtn.push_back(ConversionSpec {split[0], split[1], split[2], {&split[3], &split[split.size()]}}); + rtn.push_back(ConversionSpec { + CppName {split[0]}, CppName {split[1]}, CppName {split[2]}, {split.begin() + 3, split.end()}}); } return rtn; } diff --git a/slicer/tool/parser.h b/slicer/tool/parser.h index 7ba1b79..4335d1d 100644 --- a/slicer/tool/parser.h +++ b/slicer/tool/parser.h @@ -14,18 +14,17 @@ namespace Slicer { }; struct CppName : public SplitString { - inline CppName(std::string_view in) : SplitString {in, "."} { } + explicit inline CppName(std::string_view in) : SplitString {in, "."} { } }; class DLL_PUBLIC Slicer : public Slice::ParserVisitor { public: struct Args : public SplitString { - inline Args(std::string_view in) : SplitString {in, ","} { } + explicit inline Args(std::string_view in) : SplitString {in, ","} { } using SplitString::SplitString; }; - class ConversionSpec { - public: + struct ConversionSpec { CppName ExchangeType; CppName ConvertToModelFunc; CppName ConvertToExchangeFunc; |