2020-05-23 07:16:49 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2023-12-20 21:41:58 +01:00
|
|
|
* Copyright (C) 2007-2023 Cppcheck team.
|
2020-05-23 07:16:49 +02:00
|
|
|
*
|
|
|
|
* This program 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
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "errortypes.h"
|
|
|
|
|
2023-10-09 12:25:56 +02:00
|
|
|
#include "utils.h"
|
|
|
|
|
2023-09-20 10:40:57 +02:00
|
|
|
static std::string typeToString(InternalError::Type type)
|
2022-07-28 22:51:45 +02:00
|
|
|
{
|
|
|
|
switch (type) {
|
2023-09-20 10:40:57 +02:00
|
|
|
case InternalError::Type::AST:
|
|
|
|
return "internalAstError";
|
|
|
|
case InternalError::Type::SYNTAX:
|
|
|
|
return "syntaxError";
|
|
|
|
case InternalError::Type::UNKNOWN_MACRO:
|
|
|
|
return "unknownMacro";
|
|
|
|
case InternalError::Type::INTERNAL:
|
|
|
|
return "internalError";
|
|
|
|
case InternalError::Type::LIMIT:
|
|
|
|
return "cppcheckLimit";
|
|
|
|
case InternalError::Type::INSTANTIATION:
|
|
|
|
return "instantiationError";
|
2022-07-28 22:51:45 +02:00
|
|
|
}
|
2023-10-09 12:25:56 +02:00
|
|
|
cppcheck::unreachable();
|
2022-07-28 22:51:45 +02:00
|
|
|
}
|
|
|
|
|
2023-09-20 10:40:57 +02:00
|
|
|
InternalError::InternalError(const Token *tok, std::string errorMsg, Type type) :
|
|
|
|
InternalError(tok, std::move(errorMsg), "", type)
|
|
|
|
{}
|
|
|
|
|
|
|
|
InternalError::InternalError(const Token *tok, std::string errorMsg, std::string details, Type type) :
|
|
|
|
token(tok), errorMessage(std::move(errorMsg)), details(std::move(details)), type(type), id(typeToString(type))
|
|
|
|
{}
|
|
|
|
|
2023-10-12 11:58:39 +02:00
|
|
|
std::string severityToString(Severity severity)
|
2020-05-23 07:16:49 +02:00
|
|
|
{
|
2020-05-23 07:30:22 +02:00
|
|
|
switch (severity) {
|
2023-10-12 11:58:39 +02:00
|
|
|
case Severity::none:
|
2020-05-23 07:30:22 +02:00
|
|
|
return "";
|
2023-10-12 11:58:39 +02:00
|
|
|
case Severity::error:
|
2020-05-23 07:30:22 +02:00
|
|
|
return "error";
|
2023-10-12 11:58:39 +02:00
|
|
|
case Severity::warning:
|
2020-05-23 07:30:22 +02:00
|
|
|
return "warning";
|
2023-10-12 11:58:39 +02:00
|
|
|
case Severity::style:
|
2020-05-23 07:30:22 +02:00
|
|
|
return "style";
|
2023-10-12 11:58:39 +02:00
|
|
|
case Severity::performance:
|
2020-05-23 07:30:22 +02:00
|
|
|
return "performance";
|
2023-10-12 11:58:39 +02:00
|
|
|
case Severity::portability:
|
2020-05-23 07:30:22 +02:00
|
|
|
return "portability";
|
2023-10-12 11:58:39 +02:00
|
|
|
case Severity::information:
|
2020-05-23 07:30:22 +02:00
|
|
|
return "information";
|
2023-10-12 11:58:39 +02:00
|
|
|
case Severity::debug:
|
2020-05-23 07:30:22 +02:00
|
|
|
return "debug";
|
2023-12-18 18:26:23 +01:00
|
|
|
case Severity::internal:
|
|
|
|
return "internal";
|
2020-05-23 07:30:22 +02:00
|
|
|
}
|
|
|
|
throw InternalError(nullptr, "Unknown severity");
|
2020-05-23 07:16:49 +02:00
|
|
|
}
|
2023-10-12 11:58:39 +02:00
|
|
|
|
|
|
|
Severity severityFromString(const std::string& severity)
|
2020-05-23 07:16:49 +02:00
|
|
|
{
|
2020-05-23 07:30:22 +02:00
|
|
|
if (severity.empty())
|
2023-10-12 11:58:39 +02:00
|
|
|
return Severity::none;
|
2020-05-23 07:30:22 +02:00
|
|
|
if (severity == "none")
|
2023-10-12 11:58:39 +02:00
|
|
|
return Severity::none;
|
2020-05-23 07:30:22 +02:00
|
|
|
if (severity == "error")
|
2023-10-12 11:58:39 +02:00
|
|
|
return Severity::error;
|
2020-05-23 07:30:22 +02:00
|
|
|
if (severity == "warning")
|
2023-10-12 11:58:39 +02:00
|
|
|
return Severity::warning;
|
2020-05-23 07:30:22 +02:00
|
|
|
if (severity == "style")
|
2023-10-12 11:58:39 +02:00
|
|
|
return Severity::style;
|
2020-05-23 07:30:22 +02:00
|
|
|
if (severity == "performance")
|
2023-10-12 11:58:39 +02:00
|
|
|
return Severity::performance;
|
2020-05-23 07:30:22 +02:00
|
|
|
if (severity == "portability")
|
2023-10-12 11:58:39 +02:00
|
|
|
return Severity::portability;
|
2020-05-23 07:30:22 +02:00
|
|
|
if (severity == "information")
|
2023-10-12 11:58:39 +02:00
|
|
|
return Severity::information;
|
2020-05-23 07:30:22 +02:00
|
|
|
if (severity == "debug")
|
2023-10-12 11:58:39 +02:00
|
|
|
return Severity::debug;
|
2023-12-18 18:26:23 +01:00
|
|
|
if (severity == "internal")
|
|
|
|
return Severity::internal;
|
2023-10-12 11:58:39 +02:00
|
|
|
return Severity::none;
|
2021-10-24 11:06:48 +02:00
|
|
|
}
|