From ca9b1d779d5483a7699375b079e0bef145fe0729 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 16 Sep 2024 23:48:30 +0200 Subject: [PATCH] Print file name before warning from stream readers, compress warnings if necessary, add file name to errors --- src/db/db/dbReader.cc | 35 ++++++++++++++++++- src/db/db/dbReader.h | 15 ++++++++ .../streamers/cif/db_plugin/dbCIFReader.cc | 20 +++++++---- .../streamers/cif/db_plugin/dbCIFReader.h | 4 +-- .../streamers/dxf/db_plugin/dbDXFReader.cc | 34 +++++++++++------- .../streamers/dxf/db_plugin/dbDXFReader.h | 8 ++--- .../db_plugin/contrib/dbGDS2TextReader.cc | 20 +++++++---- .../gds2/db_plugin/contrib/dbGDS2TextReader.h | 4 +-- .../streamers/gds2/db_plugin/dbGDS2Reader.cc | 22 ++++++++---- .../streamers/gds2/db_plugin/dbGDS2Reader.h | 4 +-- .../streamers/magic/db_plugin/dbMAGReader.cc | 18 +++++++--- .../oasis/db_plugin/dbOASISReader.cc | 24 +++++++++---- .../streamers/oasis/db_plugin/dbOASISReader.h | 4 +-- 13 files changed, 156 insertions(+), 56 deletions(-) diff --git a/src/db/db/dbReader.cc b/src/db/db/dbReader.cc index a5b10cd164..b08e149623 100644 --- a/src/db/db/dbReader.cc +++ b/src/db/db/dbReader.cc @@ -61,7 +61,7 @@ join_layer_names (std::string &s, const std::string &n) // ReaderBase implementation ReaderBase::ReaderBase () - : m_warnings_as_errors (false), m_warn_level (1) + : m_warnings_as_errors (false), m_warn_level (1), m_warn_count_for_same_message (0), m_first_warning (true) { } @@ -79,6 +79,39 @@ void ReaderBase::init (const db::LoadLayoutOptions &options) { m_warn_level = options.warn_level (); + m_last_warning.clear (); + m_warn_count_for_same_message = 0; + m_first_warning = true; +} + +bool +ReaderBase::first_warning () +{ + bool f = m_first_warning; + m_first_warning = false; + return f; +} + +int +ReaderBase::compress_warning (const std::string &msg) +{ + const int max_warnings = 10; + + if (! msg.empty () && msg == m_last_warning) { + if (m_warn_count_for_same_message < max_warnings) { + ++m_warn_count_for_same_message; + return -1; + } else if (m_warn_count_for_same_message == max_warnings) { + ++m_warn_count_for_same_message; + return 0; + } else { + return 1; + } + } else { + m_last_warning = msg; + m_warn_count_for_same_message = 0; + return -1; + } } // --------------------------------------------------------------- diff --git a/src/db/db/dbReader.h b/src/db/db/dbReader.h index dc278e19f3..7d2b1013a8 100644 --- a/src/db/db/dbReader.h +++ b/src/db/db/dbReader.h @@ -126,12 +126,27 @@ class DB_PUBLIC ReaderBase return m_warn_level; } + /** + * @brief Returns true (once) if this is the first warning + */ + bool first_warning (); + + /** + * @brief Returns a value indicating whether to compress the given warning + * + * The return value is either -1 (do not skip), 0 (first warning not to be shown), 1 (warning not shown(. + */ + int compress_warning (const std::string &msg); + protected: virtual void init (const db::LoadLayoutOptions &options); private: bool m_warnings_as_errors; int m_warn_level; + std::string m_last_warning; + int m_warn_count_for_same_message; + bool m_first_warning; }; /** diff --git a/src/plugins/streamers/cif/db_plugin/dbCIFReader.cc b/src/plugins/streamers/cif/db_plugin/dbCIFReader.cc index 00ce57f9a3..d51a94a193 100644 --- a/src/plugins/streamers/cif/db_plugin/dbCIFReader.cc +++ b/src/plugins/streamers/cif/db_plugin/dbCIFReader.cc @@ -86,7 +86,7 @@ CIFReader::read (db::Layout &layout) void CIFReader::error (const std::string &msg) { - throw CIFReaderException (msg, m_stream.line_number (), m_cellname); + throw CIFReaderException (msg, m_stream.line_number (), m_cellname, m_stream.source ()); } void @@ -96,11 +96,19 @@ CIFReader::warn (const std::string &msg, int wl) return; } - // TODO: compress - tl::warn << msg - << tl::to_string (tr (" (line=")) << m_stream.line_number () - << tl::to_string (tr (", cell=")) << m_cellname - << ")"; + if (first_warning ()) { + tl::warn << tl::sprintf (tl::to_string (tr ("In file %s:")), m_stream.source ()); + } + + int ws = compress_warning (msg); + if (ws < 0) { + tl::warn << msg + << tl::to_string (tr (" (line=")) << m_stream.line_number () + << tl::to_string (tr (", cell=")) << m_cellname + << ")"; + } else if (ws == 0) { + tl::warn << tl::to_string (tr ("... further warnings of this kind are not shown")); + } } /** diff --git a/src/plugins/streamers/cif/db_plugin/dbCIFReader.h b/src/plugins/streamers/cif/db_plugin/dbCIFReader.h index 556b7a0a3b..a2b39e47cc 100644 --- a/src/plugins/streamers/cif/db_plugin/dbCIFReader.h +++ b/src/plugins/streamers/cif/db_plugin/dbCIFReader.h @@ -52,8 +52,8 @@ class DB_PLUGIN_PUBLIC CIFReaderException : public ReaderException { public: - CIFReaderException (const std::string &msg, size_t l, const std::string &cell) - : ReaderException (tl::sprintf (tl::to_string (tr ("%s (line=%ld, cell=%s)")), msg, l, cell)) + CIFReaderException (const std::string &msg, size_t l, const std::string &cell, const std::string &source) + : ReaderException (tl::sprintf (tl::to_string (tr ("%s (line=%ld, cell=%s), in file: %s")), msg, l, cell, source)) { } }; diff --git a/src/plugins/streamers/dxf/db_plugin/dbDXFReader.cc b/src/plugins/streamers/dxf/db_plugin/dbDXFReader.cc index a5c4b81ed1..d93975fa49 100644 --- a/src/plugins/streamers/dxf/db_plugin/dbDXFReader.cc +++ b/src/plugins/streamers/dxf/db_plugin/dbDXFReader.cc @@ -367,9 +367,9 @@ void DXFReader::error (const std::string &msg) { if (m_ascii) { - throw DXFReaderException (msg, m_line_number, m_cellname); + throw DXFReaderException (msg, m_line_number, m_cellname, m_stream.source ()); } else { - throw DXFReaderException (msg, m_stream.pos (), m_cellname); + throw DXFReaderException (msg, m_stream.pos (), m_cellname, m_stream.source ()); } } @@ -380,17 +380,25 @@ DXFReader::warn (const std::string &msg, int wl) return; } - // TODO: compress - if (m_ascii) { - tl::warn << msg - << tl::to_string (tr (" (line=")) << m_line_number - << tl::to_string (tr (", cell=")) << m_cellname - << ")"; - } else { - tl::warn << msg - << tl::to_string (tr (" (position=")) << m_stream.pos () - << tl::to_string (tr (", cell=")) << m_cellname - << ")"; + if (first_warning ()) { + tl::warn << tl::sprintf (tl::to_string (tr ("In file %s:")), m_stream.source ()); + } + + int ws = compress_warning (msg); + if (ws < 0) { + if (m_ascii) { + tl::warn << msg + << tl::to_string (tr (" (line=")) << m_line_number + << tl::to_string (tr (", cell=")) << m_cellname + << ")"; + } else { + tl::warn << msg + << tl::to_string (tr (" (position=")) << m_stream.pos () + << tl::to_string (tr (", cell=")) << m_cellname + << ")"; + } + } else if (ws == 0) { + tl::warn << tl::to_string (tr ("... further warnings of this kind are not shown")); } } diff --git a/src/plugins/streamers/dxf/db_plugin/dbDXFReader.h b/src/plugins/streamers/dxf/db_plugin/dbDXFReader.h index c2d5d4d768..4aab23cddd 100644 --- a/src/plugins/streamers/dxf/db_plugin/dbDXFReader.h +++ b/src/plugins/streamers/dxf/db_plugin/dbDXFReader.h @@ -53,12 +53,12 @@ class DB_PLUGIN_PUBLIC DXFReaderException : public ReaderException { public: - DXFReaderException (const std::string &msg, size_t p, const std::string &cell) - : ReaderException (tl::sprintf (tl::to_string (tr ("%s (position=%ld, cell=%s)")), msg.c_str (), p, cell)) + DXFReaderException (const std::string &msg, size_t p, const std::string &cell, const std::string &source) + : ReaderException (tl::sprintf (tl::to_string (tr ("%s (position=%ld, cell=%s), in file: %s")), msg.c_str (), p, cell, source)) { } - DXFReaderException (const std::string &msg, int line, const std::string &cell) - : ReaderException (tl::sprintf (tl::to_string (tr ("%s (line=%d, cell=%s)")), msg.c_str (), line, cell)) + DXFReaderException (const std::string &msg, int line, const std::string &cell, const std::string &source) + : ReaderException (tl::sprintf (tl::to_string (tr ("%s (line=%d, cell=%s), in file: %s")), msg.c_str (), line, cell, source)) { } }; diff --git a/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2TextReader.cc b/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2TextReader.cc index 1fcc0605c6..85bb4f8ef2 100644 --- a/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2TextReader.cc +++ b/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2TextReader.cc @@ -298,7 +298,7 @@ GDS2ReaderText::path () const void GDS2ReaderText::error (const std::string &msg) { - throw GDS2ReaderTextException (msg, int(sStream.line_number()), cellname().c_str ()); + throw GDS2ReaderTextException (msg, int (sStream.line_number()), cellname ().c_str (), sStream.source ()); } void @@ -308,11 +308,19 @@ GDS2ReaderText::warn (const std::string &msg, int wl) return; } - // TODO: compress - tl::warn << msg - << tl::to_string (tr (", line number=")) << sStream.line_number() - << tl::to_string (tr (", cell=")) << cellname ().c_str () - << ")"; + if (first_warning ()) { + tl::warn << tl::sprintf (tl::to_string (tr ("In file %s:")), sStream.source ()); + } + + int ws = compress_warning (msg); + if (ws < 0) { + tl::warn << msg + << tl::to_string (tr (", line number=")) << sStream.line_number() + << tl::to_string (tr (", cell=")) << cellname ().c_str () + << ")"; + } else if (ws == 0) { + tl::warn << tl::to_string (tr ("... further warnings of this kind are not shown")); + } } void diff --git a/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2TextReader.h b/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2TextReader.h index 6ac5431012..2c40e18a25 100644 --- a/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2TextReader.h +++ b/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2TextReader.h @@ -39,8 +39,8 @@ class DB_PLUGIN_PUBLIC GDS2ReaderTextException : public ReaderException { public: - GDS2ReaderTextException (const std::string &msg, size_t n, const std::string &cell) - : ReaderException (tl::sprintf (tl::to_string (tr ("%s (line number=%ld, cell=%s)")).c_str (), msg.c_str (), n, cell.c_str ())) + GDS2ReaderTextException (const std::string &msg, size_t n, const std::string &cell, const std::string &source) + : ReaderException (tl::sprintf (tl::to_string (tr ("%s (line number=%ld, cell=%s), in file: %s")).c_str (), msg.c_str (), n, cell.c_str (), source)) { } }; diff --git a/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.cc b/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.cc index 3582bf32a2..bd782a4656 100644 --- a/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.cc +++ b/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.cc @@ -282,7 +282,7 @@ GDS2Reader::path () const void GDS2Reader::error (const std::string &msg) { - throw GDS2ReaderException (msg, m_stream.pos (), m_recnum, cellname ().c_str ()); + throw GDS2ReaderException (msg, m_stream.pos (), m_recnum, cellname ().c_str (), m_stream.source ()); } void @@ -292,12 +292,20 @@ GDS2Reader::warn (const std::string &msg, int wl) return; } - // TODO: compress - tl::warn << msg - << tl::to_string (tr (" (position=")) << m_stream.pos () - << tl::to_string (tr (", record number=")) << m_recnum - << tl::to_string (tr (", cell=")) << cellname ().c_str () - << ")"; + if (first_warning ()) { + tl::warn << tl::sprintf (tl::to_string (tr ("In file %s:")), m_stream.source ()); + } + + int ws = compress_warning (msg); + if (ws < 0) { + tl::warn << msg + << tl::to_string (tr (" (position=")) << m_stream.pos () + << tl::to_string (tr (", record number=")) << m_recnum + << tl::to_string (tr (", cell=")) << cellname ().c_str () + << ")"; + } else if (ws == 0) { + tl::warn << tl::to_string (tr ("... further warnings of this kind are not shown")); + } } } diff --git a/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.h b/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.h index fe9ad2883d..e7975c0be1 100644 --- a/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.h +++ b/src/plugins/streamers/gds2/db_plugin/dbGDS2Reader.h @@ -48,8 +48,8 @@ class DB_PLUGIN_PUBLIC GDS2ReaderException : public ReaderException { public: - GDS2ReaderException (const std::string &msg, size_t p, size_t n, const std::string &cell) - : ReaderException (tl::sprintf (tl::to_string (tr ("%s (position=%ld, record number=%ld, cell=%s)")), msg, p, n, cell)) + GDS2ReaderException (const std::string &msg, size_t p, size_t n, const std::string &cell, const std::string &source) + : ReaderException (tl::sprintf (tl::to_string (tr ("%s (position=%ld, record number=%ld, cell=%s), in file: %s")), msg, p, n, cell, source)) { } }; diff --git a/src/plugins/streamers/magic/db_plugin/dbMAGReader.cc b/src/plugins/streamers/magic/db_plugin/dbMAGReader.cc index b56e7916e0..05841c10e7 100644 --- a/src/plugins/streamers/magic/db_plugin/dbMAGReader.cc +++ b/src/plugins/streamers/magic/db_plugin/dbMAGReader.cc @@ -143,11 +143,19 @@ MAGReader::warn (const std::string &msg, int wl) return; } - // TODO: compress - tl::warn << msg - << tl::to_string (tr (" (line=")) << mp_current_stream->line_number () - << tl::to_string (tr (", file=")) << mp_current_stream->source () - << ")"; + if (first_warning ()) { + tl::warn << tl::sprintf (tl::to_string (tr ("In file %s:")), mp_current_stream->source ()); + } + + int ws = compress_warning (msg); + if (ws < 0) { + tl::warn << msg + << tl::to_string (tr (" (line=")) << mp_current_stream->line_number () + << tl::to_string (tr (", file=")) << mp_current_stream->source () + << ")"; + } else if (ws == 0) { + tl::warn << tl::to_string (tr ("... further warnings of this kind are not shown")); + } } db::cell_index_type diff --git a/src/plugins/streamers/oasis/db_plugin/dbOASISReader.cc b/src/plugins/streamers/oasis/db_plugin/dbOASISReader.cc index 04e312470d..efaead612a 100644 --- a/src/plugins/streamers/oasis/db_plugin/dbOASISReader.cc +++ b/src/plugins/streamers/oasis/db_plugin/dbOASISReader.cc @@ -482,7 +482,7 @@ OASISReader::get_gdelta (long grid) void OASISReader::error (const std::string &msg) { - throw OASISReaderException (msg, m_stream.pos (), m_cellname.c_str ()); + throw OASISReaderException (msg, m_stream.pos (), m_cellname.c_str (), m_stream.source ()); } void @@ -493,13 +493,25 @@ OASISReader::warn (const std::string &msg, int wl) } if (warnings_as_errors ()) { + error (msg); + } else { - // TODO: compress - tl::warn << msg - << tl::to_string (tr (" (position=")) << m_stream.pos () - << tl::to_string (tr (", cell=")) << m_cellname - << ")"; + + if (first_warning ()) { + tl::warn << tl::sprintf (tl::to_string (tr ("In file %s:")), m_stream.source ()); + } + + int ws = compress_warning (msg); + if (ws < 0) { + tl::warn << msg + << tl::to_string (tr (" (position=")) << m_stream.pos () + << tl::to_string (tr (", cell=")) << m_cellname + << ")"; + } else if (ws == 0) { + tl::warn << tl::to_string (tr ("... further warnings of this kind are not shown")); + } + } } diff --git a/src/plugins/streamers/oasis/db_plugin/dbOASISReader.h b/src/plugins/streamers/oasis/db_plugin/dbOASISReader.h index 2f7c372e4f..720da38caf 100644 --- a/src/plugins/streamers/oasis/db_plugin/dbOASISReader.h +++ b/src/plugins/streamers/oasis/db_plugin/dbOASISReader.h @@ -54,8 +54,8 @@ class DB_PLUGIN_PUBLIC OASISReaderException : public ReaderException { public: - OASISReaderException (const std::string &msg, size_t p, const std::string &cell) - : ReaderException (tl::sprintf (tl::to_string (tr ("%s (position=%ld, cell=%s)")), msg, p, cell)) + OASISReaderException (const std::string &msg, size_t p, const std::string &cell, const std::string &source) + : ReaderException (tl::sprintf (tl::to_string (tr ("%s (position=%ld, cell=%s), in file: %s")), msg, p, cell, source)) { } };