diff --git a/.gitignore b/.gitignore index 71c43675e..8e9102792 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,7 @@ IPXACTmodels/GeneratedFiles GeneratedFiles/ .vs x64/Debug -PythonAPI/x64/Debug \ No newline at end of file +PythonAPI/x64/Debug + +*.obj +*.tlog \ No newline at end of file diff --git a/IPXACTmodels/Component/validators/ComponentValidator.cpp b/IPXACTmodels/Component/validators/ComponentValidator.cpp index cac2c061b..09ad0cbf9 100644 --- a/IPXACTmodels/Component/validators/ComponentValidator.cpp +++ b/IPXACTmodels/Component/validators/ComponentValidator.cpp @@ -12,6 +12,7 @@ #include "ComponentValidator.h" #include +#include #include #include @@ -67,7 +68,9 @@ //----------------------------------------------------------------------------- // Function: ComponentValidator::ComponentValidator() //----------------------------------------------------------------------------- -ComponentValidator::ComponentValidator(QSharedPointer parser, LibraryInterface* library, Document::Revision docRevision) : +ComponentValidator::ComponentValidator(QSharedPointer parser, + QSharedPointer modeConditionParserInterface, + LibraryInterface* library, Document::Revision docRevision) : component_(), busInterfaceValidator_(), indirectInterfaceValidator_(), @@ -85,7 +88,8 @@ fileSetValidator_(), cpuValidator_(), otherClockDriverValidator_(), parameterValidator_(), -assertionValidator_() +assertionValidator_(), +modeConditionParserInterface_(modeConditionParserInterface) { parameterValidator_ = QSharedPointer(new ParameterValidator(parser, QSharedPointer > > (), docRevision)); @@ -112,7 +116,8 @@ assertionValidator_() remapStateValidator_ = QSharedPointer( new RemapStateValidator(parser, QSharedPointer > > ())); - modeValidator_ = QSharedPointer(new ModeValidator(component_, parser)); + modeConditionParser_ = modeConditionParserInterface_->createParser(); + modeValidator_ = QSharedPointer(new ModeValidator(component_, modeConditionParser_)); QSharedPointer enumValidator (new EnumeratedValueValidator(parser)); QSharedPointer fieldValidator (new FieldValidator(parser, enumValidator, parameterValidator_, docRevision)); @@ -215,7 +220,6 @@ bool ComponentValidator::hasValidBusInterfaces(QSharedPointer compone return busIfsValidator_->validate(component->getBusInterfaces(), component->getRevision()); } - //----------------------------------------------------------------------------- // Function: ComponentValidator::hasValidIndirectInterfaces() //----------------------------------------------------------------------------- @@ -294,15 +298,20 @@ bool ComponentValidator::hasValidModes(QSharedPointer component) { changeComponent(component); - QVector modeNames; + modeConditionParserInterface_->setModes(modeConditionParser_, component->getModes()); + + QSet modeNames; for (QSharedPointer mode : *component->getModes()) { + modeConditionParserInterface_->setFieldSlices(modeConditionParser_, mode->getFieldSlices()); + modeConditionParserInterface_->setPortSlices(modeConditionParser_, mode->getPortSlices()); + if (modeNames.contains(mode->name()) || !modeValidator_->validate(mode)) { return false; } - modeNames.append(mode->name()); + modeNames.insert(mode->name()); } return true; @@ -710,8 +719,13 @@ void ComponentValidator::findErrorsInModes(QVector& errors, QSharedPoin { QStringList modeNames; QStringList duplicateNames; + modeConditionParserInterface_->setModes(modeConditionParser_, component->getModes()); + for (auto const& mode : *component->getModes()) { + modeConditionParserInterface_->setFieldSlices(modeConditionParser_, mode->getFieldSlices()); + modeConditionParserInterface_->setPortSlices(modeConditionParser_, mode->getPortSlices()); + if (modeNames.contains(mode->name()) && !duplicateNames.contains(mode->name())) { errors.append(QObject::tr("Mode name %1 within %2 is not unique.") diff --git a/IPXACTmodels/Component/validators/ComponentValidator.h b/IPXACTmodels/Component/validators/ComponentValidator.h index a6e0df5e9..7acc5cf39 100644 --- a/IPXACTmodels/Component/validators/ComponentValidator.h +++ b/IPXACTmodels/Component/validators/ComponentValidator.h @@ -46,6 +46,7 @@ class AssertionValidator; class ExpressionParser; class LibraryInterface; +class ModeConditionParserBaseInterface; //----------------------------------------------------------------------------- //! Validator for the ipxact:component. @@ -57,10 +58,13 @@ class IPXACTMODELS_EXPORT ComponentValidator /*! * The constructor. * - * @param [in] parser The used expression parser. - * @param [in] library The used library interface. + * @param [in] parser The used expression parser. + * @param [in] modeConditionParserInterface The interface used to create and manage the mode condition parser. + * @param [in] library The used library interface. */ - ComponentValidator(QSharedPointer parser, LibraryInterface* library, Document::Revision docRevision); + ComponentValidator(QSharedPointer parser, + QSharedPointer modeConditionParserInterface, + LibraryInterface* library, Document::Revision docRevision); //! The destructor. ~ComponentValidator() = default; @@ -589,6 +593,12 @@ class IPXACTMODELS_EXPORT ComponentValidator //! Validator for validating all indirect interfaces together. QSharedPointer indirectInterfacesValidator_; + //! Interface for creating and managing mode condition parser. + QSharedPointer modeConditionParserInterface_; + + //! The mode condition parser to use. + QSharedPointer modeConditionParser_; + //! Validator for validating all cpus together. QSharedPointer cpusValidator_; diff --git a/IPXACTmodels/Component/validators/FieldSliceValidator.cpp b/IPXACTmodels/Component/validators/FieldSliceValidator.cpp index c1bddca87..69e9a5a80 100644 --- a/IPXACTmodels/Component/validators/FieldSliceValidator.cpp +++ b/IPXACTmodels/Component/validators/FieldSliceValidator.cpp @@ -168,6 +168,14 @@ void FieldSliceValidator::componentChange(QSharedPointer newComponent component_ = newComponent; } +//----------------------------------------------------------------------------- +// Function: FieldSliceValidator::setExpressionParser() +//----------------------------------------------------------------------------- +void FieldSliceValidator::setExpressionParser(QSharedPointer expressionParser) +{ + expressionParser_ = expressionParser; +} + //----------------------------------------------------------------------------- // Function: FieldSliceValidator::isInValidRange() //----------------------------------------------------------------------------- diff --git a/IPXACTmodels/Component/validators/FieldSliceValidator.h b/IPXACTmodels/Component/validators/FieldSliceValidator.h index aa9fe28b7..984a9251f 100644 --- a/IPXACTmodels/Component/validators/FieldSliceValidator.h +++ b/IPXACTmodels/Component/validators/FieldSliceValidator.h @@ -110,6 +110,13 @@ class IPXACTMODELS_EXPORT FieldSliceValidator */ void componentChange(QSharedPointer newComponent); + /*! + * Set the expression parser to be used. + * + * @param [in] expressionParser The expression parser to set. + */ + void setExpressionParser(QSharedPointer expressionParser); + private: /* Check if the given value is in the given range. diff --git a/IPXACTmodels/Component/validators/ModeValidator.cpp b/IPXACTmodels/Component/validators/ModeValidator.cpp index be30c3698..8f95aae33 100644 --- a/IPXACTmodels/Component/validators/ModeValidator.cpp +++ b/IPXACTmodels/Component/validators/ModeValidator.cpp @@ -25,9 +25,10 @@ ModeValidator::ModeValidator( QSharedPointer component, QSharedPointer expressionParser): - portValidator_(new PortSliceValidator(component, expressionParser)), - fieldValidator_(new FieldSliceValidator(component, expressionParser)), - component_(component), +HierarchicalValidator(), +portValidator_(new PortSliceValidator(component, expressionParser)), +fieldValidator_(new FieldSliceValidator(component, expressionParser)), +component_(component), expressionParser_(expressionParser) { @@ -66,6 +67,11 @@ bool ModeValidator::validate(QSharedPointer mode) const return false; } + if (validComparedToSiblings(mode) == false) + { + return false; + } + return true; } @@ -216,3 +222,21 @@ QSharedPointer ModeValidator::getFieldSliceValidator() cons { return fieldValidator_; } + +//----------------------------------------------------------------------------- +// Function: ModeValidator::setConditionParser() +//----------------------------------------------------------------------------- +void ModeValidator::setConditionParser(QSharedPointer expressionParser) +{ + expressionParser_ = expressionParser; + portValidator_->setExpressionParser(expressionParser); + fieldValidator_->setExpressionParser(expressionParser); +} + +//----------------------------------------------------------------------------- +// Function: ModeValidator::getConditionParser() +//----------------------------------------------------------------------------- +QSharedPointer ModeValidator::getConditionParser() const +{ + return expressionParser_; +} diff --git a/IPXACTmodels/Component/validators/ModeValidator.h b/IPXACTmodels/Component/validators/ModeValidator.h index c382f6d12..5dc81c9fe 100644 --- a/IPXACTmodels/Component/validators/ModeValidator.h +++ b/IPXACTmodels/Component/validators/ModeValidator.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -30,7 +31,7 @@ class BuildCommand; //----------------------------------------------------------------------------- //! Validator for ipxact:File. //----------------------------------------------------------------------------- -class IPXACTMODELS_EXPORT ModeValidator +class IPXACTMODELS_EXPORT ModeValidator : public HierarchicalValidator { public: @@ -103,6 +104,15 @@ class IPXACTMODELS_EXPORT ModeValidator //! Get the field slice validator. QSharedPointer getFieldSliceValidator() const; + /*! + * Set the mode condition expression parser. + * + * @param [in] expressionParser The parser to set. + */ + void setConditionParser(QSharedPointer expressionParser); + + QSharedPointer getConditionParser() const; + private: //! The port slice validator to use. diff --git a/IPXACTmodels/Component/validators/PortSliceValidator.cpp b/IPXACTmodels/Component/validators/PortSliceValidator.cpp index 7e888332a..2160dc3f2 100644 --- a/IPXACTmodels/Component/validators/PortSliceValidator.cpp +++ b/IPXACTmodels/Component/validators/PortSliceValidator.cpp @@ -188,6 +188,14 @@ void PortSliceValidator::componentChange(QSharedPointer newComponent) component_ = newComponent; } +//----------------------------------------------------------------------------- +// Function: PortSliceValidator::setExpressionParser() +//----------------------------------------------------------------------------- +void PortSliceValidator::setExpressionParser(QSharedPointer expressionParser) +{ + expressionParser_ = expressionParser; +} + //----------------------------------------------------------------------------- // Function: PortSliceValidator::isInValidRange() //----------------------------------------------------------------------------- diff --git a/IPXACTmodels/Component/validators/PortSliceValidator.h b/IPXACTmodels/Component/validators/PortSliceValidator.h index cb2b957b0..1e75546b3 100644 --- a/IPXACTmodels/Component/validators/PortSliceValidator.h +++ b/IPXACTmodels/Component/validators/PortSliceValidator.h @@ -108,6 +108,13 @@ class IPXACTMODELS_EXPORT PortSliceValidator */ void componentChange(QSharedPointer newComponent); + /*! + * Set the expression parser to be used. + * + * @param [in] expressionParser The expression parser to set. + */ + void setExpressionParser(QSharedPointer expressionParser); + private: /* Check if the given value is in the given range. diff --git a/KactusAPI/KactusAPI.pri b/KactusAPI/KactusAPI.pri index 62632a08a..039effd06 100644 --- a/KactusAPI/KactusAPI.pri +++ b/KactusAPI/KactusAPI.pri @@ -46,6 +46,7 @@ HEADERS += ./KactusAPI.h \ ./include/IPluginUtility.h \ ./include/IPXactSystemVerilogParser.h \ ./include/LibraryInterface.h \ + ./include/LibraryLoader.h \ ./include/ListHelper.h \ ./include/ListParameterFinder.h \ ./include/MasterPortInterface.h \ @@ -55,12 +56,15 @@ HEADERS += ./KactusAPI.h \ ./include/MemoryRemapExpressionGatherer.h \ ./include/MessageMediator.h \ ./include/ModeConditionParser.h \ + ./include/ExpressionParserInterface.h \ + ./include/ModeConditionParserInterface.h \ ./include/ModelParameterSource.h \ ./include/ModelParameterVisualizer.h \ ./include/ModeReferenceInterface.h \ ./include/ModuleParameterInterface.h \ ./include/MultipleParameterFinder.h \ ./include/NameGroupInterface.h \ + ./include/NullChannel.h \ ./include/NullParser.h \ ./include/ParameterFinder.h \ ./include/ParameterizableInterface.h \ @@ -89,10 +93,8 @@ HEADERS += ./KactusAPI.h \ ./include/ImportRunner.h \ ./include/LibraryHandler.h \ ./include/LibraryItem.h \ - ./include/LibraryLoader.h \ ./include/LibraryTreeModel.h \ - ./include/ParameterCache.h \ - ./include/NullChannel.h + ./include/ParameterCache.h SOURCES += ./KactusAPI.cpp \ ./expressions/AddressBlockExpressionsGatherer.cpp \ ./expressions/AddressSpaceExpressionsGatherer.cpp \ @@ -115,6 +117,7 @@ SOURCES += ./KactusAPI.cpp \ ./expressions/RegisterExpressionsGatherer.cpp \ ./expressions/RegisterFileExpressionsGatherer.cpp \ ./expressions/SystemVerilogExpressionParser.cpp \ + ./include/ModeConditionParserInterface.cpp \ ./interfaces/bus/AbstractionTypeInterface.cpp \ ./interfaces/bus/PortAbstractionInterface.cpp \ ./interfaces/component/AccessPolicyInterface.cpp \ @@ -152,6 +155,7 @@ SOURCES += ./KactusAPI.cpp \ ./plugins/PluginUtilityAdapter.cpp \ ./utilities/ConsoleMediator.cpp \ ./utilities/FileHandler.cpp \ + ./utilities/NullChannel.cpp \ ./utilities/utils.cpp \ ./utilities/VersionHelper.cpp \ ./library/DocumentFileAccess.cpp \ @@ -162,5 +166,4 @@ SOURCES += ./KactusAPI.cpp \ ./library/LibraryItem.cpp \ ./library/LibraryLoader.cpp \ ./library/LibraryTreeModel.cpp \ - ./library/TagManager.cpp \ - ./utilities/NullChannel.cpp + ./library/TagManager.cpp diff --git a/KactusAPI/KactusAPI.vcxproj b/KactusAPI/KactusAPI.vcxproj index 94968d6d3..812bed57d 100644 --- a/KactusAPI/KactusAPI.vcxproj +++ b/KactusAPI/KactusAPI.vcxproj @@ -71,6 +71,8 @@ + + @@ -125,6 +127,7 @@ + diff --git a/KactusAPI/KactusAPI.vcxproj.filters b/KactusAPI/KactusAPI.vcxproj.filters index b70d2b06e..cc58da9ae 100644 --- a/KactusAPI/KactusAPI.vcxproj.filters +++ b/KactusAPI/KactusAPI.vcxproj.filters @@ -292,10 +292,16 @@ Header Files\include - Generated Files + Header Files\include - Generated Files + Header Files\include + + + Header Files\include + + + Header Files\include @@ -510,7 +516,10 @@ Source Files\interfaces\component - Generated Files + Source Files\utilities + + + Source Files\expressions diff --git a/KactusAPI/expressions/ModeConditionParser.cpp b/KactusAPI/expressions/ModeConditionParser.cpp index 8ea99bc9e..2b8f024d4 100644 --- a/KactusAPI/expressions/ModeConditionParser.cpp +++ b/KactusAPI/expressions/ModeConditionParser.cpp @@ -29,6 +29,30 @@ ModeConditionParser::ModeConditionParser(QSharedPointer finder, } +//----------------------------------------------------------------------------- +// Function: ModeConditionParser::setFieldSlices() +//----------------------------------------------------------------------------- +void ModeConditionParser::setFieldSlices(FieldSlice::List fieldSlices) +{ + fieldSlices_ = fieldSlices; +} + +//----------------------------------------------------------------------------- +// Function: ModeConditionParser::setPortSlices() +//----------------------------------------------------------------------------- +void ModeConditionParser::setPortSlices(PortSlice::List portSlices) +{ + portSlices_ = portSlices; +} + +//----------------------------------------------------------------------------- +// Function: ModeConditionParser::setModes() +//----------------------------------------------------------------------------- +void ModeConditionParser::setModes(Mode::List modes) +{ + modes_ = modes; +} + //----------------------------------------------------------------------------- // Function: ModeConditionParser::isSymbol() //----------------------------------------------------------------------------- diff --git a/KactusAPI/include/ExpressionParserInterface.h b/KactusAPI/include/ExpressionParserInterface.h new file mode 100644 index 000000000..e5c0b63f5 --- /dev/null +++ b/KactusAPI/include/ExpressionParserInterface.h @@ -0,0 +1,39 @@ +//----------------------------------------------------------------------------- +// File: ExpressionParserInterface.h +//----------------------------------------------------------------------------- +// Project: Kactus 2 +// Author: Anton Hagqvist +// Date: 26.09.2024 +// +// Description: +// Base class for parser interfaces for creating and handling expression parsers. +//----------------------------------------------------------------------------- + +#ifndef EXPRESSIONPARSERINTERFACE_H +#define EXPRESSIONPARSERINTERFACE_H + +#include +#include + +#include + +class ExpressionParserInterface +{ +public: + + ExpressionParserInterface() = default; + virtual ~ExpressionParserInterface() = default; + + ExpressionParserInterface(const ExpressionParserInterface& other) = delete; + ExpressionParserInterface& operator=(const ExpressionParserInterface& other) = delete; + + /*! + * Create the expression parser. + * + * @return The created expression parser. + */ + virtual QSharedPointer createParser() = 0; + +}; + +#endif // EXPRESSIONPARSERINTERFACE_H \ No newline at end of file diff --git a/KactusAPI/include/ModeConditionParser.h b/KactusAPI/include/ModeConditionParser.h index dce4d4ef0..15a7d732c 100644 --- a/KactusAPI/include/ModeConditionParser.h +++ b/KactusAPI/include/ModeConditionParser.h @@ -43,6 +43,27 @@ class KACTUS2_API ModeConditionParser : public IPXactSystemVerilogParser ModeConditionParser(ModeConditionParser const& rhs) = delete; ModeConditionParser& operator=(ModeConditionParser const& rhs) = delete; + /*! + * Set the mode-specific field slices to use while parsing expressions. + * + * @param [in] fieldSlices The field slices to set. + */ + void setFieldSlices(FieldSlice::List fieldSlices); + + /*! + * Set the mode-specific port slices to use while parsing expressions. + * + * @param [in] portSlices The port slices to set. + */ + void setPortSlices(PortSlice::List portSlices); + + /*! + * Set the available modes to use while parsing expressions. + * + * @param [in] modes The modes to set. + */ + void setModes(Mode::List modes); + protected: /*! diff --git a/KactusAPI/include/ModeConditionParserInterface.cpp b/KactusAPI/include/ModeConditionParserInterface.cpp new file mode 100644 index 000000000..14490b4c0 --- /dev/null +++ b/KactusAPI/include/ModeConditionParserInterface.cpp @@ -0,0 +1,56 @@ +//----------------------------------------------------------------------------- +// File: ModeConditionParserInterface.cpp +//----------------------------------------------------------------------------- +// Project: Kactus 2 +// Author: Anton Hagqvist +// Date: 27.09.2024 +// +// Description: +// Interface for creating and handling expression parsers for mode conditions. The base interface is independent of +// KactusAPI and should be used in IPXACTmodels validators. +//----------------------------------------------------------------------------- + +#include "ModeConditionParserInterface.h" + +#include + +//----------------------------------------------------------------------------- +// Function: ModeConditionParserInterface::ModeConditionParserInterface() +//----------------------------------------------------------------------------- +ModeConditionParserInterface::ModeConditionParserInterface(QSharedPointer parameterFinder): + parameterFinder_(parameterFinder) +{ + +} + +//----------------------------------------------------------------------------- +// Function: ModeConditionParserInterface::createParser() +//----------------------------------------------------------------------------- +QSharedPointer ModeConditionParserInterface::createParser() +{ + return QSharedPointer(new ModeConditionParser(parameterFinder_, nullptr, nullptr, nullptr)); +} + +//----------------------------------------------------------------------------- +// Function: ModeConditionParserInterface::setFieldSlices() +//----------------------------------------------------------------------------- +void ModeConditionParserInterface::setFieldSlices(QSharedPointer expressionParser, FieldSlice::List fieldSlices) +{ + expressionParser.staticCast()->setFieldSlices(fieldSlices); +} + +//----------------------------------------------------------------------------- +// Function: ModeConditionParserInterface::setPortSlices() +//----------------------------------------------------------------------------- +void ModeConditionParserInterface::setPortSlices(QSharedPointer expressionParser, PortSlice::List portSlices) +{ + expressionParser.staticCast()->setPortSlices(portSlices); +} + +//----------------------------------------------------------------------------- +// Function: ModeConditionParserInterface::setModes() +//----------------------------------------------------------------------------- +void ModeConditionParserInterface::setModes(QSharedPointer expressionParser, Mode::List modes) +{ + expressionParser.staticCast()->setModes(modes); +} diff --git a/KactusAPI/include/ModeConditionParserInterface.h b/KactusAPI/include/ModeConditionParserInterface.h new file mode 100644 index 000000000..9c16c7a88 --- /dev/null +++ b/KactusAPI/include/ModeConditionParserInterface.h @@ -0,0 +1,108 @@ +//----------------------------------------------------------------------------- +// File: ModeConditionParserFactory.h +//----------------------------------------------------------------------------- +// Project: Kactus 2 +// Author: Anton Hagqvist +// Date: 27.09.2024 +// +// Description: +// Interface for creating and handling expression parsers for mode conditions. The base interface is independent of +// KactusAPI and should be used in IPXACTmodels validators. +//----------------------------------------------------------------------------- + +#ifndef MODECONDITIONPARSERINTERFACE_H +#define MODECONDITIONPARSERINTERFACE_H + +#include "ExpressionParserInterface.h" +#include + +#include +#include +#include + +class ExpressionParser; +class ParameterFinder; + +class ModeConditionParserBaseInterface : public ExpressionParserInterface +{ +public: + + ModeConditionParserBaseInterface() = default; + ~ModeConditionParserBaseInterface() override = default; + + //! No copying, no assignment. + ModeConditionParserBaseInterface(ModeConditionParserBaseInterface const& other) = delete; + ModeConditionParserBaseInterface& operator=(ModeConditionParserBaseInterface const& other) = delete; + + /*! + * Set the field slices of the selected mode condition parser. + * + * @param [in] expressionParser The mode condition parser to set the field slices to. + * @param [in] fieldSlices The field slices to set. + */ + virtual void setFieldSlices(QSharedPointer expressionParser, FieldSlice::List fieldSlices) = 0; + + /*! + * Set the port slices of the selected mode condition parser. + * + * @param [in] expressionParser The mode condition parser to set the port slices to. + * @param [in] portSlices The port slices to set. + */ + virtual void setPortSlices(QSharedPointer expressionParser, PortSlice::List portSlices) = 0; + + /*! + * Set the available modes to the selected mode condition parser. + * + * @param [in] expressionParser The mode condition parser to update. + * @param [in] modes The modes to set. + */ + virtual void setModes(QSharedPointer expressionParser, Mode::List modes) = 0; +}; + +class KACTUS2_API ModeConditionParserInterface : public ModeConditionParserBaseInterface +{ +public: + explicit ModeConditionParserInterface(QSharedPointer parameterFinder); + ~ModeConditionParserInterface() final = default; + + ModeConditionParserInterface(ModeConditionParserInterface const& other) = delete; + ModeConditionParserInterface& operator=(ModeConditionParserInterface const& other) = delete; + + /*! + * Create the expression parser. + * + * @return The created expression parser. + */ + [[nodiscard]] QSharedPointer createParser() final; + + /*! + * Set the mode-specific field slices to use while parsing expressions. + * + * @param [in] expressionParser The parser whose field slices to set. + * @param [in] fieldSlices The field slices to set. + */ + void setFieldSlices(QSharedPointer expressionParser, FieldSlice::List fieldSlices) final; + + /*! + * Set the mode-specific port slices to use while parsing expressions. + * + * @param [in] expressionParser The parser whose port slices to set. + * @param [in] portSlices The port slices to set. + */ + void setPortSlices(QSharedPointer expressionParser, PortSlice::List portSlices) final; + + /*! + * Set the available modes to use while parsing expressions. + * + * @param [in] expressionParser The parser whose modes to set. + * @param [in] modes The modes to set. + */ + void setModes(QSharedPointer expressionParser, Mode::List modes) final; + +private: + + //! Parameter finder to use in the expression parser. + QSharedPointer parameterFinder_; +}; + +#endif // MODECONDITIONPARSERINTERFACE_H diff --git a/KactusAPI/library/DocumentValidator.cpp b/KactusAPI/library/DocumentValidator.cpp index 792354455..f1a97718a 100644 --- a/KactusAPI/library/DocumentValidator.cpp +++ b/KactusAPI/library/DocumentValidator.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -61,8 +62,10 @@ bool DocumentValidator::validate(QSharedPointer document) QSharedPointer currentComponent = document.dynamicCast(); changeComponentValidatorParameterFinder(currentComponent); + QSharedPointer modeConditionParserInterface(new ModeConditionParserInterface(componentValidatorFinder_)); + ComponentValidator componentValidator(QSharedPointer( - new IPXactSystemVerilogParser(componentValidatorFinder_)), library_, currentComponent->getRevision()); + new IPXactSystemVerilogParser(componentValidatorFinder_)), modeConditionParserInterface, library_, currentComponent->getRevision()); return componentValidator.validate(currentComponent); } @@ -159,8 +162,9 @@ void DocumentValidator::findErrorsInAbstractionDefinition(QSharedPointer component, QVector& errorList) { changeComponentValidatorParameterFinder(component); + QSharedPointer parserFactory(new ModeConditionParserInterface(componentValidatorFinder_)); ComponentValidator componentValidator(QSharedPointer( - new IPXactSystemVerilogParser(componentValidatorFinder_)), library_, component->getRevision()); + new IPXactSystemVerilogParser(componentValidatorFinder_)), parserFactory, library_, component->getRevision()); componentValidator.findErrorsIn(errorList, component); } diff --git a/editors/ComponentEditor/componenteditor.cpp b/editors/ComponentEditor/componenteditor.cpp index d2df75719..6cadd34ed 100644 --- a/editors/ComponentEditor/componenteditor.cpp +++ b/editors/ComponentEditor/componenteditor.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -97,7 +98,8 @@ referenceCounter_(QSharedPointer(new Compone fullParameterFinder_, component))), expressionFormatter_(new ExpressionFormatter(parameterFinder_)), expressionParser_(new IPXactSystemVerilogParser(parameterFinder_)), -validator_(new ComponentValidator(expressionParser_, getLibHandler(), component->getRevision())) +modeConditionParserInterface_(new ModeConditionParserInterface(parameterFinder_)), +validator_(new ComponentValidator(expressionParser_, modeConditionParserInterface_, getLibHandler(), component->getRevision())) { QSharedPointer fullFormatter(new ExpressionFormatter(fullParameterFinder_)); parameterReferenceTree_ = diff --git a/editors/ComponentEditor/componenteditor.h b/editors/ComponentEditor/componenteditor.h index 0ed64eb83..90b1a0676 100644 --- a/editors/ComponentEditor/componenteditor.h +++ b/editors/ComponentEditor/componenteditor.h @@ -71,6 +71,7 @@ class PortMapInterface; class TransparentBridgeInterface; class PortMapValidator; class BusInterfaceInterface; +class ModeConditionParserInterface; //----------------------------------------------------------------------------- //! The editor to edit/packet IP-Xact components. @@ -399,6 +400,9 @@ private slots: //! The used expression parser. QSharedPointer expressionParser_; + //! The mode condition parser interface to use in the component validator. + QSharedPointer modeConditionParserInterface_; + //! The used component validator. QSharedPointer validator_; diff --git a/editors/ComponentEditor/general/generaleditor.cpp b/editors/ComponentEditor/general/generaleditor.cpp index 940fd03e4..22f8c6fc7 100644 --- a/editors/ComponentEditor/general/generaleditor.cpp +++ b/editors/ComponentEditor/general/generaleditor.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -45,7 +46,8 @@ GeneralEditor::GeneralEditor(LibraryInterface* libHandler, QSharedPointergetRevision())), + modeConditionParserInterface_(new ModeConditionParserInterface(finder_)), + validator_(new ComponentValidator(parser_, modeConditionParserInterface_, libHandler, component->getRevision())), library_(libHandler) { Q_ASSERT(libHandler != 0); diff --git a/editors/ComponentEditor/general/generaleditor.h b/editors/ComponentEditor/general/generaleditor.h index 6a774f401..8799ec847 100644 --- a/editors/ComponentEditor/general/generaleditor.h +++ b/editors/ComponentEditor/general/generaleditor.h @@ -33,6 +33,7 @@ class Component; class LibraryInterface; class Document; class KactusAttributeEditor; +class ModeConditionParserInterface; //----------------------------------------------------------------------------- @@ -147,6 +148,9 @@ private slots: //! Expression parser for validator. QSharedPointer parser_; + //! The mode condition parser factory to use in the component validator. + QSharedPointer modeConditionParserInterface_; + //! Validator for checking the component compliance. QSharedPointer validator_; diff --git a/editors/ComponentEditor/modes/SingleModeEditor.cpp b/editors/ComponentEditor/modes/SingleModeEditor.cpp index 4d03dd25c..3939ee371 100644 --- a/editors/ComponentEditor/modes/SingleModeEditor.cpp +++ b/editors/ComponentEditor/modes/SingleModeEditor.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -118,6 +119,18 @@ void SingleModeEditor::onConditionChanged() { mode_->setCondition(newCondition); + auto parser = validator_->getConditionParser(); + auto parserCast = parser.dynamicCast(); + + Q_ASSERT_X(parserCast, "SingleModeEditor::onConditionChanged()", "Could not cast mode condition parser"); + if (!parserCast) + { + return; + } + + parserCast->setFieldSlices(mode_->getFieldSlices()); + parserCast->setPortSlices(mode_->getPortSlices()); + conditionStatus_.setHidden(validator_->hasValidCondition(mode_)); emit contentChanged(); } diff --git a/editors/ComponentEditor/treeStructure/ComponentEditorIndirectInterfacesItem.h b/editors/ComponentEditor/treeStructure/ComponentEditorIndirectInterfacesItem.h index bf63389a1..ba3ed270e 100644 --- a/editors/ComponentEditor/treeStructure/ComponentEditorIndirectInterfacesItem.h +++ b/editors/ComponentEditor/treeStructure/ComponentEditorIndirectInterfacesItem.h @@ -93,6 +93,11 @@ class ComponentEditorIndirectInterfacesItem : public ComponentEditorItem */ virtual void createChild(int index) override; + /*! + * Check the validity of this item. + * + * @return bool True if item is in valid state. + */ bool isValid() const override; private: diff --git a/editors/ComponentEditor/treeStructure/ComponentInstantiationsItem.h b/editors/ComponentEditor/treeStructure/ComponentInstantiationsItem.h index 8edef3137..6ded03fbb 100644 --- a/editors/ComponentEditor/treeStructure/ComponentInstantiationsItem.h +++ b/editors/ComponentEditor/treeStructure/ComponentInstantiationsItem.h @@ -90,6 +90,11 @@ class ComponentInstantiationsItem : public ComponentEditorItem */ virtual void createChild(int index); + /*! + * Check the validity of this item. + * + * @return bool True if item is in valid state. + */ bool isValid() const override; private: diff --git a/editors/ComponentEditor/treeStructure/DesignConfigurationInstantiationsItem.h b/editors/ComponentEditor/treeStructure/DesignConfigurationInstantiationsItem.h index e11147597..e920f7ea0 100644 --- a/editors/ComponentEditor/treeStructure/DesignConfigurationInstantiationsItem.h +++ b/editors/ComponentEditor/treeStructure/DesignConfigurationInstantiationsItem.h @@ -101,6 +101,7 @@ class DesignConfigurationInstantiationsItem : public ComponentEditorItem //! Expression parser to use. QSharedPointer expressionParser_; + //! Validator used to validate all instantiations together. QSharedPointer allInstantiationsValidator_; }; diff --git a/editors/ComponentEditor/treeStructure/DesignInstantiationsItem.h b/editors/ComponentEditor/treeStructure/DesignInstantiationsItem.h index 9a1e86099..89d003085 100644 --- a/editors/ComponentEditor/treeStructure/DesignInstantiationsItem.h +++ b/editors/ComponentEditor/treeStructure/DesignInstantiationsItem.h @@ -99,6 +99,7 @@ class DesignInstantiationsItem : public ComponentEditorItem //! The finder for component parameters. QSharedPointer componentParameterFinder_; + //! Validator used to validate all instantiations together. QSharedPointer allInstantiationsValidator_; }; diff --git a/editors/ComponentEditor/treeStructure/ModesItem.cpp b/editors/ComponentEditor/treeStructure/ModesItem.cpp index d56d29e46..df666e237 100644 --- a/editors/ComponentEditor/treeStructure/ModesItem.cpp +++ b/editors/ComponentEditor/treeStructure/ModesItem.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -32,12 +33,16 @@ ModesItem::ModesItem(ComponentEditorTreeModel* model, LibraryInterface* libHandl ComponentEditorItem* parent): ComponentEditorItem(model, libHandler, component, parent), modes_(component->getModes()), -expressions_(expressions) +expressions_(expressions), +modeValidator_(new ModeValidator(component, nullptr)), +modesValidator_(new HierarchicalValidator()) { setParameterFinder(expressions.finder); setExpressionFormatter(expressions.formatter); setReferenceCounter(referenceCounter); + modesValidator_->setChildValidator(modeValidator_); + const auto MODE_COUNT = modes_->count(); for (int i = 0; i < MODE_COUNT; ++i) { @@ -103,12 +108,20 @@ void ModesItem::createChild(int index) QSharedPointer parser(new ModeConditionParser(expressions_.finder, mode->getPortSlices(), mode->getFieldSlices(), component_->getModes())); - QSharedPointer validator(new ModeValidator(component_, parser)); - QSharedPointer modeItem(new SingleModeItem(mode, model_, - libHandler_, component_, referenceCounter_, expressions_, validator, this)); + libHandler_, component_, referenceCounter_, expressions_, modeValidator_, parser, this)); modeItem->setLocked(locked_); childItems_.insert(index, modeItem); } + +//----------------------------------------------------------------------------- +// Function: ModesItem::isValid() +//----------------------------------------------------------------------------- +bool ModesItem::isValid() const +{ + auto modesAsNameGroup = CollectionValidators::itemListToNameGroupList(modes_); + modesValidator_->childrenHaveUniqueNames(modesAsNameGroup); + return ComponentEditorItem::isValid(); +} diff --git a/editors/ComponentEditor/treeStructure/ModesItem.h b/editors/ComponentEditor/treeStructure/ModesItem.h index 80040b736..0d2a826be 100644 --- a/editors/ComponentEditor/treeStructure/ModesItem.h +++ b/editors/ComponentEditor/treeStructure/ModesItem.h @@ -19,6 +19,7 @@ class ExpressionParser; class Mode; class ModeValidator; +class HierarchicalValidator; //----------------------------------------------------------------------------- //! The Modes-item used in the component editor navigation tree. @@ -88,6 +89,13 @@ class ModesItem : public ComponentEditorItem */ virtual void createChild(int index); + /*! + * Check the validity of this item. + * + * @return bool True if item is in valid state. + */ + bool isValid() const override; + private: //! No copying ModesItem(const ModesItem& other); @@ -100,6 +108,12 @@ class ModesItem : public ComponentEditorItem ExpressionSet expressions_; + //! The mode validator to use. + QSharedPointer modeValidator_; + + //! The validator to validate modes together. + QSharedPointer modesValidator_; + }; #endif // MODESITEM_H diff --git a/editors/ComponentEditor/treeStructure/SingleDesignConfigurationInstantiationItem.h b/editors/ComponentEditor/treeStructure/SingleDesignConfigurationInstantiationItem.h index eae916075..6aacc59f0 100644 --- a/editors/ComponentEditor/treeStructure/SingleDesignConfigurationInstantiationItem.h +++ b/editors/ComponentEditor/treeStructure/SingleDesignConfigurationInstantiationItem.h @@ -113,6 +113,7 @@ class SingleDesignConfigurationInstantiationItem : public ParameterizableItem //! Expression formatter, formats the referencing expressions. QSharedPointer expressionFormatter_; + //! Expression parser to use. QSharedPointer expressionParser_; }; diff --git a/editors/ComponentEditor/treeStructure/SingleModeItem.cpp b/editors/ComponentEditor/treeStructure/SingleModeItem.cpp index c830277c0..8f85c277d 100644 --- a/editors/ComponentEditor/treeStructure/SingleModeItem.cpp +++ b/editors/ComponentEditor/treeStructure/SingleModeItem.cpp @@ -22,14 +22,14 @@ //----------------------------------------------------------------------------- SingleModeItem::SingleModeItem(QSharedPointer mode, ComponentEditorTreeModel* model, LibraryInterface* libHandler, QSharedPointer component, - QSharedPointer referenceCounter, - ExpressionSet expressions, - QSharedPointer validator, + QSharedPointer referenceCounter, ExpressionSet expressions, + QSharedPointer validator, QSharedPointer modeConditionParser, ComponentEditorItem* parent) : ComponentEditorItem(model, libHandler, component, parent), - mode_(mode), - validator_(validator), - expressions_(expressions) +mode_(mode), +validator_(validator), +expressions_(expressions), +modeConditionParser_(modeConditionParser) { setParameterFinder(expressions_.finder); setExpressionFormatter(expressions_.formatter); @@ -57,6 +57,7 @@ QString SingleModeItem::text() const //----------------------------------------------------------------------------- bool SingleModeItem::isValid() const { + validator_->setConditionParser(modeConditionParser_); // Each mode item has its own condition parser. return validator_->validate(mode_); } @@ -79,5 +80,6 @@ ItemEditor* SingleModeItem::editor() connectItemEditorToReferenceCounter(); } + validator_->setConditionParser(modeConditionParser_); // Update validator parser, every mode has own parser return editor_; } diff --git a/editors/ComponentEditor/treeStructure/SingleModeItem.h b/editors/ComponentEditor/treeStructure/SingleModeItem.h index 8020d62f7..90ed03944 100644 --- a/editors/ComponentEditor/treeStructure/SingleModeItem.h +++ b/editors/ComponentEditor/treeStructure/SingleModeItem.h @@ -18,6 +18,7 @@ class Mode; class ModeValidator; +class ModeConditionParser; //----------------------------------------------------------------------------- //! The single Mode item used in the component editor navigation tree. @@ -37,15 +38,13 @@ class SingleModeItem: public ComponentEditorItem * @param [in] component The component being edited. * @param [in] referenceCounter The counter for parameter references. * @param [in] expressions The collection of objects for expression handling. + * @param [in] modeConditionParser The mode condition parser to use. * @param [in] parent The parent item. */ - SingleModeItem(QSharedPointer mode, - ComponentEditorTreeModel* model, - LibraryInterface* libHandler, - QSharedPointer component, - QSharedPointer referenceCounter, - ExpressionSet expressions, - QSharedPointer validator, + SingleModeItem(QSharedPointer mode, ComponentEditorTreeModel* model, + LibraryInterface* libHandler, QSharedPointer component, + QSharedPointer referenceCounter, ExpressionSet expressions, + QSharedPointer validator, QSharedPointer modeConditionParser, ComponentEditorItem* parent); /*! @@ -89,8 +88,6 @@ class SingleModeItem: public ComponentEditorItem private: - QSharedPointer expressionParser_; - //! Pointer to the currently selected remap state. QSharedPointer mode_; @@ -98,6 +95,9 @@ class SingleModeItem: public ComponentEditorItem ExpressionSet expressions_; + //! The mode condition parser to use. + QSharedPointer modeConditionParser_; + }; #endif // SINGLE_MODE_ITEM_H diff --git a/editors/ComponentEditor/treeStructure/componenteditoraddrspacesitem.h b/editors/ComponentEditor/treeStructure/componenteditoraddrspacesitem.h index bfc51d298..d528526a8 100644 --- a/editors/ComponentEditor/treeStructure/componenteditoraddrspacesitem.h +++ b/editors/ComponentEditor/treeStructure/componenteditoraddrspacesitem.h @@ -93,6 +93,11 @@ class ComponentEditorAddrSpacesItem : public ComponentEditorItem */ virtual void createChild(int index); + /*! + * Check the validity of this item. + * + * @return bool True if item is in valid state. + */ bool isValid() const override; private slots: diff --git a/editors/ComponentEditor/treeStructure/componenteditorbusinterfacesitem.h b/editors/ComponentEditor/treeStructure/componenteditorbusinterfacesitem.h index 715ea84dd..4de85d88a 100644 --- a/editors/ComponentEditor/treeStructure/componenteditorbusinterfacesitem.h +++ b/editors/ComponentEditor/treeStructure/componenteditorbusinterfacesitem.h @@ -104,6 +104,11 @@ class ComponentEditorBusInterfacesItem : public ComponentEditorItem */ QSharedPointer getBusInterfaceItem(const QString& interfaceName) const; + /*! + * Check the validity of this item. + * + * @return bool True if item is in valid state. + */ bool isValid() const override; signals: diff --git a/editors/ComponentEditor/treeStructure/componenteditorfilesetsitem.h b/editors/ComponentEditor/treeStructure/componenteditorfilesetsitem.h index 0f3486f74..e374cc540 100644 --- a/editors/ComponentEditor/treeStructure/componenteditorfilesetsitem.h +++ b/editors/ComponentEditor/treeStructure/componenteditorfilesetsitem.h @@ -96,6 +96,11 @@ class ComponentEditorFileSetsItem : public ComponentEditorItem */ virtual void createChild(int index); + /*! + * Check the validity of this item. + * + * @return bool True if item is in valid state. + */ bool isValid() const override; signals: diff --git a/editors/ComponentEditor/treeStructure/componenteditormemmapsitem.h b/editors/ComponentEditor/treeStructure/componenteditormemmapsitem.h index b4d9d75de..2ec7d1abd 100644 --- a/editors/ComponentEditor/treeStructure/componenteditormemmapsitem.h +++ b/editors/ComponentEditor/treeStructure/componenteditormemmapsitem.h @@ -151,11 +151,13 @@ public slots: //! No assignment. ComponentEditorMemMapsItem& operator=(const ComponentEditorMemMapsItem& other); - - // TEST + /*! + * Check the validity of this item. + * + * @return bool True if item is in valid state. + */ virtual bool isValid() const override; - /*! * Create the necessary validators for memory maps. */ diff --git a/tests/IPXACTmodels/Component/tst_ComponentValidator.cpp b/tests/IPXACTmodels/Component/tst_ComponentValidator.cpp index 78c9ac229..f5319a95a 100644 --- a/tests/IPXACTmodels/Component/tst_ComponentValidator.cpp +++ b/tests/IPXACTmodels/Component/tst_ComponentValidator.cpp @@ -10,6 +10,8 @@ //----------------------------------------------------------------------------- #include +#include +#include #include #include @@ -1636,7 +1638,12 @@ bool tst_ComponentValidator::errorIsNotFoundInErrorList(QString const& expectedE QSharedPointer tst_ComponentValidator::createComponentValidator(LibraryMock* mockLibrary) { QSharedPointer parser (new SystemVerilogExpressionParser()); - QSharedPointer componentValidator (new ComponentValidator(parser, mockLibrary, Document::Revision::Std14)); + + QSharedPointer componentParameterFinder(new ComponentParameterFinder(nullptr)); + + QSharedPointer modeConditionParserIf(new ModeConditionParserInterface(componentParameterFinder)); + + QSharedPointer componentValidator (new ComponentValidator(parser, modeConditionParserIf, mockLibrary, Document::Revision::Std14)); return componentValidator; } diff --git a/version.h b/version.h index bb695ebde..75bc4b74b 100644 --- a/version.h +++ b/version.h @@ -10,20 +10,20 @@ #ifndef VERSIONNO__H #define VERSIONNO__H -#define VERSION_FULL 3.13.571.0 +#define VERSION_FULL 3.13.591.0 #define VERSION_BASEYEAR 0 -#define VERSION_DATE "2024-09-24" -#define VERSION_TIME "10:31:38" +#define VERSION_DATE "2024-10-03" +#define VERSION_TIME "14:53:15" #define VERSION_MAJOR 3 #define VERSION_MINOR 13 -#define VERSION_BUILDNO 571 +#define VERSION_BUILDNO 591 #define VERSION_EXTEND 0 -#define VERSION_FILE 3,13,571,0 -#define VERSION_PRODUCT 3,13,571,0 -#define VERSION_FILESTR "3,13,571,0" -#define VERSION_PRODUCTSTR "3,13,571,0" +#define VERSION_FILE 3,13,591,0 +#define VERSION_PRODUCT 3,13,591,0 +#define VERSION_FILESTR "3,13,591,0" +#define VERSION_PRODUCTSTR "3,13,591,0" #endif