From a148b923762712c6f724acf7fdec1fa18d221a6a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 6 Oct 2021 00:58:16 +0100 Subject: Add stub header for all header only files, fix up most IWYU errors Errors disabled for generated code as some of it isn't generated in slicer --- slicer/db/Jamfile.jam | 2 + slicer/slicer/enumMap.cpp | 1 + slicer/slicer/enumMap.h | 1 + slicer/slicer/hook-test.cpp | 1 - slicer/slicer/metadata.cpp | 1 + slicer/slicer/metadata.h | 2 + slicer/slicer/modelPartsTraits.cpp | 1 + slicer/slicer/modelPartsTraits.h | 4 ++ slicer/slicer/modelPartsTypes.impl.cpp | 1 + slicer/slicer/modelPartsTypes.impl.h | 24 ++++++- slicer/test/Jamfile.jam | 2 + slicer/test/types.ice | 4 +- slicer/tool/parser.cpp | 114 ++++++++++++++++++++++++++------- 13 files changed, 128 insertions(+), 30 deletions(-) create mode 100644 slicer/slicer/enumMap.cpp create mode 100644 slicer/slicer/metadata.cpp create mode 100644 slicer/slicer/modelPartsTraits.cpp create mode 100644 slicer/slicer/modelPartsTypes.impl.cpp diff --git a/slicer/db/Jamfile.jam b/slicer/db/Jamfile.jam index 7a5de7e..bc43dcb 100644 --- a/slicer/db/Jamfile.jam +++ b/slicer/db/Jamfile.jam @@ -47,6 +47,8 @@ lib testCommon : ..//adhocutil dbicetypes dbicetypes + -debug\:on + tidy:off gcc:../tool//slicer/gcc clang:../tool//slicer/clang tidy:../tool//slicer/gcc diff --git a/slicer/slicer/enumMap.cpp b/slicer/slicer/enumMap.cpp new file mode 100644 index 0000000..8d6b96a --- /dev/null +++ b/slicer/slicer/enumMap.cpp @@ -0,0 +1 @@ +#include "enumMap.h" diff --git a/slicer/slicer/enumMap.h b/slicer/slicer/enumMap.h index 72c1511..4c50bd8 100644 --- a/slicer/slicer/enumMap.h +++ b/slicer/slicer/enumMap.h @@ -2,6 +2,7 @@ #define SLICER_ENUM_MAP_H #include +#include #include #include diff --git a/slicer/slicer/hook-test.cpp b/slicer/slicer/hook-test.cpp index b5b0701..3af28b4 100644 --- a/slicer/slicer/hook-test.cpp +++ b/slicer/slicer/hook-test.cpp @@ -5,7 +5,6 @@ #include #include #include -#include namespace test { struct S { diff --git a/slicer/slicer/metadata.cpp b/slicer/slicer/metadata.cpp new file mode 100644 index 0000000..f5a1b66 --- /dev/null +++ b/slicer/slicer/metadata.cpp @@ -0,0 +1 @@ +#include "metadata.h" diff --git a/slicer/slicer/metadata.h b/slicer/slicer/metadata.h index 455507a..8aa65c9 100644 --- a/slicer/slicer/metadata.h +++ b/slicer/slicer/metadata.h @@ -2,9 +2,11 @@ #define SLICER_METADATA_H #include +#include #include #include #include +#include #include #include diff --git a/slicer/slicer/modelPartsTraits.cpp b/slicer/slicer/modelPartsTraits.cpp new file mode 100644 index 0000000..ca770cd --- /dev/null +++ b/slicer/slicer/modelPartsTraits.cpp @@ -0,0 +1 @@ +#include "modelPartsTraits.h" diff --git a/slicer/slicer/modelPartsTraits.h b/slicer/slicer/modelPartsTraits.h index 6213c9c..6b88a57 100644 --- a/slicer/slicer/modelPartsTraits.h +++ b/slicer/slicer/modelPartsTraits.h @@ -2,7 +2,11 @@ #define SLICER_MODELPARTSTRAITS_H #include +#include #include +#include +#include +#include namespace Slicer { // Function traits helpers diff --git a/slicer/slicer/modelPartsTypes.impl.cpp b/slicer/slicer/modelPartsTypes.impl.cpp new file mode 100644 index 0000000..639f718 --- /dev/null +++ b/slicer/slicer/modelPartsTypes.impl.cpp @@ -0,0 +1 @@ +#include "modelPartsTypes.impl.h" diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index ef07248..5423152 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -2,14 +2,34 @@ #define SLICER_MODELPARTSTYPES_IMPL_H #include "common.h" -#include "enumMap.h" +#include "enumMap.h" // IWYU pragma: keep #include "hookMap.h" +#include "metadata.h" +#include "modelParts.h" #include "modelPartsTraits.h" #include "modelPartsTypes.h" +#include +#include +#include +#include #include -#include +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// IWYU pragma: no_forward_declare Slicer::EnumMap +namespace Ice { + class Object; +} #define CUSTOMMODELPARTFOR(Type, BaseModelPart, ModelPartType) \ template<> DLL_PUBLIC ModelPartPtr ModelPart::Make(typename ModelPartType::element_type * t) \ diff --git a/slicer/test/Jamfile.jam b/slicer/test/Jamfile.jam index 6f27f92..1682b58 100644 --- a/slicer/test/Jamfile.jam +++ b/slicer/test/Jamfile.jam @@ -29,6 +29,8 @@ lib types : gcc:../tool//slicer/gcc clang:../tool//slicer/clang tidy:../tool//slicer/gcc + -debug\:on + tidy:off . ..//adhocutil boost_date_time diff --git a/slicer/test/types.ice b/slicer/test/types.ice index ac3a706..5a8fcba 100644 --- a/slicer/test/types.ice +++ b/slicer/test/types.ice @@ -1,9 +1,7 @@ #ifndef SLICER_TEST_TYPES #define SLICER_TEST_TYPES -[["cpp:include:boost/date_time/posix_time/posix_time_types.hpp"]] -[["cpp:include:boost/date_time/posix_time/time_formatters.hpp"]] -[["cpp:include:boost/date_time/posix_time/time_parsers.hpp"]] +[["cpp:include:boost/date_time/posix_time/posix_time.hpp"]] #include #include diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index d0bf601..ec94a43 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -39,29 +39,65 @@ namespace fs = std::filesystem; namespace Slicer { + template + bool + ignoreType(const TPtr & t) + { + return (!t || t->hasMetaData("slicer:ignore")); + } + class Count : public Slice::ParserVisitor { public: - bool - visitClassDefStart(const Slice::ClassDefPtr &) override + [[nodiscard]] bool + visitClassDefStart(const Slice::ClassDefPtr & c) override { - classes += 1; - return true; + return countIfUsed(c, classes, !c->isInterface()); } - bool - visitStructStart(const Slice::StructPtr &) override + [[nodiscard]] bool + visitStructStart(const Slice::StructPtr & s) override { - structs += 1; - return true; + return countIfUsed(s, structs); + } + void + visitSequence(const Slice::SequencePtr & s) override + { + countIfUsed(s, sequences); } void - visitEnum(const Slice::EnumPtr &) override + visitDictionary(const Slice::DictionaryPtr & d) override { - enums += 1; + countIfUsed(d, dictionaries); + } + void + visitEnum(const Slice::EnumPtr & e) override + { + countIfUsed(e, enums); + } + [[nodiscard]] auto + complexes() const + { + return classes + structs; } unsigned int classes {0}; unsigned int structs {0}; unsigned int enums {0}; + unsigned int sequences {0}; + unsigned int dictionaries {0}; + unsigned int total {0}; + + private: + template + bool + countIfUsed(const TPtr & t, auto & counter, bool condition = true) + { + if (!condition || ignoreType(t)) { + return false; + } + counter += 1; + total += 1; + return true; + } }; class ForwardDeclare : public Slice::ParserVisitor { @@ -82,14 +118,14 @@ namespace Slicer { bool visitClassDefStart(const Slice::ClassDefPtr & c) override { - fprintbf(cpp, "class ICE_CLASS(JAM_DLL_PUBLIC) %s;\n", c->name()); + fprintbf(cpp, "class ICE_CLASS(JAM_DLL_PUBLIC) %s; // IWYU pragma: keep\n", c->name()); return false; }; bool visitStructStart(const Slice::StructPtr & s) override { - fprintbf(cpp, "struct ICE_CLASS(JAM_DLL_PUBLIC) %s;\n", s->name()); + fprintbf(cpp, "struct ICE_CLASS(JAM_DLL_PUBLIC) %s; // IWYU pragma: keep\n", s->name()); return false; }; @@ -128,13 +164,6 @@ namespace Slicer { return o; } - template - bool - ignoreType(const TPtr & t) - { - return (!t || t->hasMetaData("slicer:ignore")); - } - Slicer::Slicer() : cpp(nullptr), headerPrefix("slicer"), components(0), classNo(0) { } void @@ -221,20 +250,57 @@ namespace Slicer { if (!cpp) { return true; } - - fprintbf(cpp, "// Begin Slicer code\n\n"); - fprintbf(cpp, "#include <%s>\n\n", (headerPrefix / "modelPartsTypes.impl.h").string()); + auto include = [this](const auto & h, bool keep = false) { + fprintbf(cpp, "#include <%s>", h); + if (keep) { + fputs(" // IWYU pragma: keep", cpp); + } + fputs("\n", cpp); + }; Count count; u->visit(&count, true); + + if (count.total == 0) { + return false; + } + + fprintbf(cpp, "// Begin Slicer code\n\n"); + include((headerPrefix / "modelPartsTypes.impl.h").string()); + include((headerPrefix / "modelPartsTypes.h").string()); + include((headerPrefix / "modelParts.h").string()); + include((headerPrefix / "hookMap.h").string()); + include((headerPrefix / "metadata.h").string(), true); + + include("array"); + include("optional"); + include("string"); + include("string_view"); + include("visibility.h"); + if (count.classes) { + include("memory", true); + include("boost/assert.hpp", true); + include("Ice/Config.h", true); + } + if (count.enums) { + include((headerPrefix / "enumMap.h").string()); + } + include("Ice/Optional.h"); + if (count.complexes() || count.dictionaries) { + include("IceUtil/Config.h"); + } + if (count.dictionaries) { + include("map", true); + include("utility", true); + } ForwardDeclare fd {cpp, count}; u->visit(&fd, true); - fprintbf(cpp, "#include <%s>\n", fs::path {topLevelFile.filename()}.replace_extension(".h").string()); + include(fs::path {topLevelFile.filename()}.replace_extension(".h").string()); for (const auto & m : u->modules()) { IceMetaData md {m->getMetaData()}; for (const auto & i : md.values("slicer:include:")) { - fprintbf(cpp, "#include <%s>\n", i); + include(i); } } fprintbf(cpp, "\n"); -- cgit v1.2.3