Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ function(append_target_property _TARGET _PROPERTY _VALUE)
endfunction()

if(LIBCELLML_COVERAGE)
append_target_property(cellml COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
append_target_property(cellml LINK_FLAGS "-fprofile-arcs -ftest-coverage")
target_compile_options(cellml PRIVATE -fprofile-arcs -ftest-coverage)
target_link_options(cellml PUBLIC $<BUILD_INTERFACE:-fprofile-arcs>)

# Share some paths with interested parties (tests)
set(GCOV_ANALYSIS_PATH "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cellml.dir" PARENT_SCOPE)
Expand All @@ -299,8 +299,8 @@ if(LIBCELLML_COVERAGE)
endif()

if(LIBCELLML_LLVM_COVERAGE)
append_target_property(cellml COMPILE_FLAGS "-fprofile-instr-generate -fcoverage-mapping")
append_target_property(cellml LINK_FLAGS "-fprofile-instr-generate")
target_compile_options(cellml PRIVATE -fprofile-instr-generate -fcoverage-mapping)
target_link_options(cellml PUBLIC $<BUILD_INTERFACE:-fprofile-instr-generate>)
endif()

install(TARGETS cellml EXPORT libcellml-targets
Expand Down
240 changes: 119 additions & 121 deletions src/analyser.cpp

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions src/analyser_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ class Analyser::AnalyserImpl: public Logger::LoggerImpl

GeneratorProfilePtr mGeneratorProfile = GeneratorProfile::create();

std::map<std::string, UnitsPtr> mStandardUnits;
std::map<AnalyserEquationAstPtr, UnitsPtr> mCiCnUnits;
std::unordered_map<std::string, UnitsPtr> mStandardUnits;
std::unordered_map<AnalyserEquationAstPtr, UnitsPtr> mCiCnUnits;

AnalyserImpl();

Expand All @@ -183,10 +183,6 @@ class Analyser::AnalyserImpl: public Logger::LoggerImpl
void analyseComponent(const ComponentPtr &component);
void analyseComponentVariables(const ComponentPtr &component);

void equivalentVariables(const VariablePtr &variable,
VariablePtrs &equivalentVariables) const;
VariablePtrs equivalentVariables(const VariablePtr &variable) const;

void analyseEquationAst(const AnalyserEquationAstPtr &ast);

void updateUnitsMapWithStandardUnit(const std::string &unitsName,
Expand Down Expand Up @@ -253,7 +249,7 @@ class Analyser::AnalyserImpl: public Logger::LoggerImpl
static bool isExternalVariable(const AnalyserInternalVariablePtr &variable);

bool isStateRateBased(const AnalyserEquationPtr &analyserEquation,
AnalyserEquationPtrs &checkedEquations);
std::unordered_set<AnalyserEquation *> &checkedEquations);

void addInvalidVariableIssue(const AnalyserInternalVariablePtr &variable,
Issue::ReferenceRule referenceRule);
Expand Down
8 changes: 4 additions & 4 deletions src/analyserequation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ size_t AnalyserEquation::stateCount() const
return mPimpl->mStates.size();
}

std::vector<AnalyserVariablePtr> AnalyserEquation::states() const
const std::vector<AnalyserVariablePtr> &AnalyserEquation::states() const
{
return mPimpl->mStates;
}
Expand All @@ -168,7 +168,7 @@ size_t AnalyserEquation::computedConstantCount() const
return mPimpl->mComputedConstants.size();
}

std::vector<AnalyserVariablePtr> AnalyserEquation::computedConstants() const
const std::vector<AnalyserVariablePtr> &AnalyserEquation::computedConstants() const
{
return mPimpl->mComputedConstants;
}
Expand All @@ -187,7 +187,7 @@ size_t AnalyserEquation::algebraicVariableCount() const
return mPimpl->mAlgebraicVariables.size();
}

std::vector<AnalyserVariablePtr> AnalyserEquation::algebraicVariables() const
const std::vector<AnalyserVariablePtr> &AnalyserEquation::algebraicVariables() const
{
return mPimpl->mAlgebraicVariables;
}
Expand All @@ -206,7 +206,7 @@ size_t AnalyserEquation::externalVariableCount() const
return mPimpl->mExternalVariables.size();
}

