From 7cdbff0970101f7df25a958e795bb3115f387abc Mon Sep 17 00:00:00 2001 From: Thomas Knoll Date: Thu, 30 Nov 2023 10:13:16 +0100 Subject: [PATCH] added const to config + const prop handling --- util/ConfigYaml.cpp | 51 ++++++++++++++++++++++++++++++++++-- util/ConfigYaml.h | 21 ++++++++++++++- util/Grid.cpp | 39 ++++++++++++++++----------- util/PrismModulesPrinter.cpp | 43 ++++++++++++++++++++++-------- util/PrismModulesPrinter.h | 6 ++--- 5 files changed, 127 insertions(+), 33 deletions(-) diff --git a/util/ConfigYaml.cpp b/util/ConfigYaml.cpp index 063face..07c2b8e 100644 --- a/util/ConfigYaml.cpp +++ b/util/ConfigYaml.cpp @@ -16,6 +16,11 @@ std::ostream& operator << (std::ostream& os, const Action& action) { return os; } +std::ostream& operator << (std::ostream& os, const Constant& constant) { + os << "const " << constant.type_ << " " << constant.constant_ << " = " << constant.value_; + return os; +} + std::ostream& operator << (std::ostream& os, const Module& module) { os << "Module: " << module.module_ << std::endl; for (auto& action : module.actions_) { @@ -48,6 +53,14 @@ std::string Action::createExpression() const { return "\t" + action_ + "\t" + guard_ + "-> " + update_+ Configuration::configuration_identifier_; } +std::string Constant::createExpression() const { + if (overwrite_) { + return "const " + type_ + " " + constant_ + " = " + value_ + Configuration::overwrite_identifier_; + } + + return "const " + type_ + " " + constant_ + " = " + value_ + Configuration::configuration_identifier_; +} + YAML::Node YAML::convert::encode(const Module& rhs) { YAML::Node node; @@ -145,6 +158,33 @@ bool YAML::convert::decode(const YAML::Node& node, Formula& rhs) { return true; } +YAML::Node YAML::convert::encode(const Constant& rhs) { + YAML::Node node; + + node.push_back(rhs.constant_); + node.push_back(rhs.value_); + node.push_back(rhs.type_); + node.push_back(rhs.overwrite_); + + return node; +} + +bool YAML::convert::decode(const YAML::Node& node, Constant& rhs) { + if (!node.IsDefined() || !node.Type() == NodeType::Map || !node["constant"] || !node["type"] || !node["value"]) { + return false; + } + + rhs.constant_ = node["constant"].as(); + rhs.type_ = node["type"].as(); + rhs.value_ = node["value"].as(); + + if(node["overwrite"]) { + rhs.overwrite_ = node["overwrite"].as(); + } + + return true; +} + const std::string Configuration::configuration_identifier_ { "; // created through configuration"}; const std::string Configuration::overwrite_identifier_{"; // Overwritten through configuration"}; @@ -156,6 +196,7 @@ const std::string Configuration::overwrite_identifier_{"; // Overwritten through std::vector