Browse Source

basic overwrite guard and update

overwrites
Thomas Knoll 11 months ago
committed by sp
parent
commit
df00224661
  1. 2
      main.cpp
  2. 36
      util/ConfigYaml.cpp
  3. 8
      util/ConfigYaml.h

2
main.cpp

@ -177,7 +177,7 @@ int main(int argc, char* argv[]) {
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";
} 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::exit(EXIT_FAILURE);
}

36
util/ConfigYaml.cpp

@ -47,10 +47,10 @@ std::string Formula::createExpression() const {
std::string Command::createExpression() const {
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 {
@ -76,6 +76,13 @@ bool YAML::convert<Module>::decode(const YAML::Node& node, Module& rhs) {
}
rhs.commands_ = node["commands"].as<std::vector<Command>>();
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;
}
@ -96,8 +103,13 @@ bool YAML::convert<Command>::decode(const YAML::Node& node, Command& rhs) {
}
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"]) {
rhs.overwrite_ = node["overwrite"].as<bool>();
@ -249,8 +261,22 @@ YamlConfigParseResult YamlConfigParser::parseConfiguration() {
configuration.push_back({formula.createExpression(), formula.formula_ ,ConfigType::Formula, formula.overwrite_});
}
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_) {
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) {

8
util/ConfigYaml.h

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

Loading…
Cancel
Save