From d399910103de05bc15ebc90a732f55a50732146e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 19 Mar 2019 21:56:50 +0000 Subject: Clang tidy our own generated code Builds tools with gcc to run a real slicer for the codegen. Fixs results tidy warnings --- slicer/slicer/modelPartsTypes.impl.h | 18 ++++++++++++++++++ slicer/test/Jamfile.jam | 8 ++++++-- slicer/test/slicer.jam | 2 -- slicer/tool/parser.cpp | 20 ++++++++++++-------- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 74bf0c6..e75c849 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -146,6 +146,7 @@ namespace Slicer { template void ModelPartForSimple::SetValue(ValueSource && s) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); s.set(*this->Model); } @@ -153,6 +154,7 @@ namespace Slicer { template bool ModelPartForSimple::GetValue(ValueTarget && s) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); s.get(*this->Model); return true; @@ -174,6 +176,7 @@ namespace Slicer { template M::* MV> bool ModelPartForConverted, M, MV>::HasValue() const { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); return (bool)*this->Model; } @@ -289,6 +292,7 @@ namespace Slicer { template bool ModelPartForOptional::hasModel() const { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); return (bool)*this->Model; } @@ -296,6 +300,7 @@ namespace Slicer { template void ModelPartForOptional::Create() { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); if (!*this->Model) { *this->Model = typename T::element_type(); @@ -307,6 +312,7 @@ namespace Slicer { template bool ModelPartForOptional::GetValue(ValueTarget && s) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); if (*this->Model) { return modelPart->GetValue(std::move(s)); @@ -446,6 +452,7 @@ namespace Slicer { template void ModelPartForClass::Create() { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); *this->Model = std::make_shared(); } @@ -459,6 +466,7 @@ namespace Slicer { template ModelPartPtr ModelPartForClass::GetSubclassModelPart(const std::string & name) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); return ModelPartForComplexBase::getSubclassModelPart(name, this->Model); } @@ -466,6 +474,7 @@ namespace Slicer { template bool ModelPartForClass::HasValue() const { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); return (bool)*this->Model; } @@ -507,6 +516,7 @@ namespace Slicer { TypeId ModelPartForClass::GetTypeId() const { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); return ModelPartForComplexBase::GetTypeId(getTypeId(), *className); } @@ -591,6 +601,7 @@ namespace Slicer { template void ModelPartForEnum::SetValue(ValueSource && s) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); std::string val; s.set(val); @@ -600,6 +611,7 @@ namespace Slicer { template bool ModelPartForEnum::GetValue(ValueTarget && s) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); s.get(lookup(*this->Model)); return true; @@ -615,6 +627,7 @@ namespace Slicer { template void ModelPartForSequence::OnEachChild(const ChildHandler & ch) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); for(auto & element : *this->Model) { ch(elementName, elementModelPart(element), NULL); @@ -624,6 +637,7 @@ namespace Slicer { template ChildRef ModelPartForSequence::GetAnonChildRef(const HookFilter &) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); this->Model->push_back(typename element_type::value_type()); return ChildRef(ModelPart::CreateFor(this->Model->back())); @@ -671,6 +685,7 @@ namespace Slicer { template void ModelPartForDictionary::OnEachChild(const ChildHandler & ch) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); for (auto & pair : *this->Model) { ch(pairName, std::make_shared>(&pair), NULL); @@ -680,6 +695,7 @@ namespace Slicer { template ChildRef ModelPartForDictionary::GetAnonChildRef(const HookFilter &) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); return ChildRef(std::make_shared>(this->Model)); } @@ -687,6 +703,7 @@ namespace Slicer { template ChildRef ModelPartForDictionary::GetChildRef(const std::string & name, const HookFilter &, bool matchCase) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); if (!optionalCaseEq(name, pairName, matchCase)) { throw IncorrectElementName(name); @@ -724,6 +741,7 @@ namespace Slicer { void ModelPartForStream::OnEachChild(const ChildHandler & ch) { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); this->Model->Produce([&ch](const T & element) { ch(ModelPartForSequence>::elementName, ModelPart::CreateFor(element), NULL); diff --git a/slicer/test/Jamfile.jam b/slicer/test/Jamfile.jam index c288fc9..4c0acbd 100644 --- a/slicer/test/Jamfile.jam +++ b/slicer/test/Jamfile.jam @@ -22,9 +22,13 @@ lib types : [ glob *.ice ] conversions.cpp : - ../tool//slicer + gcc:../tool//slicer/gcc + clang:../tool//slicer/clang + tidy:../tool//slicer/gcc pure - ../tool//slicer + gcc:../tool//slicer/gcc + clang:../tool//slicer/clang + tidy:../tool//slicer/gcc . ..//adhocutil boost_date_time diff --git a/slicer/test/slicer.jam b/slicer/test/slicer.jam index f43d087..f413628 100644 --- a/slicer/test/slicer.jam +++ b/slicer/test/slicer.jam @@ -14,13 +14,11 @@ toolset.flags slicer INCLUDES ; actions slicer bind SLICERBIN { slice2cpp -I"$(INCLUDES)" --checksum --output-dir $(1[1]:D) $(2) --dll-export JAM_DLL_PUBLIC - touch $(1[2]) "$(SLICERBIN)" -I"$(INCLUDES)" $(2) $(1[2]) --headerPrefix="\"\"" } actions slicer.pure bind SLICERBIN { - touch $(1[1]) "$(SLICERBIN)" -I"$(INCLUDES)" $(2) $(1[1]) --headerPrefix="\"\"" } diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 9aa27cd..0edcc2f 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -50,16 +50,17 @@ namespace Slicer { fprintbf(cpp, "template<> DLL_PUBLIC\nvoid\n"); createModelPartForConverted(type, c->scoped(), dm); fprintbf(cpp, "::SetValue(ValueSource && vsp)\n{\n"); + fprintbf(cpp, "\t// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)\n"); fprintbf(cpp, "\tBOOST_ASSERT(Model);\n"); for (const auto & conversion : conversions) { - fprintbf(cpp, "\tif (tryConvertFrom< %s >(vsp, Model, &%s)) return;\n", + fprintbf(cpp, "\tif (tryConvertFrom< %s >(vsp, Model, &%s)) {\n\t\treturn;\n\t}\n", conversion.ExchangeType, conversion.ConvertToModelFunc); } // Default conversion if (!dm->hasMetaData("slicer:nodefaultconversion")) { - fprintbf(cpp, "\tif (tryConvertFrom< %s >(vsp, Model)) return;\n", + fprintbf(cpp, "\tif (tryConvertFrom< %s >(vsp, Model)) {\n\t\treturn;\n\t}\n", Slice::typeToString(type)); } // Failed to convert @@ -70,16 +71,17 @@ namespace Slicer { fprintbf(cpp, "template<> DLL_PUBLIC\nbool\n"); createModelPartForConverted(type, c->scoped(), dm); fprintbf(cpp, "::GetValue(ValueTarget && vtp)\n{\n"); + fprintbf(cpp, "\t// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)\n"); fprintbf(cpp, "\tBOOST_ASSERT(Model);\n"); for (const auto & conversion : conversions) { - fprintbf(cpp, "\tif (auto r = tryConvertTo< %s >(vtp, Model, &%s)) return (r == tcr_Value);\n", + fprintbf(cpp, "\tif (auto r = tryConvertTo< %s >(vtp, Model, &%s)) {\n\t\treturn (r == tcr_Value);\n\t}\n", conversion.ExchangeType, conversion.ConvertToExchangeFunc); } // Default conversion if (!dm->hasMetaData("slicer:nodefaultconversion")) { - fprintbf(cpp, "\tif (auto r = tryConvertTo< %s >(vtp, Model)) return (r == tcr_Value);\n", + fprintbf(cpp, "\tif (auto r = tryConvertTo< %s >(vtp, Model)) {\n\t\treturn (r == tcr_Value);\n\t}\n", Slice::typeToString(type)); } // Failed to convert @@ -199,6 +201,7 @@ namespace Slicer { copyMetadata(c->getMetaData()); fprintbf(cpp, ";\n\n"); + fprintbf(cpp, "// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)\n"); if (auto cmp = metaDataValue("slicer:custommodelpart:", c->getMetaData())) { fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, %s< %s >, %s);\n\n", Slice::typeToString(decl), getBasicModelPart(decl), c->scoped(), boost::algorithm::replace_all_copy(*cmp, ".", "::")); @@ -243,8 +246,8 @@ namespace Slicer { { if (!cpp) { return; } - fprintbf(cpp, "typedef ModelPartForComplex< %s > C%d;\n", - it->scoped(), components); + fprintbf(cpp, "using C%d = ModelPartForComplex< %s >;\n", + components, it->scoped()); fprintbf(cpp, "template<> DLL_PUBLIC\n"); fprintbf(cpp, "const C%d::Hooks ", components); @@ -373,8 +376,8 @@ namespace Slicer { d->scoped(), iname ? *iname : "element"); - fprintbf(cpp, "typedef ModelPartForComplex< %s::value_type > C%d;\n", - d->scoped(), components); + fprintbf(cpp, "using C%d = ModelPartForComplex< %s::value_type >;\n", + components, d->scoped()); fprintbf(cpp, "template<> DLL_PUBLIC\n"); fprintbf(cpp, "const C%d::Hooks ", components); @@ -550,6 +553,7 @@ namespace Slicer { void Slicer::defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata) const { + fprintbf(cpp, "// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)\n"); if (auto cmp = metaDataValue("slicer:custommodelpart:", metadata)) { fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, %s< %s >, %s);\n\n", type, getBasicModelPart(stype), type, boost::algorithm::replace_all_copy(*cmp, ".", "::")); -- cgit v1.2.3