forked from csutils/csdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefect.hh
132 lines (112 loc) · 4.07 KB
/
defect.hh
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
/*
* Copyright (C) 2011-2013 Red Hat, Inc.
*
* This file is part of csdiff.
*
* csdiff is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* csdiff is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with csdiff. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef H_GUARD_DEFECT_H
#define H_GUARD_DEFECT_H
#include <limits>
#include <map>
#include <string>
#include <vector>
// FIXME: move this to a separate header file?
#define RETURN_IF_COMPARED(a, b, member) do { \
if (a.member < b.member) \
return true; \
if (b.member < a.member) \
return false; \
} while (0)
// FIXME: move this to a separate header file?
#define RETURN_BY_REF_IF_COMPARED(a, b, member) do { \
if (a.member < b.member) \
*pResult = true; \
else if (b.member < a.member) \
*pResult = false; \
else \
break; \
return true; \
} while (0)
struct DefEvent {
std::string fileName;
int line = 0;
int column = 0;
std::string event;
std::string msg;
/// 0 = key event, 1 = info event, 2 = trace event
int verbosityLevel = 0;
using TNumDiff = unsigned short;
TNumDiff hSize = 0; //< endColumn - startColumn
TNumDiff vSize = 0; //< endLine - startLine
DefEvent() { }
explicit DefEvent(const std::string &event):
event(event)
{
}
void clearLoc()
{
this->fileName.clear();
this->line = 0;
this->column = 0;
this->hSize = 0;
this->vSize = 0;
}
};
///< return (end - beg) if it is positive and fits into target type, 0 otherwise
inline DefEvent::TNumDiff diffNums(const int beg, const int end)
{
const int diff = end - beg;
return (0 < diff && diff < std::numeric_limits<DefEvent::TNumDiff>::max())
? diff
: 0;
}
inline bool cmpEvents(bool *pResult, const DefEvent &a, const DefEvent &b)
{
RETURN_BY_REF_IF_COMPARED(a, b, fileName);
RETURN_BY_REF_IF_COMPARED(a, b, line);
RETURN_BY_REF_IF_COMPARED(a, b, column);
RETURN_BY_REF_IF_COMPARED(a, b, event);
RETURN_BY_REF_IF_COMPARED(a, b, msg);
RETURN_BY_REF_IF_COMPARED(a, b, verbosityLevel);
RETURN_BY_REF_IF_COMPARED(a, b, hSize);
RETURN_BY_REF_IF_COMPARED(a, b, vSize);
// incomparable events
return false;
}
inline bool operator<(const DefEvent &a, const DefEvent &b)
{
bool result;
return cmpEvents(&result, a, b)
&& result;
}
typedef std::vector<DefEvent> TEvtList;
struct Defect {
std::string checker;
std::string annotation;
TEvtList events;
unsigned keyEventIdx = 0U; ///< in range 0..(events.size()-1)
int cwe = 0; ///< CWE number, 0 means unused
int imp = 0; ///< "important" flag, bool for now
int defectId = 0; ///< used only by the JSON format
std::string function; ///< used only by the JSON format
std::string language; ///< used only by the JSON format
std::string tool; ///< used only by the JSON format
Defect() { }
explicit Defect(const std::string &checker):
checker(checker)
{
}
};
#endif /* H_GUARD_DEFECT_H */