Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyser/Generator: added some xxxAsString() methods #1131

Merged
merged 23 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7477da5
GeneratorProfile: added `profileAsString()`.
agarny Feb 19, 2023
0f92e83
Analyser: added some `typeAsString()` methods.
agarny Feb 20, 2023
5728948
Cleaned up our use of some mappings.
agarny Feb 21, 2023
088ca98
Analyser/generator: use std::map for our `xxxAsString()` methods.
agarny Feb 21, 2023
467f25f
Analyser/generator: replaced our `xxxAsString()` methods with static …
agarny Feb 21, 2023
15ebc22
Analyser/generator: use lower case string for our class enum mappings.
agarny Feb 21, 2023
7f1ddb6
Analyser/generator: ensure Python coverage.
agarny Feb 21, 2023
97dd817
Allow gcov to get 100% coverage.
agarny Feb 21, 2023
3cd1f9a
Merge branch 'main' into issue446
agarny Mar 28, 2023
c08a6b2
Merge branch 'main' into issue446.
agarny Mar 30, 2023
a9b3563
Fixed a merging issue.
agarny Mar 30, 2023
006602b
Merge branch 'main' into issue446
agarny Apr 5, 2023
868d5ea
Merge branch 'main' into issue446
agarny Apr 5, 2023
8acfacb
Merge branch 'main' into issue446
agarny Apr 12, 2023
3bc6873
Python bindings: make sure that analyser-related types are valid.
agarny Apr 16, 2023
7335511
Merge branch 'main' into issue446
agarny Apr 25, 2023
b3d1216
Merge branch 'main' into issue446
agarny Apr 25, 2023
bf868f5
Merge branch 'main' into issue446
agarny Apr 25, 2023
6d0561c
Python: make sure that xxxAsString() doesn't work with invalid values.
agarny Apr 25, 2023
4cff52e
Merge branch 'main' into issue446
agarny Apr 25, 2023
80e3236
Units: improved casting.
agarny Apr 26, 2023
ada4cb5
Documentation: use @ref rather than @c wherever possible in our analy…
agarny Apr 26, 2023
e8c62c7
Merge branch 'main' into issue446
hsorby Apr 26, 2023
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
1 change: 1 addition & 0 deletions src/analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ limitations under the License.
#include "analysermodel_p.h"
#include "analyservariable_p.h"
#include "anycellmlelement_p.h"
#include "commonutils.h"
hsorby marked this conversation as resolved.
Show resolved Hide resolved
#include "generator_p.h"
#include "issue_p.h"
#include "logger_p.h"
Expand Down
12 changes: 12 additions & 0 deletions src/analyserequation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ AnalyserEquation::Type AnalyserEquation::type() const
return mPimpl->mType;
}

static const std::map<AnalyserEquation::Type, std::string> typeToString = {
{AnalyserEquation::Type::TRUE_CONSTANT, "true_constant"},
{AnalyserEquation::Type::VARIABLE_BASED_CONSTANT, "variable_based_constant"},
{AnalyserEquation::Type::RATE, "rate"},
{AnalyserEquation::Type::ALGEBRAIC, "algebraic"},
{AnalyserEquation::Type::EXTERNAL, "external"}};

std::string AnalyserEquation::typeAsString(Type type)
{
return typeToString.at(type);
}

