Browse Source

basic overwrite guard and update

Thomas Knoll 10 months ago
parent
commit
d9679da353
  1. 4
      main.cpp
  2. 36
      util/ConfigYaml.cpp
  3. 8
      util/ConfigYaml.h

4
main.cpp

@ -164,7 +164,7 @@ int main(int argc, char* argv[]) {
} }
if(ok) { if(ok) {
Grid grid(contentCells, backgroundCells, stateRewards, probIntended, faultyProbability); Grid grid(contentCells, backgroundCells, stateRewards, probIntended, faultyProbability);
//grid.printToPrism(std::cout, configurations); //grid.printToPrism(std::cout, configurations);
std::stringstream ss; std::stringstream ss;
grid.printToPrism(ss, configurations); grid.printToPrism(ss, configurations);
@ -177,7 +177,7 @@ int main(int argc, char* argv[]) {
std::cout << "got: \"" << std::string(e.first, e.last) << '"' << std::endl; std::cout << "got: \"" << std::string(e.first, e.last) << '"' << std::endl;
std::cout << "Expectation failure: " << e.what() << " at '" << std::string(e.first,e.last) << "'\n"; std::cout << "Expectation failure: " << e.what() << " at '" << std::string(e.first,e.last) << "'\n";
} catch(const std::exception& e) { } catch(const std::exception& e) {
std::cerr << "Exception '" << typeid(e).name() << "' caught:" << std::endl;
std::cerr << "Exception '" << typeid(e).name() << "' caught:" << e.what() << std::endl;
std::cerr << "\t" << e.what() << std::endl; std::cerr << "\t" << e.what() << std::endl;
std::exit(EXIT_FAILURE); std::exit(EXIT_FAILURE);
} }

36
util/ConfigYaml.cpp

@ -47,10 +47,10 @@ std::string Formula::createExpression() const {
std::string Command::createExpression() const { std::string Command::createExpression() const {
if (overwrite_) { if (overwrite_) {
return action_ + "\t" + guard_ + "-> " + update_ + Configuration::overwrite_identifier_;
return action_ + "\t" + guard_ + " -> " + update_ + Configuration::overwrite_identifier_;
} }
return "\t" + action_ + "\t" + guard_ + "-> " + update_+ Configuration::configuration_identifier_;
return "\t" + action_ + "\t" + guard_ + " -> " + update_+ Configuration::configuration_identifier_;
} }
std::string Constant::createExpression() const { std::string Constant::createExpression() const {
@ -76,6 +76,13 @@ bool YAML::convert<Module>::decode(const YAML::Node& node, Module& rhs) {
} }
rhs.commands_ = node["commands"].as<std::vector<Command>>(); rhs.commands_ = node["commands"].as<std::vector<Command>>();
rhs.module_ = node["module"].as<std::string>(); rhs.module_ = node["module"].as<std::string>();
if (node["module_text"]) {
rhs.module_text_ = node["module_text"].as<std::string>();
}
if (node["overwrite"]) {
rhs.overwrite_module = node["overwrite"].as<bool>();
}
return true; return true;
} }
@ -96,8 +103,13 @@ bool YAML::convert<Command>::decode(const YAML::Node& node, Command& rhs) {
} }
rhs.action_ = node["action"].as<std::string>(); rhs.action_ = node["action"].as<std::string>();
rhs.guard_ = node["guard"].as<std::string>();
rhs.update_ = node["update"].as<std::string>();
if (node["guard"]) {
rhs.guard_ = node["guard"].as<std::string>();
}
if (node["update"]) {
rhs.update_ = node["update"].as<std::string>();
}
if (node["overwrite"]) { if (node["overwrite"]) {
rhs.overwrite_ = node["overwrite"].as<bool>(); rhs.overwrite_ = node["overwrite"].as<bool>();
@ -249,8 +261,22 @@ YamlConfigParseResult YamlConfigParser::parseConfiguration() {
configuration.push_back({formula.createExpression(), formula.formula_ ,ConfigType::Formula, formula.overwrite_}); configuration.push_back({formula.createExpression(), formula.formula_ ,ConfigType::Formula, formula.overwrite_});
} }
for (auto& module : modules) { for (auto& module : modules) {
if (module.overwrite_module) {
Configuration config = Configuration(module.module_text_, module.module_, ConfigType::Module, true, module.module_, {0}, "endmodule");
configuration.push_back(config);
continue;
}
for (auto& command : module.commands_) { for (auto& command : module.commands_) {
configuration.push_back({command.createExpression(), command.action_, ConfigType::Module, command.overwrite_, module.module_, command.indexes_});
Configuration config;
if (!command.guard_.empty() && !command.action_.empty() && command.update_.empty()) {
config = Configuration(" " + command.guard_, command.action_, ConfigType::Module, true, module.module_, command.indexes_, "->", false);
} else if (!command.update_.empty() && !command.action_.empty() && command.guard_.empty()) {
config = Configuration( " " + command.update_, command.action_, ConfigType::Module, true, module.module_, command.indexes_, ";", false);
} else {
config = Configuration(command.createExpression(), command.action_, ConfigType::Module, command.overwrite_, module.module_, command.indexes_);
}
configuration.push_back(config);
} }
} }
for (auto& constant : constants) { for (auto& constant : constants) {

8
util/ConfigYaml.h

@ -22,10 +22,12 @@ struct Configuration
std::string module_ {}; std::string module_ {};
std::string expression_{}; std::string expression_{};
std::string identifier_{}; std::string identifier_{};
std::string end_identifier_{};
std::vector<int> indexes_{0}; std::vector<int> indexes_{0};
ConfigType type_ {ConfigType::Label}; ConfigType type_ {ConfigType::Label};
bool overwrite_ {false}; bool overwrite_ {false};
bool include_identifier_for_overwrite_{true};
Configuration() = default; Configuration() = default;
Configuration(std::string expression Configuration(std::string expression
@ -33,7 +35,9 @@ struct Configuration
, ConfigType type , ConfigType type
, bool overwrite = false , bool overwrite = false
, std::string module = "" , std::string module = ""
, std::vector<int> indexes = {0}) : expression_(expression), identifier_(identifier), type_(type), overwrite_(overwrite), module_{module}, indexes_(indexes) {}
, std::vector<int> indexes = {0}
, std::string end_identifier = {";"}
, bool include_identifier_for_overwrite = true) : expression_(expression), identifier_(identifier), type_(type), overwrite_(overwrite), module_{module}, indexes_(indexes), end_identifier_{end_identifier}, include_identifier_for_overwrite_{include_identifier_for_overwrite} {}
~Configuration() = default; ~Configuration() = default;
Configuration(const Configuration&) = default; Configuration(const Configuration&) = default;
@ -113,6 +117,8 @@ struct Module {
std::vector<Command> commands_; std::vector<Command> commands_;
std::string module_; std::string module_;
std::string module_text_;
bool overwrite_module{false};
friend std::ostream& operator << (std::ostream& os, const Module& module); friend std::ostream& operator << (std::ostream& os, const Module& module);
}; };

Loading…
Cancel
Save