Browse Source

Output line number for GalileoParser errors

tempestpy_adaptions
Matthias Volk 6 years ago
parent
commit
15bcb8afb6
  1. 38
      src/storm-dft/parser/DFTGalileoParser.cpp
  2. 3
      src/storm-dft/parser/DFTGalileoParser.h

38
src/storm-dft/parser/DFTGalileoParser.cpp

@ -145,7 +145,7 @@ namespace storm {
ValueType probability = valueParser.parseValue(type.substr(5)); ValueType probability = valueParser.parseValue(type.substr(5));
success = builder.addDepElement(name, childNames, probability); success = builder.addDepElement(name, childNames, probability);
} else if (type.find("=") != std::string::npos) { } else if (type.find("=") != std::string::npos) {
success = parseBasicElement(name, line, builder, valueParser);
success = parseBasicElement(name, line, lineNo, builder, valueParser);
} else if (type.find("insp") != std::string::npos) { } else if (type.find("insp") != std::string::npos) {
// Inspection as defined by DFTCalc // Inspection as defined by DFTCalc
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Inspections (defined in line " << lineNo << ") are not supported."); STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Inspections (defined in line " << lineNo << ") are not supported.");
@ -204,7 +204,7 @@ namespace storm {
} }
template<typename ValueType> template<typename ValueType>
bool DFTGalileoParser<ValueType>::parseBasicElement(std::string const& name, std::string const& input, storm::builder::DFTBuilder<ValueType>& builder, ValueParser<ValueType>& valueParser) {
bool DFTGalileoParser<ValueType>::parseBasicElement(std::string const& name, std::string const& input, size_t lineNo, storm::builder::DFTBuilder<ValueType>& builder, ValueParser<ValueType>& valueParser) {
// Default values // Default values
Distribution distribution = Distribution::None; Distribution distribution = Distribution::None;
ValueType firstValDistribution = storm::utility::zero<ValueType>(); ValueType firstValDistribution = storm::utility::zero<ValueType>();
@ -220,14 +220,14 @@ namespace storm {
// Constant distribution // Constant distribution
std::pair<bool, ValueType> result = parseValue("prob", line, valueParser); std::pair<bool, ValueType> result = parseValue("prob", line, valueParser);
if (result.first) { if (result.first) {
STORM_LOG_THROW(distribution == Distribution::None, storm::exceptions::WrongFormatException, "A different distribution was already defined for this basic element.");
STORM_LOG_THROW(distribution == Distribution::None, storm::exceptions::WrongFormatException, "A different distribution was already defined for basic element '" << name << "' in line " << lineNo << ".");
firstValDistribution = result.second; firstValDistribution = result.second;
distribution = Distribution::Constant; distribution = Distribution::Constant;
} }
// Exponential distribution // Exponential distribution
result = parseValue("lambda", line, valueParser); result = parseValue("lambda", line, valueParser);
if (result.first) { if (result.first) {
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::Erlang, storm::exceptions::WrongFormatException, "A different distribution was already defined for this basic element.");
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::Erlang, storm::exceptions::WrongFormatException, "A different distribution was already defined for basic element '" << name << "' in line " << lineNo << ".");
firstValDistribution = result.second; firstValDistribution = result.second;
if (distribution == Distribution::None) { if (distribution == Distribution::None) {
distribution = Distribution::Exponential; distribution = Distribution::Exponential;
@ -236,53 +236,53 @@ namespace storm {
// Erlang distribution // Erlang distribution
std::pair<bool, unsigned> resultNum = parseNumber("phases", line); std::pair<bool, unsigned> resultNum = parseNumber("phases", line);
if (resultNum.first) { if (resultNum.first) {
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::Exponential, storm::exceptions::WrongFormatException, "A different distribution was already defined for this basic element.");
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::Exponential, storm::exceptions::WrongFormatException, "A different distribution was already defined for basic element '" << name << "' in line " << lineNo << ".");
erlangPhases = resultNum.second; erlangPhases = resultNum.second;
distribution = Distribution::Erlang; distribution = Distribution::Erlang;
} }
// Weibull distribution // Weibull distribution
result = parseValue("rate", line, valueParser); result = parseValue("rate", line, valueParser);
if (result.first) { if (result.first) {
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::Weibull, storm::exceptions::WrongFormatException, "A different distribution was already defined for this basic element.");
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::Weibull, storm::exceptions::WrongFormatException, "A different distribution was already defined for basic element '" << name << "' in line " << lineNo << ".");
firstValDistribution = result.second; firstValDistribution = result.second;
distribution = Distribution::Weibull; distribution = Distribution::Weibull;
} }
result = parseValue("shape", line, valueParser); result = parseValue("shape", line, valueParser);
if (result.first) { if (result.first) {
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::Weibull, storm::exceptions::WrongFormatException, "A different distribution was already defined for this basic element.");
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::Weibull, storm::exceptions::WrongFormatException, "A different distribution was already defined for basic element '" << name << "' in line " << lineNo << ".");
secondValDistribution = result.second; secondValDistribution = result.second;
distribution = Distribution::Weibull; distribution = Distribution::Weibull;
} }
// Lognormal distribution // Lognormal distribution
result = parseValue("mean", line, valueParser); result = parseValue("mean", line, valueParser);
if (result.first) { if (result.first) {
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::LogNormal, storm::exceptions::WrongFormatException, "A different distribution was already defined for this basic element.");
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::LogNormal, storm::exceptions::WrongFormatException, "A different distribution was already defined for basic element '" << name << "' in line " << lineNo << ".");
firstValDistribution = result.second; firstValDistribution = result.second;
distribution = Distribution::LogNormal; distribution = Distribution::LogNormal;
} }
result = parseValue("stddev", line, valueParser); result = parseValue("stddev", line, valueParser);
if (result.first) { if (result.first) {
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::LogNormal, storm::exceptions::WrongFormatException, "A different distribution was already defined for this basic element.");
STORM_LOG_THROW(distribution == Distribution::None || distribution == Distribution::LogNormal, storm::exceptions::WrongFormatException, "A different distribution was already defined for basic element '" << name << "' in line " << lineNo << ".");
secondValDistribution = result.second; secondValDistribution = result.second;
distribution = Distribution::LogNormal; distribution = Distribution::LogNormal;
} }
// Additional arguments // Additional arguments
result = parseValue("cov", line, valueParser); result = parseValue("cov", line, valueParser);
if (result.first) { if (result.first) {
STORM_LOG_WARN("Coverage is not supported and will be ignored.");
STORM_LOG_WARN("Coverage is not supported and will be ignored for basic element '" << name << "' in line " << lineNo << ".");
} }
result = parseValue("res", line, valueParser); result = parseValue("res", line, valueParser);
if (result.first) { if (result.first) {
STORM_LOG_WARN("Restoration is not supported and will be ignored.");
STORM_LOG_WARN("Restoration is not supported and will be ignored for basic element '" << name << "' in line " << lineNo << ".");
} }
resultNum = parseNumber("repl", line); resultNum = parseNumber("repl", line);
if (resultNum.first) { if (resultNum.first) {
replication = resultNum.second; replication = resultNum.second;
STORM_LOG_THROW(replication == 1, storm::exceptions::NotSupportedException, "Replication > 1 is not supported.");
STORM_LOG_THROW(replication == 1, storm::exceptions::NotSupportedException, "Replication > 1 is not supported for basic element '" << name << "' in line " << lineNo << ".");
} }
result = parseValue("interval", line, valueParser); result = parseValue("interval", line, valueParser);
if (result.first) { if (result.first) {
STORM_LOG_WARN("Interval is not supported and will be ignored.");
STORM_LOG_WARN("Interval is not supported and will be ignored for basic element '" << name << "' in line " << lineNo << ".");
} }
result = parseValue("dorm", line, valueParser); result = parseValue("dorm", line, valueParser);
if (result.first) { if (result.first) {
@ -290,12 +290,12 @@ namespace storm {
} }
boost::trim(line); boost::trim(line);
if (line != "") { if (line != "") {
STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Unknown arguments: " << line << ".");
STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Unknown arguments for basic element '" << name << "' in line " << lineNo << ": " << line);
} }
switch (distribution) { switch (distribution) {
case Constant: case Constant:
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Constant distribution is not supported.");
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Constant distribution is not supported for basic element '" << name << "' in line " << lineNo << ".");
break; break;
case Exponential: case Exponential:
return builder.addBasicElement(parseName(name), firstValDistribution, dormancyFactor, false); // TODO set transient BEs return builder.addBasicElement(parseName(name), firstValDistribution, dormancyFactor, false); // TODO set transient BEs
@ -307,7 +307,7 @@ namespace storm {
} else { } else {
// Model Erlang distribution by using SEQ over BEs instead. // Model Erlang distribution by using SEQ over BEs instead.
// For each phase a BE is added, then the SEQ ensures the ordered failure. // For each phase a BE is added, then the SEQ ensures the ordered failure.
STORM_LOG_WARN("Erlang distribution is modelled by SEQ gate and BEs.");
STORM_LOG_WARN("Erlang distribution for basic element '" << name << "' in line " << lineNo << " is modelled by SEQ gate and BEs.");
std::string origName = parseName(name); std::string origName = parseName(name);
std::vector<std::string> childNames; std::vector<std::string> childNames;
bool success = builder.addBasicElement(origName, firstValDistribution, dormancyFactor, false); // TODO set transient BEs bool success = builder.addBasicElement(origName, firstValDistribution, dormancyFactor, false); // TODO set transient BEs
@ -325,16 +325,16 @@ namespace storm {
// Weibull distribution reduces to exponential distribution // Weibull distribution reduces to exponential distribution
return builder.addBasicElement(parseName(name), firstValDistribution, dormancyFactor, false); // TODO set transient BEs return builder.addBasicElement(parseName(name), firstValDistribution, dormancyFactor, false); // TODO set transient BEs
} else { } else {
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Weibull distribution is not supported.");
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Weibull distribution is not supported for basic element '" << name << "' in line " << lineNo << ".");
} }
break; break;
case LogNormal: case LogNormal:
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "LogNormal distribution is not supported.");
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "LogNormal distribution is not supported for basic element '" << name << "' in line " << lineNo << ".");
break; break;
case None: case None:
// go-through // go-through
default: default:
STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "No distribution for basic element defined.");
STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "No distribution defined for basic element '" << name << "' in line " << lineNo << ".");
break; break;
} }
return false; return false;

3
src/storm-dft/parser/DFTGalileoParser.h

@ -47,12 +47,13 @@ namespace storm {
* *
* @param name Name of BE. * @param name Name of BE.
* @param input Input line. * @param input Input line.
* @param lineNo Line number.
* @param builder DFTBuilder. * @param builder DFTBuilder.
* @param valueParser ValueParser. * @param valueParser ValueParser.
* *
* @return True iff the parsing and creation was successful. * @return True iff the parsing and creation was successful.
*/ */
static bool parseBasicElement(std::string const& name, std::string const& input, storm::builder::DFTBuilder<ValueType>& builder, ValueParser<ValueType>& valueParser);
static bool parseBasicElement(std::string const& name, std::string const& input, size_t lineNo, storm::builder::DFTBuilder<ValueType>& builder, ValueParser<ValueType>& valueParser);
/*! /*!
* Parse argument of basic element of the form "name=value". * Parse argument of basic element of the form "name=value".

Loading…
Cancel
Save