diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-07-07 11:14:38 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-07-07 11:14:38 +0100 |
commit | 3cc1221f7643e749c6076046727a33096171a1ac (patch) | |
tree | 11aff39e3016d2b3d1eaae1b5002c2bb4631a714 | |
parent | Apply previous fixes for classes to structs too (diff) | |
download | slicer-1.10.2.tar.bz2 slicer-1.10.2.tar.xz slicer-1.10.2.zip |
Apply previous fixes to enums tooslicer-1.10.2
Includes change to method of finding in-use types.
Allows removal of dirty clang link fix.
-rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 8 | ||||
-rw-r--r-- | slicer/tool/parser.cpp | 64 |
2 files changed, 60 insertions, 12 deletions
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index ca562a6..b821d06 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -13,12 +13,6 @@ #include <boost/multi_index_container.hpp> #include <c++11Helpers.h> -#ifdef __clang__ -# define FINALVISMODELPARTS DLL_PUBLIC -#else -# define FINALVISMODELPARTS -#endif - #define CUSTOMMODELPARTFOR(Type, BaseModelPart, ModelPartType) \ template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor<Type>() \ { \ @@ -56,7 +50,7 @@ { \ return CreateRootFor(const_cast<Ice::optional<Type> &>(s)); \ } \ - template class FINALVISMODELPARTS BaseModelPart; \ + template class BaseModelPart; \ template class ModelPartForRoot<Type>; \ template class ModelPartForRoot<Ice::optional<Type>>; diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 3d0505a..33f003b 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -14,17 +14,60 @@ namespace fs = std::filesystem; namespace Slicer { + class Count : public Slice::ParserVisitor { + public: + bool + visitClassDefStart(const Slice::ClassDefPtr &) override + { + classes += 1; + return true; + } + bool + visitStructStart(const Slice::StructPtr &) override + { + structs += 1; + return true; + } + void + visitEnum(const Slice::EnumPtr &) override + { + enums += 1; + } + + unsigned int classes {0}; + unsigned int structs {0}; + unsigned int enums {0}; + }; + class ForwardDeclare : public Slice::ParserVisitor { public: - ForwardDeclare(FILE * c) : cpp(c) { } + ForwardDeclare(FILE * c, const Count & cnt) : cpp(c), count(cnt) { } + bool - visitModuleStart(const Slice::ModulePtr & m) override + visitUnitStart(const Slice::UnitPtr &) override { - fprintbf(cpp, "namespace %s {\n", m->name()); + if (count.enums) { + fprintbf(cpp, "#ifdef ICE_CPP11_MAPPING // C++11 mapping\n"); + fprintbf( + cpp, "#define FORWARD_ENUM(name) enum class ICE_CLASS(JAM_DLL_PUBLIC) name : unsigned char;\n"); + fprintbf(cpp, "#else // C++98 mapping\n"); + fprintbf(cpp, "#define FORWARD_ENUM(name) enum ICE_CLASS(JAM_DLL_PUBLIC) name;\n"); + fprintbf(cpp, "#endif\n\n"); + } return true; } bool + visitModuleStart(const Slice::ModulePtr & m) override + { + if (count.classes || count.structs || count.enums) { + fprintbf(cpp, "namespace %s {\n", m->name()); + return true; + } + return false; + } + + bool visitClassDefStart(const Slice::ClassDefPtr & c) override { fprintbf(cpp, "class ICE_CLASS(JAM_DLL_PUBLIC) %s;\n", c->name()); @@ -39,12 +82,21 @@ namespace Slicer { }; void + visitEnum(const Slice::EnumPtr & e) override + { + fprintbf(cpp, "FORWARD_ENUM(%s);\n", e->name()); + }; + + void visitModuleEnd(const Slice::ModulePtr & m) override { - fprintbf(cpp, "} // %s\n\n", m->name()); + if (count.classes || count.structs || count.enums) { + fprintbf(cpp, "} // %s\n\n", m->name()); + } } FILE * cpp; + const Count & count; }; template<typename TPtr> @@ -136,7 +188,9 @@ namespace Slicer { fprintbf(cpp, "// Begin Slicer code\n\n"); fprintbf(cpp, "#include <%s>\n\n", (headerPrefix / "modelPartsTypes.impl.h").string()); - ForwardDeclare fd {cpp}; + Count count; + u->visit(&count, true); + ForwardDeclare fd {cpp, count}; u->visit(&fd, true); fprintbf(cpp, "#include <%s>\n", fs::path(topLevelFile.filename()).replace_extension(".h").string()); |