Refactoring: Rename variables. Do not use leading _. Renamed 'col' to 'column'
This commit is contained in:
parent
5f2379f3d1
commit
2d9a131817
|
@ -34,7 +34,7 @@ class Directive:
|
|||
str = None
|
||||
file = None
|
||||
linenr = None
|
||||
col = 0
|
||||
column = 0
|
||||
|
||||
def __init__(self, element):
|
||||
self.str = element.get('str')
|
||||
|
@ -131,7 +131,7 @@ class Token:
|
|||
astOperand2 ast operand2
|
||||
file file name
|
||||
linenr line number
|
||||
col column
|
||||
column column
|
||||
|
||||
To iterate through all tokens use such code:
|
||||
@code
|
||||
|
@ -188,7 +188,7 @@ class Token:
|
|||
|
||||
file = None
|
||||
linenr = None
|
||||
col = None
|
||||
column = None
|
||||
|
||||
def __init__(self, element):
|
||||
self.Id = element.get('id')
|
||||
|
@ -251,7 +251,7 @@ class Token:
|
|||
self.astOperand2 = None
|
||||
self.file = element.get('file')
|
||||
self.linenr = int(element.get('linenr'))
|
||||
self.col = int(element.get('col'))
|
||||
self.column = int(element.get('column'))
|
||||
|
||||
def setId(self, IdMap):
|
||||
self.scope = IdMap[self.scopeId]
|
||||
|
@ -868,7 +868,7 @@ def reportError(location, severity, message, addon, errorId, extra=''):
|
|||
if '--cli' in sys.argv:
|
||||
msg = { 'file': location.file,
|
||||
'linenr': location.linenr,
|
||||
'col': location.col,
|
||||
'column': location.column,
|
||||
'severity': severity,
|
||||
'message': message,
|
||||
'addon': addon,
|
||||
|
|
|
@ -746,7 +746,7 @@ class MisraChecker:
|
|||
tokens = long_vars[name_prefix]
|
||||
if len(tokens) < 2:
|
||||
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)
|
||||
|
||||
def misra_5_2(self, data):
|
||||
|
@ -1479,7 +1479,7 @@ class MisraChecker:
|
|||
continue
|
||||
if not simpleMatch(scope.bodyStart, '{ if ('):
|
||||
continue
|
||||
if scope.bodyStart.col > 0:
|
||||
if scope.bodyStart.column > 0:
|
||||
continue
|
||||
tok = scope.bodyStart.next.next.link
|
||||
if not simpleMatch(tok, ') {'):
|
||||
|
|
|
@ -294,7 +294,7 @@ unsigned int ThreadExecutor::check()
|
|||
oss << "Internal error: Child process crashed with signal " << WTERMSIG(stat);
|
||||
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locations;
|
||||
locations.emplace_back(childname, 0);
|
||||
locations.emplace_back(childname, 0, 0);
|
||||
const ErrorLogger::ErrorMessage errmsg(locations,
|
||||
emptyString,
|
||||
Severity::error,
|
||||
|
|
|
@ -347,7 +347,7 @@ void CheckThread::parseAddonErrors(QString err, const QString &tool)
|
|||
/*
|
||||
msg = { 'file': location.file,
|
||||
'linenr': location.linenr,
|
||||
'col': location.col,
|
||||
'column': location.column,
|
||||
'severity': severity,
|
||||
'message': message,
|
||||
'addon': addon,
|
||||
|
@ -357,14 +357,13 @@ void CheckThread::parseAddonErrors(QString err, const QString &tool)
|
|||
|
||||
const std::string &filename = obj["file"].toString().toStdString();
|
||||
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 message = obj["message"].toString().toStdString();
|
||||
const std::string id = (obj["addon"].toString() + "-" + obj["errorId"].toString()).toStdString();
|
||||
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
|
||||
callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(filename, lineNumber));
|
||||
callstack.back().col = column;
|
||||
callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(filename, lineNumber, column));
|
||||
ErrorLogger::ErrorMessage errmsg(callstack, filename, Severity::fromString(severity), message, id, false);
|
||||
|
||||
if (isSuppressed(errmsg.toSuppressionsErrorMessage()))
|
||||
|
@ -387,9 +386,9 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
|
|||
if (line.startsWith("Assertion failed:")) {
|
||||
ErrorItem e;
|
||||
e.errorPath.append(QErrorPathItem());
|
||||
e.errorPath.last().file = file0;
|
||||
e.errorPath.last().line = 1;
|
||||
e.errorPath.last().col = 1;
|
||||
e.errorPath.last().file = file0;
|
||||
e.errorPath.last().line = 1;
|
||||
e.errorPath.last().column = 1;
|
||||
e.errorId = tool + "-internal-error";
|
||||
e.file0 = file0;
|
||||
e.message = line;
|
||||
|
@ -409,7 +408,7 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
|
|||
errorItem.errorPath.append(QErrorPathItem());
|
||||
errorItem.errorPath.last().file = r1.cap(1);
|
||||
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")
|
||||
errorItem.severity = Severity::SeverityType::warning;
|
||||
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;
|
||||
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 msg = e.message.toStdString();
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
QErrorPathItem::QErrorPathItem(const ErrorLogger::ErrorMessage::FileLocation &loc)
|
||||
: file(QString::fromStdString(loc.getfile(false)))
|
||||
, line(loc.line)
|
||||
, col(loc.col)
|
||||
, column(loc.column)
|
||||
, info(QString::fromStdString(loc.getinfo()))
|
||||
{
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -40,16 +40,16 @@ ErrorItem::ErrorItem()
|
|||
}
|
||||
|
||||
ErrorItem::ErrorItem(const ErrorLogger::ErrorMessage &errmsg)
|
||||
: errorId(QString::fromStdString(errmsg._id))
|
||||
, severity(errmsg._severity)
|
||||
, inconclusive(errmsg._inconclusive)
|
||||
: errorId(QString::fromStdString(errmsg.id))
|
||||
, severity(errmsg.severity)
|
||||
, inconclusive(errmsg.inconclusive)
|
||||
, summary(QString::fromStdString(errmsg.shortMessage()))
|
||||
, message(QString::fromStdString(errmsg.verboseMessage()))
|
||||
, cwe(errmsg._cwe.id)
|
||||
, cwe(errmsg.cwe.id)
|
||||
, symbolNames(QString::fromStdString(errmsg.symbolNames()))
|
||||
{
|
||||
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = errmsg._callStack.begin();
|
||||
loc != errmsg._callStack.end();
|
||||
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = errmsg.callStack.begin();
|
||||
loc != errmsg.callStack.end();
|
||||
++loc) {
|
||||
errorPath << QErrorPathItem(*loc);
|
||||
}
|
||||
|
|
|
@ -51,11 +51,11 @@ public:
|
|||
*/
|
||||
class QErrorPathItem {
|
||||
public:
|
||||
QErrorPathItem() : line(0), col(-1) {}
|
||||
QErrorPathItem() : line(0), column(-1) {}
|
||||
explicit QErrorPathItem(const ErrorLogger::ErrorMessage::FileLocation &loc);
|
||||
QString file;
|
||||
unsigned int line;
|
||||
int col;
|
||||
int line;
|
||||
int column;
|
||||
QString info;
|
||||
};
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ NewSuppressionDialog::NewSuppressionDialog(QWidget *parent) :
|
|||
public:
|
||||
virtual void reportOut(const std::string &/*outmsg*/) {}
|
||||
virtual void reportErr(const ErrorLogger::ErrorMessage &msg) {
|
||||
errorIds << QString::fromStdString(msg._id);
|
||||
errorIds << QString::fromStdString(msg.id);
|
||||
}
|
||||
QStringList errorIds;
|
||||
};
|
||||
|
|
|
@ -187,7 +187,7 @@ bool ResultsTree::addErrorItem(const ErrorItem &item)
|
|||
data["message"] = item.message;
|
||||
data["file"] = loc.file;
|
||||
data["line"] = loc.line;
|
||||
data["col"] = loc.col;
|
||||
data["column"] = loc.column;
|
||||
data["id"] = item.errorId;
|
||||
data["inconclusive"] = item.inconclusive;
|
||||
data["file0"] = stripPath(item.file0, true);
|
||||
|
@ -219,7 +219,7 @@ bool ResultsTree::addErrorItem(const ErrorItem &item)
|
|||
child_data["message"] = line.message;
|
||||
child_data["file"] = e.file;
|
||||
child_data["line"] = e.line;
|
||||
child_data["col"] = e.col;
|
||||
child_data["column"] = e.column;
|
||||
child_data["id"] = line.errorId;
|
||||
child_data["inconclusive"] = line.inconclusive;
|
||||
child_item->setData(QVariant(child_data));
|
||||
|
|
|
@ -61,7 +61,7 @@ void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
|
|||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
const ErrorItem item(msg);
|
||||
if (msg._severity != Severity::debug)
|
||||
if (msg.severity != Severity::debug)
|
||||
emit error(item);
|
||||
else
|
||||
emit debugError(item);
|
||||
|
|
|
@ -33,7 +33,6 @@ static const QString CppcheckElementName = "cppcheck";
|
|||
static const QString ErrorElementName = "error";
|
||||
static const QString ErrorsElementName = "errors";
|
||||
static const QString LocationElementName = "location";
|
||||
static const QString ColAttribute = "col";
|
||||
static const QString CWEAttribute = "cwe";
|
||||
static const QString SinceDateAttribute = "sinceDate";
|
||||
static const QString TagsAttribute = "tag";
|
||||
|
@ -42,6 +41,7 @@ static const QString IncludedFromFilenameAttribute = "file0";
|
|||
static const QString InconclusiveAttribute = "inconclusive";
|
||||
static const QString InfoAttribute = "info";
|
||||
static const QString LineAttribute = "line";
|
||||
static const QString ColumnAttribute = "column";
|
||||
static const QString IdAttribute = "id";
|
||||
static const QString SeverityAttribute = "severity";
|
||||
static const QString MsgAttribute = "msg";
|
||||
|
@ -136,8 +136,8 @@ void XmlReportV2::writeError(const ErrorItem &error)
|
|||
}
|
||||
mXmlWriter->writeAttribute(FilenameAttribute, XmlReport::quoteMessage(file));
|
||||
mXmlWriter->writeAttribute(LineAttribute, QString::number(error.errorPath[i].line));
|
||||
if (error.errorPath[i].col > 0)
|
||||
mXmlWriter->writeAttribute(ColAttribute, QString::number(error.errorPath[i].col));
|
||||
if (error.errorPath[i].column > 0)
|
||||
mXmlWriter->writeAttribute(ColumnAttribute, QString::number(error.errorPath[i].column));
|
||||
if (error.errorPath.count() > 1)
|
||||
mXmlWriter->writeAttribute(InfoAttribute, XmlReport::quoteMessage(error.errorPath[i].info));
|
||||
|
||||
|
@ -235,8 +235,8 @@ ErrorItem XmlReportV2::readError(QXmlStreamReader *reader)
|
|||
QErrorPathItem loc;
|
||||
loc.file = XmlReport::unquoteMessage(attribs.value(QString(), FilenameAttribute).toString());
|
||||
loc.line = attribs.value(QString(), LineAttribute).toString().toUInt();
|
||||
if (attribs.hasAttribute(QString(), ColAttribute))
|
||||
loc.col = attribs.value(QString(), ColAttribute).toString().toInt();
|
||||
if (attribs.hasAttribute(QString(), ColumnAttribute))
|
||||
loc.column = attribs.value(QString(), ColumnAttribute).toString().toInt();
|
||||
if (attribs.hasAttribute(QString(), InfoAttribute))
|
||||
loc.info = XmlReport::unquoteMessage(attribs.value(QString(), InfoAttribute).toString());
|
||||
item.errorPath.push_front(loc);
|
||||
|
|
|
@ -279,7 +279,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
|||
};
|
||||
|
||||
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);
|
||||
|
||||
ErrorLogger::ErrorMessage errmsg(callstack,
|
||||
|
@ -562,7 +562,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
|||
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||
if (e.token) {
|
||||
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));
|
||||
loc.setfile(fixedpath);
|
||||
} else {
|
||||
|
@ -579,7 +579,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
|||
e.id,
|
||||
false);
|
||||
|
||||
if (errmsg._severity == Severity::error || mSettings.isEnabled(errmsg._severity))
|
||||
if (errmsg.severity == Severity::error || mSettings.isEnabled(errmsg.severity))
|
||||
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 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;
|
||||
|
||||
errmsg._callStack.emplace_back(ErrorLogger::ErrorMessage::FileLocation(fileName, lineNumber));
|
||||
errmsg._callStack.back().col = column;
|
||||
errmsg.callStack.emplace_back(ErrorLogger::ErrorMessage::FileLocation(fileName, lineNumber, 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>();
|
||||
errmsg.setmsg(text);
|
||||
const std::string severity = obj["severity"].get<std::string>();
|
||||
errmsg._severity = Severity::fromString(severity);
|
||||
if (errmsg._severity == Severity::SeverityType::none)
|
||||
errmsg.severity = Severity::fromString(severity);
|
||||
if (errmsg.severity == Severity::SeverityType::none)
|
||||
continue;
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
ErrorLogger::ErrorMessage errmsg(callstack,
|
||||
|
|
|
@ -44,7 +44,7 @@ int CTU::maxCtuDepth = 2;
|
|||
|
||||
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)
|
||||
|
|
|
@ -59,17 +59,17 @@ InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type
|
|||
}
|
||||
|
||||
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) :
|
||||
_callStack(callStack), // locations for this error message
|
||||
_id(id), // set the message id
|
||||
callStack(callStack), // locations for this error message
|
||||
id(id), // set the message id
|
||||
file0(file1),
|
||||
_severity(severity), // severity for this error message
|
||||
_cwe(0U),
|
||||
_inconclusive(inconclusive)
|
||||
severity(severity), // severity for this error message
|
||||
cwe(0U),
|
||||
inconclusive(inconclusive)
|
||||
{
|
||||
// set the summary and verbose messages
|
||||
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) :
|
||||
_callStack(callStack), // locations for this error message
|
||||
_id(id), // set the message id
|
||||
callStack(callStack), // locations for this error message
|
||||
id(id), // set the message id
|
||||
file0(file1),
|
||||
_severity(severity), // severity for this error message
|
||||
_cwe(cwe.id),
|
||||
_inconclusive(inconclusive)
|
||||
severity(severity), // severity for this error message
|
||||
cwe(cwe.id),
|
||||
inconclusive(inconclusive)
|
||||
{
|
||||
// set the summary and verbose messages
|
||||
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)
|
||||
: _id(id), _severity(severity), _cwe(0U), _inconclusive(inconclusive)
|
||||
: id(id), severity(severity), cwe(0U), inconclusive(inconclusive)
|
||||
{
|
||||
// Format callstack
|
||||
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))
|
||||
continue;
|
||||
|
||||
_callStack.emplace_back(*it, list);
|
||||
callStack.emplace_back(*it, list);
|
||||
}
|
||||
|
||||
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)
|
||||
: _id(id), _severity(severity), _cwe(cwe.id), _inconclusive(inconclusive)
|
||||
: id(id), severity(severity), cwe(cwe.id), inconclusive(inconclusive)
|
||||
{
|
||||
// Format callstack
|
||||
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))
|
||||
continue;
|
||||
|
||||
_callStack.emplace_back(*it, list);
|
||||
callStack.emplace_back(*it, list);
|
||||
}
|
||||
|
||||
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)
|
||||
: _id(id), _severity(severity), _cwe(cwe.id), _inconclusive(inconclusive)
|
||||
: id(id), severity(severity), cwe(cwe.id), inconclusive(inconclusive)
|
||||
{
|
||||
// Format callstack
|
||||
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
|
||||
if (tok)
|
||||
_callStack.emplace_back(tok, info, tokenList);
|
||||
callStack.emplace_back(tok, info, tokenList);
|
||||
}
|
||||
|
||||
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)
|
||||
: _severity(Severity::none),
|
||||
_cwe(0U),
|
||||
_inconclusive(false)
|
||||
: severity(Severity::none),
|
||||
cwe(0U),
|
||||
inconclusive(false)
|
||||
{
|
||||
const char * const unknown = "<UNKNOWN>";
|
||||
|
||||
const char *attr = errmsg->Attribute("id");
|
||||
_id = attr ? attr : unknown;
|
||||
id = attr ? attr : unknown;
|
||||
|
||||
attr = errmsg->Attribute("severity");
|
||||
_severity = attr ? Severity::fromString(attr) : Severity::none;
|
||||
severity = attr ? Severity::fromString(attr) : Severity::none;
|
||||
|
||||
attr = errmsg->Attribute("cwe");
|
||||
std::istringstream(attr ? attr : "0") >> _cwe.id;
|
||||
std::istringstream(attr ? attr : "0") >> cwe.id;
|
||||
|
||||
attr = errmsg->Attribute("inconclusive");
|
||||
_inconclusive = attr && (std::strcmp(attr, "true") == 0);
|
||||
inconclusive = attr && (std::strcmp(attr, "true") == 0);
|
||||
|
||||
attr = errmsg->Attribute("msg");
|
||||
mShortMessage = attr ? attr : "";
|
||||
|
@ -175,11 +175,13 @@ ErrorLogger::ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errms
|
|||
const char *strfile = e->Attribute("file");
|
||||
const char *strinfo = e->Attribute("info");
|
||||
const char *strline = e->Attribute("line");
|
||||
const char *strcolumn = e->Attribute("column");
|
||||
|
||||
const char *file = strfile ? strfile : unknown;
|
||||
const char *info = strinfo ? strinfo : "";
|
||||
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 ret;
|
||||
ret.errorId = _id;
|
||||
if (!_callStack.empty()) {
|
||||
ret.setFileName(_callStack.back().getfile(false));
|
||||
ret.lineNumber = _callStack.back().line;
|
||||
ret.errorId = id;
|
||||
if (!callStack.empty()) {
|
||||
ret.setFileName(callStack.back().getfile(false));
|
||||
ret.lineNumber = callStack.back().line;
|
||||
}
|
||||
ret.inconclusive = _inconclusive;
|
||||
ret.inconclusive = inconclusive;
|
||||
ret.symbolNames = mSymbolNames;
|
||||
return ret;
|
||||
}
|
||||
|
@ -228,10 +230,10 @@ std::string ErrorLogger::ErrorMessage::serialize() const
|
|||
{
|
||||
// Serialize this message into a simple string
|
||||
std::ostringstream oss;
|
||||
oss << _id.length() << " " << _id;
|
||||
oss << Severity::toString(_severity).length() << " " << Severity::toString(_severity);
|
||||
oss << MathLib::toString(_cwe.id).length() << " " << MathLib::toString(_cwe.id);
|
||||
if (_inconclusive) {
|
||||
oss << id.length() << " " << id;
|
||||
oss << Severity::toString(severity).length() << " " << Severity::toString(severity);
|
||||
oss << MathLib::toString(cwe.id).length() << " " << MathLib::toString(cwe.id);
|
||||
if (inconclusive) {
|
||||
const std::string inconclusive("inconclusive");
|
||||
oss << inconclusive.length() << " " << inconclusive;
|
||||
}
|
||||
|
@ -241,11 +243,11 @@ std::string ErrorLogger::ErrorMessage::serialize() const
|
|||
|
||||
oss << saneShortMessage.length() << " " << saneShortMessage;
|
||||
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;
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -254,8 +256,8 @@ std::string ErrorLogger::ErrorMessage::serialize() const
|
|||
|
||||
bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
||||
{
|
||||
_inconclusive = false;
|
||||
_callStack.clear();
|
||||
inconclusive = false;
|
||||
callStack.clear();
|
||||
std::istringstream iss(data);
|
||||
std::array<std::string, 5> results;
|
||||
std::size_t elem = 0;
|
||||
|
@ -272,7 +274,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
|||
}
|
||||
|
||||
if (temp == "inconclusive") {
|
||||
_inconclusive = true;
|
||||
inconclusive = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -284,10 +286,10 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
|||
if (elem != 5)
|
||||
throw InternalError(nullptr, "Internal Error: Deserialization of error message failed");
|
||||
|
||||
_id = results[0];
|
||||
_severity = Severity::fromString(results[1]);
|
||||
id = results[0];
|
||||
severity = Severity::fromString(results[1]);
|
||||
std::istringstream scwe(results[2]);
|
||||
scwe >> _cwe.id;
|
||||
scwe >> cwe.id;
|
||||
mShortMessage = results[3];
|
||||
mVerboseMessage = results[4];
|
||||
|
||||
|
@ -327,12 +329,12 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
|||
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||
loc.setfile(tempfile);
|
||||
loc.setinfo(tempinfo);
|
||||
loc.col = MathLib::toLongNumber(tempcolumn);
|
||||
loc.column = MathLib::toLongNumber(tempcolumn);
|
||||
loc.line = MathLib::toLongNumber(templine);
|
||||
|
||||
_callStack.push_back(loc);
|
||||
callStack.push_back(loc);
|
||||
|
||||
if (_callStack.size() >= stackSize)
|
||||
if (callStack.size() >= stackSize)
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -391,22 +393,22 @@ std::string ErrorLogger::ErrorMessage::toXML() const
|
|||
{
|
||||
tinyxml2::XMLPrinter printer(nullptr, false, 2);
|
||||
printer.OpenElement("error", false);
|
||||
printer.PushAttribute("id", _id.c_str());
|
||||
printer.PushAttribute("severity", Severity::toString(_severity).c_str());
|
||||
printer.PushAttribute("id", id.c_str());
|
||||
printer.PushAttribute("severity", Severity::toString(severity).c_str());
|
||||
printer.PushAttribute("msg", fixInvalidChars(mShortMessage).c_str());
|
||||
printer.PushAttribute("verbose", fixInvalidChars(mVerboseMessage).c_str());
|
||||
if (_cwe.id)
|
||||
printer.PushAttribute("cwe", _cwe.id);
|
||||
if (_inconclusive)
|
||||
if (cwe.id)
|
||||
printer.PushAttribute("cwe", cwe.id);
|
||||
if (inconclusive)
|
||||
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);
|
||||
if (!file0.empty() && (*it).getfile() != file0)
|
||||
printer.PushAttribute("file0", Path::toNativeSeparators(file0).c_str());
|
||||
printer.PushAttribute("file", (*it).getfile().c_str());
|
||||
printer.PushAttribute("line", std::max((*it).line,0));
|
||||
printer.PushAttribute("column", (*it).col);
|
||||
printer.PushAttribute("column", (*it).column);
|
||||
if (!it->getinfo().empty())
|
||||
printer.PushAttribute("info", fixInvalidChars(it->getinfo()).c_str());
|
||||
printer.CloseElement(false);
|
||||
|
@ -462,11 +464,11 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
|
|||
// No template is given
|
||||
if (templateFormat.empty()) {
|
||||
std::ostringstream text;
|
||||
if (!_callStack.empty())
|
||||
text << callStackToString(_callStack) << ": ";
|
||||
if (_severity != Severity::none) {
|
||||
text << '(' << Severity::toString(_severity);
|
||||
if (_inconclusive)
|
||||
if (!callStack.empty())
|
||||
text << callStackToString(callStack) << ": ";
|
||||
if (severity != Severity::none) {
|
||||
text << '(' << Severity::toString(severity);
|
||||
if (inconclusive)
|
||||
text << ", inconclusive";
|
||||
text << ") ";
|
||||
}
|
||||
|
@ -483,22 +485,22 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
|
|||
findAndReplace(result, "\\r", "\r");
|
||||
findAndReplace(result, "\\t", "\t");
|
||||
|
||||
findAndReplace(result, "{id}", _id);
|
||||
findAndReplace(result, "{id}", id);
|
||||
if (result.find("{inconclusive:") != std::string::npos) {
|
||||
const std::string::size_type pos1 = result.find("{inconclusive:");
|
||||
const std::string::size_type pos2 = result.find('}', 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, "{severity}", Severity::toString(_severity));
|
||||
findAndReplace(result, "{cwe}", MathLib::toString(_cwe.id));
|
||||
findAndReplace(result, "{severity}", Severity::toString(severity));
|
||||
findAndReplace(result, "{cwe}", MathLib::toString(cwe.id));
|
||||
findAndReplace(result, "{message}", verbose ? mVerboseMessage : mShortMessage);
|
||||
findAndReplace(result, "{callstack}", _callStack.empty() ? emptyString : callStackToString(_callStack));
|
||||
if (!_callStack.empty()) {
|
||||
findAndReplace(result, "{file}", _callStack.back().getfile());
|
||||
findAndReplace(result, "{line}", MathLib::toString(_callStack.back().line));
|
||||
findAndReplace(result, "{column}", MathLib::toString(_callStack.back().col));
|
||||
findAndReplace(result, "{callstack}", callStack.empty() ? emptyString : callStackToString(callStack));
|
||||
if (!callStack.empty()) {
|
||||
findAndReplace(result, "{file}", callStack.back().getfile());
|
||||
findAndReplace(result, "{line}", MathLib::toString(callStack.back().line));
|
||||
findAndReplace(result, "{column}", MathLib::toString(callStack.back().column));
|
||||
if (result.find("{code}") != std::string::npos) {
|
||||
const std::string::size_type pos = result.find('\r');
|
||||
const char *endl;
|
||||
|
@ -508,7 +510,7 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
|
|||
endl = "\r\n";
|
||||
else
|
||||
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 {
|
||||
findAndReplace(result, "{file}", "nofile");
|
||||
|
@ -517,8 +519,8 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
|
|||
findAndReplace(result, "{code}", emptyString);
|
||||
}
|
||||
|
||||
if (!templateLocation.empty() && _callStack.size() >= 2U) {
|
||||
for (const FileLocation &fileLocation : _callStack) {
|
||||
if (!templateLocation.empty() && callStack.size() >= 2U) {
|
||||
for (const FileLocation &fileLocation : callStack) {
|
||||
std::string text = templateLocation;
|
||||
|
||||
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, "{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());
|
||||
if (text.find("{code}") != std::string::npos) {
|
||||
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";
|
||||
else
|
||||
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;
|
||||
}
|
||||
|
@ -574,7 +576,7 @@ bool ErrorLogger::reportUnmatchedSuppressions(const std::list<Suppressions::Supp
|
|||
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
|
||||
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));
|
||||
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)
|
||||
: 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)
|
||||
: 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;
|
||||
ostr << indent << "<dict>\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 << "</dict>\r\n";
|
||||
return ostr.str();
|
||||
|
@ -701,9 +703,9 @@ std::string ErrorLogger::plistData(const ErrorLogger::ErrorMessage &msg)
|
|||
<< " <key>path</key>\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) {
|
||||
plist << " <dict>\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;
|
||||
++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"
|
||||
<< " <key>kind</key><string>event</string>\r\n"
|
||||
|
@ -751,16 +753,16 @@ std::string ErrorLogger::plistData(const ErrorLogger::ErrorMessage &msg)
|
|||
|
||||
plist << " </array>\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>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"
|
||||
<< " <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</key><string></string>\r\n"
|
||||
<< " <key>issue_hash_function_offset</key><string></string>\r\n"
|
||||
<< " <key>location</key>\r\n"
|
||||
<< plistLoc(" ", msg._callStack.back())
|
||||
<< plistLoc(" ", msg.callStack.back())
|
||||
<< " </dict>\r\n";
|
||||
return plist.str();
|
||||
}
|
||||
|
|
|
@ -190,15 +190,15 @@ public:
|
|||
class CPPCHECKLIB FileLocation {
|
||||
public:
|
||||
FileLocation()
|
||||
: fileIndex(0), line(0), col(0) {
|
||||
: fileIndex(0), line(0), column(0) {
|
||||
}
|
||||
|
||||
FileLocation(const std::string &file, int line)
|
||||
: fileIndex(0), line(line), col(0), mOrigFileName(file), mFileName(file) {
|
||||
FileLocation(const std::string &file, int line, int column)
|
||||
: fileIndex(0), line(line), column(column), mOrigFileName(file), mFileName(file) {
|
||||
}
|
||||
|
||||
FileLocation(const std::string &file, const std::string &info, int line)
|
||||
: fileIndex(0), line(line), col(0), mOrigFileName(file), mFileName(file), mInfo(info) {
|
||||
FileLocation(const std::string &file, const std::string &info, int line, int column)
|
||||
: fileIndex(0), line(line), column(column), mOrigFileName(file), mFileName(file), mInfo(info) {
|
||||
}
|
||||
|
||||
FileLocation(const Token* tok, const TokenList* tokenList);
|
||||
|
@ -226,7 +226,7 @@ public:
|
|||
|
||||
unsigned int fileIndex;
|
||||
int line; // negative value means "no line"
|
||||
unsigned int col;
|
||||
unsigned int column;
|
||||
|
||||
std::string getinfo() const {
|
||||
return mInfo;
|
||||
|
@ -300,15 +300,15 @@ public:
|
|||
std::string serialize() const;
|
||||
bool deserialize(const std::string &data);
|
||||
|
||||
std::list<FileLocation> _callStack;
|
||||
std::string _id;
|
||||
std::list<FileLocation> callStack;
|
||||
std::string id;
|
||||
|
||||
/** source file (not header) */
|
||||
std::string file0;
|
||||
|
||||
Severity::SeverityType _severity;
|
||||
CWE _cwe;
|
||||
bool _inconclusive;
|
||||
Severity::SeverityType severity;
|
||||
CWE cwe;
|
||||
bool inconclusive;
|
||||
|
||||
/** set short and verbose messages */
|
||||
void setmsg(const std::string &msg);
|
||||
|
|
|
@ -725,7 +725,7 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const
|
|||
{
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||
if (!filename.empty()) {
|
||||
const ErrorLogger::ErrorMessage::FileLocation loc(filename, linenr);
|
||||
const ErrorLogger::ErrorMessage::FileLocation loc(filename, linenr, 0);
|
||||
locationList.push_back(loc);
|
||||
}
|
||||
mErrorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
|
||||
|
@ -807,7 +807,7 @@ void Preprocessor::validateCfgError(const std::string &file, const unsigned int
|
|||
{
|
||||
const std::string id = "ConfigurationNotChecked";
|
||||
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);
|
||||
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);
|
||||
|
|
|
@ -1477,7 +1477,7 @@ void Token::printAst(bool verbose, bool xml, std::ostream &out) const
|
|||
|
||||
if (xml) {
|
||||
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);
|
||||
out << "</ast>" << std::endl;
|
||||
} else if (verbose)
|
||||
|
|
|
@ -661,10 +661,10 @@ public:
|
|||
mImpl->mLineNumber = lineNumber;
|
||||
}
|
||||
|
||||
nonneg int col() const {
|
||||
nonneg int column() const {
|
||||
return mImpl->mColumn;
|
||||
}
|
||||
void col(nonneg int c) {
|
||||
void column(nonneg int c) {
|
||||
mImpl->mColumn = c;
|
||||
}
|
||||
|
||||
|
|
|
@ -4829,7 +4829,7 @@ void Tokenizer::dump(std::ostream &out) const
|
|||
// tokens..
|
||||
out << " <tokenlist>" << std::endl;
|
||||
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 << " scope=\"" << tok->scope() << '\"';
|
||||
if (tok->isName()) {
|
||||
|
|
|
@ -185,7 +185,7 @@ void TokenList::addtoken(std::string str, const Token *locationTok)
|
|||
if (isCPP() && str == "delete")
|
||||
mTokensFrontBack.back->isKeyword(true);
|
||||
mTokensFrontBack.back->linenr(locationTok->linenr());
|
||||
mTokensFrontBack.back->col(locationTok->col());
|
||||
mTokensFrontBack.back->column(locationTok->column());
|
||||
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->linenr(locationTok->linenr());
|
||||
mTokensFrontBack.back->col(locationTok->col());
|
||||
mTokensFrontBack.back->column(locationTok->column());
|
||||
mTokensFrontBack.back->fileIndex(locationTok->fileIndex());
|
||||
}
|
||||
|
||||
|
@ -247,7 +247,7 @@ void TokenList::addtoken(const Token *tok)
|
|||
|
||||
mTokensFrontBack.back->flags(tok->flags());
|
||||
mTokensFrontBack.back->linenr(tok->linenr());
|
||||
mTokensFrontBack.back->col(tok->col());
|
||||
mTokensFrontBack.back->column(tok->column());
|
||||
mTokensFrontBack.back->fileIndex(tok->fileIndex());
|
||||
}
|
||||
|
||||
|
@ -392,7 +392,7 @@ void TokenList::createTokens(const simplecpp::TokenList *tokenList)
|
|||
mTokensFrontBack.back->isKeyword(true);
|
||||
mTokensFrontBack.back->fileIndex(tok->location.fileIndex);
|
||||
mTokensFrontBack.back->linenr(tok->location.line);
|
||||
mTokensFrontBack.back->col(tok->location.col);
|
||||
mTokensFrontBack.back->column(tok->location.col);
|
||||
mTokensFrontBack.back->isExpandedMacro(!tok->macro.empty());
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ private:
|
|||
}
|
||||
|
||||
void reportErr(const ErrorLogger::ErrorMessage &msg) {
|
||||
id.push_back(msg._id);
|
||||
id.push_back(msg.id);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
class TestErrorLogger : public TestFixture {
|
||||
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:
|
||||
|
@ -66,7 +66,7 @@ private:
|
|||
const std::string plainText = "text";
|
||||
|
||||
ErrorLogger::ErrorMessage message;
|
||||
message._id = id;
|
||||
message.id = id;
|
||||
|
||||
std::string serialized = message.toString(true, idPlaceholder + plainText + idPlaceholder);
|
||||
ASSERT_EQUALS(id + plainText + id, serialized);
|
||||
|
@ -113,7 +113,7 @@ private:
|
|||
void ErrorMessageConstruct() const {
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||
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.verboseMessage());
|
||||
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false));
|
||||
|
@ -123,7 +123,7 @@ private:
|
|||
void ErrorMessageConstructLocations() const {
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs = { fooCpp5, barCpp8 };
|
||||
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.verboseMessage());
|
||||
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(false));
|
||||
|
@ -133,7 +133,7 @@ private:
|
|||
void ErrorMessageVerbose() const {
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||
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("Verbose error", msg.verboseMessage());
|
||||
ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false));
|
||||
|
@ -143,7 +143,7 @@ private:
|
|||
void ErrorMessageVerboseLocations() const {
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs = { fooCpp5, barCpp8 };
|
||||
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("Verbose error", msg.verboseMessage());
|
||||
ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(false));
|
||||
|
@ -153,7 +153,7 @@ private:
|
|||
void CustomFormat() const {
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||
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("Verbose error", msg.verboseMessage());
|
||||
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 {
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||
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("Verbose error", msg.verboseMessage());
|
||||
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
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs = { fooCpp5, barCpp8 };
|
||||
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("Verbose error", msg.verboseMessage());
|
||||
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());
|
||||
std::string message(" <error id=\"errorId\" severity=\"error\"");
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -208,8 +208,8 @@ private:
|
|||
ASSERT_EQUALS(" </errors>\n</results>", ErrorLogger::ErrorMessage::getXMLFooter());
|
||||
std::string message(" <error id=\"errorId\" severity=\"error\"");
|
||||
message += " msg=\"Programming error.\" verbose=\"Verbose error\">\n";
|
||||
message += " <location file=\"bar.cpp\" line=\"8\" column=\"0\" info=\"\\303\\244\"/>\n";
|
||||
message += " <location file=\"foo.cpp\" line=\"5\" column=\"0\"/>\n </error>";
|
||||
message += " <location file=\"bar.cpp\" line=\"8\" column=\"1\" info=\"\\303\\244\"/>\n";
|
||||
message += " <location file=\"foo.cpp\" line=\"5\" column=\"1\"/>\n </error>";
|
||||
ASSERT_EQUALS(message, msg.toXML());
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,7 @@ private:
|
|||
|
||||
// xml version 2 error message
|
||||
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>",
|
||||
msg.toXML());
|
||||
}
|
||||
|
@ -259,9 +259,9 @@ private:
|
|||
|
||||
ErrorMessage msg2;
|
||||
msg2.deserialize(msg.serialize());
|
||||
ASSERT_EQUALS("errorId", msg2._id);
|
||||
ASSERT_EQUALS(Severity::error, msg2._severity);
|
||||
ASSERT_EQUALS(true, msg2._inconclusive);
|
||||
ASSERT_EQUALS("errorId", msg2.id);
|
||||
ASSERT_EQUALS(Severity::error, msg2.severity);
|
||||
ASSERT_EQUALS(true, msg2.inconclusive);
|
||||
ASSERT_EQUALS("Programming error", msg2.shortMessage());
|
||||
ASSERT_EQUALS("Programming error", msg2.verboseMessage());
|
||||
}
|
||||
|
@ -284,8 +284,8 @@ private:
|
|||
|
||||
ErrorMessage msg2;
|
||||
msg2.deserialize(msg.serialize());
|
||||
ASSERT_EQUALS("errorId", msg2._id);
|
||||
ASSERT_EQUALS(Severity::error, msg2._severity);
|
||||
ASSERT_EQUALS("errorId", msg2.id);
|
||||
ASSERT_EQUALS(Severity::error, msg2.severity);
|
||||
ASSERT_EQUALS("Illegal character in \"foo\\001bar\"", msg2.shortMessage());
|
||||
ASSERT_EQUALS("Illegal character in \"foo\\001bar\"", msg2.verboseMessage());
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ private:
|
|||
ErrorLogger::ErrorMessage::FileLocation loc1;
|
||||
loc1.setfile(":/,");
|
||||
loc1.line = 643;
|
||||
loc1.col = 33;
|
||||
loc1.column = 33;
|
||||
loc1.setinfo("abcd:/,");
|
||||
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs{loc1};
|
||||
|
@ -303,10 +303,10 @@ private:
|
|||
|
||||
ErrorMessage msg2;
|
||||
msg2.deserialize(msg.serialize());
|
||||
ASSERT_EQUALS(":/,", msg2._callStack.front().getfile(false));
|
||||
ASSERT_EQUALS(643, msg2._callStack.front().line);
|
||||
ASSERT_EQUALS(33, msg2._callStack.front().col);
|
||||
ASSERT_EQUALS("abcd:/,", msg2._callStack.front().getinfo());
|
||||
ASSERT_EQUALS(":/,", msg2.callStack.front().getfile(false));
|
||||
ASSERT_EQUALS(643, msg2.callStack.front().line);
|
||||
ASSERT_EQUALS(33, msg2.callStack.front().column);
|
||||
ASSERT_EQUALS("abcd:/,", msg2.callStack.front().getinfo());
|
||||
}
|
||||
|
||||
void suppressUnmatchedSuppressions() {
|
||||
|
|
|
@ -26,21 +26,21 @@ class Token;
|
|||
|
||||
class givenACodeSampleToTokenize {
|
||||
private:
|
||||
Settings _settings;
|
||||
Tokenizer _tokenizer;
|
||||
Settings settings;
|
||||
Tokenizer tokenizer;
|
||||
|
||||
public:
|
||||
explicit givenACodeSampleToTokenize(const char sample[], bool createOnly = false, bool cpp = true)
|
||||
: _tokenizer(&_settings, nullptr) {
|
||||
: tokenizer(&settings, nullptr) {
|
||||
std::istringstream iss(sample);
|
||||
if (createOnly)
|
||||
_tokenizer.list.createTokens(iss, cpp ? "test.cpp" : "test.c");
|
||||
tokenizer.list.createTokens(iss, cpp ? "test.cpp" : "test.c");
|
||||
else
|
||||
_tokenizer.tokenize(iss, cpp ? "test.cpp" : "test.c");
|
||||
tokenizer.tokenize(iss, cpp ? "test.cpp" : "test.c");
|
||||
}
|
||||
|
||||
const Token* tokens() const {
|
||||
return _tokenizer.tokens();
|
||||
return tokenizer.tokens();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -48,18 +48,18 @@ public:
|
|||
class SimpleSuppressor : public ErrorLogger {
|
||||
public:
|
||||
SimpleSuppressor(Settings &settings, ErrorLogger *next)
|
||||
: _settings(settings), _next(next) {
|
||||
: settings(settings), next(next) {
|
||||
}
|
||||
virtual void reportOut(const std::string &outmsg) OVERRIDE {
|
||||
_next->reportOut(outmsg);
|
||||
next->reportOut(outmsg);
|
||||
}
|
||||
virtual void reportErr(const ErrorLogger::ErrorMessage &msg) OVERRIDE {
|
||||
if (!msg._callStack.empty() && !_settings.nomsg.isSuppressed(msg.toSuppressionsErrorMessage()))
|
||||
_next->reportErr(msg);
|
||||
if (!msg.callStack.empty() && !settings.nomsg.isSuppressed(msg.toSuppressionsErrorMessage()))
|
||||
next->reportErr(msg);
|
||||
}
|
||||
private:
|
||||
Settings &_settings;
|
||||
ErrorLogger *_next;
|
||||
Settings &settings;
|
||||
ErrorLogger *next;
|
||||
};
|
||||
|
||||
#endif // TestUtilsH
|
||||
|
|
Loading…
Reference in New Issue