Skip to content

Commit

Permalink
[CORRECTIVE] Fix mode validation to use mode condition parser instead…
Browse files Browse the repository at this point in the history
… of IpxactSystemVerilogExpressionParser.

[ADDITIVE] Add interface for creating and handling expression parsers. Add ModeConditionParserInterface for use in validators.
[ADDITIVE] Update mode validation to use hierarchical validation in editors.
  • Loading branch information
hagantsa committed Oct 4, 2024
1 parent f70c2f2 commit c81e957
Show file tree
Hide file tree
Showing 38 changed files with 506 additions and 57 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ IPXACTmodels/GeneratedFiles
GeneratedFiles/
.vs
x64/Debug
PythonAPI/x64/Debug
PythonAPI/x64/Debug

*.obj
*.tlog
26 changes: 20 additions & 6 deletions IPXACTmodels/Component/validators/ComponentValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ComponentValidator.h"

#include <KactusAPI/include/ExpressionParser.h>
#include <KactusAPI/include/ModeConditionParserInterface.h>

#include <IPXACTmodels/Component/Component.h>
#include <IPXACTmodels/Component/BusInterface.h>
Expand Down Expand Up @@ -67,7 +68,9 @@
//-----------------------------------------------------------------------------
// Function: ComponentValidator::ComponentValidator()
//-----------------------------------------------------------------------------
ComponentValidator::ComponentValidator(QSharedPointer<ExpressionParser> parser, LibraryInterface* library, Document::Revision docRevision) :
ComponentValidator::ComponentValidator(QSharedPointer<ExpressionParser> parser,
QSharedPointer<ModeConditionParserBaseInterface> modeConditionParserInterface,
LibraryInterface* library, Document::Revision docRevision) :
component_(),
busInterfaceValidator_(),
indirectInterfaceValidator_(),
Expand All @@ -85,7 +88,8 @@ fileSetValidator_(),
cpuValidator_(),
otherClockDriverValidator_(),
parameterValidator_(),
assertionValidator_()
assertionValidator_(),
modeConditionParserInterface_(modeConditionParserInterface)
{
parameterValidator_ = QSharedPointer<ParameterValidator>(new ParameterValidator(parser,
QSharedPointer<QList<QSharedPointer<Choice> > > (), docRevision));
Expand All @@ -112,7 +116,8 @@ assertionValidator_()
remapStateValidator_ = QSharedPointer<RemapStateValidator>(
new RemapStateValidator(parser, QSharedPointer<QList<QSharedPointer<Port> > > ()));

modeValidator_ = QSharedPointer<ModeValidator>(new ModeValidator(component_, parser));
modeConditionParser_ = modeConditionParserInterface_->createParser();
modeValidator_ = QSharedPointer<ModeValidator>(new ModeValidator(component_, modeConditionParser_));

QSharedPointer<EnumeratedValueValidator> enumValidator (new EnumeratedValueValidator(parser));
QSharedPointer<FieldValidator> fieldValidator (new FieldValidator(parser, enumValidator, parameterValidator_, docRevision));
Expand Down Expand Up @@ -215,7 +220,6 @@ bool ComponentValidator::hasValidBusInterfaces(QSharedPointer<Component> compone
return busIfsValidator_->validate(component->getBusInterfaces(), component->getRevision());
}


//-----------------------------------------------------------------------------
// Function: ComponentValidator::hasValidIndirectInterfaces()
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -294,15 +298,20 @@ bool ComponentValidator::hasValidModes(QSharedPointer<Component> component)
{
changeComponent(component);

QVector<QString> modeNames;
modeConditionParserInterface_->setModes(modeConditionParser_, component->getModes());

QSet<QString> modeNames;
for (QSharedPointer<Mode> 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;
Expand Down Expand Up @@ -710,8 +719,13 @@ void ComponentValidator::findErrorsInModes(QVector<QString>& 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.")
Expand Down
16 changes: 13 additions & 3 deletions IPXACTmodels/Component/validators/ComponentValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class AssertionValidator;

class ExpressionParser;
class LibraryInterface;
class ModeConditionParserBaseInterface;

//-----------------------------------------------------------------------------
//! Validator for the ipxact:component.
Expand All @@ -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<ExpressionParser> parser, LibraryInterface* library, Document::Revision docRevision);
ComponentValidator(QSharedPointer<ExpressionParser> parser,
QSharedPointer<ModeConditionParserBaseInterface> modeConditionParserInterface,
LibraryInterface* library, Document::Revision docRevision);

//! The destructor.
~ComponentValidator() = default;
Expand Down Expand Up @@ -589,6 +593,12 @@ class IPXACTMODELS_EXPORT ComponentValidator
//! Validator for validating all indirect interfaces together.
QSharedPointer<IndirectInterfacesValidator> indirectInterfacesValidator_;

//! Interface for creating and managing mode condition parser.
QSharedPointer<ModeConditionParserBaseInterface> modeConditionParserInterface_;

//! The mode condition parser to use.
QSharedPointer<ExpressionParser> modeConditionParser_;

//! Validator for validating all cpus together.
QSharedPointer<CPUsValidator> cpusValidator_;

Expand Down
8 changes: 8 additions & 0 deletions IPXACTmodels/Component/validators/FieldSliceValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ void FieldSliceValidator::componentChange(QSharedPointer<Component> newComponent
component_ = newComponent;
}

//-----------------------------------------------------------------------------
// Function: FieldSliceValidator::setExpressionParser()
//-----------------------------------------------------------------------------
void FieldSliceValidator::setExpressionParser(QSharedPointer<ExpressionParser> expressionParser)
{
expressionParser_ = expressionParser;
}

//-----------------------------------------------------------------------------
// Function: FieldSliceValidator::isInValidRange()
//-----------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions IPXACTmodels/Component/validators/FieldSliceValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ class IPXACTMODELS_EXPORT FieldSliceValidator
*/
void componentChange(QSharedPointer<Component> newComponent);

/*!
* Set the expression parser to be used.
*
* @param [in] expressionParser The expression parser to set.
*/
void setExpressionParser(QSharedPointer<ExpressionParser> expressionParser);

private:

/* Check if the given value is in the given range.
Expand Down
30 changes: 27 additions & 3 deletions IPXACTmodels/Component/validators/ModeValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
ModeValidator::ModeValidator(
QSharedPointer<Component> component,
QSharedPointer<ExpressionParser> 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)
{

Expand Down Expand Up @@ -66,6 +67,11 @@ bool ModeValidator::validate(QSharedPointer<Mode> mode) const
return false;
}

if (validComparedToSiblings(mode) == false)
{
return false;
}

return true;
}

Expand Down Expand Up @@ -216,3 +222,21 @@ QSharedPointer<FieldSliceValidator> ModeValidator::getFieldSliceValidator() cons
{
return fieldValidator_;
}

//-----------------------------------------------------------------------------
// Function: ModeValidator::setConditionParser()
//-----------------------------------------------------------------------------
void ModeValidator::setConditionParser(QSharedPointer<ExpressionParser> expressionParser)
{
expressionParser_ = expressionParser;
portValidator_->setExpressionParser(expressionParser);
fieldValidator_->setExpressionParser(expressionParser);
}

//-----------------------------------------------------------------------------
// Function: ModeValidator::getConditionParser()
//-----------------------------------------------------------------------------
QSharedPointer<ExpressionParser> ModeValidator::getConditionParser() const
{
return expressionParser_;
}
12 changes: 11 additions & 1 deletion IPXACTmodels/Component/validators/ModeValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <IPXACTmodels/Component/validators/PortSliceValidator.h>
#include <IPXACTmodels/Component/validators/FieldSliceValidator.h>
#include <IPXACTmodels/Component/validators/CollectionValidators.h>

#include <QSharedPointer>
#include <QString>
Expand All @@ -30,7 +31,7 @@ class BuildCommand;
//-----------------------------------------------------------------------------
//! Validator for ipxact:File.
//-----------------------------------------------------------------------------
class IPXACTMODELS_EXPORT ModeValidator
class IPXACTMODELS_EXPORT ModeValidator : public HierarchicalValidator
{
public:

Expand Down Expand Up @@ -103,6 +104,15 @@ class IPXACTMODELS_EXPORT ModeValidator
//! Get the field slice validator.
QSharedPointer<FieldSliceValidator> getFieldSliceValidator() const;

/*!
* Set the mode condition expression parser.
*
* @param [in] expressionParser The parser to set.
*/
void setConditionParser(QSharedPointer<ExpressionParser> expressionParser);

QSharedPointer<ExpressionParser> getConditionParser() const;

private:

//! The port slice validator to use.
Expand Down
8 changes: 8 additions & 0 deletions IPXACTmodels/Component/validators/PortSliceValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ void PortSliceValidator::componentChange(QSharedPointer<Component> newComponent)
component_ = newComponent;
}

//-----------------------------------------------------------------------------
// Function: PortSliceValidator::setExpressionParser()
//-----------------------------------------------------------------------------
void PortSliceValidator::setExpressionParser(QSharedPointer<ExpressionParser> expressionParser)
{
expressionParser_ = expressionParser;
}

//-----------------------------------------------------------------------------
// Function: PortSliceValidator::isInValidRange()
//-----------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions IPXACTmodels/Component/validators/PortSliceValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ class IPXACTMODELS_EXPORT PortSliceValidator
*/
void componentChange(QSharedPointer<Component> newComponent);

/*!
* Set the expression parser to be used.
*
* @param [in] expressionParser The expression parser to set.
*/
void setExpressionParser(QSharedPointer<ExpressionParser> expressionParser);

private:

/* Check if the given value is in the given range.
Expand Down
13 changes: 8 additions & 5 deletions KactusAPI/KactusAPI.pri
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down Expand Up @@ -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 \
Expand All @@ -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
3 changes: 3 additions & 0 deletions KactusAPI/KactusAPI.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
<ClInclude Include="include\MemoryRemapExpressionGatherer.h" />
<ClInclude Include="include\MessageMediator.h" />
<ClInclude Include="include\ModeConditionParser.h" />
<ClInclude Include="include\ExpressionParserInterface.h" />
<ClInclude Include="include\ModeConditionParserInterface.h" />
<ClInclude Include="include\ModelParameterSource.h" />
<ClInclude Include="include\ModelParameterVisualizer.h" />
<ClInclude Include="include\ModeReferenceInterface.h" />
Expand Down Expand Up @@ -125,6 +127,7 @@
<ClCompile Include="expressions\RegisterExpressionsGatherer.cpp" />
<ClCompile Include="expressions\RegisterFileExpressionsGatherer.cpp" />
<ClCompile Include="expressions\SystemVerilogExpressionParser.cpp" />
<ClCompile Include="include\ModeConditionParserInterface.cpp" />
<ClCompile Include="interfaces\bus\AbstractionTypeInterface.cpp" />
<ClCompile Include="interfaces\bus\PortAbstractionInterface.cpp" />
<ClCompile Include="interfaces\common\AbstractParameterInterface.cpp" />
Expand Down
15 changes: 12 additions & 3 deletions KactusAPI/KactusAPI.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,16 @@
<Filter>Header Files\include</Filter>
</ClInclude>
<ClInclude Include="include\LibraryLoader.h">
<Filter>Generated Files</Filter>
<Filter>Header Files\include</Filter>
</ClInclude>
<ClInclude Include="include\NullChannel.h">
<Filter>Generated Files</Filter>
<Filter>Header Files\include</Filter>
</ClInclude>
<ClInclude Include="include\ExpressionParserInterface.h">
<Filter>Header Files\include</Filter>
</ClInclude>
<ClInclude Include="include\ModeConditionParserInterface.h">
<Filter>Header Files\include</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -510,7 +516,10 @@
<Filter>Source Files\interfaces\component</Filter>
</ClCompile>
<ClCompile Include="utilities\NullChannel.cpp">
<Filter>Generated Files</Filter>
<Filter>Source Files\utilities</Filter>
</ClCompile>
<ClCompile Include="include\ModeConditionParserInterface.cpp">
<Filter>Source Files\expressions</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
Expand Down
Loading

0 comments on commit c81e957

Please sign in to comment.