logger: fix for multiple calls with same pattern
authorEddie Hung <eddie@fpgeh.com>
Mon, 11 May 2020 17:01:29 +0000 (10:01 -0700)
committerEddie Hung <eddie@fpgeh.com>
Thu, 14 May 2020 17:32:07 +0000 (10:32 -0700)
passes/cmds/logger.cc

index 9a27952d4acbbe0430c715f73d8b38f07a2d7dc5..64f939525856a97cd0d0841d96685b96fc1bb375 100644 (file)
@@ -158,12 +158,40 @@ struct LoggerPass : public Pass {
                                        log_cmd_error("Expected error message occurrences must be 1 !\n");
                                log("Added regex '%s' for warnings to expected %s list.\n", pattern.c_str(), type.c_str());
                                try {
-                                       if (type=="error")
-                                               log_expect_error.push_back(std::make_pair(YS_REGEX_COMPILE(pattern), LogExpectedItem(pattern, count)));
-                                       else if (type=="warning")
-                                               log_expect_warning.push_back(std::make_pair(YS_REGEX_COMPILE(pattern), LogExpectedItem(pattern, count)));
-                                       else
-                                               log_expect_log.push_back(std::make_pair(YS_REGEX_COMPILE(pattern), LogExpectedItem(pattern, count)));
+                                       if (type=="error") {
+                                               auto it = log_expect_error.begin();
+                                               auto ie = log_expect_error.end();
+                                               for (; it != ie; it++)
+                                                       if (it->second.pattern == pattern) {
+                                                               it->second.expected_count = count;
+                                                               break;
+                                                       }
+                                               if (it == ie)
+                                                       log_expect_error.emplace_back(YS_REGEX_COMPILE(pattern), LogExpectedItem(pattern, count));
+                                       }
+                                       else if (type=="warning") {
+                                               auto it = log_expect_warning.begin();
+                                               auto ie = log_expect_warning.end();
+                                               for (; it != ie; it++)
+                                                       if (it->second.pattern == pattern) {
+                                                               it->second.expected_count = count;
+                                                               break;
+                                                       }
+                                               if (it == ie)
+                                                       log_expect_warning.emplace_back(YS_REGEX_COMPILE(pattern), LogExpectedItem(pattern, count));
+                                       }
+                                       else if (type=="log") {
+                                               auto it = log_expect_log.begin();
+                                               auto ie = log_expect_log.end();
+                                               for (; it != ie; it++)
+                                                       if (it->second.pattern == pattern) {
+                                                               it->second.expected_count = count;
+                                                               break;
+                                                       }
+                                               if (it == ie)
+                                                       log_expect_log.emplace_back(YS_REGEX_COMPILE(pattern), LogExpectedItem(pattern, count));
+                                       }
+                                       else log_abort();
                                }
                                catch (const YS_REGEX_NS::regex_error& e) {
                                        log_cmd_error("Error in regex expression '%s' !\n", pattern.c_str());