From b53a2ff9eb3e35bb5d2010603c025103a4b5d705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 19 May 2017 17:09:49 +0200 Subject: [PATCH] Command line: Added --template=clang formatting --- cli/cmdlineparser.cpp | 2 +- lib/check.h | 2 +- lib/errorlogger.cpp | 26 +++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 03b40855f..87022f58d 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -992,7 +992,7 @@ void CmdLineParser::PrintHelp() " '{file}:{line},{severity},{id},{message}' or\n" " '{file}({line}):({severity}) {message}' or\n" " '{callstack} {message}'\n" - " Pre-defined templates: gcc, vs, edit.\n" + " Pre-defined templates: clang, gcc, vs, edit.\n" " -v, --verbose Output more detailed error information.\n" " --version Print out version number.\n" " --xml Write results in xml format to error stream (stderr).\n" diff --git a/lib/check.h b/lib/check.h index 3dcee68f8..fabda7173 100644 --- a/lib/check.h +++ b/lib/check.h @@ -169,7 +169,7 @@ protected: ErrorPath errorPath; if (!value) { errorPath.push_back(ErrorPathItem(errtok,"")); - } else if (_settings->verbose) { + } else if (_settings->verbose || _settings->outputFormat == "clang") { errorPath = value->errorPath; errorPath.push_back(ErrorPathItem(errtok,"")); } else { diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index bd9fe3348..088d727f4 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -399,7 +399,7 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string // Save this ErrorMessage in plain text. // No template is given - if (outputFormat.length() == 0) { + if (outputFormat.empty()) { std::ostringstream text; if (!_callStack.empty()) text << callStackToString(_callStack) << ": "; @@ -413,6 +413,30 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string return text.str(); } + else if (outputFormat == "clang") { + std::ostringstream text; + text << _callStack.back().getfile() + << ':' + << _callStack.back().line + << ':' + << _callStack.back().col + << ": " + << Severity::toString(_severity) + << ": " + << (verbose ? _verboseMessage : _shortMessage) + << " [" << _id << ']'; + for (std::list::const_iterator loc = _callStack.begin(); loc != _callStack.end(); ++loc) + text << std::endl + << loc->getfile() + << ':' + << loc->line + << ':' + << loc->col + << ": note: " + << (loc->getinfo().empty() ? _shortMessage : loc->getinfo()); + return text.str(); + } + // template is given. Reformat the output according to it else { std::string result = outputFormat;