summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2020-04-26 16:46:46 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2020-04-26 17:10:34 +0100
commit6b0cfee627c24a725863e9fbe07053b5557d5fee (patch)
tree22741854fff5e58005f2981fd8876588abc46a5a
parentPut library includes before client includes (diff)
downloadslicer-6b0cfee627c24a725863e9fbe07053b5557d5fee.tar.bz2
slicer-6b0cfee627c24a725863e9fbe07053b5557d5fee.tar.xz
slicer-6b0cfee627c24a725863e9fbe07053b5557d5fee.zip
Only explicitly instantiate modelparts
-rw-r--r--slicer/tool/parser.cpp19
-rw-r--r--slicer/tool/parser.h4
2 files changed, 21 insertions, 2 deletions
diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp
index 6ede17e..294dd7a 100644
--- a/slicer/tool/parser.cpp
+++ b/slicer/tool/parser.cpp
@@ -154,6 +154,15 @@ namespace Slicer {
type, name);
}
+ void
+ Slicer::externType(const Slice::TypePtr & type) const
+ {
+ if (definedTypes.count(type->typeId())) return;
+
+ fprintbf(cpp, "extern template class %s< %s >;\n",
+ getBasicModelPart(type), Slice::ClassDeclPtr::dynamicCast(type) ? type->typeId() : Slice::typeToString(type));
+ }
+
bool
Slicer::visitClassDefStart(const Slice::ClassDefPtr & c)
{
@@ -209,6 +218,7 @@ namespace Slicer {
fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, ModelPartForClass<%s>, ModelPartForClass<%s>);\n\n",
Slice::typeToString(decl), c->scoped(), c->scoped());
}
+ definedTypes.insert(decl->typeId());
classNo += 1;
@@ -245,6 +255,9 @@ namespace Slicer {
{
if (!cpp) { return; }
+ for (const auto & dm : dataMembers) {
+ externType(dm->type());
+ }
fprintbf(cpp, "using C%d = ModelPartForComplex< %s >;\n",
components, it->scoped());
fprintbf(cpp, "template<> DLL_PUBLIC\n");
@@ -328,6 +341,7 @@ namespace Slicer {
if (!cpp) { return; }
fprintbf(cpp, "// Sequence %s\n", s->name());
+ externType(s->type());
fprintbf(cpp, "template<> DLL_PUBLIC\n");
fprintbf(cpp, "ChildRef ModelPartForSequence< %s >::GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase)\n{\n",
s->scoped());
@@ -369,6 +383,8 @@ namespace Slicer {
if (!cpp) { return; }
fprintbf(cpp, "// Dictionary %s\n", d->name());
+ externType(d->keyType());
+ externType(d->valueType());
auto iname = metaDataValue("slicer:item:", d->getMetaData());
fprintbf(cpp, "template<> DLL_PUBLIC\n");
fprintbf(cpp, "const std::string ModelPartForDictionary< %s >::pairName(\"%s\");\n\n",
@@ -550,7 +566,7 @@ namespace Slicer {
}
void
- Slicer::defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata) const
+ Slicer::defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata)
{
fprintbf(cpp, "// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)\n");
if (auto cmp = metaDataValue("slicer:custommodelpart:", metadata)) {
@@ -561,6 +577,7 @@ namespace Slicer {
fprintbf(cpp, "MODELPARTFOR(%s, %s);\n\n",
type, getBasicModelPart(stype));
}
+ definedTypes.insert(stype->typeId());
}
unsigned int
diff --git a/slicer/tool/parser.h b/slicer/tool/parser.h
index 6b5ba8b..67aa243 100644
--- a/slicer/tool/parser.h
+++ b/slicer/tool/parser.h
@@ -63,17 +63,19 @@ namespace Slicer {
void createModelPartForConverted(const Slice::TypePtr & type, const std::string & container, const Slice::DataMemberPtr & dm) const;
void createNewModelPartPtrFor(const Slice::TypePtr & type, const Slice::DataMemberPtr & dm = Slice::DataMemberPtr(), const Slice::StringList & md = Slice::StringList()) const;
[[nodiscard]] std::string getBasicModelPart(const Slice::TypePtr & type) const;
- void defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata) const;
+ void defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata);
void visitComplexDataMembers(const Slice::ConstructedPtr & t, const Slice::DataMemberList &) const;
void defineConversions(const Slice::DataMemberPtr & dm) const;
void defineRoot(const std::string & type, const std::string & name, const Slice::TypePtr & stype) const;
+ void externType(const Slice::TypePtr &) const;
[[nodiscard]] bool hasMetadata(const std::list<std::string> & metadata) const;
void copyMetadata(const std::list<std::string> & metadata) const;
static Slice::StringList getAllMetadata(const Slice::DataMemberPtr & dm);
static Conversions getConversions(const Slice::StringList & metadata);
+ std::set<std::string> definedTypes;
#pragma GCC visibility pop
unsigned int components;