From 7e0524b8a2390203d6e5306c7067a8cb19c8aa0c Mon Sep 17 00:00:00 2001 From: couriersud Date: Mon, 22 Apr 2019 14:49:28 +0200 Subject: [PATCH] netlist: fix some error/warnings. (nw) --- src/lib/netlist/nl_errstr.h | 1 + src/lib/netlist/nl_setup.cpp | 11 +++-- src/lib/netlist/plib/pstring.h | 70 ------------------------------- src/lib/netlist/plib/putil.h | 76 +++++++++++++++++++++++++++++++++- 4 files changed, 84 insertions(+), 74 deletions(-) diff --git a/src/lib/netlist/nl_errstr.h b/src/lib/netlist/nl_errstr.h index d6cbe477931..6f9aa0d7d12 100644 --- a/src/lib/netlist/nl_errstr.h +++ b/src/lib/netlist/nl_errstr.h @@ -88,6 +88,7 @@ namespace netlist PERRMSGV(MF_MODEL_PARAMETERS_NOT_UPPERCASE_1_2, 2, "Model parameters should be uppercase:{1} {2}") PERRMSGV(MF_ENTITY_1_NOT_FOUND_IN_MODEL_2, 2, "Entity {1} not found in model {2}") PERRMSGV(MF_UNKNOWN_NUMBER_FACTOR_IN_1, 1, "Unknown number factor in: {1}") + PERRMSGV(MF_MODEL_NUMBER_CONVERSION_ERROR, 4, "Can't convert {1}={2} to {3} for model {4}") PERRMSGV(MF_NOT_FOUND_IN_SOURCE_COLLECTION, 1, "unable to find {1} in sources collection") PERRMSGV(MW_OVERWRITING_PARAM_1_OLD_2_NEW_3, 3, "Overwriting {1} old <{2}> new <{3}>") diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 816669f2d3c..2c6b51eaaec 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -955,7 +955,11 @@ nl_double models_t::value(const pstring &model, const pstring &entity) tmp = plib::left(tmp, tmp.size() - 1); // FIXME: check for errors //printf("%s %s %e %e\n", entity.c_str(), tmp.c_str(), plib::pstonum(tmp), factor); - return plib::pstonum(tmp) * factor; + bool err(false); + nl_double val = plib::pstonum_ne(tmp, err); + if (err) + throw nl_exception(MF_MODEL_NUMBER_CONVERSION_ERROR(entity, tmp, "double", model)); + return val * factor; } class logic_family_std_proxy_t : public logic_family_desc_t @@ -1118,8 +1122,9 @@ void setup_t::prepare_to_run() if (p != m_param_values.end()) { //FIXME: check for errors ... - auto v = plib::pstonum(p->second); - if (std::abs(v - std::floor(v)) > 1e-6 ) + bool err(false); + auto v = plib::pstonum_ne(p->second, err); + if (err || std::abs(v - std::floor(v)) > 1e-6 ) log().fatal(MF_HND_VAL_NOT_SUPPORTED(p->second)); d.second->set_hint_deactivate(v == 0.0); } diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index c4caeab8e8f..cb4ad651548 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -510,76 +510,6 @@ namespace plib return pwstring(std::to_wstring(v)); } - template - struct pstonum_helper; - - template - struct pstonum_helper::value - && std::is_signed::value>::type> - { - template - long long operator()(const S &arg, std::size_t *idx) - { - return std::stoll(arg, idx); - } - }; - - template - struct pstonum_helper::value - && !std::is_signed::value>::type> - { - template - unsigned long long operator()(const S &arg, std::size_t *idx) - { - return std::stoull(arg, idx); - } - }; - - template - struct pstonum_helper::value>::type> - { - template - long double operator()(const S &arg, std::size_t *idx) - { - return std::stold(arg, idx); - } - }; - - template - T pstonum(const S &arg) - { - decltype(arg.c_str()) cstr = arg.c_str(); - std::size_t idx(0); - auto ret = pstonum_helper()(cstr, &idx); - using ret_type = decltype(ret); - if (ret >= static_cast(std::numeric_limits::lowest()) - && ret <= static_cast(std::numeric_limits::max())) - //&& (ret == T(0) || std::abs(ret) >= std::numeric_limits::min() )) - { - if (cstr[idx] != 0) - throw std::invalid_argument(std::string("Continuation after numeric value ends: ") + cstr); - } - else - { - throw std::out_of_range(std::string("Out of range: ") + cstr); - } - return static_cast(ret); - } - - template - R pstonum_ne(const T &str, bool &err) noexcept - { - try - { - err = false; - return pstonum(str); - } - catch (...) - { - err = true; - return R(0); - } - } template typename T::size_type find_first_not_of(const T &str, const T &no) diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index 2e0158891f6..5dadb9a0bb5 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -9,7 +9,7 @@ #define PUTIL_H_ #include "pstring.h" - +#include "pexception.h" #include #include #include @@ -124,6 +124,80 @@ namespace plib const std::string &token, const std::size_t maxsplit); + // ---------------------------------------------------------------------------------------- + // number conversions + // ---------------------------------------------------------------------------------------- + + template + struct pstonum_helper; + + template + struct pstonum_helper::value + && std::is_signed::value>::type> + { + template + long long operator()(const S &arg, std::size_t *idx) + { + return std::stoll(arg, idx); + } + }; + + template + struct pstonum_helper::value + && !std::is_signed::value>::type> + { + template + unsigned long long operator()(const S &arg, std::size_t *idx) + { + return std::stoull(arg, idx); + } + }; + + template + struct pstonum_helper::value>::type> + { + template + long double operator()(const S &arg, std::size_t *idx) + { + return std::stold(arg, idx); + } + }; + + template + T pstonum(const S &arg) + { + decltype(arg.c_str()) cstr = arg.c_str(); + std::size_t idx(0); + auto ret = pstonum_helper()(cstr, &idx); + using ret_type = decltype(ret); + if (ret >= static_cast(std::numeric_limits::lowest()) + && ret <= static_cast(std::numeric_limits::max())) + //&& (ret == T(0) || std::abs(ret) >= std::numeric_limits::min() )) + { + if (cstr[idx] != 0) + throw pexception(pstring("Continuation after numeric value ends: ") + cstr); + } + else + { + throw pexception(pstring("Out of range: ") + cstr); + } + return static_cast(ret); + } + + template + R pstonum_ne(const T &str, bool &err) noexcept + { + try + { + err = false; + return pstonum(str); + } + catch (...) + { + err = true; + return R(0); + } + } //============================================================ // penum - strongly typed enumeration