AnalyserEquationAstPtr AnalyserEquation::ast() const
{
return mPimpl->mAst;
Expand Down
76 changes: 76 additions & 0 deletions src/analyserequationast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ limitations under the License.

#include "analyserequationast_p.h"

#ifdef NAN
# undef NAN
#endif

hsorby marked this conversation as resolved.
Show resolved Hide resolved
namespace libcellml {

void AnalyserEquationAst::AnalyserEquationAstImpl::populate(AnalyserEquationAst::Type type,
Expand Down Expand Up @@ -65,6 +69,78 @@ AnalyserEquationAst::Type AnalyserEquationAst::type() const
return mPimpl->mType;
}

static const std::map<AnalyserEquationAst::Type, std::string> typeToString = {
{AnalyserEquationAst::Type::ASSIGNMENT, "assignment"},
{AnalyserEquationAst::Type::EQ, "eq"},
{AnalyserEquationAst::Type::NEQ, "neq"},
{AnalyserEquationAst::Type::LT, "lt"},
{AnalyserEquationAst::Type::LEQ, "leq"},
{AnalyserEquationAst::Type::GT, "gt"},
{AnalyserEquationAst::Type::GEQ, "geq"},
{AnalyserEquationAst::Type::AND, "and"},
{AnalyserEquationAst::Type::OR, "or"},
{AnalyserEquationAst::Type::XOR, "xor"},
{AnalyserEquationAst::Type::NOT, "not"},
{AnalyserEquationAst::Type::PLUS, "plus"},
{AnalyserEquationAst::Type::MINUS, "minus"},
{AnalyserEquationAst::Type::TIMES, "times"},
{AnalyserEquationAst::Type::DIVIDE, "divide"},
{AnalyserEquationAst::Type::POWER, "power"},
{AnalyserEquationAst::Type::ROOT, "root"},
{AnalyserEquationAst::Type::ABS, "abs"},
{AnalyserEquationAst::Type::EXP, "exp"},
{AnalyserEquationAst::Type::LN, "ln"},
{AnalyserEquationAst::Type::LOG, "log"},
{AnalyserEquationAst::Type::CEILING, "ceiling"},
{AnalyserEquationAst::Type::FLOOR, "floor"},
{AnalyserEquationAst::Type::MIN, "min"},
{AnalyserEquationAst::Type::MAX, "max"},
{AnalyserEquationAst::Type::REM, "rem"},
{AnalyserEquationAst::Type::DIFF, "diff"},
{AnalyserEquationAst::Type::SIN, "sin"},
{AnalyserEquationAst::Type::COS, "cos"},
{AnalyserEquationAst::Type::TAN, "tan"},
{AnalyserEquationAst::Type::SEC, "sec"},
{AnalyserEquationAst::Type::CSC, "csc"},
{AnalyserEquationAst::Type::COT, "cot"},
{AnalyserEquationAst::Type::SINH, "sinh"},
{AnalyserEquationAst::Type::COSH, "cosh"},
{AnalyserEquationAst::Type::TANH, "tanh"},
{AnalyserEquationAst::Type::SECH, "sech"},
{AnalyserEquationAst::Type::CSCH, "csch"},
{AnalyserEquationAst::Type::COTH, "coth"},
{AnalyserEquationAst::Type::ASIN, "asin"},
{AnalyserEquationAst::Type::ACOS, "acos"},
{AnalyserEquationAst::Type::ATAN, "atan"},
{AnalyserEquationAst::Type::ASEC, "asec"},
{AnalyserEquationAst::Type::ACSC, "acsc"},
{AnalyserEquationAst::Type::ACOT, "acot"},
{AnalyserEquationAst::Type::ASINH, "asinh"},
{AnalyserEquationAst::Type::ACOSH, "acosh"},
{AnalyserEquationAst::Type::ATANH, "atanh"},
{AnalyserEquationAst::Type::ASECH, "asech"},
{AnalyserEquationAst::Type::ACSCH, "acsch"},
{AnalyserEquationAst::Type::ACOTH, "acoth"},
{AnalyserEquationAst::Type::PIECEWISE, "piecewise"},
{AnalyserEquationAst::Type::PIECE, "piece"},
{AnalyserEquationAst::Type::OTHERWISE, "otherwise"},
{AnalyserEquationAst::Type::CI, "ci"},
{AnalyserEquationAst::Type::CN, "cn"},
{AnalyserEquationAst::Type::DEGREE, "degree"},
{AnalyserEquationAst::Type::LOGBASE, "logbase"},
{AnalyserEquationAst::Type::BVAR, "bvar"},
{AnalyserEquationAst::Type::TRUE, "true"},
{AnalyserEquationAst::Type::FALSE, "false"},
{AnalyserEquationAst::Type::E, "e"},
{AnalyserEquationAst::Type::PI, "pi"},
{AnalyserEquationAst::Type::INF, "inf"},
{AnalyserEquationAst::Type::NAN, "nan"}};

std::string AnalyserEquationAst::typeAsString(Type type)
{
return typeToString.at(type);
}

void AnalyserEquationAst::setType(Type type)
{
mPimpl->mType = type;
Expand Down
1 change: 1 addition & 0 deletions src/analyserexternalvariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
#include "libcellml/analyserexternalvariable.h"

#include "analyserexternalvariable_p.h"
#include "commonutils.h"
hsorby marked this conversation as resolved.
Show resolved Hide resolved
#include "utilities.h"

namespace libcellml {
Expand Down
14 changes: 14 additions & 0 deletions src/analysermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ AnalyserModel::Type AnalyserModel::type() const
return mPimpl->mType;
}

static const std::map<AnalyserModel::Type, std::string> typeToString = {
{AnalyserModel::Type::UNKNOWN, "unknown"},
{AnalyserModel::Type::ALGEBRAIC, "algebraic"},
{AnalyserModel::Type::ODE, "ode"},
{AnalyserModel::Type::INVALID, "invalid"},
{AnalyserModel::Type::UNDERCONSTRAINED, "underconstrained"},
{AnalyserModel::Type::OVERCONSTRAINED, "overconstrained"},
{AnalyserModel::Type::UNSUITABLY_CONSTRAINED, "unsuitably_constrained"}};

std::string AnalyserModel::typeAsString(Type type)
{
return typeToString.at(type);
}

bool AnalyserModel::hasExternalVariables() const
{
if (!isValid()) {
Expand Down
13 changes: 13 additions & 0 deletions src/analyservariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ AnalyserVariable::Type AnalyserVariable::type() const
return mPimpl->mType;
}

static const std::map<AnalyserVariable::Type, std::string> typeToString = {
{AnalyserVariable::Type::VARIABLE_OF_INTEGRATION, "variable_of_integration"},
{AnalyserVariable::Type::STATE, "state"},
{AnalyserVariable::Type::CONSTANT, "constant"},
{AnalyserVariable::Type::COMPUTED_CONSTANT, "computed_constant"},
{AnalyserVariable::Type::ALGEBRAIC, "algebraic"},
{AnalyserVariable::Type::EXTERNAL, "external"}};

std::string AnalyserVariable::typeAsString(Type type)
{
return typeToString.at(type);
}

size_t AnalyserVariable::index() const
{
return mPimpl->mIndex;
Expand Down
17 changes: 1 addition & 16 deletions src/annotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ limitations under the License.
#include "libcellml/variable.h"

#include "anycellmlelement_p.h"
#include "commonutils.h"
#include "internaltypes.h"
#include "issue_p.h"
#include "logger_p.h"
Expand All @@ -38,22 +39,6 @@ namespace libcellml {

using ItemList = std::multimap<std::string, AnyCellmlElementPtr>;

static const std::map<CellmlElementType, std::string> typeToString = {
{CellmlElementType::COMPONENT, "component"},
{CellmlElementType::COMPONENT_REF, "component_ref"},
{CellmlElementType::CONNECTION, "connection"},
{CellmlElementType::ENCAPSULATION, "encapsulation"},
{CellmlElementType::IMPORT, "import"},
{CellmlElementType::MAP_VARIABLES, "map_variables"},
{CellmlElementType::MODEL, "model"},
{CellmlElementType::RESET, "reset"},
{CellmlElementType::RESET_VALUE, "reset_value"},
{CellmlElementType::TEST_VALUE, "test_value"},
{CellmlElementType::UNDEFINED, "undefined"},
{CellmlElementType::UNIT, "unit"},
{CellmlElementType::UNITS, "units"},
{CellmlElementType::VARIABLE, "variable"}};

/**
* @brief The Annotator::AnnotatorImpl class.
*
Expand Down
32 changes: 16 additions & 16 deletions src/api/libcellml/analyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class LIBCELLML_EXPORT Analyser: public Logger
static AnalyserPtr create() noexcept;

/**
* @brief Analyse the @c Model.
* @brief Analyse the @ref Model.
*
* Analyse the @c Model using this @ref Analyser.
* Analyse the @ref Model using this @ref Analyser.
*
* @param model The @c Model to analyse.
* @param model The @ref Model to analyse.
*/
void analyseModel(const ModelPtr &model);

Expand Down Expand Up @@ -87,16 +87,16 @@ class LIBCELLML_EXPORT Analyser: public Logger
* @overload
*
* @brief Remove the @ref AnalyserExternalVariable with the given
* @p variableName in the @c Component with the given @p componentName in
* @p variableName in the @ref Component with the given @p componentName in
* the given @p model.
*
* Remove the @ref AnalyserExternalVariable found that matches the given
* @p variableName in the @c Component with the given @p componentName in
* @p variableName in the @ref Component with the given @p componentName in
* the given @p model.
*
* @param model The pointer to the @c Model which contains the
* @param model The pointer to the @ref Model which contains the
* @ref AnalyserExternalVariable to remove.
* @param componentName The name of the @c Component which contains the
* @param componentName The name of the @ref Component which contains the
* @ref AnalyserExternalVariable to remove.
* @param variableName The name of the @ref AnalyserExternalVariable to
* remove.
Expand Down Expand Up @@ -134,18 +134,18 @@ class LIBCELLML_EXPORT Analyser: public Logger

/**
* @brief Test to see if the @ref AnalyserExternalVariable with the given
* @p variableName in the @c Component with the given @p componentName in
* @p variableName in the @ref Component with the given @p componentName in
* the given @p model is contained within this @ref Analyser.
*
* Test to see if the @ref AnalyserExternalVariable with the the given
* @p variableName in the @c Component with the given @p componentName in
* @p variableName in the @ref Component with the given @p componentName in
* the given @p model is contained within this @ref Analyser. Return @c true
* if the @ref AnalyserExternalVariable is in the @ref Analyser and @c false
* otherwise.
*
* @param model The pointer to the @c Model which contains the
* @param model The pointer to the @ref Model which contains the
* @ref AnalyserExternalVariable to test.
* @param componentName The name of the @c Component which contains the
* @param componentName The name of the @ref Component which contains the
* @ref AnalyserExternalVariable to test.
* @param variableName The name of the @ref AnalyserExternalVariable to test.
*
Expand Down Expand Up @@ -192,19 +192,19 @@ class LIBCELLML_EXPORT Analyser: public Logger
* @brief Get the @ref AnalyserExternalVariable with the given @p name.
*
* Return the @ref AnalyserExternalVariable with the given @p variableName in
* the @c Component with the given @p componentName in the given @p model.
* the @ref Component with the given @p componentName in the given @p model.
* If no such @ref AnalyserExternalVariable is contained within the
* @ref Analyser, a @c nullptr is returned.
*
* @param model The pointer to the @c Model which contains the
* @param model The pointer to the @ref Model which contains the
* @ref AnalyserExternalVariable to retrieve.
* @param componentName The name of the @c Component which contains the
* @param componentName The name of the @ref Component which contains the
* @ref AnalyserExternalVariable to retrieve.
* @param variableName The name of the @ref AnalyserExternalVariable to
* retrieve.
*
* @return The @ref AnalyserExternalVariable with the given @p variableName in
* the @c Component with the given @p componentName in the given @p model on
* the @ref Component with the given @p componentName in the given @p model on
* success, @c nullptr on failure.
*/
AnalyserExternalVariablePtr externalVariable(const ModelPtr &model,
Expand All @@ -230,7 +230,7 @@ class LIBCELLML_EXPORT Analyser: public Logger
* variable of integration, states, variables, equations, and whether it
* needs some specific mathematical functions.
*
* @return The analysed model for the @c Model analysed by this @ref Analyser.
* @return The analysed model for the @ref Model analysed by this @ref Analyser.
*/
AnalyserModelPtr model() const;

Expand Down
43 changes: 27 additions & 16 deletions src/api/libcellml/analyserequation.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,51 +53,62 @@ class LIBCELLML_EXPORT AnalyserEquation
AnalyserEquation &operator=(AnalyserEquation rhs) = delete; /**< Assignment operator, @private. */

/**
* @brief Get the @c Type of this @c AnalyserEquation.
* @brief Get the @ref Type of this @ref AnalyserEquation.
*
* Return the @c Type of this @c AnalyserEquation.
* Return the @ref Type of this @ref AnalyserEquation.
*
* @return The @c Type.
* @return The @ref Type.
*/
Type type() const;

/**
* @brief Get the @c AnalyserEquationAst for this @c AnalyserEquation.
* @brief Get the string version of a @ref Type.
*
* Return the @c AnalyserEquationAst for this @c AnalyserEquation.
* Return the string version of a @ref Type.
*
* @return The @c AnalyserEquationAst.
* @param type The type for which we want the string version.
*
* @return The string version of the @ref Type.
*/
static std::string typeAsString(Type type);

/**
* @brief Get the @ref AnalyserEquationAst for this @ref AnalyserEquation.
*
* Return the @ref AnalyserEquationAst for this @ref AnalyserEquation.
*
* @return The @ref AnalyserEquationAst.
*/
AnalyserEquationAstPtr ast() const;

/**
* @brief Get the list of @c AnalyserEquation dependencies.
* @brief Get the list of @ref AnalyserEquation dependencies.
*
* Return the list of @c AnalyserEquation items which correspond to the
* equations on which this @c AnalyserEquation depends.
* Return the list of @ref AnalyserEquation items which correspond to the
* equations on which this @ref AnalyserEquation depends.
*
* @return The list of @c AnalyserEquation dependencies.
* @return The list of @ref AnalyserEquation dependencies.
*/
std::vector<AnalyserEquationPtr> dependencies() const;

/**
* @brief Test to determine if this @c AnalyserEquation relies on states
* @brief Test to determine if this @ref AnalyserEquation relies on states
* and/or rates.
*
* Test to determine if this @c AnalyserEquation relies on states and/or
* Test to determine if this @ref AnalyserEquation relies on states and/or
* rates, return @c true if it does and @c false otherwise.
*
* @return @c true if this @c AnalyserEquation relies on states and/or
* @return @c true if this @ref AnalyserEquation relies on states and/or
* rates, @c false otherwise.
*/
bool isStateRateBased() const;

/**
* @brief Get the @c AnalyserVariable for this @c AnalyserEquation.
* @brief Get the @ref AnalyserVariable for this @ref AnalyserEquation.
*
* Return the @c AnalyserVariable for this @c AnalyserEquation.
* Return the @ref AnalyserVariable for this @ref AnalyserEquation.
*
* @return The @c AnalyserVariable.
* @return The @ref AnalyserVariable.
*/
AnalyserVariablePtr variable() const;

Expand Down
Loading