From d9072626f00098e89362e7a5ae0975a68d40107d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 16 Jul 2017 13:33:34 +0100 Subject: Add assertions in places where the model pointer is required to valid --- slicer/slicer/modelPartsTypes.impl.h | 25 +++++++++++++++++++++---- slicer/tool/parser.cpp | 2 ++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 6811de3..0ded2a2 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -140,12 +140,14 @@ namespace Slicer { template void ModelPartForSimple::SetValue(ValueSourcePtr s) { + BOOST_ASSERT(this->Model); s->set(*this->Model); } template void ModelPartForSimple::GetValue(ValueTargetPtr s) { + BOOST_ASSERT(this->Model); s->get(*this->Model); } @@ -161,6 +163,7 @@ namespace Slicer { ModelPartForOptional::ModelPartForOptional(IceUtil::Optional< typename T::element_type > * h) : ModelPartModel >(h) { + BOOST_ASSERT(this->Model); if (*this->Model) { modelPart = new T(&**this->Model); } @@ -169,12 +172,14 @@ namespace Slicer { template bool ModelPartForOptional::hasModel() const { + BOOST_ASSERT(this->Model); return *this->Model; } template void ModelPartForOptional::Create() { + BOOST_ASSERT(this->Model); if (!*this->Model) { *this->Model = typename T::element_type(); modelPart = new T(&**this->Model); @@ -185,6 +190,7 @@ namespace Slicer { template void ModelPartForOptional::GetValue(ValueTargetPtr s) { + BOOST_ASSERT(this->Model); if (!*this->Model) { *this->Model = typename T::element_type(); modelPart = new T(&**this->Model); @@ -245,24 +251,28 @@ namespace Slicer { template void ModelPartForClass::Create() { + BOOST_ASSERT(this->Model); *this->Model = new T(); } template T * ModelPartForClass::GetModel() { + BOOST_ASSERT(this->Model); return this->Model->get(); } template ModelPartPtr ModelPartForClass::GetSubclassModelPart(const std::string & name) { + BOOST_ASSERT(this->Model); return ModelPartForComplexBase::getSubclassModelPart(name, this->Model); } template bool ModelPartForClass::HasValue() const { + BOOST_ASSERT(this->Model); return *this->Model; } @@ -303,6 +313,7 @@ namespace Slicer { TypeId ModelPartForClass::GetTypeId() const { + BOOST_ASSERT(this->Model); return ModelPartForComplexBase::GetTypeId((*this->Model)->ice_id(), *className); } @@ -316,6 +327,7 @@ namespace Slicer { template T * ModelPartForStruct::GetModel() { + BOOST_ASSERT(this->Model); return this->Model; } @@ -347,15 +359,17 @@ namespace Slicer { template void ModelPartForSequence::OnEachChild(const ChildHandler & ch) - { - for(auto & element : *this->Model) { - ch(elementName, elementModelPart(element), NULL); - } + { + BOOST_ASSERT(this->Model); + for(auto & element : *this->Model) { + ch(elementName, elementModelPart(element), NULL); } + } template ChildRefPtr ModelPartForSequence::GetAnonChildRef(const HookFilter &) { + BOOST_ASSERT(this->Model); this->Model->push_back(typename element_type::value_type()); return new ImplicitChildRef(ModelPart::CreateFor(this->Model->back())); } @@ -410,6 +424,7 @@ namespace Slicer { template void ModelPartForDictionary::OnEachChild(const ChildHandler & ch) { + BOOST_ASSERT(this->Model); for (auto & pair : *this->Model) { ch(pairName, new ModelPartForStruct(&pair), NULL); } @@ -418,12 +433,14 @@ namespace Slicer { template ChildRefPtr ModelPartForDictionary::GetAnonChildRef(const HookFilter &) { + BOOST_ASSERT(this->Model); return new ImplicitChildRef(new ModelPartForDictionaryElementInserter(this->Model)); } template ChildRefPtr ModelPartForDictionary::GetChildRef(const std::string & name, const HookFilter &) { + BOOST_ASSERT(this->Model); if (name != pairName) { throw IncorrectElementName(name); } diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 43feace..bc8c0ef 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -53,6 +53,7 @@ namespace Slicer { fprintbf(cpp, "template<> DLL_PUBLIC\nvoid\n"); createModelPartForConverted(type, c->scoped(), dm); fprintbf(cpp, "::SetValue(ValueSourcePtr vsp)\n{\n"); + fprintbf(cpp, "\tBOOST_ASSERT(Model);\n"); for (const auto & conversion : conversions) { fprintbf(cpp, "\tif (auto vspt = dynamic_cast *>(vsp.get())) {\n", @@ -81,6 +82,7 @@ namespace Slicer { fprintbf(cpp, "template<> DLL_PUBLIC\nvoid\n"); createModelPartForConverted(type, c->scoped(), dm); fprintbf(cpp, "::GetValue(ValueTargetPtr vtp)\n{\n"); + fprintbf(cpp, "\tBOOST_ASSERT(Model);\n"); for (const auto & conversion : conversions) { fprintbf(cpp, "\tif (auto vtpt = dynamic_cast *>(vtp.get())) {\n", -- cgit v1.2.3