Coverage Report

Created: 2023-09-25 06:15

/src/cppcheck/lib/errortypes.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Cppcheck - A tool for static C/C++ code analysis
3
 * Copyright (C) 2007-2022 Cppcheck team.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
#include "errortypes.h"
20
21
static std::string typeToString(InternalError::Type type)
22
1
{
23
1
    switch (type) {
24
1
    case InternalError::Type::AST:
25
1
        return "internalAstError";
26
0
    case InternalError::Type::SYNTAX:
27
0
        return "syntaxError";
28
0
    case InternalError::Type::UNKNOWN_MACRO:
29
0
        return "unknownMacro";
30
0
    case InternalError::Type::INTERNAL:
31
0
        return "internalError";
32
0
    case InternalError::Type::LIMIT:
33
0
        return "cppcheckLimit";
34
0
    case InternalError::Type::INSTANTIATION:
35
0
        return "instantiationError";
36
1
    }
37
1
}
38
39
InternalError::InternalError(const Token *tok, std::string errorMsg, Type type) :
40
    InternalError(tok, std::move(errorMsg), "", type)
41
1
{}
42
43
InternalError::InternalError(const Token *tok, std::string errorMsg, std::string details, Type type) :
44
    token(tok), errorMessage(std::move(errorMsg)), details(std::move(details)), type(type), id(typeToString(type))
45
1
{}
46
47
std::string Severity::toString(Severity::SeverityType severity)
48
1.48k
{
49
1.48k
    switch (severity) {
50
0
    case none:
51
0
        return "";
52
5
    case error:
53
5
        return "error";
54
257
    case warning:
55
257
        return "warning";
56
1.22k
    case style:
57
1.22k
        return "style";
58
0
    case performance:
59
0
        return "performance";
60
0
    case portability:
61
0
        return "portability";
62
0
    case information:
63
0
        return "information";
64
0
    case debug:
65
0
        return "debug";
66
1.48k
    }
67
0
    throw InternalError(nullptr, "Unknown severity");
68
1.48k
}
69
Severity::SeverityType Severity::fromString(const std::string& severity)
70
0
{
71
0
    if (severity.empty())
72
0
        return none;
73
0
    if (severity == "none")
74
0
        return none;
75
0
    if (severity == "error")
76
0
        return error;
77
0
    if (severity == "warning")
78
0
        return warning;
79
0
    if (severity == "style")
80
0
        return style;
81
0
    if (severity == "performance")
82
0
        return performance;
83
0
    if (severity == "portability")
84
0
        return portability;
85
0
    if (severity == "information")
86
0
        return information;
87
0
    if (severity == "debug")
88
0
        return debug;
89
0
    return none;
90
0
}