std::vector<AnalyserVariablePtr> AnalyserEquation::externalVariables() const
const std::vector<AnalyserVariablePtr> &AnalyserEquation::externalVariables() const
{
return mPimpl->mExternalVariables;
}
Expand Down
2 changes: 1 addition & 1 deletion src/analyserequationast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void AnalyserEquationAst::setType(Type type)
mPimpl->mType = type;
}

std::string AnalyserEquationAst::value() const
const std::string &AnalyserEquationAst::value() const
{
return mPimpl->mValue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/analyserexternalvariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ std::vector<VariablePtr>::iterator AnalyserExternalVariable::AnalyserExternalVar
const std::string &componentName,
const std::string &variableName)
{
return std::find_if(mDependencies.begin(), mDependencies.end(), [=](const auto &v) {
return std::find_if(mDependencies.begin(), mDependencies.end(), [&](const auto &v) {
return (owningModel(v) == model)
&& (owningComponent(v)->name() == componentName)
&& (v->name() == variableName);
Expand All @@ -40,7 +40,7 @@ std::vector<VariablePtr>::iterator AnalyserExternalVariable::AnalyserExternalVar

std::vector<VariablePtr>::iterator AnalyserExternalVariable::AnalyserExternalVariableImpl::findDependency(const VariablePtr &variable)
{
return std::find_if(mDependencies.begin(), mDependencies.end(), [=](const auto &v) {
return std::find_if(mDependencies.begin(), mDependencies.end(), [&](const auto &v) {
return v == variable;
});
}
Expand Down Expand Up @@ -155,7 +155,7 @@ VariablePtr AnalyserExternalVariable::dependency(const ModelPtr &model,
nullptr;
}

std::vector<VariablePtr> AnalyserExternalVariable::dependencies() const
const std::vector<VariablePtr> &AnalyserExternalVariable::dependencies() const
{
return mPimpl->mDependencies;
}
Expand Down
36 changes: 24 additions & 12 deletions src/analysermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ size_t AnalyserModel::stateCount() const
return mPimpl->mStates.size();
}

std::vector<AnalyserVariablePtr> AnalyserModel::states() const
const std::vector<AnalyserVariablePtr> &AnalyserModel::states() const
{
static const std::vector<AnalyserVariablePtr> NO_ANALYSER_VARIABLE;

if (!isValid()) {
return {};
return NO_ANALYSER_VARIABLE;
}

return mPimpl->mStates;
Expand All @@ -185,10 +187,12 @@ size_t AnalyserModel::constantCount() const
return mPimpl->mConstants.size();
}

std::vector<AnalyserVariablePtr> AnalyserModel::constants() const
const std::vector<AnalyserVariablePtr> &AnalyserModel::constants() const
{
static const std::vector<AnalyserVariablePtr> NO_ANALYSER_VARIABLE;

if (!isValid()) {
return {};
return NO_ANALYSER_VARIABLE;
}

return mPimpl->mConstants;
Expand All @@ -212,10 +216,12 @@ size_t AnalyserModel::computedConstantCount() const
return mPimpl->mComputedConstants.size();
}

std::vector<AnalyserVariablePtr> AnalyserModel::computedConstants() const
const std::vector<AnalyserVariablePtr> &AnalyserModel::computedConstants() const
{
static const std::vector<AnalyserVariablePtr> NO_ANALYSER_VARIABLE;

if (!isValid()) {
return {};
return NO_ANALYSER_VARIABLE;
}

return mPimpl->mComputedConstants;
Expand All @@ -239,10 +245,12 @@ size_t AnalyserModel::algebraicVariableCount() const
return mPimpl->mAlgebraicVariables.size();
}

std::vector<AnalyserVariablePtr> AnalyserModel::algebraicVariables() const
const std::vector<AnalyserVariablePtr> &AnalyserModel::algebraicVariables() const
{
static const std::vector<AnalyserVariablePtr> NO_ANALYSER_VARIABLE;

if (!isValid()) {
return {};
return NO_ANALYSER_VARIABLE;
}

return mPimpl->mAlgebraicVariables;
Expand All @@ -266,10 +274,12 @@ size_t AnalyserModel::externalVariableCount() const
return mPimpl->mExternalVariables.size();
}

std::vector<AnalyserVariablePtr> AnalyserModel::externalVariables() const
const std::vector<AnalyserVariablePtr> &AnalyserModel::externalVariables() const
{
static const std::vector<AnalyserVariablePtr> NO_ANALYSER_VARIABLE;

if (!isValid()) {
return {};
return NO_ANALYSER_VARIABLE;
}

return mPimpl->mExternalVariables;
Expand Down Expand Up @@ -336,10 +346,12 @@ size_t AnalyserModel::analyserEquationCount() const
return mPimpl->mAnalyserEquations.size();
}

std::vector<AnalyserEquationPtr> AnalyserModel::analyserEquations() const
const std::vector<AnalyserEquationPtr> &AnalyserModel::analyserEquations() const
{
static const std::vector<AnalyserEquationPtr> NO_ANALYSER_EQUATION;

if (!isValid()) {
return {};
return NO_ANALYSER_EQUATION;
}

return mPimpl->mAnalyserEquations;
Expand Down
41 changes: 25 additions & 16 deletions src/annotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
#include "libcellml/annotator.h"

#include <algorithm>
#include <format>
#include <sstream>
#include <unordered_map>

Expand Down Expand Up @@ -236,13 +237,17 @@ void Annotator::AnnotatorImpl::listComponentIdsAndItems(const ComponentPtr &comp
if (idList.count(id) != 0) {
// Get the range of items with this identifier:
auto rangePair = idList.equal_range(id);
auto compVar = owningComponent(variable);
auto compEquivVar = owningComponent(equivalentVariable);
for (auto it = rangePair.first; it != rangePair.second; ++it) {
// Make sure it's also a CONNECTION item.
if (it->second->type() == CellmlElementType::CONNECTION) {
auto testPair = it->second->variablePair();
if ((owningComponent(testPair->variable1()) == owningComponent(equivalentVariable)) && (owningComponent(testPair->variable2()) == owningComponent(variable))) {
found = true;
} else if ((owningComponent(testPair->variable2()) == owningComponent(equivalentVariable)) && (owningComponent(testPair->variable1()) == owningComponent(variable))) {
auto compVar1 = owningComponent(testPair->variable1());
auto compVar2 = owningComponent(testPair->variable2());

if (((compVar1 == compEquivVar) && (compVar2 == compVar))
|| ((compVar2 == compEquivVar) && (compVar1 == compVar))) {
found = true;
}
}
Expand Down Expand Up @@ -352,7 +357,7 @@ AnyCellmlElementPtr Annotator::AnnotatorImpl::convertToWeak(const AnyCellmlEleme

converted->mPimpl->mType = type;

switch (item->type()) {
switch (type) {
case CellmlElementType::COMPONENT:
case CellmlElementType::COMPONENT_REF: {
ComponentWeakPtr weakComponent = item->component();
Expand Down Expand Up @@ -517,7 +522,7 @@ void Annotator::AnnotatorImpl::addIssueInvalidArgument(CellmlElementType type)
void Annotator::AnnotatorImpl::addIssueNonUnique(const std::string &id)
{
auto issue = Issue::IssueImpl::create();
issue->mPimpl->setDescription("The identifier '" + id + "' occurs " + std::to_string(mIdList.count(id)) + " times in the model so a unique item cannot be located.");
issue->mPimpl->setDescription("The identifier '" + id + "' occurs " + std::format("{}", mIdList.count(id)) + " times in the model so a unique item cannot be located.");
issue->mPimpl->setLevel(Issue::Level::WARNING);
issue->mPimpl->setReferenceRule(Issue::ReferenceRule::ANNOTATOR_ID_NOT_UNIQUE);
addIssue(issue);
Expand Down Expand Up @@ -1417,20 +1422,24 @@ size_t Annotator::itemCount(const std::string &id)

void Annotator::AnnotatorImpl::doUpdateComponentHash(const ComponentPtr &component, std::string &idsString)
{
for (size_t i = 0; i < component->variableCount(); ++i) {
idsString += "v=" + std::to_string(i) + component->variable(i)->id();
const auto variableCount = component->variableCount();
const auto resetCount = component->resetCount();
const auto componentCount = component->componentCount();

for (size_t i = 0; i < variableCount; ++i) {
idsString += "v=" + std::format("{}", i) + component->variable(i)->id();
}

for (size_t i = 0; i < component->resetCount(); ++i) {
for (size_t i = 0; i < resetCount; ++i) {
auto reset = component->reset(i);
idsString += "r=" + std::to_string(i) + reset->id() + "rv=" + reset->resetValueId() + "tv=" + reset->testValueId();
idsString += "r=" + std::format("{}", i) + reset->id() + "rv=" + reset->resetValueId() + "tv=" + reset->testValueId();
}

// Note that MathML identifiers are not yet included.

for (size_t i = 0; i < component->componentCount(); ++i) {
for (size_t i = 0; i < componentCount; ++i) {
auto child = component->component(i);
idsString += "c=" + std::to_string(i) + child->id() + "ce=" + child->encapsulationId();
idsString += "c=" + std::format("{}", i) + child->id() + "ce=" + child->encapsulationId();
doUpdateComponentHash(child, idsString);
}
}
Expand All @@ -1448,21 +1457,21 @@ size_t Annotator::AnnotatorImpl::generateHash()
auto importSources = getAllImportSources(model);
i = 0;
for (auto &importSource : importSources) {
idsString += "i=" + std::to_string(++i) + importSource->id();
idsString += "i=" + std::format("{}", ++i) + importSource->id();
}

for (i = 0; i < model->unitsCount(); ++i) {
auto units = model->units(i);
idsString += "U=" + std::to_string(i) + units->id();
idsString += "U=" + std::format("{}", i) + units->id();
for (size_t j = 0; j < units->unitCount(); ++j) {
idsString += "u=" + std::to_string(j) + units->unitId(j);
idsString += "u=" + std::format("{}", j) + units->unitId(j);
}
}

for (i = 0; i < model->componentCount(); ++i) {
auto component = model->component(i);
idsString += "c=" + std::to_string(i) + component->id();
idsString += "cr=" + std::to_string(i) + component->encapsulationId();
idsString += "c=" + std::format("{}", i) + component->id();
idsString += "cr=" + std::format("{}", i) + component->encapsulationId();
doUpdateComponentHash(component, idsString);
}

Expand Down
8 changes: 4 additions & 4 deletions src/api/libcellml/analyserequation.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class LIBCELLML_EXPORT AnalyserEquation
*
* @return The states as a @c std::vector.
*/
std::vector<AnalyserVariablePtr> states() const;
const std::vector<AnalyserVariablePtr> &states() const;

/**
* @brief Get the state, at @p index, computed by this @ref AnalyserEquation.
Expand Down Expand Up @@ -214,7 +214,7 @@ class LIBCELLML_EXPORT AnalyserEquation
*
* @return The computed constants as a @c std::vector.
*/
std::vector<AnalyserVariablePtr> computedConstants() const;
const std::vector<AnalyserVariablePtr> &computedConstants() const;

/**
* @brief Get the computed constant, at @p index, computed by this @ref AnalyserEquation.
Expand Down Expand Up @@ -243,7 +243,7 @@ class LIBCELLML_EXPORT AnalyserEquation
*
* @return The algebraic variables as a @c std::vector.
*/
std::vector<AnalyserVariablePtr> algebraicVariables() const;
const std::vector<AnalyserVariablePtr> &algebraicVariables() const;

/**
* @brief Get the algebraic variable, at @p index, computed by this @ref AnalyserEquation.
Expand Down Expand Up @@ -272,7 +272,7 @@ class LIBCELLML_EXPORT AnalyserEquation
*
* @return The external variables as a @c std::vector.
*/
std::vector<AnalyserVariablePtr> externalVariables() const;
const std::vector<AnalyserVariablePtr> &externalVariables() const;

/**
* @brief Get the external variable, at @p index, computed by this @ref AnalyserEquation.
Expand Down
2 changes: 1 addition & 1 deletion src/api/libcellml/analyserequationast.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class LIBCELLML_EXPORT AnalyserEquationAst
*
* @return The value.
*/
std::string value() const;
const std::string &value() const;

/**
* @brief Set the value for this @ref AnalyserEquationAst.
Expand Down
2 changes: 1 addition & 1 deletion src/api/libcellml/analyserexternalvariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class LIBCELLML_EXPORT AnalyserExternalVariable
*
* @return The dependencies as a @c std::vector.
*/
std::vector<VariablePtr> dependencies() const;
const std::vector<VariablePtr> &dependencies() const;

/**
* @brief Get the number of dependencies of this @ref AnalyserExternalVariable.
Expand Down
Loading
Loading