forked from viva64/plog-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuppressfilter.cpp
139 lines (118 loc) · 3.13 KB
/
suppressfilter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// 2006-2008 (c) Viva64.com Team
// 2008-2020 (c) OOO "Program Verification Systems"
#include "suppressfilter.h"
#include "warning.h"
#include <cstring>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cassert>
namespace PlogConverter
{
static size_t AnalyzerLevelIndex(AnalyzerType type, int level)
{
assert(level >= 1 && level <= Analyzer::LevelsCount);
assert(type != AnalyzerType::Unknown);
return static_cast<size_t>(type) * Analyzer::LevelsCount + (level - 1);
}
SuppressFilter::SuppressFilter(const ProgramOptions &options)
: m_disabledWarnings(options.disabledWarnings)
, m_enabledAnalyzerLevels(Analyzer::AnalyzersCount * Analyzer::LevelsCount, options.enabledAnalyzers.empty() ? 1 : 0)
, m_enabledFiles(options.enabledFiles.size())
, m_enabledWarnings(options.enabledWarnings)
{
for (const Analyzer& it : options.enabledAnalyzers)
{
if (it.levels.empty())
{
for (int l = 1; l <= Analyzer::LevelsCount; ++l)
{
m_enabledAnalyzerLevels[AnalyzerLevelIndex(it.type, l)] = 1;
}
}
for (int l : it.levels)
{
m_enabledAnalyzerLevels[AnalyzerLevelIndex(it.type, l)] = 1;
}
}
for (size_t count = 0; count < options.enabledFiles.size(); ++count)
{
auto &file = options.enabledFiles[count];
if (auto linePos = file.rfind(':');
linePos != std::string::npos)
{
auto name = file.substr(0, linePos - 1);
auto line = file.substr(linePos + 1);
try
{
m_enabledFiles[count].line = std::stoul(line);
}
catch (std::invalid_argument &)
{
name = file;
}
m_enabledFiles[count].name = name;
}
else
{
m_enabledFiles[count].name = file;
}
}
}
SuppressFilter::~SuppressFilter() = default;
bool SuppressFilter::Check(const Warning &message) const
{
return CheckCode(message)
&& CheckFalseAlarm(message)
&& CheckFiles(message)
&& CheckLevel(message)
&& CheckWarnings(message);
}
bool SuppressFilter::CheckCode(const Warning &message) const
{
return m_disabledWarnings.find(message.code) == m_disabledWarnings.end();
}
bool SuppressFilter::CheckFalseAlarm(const Warning &message) const
{
return !message.falseAlarm;
}
bool SuppressFilter::CheckFiles(const Warning &message) const
{
if (m_enabledFiles.empty())
{
return true;
}
for (auto file : m_enabledFiles)
{
if ( File::CheckName(message, file)
&& File::CheckLine(message, file))
{
return true;
}
}
return false;
}
bool SuppressFilter::CheckLevel(const Warning &message) const
{
const AnalyzerType type = message.GetType();
return message.level <= 0
|| message.level > Analyzer::LevelsCount
|| type == AnalyzerType::Unknown
|| m_enabledAnalyzerLevels[AnalyzerLevelIndex(type, message.level)];
}
bool SuppressFilter::CheckWarnings(const Warning &message) const
{
if (m_enabledWarnings.empty())
{
return true;
}
for (auto warning : m_enabledWarnings)
{
if (warning == message.GetErrorCode())
{
return true;
}
}
return false;
}
}