From 97614cc3bf4233b0e45eedf971f90ab8dc4bf21e Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Mon, 6 May 2024 18:13:24 +0300 Subject: [PATCH] Fix clang-tidy warnings --- .clang-tidy | 66 ++++++++++--------- ccl/cclGraph/cclGraph.vcxproj | 8 +-- ccl/cclGraph/cclGraph.vcxproj.filters | 7 -- ccl/cclGraph/src/CGraph.cpp | 2 +- ccl/cclLang/src/Reference.cpp | 3 +- ccl/cclLang/src/RefsManager.cpp | 2 +- ccl/core/include/ccl/semantic/RSConcept.h | 17 +++-- ccl/core/include/ccl/semantic/RSForm.h | 2 +- ccl/core/include/ccl/semantic/RSModel.h | 2 +- ccl/core/src/ops/EquationOptions.cpp | 23 ++++--- ccl/core/src/oss/OSSchema.cpp | 27 +++++--- ccl/core/src/oss/ossGraphFacet.cpp | 2 +- ccl/core/src/oss/ossOperationsFacet.cpp | 9 ++- ccl/core/src/semantic/rscore/RSCore.cpp | 2 + .../src/semantic/rsmodel/rsValuesFacet.cpp | 3 +- ccl/rslang/RSlang.vcxproj | 2 +- ccl/rslang/RSlang.vcxproj.filters | 6 +- ccl/rslang/include/ccl/rslang/RSToken.h | 2 +- ccl/rslang/src/ASTNormalizer.cpp | 2 +- ccl/rslang/src/Auditor.cpp | 2 - ccl/rslang/src/Interpreter.cpp | 2 - ccl/rslang/src/RSGenerator.cpp | 2 +- ccl/rslang/src/SDataCompact.cpp | 2 +- ccl/rslang/src/SyntaxTree.cpp | 4 +- 24 files changed, 108 insertions(+), 91 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index fa906dd..3cb78cb 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,40 +1,44 @@ Checks: "*,\ + -altera-id-dependent-backward-branch,\ -altera-struct-pack-align,\ -altera-unroll-loops,\ - -altera-id-dependent-backward-branch,\ - -llvmlibc-callee-namespace,\ - -llvmlibc-restrict-system-libc-headers,\ - -llvmlibc-implementation-in-namespace,\ - -llvmlibc-inline-function-decl,\ + -bugprone-branch-clone,\ + -bugprone-easily-swappable-parameters,\ + -bugprone-suspicious-include,\ + -bugprone-exception-escape,\ + -cppcoreguidelines-avoid-const-or-ref-data-members,\ + -cppcoreguidelines-avoid-do-while,\ + -cppcoreguidelines-non-private-member-variables-in-classes,\ + -cppcoreguidelines-prefer-member-initializer,\ + -cppcoreguidelines-special-member-functions,\ + -fuchsia-default-arguments,\ + -fuchsia-default-arguments-calls,\ + -fuchsia-default-arguments-declarations,\ + -fuchsia-multiple-inheritance,\ + -fuchsia-overloaded-operator,\ + -fuchsia-statically-constructed-objects,\ + -fuchsia-trailing-return,\ + -google-global-names-in-headers,\ + -google-readability-todo,\ + -google-runtime-references,\ + -hicpp-special-member-functions,\ -llvm-else-after-return,\ -llvm-header-guard,\ -llvm-include-order,\ - -bugprone-branch-clone,\ - -bugprone-suspicious-include,\ - -bugprone-easily-swappable-parameters,\ + -llvmlibc-callee-namespace,\ + -llvmlibc-implementation-in-namespace,\ + -llvmlibc-inline-function-decl,\ + -llvmlibc-restrict-system-libc-headers,\ + -misc-include-cleaner,\ + -misc-no-recursion,\ + -misc-non-private-member-variables-in-classes,\ -modernize-use-trailing-return-type,\ - -hicpp-special-member-functions,\ - -google-runtime-references,\ - -fuchsia-overloaded-operator,\ - -fuchsia-default-arguments,\ - -google-readability-todo,\ - -google-global-names-in-headers,\ - -readability-redundant-access-specifiers,\ - -readability-redundant-member-init,\ - -readability-else-after-return,\ - -readability-implicit-bool-conversion,\ - -readability-use-anyofallof,\ - -readability-identifier-length,\ -performance-inefficient-string-concatenation,\ -performance-unnecessary-value-param,\ - -fuchsia-default-arguments-declarations,\ - -fuchsia-trailing-return,\ - -fuchsia-multiple-inheritance,\ - -fuchsia-default-arguments-calls,\ - -misc-non-private-member-variables-in-classes,\ - -misc-no-recursion,\ - -misc-include-cleaner,\ - -cppcoreguidelines-special-member-functions,\ - -cppcoreguidelines-prefer-member-initializer,\ - -cppcoreguidelines-avoid-const-or-ref-data-members,\ - -cppcoreguidelines-non-private-member-variables-in-classes" \ No newline at end of file + -readability-else-after-return,\ + -readability-function-cognitive-complexity,\ + -readability-identifier-length,\ + -readability-implicit-bool-conversion,\ + -readability-redundant-access-specifiers,\ + -readability-redundant-member-init,\ + -readability-use-anyofallof" \ No newline at end of file diff --git a/ccl/cclGraph/cclGraph.vcxproj b/ccl/cclGraph/cclGraph.vcxproj index a6dc509..85fe9c1 100644 --- a/ccl/cclGraph/cclGraph.vcxproj +++ b/ccl/cclGraph/cclGraph.vcxproj @@ -28,12 +28,12 @@ 16.0 {7E1D5338-F819-4C96-B461-9EAAB8D02E1D} - StaticLibrary + StaticLibrary Win32Proj cclGraph - v143 + v143 10.0 - Unicode + Unicode @@ -120,7 +120,7 @@ xcopy /y /s /q /i ..\cclCommons\include ..\..\output\include include $(IntDir)$(ProjectName)d.pdb $(IntDir)obj\ - Disabled + Disabled Windows diff --git a/ccl/cclGraph/cclGraph.vcxproj.filters b/ccl/cclGraph/cclGraph.vcxproj.filters index 24815cc..c951382 100644 --- a/ccl/cclGraph/cclGraph.vcxproj.filters +++ b/ccl/cclGraph/cclGraph.vcxproj.filters @@ -1,9 +1,5 @@  - - - - {f0a3dd37-e5ae-4a37-ab65-d574c8dfe252} @@ -20,7 +16,4 @@ Graph - - - \ No newline at end of file diff --git a/ccl/cclGraph/src/CGraph.cpp b/ccl/cclGraph/src/CGraph.cpp index 1bab70a..b912dc5 100644 --- a/ccl/cclGraph/src/CGraph.cpp +++ b/ccl/cclGraph/src/CGraph.cpp @@ -298,7 +298,7 @@ CGraph::ItemsGroup CGraph::GetAllLoopsItems() const { } } if (size(component) != 1 || HasEdge(index, index)) { - result.push_back({}); + result.emplace_back(); result.back().reserve(size(component)); for (const auto item : component) { result.back().emplace(graph[item].uid); diff --git a/ccl/cclLang/src/Reference.cpp b/ccl/cclLang/src/Reference.cpp index 9bb0a86..cda99f7 100644 --- a/ccl/cclLang/src/Reference.cpp +++ b/ccl/cclLang/src/Reference.cpp @@ -64,7 +64,8 @@ namespace { [[nodiscard]] UTF8Iterator ReferenceStart(const std::string_view refStr, const StrPos start) noexcept { for (auto iter = UTF8Iterator(refStr, start); iter != UTF8End(refStr); ++iter) { if (*iter == '@') { - if (++iter == UTF8End(refStr) || *iter == '{') { + ++iter; + if (iter == UTF8End(refStr) || *iter == '{') { return iter; } } diff --git a/ccl/cclLang/src/RefsManager.cpp b/ccl/cclLang/src/RefsManager.cpp index 637d9b5..f6bf95b 100644 --- a/ccl/cclLang/src/RefsManager.cpp +++ b/ccl/cclLang/src/RefsManager.cpp @@ -160,7 +160,7 @@ std::string RefsManager::OutputRefs(const std::string& normStr, const StrRange s auto finish = subRange.finish; for (const auto& ref : refs) { const auto intersection = subRange.Intersect(ref.position); - if (!intersection.has_value() || intersection->length() == 0) { + if (!intersection.has_value() || intersection->empty()) { if (subRange.IsBefore(ref.position)) { break; } diff --git a/ccl/core/include/ccl/semantic/RSConcept.h b/ccl/core/include/ccl/semantic/RSConcept.h index f51bdf3..2b1170d 100644 --- a/ccl/core/include/ccl/semantic/RSConcept.h +++ b/ccl/core/include/ccl/semantic/RSConcept.h @@ -16,10 +16,19 @@ struct RSConcept { std::string definition{}; std::string convention{}; - explicit RSConcept(const EntityUID entity, std::string alias, const CstType type = CstType::base, - std::string definition = {}, std::string convention = {}) noexcept - : uid{ entity }, alias{ std::move(alias) }, type{ type }, - definition{ std::move(definition) }, convention{ std::move(convention) } {} + explicit RSConcept( + const EntityUID entity, + std::string alias, + const CstType type = CstType::base, + std::string definition = {}, + std::string convention = {} + ) noexcept : + uid{ entity }, + alias{ std::move(alias) }, + type{ type }, + definition{ std::move(definition) }, + convention{ std::move(convention) } + {} RSConcept() = default; diff --git a/ccl/core/include/ccl/semantic/RSForm.h b/ccl/core/include/ccl/semantic/RSForm.h index 4e2ce5c..c86ac7c 100644 --- a/ccl/core/include/ccl/semantic/RSForm.h +++ b/ccl/core/include/ccl/semantic/RSForm.h @@ -81,7 +81,7 @@ public: [[nodiscard]] change::Hash FullHash() const; private: - [[nodiscard]] inline bool NotifyAndReturn(const bool result) { + [[nodiscard]] bool NotifyAndReturn(const bool result) { if (result) { NotifyModification(); } diff --git a/ccl/core/include/ccl/semantic/RSModel.h b/ccl/core/include/ccl/semantic/RSModel.h index dadb098..652e987 100644 --- a/ccl/core/include/ccl/semantic/RSModel.h +++ b/ccl/core/include/ccl/semantic/RSModel.h @@ -71,7 +71,7 @@ public: void UpdateState(); private: - [[nodiscard]] inline bool NotifyAndReturn(const bool result) { + [[nodiscard]] bool NotifyAndReturn(const bool result) { if (result) { NotifyModification(); } diff --git a/ccl/core/src/ops/EquationOptions.cpp b/ccl/core/src/ops/EquationOptions.cpp index 1486f28..ff69dc9 100644 --- a/ccl/core/src/ops/EquationOptions.cpp +++ b/ccl/core/src/ops/EquationOptions.cpp @@ -17,17 +17,20 @@ bool EquationOptions::IsEqualTo(const Options& opt2) const { bool EquationOptions::SwapKeyVal(const EntityUID key) { if (!ContainsKey(key)) { return false; - } else if (const auto val = translation(key); ContainsKey(translation(key))) { - return false; - } else { - Equation props = properties[key]; - if (props.mode != Equation::Mode::createNew) { - props.mode = props.mode == Equation::Mode::keepHier ? Equation::Mode::keepDel : Equation::Mode::keepHier; - } - Erase(key); - Insert(val, key, props); - return true; } + const auto newKey = translation(key); + if (ContainsKey(newKey)) { + return false; + } + + Equation props = properties[key]; + if (props.mode != Equation::Mode::createNew) { + props.mode = props.mode == Equation::Mode::keepHier ? Equation::Mode::keepDel : Equation::Mode::keepHier; + } + Erase(key); + const auto newValue = key; + Insert(newKey, newValue, props); + return true; } const Equation& EquationOptions::PropsFor(const EntityUID key) const { diff --git a/ccl/core/src/oss/OSSchema.cpp b/ccl/core/src/oss/OSSchema.cpp index 18513ad..02fcbc8 100644 --- a/ccl/core/src/oss/OSSchema.cpp +++ b/ccl/core/src/oss/OSSchema.cpp @@ -126,8 +126,12 @@ void OSSchema::SetPictLink(const PictID target, const MediaLink& lnk) { } } -const Pict& OSSchema::LoadPict(Pict&& pict, GridPosition pos, const src::Handle& handle, - std::unique_ptr params) { +// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) +const Pict& OSSchema::LoadPict( + Pict&& pict, GridPosition pos, + const src::Handle& handle, + std::unique_ptr params +) { if (Grid()(pos).has_value()) { pos = Grid().ClosestFreePos(pos); } @@ -149,10 +153,12 @@ PictPtr OSSchema::InsertOperation(const PictID operand1, const PictID operand2) graph->AddItem(newID, { operand1, operand2 }); const auto newPos = Grid().ChildPosFor(operand1, operand2); - InsertInternal(Pict{ newID }, - newPos, - src::Handle{ src::SrcType::rsDoc }, - std::make_unique()); + InsertInternal( + Pict{ newID }, + newPos, + src::Handle{ src::SrcType::rsDoc }, + std::make_unique() + ); NotifyModification(); return &storage.at(newID); @@ -168,9 +174,12 @@ PictPtr OSSchema::InsertBase() { return &storage.at(newID); } -void OSSchema::InsertInternal(const Pict& pict, GridPosition pos, - const src::Handle& srcHandle, - std::unique_ptr opHandle) { +void OSSchema::InsertInternal( + const Pict& pict, + GridPosition pos, + const src::Handle& srcHandle, + std::unique_ptr opHandle +) { const auto pid = pict.uid; idGen.AddUID(pid); diff --git a/ccl/core/src/oss/ossGraphFacet.cpp b/ccl/core/src/oss/ossGraphFacet.cpp index 6f751db..f379bcc 100644 --- a/ccl/core/src/oss/ossGraphFacet.cpp +++ b/ccl/core/src/oss/ossGraphFacet.cpp @@ -119,7 +119,7 @@ std::optional ossGraphFacet::FindItemIndex(const PictID item) const { } size_t ossGraphFacet::InsertKeyValue(const PictID item) { - graph.emplace_back(std::vector{}); + graph.emplace_back(); items.emplace_back(item); return size(items) - 1U; } diff --git a/ccl/core/src/oss/ossOperationsFacet.cpp b/ccl/core/src/oss/ossOperationsFacet.cpp index 7132aad..f141908 100644 --- a/ccl/core/src/oss/ossOperationsFacet.cpp +++ b/ccl/core/src/oss/ossOperationsFacet.cpp @@ -216,9 +216,12 @@ ops::Result ossOperationsFacet::CreateNewResult(const PictID pid) { return opResult; } -bool ossOperationsFacet::SaveOperationResult(const PictID pid, - const EntityTranslation& old2New, - ops::Result&& opResult) { +// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) +bool ossOperationsFacet::SaveOperationResult( + const PictID pid, + const EntityTranslation& old2New, + ops::Result&& opResult +) { auto& opHandle = operations.at(pid); assert(opHandle != nullptr); const auto guard = core.DndGuard(); diff --git a/ccl/core/src/semantic/rscore/RSCore.cpp b/ccl/core/src/semantic/rscore/RSCore.cpp index 73eff57..f42e9ec 100644 --- a/ccl/core/src/semantic/rscore/RSCore.cpp +++ b/ccl/core/src/semantic/rscore/RSCore.cpp @@ -87,6 +87,7 @@ EntityUID RSCore::Emplace(const CstType type, const std::string& definition) { return newID.uid; } +// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) EntityUID RSCore::Insert(ConceptRecord&& cst) { RSConcept newRS{cst.uid, cst.alias, cst.type, std::move(cst.rs), std::move(cst.convention) }; TextConcept newText{cst.uid, cst.alias, std::move(cst.term), std::move(cst.definition) }; @@ -213,6 +214,7 @@ VectorOfEntities RSCore::InsertCopy(const std::vector& input) { return result; } +// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved) EntityUID RSCore::Load(ConceptRecord&& cst) { RSConcept newRS{ cst.uid, cst.alias, cst.type, std::move(cst.rs), std::move(cst.convention) }; TextConcept newText{ cst.uid, cst.alias, std::move(cst.term), std::move(cst.definition) }; diff --git a/ccl/core/src/semantic/rsmodel/rsValuesFacet.cpp b/ccl/core/src/semantic/rsmodel/rsValuesFacet.cpp index b73a9ea..20a6435 100644 --- a/ccl/core/src/semantic/rsmodel/rsValuesFacet.cpp +++ b/ccl/core/src/semantic/rsmodel/rsValuesFacet.cpp @@ -172,7 +172,8 @@ void rsValuesFacet::PruneStructure(const EntityUID target) { } const auto& typeValue = core.GetParse(target).exprType; assert(typeValue.has_value()); - const auto& type = std::get(typeValue.value()); // NOLINT(bugprone-exception-escape) + // NOLINTNEXTLINE(bugprone-exception-escape, bugprone-unchecked-optional-access) + const auto& type = std::get(typeValue.value()); if (!oldData->IsCollection()) { if (!CheckBasicElements(oldData.value(), type)) { storage->Erase(target); diff --git a/ccl/rslang/RSlang.vcxproj b/ccl/rslang/RSlang.vcxproj index 113403c..cba3aa0 100644 --- a/ccl/rslang/RSlang.vcxproj +++ b/ccl/rslang/RSlang.vcxproj @@ -46,7 +46,7 @@ - + diff --git a/ccl/rslang/RSlang.vcxproj.filters b/ccl/rslang/RSlang.vcxproj.filters index abc3705..2ab0e37 100644 --- a/ccl/rslang/RSlang.vcxproj.filters +++ b/ccl/rslang/RSlang.vcxproj.filters @@ -207,10 +207,6 @@ 11 parse\lexer - - - - 11 parse\parser - + \ No newline at end of file diff --git a/ccl/rslang/include/ccl/rslang/RSToken.h b/ccl/rslang/include/ccl/rslang/RSToken.h index 4a2ffdb..b057608 100644 --- a/ccl/rslang/include/ccl/rslang/RSToken.h +++ b/ccl/rslang/include/ccl/rslang/RSToken.h @@ -18,7 +18,7 @@ enum class Syntax : uint8_t { }; //! RS language token types enumeration -enum class TokenID : uint32_t { +enum class TokenID : uint32_t { // NOLINT(performance-enum-size) // Global, local IDs and literals ID_LOCAL = 258, ID_GLOBAL, diff --git a/ccl/rslang/src/ASTNormalizer.cpp b/ccl/rslang/src/ASTNormalizer.cpp index 82890ae..333e543 100644 --- a/ccl/rslang/src/ASTNormalizer.cpp +++ b/ccl/rslang/src/ASTNormalizer.cpp @@ -92,7 +92,7 @@ std::string Normalizer::CreateTupleName(const SyntaxTree::Node& root) { std::stack nodeStack{}; std::stack> pathStack{}; nodeStack.push(&root); - pathStack.push({}); + pathStack.emplace(); while (!std::empty(nodeStack)) { auto curPath = pathStack.top(); pathStack.pop(); diff --git a/ccl/rslang/src/Auditor.cpp b/ccl/rslang/src/Auditor.cpp index c0716c5..2b7f25c 100644 --- a/ccl/rslang/src/Auditor.cpp +++ b/ccl/rslang/src/Auditor.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "ccl/rslang/Auditor.h" namespace ccl::rslang { diff --git a/ccl/rslang/src/Interpreter.cpp b/ccl/rslang/src/Interpreter.cpp index e08aae2..5aa7474 100644 --- a/ccl/rslang/src/Interpreter.cpp +++ b/ccl/rslang/src/Interpreter.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "ccl/rslang/Interpreter.h" #include diff --git a/ccl/rslang/src/RSGenerator.cpp b/ccl/rslang/src/RSGenerator.cpp index 4305229..fd94b5a 100644 --- a/ccl/rslang/src/RSGenerator.cpp +++ b/ccl/rslang/src/RSGenerator.cpp @@ -42,7 +42,7 @@ using Description = Generator::StructureDescription; return {}; } const auto& newName = substitutes.at(argName); - argsTypes.emplace_back(TypedID{ newName, std::get(*type) }); + argsTypes.emplace_back(newName, std::get(*type)); } return Generator::CreatePrefix(argsTypes); } diff --git a/ccl/rslang/src/SDataCompact.cpp b/ccl/rslang/src/SDataCompact.cpp index 2e951da..5a6e804 100644 --- a/ccl/rslang/src/SDataCompact.cpp +++ b/ccl/rslang/src/SDataCompact.cpp @@ -63,7 +63,7 @@ SDCompact::Header SDCompact::CreateHeader(const Typification& type) { result.push_back(host.E().baseID); break; case rslang::StructureType::collection: - result.push_back("B"); break; + result.emplace_back("B"); break; case rslang::StructureType::tuple: break; diff --git a/ccl/rslang/src/SyntaxTree.cpp b/ccl/rslang/src/SyntaxTree.cpp index c034b14..146806a 100644 --- a/ccl/rslang/src/SyntaxTree.cpp +++ b/ccl/rslang/src/SyntaxTree.cpp @@ -223,8 +223,8 @@ std::optional FindMinimalNode(SyntaxTree::Cursor root, StrRa } else { root.MoveToChild(0); do { - if (const auto result = FindMinimalNode(root, range); - result.has_value()) { + const auto result = FindMinimalNode(root, range); + if (result.has_value()) { return result; } } while (root.MoveToNextSibling());