From 15bcb8afb6d0181faf1efb8e3da37b1f1a7954f5 Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Fri, 1 Mar 2019 15:59:15 +0100 Subject: [PATCH] Output line number for GalileoParser errors --- src/storm-dft/parser/DFTGalileoParser.cpp | 38 +++++++++++------------ src/storm-dft/parser/DFTGalileoParser.h | 3 +- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/storm-dft/parser/DFTGalileoParser.cpp b/src/storm-dft/parser/DFTGalileoParser.cpp index 51d970700..7416d3dea 100644 --- a/src/storm-dft/parser/DFTGalileoParser.cpp +++ b/src/storm-dft/parser/DFTGalileoParser.cpp @@ -145,7 +145,7 @@ namespace storm { ValueType probability = valueParser.parseValue(type.substr(5)); success = builder.addDepElement(name, childNames, probability); } 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) { // Inspection as defined by DFTCalc STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Inspections (defined in line " << lineNo << ") are not supported."); @@ -204,7 +204,7 @@ namespace storm { } template - bool DFTGalileoParser::parseBasicElement(std::string const& name, std::string const& input, storm::builder::DFTBuilder& builder, ValueParser& valueParser) { + bool DFTGalileoParser::parseBasicElement(std::string const& name, std::string const& input, size_t lineNo, storm::builder::DFTBuilder& builder, ValueParser& valueParser) { // Default values Distribution distribution = Distribution::None; ValueType firstValDistribution = storm::utility::zero(); @@ -220,14 +220,14 @@ namespace storm { // Constant distribution std::pair result = parseValue("prob", line, valueParser); 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; distribution = Distribution::Constant; } // Exponential distribution result = parseValue("lambda", line, valueParser); 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; if (distribution == Distribution::None) { distribution = Distribution::Exponential; @@ -236,53 +236,53 @@ namespace storm { // Erlang distribution std::pair resultNum = parseNumber("phases", line); 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; distribution = Distribution::Erlang; } // Weibull distribution result = parseValue("rate", line, valueParser); 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; distribution = Distribution::Weibull; } result = parseValue("shape", line, valueParser); 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; distribution = Distribution::Weibull; } // Lognormal distribution result = parseValue("mean", line, valueParser); 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; distribution = Distribution::LogNormal; } result = parseValue("stddev", line, valueParser); 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; distribution = Distribution::LogNormal; } // Additional arguments result = parseValue("cov", line, valueParser); 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); 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); if (resultNum.first) { 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); 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); if (result.first) { @@ -290,12 +290,12 @@ namespace storm { } boost::trim(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) { 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; case Exponential: return builder.addBasicElement(parseName(name), firstValDistribution, dormancyFactor, false); // TODO set transient BEs @@ -307,7 +307,7 @@ namespace storm { } else { // Model Erlang distribution by using SEQ over BEs instead. // 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::vector childNames; bool success = builder.addBasicElement(origName, firstValDistribution, dormancyFactor, false); // TODO set transient BEs @@ -325,16 +325,16 @@ namespace storm { // Weibull distribution reduces to exponential distribution return builder.addBasicElement(parseName(name), firstValDistribution, dormancyFactor, false); // TODO set transient BEs } 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; 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; case None: // go-through 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; } return false; diff --git a/src/storm-dft/parser/DFTGalileoParser.h b/src/storm-dft/parser/DFTGalileoParser.h index 3ead2ddcb..0c280fd88 100644 --- a/src/storm-dft/parser/DFTGalileoParser.h +++ b/src/storm-dft/parser/DFTGalileoParser.h @@ -47,12 +47,13 @@ namespace storm { * * @param name Name of BE. * @param input Input line. + * @param lineNo Line number. * @param builder DFTBuilder. * @param valueParser ValueParser. * * @return True iff the parsing and creation was successful. */ - static bool parseBasicElement(std::string const& name, std::string const& input, storm::builder::DFTBuilder& builder, ValueParser& valueParser); + static bool parseBasicElement(std::string const& name, std::string const& input, size_t lineNo, storm::builder::DFTBuilder& builder, ValueParser& valueParser); /*! * Parse argument of basic element of the form "name=value".