From 42f1a5e97c8febb3939239e8fff8d8918e8e74c8 Mon Sep 17 00:00:00 2001 From: xtof Date: Wed, 17 Sep 2025 15:13:15 +0200 Subject: [PATCH 1/3] update workflows and set cppcheck --- .github/workflows/asan-build.yml | 2 +- .github/workflows/coverage.yml | 2 +- .github/workflows/cppcheck.yml | 19 +++++++++++++++++++ .github/workflows/emscripten.yml | 2 +- .github/workflows/macos-build.yml | 2 +- .github/workflows/naja_app_build.yml | 2 +- .github/workflows/najaeda-examples.yml | 2 +- .github/workflows/najaeda-test.yml | 2 +- .github/workflows/regress.yml | 2 +- .github/workflows/reuse.yml | 2 +- .github/workflows/snl_python_app.yml | 2 +- .github/workflows/ubuntu-build.yml | 2 +- .github/workflows/valgrind.yml | 2 +- 13 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/cppcheck.yml diff --git a/.github/workflows/asan-build.yml b/.github/workflows/asan-build.yml index fdc7b01f4..31e4c4aee 100644 --- a/.github/workflows/asan-build.yml +++ b/.github/workflows/asan-build.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: submodules: true # install dependencies diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index d12404f57..d0a3fb617 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 submodules: true diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml new file mode 100644 index 000000000..bb6b84ee4 --- /dev/null +++ b/.github/workflows/cppcheck.yml @@ -0,0 +1,19 @@ +name: cppcheck + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + cppcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - name: Install cppcheck + run: sudo apt-get install -y cppcheck + + - name: Run cppcheck + run: cppcheck --enable=all --inconclusive --std=c++17 --force . \ No newline at end of file diff --git a/.github/workflows/emscripten.yml b/.github/workflows/emscripten.yml index bfd0d6fc5..b2c5107c6 100644 --- a/.github/workflows/emscripten.yml +++ b/.github/workflows/emscripten.yml @@ -12,7 +12,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 with: submodules: true # install dependencies diff --git a/.github/workflows/macos-build.yml b/.github/workflows/macos-build.yml index 0daea4a18..6bd527ebd 100644 --- a/.github/workflows/macos-build.yml +++ b/.github/workflows/macos-build.yml @@ -23,7 +23,7 @@ jobs: os: [macos-15, macos-14, macos-13] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: submodules: true # install dependencies diff --git a/.github/workflows/naja_app_build.yml b/.github/workflows/naja_app_build.yml index 308d7414c..ffe632c75 100644 --- a/.github/workflows/naja_app_build.yml +++ b/.github/workflows/naja_app_build.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 submodules: true diff --git a/.github/workflows/najaeda-examples.yml b/.github/workflows/najaeda-examples.yml index 09d14a30b..549c65f04 100644 --- a/.github/workflows/najaeda-examples.yml +++ b/.github/workflows/najaeda-examples.yml @@ -13,7 +13,7 @@ jobs: build: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 submodules: true diff --git a/.github/workflows/najaeda-test.yml b/.github/workflows/najaeda-test.yml index 03094788b..0788171c2 100644 --- a/.github/workflows/najaeda-test.yml +++ b/.github/workflows/najaeda-test.yml @@ -13,7 +13,7 @@ jobs: build: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 submodules: true diff --git a/.github/workflows/regress.yml b/.github/workflows/regress.yml index 4b0adba00..c35b328bb 100644 --- a/.github/workflows/regress.yml +++ b/.github/workflows/regress.yml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: submodules: true diff --git a/.github/workflows/reuse.yml b/.github/workflows/reuse.yml index 788ee648f..8122e9cfe 100644 --- a/.github/workflows/reuse.yml +++ b/.github/workflows/reuse.yml @@ -14,6 +14,6 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - name: REUSE Compliance Check uses: fsfe/reuse-action@v2 diff --git a/.github/workflows/snl_python_app.yml b/.github/workflows/snl_python_app.yml index 620462479..331f7b37c 100644 --- a/.github/workflows/snl_python_app.yml +++ b/.github/workflows/snl_python_app.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 submodules: true diff --git a/.github/workflows/ubuntu-build.yml b/.github/workflows/ubuntu-build.yml index 15010a9c6..3a3037003 100644 --- a/.github/workflows/ubuntu-build.yml +++ b/.github/workflows/ubuntu-build.yml @@ -23,7 +23,7 @@ jobs: os: [ubuntu-24.04, ubuntu-22.04] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: submodules: true # install dependencies diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 40541ee46..bbadbb20f 100644 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 submodules: true From 6bcd97c0140f3ddca92b7c9c4fa00ec71a8dad9b Mon Sep 17 00:00:00 2001 From: xtof Date: Thu, 18 Sep 2025 21:43:23 +0200 Subject: [PATCH 2/3] code cleaning --- .github/workflows/cppcheck.yml | 19 ------------ src/core/NajaCollection.h | 30 ++++++++++--------- src/core/NajaObject.h | 2 +- src/nl/nl/nl/NLDesign.h | 1 + src/nl/nl/nl/NLID.h | 6 ++-- src/nl/nl/nl/NLLibrary.h | 2 +- src/nl/nl/nl/NLName.h | 3 +- src/nl/nl/nl/NLObject.h | 4 ++- src/nl/nl/nl/NLUniverse.h | 2 +- src/nl/nl/pnl/PNLBitNet.h | 2 +- src/nl/nl/pnl/PNLBitTerm.h | 2 +- src/nl/nl/pnl/PNLDesignObject.h | 2 +- src/nl/nl/pnl/PNLInstTerm.h | 2 +- src/nl/nl/pnl/PNLInstance.cpp | 8 ++++- src/nl/nl/pnl/PNLInstance.h | 2 +- src/nl/nl/pnl/PNLNet.h | 2 +- src/nl/nl/pnl/PNLNetComponent.h | 2 +- src/nl/nl/pnl/PNLScalarNet.h | 2 +- src/nl/nl/pnl/PNLScalarTerm.h | 2 +- src/nl/nl/pnl/PNLTerm.h | 2 +- src/nl/nl/snl/SNLAttributes.h | 4 +-- src/nl/nl/snl/SNLBitNet.h | 2 +- src/nl/nl/snl/SNLBitTerm.h | 2 +- src/nl/nl/snl/SNLBusNet.h | 2 +- src/nl/nl/snl/SNLBusNetBit.h | 2 +- src/nl/nl/snl/SNLBusTerm.h | 2 +- src/nl/nl/snl/SNLBusTermBit.h | 2 +- src/nl/nl/snl/SNLDesign.h | 2 +- src/nl/nl/snl/SNLDesignObject.h | 2 +- src/nl/nl/snl/SNLInstParameter.cpp | 4 +-- src/nl/nl/snl/SNLInstParameter.h | 12 ++++---- src/nl/nl/snl/SNLInstTerm.h | 4 +-- src/nl/nl/snl/SNLInstance.h | 2 +- src/nl/nl/snl/SNLNet.h | 4 +-- src/nl/nl/snl/SNLNetComponent.h | 4 +-- src/nl/nl/snl/SNLParameter.h | 2 +- src/nl/nl/snl/SNLScalarNet.h | 2 +- src/nl/nl/snl/SNLScalarTerm.h | 2 +- src/nl/nl/snl/SNLTerm.h | 2 +- src/nl/nl/snl/SNLUniquifier.cpp | 1 - src/nl/nl/snl/SNLUniquifier.h | 2 +- test/core/NajaPrivatePropertyTest.cpp | 2 +- .../naja_wrapping/NajaPythonPropertyTest.cpp | 2 +- 43 files changed, 77 insertions(+), 85 deletions(-) delete mode 100644 .github/workflows/cppcheck.yml diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml deleted file mode 100644 index bb6b84ee4..000000000 --- a/.github/workflows/cppcheck.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: cppcheck - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - cppcheck: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - - name: Install cppcheck - run: sudo apt-get install -y cppcheck - - - name: Run cppcheck - run: cppcheck --enable=all --inconclusive --std=c++17 --force . \ No newline at end of file diff --git a/src/core/NajaCollection.h b/src/core/NajaCollection.h index 7f8d75297..b16be9d97 100644 --- a/src/core/NajaCollection.h +++ b/src/core/NajaCollection.h @@ -55,7 +55,7 @@ class NajaSingletonCollection: public NajaBaseCollection { class NajaSingletonCollectionIterator: public NajaBaseIterator { public: NajaSingletonCollectionIterator(const NajaSingletonCollectionIterator&) = default; - NajaSingletonCollectionIterator(Type* object, bool beginOrEnd=true): object_(object) { + explicit NajaSingletonCollectionIterator(Type* object, bool beginOrEnd=true): object_(object) { if (object_) { if (beginOrEnd) { begin_ = true; @@ -94,7 +94,7 @@ class NajaSingletonCollection: public NajaBaseCollection { NajaSingletonCollection() = delete; NajaSingletonCollection(const NajaSingletonCollection&) = delete; NajaSingletonCollection(NajaSingletonCollection&&) = delete; - NajaSingletonCollection(Type* object): super(), object_(object) {} + explicit NajaSingletonCollection(Type* object): super(), object_(object) {} NajaBaseCollection* clone() const override { return new NajaSingletonCollection(object_); @@ -123,7 +123,7 @@ class NajaIntrusiveSetCollection: public NajaBaseCollectionbegin(); @@ -162,7 +162,7 @@ class NajaIntrusiveSetCollection: public NajaBaseCollection* clone() const override { return new NajaIntrusiveSetCollection(set_); @@ -188,7 +188,7 @@ class NajaSTLCollection: public NajaBaseCollection using STLTypeIterator = typename STLType::const_iterator; NajaSTLCollectionIterator(NajaSTLCollectionIterator&) = default; - NajaSTLCollectionIterator(const STLType* container, bool beginOrEnd=true): container_(container) { + explicit NajaSTLCollectionIterator(const STLType* container, bool beginOrEnd=true): container_(container) { if (container_) { if (beginOrEnd) { it_ = container_->begin(); @@ -221,7 +221,7 @@ class NajaSTLCollection: public NajaBaseCollection NajaSTLCollection() = delete; NajaSTLCollection(const NajaSTLCollection&) = delete; NajaSTLCollection(NajaSTLCollection&&) = delete; - NajaSTLCollection(const STLType* container): super(), container_(container) {} + explicit NajaSTLCollection(const STLType* container): super(), container_(container) {} NajaBaseCollection* clone() const override { return new NajaSTLCollection(container_); } @@ -253,7 +253,7 @@ class NajaSTLMapCollection: public NajaBaseCollectionbegin(); @@ -286,7 +286,7 @@ class NajaSTLMapCollection: public NajaBaseCollection* clone() const override { return new NajaSTLMapCollection(container_); } @@ -315,7 +315,7 @@ template class NajaParentTypeCollection: public Na class NajaParentTypeCollectionIterator: public NajaBaseIterator { public: using super = NajaBaseIterator; - NajaParentTypeCollectionIterator(const NajaBaseCollection* collection, bool beginOrEnd=true): + explicit NajaParentTypeCollectionIterator(const NajaBaseCollection* collection, bool beginOrEnd=true): super() { if (collection) { endIt_ = collection->end(); @@ -369,7 +369,7 @@ template class NajaParentTypeCollection: public Na NajaParentTypeCollection(const NajaParentTypeCollection&) = delete; NajaParentTypeCollection& operator=(const NajaParentTypeCollection&) = delete; NajaParentTypeCollection(const NajaParentTypeCollection&&) = delete; - NajaParentTypeCollection(const NajaBaseCollection* collection): + explicit NajaParentTypeCollection(const NajaBaseCollection* collection): super(), collection_(collection) {} ~NajaParentTypeCollection() { @@ -408,7 +408,7 @@ template class NajaSubTypeCollection: public NajaBase class NajaSubTypeCollectionIterator: public NajaBaseIterator { public: using super = NajaBaseIterator; - NajaSubTypeCollectionIterator(const NajaBaseCollection* collection, bool beginOrEnd=true): + explicit NajaSubTypeCollectionIterator(const NajaBaseCollection* collection, bool beginOrEnd=true): super() { if (collection) { endIt_ = collection->end(); @@ -416,7 +416,8 @@ template class NajaSubTypeCollection: public NajaBase it_ = endIt_; } else { it_ = collection->begin(); - while (isValid() and not dynamic_cast(it_->getElement())) { + while (NajaSubTypeCollectionIterator::isValid() + and not dynamic_cast(it_->getElement())) { it_->progress(); } } @@ -467,7 +468,7 @@ template class NajaSubTypeCollection: public NajaBase NajaSubTypeCollection(const NajaSubTypeCollection&) = delete; NajaSubTypeCollection& operator=(const NajaSubTypeCollection&) = delete; NajaSubTypeCollection(const NajaSubTypeCollection&&) = delete; - NajaSubTypeCollection(const NajaBaseCollection* collection): + explicit NajaSubTypeCollection(const NajaBaseCollection* collection): super(), collection_(collection) {} ~NajaSubTypeCollection() { @@ -519,7 +520,8 @@ template class NajaFilteredCollection: public NajaB it_ = endIt_; } else { it_ = collection->begin(); - while (isValid() and not filter_(it_->getElement())) { + while (NajaFilteredCollectionIterator::isValid() + and not filter_(it_->getElement())) { it_->progress(); } } diff --git a/src/core/NajaObject.h b/src/core/NajaObject.h index c474746fd..9a80b9003 100644 --- a/src/core/NajaObject.h +++ b/src/core/NajaObject.h @@ -49,7 +49,7 @@ class NajaObject { virtual ~NajaObject() = default; static void preCreate() {} - void postCreate() {} + virtual void postCreate() {} virtual void preDestroy(); private: diff --git a/src/nl/nl/nl/NLDesign.h b/src/nl/nl/nl/NLDesign.h index 7dfd7681c..ac1d53df0 100644 --- a/src/nl/nl/nl/NLDesign.h +++ b/src/nl/nl/nl/NLDesign.h @@ -15,6 +15,7 @@ class NLDesign { enum CompareTypeEnum { Complete, IgnoreID, IgnoreIDAndName }; + // cppcheck-suppress noExplicitConstructor CompareType(const CompareTypeEnum& typeEnum); CompareType(const CompareType& type) = default; operator const CompareTypeEnum&() const {return typeEnum_;} diff --git a/src/nl/nl/nl/NLID.h b/src/nl/nl/nl/NLID.h index 25fa069aa..45c322056 100644 --- a/src/nl/nl/nl/NLID.h +++ b/src/nl/nl/nl/NLID.h @@ -62,7 +62,7 @@ struct NLID final { DesignReference() = delete; DesignReference(const DesignReference&) = default; - DesignReference(const NLID& id): + explicit DesignReference(const NLID& id): dbID_(id.dbID_), libraryID_(id.libraryID_), designID_(id.designID_) @@ -99,7 +99,7 @@ struct NLID final { DesignObjectReference() = delete; DesignObjectReference(const DesignObjectReference&) = default; - DesignObjectReference(const NLID& id): + explicit DesignObjectReference(const NLID& id): dbID_(id.dbID_), libraryID_(id.libraryID_), designID_(id.designID_), @@ -224,7 +224,7 @@ struct NLID final { NLID() = delete; ///Special constructor for SNLDB - NLID(DBID dbID): + explicit NLID(DBID dbID): type_(NLID::Type::DB), dbID_(dbID) {} diff --git a/src/nl/nl/nl/NLLibrary.h b/src/nl/nl/nl/NLLibrary.h index e396c8e9a..c1237d2a5 100644 --- a/src/nl/nl/nl/NLLibrary.h +++ b/src/nl/nl/nl/NLLibrary.h @@ -157,7 +157,7 @@ class NLLibrary final: public NLObject { static void preCreate(NLLibrary* parent, NLID::LibraryID id, Type type, const NLName& name); void destroyFromDB(); void destroyFromParentLibrary(); - void postCreate(); + void postCreate() override; void postCreateAndSetID(); void commonPreDestroy(); void preDestroy() override; diff --git a/src/nl/nl/nl/NLName.h b/src/nl/nl/nl/NLName.h index 1859f86ec..8d9d9374d 100644 --- a/src/nl/nl/nl/NLName.h +++ b/src/nl/nl/nl/NLName.h @@ -11,7 +11,8 @@ namespace naja { namespace NL { class NLName { public: - explicit NLName(const std::string& name = std::string()): + // cppcheck-suppress noExplicitConstructor + NLName(const std::string& name = std::string()): string_(name) {} diff --git a/src/nl/nl/nl/NLObject.h b/src/nl/nl/nl/NLObject.h index 6b79a6977..6cd577bed 100644 --- a/src/nl/nl/nl/NLObject.h +++ b/src/nl/nl/nl/NLObject.h @@ -30,8 +30,10 @@ class NLObject: public NajaObject { virtual void debugDump(size_t indent, bool recursive=true, std::ostream& stream=std::cerr) const = 0; protected: + // cppcheck-suppress duplInheritedMember static void preCreate(); - void postCreate(); + + void postCreate() override; void preDestroy() override; }; diff --git a/src/nl/nl/nl/NLUniverse.h b/src/nl/nl/nl/NLUniverse.h index 3882ec41f..ddb25a8f1 100644 --- a/src/nl/nl/nl/NLUniverse.h +++ b/src/nl/nl/nl/NLUniverse.h @@ -101,7 +101,7 @@ class NLUniverse final: public NLObject { private: NLUniverse() = default; static void preCreate(); - void postCreate(); + void postCreate() override; void preDestroy() override; void addDBAndSetID(NLDB* db); diff --git a/src/nl/nl/pnl/PNLBitNet.h b/src/nl/nl/pnl/PNLBitNet.h index 2a0bc1114..c78cd6e80 100644 --- a/src/nl/nl/pnl/PNLBitNet.h +++ b/src/nl/nl/pnl/PNLBitNet.h @@ -41,7 +41,7 @@ class PNLBitNet: public PNLNet { protected: PNLBitNet() = default; static void preCreate(); - void postCreate(); + void postCreate() override; void preDestroy() override; //void cloneComponents(PNLBitNet* newNet) const; diff --git a/src/nl/nl/pnl/PNLBitTerm.h b/src/nl/nl/pnl/PNLBitTerm.h index 22a88f4cf..e97c1fd08 100644 --- a/src/nl/nl/pnl/PNLBitTerm.h +++ b/src/nl/nl/pnl/PNLBitTerm.h @@ -31,7 +31,7 @@ class PNLBitTerm: public PNLTerm { protected: PNLBitTerm() = default; static void preCreate(); - void postCreate(); + void postCreate() override; void preDestroy() override; private: PNLBitNet* net_ { nullptr }; diff --git a/src/nl/nl/pnl/PNLDesignObject.h b/src/nl/nl/pnl/PNLDesignObject.h index a5e0ecf53..c5d11790c 100644 --- a/src/nl/nl/pnl/PNLDesignObject.h +++ b/src/nl/nl/pnl/PNLDesignObject.h @@ -39,7 +39,7 @@ class PNLDesignObject: public NL::NLObject { PNLDesignObject() = default; static void preCreate(); - void postCreate(); + void postCreate() override; }; }} // namespace NL // namespace naja diff --git a/src/nl/nl/pnl/PNLInstTerm.h b/src/nl/nl/pnl/PNLInstTerm.h index f8d772769..346e9d0a6 100644 --- a/src/nl/nl/pnl/PNLInstTerm.h +++ b/src/nl/nl/pnl/PNLInstTerm.h @@ -45,7 +45,7 @@ class PNLInstTerm final: public PNLNetComponent { PNLInstTerm(PNLInstance* instance, PNLBitTerm* term); static PNLInstTerm* create(PNLInstance* instance, PNLBitTerm* term); static void preCreate(const PNLInstance* instance, const PNLBitTerm* term); - void postCreate(); + void postCreate() override; void preDestroy() override; void destroyFromInstance(); diff --git a/src/nl/nl/pnl/PNLInstance.cpp b/src/nl/nl/pnl/PNLInstance.cpp index 3419d7175..2cd72b6fb 100644 --- a/src/nl/nl/pnl/PNLInstance.cpp +++ b/src/nl/nl/pnl/PNLInstance.cpp @@ -20,7 +20,7 @@ namespace NL { PNLInstance::PNLInstance(PNLDesign* design, PNLDesign* model, const NLName& name) - : super(), design_(design), model_(model), name_(name) {} + : super(), design_(design), model_(model), name_(name) {} void PNLInstance::postCreateAndSetID() { super::postCreate(); @@ -28,6 +28,12 @@ void PNLInstance::postCreateAndSetID() { commonPostCreate(); } +void PNLInstance::postCreate() { + super::postCreate(); + getDesign()->addInstance(this); + commonPostCreate(); +} + PNLInstance* PNLInstance::create(PNLDesign* design, PNLDesign* model, const NLName& name) { diff --git a/src/nl/nl/pnl/PNLInstance.h b/src/nl/nl/pnl/PNLInstance.h index eb6117cc1..b3d9e7d7b 100644 --- a/src/nl/nl/pnl/PNLInstance.h +++ b/src/nl/nl/pnl/PNLInstance.h @@ -66,7 +66,7 @@ class PNLInstance final: public PNLDesignObject { static void preCreate(PNLDesign* design, const PNLDesign* model, const NLName& name); void commonPostCreate(); void postCreateAndSetID(); - void postCreate(); + void postCreate() override; void createInstTerm(PNLBitTerm* term); void removeInstTerm(PNLBitTerm* term); void commonPreDestroy(); diff --git a/src/nl/nl/pnl/PNLNet.h b/src/nl/nl/pnl/PNLNet.h index 3c7f1106b..dfe9528a0 100644 --- a/src/nl/nl/pnl/PNLNet.h +++ b/src/nl/nl/pnl/PNLNet.h @@ -89,7 +89,7 @@ class PNLNet: public PNLDesignObject { PNLNet() = default; static void preCreate(); - void postCreate(); + void postCreate() override; void preDestroy() override; private: diff --git a/src/nl/nl/pnl/PNLNetComponent.h b/src/nl/nl/pnl/PNLNetComponent.h index 9e74ff2ea..4f85be607 100644 --- a/src/nl/nl/pnl/PNLNetComponent.h +++ b/src/nl/nl/pnl/PNLNetComponent.h @@ -61,7 +61,7 @@ class PNLNetComponent: public PNLDesignObject { PNLNetComponent() = default; static void preCreate(); - void postCreate(); + void postCreate() override; void preDestroy() override; private: diff --git a/src/nl/nl/pnl/PNLScalarNet.h b/src/nl/nl/pnl/PNLScalarNet.h index bbadcac38..8763a8f87 100644 --- a/src/nl/nl/pnl/PNLScalarNet.h +++ b/src/nl/nl/pnl/PNLScalarNet.h @@ -55,7 +55,7 @@ class PNLScalarNet final: public PNLBitNet { PNLScalarNet(PNLDesign* design, NLID::DesignObjectID id, const NLName& name); static void preCreate(const PNLDesign* design, const NLName& name); static void preCreate(const PNLDesign* design, NLID::DesignObjectID id, const NLName& name); - void postCreate(); + void postCreate() override; void postCreateAndSetID(); void destroyFromDesign() override; void commonPreDestroy(); diff --git a/src/nl/nl/pnl/PNLScalarTerm.h b/src/nl/nl/pnl/PNLScalarTerm.h index 40756d739..a6240c4fd 100644 --- a/src/nl/nl/pnl/PNLScalarTerm.h +++ b/src/nl/nl/pnl/PNLScalarTerm.h @@ -59,7 +59,7 @@ class PNLScalarTerm final: public PNLBitTerm { static void preCreate(PNLDesign* design, const NLName& name); static void preCreate(PNLDesign* design, NLID::DesignObjectID id, const NLName& name); void postCreateAndSetID(); - void postCreate(); + void postCreate() override; void destroyFromDesign() override; //PNLTerm* clone(PNLDesign* design) const override; void commonPreDestroy(); diff --git a/src/nl/nl/pnl/PNLTerm.h b/src/nl/nl/pnl/PNLTerm.h index f207832a5..b0ed4f288 100644 --- a/src/nl/nl/pnl/PNLTerm.h +++ b/src/nl/nl/pnl/PNLTerm.h @@ -54,7 +54,7 @@ class PNLTerm: public PNLNetComponent { PNLTerm() = default; static void preCreate(); - void postCreate(); + void postCreate() override; void preDestroy() override; private: diff --git a/src/nl/nl/snl/SNLAttributes.h b/src/nl/nl/snl/SNLAttributes.h index 842b7bcfa..8c7ce8d41 100644 --- a/src/nl/nl/snl/SNLAttributes.h +++ b/src/nl/nl/snl/SNLAttributes.h @@ -19,7 +19,7 @@ class SNLAttributeValue { enum class Type { NUMBER, STRING }; SNLAttributeValue() = default; SNLAttributeValue(const SNLAttributeValue&) = default; - SNLAttributeValue(const std::string& value): type_(Type::STRING), value_(value) {}; + explicit SNLAttributeValue(const std::string& value): type_(Type::STRING), value_(value) {}; SNLAttributeValue(Type type, const std::string& value): type_(type), value_(value) {}; std::string getString() const { return value_; } bool isString() const { return type_ == Type::STRING; } @@ -53,7 +53,7 @@ class SNLAttribute { //Values are either numbers or strings. //but stored as strings. SNLAttribute() = default; //LCOV_EXCL_LINE - SNLAttribute(const NLName& name, const SNLAttributeValue& value=SNLAttributeValue()); + explicit SNLAttribute(const NLName& name, const SNLAttributeValue& value=SNLAttributeValue()); SNLAttribute(const SNLAttribute&) = default; NLName getName() const { return name_; } diff --git a/src/nl/nl/snl/SNLBitNet.h b/src/nl/nl/snl/SNLBitNet.h index 826005a4d..a0ee231bd 100644 --- a/src/nl/nl/snl/SNLBitNet.h +++ b/src/nl/nl/snl/SNLBitNet.h @@ -44,7 +44,7 @@ class SNLBitNet: public SNLNet { protected: SNLBitNet() = default; static void preCreate(); - void postCreate(); + void postCreate() override; void preDestroy() override; void cloneComponents(SNLBitNet* newNet) const; diff --git a/src/nl/nl/snl/SNLBitTerm.h b/src/nl/nl/snl/SNLBitTerm.h index 9d81be2ff..9e7619aab 100644 --- a/src/nl/nl/snl/SNLBitTerm.h +++ b/src/nl/nl/snl/SNLBitTerm.h @@ -31,7 +31,7 @@ class SNLBitTerm: public SNLTerm { protected: SNLBitTerm() = default; static void preCreate(); - void postCreate(); + void postCreate() override; void preDestroy() override; private: SNLBitNet* net_ { nullptr }; diff --git a/src/nl/nl/snl/SNLBusNet.h b/src/nl/nl/snl/SNLBusNet.h index 0b7151c59..d4a02f0f9 100644 --- a/src/nl/nl/snl/SNLBusNet.h +++ b/src/nl/nl/snl/SNLBusNet.h @@ -100,7 +100,7 @@ class SNLBusNet final: public SNLNet { static void preCreate(const SNLDesign* design, NLID::DesignObjectID id, const NLName& name); void createBits(); void postCreateAndSetID(); - void postCreate(); + void postCreate() override; void destroyFromDesign() override; void commonPreDestroy(); void preDestroy() override; diff --git a/src/nl/nl/snl/SNLBusNetBit.h b/src/nl/nl/snl/SNLBusNetBit.h index 2653e54ad..a9dd80837 100644 --- a/src/nl/nl/snl/SNLBusNetBit.h +++ b/src/nl/nl/snl/SNLBusNetBit.h @@ -38,7 +38,7 @@ class SNLBusNetBit final: public SNLBitNet { SNLBusNetBit(SNLBusNet* bus, NLID::Bit bit); static void preCreate(const SNLBusNet* bus, NLID::Bit bit); - void postCreate(); + void postCreate() override; void destroyFromBus(); void destroyFromDesign() override {} //LCOV_EXCL_LINE void commonPreDestroy(); diff --git a/src/nl/nl/snl/SNLBusTerm.h b/src/nl/nl/snl/SNLBusTerm.h index 10ce2ee90..ebcc3cf3a 100644 --- a/src/nl/nl/snl/SNLBusTerm.h +++ b/src/nl/nl/snl/SNLBusTerm.h @@ -103,7 +103,7 @@ class SNLBusTerm final: public SNLTerm { static void preCreate(const SNLDesign* design, const NLName& name); static void preCreate(const SNLDesign* design, NLID::DesignObjectID id, const NLName& name); void createBits(); - void postCreate(); + void postCreate() override; void postCreateAndSetID(); void destroyFromDesign() override; SNLTerm* clone(SNLDesign* design) const override; diff --git a/src/nl/nl/snl/SNLBusTermBit.h b/src/nl/nl/snl/SNLBusTermBit.h index 0c4c632c2..27f200647 100644 --- a/src/nl/nl/snl/SNLBusTermBit.h +++ b/src/nl/nl/snl/SNLBusTermBit.h @@ -47,7 +47,7 @@ class SNLBusTermBit final: public SNLBitTerm { SNLBusTermBit(SNLBusTerm* bus, NLID::Bit bit); static void preCreate(const SNLBusTerm* bus, NLID::Bit bit); - void postCreate(); + void postCreate() override; void destroyFromBus(); void destroyFromDesign() override {} //LCOV_EXCL_LINE SNLTerm* clone(SNLDesign* design) const override { return nullptr; } //LCOV_EXCL_LINE diff --git a/src/nl/nl/snl/SNLDesign.h b/src/nl/nl/snl/SNLDesign.h index 5a2c11728..1017ca572 100644 --- a/src/nl/nl/snl/SNLDesign.h +++ b/src/nl/nl/snl/SNLDesign.h @@ -301,7 +301,7 @@ class SNLDesign final: public NLObject { static void preCreate(const NLLibrary* library, NLID::DesignID id, Type type, const NLName& name); void destroyFromLibrary(); void postCreateAndSetID(); - void postCreate(); + void postCreate() override; void commonPreDestroy(); void preDestroy() override; void addTerm(SNLTerm* term); diff --git a/src/nl/nl/snl/SNLDesignObject.h b/src/nl/nl/snl/SNLDesignObject.h index 5f39a55b9..a694c3970 100644 --- a/src/nl/nl/snl/SNLDesignObject.h +++ b/src/nl/nl/snl/SNLDesignObject.h @@ -70,7 +70,7 @@ class SNLDesignObject: public NLObject { protected: SNLDesignObject() = default; - void postCreate(); + void postCreate() override; void preDestroy() override; }; diff --git a/src/nl/nl/snl/SNLInstParameter.cpp b/src/nl/nl/snl/SNLInstParameter.cpp index b24cc7f7f..68b34d263 100644 --- a/src/nl/nl/snl/SNLInstParameter.cpp +++ b/src/nl/nl/snl/SNLInstParameter.cpp @@ -41,9 +41,9 @@ void SNLInstParameter::preCreate(SNLInstance* instance, SNLParameter* parameter) } } -void SNLInstParameter::destroy() { +void SNLInstParameter::preDestroy() { instance_->removeInstParameter(this); - delete this; + super::preDestroy(); } void SNLInstParameter::destroyFromInstance() { diff --git a/src/nl/nl/snl/SNLInstParameter.h b/src/nl/nl/snl/SNLInstParameter.h index 6f504ddb9..f4e8a4e40 100644 --- a/src/nl/nl/snl/SNLInstParameter.h +++ b/src/nl/nl/snl/SNLInstParameter.h @@ -18,6 +18,7 @@ class SNLParameter; class SNLInstParameter : public NajaObject { public: friend class SNLInstance; + using super = NajaObject; SNLInstParameter() = delete; SNLInstParameter(const SNLInstParameter&) = delete; @@ -30,8 +31,6 @@ class SNLInstParameter : public NajaObject { * \return The new instance parameter. */ static SNLInstParameter* create(SNLInstance* instance, SNLParameter* parameter, const std::string& value); - /// \brief Destroy this instance parameter. - void destroy(); /// \return The name of the parameter. NLName getName() const; /// \return The instance to which this instance parameter belongs. @@ -42,9 +41,9 @@ class SNLInstParameter : public NajaObject { std::string getValue() const { return value_; } void setValue(const std::string& value) { value_ = value; } - const char* getTypeName() const; - std::string getString() const; - std::string getDescription() const; + const char* getTypeName() const override; + std::string getString() const override; + std::string getDescription() const override; friend bool operator< (const SNLInstParameter& lp, const SNLInstParameter& rp) { return lp.getName() < rp.getName(); @@ -61,7 +60,8 @@ class SNLInstParameter : public NajaObject { private: SNLInstParameter(SNLInstance* instance, SNLParameter* parameter, const std::string& value); static void preCreate(SNLInstance* instance, SNLParameter* parameter); - void postCreate(); + void postCreate() override; + void preDestroy() override; void destroyFromInstance(); SNLInstance* instance_ {nullptr}; diff --git a/src/nl/nl/snl/SNLInstTerm.h b/src/nl/nl/snl/SNLInstTerm.h index ab3a0785c..4d3d82cfd 100644 --- a/src/nl/nl/snl/SNLInstTerm.h +++ b/src/nl/nl/snl/SNLInstTerm.h @@ -46,13 +46,13 @@ class SNLInstTerm final: public SNLNetComponent { SNLInstTerm(SNLInstance* instance, SNLBitTerm* term); static SNLInstTerm* create(SNLInstance* instance, SNLBitTerm* term); static void preCreate(const SNLInstance* instance, const SNLBitTerm* term); - void postCreate(); + void postCreate() override; void preDestroy() override; void destroyFromInstance(); SNLInstance* instance_; SNLBitTerm* bitTerm_; - SNLBitNet* net_ { nullptr}; + SNLBitNet* net_ { nullptr }; }; }} // namespace NL // namespace naja diff --git a/src/nl/nl/snl/SNLInstance.h b/src/nl/nl/snl/SNLInstance.h index 68cfa20e9..de8ae3ba5 100644 --- a/src/nl/nl/snl/SNLInstance.h +++ b/src/nl/nl/snl/SNLInstance.h @@ -158,7 +158,7 @@ class SNLInstance final: public SNLDesignObject { static void preCreate(SNLDesign* design, const SNLDesign* model, NLID::DesignObjectID id, const NLName& name); void commonPostCreate(); void postCreateAndSetID(); - void postCreate(); + void postCreate() override; void commonPreDestroy(); void addInstParameter(SNLInstParameter* instParameter); void removeInstParameter(SNLInstParameter* instParameter); diff --git a/src/nl/nl/snl/SNLNet.h b/src/nl/nl/snl/SNLNet.h index 49adf435e..63eeb9399 100644 --- a/src/nl/nl/snl/SNLNet.h +++ b/src/nl/nl/snl/SNLNet.h @@ -96,7 +96,7 @@ class SNLNet: public SNLDesignObject { SNLNet() = default; static void preCreate(); - void postCreate(); + void postCreate() override; void preDestroy() override; private: @@ -110,4 +110,4 @@ class SNLNet: public SNLDesignObject { }} // namespace NL // namespace naja -#endif // __SNL_NET_H_ \ No newline at end of file +#endif // __SNL_NET_H_ diff --git a/src/nl/nl/snl/SNLNetComponent.h b/src/nl/nl/snl/SNLNetComponent.h index d1a1f8714..f22bc7fbd 100644 --- a/src/nl/nl/snl/SNLNetComponent.h +++ b/src/nl/nl/snl/SNLNetComponent.h @@ -58,7 +58,7 @@ class SNLNetComponent: public SNLDesignObject { SNLNetComponent() = default; static void preCreate(); - void postCreate(); + void postCreate() override; void preDestroy() override; private: @@ -67,4 +67,4 @@ class SNLNetComponent: public SNLDesignObject { }} // namespace NL // namespace naja -#endif // __SNL_NET_COMPONENT_H_ \ No newline at end of file +#endif // __SNL_NET_COMPONENT_H_ diff --git a/src/nl/nl/snl/SNLParameter.h b/src/nl/nl/snl/SNLParameter.h index e63a23bfa..9bb057668 100644 --- a/src/nl/nl/snl/SNLParameter.h +++ b/src/nl/nl/snl/SNLParameter.h @@ -86,4 +86,4 @@ class SNLParameter : public NajaObject { }} // namespace NL // namespace naja -#endif // __SNL_PARAMETER_H_ \ No newline at end of file +#endif // __SNL_PARAMETER_H_ diff --git a/src/nl/nl/snl/SNLScalarNet.h b/src/nl/nl/snl/SNLScalarNet.h index 364472fd5..2faf86a01 100644 --- a/src/nl/nl/snl/SNLScalarNet.h +++ b/src/nl/nl/snl/SNLScalarNet.h @@ -55,7 +55,7 @@ class SNLScalarNet final: public SNLBitNet { SNLScalarNet(SNLDesign* design, NLID::DesignObjectID id, const NLName& name); static void preCreate(const SNLDesign* design, const NLName& name); static void preCreate(const SNLDesign* design, NLID::DesignObjectID id, const NLName& name); - void postCreate(); + void postCreate() override; void postCreateAndSetID(); void destroyFromDesign() override; void commonPreDestroy(); diff --git a/src/nl/nl/snl/SNLScalarTerm.h b/src/nl/nl/snl/SNLScalarTerm.h index 9a7a2793a..375254287 100644 --- a/src/nl/nl/snl/SNLScalarTerm.h +++ b/src/nl/nl/snl/SNLScalarTerm.h @@ -59,7 +59,7 @@ class SNLScalarTerm final: public SNLBitTerm { static void preCreate(SNLDesign* design, const NLName& name); static void preCreate(SNLDesign* design, NLID::DesignObjectID id, const NLName& name); void postCreateAndSetID(); - void postCreate(); + void postCreate() override; void destroyFromDesign() override; SNLTerm* clone(SNLDesign* design) const override; void commonPreDestroy(); diff --git a/src/nl/nl/snl/SNLTerm.h b/src/nl/nl/snl/SNLTerm.h index 477fb4d63..a70d8dfe5 100644 --- a/src/nl/nl/snl/SNLTerm.h +++ b/src/nl/nl/snl/SNLTerm.h @@ -52,7 +52,7 @@ class SNLTerm: public SNLNetComponent { SNLTerm() = default; static void preCreate(); - void postCreate(); + void postCreate() override; void preDestroy() override; private: diff --git a/src/nl/nl/snl/SNLUniquifier.cpp b/src/nl/nl/snl/SNLUniquifier.cpp index 75f6c8ade..8d27742a6 100644 --- a/src/nl/nl/snl/SNLUniquifier.cpp +++ b/src/nl/nl/snl/SNLUniquifier.cpp @@ -23,7 +23,6 @@ SNLUniquifier::SNLUniquifier(const SNLPath& path, bool uniquifyTail): } void SNLUniquifier::process() { - std::vector instancesToDelete; #ifdef DEBUG_PRINTS // LCOV_EXCL_START printf("SNLUniquifier::process() - dnlid %s\n", id_); diff --git a/src/nl/nl/snl/SNLUniquifier.h b/src/nl/nl/snl/SNLUniquifier.h index c157974e0..7067d6ecd 100644 --- a/src/nl/nl/snl/SNLUniquifier.h +++ b/src/nl/nl/snl/SNLUniquifier.h @@ -20,7 +20,7 @@ class SNLUniquifier { :path_(path), id_(std::to_string(id)), uniquifyTail_(uniquifyTail) {} SNLUniquifier(const std::vector& path, std::string id, bool uniquifyTail = false) :path_(path), id_(id), uniquifyTail_(uniquifyTail) {} - SNLUniquifier(const SNLPath& path, bool uniquifyTail = true); + explicit SNLUniquifier(const SNLPath& path, bool uniquifyTail = true); void process(); SNLInstance* replaceWithClone(SNLInstance* inst); std::vector& getPathUniq() { return pathUniq_; } diff --git a/test/core/NajaPrivatePropertyTest.cpp b/test/core/NajaPrivatePropertyTest.cpp index 6a0f9193e..547ab94e7 100644 --- a/test/core/NajaPrivatePropertyTest.cpp +++ b/test/core/NajaPrivatePropertyTest.cpp @@ -25,7 +25,7 @@ class TestObject: public NajaObject { return "TestObject"; } - void postCreate() { + void postCreate() override { super::postCreate(); } diff --git a/test/nl/python/naja_wrapping/NajaPythonPropertyTest.cpp b/test/nl/python/naja_wrapping/NajaPythonPropertyTest.cpp index 3429112e0..6ea3f5da0 100644 --- a/test/nl/python/naja_wrapping/NajaPythonPropertyTest.cpp +++ b/test/nl/python/naja_wrapping/NajaPythonPropertyTest.cpp @@ -25,7 +25,7 @@ class TestObject: public NajaObject { return "TestObject"; } - void postCreate() { + void postCreate() override { super::postCreate(); } From 9652b8415632047a435594e7bb8a9c7182c81a03 Mon Sep 17 00:00:00 2001 From: xtof Date: Fri, 19 Sep 2025 12:44:08 +0200 Subject: [PATCH 3/3] code cleaning --- src/nl/nl/pnl/PNLInstance.cpp | 25 ++++++++----------------- src/nl/nl/pnl/PNLInstance.h | 17 +++++++---------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/nl/nl/pnl/PNLInstance.cpp b/src/nl/nl/pnl/PNLInstance.cpp index 2cd72b6fb..1afd7b016 100644 --- a/src/nl/nl/pnl/PNLInstance.cpp +++ b/src/nl/nl/pnl/PNLInstance.cpp @@ -17,10 +17,12 @@ namespace naja { namespace NL { -PNLInstance::PNLInstance(PNLDesign* design, - PNLDesign* model, - const NLName& name) - : super(), design_(design), model_(model), name_(name) {} +PNLInstance::PNLInstance(PNLDesign* design, PNLDesign* model, const NLName& name): + super(), + design_(design), + model_(model), + name_(name) +{} void PNLInstance::postCreateAndSetID() { super::postCreate(); @@ -28,25 +30,14 @@ void PNLInstance::postCreateAndSetID() { commonPostCreate(); } -void PNLInstance::postCreate() { - super::postCreate(); - getDesign()->addInstance(this); - commonPostCreate(); -} - -PNLInstance* PNLInstance::create(PNLDesign* design, - PNLDesign* model, - const NLName& name) { - +PNLInstance* PNLInstance::create(PNLDesign* design, PNLDesign* model, const NLName& name) { preCreate(design, model, name); auto instance = new PNLInstance(design, model, name); instance->postCreateAndSetID(); return instance; } -void PNLInstance::preCreate(PNLDesign* design, - const PNLDesign* model, - const NLName& name) { +void PNLInstance::preCreate(PNLDesign* design, const PNLDesign* model, const NLName& name) { super::preCreate(); if (not design) { std::ostringstream reason; diff --git a/src/nl/nl/pnl/PNLInstance.h b/src/nl/nl/pnl/PNLInstance.h index b3d9e7d7b..ef111ff87 100644 --- a/src/nl/nl/pnl/PNLInstance.h +++ b/src/nl/nl/pnl/PNLInstance.h @@ -61,28 +61,25 @@ class PNLInstance final: public PNLDesignObject { const PNLPoint& getOrigin() const { return origin_; } private: - PNLInstance(PNLDesign* design, PNLDesign* model, const NLName& name); static void preCreate(PNLDesign* design, const PNLDesign* model, const NLName& name); void commonPostCreate(); void postCreateAndSetID(); - void postCreate() override; void createInstTerm(PNLBitTerm* term); void removeInstTerm(PNLBitTerm* term); void commonPreDestroy(); void preDestroy() override; - PNLDesign* design_ {nullptr}; - PNLDesign* model_ {nullptr}; + PNLDesign* design_ {nullptr}; + PNLDesign* model_ {nullptr}; NLID::DesignObjectID id_; - PNLInstanceInstTerms instTerms_ {}; - NLName name_ {}; - PNLPoint origin_ {0, 0}; + PNLInstanceInstTerms instTerms_ {}; + NLName name_ {}; + PNLPoint origin_ {0, 0}; PNLTransform transform_; - PlacementStatus placementStatus_ {Unplaced}; - boost::intrusive::set_member_hook<> designInstancesHook_ {}; + PlacementStatus placementStatus_ {Unplaced}; + boost::intrusive::set_member_hook<> designInstancesHook_ {}; boost::intrusive::set_member_hook<> designSlaveInstancesHook_ {}; - }; }} // namespace NL // namespace naja \ No newline at end of file