Refactoring: Rename variables. Do not use leading _. Renamed 'col' to 'column'

This commit is contained in:
Daniel Marjamäki 2019-08-18 12:19:05 +02:00
parent 5f2379f3d1
commit 2d9a131817
22 changed files with 187 additions and 187 deletions

View File

@ -34,7 +34,7 @@ class Directive:
str = None str = None
file = None file = None
linenr = None linenr = None
col = 0 column = 0
def __init__(self, element): def __init__(self, element):
self.str = element.get('str') self.str = element.get('str')
@ -131,7 +131,7 @@ class Token:
astOperand2 ast operand2 astOperand2 ast operand2
file file name file file name
linenr line number linenr line number
col column column column
To iterate through all tokens use such code: To iterate through all tokens use such code:
@code @code
@ -188,7 +188,7 @@ class Token:
file = None file = None
linenr = None linenr = None
col = None column = None
def __init__(self, element): def __init__(self, element):
self.Id = element.get('id') self.Id = element.get('id')
@ -251,7 +251,7 @@ class Token:
self.astOperand2 = None self.astOperand2 = None
self.file = element.get('file') self.file = element.get('file')
self.linenr = int(element.get('linenr')) self.linenr = int(element.get('linenr'))
self.col = int(element.get('col')) self.column = int(element.get('column'))
def setId(self, IdMap): def setId(self, IdMap):
self.scope = IdMap[self.scopeId] self.scope = IdMap[self.scopeId]
@ -868,7 +868,7 @@ def reportError(location, severity, message, addon, errorId, extra=''):
if '--cli' in sys.argv: if '--cli' in sys.argv:
msg = { 'file': location.file, msg = { 'file': location.file,
'linenr': location.linenr, 'linenr': location.linenr,
'col': location.col, 'column': location.column,
'severity': severity, 'severity': severity,
'message': message, 'message': message,
'addon': addon, 'addon': addon,

View File

@ -746,7 +746,7 @@ class MisraChecker:
tokens = long_vars[name_prefix] tokens = long_vars[name_prefix]
if len(tokens) < 2: if len(tokens) < 2:
continue continue
for tok in sorted(tokens, key=lambda t: (t.linenr, t.col))[1:]: for tok in sorted(tokens, key=lambda t: (t.linenr, t.column))[1:]:
self.reportError(tok, 5, 1) self.reportError(tok, 5, 1)
def misra_5_2(self, data): def misra_5_2(self, data):
@ -1479,7 +1479,7 @@ class MisraChecker:
continue continue
if not simpleMatch(scope.bodyStart, '{ if ('): if not simpleMatch(scope.bodyStart, '{ if ('):
continue continue
if scope.bodyStart.col > 0: if scope.bodyStart.column > 0:
continue continue
tok = scope.bodyStart.next.next.link tok = scope.bodyStart.next.next.link
if not simpleMatch(tok, ') {'): if not simpleMatch(tok, ') {'):

View File

@ -294,7 +294,7 @@ unsigned int ThreadExecutor::check()
oss << "Internal error: Child process crashed with signal " << WTERMSIG(stat); oss << "Internal error: Child process crashed with signal " << WTERMSIG(stat);
std::list<ErrorLogger::ErrorMessage::FileLocation> locations; std::list<ErrorLogger::ErrorMessage::FileLocation> locations;
locations.emplace_back(childname, 0); locations.emplace_back(childname, 0, 0);
const ErrorLogger::ErrorMessage errmsg(locations, const ErrorLogger::ErrorMessage errmsg(locations,
emptyString, emptyString,
Severity::error, Severity::error,

View File

@ -347,7 +347,7 @@ void CheckThread::parseAddonErrors(QString err, const QString &tool)
/* /*
msg = { 'file': location.file, msg = { 'file': location.file,
'linenr': location.linenr, 'linenr': location.linenr,
'col': location.col, 'column': location.column,
'severity': severity, 'severity': severity,
'message': message, 'message': message,
'addon': addon, 'addon': addon,
@ -357,14 +357,13 @@ void CheckThread::parseAddonErrors(QString err, const QString &tool)
const std::string &filename = obj["file"].toString().toStdString(); const std::string &filename = obj["file"].toString().toStdString();
const int lineNumber = obj["linenr"].toInt(); const int lineNumber = obj["linenr"].toInt();
const int column = obj["col"].toInt(); const int column = obj["column"].toInt();
const std::string severity = obj["severity"].toString().toStdString(); const std::string severity = obj["severity"].toString().toStdString();
const std::string message = obj["message"].toString().toStdString(); const std::string message = obj["message"].toString().toStdString();
const std::string id = (obj["addon"].toString() + "-" + obj["errorId"].toString()).toStdString(); const std::string id = (obj["addon"].toString() + "-" + obj["errorId"].toString()).toStdString();
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack; std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(filename, lineNumber)); callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(filename, lineNumber, column));
callstack.back().col = column;
ErrorLogger::ErrorMessage errmsg(callstack, filename, Severity::fromString(severity), message, id, false); ErrorLogger::ErrorMessage errmsg(callstack, filename, Severity::fromString(severity), message, id, false);
if (isSuppressed(errmsg.toSuppressionsErrorMessage())) if (isSuppressed(errmsg.toSuppressionsErrorMessage()))
@ -387,9 +386,9 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
if (line.startsWith("Assertion failed:")) { if (line.startsWith("Assertion failed:")) {
ErrorItem e; ErrorItem e;
e.errorPath.append(QErrorPathItem()); e.errorPath.append(QErrorPathItem());
e.errorPath.last().file = file0; e.errorPath.last().file = file0;
e.errorPath.last().line = 1; e.errorPath.last().line = 1;
e.errorPath.last().col = 1; e.errorPath.last().column = 1;
e.errorId = tool + "-internal-error"; e.errorId = tool + "-internal-error";
e.file0 = file0; e.file0 = file0;
e.message = line; e.message = line;
@ -409,7 +408,7 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
errorItem.errorPath.append(QErrorPathItem()); errorItem.errorPath.append(QErrorPathItem());
errorItem.errorPath.last().file = r1.cap(1); errorItem.errorPath.last().file = r1.cap(1);
errorItem.errorPath.last().line = r1.cap(2).toInt(); errorItem.errorPath.last().line = r1.cap(2).toInt();
errorItem.errorPath.last().col = r1.cap(3).toInt(); errorItem.errorPath.last().column = r1.cap(3).toInt();
if (r1.cap(4) == "warning") if (r1.cap(4) == "warning")
errorItem.severity = Severity::SeverityType::warning; errorItem.severity = Severity::SeverityType::warning;
else if (r1.cap(4) == "error" || r1.cap(4) == "fatal error") else if (r1.cap(4) == "error" || r1.cap(4) == "fatal error")
@ -461,7 +460,7 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack; std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
foreach (const QErrorPathItem &path, e.errorPath) { foreach (const QErrorPathItem &path, e.errorPath) {
callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(path.file.toStdString(), path.info.toStdString(), path.line)); callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(path.file.toStdString(), path.info.toStdString(), path.line, path.column));
} }
const std::string f0 = file0.toStdString(); const std::string f0 = file0.toStdString();
const std::string msg = e.message.toStdString(); const std::string msg = e.message.toStdString();

View File

@ -22,14 +22,14 @@
QErrorPathItem::QErrorPathItem(const ErrorLogger::ErrorMessage::FileLocation &loc) QErrorPathItem::QErrorPathItem(const ErrorLogger::ErrorMessage::FileLocation &loc)
: file(QString::fromStdString(loc.getfile(false))) : file(QString::fromStdString(loc.getfile(false)))
, line(loc.line) , line(loc.line)
, col(loc.col) , column(loc.column)
, info(QString::fromStdString(loc.getinfo())) , info(QString::fromStdString(loc.getinfo()))
{ {
} }
bool operator==(const QErrorPathItem &i1, const QErrorPathItem &i2) bool operator==(const QErrorPathItem &i1, const QErrorPathItem &i2)
{ {
return i1.file == i2.file && i1.col == i2.col && i1.line == i2.line && i1.info == i2.info; return i1.file == i2.file && i1.column == i2.column && i1.line == i2.line && i1.info == i2.info;
} }
ErrorItem::ErrorItem() ErrorItem::ErrorItem()
@ -40,16 +40,16 @@ ErrorItem::ErrorItem()
} }
ErrorItem::ErrorItem(const ErrorLogger::ErrorMessage &errmsg) ErrorItem::ErrorItem(const ErrorLogger::ErrorMessage &errmsg)
: errorId(QString::fromStdString(errmsg._id)) : errorId(QString::fromStdString(errmsg.id))
, severity(errmsg._severity) , severity(errmsg.severity)
, inconclusive(errmsg._inconclusive) , inconclusive(errmsg.inconclusive)
, summary(QString::fromStdString(errmsg.shortMessage())) , summary(QString::fromStdString(errmsg.shortMessage()))
, message(QString::fromStdString(errmsg.verboseMessage())) , message(QString::fromStdString(errmsg.verboseMessage()))
, cwe(errmsg._cwe.id) , cwe(errmsg.cwe.id)
, symbolNames(QString::fromStdString(errmsg.symbolNames())) , symbolNames(QString::fromStdString(errmsg.symbolNames()))
{ {
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = errmsg._callStack.begin(); for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = errmsg.callStack.begin();
loc != errmsg._callStack.end(); loc != errmsg.callStack.end();
++loc) { ++loc) {
errorPath << QErrorPathItem(*loc); errorPath << QErrorPathItem(*loc);
} }

View File

@ -51,11 +51,11 @@ public:
*/ */
class QErrorPathItem { class QErrorPathItem {
public: public:
QErrorPathItem() : line(0), col(-1) {} QErrorPathItem() : line(0), column(-1) {}
explicit QErrorPathItem(const ErrorLogger::ErrorMessage::FileLocation &loc); explicit QErrorPathItem(const ErrorLogger::ErrorMessage::FileLocation &loc);
QString file; QString file;
unsigned int line; int line;
int col; int column;
QString info; QString info;
}; };

View File

@ -14,7 +14,7 @@ NewSuppressionDialog::NewSuppressionDialog(QWidget *parent) :
public: public:
virtual void reportOut(const std::string &/*outmsg*/) {} virtual void reportOut(const std::string &/*outmsg*/) {}
virtual void reportErr(const ErrorLogger::ErrorMessage &msg) { virtual void reportErr(const ErrorLogger::ErrorMessage &msg) {
errorIds << QString::fromStdString(msg._id); errorIds << QString::fromStdString(msg.id);
} }
QStringList errorIds; QStringList errorIds;
}; };

View File

@ -187,7 +187,7 @@ bool ResultsTree::addErrorItem(const ErrorItem &item)
data["message"] = item.message; data["message"] = item.message;
data["file"] = loc.file; data["file"] = loc.file;
data["line"] = loc.line; data["line"] = loc.line;
data["col"] = loc.col; data["column"] = loc.column;
data["id"] = item.errorId; data["id"] = item.errorId;
data["inconclusive"] = item.inconclusive; data["inconclusive"] = item.inconclusive;
data["file0"] = stripPath(item.file0, true); data["file0"] = stripPath(item.file0, true);
@ -219,7 +219,7 @@ bool ResultsTree::addErrorItem(const ErrorItem &item)
child_data["message"] = line.message; child_data["message"] = line.message;
child_data["file"] = e.file; child_data["file"] = e.file;
child_data["line"] = e.line; child_data["line"] = e.line;
child_data["col"] = e.col; child_data["column"] = e.column;
child_data["id"] = line.errorId; child_data["id"] = line.errorId;
child_data["inconclusive"] = line.inconclusive; child_data["inconclusive"] = line.inconclusive;
child_item->setData(QVariant(child_data)); child_item->setData(QVariant(child_data));

View File

@ -61,7 +61,7 @@ void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
{ {
QMutexLocker locker(&mutex); QMutexLocker locker(&mutex);
const ErrorItem item(msg); const ErrorItem item(msg);
if (msg._severity != Severity::debug) if (msg.severity != Severity::debug)
emit error(item); emit error(item);
else else
emit debugError(item); emit debugError(item);

View File

@ -33,7 +33,6 @@ static const QString CppcheckElementName = "cppcheck";
static const QString ErrorElementName = "error"; static const QString ErrorElementName = "error";
static const QString ErrorsElementName = "errors"; static const QString ErrorsElementName = "errors";
static const QString LocationElementName = "location"; static const QString LocationElementName = "location";
static const QString ColAttribute = "col";
static const QString CWEAttribute = "cwe"; static const QString CWEAttribute = "cwe";
static const QString SinceDateAttribute = "sinceDate"; static const QString SinceDateAttribute = "sinceDate";
static const QString TagsAttribute = "tag"; static const QString TagsAttribute = "tag";
@ -42,6 +41,7 @@ static const QString IncludedFromFilenameAttribute = "file0";
static const QString InconclusiveAttribute = "inconclusive"; static const QString InconclusiveAttribute = "inconclusive";
static const QString InfoAttribute = "info"; static const QString InfoAttribute = "info";
static const QString LineAttribute = "line"; static const QString LineAttribute = "line";
static const QString ColumnAttribute = "column";
static const QString IdAttribute = "id"; static const QString IdAttribute = "id";
static const QString SeverityAttribute = "severity"; static const QString SeverityAttribute = "severity";
static const QString MsgAttribute = "msg"; static const QString MsgAttribute = "msg";
@ -136,8 +136,8 @@ void XmlReportV2::writeError(const ErrorItem &error)
} }
mXmlWriter->writeAttribute(FilenameAttribute, XmlReport::quoteMessage(file)); mXmlWriter->writeAttribute(FilenameAttribute, XmlReport::quoteMessage(file));
mXmlWriter->writeAttribute(LineAttribute, QString::number(error.errorPath[i].line)); mXmlWriter->writeAttribute(LineAttribute, QString::number(error.errorPath[i].line));
if (error.errorPath[i].col > 0) if (error.errorPath[i].column > 0)
mXmlWriter->writeAttribute(ColAttribute, QString::number(error.errorPath[i].col)); mXmlWriter->writeAttribute(ColumnAttribute, QString::number(error.errorPath[i].column));
if (error.errorPath.count() > 1) if (error.errorPath.count() > 1)
mXmlWriter->writeAttribute(InfoAttribute, XmlReport::quoteMessage(error.errorPath[i].info)); mXmlWriter->writeAttribute(InfoAttribute, XmlReport::quoteMessage(error.errorPath[i].info));
@ -235,8 +235,8 @@ ErrorItem XmlReportV2::readError(QXmlStreamReader *reader)
QErrorPathItem loc; QErrorPathItem loc;
loc.file = XmlReport::unquoteMessage(attribs.value(QString(), FilenameAttribute).toString()); loc.file = XmlReport::unquoteMessage(attribs.value(QString(), FilenameAttribute).toString());
loc.line = attribs.value(QString(), LineAttribute).toString().toUInt(); loc.line = attribs.value(QString(), LineAttribute).toString().toUInt();
if (attribs.hasAttribute(QString(), ColAttribute)) if (attribs.hasAttribute(QString(), ColumnAttribute))
loc.col = attribs.value(QString(), ColAttribute).toString().toInt(); loc.column = attribs.value(QString(), ColumnAttribute).toString().toInt();
if (attribs.hasAttribute(QString(), InfoAttribute)) if (attribs.hasAttribute(QString(), InfoAttribute))
loc.info = XmlReport::unquoteMessage(attribs.value(QString(), InfoAttribute).toString()); loc.info = XmlReport::unquoteMessage(attribs.value(QString(), InfoAttribute).toString());
item.errorPath.push_front(loc); item.errorPath.push_front(loc);

View File

@ -279,7 +279,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
}; };
if (err) { if (err) {
const ErrorLogger::ErrorMessage::FileLocation loc1(output.location.file(), output.location.line); const ErrorLogger::ErrorMessage::FileLocation loc1(output.location.file(), output.location.line, output.location.col);
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack(1, loc1); std::list<ErrorLogger::ErrorMessage::FileLocation> callstack(1, loc1);
ErrorLogger::ErrorMessage errmsg(callstack, ErrorLogger::ErrorMessage errmsg(callstack,
@ -562,7 +562,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
ErrorLogger::ErrorMessage::FileLocation loc; ErrorLogger::ErrorMessage::FileLocation loc;
if (e.token) { if (e.token) {
loc.line = e.token->linenr(); loc.line = e.token->linenr();
loc.col = e.token->col(); loc.column = e.token->column();
const std::string fixedpath = Path::toNativeSeparators(mTokenizer.list.file(e.token)); const std::string fixedpath = Path::toNativeSeparators(mTokenizer.list.file(e.token));
loc.setfile(fixedpath); loc.setfile(fixedpath);
} else { } else {
@ -579,7 +579,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
e.id, e.id,
false); false);
if (errmsg._severity == Severity::error || mSettings.isEnabled(errmsg._severity)) if (errmsg.severity == Severity::error || mSettings.isEnabled(errmsg.severity))
reportErr(errmsg); reportErr(errmsg);
} }
} }
@ -636,19 +636,18 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
const std::string fileName = obj["file"].get<std::string>(); const std::string fileName = obj["file"].get<std::string>();
const int64_t lineNumber = obj["linenr"].get<int64_t>(); const int64_t lineNumber = obj["linenr"].get<int64_t>();
const int64_t column = obj["col"].get<int64_t>(); const int64_t column = obj["column"].get<int64_t>();
ErrorLogger::ErrorMessage errmsg; ErrorLogger::ErrorMessage errmsg;
errmsg._callStack.emplace_back(ErrorLogger::ErrorMessage::FileLocation(fileName, lineNumber)); errmsg.callStack.emplace_back(ErrorLogger::ErrorMessage::FileLocation(fileName, lineNumber, column));
errmsg._callStack.back().col = column;
errmsg._id = obj["addon"].get<std::string>() + "-" + obj["errorId"].get<std::string>(); errmsg.id = obj["addon"].get<std::string>() + "-" + obj["errorId"].get<std::string>();
const std::string text = obj["message"].get<std::string>(); const std::string text = obj["message"].get<std::string>();
errmsg.setmsg(text); errmsg.setmsg(text);
const std::string severity = obj["severity"].get<std::string>(); const std::string severity = obj["severity"].get<std::string>();
errmsg._severity = Severity::fromString(severity); errmsg.severity = Severity::fromString(severity);
if (errmsg._severity == Severity::SeverityType::none) if (errmsg.severity == Severity::SeverityType::none)
continue; continue;
errmsg.file0 = fileName; errmsg.file0 = fileName;
@ -686,7 +685,7 @@ void CppCheck::internalError(const std::string &filename, const std::string &msg
const std::string fullmsg("Bailing out from checking " + fixedpath + " since there was an internal error: " + msg); const std::string fullmsg("Bailing out from checking " + fixedpath + " since there was an internal error: " + msg);
if (mSettings.isEnabled(Settings::INFORMATION)) { if (mSettings.isEnabled(Settings::INFORMATION)) {
const ErrorLogger::ErrorMessage::FileLocation loc1(filename, 0); const ErrorLogger::ErrorMessage::FileLocation loc1(filename, 0, 0);
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack(1, loc1); std::list<ErrorLogger::ErrorMessage::FileLocation> callstack(1, loc1);
ErrorLogger::ErrorMessage errmsg(callstack, ErrorLogger::ErrorMessage errmsg(callstack,

View File

@ -44,7 +44,7 @@ int CTU::maxCtuDepth = 2;
std::string CTU::getFunctionId(const Tokenizer *tokenizer, const Function *function) std::string CTU::getFunctionId(const Tokenizer *tokenizer, const Function *function)
{ {
return tokenizer->list.file(function->tokenDef) + ':' + MathLib::toString(function->tokenDef->linenr()) + ':' + MathLib::toString(function->tokenDef->col()); return tokenizer->list.file(function->tokenDef) + ':' + MathLib::toString(function->tokenDef->linenr()) + ':' + MathLib::toString(function->tokenDef->column());
} }
CTU::FileInfo::Location::Location(const Tokenizer *tokenizer, const Token *tok) CTU::FileInfo::Location::Location(const Tokenizer *tokenizer, const Token *tok)

View File

@ -59,17 +59,17 @@ InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type
} }
ErrorLogger::ErrorMessage::ErrorMessage() ErrorLogger::ErrorMessage::ErrorMessage()
: _severity(Severity::none), _cwe(0U), _inconclusive(false) : severity(Severity::none), cwe(0U), inconclusive(false)
{ {
} }
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, const std::string& file1, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive) : ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, const std::string& file1, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive) :
_callStack(callStack), // locations for this error message callStack(callStack), // locations for this error message
_id(id), // set the message id id(id), // set the message id
file0(file1), file0(file1),
_severity(severity), // severity for this error message severity(severity), // severity for this error message
_cwe(0U), cwe(0U),
_inconclusive(inconclusive) inconclusive(inconclusive)
{ {
// set the summary and verbose messages // set the summary and verbose messages
setmsg(msg); setmsg(msg);
@ -78,19 +78,19 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, const std::string& file1, Severity::SeverityType severity, const std::string &msg, const std::string &id, const CWE &cwe, bool inconclusive) : ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, const std::string& file1, Severity::SeverityType severity, const std::string &msg, const std::string &id, const CWE &cwe, bool inconclusive) :
_callStack(callStack), // locations for this error message callStack(callStack), // locations for this error message
_id(id), // set the message id id(id), // set the message id
file0(file1), file0(file1),
_severity(severity), // severity for this error message severity(severity), // severity for this error message
_cwe(cwe.id), cwe(cwe.id),
_inconclusive(inconclusive) inconclusive(inconclusive)
{ {
// set the summary and verbose messages // set the summary and verbose messages
setmsg(msg); setmsg(msg);
} }
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive) ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive)
: _id(id), _severity(severity), _cwe(0U), _inconclusive(inconclusive) : id(id), severity(severity), cwe(0U), inconclusive(inconclusive)
{ {
// Format callstack // Format callstack
for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it) { for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it) {
@ -98,7 +98,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack
if (!(*it)) if (!(*it))
continue; continue;
_callStack.emplace_back(*it, list); callStack.emplace_back(*it, list);
} }
if (list && !list->getFiles().empty()) if (list && !list->getFiles().empty())
@ -109,7 +109,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, const CWE &cwe, bool inconclusive) ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, const CWE &cwe, bool inconclusive)
: _id(id), _severity(severity), _cwe(cwe.id), _inconclusive(inconclusive) : id(id), severity(severity), cwe(cwe.id), inconclusive(inconclusive)
{ {
// Format callstack // Format callstack
for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it) { for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it) {
@ -117,7 +117,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack
if (!(*it)) if (!(*it))
continue; continue;
_callStack.emplace_back(*it, list); callStack.emplace_back(*it, list);
} }
if (list && !list->getFiles().empty()) if (list && !list->getFiles().empty())
@ -127,7 +127,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack
} }
ErrorLogger::ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, bool inconclusive) ErrorLogger::ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, bool inconclusive)
: _id(id), _severity(severity), _cwe(cwe.id), _inconclusive(inconclusive) : id(id), severity(severity), cwe(cwe.id), inconclusive(inconclusive)
{ {
// Format callstack // Format callstack
for (ErrorPath::const_iterator it = errorPath.begin(); it != errorPath.end(); ++it) { for (ErrorPath::const_iterator it = errorPath.begin(); it != errorPath.end(); ++it) {
@ -136,7 +136,7 @@ ErrorLogger::ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenL
// --errorlist can provide null values here // --errorlist can provide null values here
if (tok) if (tok)
_callStack.emplace_back(tok, info, tokenList); callStack.emplace_back(tok, info, tokenList);
} }
if (tokenList && !tokenList->getFiles().empty()) if (tokenList && !tokenList->getFiles().empty())
@ -146,23 +146,23 @@ ErrorLogger::ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenL
} }
ErrorLogger::ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg) ErrorLogger::ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
: _severity(Severity::none), : severity(Severity::none),
_cwe(0U), cwe(0U),
_inconclusive(false) inconclusive(false)
{ {
const char * const unknown = "<UNKNOWN>"; const char * const unknown = "<UNKNOWN>";
const char *attr = errmsg->Attribute("id"); const char *attr = errmsg->Attribute("id");
_id = attr ? attr : unknown; id = attr ? attr : unknown;
attr = errmsg->Attribute("severity"); attr = errmsg->Attribute("severity");
_severity = attr ? Severity::fromString(attr) : Severity::none; severity = attr ? Severity::fromString(attr) : Severity::none;
attr = errmsg->Attribute("cwe"); attr = errmsg->Attribute("cwe");
std::istringstream(attr ? attr : "0") >> _cwe.id; std::istringstream(attr ? attr : "0") >> cwe.id;
attr = errmsg->Attribute("inconclusive"); attr = errmsg->Attribute("inconclusive");
_inconclusive = attr && (std::strcmp(attr, "true") == 0); inconclusive = attr && (std::strcmp(attr, "true") == 0);
attr = errmsg->Attribute("msg"); attr = errmsg->Attribute("msg");
mShortMessage = attr ? attr : ""; mShortMessage = attr ? attr : "";
@ -175,11 +175,13 @@ ErrorLogger::ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errms
const char *strfile = e->Attribute("file"); const char *strfile = e->Attribute("file");
const char *strinfo = e->Attribute("info"); const char *strinfo = e->Attribute("info");
const char *strline = e->Attribute("line"); const char *strline = e->Attribute("line");
const char *strcolumn = e->Attribute("column");
const char *file = strfile ? strfile : unknown; const char *file = strfile ? strfile : unknown;
const char *info = strinfo ? strinfo : ""; const char *info = strinfo ? strinfo : "";
const int line = strline ? std::atoi(strline) : 0; const int line = strline ? std::atoi(strline) : 0;
_callStack.emplace_back(file, info, line); const int column = strcolumn ? std::atoi(strcolumn) : 0;
callStack.emplace_back(file, info, line, column);
} }
} }
} }
@ -213,12 +215,12 @@ void ErrorLogger::ErrorMessage::setmsg(const std::string &msg)
Suppressions::ErrorMessage ErrorLogger::ErrorMessage::toSuppressionsErrorMessage() const Suppressions::ErrorMessage ErrorLogger::ErrorMessage::toSuppressionsErrorMessage() const
{ {
Suppressions::ErrorMessage ret; Suppressions::ErrorMessage ret;
ret.errorId = _id; ret.errorId = id;
if (!_callStack.empty()) { if (!callStack.empty()) {
ret.setFileName(_callStack.back().getfile(false)); ret.setFileName(callStack.back().getfile(false));
ret.lineNumber = _callStack.back().line; ret.lineNumber = callStack.back().line;
} }
ret.inconclusive = _inconclusive; ret.inconclusive = inconclusive;
ret.symbolNames = mSymbolNames; ret.symbolNames = mSymbolNames;
return ret; return ret;
} }
@ -228,10 +230,10 @@ std::string ErrorLogger::ErrorMessage::serialize() const
{ {
// Serialize this message into a simple string // Serialize this message into a simple string
std::ostringstream oss; std::ostringstream oss;
oss << _id.length() << " " << _id; oss << id.length() << " " << id;
oss << Severity::toString(_severity).length() << " " << Severity::toString(_severity); oss << Severity::toString(severity).length() << " " << Severity::toString(severity);
oss << MathLib::toString(_cwe.id).length() << " " << MathLib::toString(_cwe.id); oss << MathLib::toString(cwe.id).length() << " " << MathLib::toString(cwe.id);
if (_inconclusive) { if (inconclusive) {
const std::string inconclusive("inconclusive"); const std::string inconclusive("inconclusive");
oss << inconclusive.length() << " " << inconclusive; oss << inconclusive.length() << " " << inconclusive;
} }
@ -241,11 +243,11 @@ std::string ErrorLogger::ErrorMessage::serialize() const
oss << saneShortMessage.length() << " " << saneShortMessage; oss << saneShortMessage.length() << " " << saneShortMessage;
oss << saneVerboseMessage.length() << " " << saneVerboseMessage; oss << saneVerboseMessage.length() << " " << saneVerboseMessage;
oss << _callStack.size() << " "; oss << callStack.size() << " ";
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = _callStack.begin(); loc != _callStack.end(); ++loc) { for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = callStack.begin(); loc != callStack.end(); ++loc) {
std::ostringstream smallStream; std::ostringstream smallStream;
smallStream << (*loc).line << ':' << (*loc).col << ':' << (*loc).getfile() << '\t' << loc->getinfo(); smallStream << (*loc).line << ':' << (*loc).column << ':' << (*loc).getfile() << '\t' << loc->getinfo();
oss << smallStream.str().length() << " " << smallStream.str(); oss << smallStream.str().length() << " " << smallStream.str();
} }
@ -254,8 +256,8 @@ std::string ErrorLogger::ErrorMessage::serialize() const
bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
{ {
_inconclusive = false; inconclusive = false;
_callStack.clear(); callStack.clear();
std::istringstream iss(data); std::istringstream iss(data);
std::array<std::string, 5> results; std::array<std::string, 5> results;
std::size_t elem = 0; std::size_t elem = 0;
@ -272,7 +274,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
} }
if (temp == "inconclusive") { if (temp == "inconclusive") {
_inconclusive = true; inconclusive = true;
continue; continue;
} }
@ -284,10 +286,10 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
if (elem != 5) if (elem != 5)
throw InternalError(nullptr, "Internal Error: Deserialization of error message failed"); throw InternalError(nullptr, "Internal Error: Deserialization of error message failed");
_id = results[0]; id = results[0];
_severity = Severity::fromString(results[1]); severity = Severity::fromString(results[1]);
std::istringstream scwe(results[2]); std::istringstream scwe(results[2]);
scwe >> _cwe.id; scwe >> cwe.id;
mShortMessage = results[3]; mShortMessage = results[3];
mVerboseMessage = results[4]; mVerboseMessage = results[4];
@ -327,12 +329,12 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
ErrorLogger::ErrorMessage::FileLocation loc; ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile(tempfile); loc.setfile(tempfile);
loc.setinfo(tempinfo); loc.setinfo(tempinfo);
loc.col = MathLib::toLongNumber(tempcolumn); loc.column = MathLib::toLongNumber(tempcolumn);
loc.line = MathLib::toLongNumber(templine); loc.line = MathLib::toLongNumber(templine);
_callStack.push_back(loc); callStack.push_back(loc);
if (_callStack.size() >= stackSize) if (callStack.size() >= stackSize)
break; break;
} }
@ -391,22 +393,22 @@ std::string ErrorLogger::ErrorMessage::toXML() const
{ {
tinyxml2::XMLPrinter printer(nullptr, false, 2); tinyxml2::XMLPrinter printer(nullptr, false, 2);
printer.OpenElement("error", false); printer.OpenElement("error", false);
printer.PushAttribute("id", _id.c_str()); printer.PushAttribute("id", id.c_str());
printer.PushAttribute("severity", Severity::toString(_severity).c_str()); printer.PushAttribute("severity", Severity::toString(severity).c_str());
printer.PushAttribute("msg", fixInvalidChars(mShortMessage).c_str()); printer.PushAttribute("msg", fixInvalidChars(mShortMessage).c_str());
printer.PushAttribute("verbose", fixInvalidChars(mVerboseMessage).c_str()); printer.PushAttribute("verbose", fixInvalidChars(mVerboseMessage).c_str());
if (_cwe.id) if (cwe.id)
printer.PushAttribute("cwe", _cwe.id); printer.PushAttribute("cwe", cwe.id);
if (_inconclusive) if (inconclusive)
printer.PushAttribute("inconclusive", "true"); printer.PushAttribute("inconclusive", "true");
for (std::list<FileLocation>::const_reverse_iterator it = _callStack.rbegin(); it != _callStack.rend(); ++it) { for (std::list<FileLocation>::const_reverse_iterator it = callStack.rbegin(); it != callStack.rend(); ++it) {
printer.OpenElement("location", false); printer.OpenElement("location", false);
if (!file0.empty() && (*it).getfile() != file0) if (!file0.empty() && (*it).getfile() != file0)
printer.PushAttribute("file0", Path::toNativeSeparators(file0).c_str()); printer.PushAttribute("file0", Path::toNativeSeparators(file0).c_str());
printer.PushAttribute("file", (*it).getfile().c_str()); printer.PushAttribute("file", (*it).getfile().c_str());
printer.PushAttribute("line", std::max((*it).line,0)); printer.PushAttribute("line", std::max((*it).line,0));
printer.PushAttribute("column", (*it).col); printer.PushAttribute("column", (*it).column);
if (!it->getinfo().empty()) if (!it->getinfo().empty())
printer.PushAttribute("info", fixInvalidChars(it->getinfo()).c_str()); printer.PushAttribute("info", fixInvalidChars(it->getinfo()).c_str());
printer.CloseElement(false); printer.CloseElement(false);
@ -462,11 +464,11 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
// No template is given // No template is given
if (templateFormat.empty()) { if (templateFormat.empty()) {
std::ostringstream text; std::ostringstream text;
if (!_callStack.empty()) if (!callStack.empty())
text << callStackToString(_callStack) << ": "; text << callStackToString(callStack) << ": ";
if (_severity != Severity::none) { if (severity != Severity::none) {
text << '(' << Severity::toString(_severity); text << '(' << Severity::toString(severity);
if (_inconclusive) if (inconclusive)
text << ", inconclusive"; text << ", inconclusive";
text << ") "; text << ") ";
} }
@ -483,22 +485,22 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
findAndReplace(result, "\\r", "\r"); findAndReplace(result, "\\r", "\r");
findAndReplace(result, "\\t", "\t"); findAndReplace(result, "\\t", "\t");
findAndReplace(result, "{id}", _id); findAndReplace(result, "{id}", id);
if (result.find("{inconclusive:") != std::string::npos) { if (result.find("{inconclusive:") != std::string::npos) {
const std::string::size_type pos1 = result.find("{inconclusive:"); const std::string::size_type pos1 = result.find("{inconclusive:");
const std::string::size_type pos2 = result.find('}', pos1+1); const std::string::size_type pos2 = result.find('}', pos1+1);
const std::string replaceFrom = result.substr(pos1,pos2-pos1+1); const std::string replaceFrom = result.substr(pos1,pos2-pos1+1);
const std::string replaceWith = _inconclusive ? result.substr(pos1+14, pos2-pos1-14) : std::string(); const std::string replaceWith = inconclusive ? result.substr(pos1+14, pos2-pos1-14) : std::string();
findAndReplace(result, replaceFrom, replaceWith); findAndReplace(result, replaceFrom, replaceWith);
} }
findAndReplace(result, "{severity}", Severity::toString(_severity)); findAndReplace(result, "{severity}", Severity::toString(severity));
findAndReplace(result, "{cwe}", MathLib::toString(_cwe.id)); findAndReplace(result, "{cwe}", MathLib::toString(cwe.id));
findAndReplace(result, "{message}", verbose ? mVerboseMessage : mShortMessage); findAndReplace(result, "{message}", verbose ? mVerboseMessage : mShortMessage);
findAndReplace(result, "{callstack}", _callStack.empty() ? emptyString : callStackToString(_callStack)); findAndReplace(result, "{callstack}", callStack.empty() ? emptyString : callStackToString(callStack));
if (!_callStack.empty()) { if (!callStack.empty()) {
findAndReplace(result, "{file}", _callStack.back().getfile()); findAndReplace(result, "{file}", callStack.back().getfile());
findAndReplace(result, "{line}", MathLib::toString(_callStack.back().line)); findAndReplace(result, "{line}", MathLib::toString(callStack.back().line));
findAndReplace(result, "{column}", MathLib::toString(_callStack.back().col)); findAndReplace(result, "{column}", MathLib::toString(callStack.back().column));
if (result.find("{code}") != std::string::npos) { if (result.find("{code}") != std::string::npos) {
const std::string::size_type pos = result.find('\r'); const std::string::size_type pos = result.find('\r');
const char *endl; const char *endl;
@ -508,7 +510,7 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
endl = "\r\n"; endl = "\r\n";
else else
endl = "\r"; endl = "\r";
findAndReplace(result, "{code}", readCode(_callStack.back().getOrigFile(), _callStack.back().line, _callStack.back().col, endl)); findAndReplace(result, "{code}", readCode(callStack.back().getOrigFile(), callStack.back().line, callStack.back().column, endl));
} }
} else { } else {
findAndReplace(result, "{file}", "nofile"); findAndReplace(result, "{file}", "nofile");
@ -517,8 +519,8 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
findAndReplace(result, "{code}", emptyString); findAndReplace(result, "{code}", emptyString);
} }
if (!templateLocation.empty() && _callStack.size() >= 2U) { if (!templateLocation.empty() && callStack.size() >= 2U) {
for (const FileLocation &fileLocation : _callStack) { for (const FileLocation &fileLocation : callStack) {
std::string text = templateLocation; std::string text = templateLocation;
findAndReplace(text, "\\b", "\b"); findAndReplace(text, "\\b", "\b");
@ -528,7 +530,7 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
findAndReplace(text, "{file}", fileLocation.getfile()); findAndReplace(text, "{file}", fileLocation.getfile());
findAndReplace(text, "{line}", MathLib::toString(fileLocation.line)); findAndReplace(text, "{line}", MathLib::toString(fileLocation.line));
findAndReplace(text, "{column}", MathLib::toString(fileLocation.col)); findAndReplace(text, "{column}", MathLib::toString(fileLocation.column));
findAndReplace(text, "{info}", fileLocation.getinfo().empty() ? mShortMessage : fileLocation.getinfo()); findAndReplace(text, "{info}", fileLocation.getinfo().empty() ? mShortMessage : fileLocation.getinfo());
if (text.find("{code}") != std::string::npos) { if (text.find("{code}") != std::string::npos) {
const std::string::size_type pos = text.find('\r'); const std::string::size_type pos = text.find('\r');
@ -539,7 +541,7 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
endl = "\r\n"; endl = "\r\n";
else else
endl = "\r"; endl = "\r";
findAndReplace(text, "{code}", readCode(fileLocation.getOrigFile(), fileLocation.line, fileLocation.col, endl)); findAndReplace(text, "{code}", readCode(fileLocation.getOrigFile(), fileLocation.line, fileLocation.column, endl));
} }
result += '\n' + text; result += '\n' + text;
} }
@ -574,7 +576,7 @@ bool ErrorLogger::reportUnmatchedSuppressions(const std::list<Suppressions::Supp
std::list<ErrorLogger::ErrorMessage::FileLocation> callStack; std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
if (!s.fileName.empty()) if (!s.fileName.empty())
callStack.emplace_back(s.fileName, s.lineNumber); callStack.emplace_back(s.fileName, s.lineNumber, 0);
reportErr(ErrorLogger::ErrorMessage(callStack, emptyString, Severity::information, "Unmatched suppression: " + s.errorId, "unmatchedSuppression", false)); reportErr(ErrorLogger::ErrorMessage(callStack, emptyString, Severity::information, "Unmatched suppression: " + s.errorId, "unmatchedSuppression", false));
err = true; err = true;
} }
@ -592,12 +594,12 @@ std::string ErrorLogger::callStackToString(const std::list<ErrorLogger::ErrorMes
ErrorLogger::ErrorMessage::FileLocation::FileLocation(const Token* tok, const TokenList* tokenList) ErrorLogger::ErrorMessage::FileLocation::FileLocation(const Token* tok, const TokenList* tokenList)
: fileIndex(tok->fileIndex()), line(tok->linenr()), col(tok->col()), mOrigFileName(tokenList->getOrigFile(tok)), mFileName(tokenList->file(tok)) : fileIndex(tok->fileIndex()), line(tok->linenr()), column(tok->column()), mOrigFileName(tokenList->getOrigFile(tok)), mFileName(tokenList->file(tok))
{ {
} }
ErrorLogger::ErrorMessage::FileLocation::FileLocation(const Token* tok, const std::string &info, const TokenList* tokenList) ErrorLogger::ErrorMessage::FileLocation::FileLocation(const Token* tok, const std::string &info, const TokenList* tokenList)
: fileIndex(tok->fileIndex()), line(tok->linenr()), col(tok->col()), mOrigFileName(tokenList->getOrigFile(tok)), mFileName(tokenList->file(tok)), mInfo(info) : fileIndex(tok->fileIndex()), line(tok->linenr()), column(tok->column()), mOrigFileName(tokenList->getOrigFile(tok)), mFileName(tokenList->file(tok)), mInfo(info)
{ {
} }
@ -688,7 +690,7 @@ static std::string plistLoc(const char indent[], const ErrorLogger::ErrorMessage
std::ostringstream ostr; std::ostringstream ostr;
ostr << indent << "<dict>\r\n" ostr << indent << "<dict>\r\n"
<< indent << ' ' << "<key>line</key><integer>" << loc.line << "</integer>\r\n" << indent << ' ' << "<key>line</key><integer>" << loc.line << "</integer>\r\n"
<< indent << ' ' << "<key>col</key><integer>" << loc.col << "</integer>\r\n" << indent << ' ' << "<key>col</key><integer>" << loc.column << "</integer>\r\n"
<< indent << ' ' << "<key>file</key><integer>" << loc.fileIndex << "</integer>\r\n" << indent << ' ' << "<key>file</key><integer>" << loc.fileIndex << "</integer>\r\n"
<< indent << "</dict>\r\n"; << indent << "</dict>\r\n";
return ostr.str(); return ostr.str();
@ -701,9 +703,9 @@ std::string ErrorLogger::plistData(const ErrorLogger::ErrorMessage &msg)
<< " <key>path</key>\r\n" << " <key>path</key>\r\n"
<< " <array>\r\n"; << " <array>\r\n";
std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator prev = msg._callStack.begin(); std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator prev = msg.callStack.begin();
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator it = msg._callStack.begin(); it != msg._callStack.end(); ++it) { for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator it = msg.callStack.begin(); it != msg.callStack.end(); ++it) {
if (prev != it) { if (prev != it) {
plist << " <dict>\r\n" plist << " <dict>\r\n"
<< " <key>kind</key><string>control</string>\r\n" << " <key>kind</key><string>control</string>\r\n"
@ -728,7 +730,7 @@ std::string ErrorLogger::plistData(const ErrorLogger::ErrorMessage &msg)
std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator next = it; std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator next = it;
++next; ++next;
const std::string message = (it->getinfo().empty() && next == msg._callStack.end() ? msg.shortMessage() : it->getinfo()); const std::string message = (it->getinfo().empty() && next == msg.callStack.end() ? msg.shortMessage() : it->getinfo());
plist << " <dict>\r\n" plist << " <dict>\r\n"
<< " <key>kind</key><string>event</string>\r\n" << " <key>kind</key><string>event</string>\r\n"
@ -751,16 +753,16 @@ std::string ErrorLogger::plistData(const ErrorLogger::ErrorMessage &msg)
plist << " </array>\r\n" plist << " </array>\r\n"
<< " <key>description</key><string>" << ErrorLogger::toxml(msg.shortMessage()) << "</string>\r\n" << " <key>description</key><string>" << ErrorLogger::toxml(msg.shortMessage()) << "</string>\r\n"
<< " <key>category</key><string>" << Severity::toString(msg._severity) << "</string>\r\n" << " <key>category</key><string>" << Severity::toString(msg.severity) << "</string>\r\n"
<< " <key>type</key><string>" << ErrorLogger::toxml(msg.shortMessage()) << "</string>\r\n" << " <key>type</key><string>" << ErrorLogger::toxml(msg.shortMessage()) << "</string>\r\n"
<< " <key>check_name</key><string>" << msg._id << "</string>\r\n" << " <key>check_name</key><string>" << msg.id << "</string>\r\n"
<< " <!-- This hash is experimental and going to change! -->\r\n" << " <!-- This hash is experimental and going to change! -->\r\n"
<< " <key>issue_hash_content_of_line_in_context</key><string>" << 0 << "</string>\r\n" << " <key>issue_hash_content_of_line_in_context</key><string>" << 0 << "</string>\r\n"
<< " <key>issue_context_kind</key><string></string>\r\n" << " <key>issue_context_kind</key><string></string>\r\n"
<< " <key>issue_context</key><string></string>\r\n" << " <key>issue_context</key><string></string>\r\n"
<< " <key>issue_hash_function_offset</key><string></string>\r\n" << " <key>issue_hash_function_offset</key><string></string>\r\n"
<< " <key>location</key>\r\n" << " <key>location</key>\r\n"
<< plistLoc(" ", msg._callStack.back()) << plistLoc(" ", msg.callStack.back())
<< " </dict>\r\n"; << " </dict>\r\n";
return plist.str(); return plist.str();
} }

View File

@ -190,15 +190,15 @@ public:
class CPPCHECKLIB FileLocation { class CPPCHECKLIB FileLocation {
public: public:
FileLocation() FileLocation()
: fileIndex(0), line(0), col(0) { : fileIndex(0), line(0), column(0) {
} }
FileLocation(const std::string &file, int line) FileLocation(const std::string &file, int line, int column)
: fileIndex(0), line(line), col(0), mOrigFileName(file), mFileName(file) { : fileIndex(0), line(line), column(column), mOrigFileName(file), mFileName(file) {
} }
FileLocation(const std::string &file, const std::string &info, int line) FileLocation(const std::string &file, const std::string &info, int line, int column)
: fileIndex(0), line(line), col(0), mOrigFileName(file), mFileName(file), mInfo(info) { : fileIndex(0), line(line), column(column), mOrigFileName(file), mFileName(file), mInfo(info) {
} }
FileLocation(const Token* tok, const TokenList* tokenList); FileLocation(const Token* tok, const TokenList* tokenList);
@ -226,7 +226,7 @@ public:
unsigned int fileIndex; unsigned int fileIndex;
int line; // negative value means "no line" int line; // negative value means "no line"
unsigned int col; unsigned int column;
std::string getinfo() const { std::string getinfo() const {
return mInfo; return mInfo;
@ -300,15 +300,15 @@ public:
std::string serialize() const; std::string serialize() const;
bool deserialize(const std::string &data); bool deserialize(const std::string &data);
std::list<FileLocation> _callStack; std::list<FileLocation> callStack;
std::string _id; std::string id;
/** source file (not header) */ /** source file (not header) */
std::string file0; std::string file0;
Severity::SeverityType _severity; Severity::SeverityType severity;
CWE _cwe; CWE cwe;
bool _inconclusive; bool inconclusive;
/** set short and verbose messages */ /** set short and verbose messages */
void setmsg(const std::string &msg); void setmsg(const std::string &msg);

View File

@ -725,7 +725,7 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const
{ {
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList; std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
if (!filename.empty()) { if (!filename.empty()) {
const ErrorLogger::ErrorMessage::FileLocation loc(filename, linenr); const ErrorLogger::ErrorMessage::FileLocation loc(filename, linenr, 0);
locationList.push_back(loc); locationList.push_back(loc);
} }
mErrorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, mErrorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
@ -807,7 +807,7 @@ void Preprocessor::validateCfgError(const std::string &file, const unsigned int
{ {
const std::string id = "ConfigurationNotChecked"; const std::string id = "ConfigurationNotChecked";
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList; std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
const ErrorLogger::ErrorMessage::FileLocation loc(file, line); const ErrorLogger::ErrorMessage::FileLocation loc(file, line, 0);
locationList.push_back(loc); locationList.push_back(loc);
const ErrorLogger::ErrorMessage errmsg(locationList, mFile0, Severity::information, "Skipping configuration '" + cfg + "' since the value of '" + macro + "' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.", id, false); const ErrorLogger::ErrorMessage errmsg(locationList, mFile0, Severity::information, "Skipping configuration '" + cfg + "' since the value of '" + macro + "' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.", id, false);
mErrorLogger->reportInfo(errmsg); mErrorLogger->reportInfo(errmsg);

View File

@ -1477,7 +1477,7 @@ void Token::printAst(bool verbose, bool xml, std::ostream &out) const
if (xml) { if (xml) {
out << "<ast scope=\"" << tok->scope() << "\" fileIndex=\"" << tok->fileIndex() << "\" linenr=\"" << tok->linenr() out << "<ast scope=\"" << tok->scope() << "\" fileIndex=\"" << tok->fileIndex() << "\" linenr=\"" << tok->linenr()
<< "\" col=\"" << tok->col() << "\">" << std::endl; << "\" column=\"" << tok->column() << "\">" << std::endl;
astStringXml(tok, 2U, out); astStringXml(tok, 2U, out);
out << "</ast>" << std::endl; out << "</ast>" << std::endl;
} else if (verbose) } else if (verbose)

View File

@ -661,10 +661,10 @@ public:
mImpl->mLineNumber = lineNumber; mImpl->mLineNumber = lineNumber;
} }
nonneg int col() const { nonneg int column() const {
return mImpl->mColumn; return mImpl->mColumn;
} }
void col(nonneg int c) { void column(nonneg int c) {
mImpl->mColumn = c; mImpl->mColumn = c;
} }

View File

@ -4829,7 +4829,7 @@ void Tokenizer::dump(std::ostream &out) const
// tokens.. // tokens..
out << " <tokenlist>" << std::endl; out << " <tokenlist>" << std::endl;
for (const Token *tok = list.front(); tok; tok = tok->next()) { for (const Token *tok = list.front(); tok; tok = tok->next()) {
out << " <token id=\"" << tok << "\" file=\"" << ErrorLogger::toxml(list.file(tok)) << "\" linenr=\"" << tok->linenr() << "\" col=\"" << tok->col() << "\""; out << " <token id=\"" << tok << "\" file=\"" << ErrorLogger::toxml(list.file(tok)) << "\" linenr=\"" << tok->linenr() << "\" column=\"" << tok->column() << "\"";
out << " str=\"" << ErrorLogger::toxml(tok->str()) << '\"'; out << " str=\"" << ErrorLogger::toxml(tok->str()) << '\"';
out << " scope=\"" << tok->scope() << '\"'; out << " scope=\"" << tok->scope() << '\"';
if (tok->isName()) { if (tok->isName()) {

View File

@ -185,7 +185,7 @@ void TokenList::addtoken(std::string str, const Token *locationTok)
if (isCPP() && str == "delete") if (isCPP() && str == "delete")
mTokensFrontBack.back->isKeyword(true); mTokensFrontBack.back->isKeyword(true);
mTokensFrontBack.back->linenr(locationTok->linenr()); mTokensFrontBack.back->linenr(locationTok->linenr());
mTokensFrontBack.back->col(locationTok->col()); mTokensFrontBack.back->column(locationTok->column());
mTokensFrontBack.back->fileIndex(locationTok->fileIndex()); mTokensFrontBack.back->fileIndex(locationTok->fileIndex());
} }
@ -226,7 +226,7 @@ void TokenList::addtoken(const Token *tok, const Token *locationTok)
mTokensFrontBack.back->flags(tok->flags()); mTokensFrontBack.back->flags(tok->flags());
mTokensFrontBack.back->linenr(locationTok->linenr()); mTokensFrontBack.back->linenr(locationTok->linenr());
mTokensFrontBack.back->col(locationTok->col()); mTokensFrontBack.back->column(locationTok->column());
mTokensFrontBack.back->fileIndex(locationTok->fileIndex()); mTokensFrontBack.back->fileIndex(locationTok->fileIndex());
} }
@ -247,7 +247,7 @@ void TokenList::addtoken(const Token *tok)
mTokensFrontBack.back->flags(tok->flags()); mTokensFrontBack.back->flags(tok->flags());
mTokensFrontBack.back->linenr(tok->linenr()); mTokensFrontBack.back->linenr(tok->linenr());
mTokensFrontBack.back->col(tok->col()); mTokensFrontBack.back->column(tok->column());
mTokensFrontBack.back->fileIndex(tok->fileIndex()); mTokensFrontBack.back->fileIndex(tok->fileIndex());
} }
@ -392,7 +392,7 @@ void TokenList::createTokens(const simplecpp::TokenList *tokenList)
mTokensFrontBack.back->isKeyword(true); mTokensFrontBack.back->isKeyword(true);
mTokensFrontBack.back->fileIndex(tok->location.fileIndex); mTokensFrontBack.back->fileIndex(tok->location.fileIndex);
mTokensFrontBack.back->linenr(tok->location.line); mTokensFrontBack.back->linenr(tok->location.line);
mTokensFrontBack.back->col(tok->location.col); mTokensFrontBack.back->column(tok->location.col);
mTokensFrontBack.back->isExpandedMacro(!tok->macro.empty()); mTokensFrontBack.back->isExpandedMacro(!tok->macro.empty());
} }

View File

@ -41,7 +41,7 @@ private:
} }
void reportErr(const ErrorLogger::ErrorMessage &msg) { void reportErr(const ErrorLogger::ErrorMessage &msg) {
id.push_back(msg._id); id.push_back(msg.id);
} }
}; };

View File

@ -28,7 +28,7 @@
class TestErrorLogger : public TestFixture { class TestErrorLogger : public TestFixture {
public: public:
TestErrorLogger() : TestFixture("TestErrorLogger"), fooCpp5("foo.cpp", 5), barCpp8("bar.cpp", 8) { TestErrorLogger() : TestFixture("TestErrorLogger"), fooCpp5("foo.cpp", 5, 1), barCpp8("bar.cpp", 8, 1) {
} }
private: private:
@ -66,7 +66,7 @@ private:
const std::string plainText = "text"; const std::string plainText = "text";
ErrorLogger::ErrorMessage message; ErrorLogger::ErrorMessage message;
message._id = id; message.id = id;
std::string serialized = message.toString(true, idPlaceholder + plainText + idPlaceholder); std::string serialized = message.toString(true, idPlaceholder + plainText + idPlaceholder);
ASSERT_EQUALS(id + plainText + id, serialized); ASSERT_EQUALS(id + plainText + id, serialized);
@ -113,7 +113,7 @@ private:
void ErrorMessageConstruct() const { void ErrorMessageConstruct() const {
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5); std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.", "errorId", false); ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS(1, msg.callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Programming error.", msg.verboseMessage()); ASSERT_EQUALS("Programming error.", msg.verboseMessage());
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false)); ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false));
@ -123,7 +123,7 @@ private:
void ErrorMessageConstructLocations() const { void ErrorMessageConstructLocations() const {
std::list<ErrorLogger::ErrorMessage::FileLocation> locs = { fooCpp5, barCpp8 }; std::list<ErrorLogger::ErrorMessage::FileLocation> locs = { fooCpp5, barCpp8 };
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.", "errorId", false); ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.", "errorId", false);
ASSERT_EQUALS(2, (int)msg._callStack.size()); ASSERT_EQUALS(2, msg.callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Programming error.", msg.verboseMessage()); ASSERT_EQUALS("Programming error.", msg.verboseMessage());
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(false)); ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(false));
@ -133,7 +133,7 @@ private:
void ErrorMessageVerbose() const { void ErrorMessageVerbose() const {
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5); std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS(1, msg.callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage());
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false)); ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false));
@ -143,7 +143,7 @@ private:
void ErrorMessageVerboseLocations() const { void ErrorMessageVerboseLocations() const {
std::list<ErrorLogger::ErrorMessage::FileLocation> locs = { fooCpp5, barCpp8 }; std::list<ErrorLogger::ErrorMessage::FileLocation> locs = { fooCpp5, barCpp8 };
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(2, (int)msg._callStack.size()); ASSERT_EQUALS(2, msg.callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage());
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(false)); ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(false));
@ -153,7 +153,7 @@ private:
void CustomFormat() const { void CustomFormat() const {
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5); std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS(1, msg.callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage());
ASSERT_EQUALS("foo.cpp:5,error,errorId,Programming error.", msg.toString(false, "{file}:{line},{severity},{id},{message}")); ASSERT_EQUALS("foo.cpp:5,error,errorId,Programming error.", msg.toString(false, "{file}:{line},{severity},{id},{message}"));
@ -163,7 +163,7 @@ private:
void CustomFormat2() const { void CustomFormat2() const {
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5); std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS(1, msg.callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage());
ASSERT_EQUALS("Programming error. - foo.cpp(5):(error,errorId)", msg.toString(false, "{message} - {file}({line}):({severity},{id})")); ASSERT_EQUALS("Programming error. - foo.cpp(5):(error,errorId)", msg.toString(false, "{message} - {file}({line}):({severity},{id})"));
@ -174,7 +174,7 @@ private:
// Check that first location from location stack is used in template // Check that first location from location stack is used in template
std::list<ErrorLogger::ErrorMessage::FileLocation> locs = { fooCpp5, barCpp8 }; std::list<ErrorLogger::ErrorMessage::FileLocation> locs = { fooCpp5, barCpp8 };
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
ASSERT_EQUALS(2, (int)msg._callStack.size()); ASSERT_EQUALS(2, msg.callStack.size());
ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Programming error.", msg.shortMessage());
ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage());
ASSERT_EQUALS("Programming error. - bar.cpp(8):(error,errorId)", msg.toString(false, "{message} - {file}({line}):({severity},{id})")); ASSERT_EQUALS("Programming error. - bar.cpp(8):(error,errorId)", msg.toString(false, "{message} - {file}({line}):({severity},{id})"));
@ -192,7 +192,7 @@ private:
ASSERT_EQUALS(" </errors>\n</results>", ErrorLogger::ErrorMessage::getXMLFooter()); ASSERT_EQUALS(" </errors>\n</results>", ErrorLogger::ErrorMessage::getXMLFooter());
std::string message(" <error id=\"errorId\" severity=\"error\""); std::string message(" <error id=\"errorId\" severity=\"error\"");
message += " msg=\"Programming error.\" verbose=\"Verbose error\">\n"; message += " msg=\"Programming error.\" verbose=\"Verbose error\">\n";
message += " <location file=\"foo.cpp\" line=\"5\" column=\"0\"/>\n </error>"; message += " <location file=\"foo.cpp\" line=\"5\" column=\"1\"/>\n </error>";
ASSERT_EQUALS(message, msg.toXML()); ASSERT_EQUALS(message, msg.toXML());
} }
@ -208,8 +208,8 @@ private:
ASSERT_EQUALS(" </errors>\n</results>", ErrorLogger::ErrorMessage::getXMLFooter()); ASSERT_EQUALS(" </errors>\n</results>", ErrorLogger::ErrorMessage::getXMLFooter());
std::string message(" <error id=\"errorId\" severity=\"error\""); std::string message(" <error id=\"errorId\" severity=\"error\"");
message += " msg=\"Programming error.\" verbose=\"Verbose error\">\n"; message += " msg=\"Programming error.\" verbose=\"Verbose error\">\n";
message += " <location file=\"bar.cpp\" line=\"8\" column=\"0\" info=\"\\303\\244\"/>\n"; message += " <location file=\"bar.cpp\" line=\"8\" column=\"1\" info=\"\\303\\244\"/>\n";
message += " <location file=\"foo.cpp\" line=\"5\" column=\"0\"/>\n </error>"; message += " <location file=\"foo.cpp\" line=\"5\" column=\"1\"/>\n </error>";
ASSERT_EQUALS(message, msg.toXML()); ASSERT_EQUALS(message, msg.toXML());
} }
@ -240,7 +240,7 @@ private:
// xml version 2 error message // xml version 2 error message
ASSERT_EQUALS(" <error id=\"errorId\" severity=\"error\" msg=\"Programming error\" verbose=\"Programming error\" inconclusive=\"true\">\n" ASSERT_EQUALS(" <error id=\"errorId\" severity=\"error\" msg=\"Programming error\" verbose=\"Programming error\" inconclusive=\"true\">\n"
" <location file=\"foo.cpp\" line=\"5\" column=\"0\"/>\n" " <location file=\"foo.cpp\" line=\"5\" column=\"1\"/>\n"
" </error>", " </error>",
msg.toXML()); msg.toXML());
} }
@ -259,9 +259,9 @@ private:
ErrorMessage msg2; ErrorMessage msg2;
msg2.deserialize(msg.serialize()); msg2.deserialize(msg.serialize());
ASSERT_EQUALS("errorId", msg2._id); ASSERT_EQUALS("errorId", msg2.id);
ASSERT_EQUALS(Severity::error, msg2._severity); ASSERT_EQUALS(Severity::error, msg2.severity);
ASSERT_EQUALS(true, msg2._inconclusive); ASSERT_EQUALS(true, msg2.inconclusive);
ASSERT_EQUALS("Programming error", msg2.shortMessage()); ASSERT_EQUALS("Programming error", msg2.shortMessage());
ASSERT_EQUALS("Programming error", msg2.verboseMessage()); ASSERT_EQUALS("Programming error", msg2.verboseMessage());
} }
@ -284,8 +284,8 @@ private:
ErrorMessage msg2; ErrorMessage msg2;
msg2.deserialize(msg.serialize()); msg2.deserialize(msg.serialize());
ASSERT_EQUALS("errorId", msg2._id); ASSERT_EQUALS("errorId", msg2.id);
ASSERT_EQUALS(Severity::error, msg2._severity); ASSERT_EQUALS(Severity::error, msg2.severity);
ASSERT_EQUALS("Illegal character in \"foo\\001bar\"", msg2.shortMessage()); ASSERT_EQUALS("Illegal character in \"foo\\001bar\"", msg2.shortMessage());
ASSERT_EQUALS("Illegal character in \"foo\\001bar\"", msg2.verboseMessage()); ASSERT_EQUALS("Illegal character in \"foo\\001bar\"", msg2.verboseMessage());
} }
@ -294,7 +294,7 @@ private:
ErrorLogger::ErrorMessage::FileLocation loc1; ErrorLogger::ErrorMessage::FileLocation loc1;
loc1.setfile(":/,"); loc1.setfile(":/,");
loc1.line = 643; loc1.line = 643;
loc1.col = 33; loc1.column = 33;
loc1.setinfo("abcd:/,"); loc1.setinfo("abcd:/,");
std::list<ErrorLogger::ErrorMessage::FileLocation> locs{loc1}; std::list<ErrorLogger::ErrorMessage::FileLocation> locs{loc1};
@ -303,10 +303,10 @@ private:
ErrorMessage msg2; ErrorMessage msg2;
msg2.deserialize(msg.serialize()); msg2.deserialize(msg.serialize());
ASSERT_EQUALS(":/,", msg2._callStack.front().getfile(false)); ASSERT_EQUALS(":/,", msg2.callStack.front().getfile(false));
ASSERT_EQUALS(643, msg2._callStack.front().line); ASSERT_EQUALS(643, msg2.callStack.front().line);
ASSERT_EQUALS(33, msg2._callStack.front().col); ASSERT_EQUALS(33, msg2.callStack.front().column);
ASSERT_EQUALS("abcd:/,", msg2._callStack.front().getinfo()); ASSERT_EQUALS("abcd:/,", msg2.callStack.front().getinfo());
} }
void suppressUnmatchedSuppressions() { void suppressUnmatchedSuppressions() {

View File

@ -26,21 +26,21 @@ class Token;
class givenACodeSampleToTokenize { class givenACodeSampleToTokenize {
private: private:
Settings _settings; Settings settings;
Tokenizer _tokenizer; Tokenizer tokenizer;
public: public:
explicit givenACodeSampleToTokenize(const char sample[], bool createOnly = false, bool cpp = true) explicit givenACodeSampleToTokenize(const char sample[], bool createOnly = false, bool cpp = true)
: _tokenizer(&_settings, nullptr) { : tokenizer(&settings, nullptr) {
std::istringstream iss(sample); std::istringstream iss(sample);
if (createOnly) if (createOnly)
_tokenizer.list.createTokens(iss, cpp ? "test.cpp" : "test.c"); tokenizer.list.createTokens(iss, cpp ? "test.cpp" : "test.c");
else else
_tokenizer.tokenize(iss, cpp ? "test.cpp" : "test.c"); tokenizer.tokenize(iss, cpp ? "test.cpp" : "test.c");
} }
const Token* tokens() const { const Token* tokens() const {
return _tokenizer.tokens(); return tokenizer.tokens();
} }
}; };
@ -48,18 +48,18 @@ public:
class SimpleSuppressor : public ErrorLogger { class SimpleSuppressor : public ErrorLogger {
public: public:
SimpleSuppressor(Settings &settings, ErrorLogger *next) SimpleSuppressor(Settings &settings, ErrorLogger *next)
: _settings(settings), _next(next) { : settings(settings), next(next) {
} }
virtual void reportOut(const std::string &outmsg) OVERRIDE { virtual void reportOut(const std::string &outmsg) OVERRIDE {
_next->reportOut(outmsg); next->reportOut(outmsg);
} }
virtual void reportErr(const ErrorLogger::ErrorMessage &msg) OVERRIDE { virtual void reportErr(const ErrorLogger::ErrorMessage &msg) OVERRIDE {
if (!msg._callStack.empty() && !_settings.nomsg.isSuppressed(msg.toSuppressionsErrorMessage())) if (!msg.callStack.empty() && !settings.nomsg.isSuppressed(msg.toSuppressionsErrorMessage()))
_next->reportErr(msg); next->reportErr(msg);
} }
private: private:
Settings &_settings; Settings &settings;
ErrorLogger *_next; ErrorLogger *next;
}; };
#endif // TestUtilsH #endif // TestUtilsH