|
Packit |
2035a7 |
/*
|
|
Packit |
2035a7 |
* Cppcheck - A tool for static C/C++ code analysis
|
|
Packit |
2035a7 |
* Copyright (C) 2007-2017 Cppcheck team.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* This program is free software: you can redistribute it and/or modify
|
|
Packit |
2035a7 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
2035a7 |
* the Free Software Foundation, either version 3 of the License, or
|
|
Packit |
2035a7 |
* (at your option) any later version.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
2035a7 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
2035a7 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
2035a7 |
* GNU General Public License for more details.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
2035a7 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
2035a7 |
*/
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
#include "erroritem.h"
|
|
Packit |
2035a7 |
#include "common.h"
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
QErrorPathItem::QErrorPathItem(const ErrorLogger::ErrorMessage::FileLocation &loc)
|
|
Packit |
2035a7 |
: file(QString::fromStdString(loc.getfile(false)))
|
|
Packit |
2035a7 |
, line(loc.line)
|
|
Packit |
2035a7 |
, col(loc.col)
|
|
Packit |
2035a7 |
, info(QString::fromStdString(loc.getinfo()))
|
|
Packit |
2035a7 |
{
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
bool operator==(const QErrorPathItem &i1, const QErrorPathItem &i2)
|
|
Packit |
2035a7 |
{
|
|
Packit |
2035a7 |
return i1.file == i2.file && i1.col == i2.col && i1.line == i2.line && i1.info == i2.info;
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
ErrorItem::ErrorItem()
|
|
Packit |
2035a7 |
: severity(Severity::none)
|
|
Packit |
2035a7 |
, inconclusive(false)
|
|
Packit |
2035a7 |
, cwe(-1)
|
|
Packit |
2035a7 |
{
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
ErrorItem::ErrorItem(const ErrorLogger::ErrorMessage &errmsg)
|
|
Packit |
2035a7 |
: errorId(QString::fromStdString(errmsg._id))
|
|
Packit |
2035a7 |
, severity(errmsg._severity)
|
|
Packit |
2035a7 |
, inconclusive(errmsg._inconclusive)
|
|
Packit |
2035a7 |
, summary(QString::fromStdString(errmsg.shortMessage()))
|
|
Packit |
2035a7 |
, message(QString::fromStdString(errmsg.verboseMessage()))
|
|
Packit |
2035a7 |
, cwe(errmsg._cwe.id)
|
|
Packit |
2035a7 |
{
|
|
Packit |
2035a7 |
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = errmsg._callStack.begin();
|
|
Packit |
2035a7 |
loc != errmsg._callStack.end();
|
|
Packit |
2035a7 |
++loc) {
|
|
Packit |
2035a7 |
errorPath << QErrorPathItem(*loc);
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
QString ErrorItem::tool() const
|
|
Packit |
2035a7 |
{
|
|
Packit |
2035a7 |
if (errorId == CLANG_ANALYZER)
|
|
Packit |
2035a7 |
return CLANG_ANALYZER;
|
|
Packit |
2035a7 |
if (errorId.startsWith(CLANG_TIDY))
|
|
Packit |
2035a7 |
return CLANG_TIDY;
|
|
Packit |
2035a7 |
if (errorId.startsWith("clang-"))
|
|
Packit |
2035a7 |
return "clang";
|
|
Packit |
2035a7 |
return "cppcheck";
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
QString ErrorItem::ToString() const
|
|
Packit |
2035a7 |
{
|
|
Packit |
2035a7 |
QString str = errorPath.back().file + " - " + errorId + " - ";
|
|
Packit |
2035a7 |
if (inconclusive)
|
|
Packit |
2035a7 |
str += "inconclusive ";
|
|
Packit |
2035a7 |
str += GuiSeverity::toString(severity) +"\n";
|
|
Packit |
2035a7 |
str += summary + "\n";
|
|
Packit |
2035a7 |
str += message + "\n";
|
|
Packit |
2035a7 |
for (int i = 0; i < errorPath.size(); i++) {
|
|
Packit |
2035a7 |
str += " " + errorPath[i].file + ": " + QString::number(errorPath[i].line) + "\n";
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
return str;
|
|
Packit |
2035a7 |
}
|