ClangParser: Use QRegularExpression

Change-Id: I08e9ee73fef0cffd7c31508838b104d0894fbfdb
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Daniel Teske
2014-09-22 17:31:02 +02:00
parent 30955a9058
commit cb6c9d2b73
2 changed files with 27 additions and 22 deletions

View File

@@ -47,7 +47,7 @@ static const char * const FILE_PATTERN = "(<command line>|([A-Za-z]:)?[^:]+\\.[^
ClangParser::ClangParser() : ClangParser::ClangParser() :
m_commandRegExp(QLatin1String("^clang(\\+\\+)?: +(fatal +)?(warning|error|note): (.*)$")), m_commandRegExp(QLatin1String("^clang(\\+\\+)?: +(fatal +)?(warning|error|note): (.*)$")),
m_inLineRegExp(QLatin1String("^In (.*) included from (.*):(\\d+):$")), m_inLineRegExp(QLatin1String("^In (.*?) included from (.*?):(\\d+):$")),
m_messageRegExp(QLatin1Char('^') + QLatin1String(FILE_PATTERN) + QLatin1String("(:(\\d+):\\d+|\\((\\d+)\\) *): +(fatal +)?(error|warning|note): (.*)$")), m_messageRegExp(QLatin1Char('^') + QLatin1String(FILE_PATTERN) + QLatin1String("(:(\\d+):\\d+|\\((\\d+)\\) *): +(fatal +)?(error|warning|note): (.*)$")),
m_summaryRegExp(QLatin1String("^\\d+ (warnings?|errors?)( and \\d (warnings?|errors?))? generated.$")), m_summaryRegExp(QLatin1String("^\\d+ (warnings?|errors?)( and \\d (warnings?|errors?))? generated.$")),
m_codesignRegExp(QLatin1String("^Code ?Sign error: (.*)$")), m_codesignRegExp(QLatin1String("^Code ?Sign error: (.*)$")),
@@ -61,16 +61,18 @@ ClangParser::ClangParser() :
void ClangParser::stdError(const QString &line) void ClangParser::stdError(const QString &line)
{ {
const QString lne = rightTrimmed(line); const QString lne = rightTrimmed(line);
if (m_summaryRegExp.indexIn(lne) > -1) { QRegularExpressionMatch match = m_summaryRegExp.match(lne);
if (match.hasMatch()) {
doFlush(); doFlush();
m_expectSnippet = false; m_expectSnippet = false;
return; return;
} }
if (m_commandRegExp.indexIn(lne) > -1) { match = m_commandRegExp.match(lne);
if (match.hasMatch()) {
m_expectSnippet = true; m_expectSnippet = true;
Task task(taskType(m_commandRegExp.cap(3)), Task task(taskType(match.captured(3)),
m_commandRegExp.cap(4), match.captured(4),
Utils::FileName(), /* filename */ Utils::FileName(), /* filename */
-1, /* line */ -1, /* line */
Constants::TASK_CATEGORY_COMPILE); Constants::TASK_CATEGORY_COMPILE);
@@ -78,35 +80,38 @@ void ClangParser::stdError(const QString &line)
return; return;
} }
if (m_inLineRegExp.indexIn(lne) > -1) { match = m_inLineRegExp.match(lne);
if (match.hasMatch()) {
m_expectSnippet = true; m_expectSnippet = true;
newTask(Task(Task::Unknown, newTask(Task(Task::Unknown,
lne.trimmed(), lne.trimmed(),
Utils::FileName::fromUserInput(m_inLineRegExp.cap(2)), /* filename */ Utils::FileName::fromUserInput(match.captured(2)), /* filename */
m_inLineRegExp.cap(3).toInt(), /* line */ match.captured(3).toInt(), /* line */
Constants::TASK_CATEGORY_COMPILE)); Constants::TASK_CATEGORY_COMPILE));
return; return;
} }
if (m_messageRegExp.indexIn(lne) > -1) { match = m_messageRegExp.match(lne);
if (match.hasMatch()) {
m_expectSnippet = true; m_expectSnippet = true;
bool ok = false; bool ok = false;
int lineNo = m_messageRegExp.cap(4).toInt(&ok); int lineNo = match.captured(4).toInt(&ok);
if (!ok) if (!ok)
lineNo = m_messageRegExp.cap(5).toInt(&ok); lineNo = match.captured(5).toInt(&ok);
Task task(taskType(m_messageRegExp.cap(7)), Task task(taskType(match.captured(7)),
m_messageRegExp.cap(8), match.captured(8),
Utils::FileName::fromUserInput(m_messageRegExp.cap(1)), /* filename */ Utils::FileName::fromUserInput(match.captured(1)), /* filename */
lineNo, lineNo,
Core::Id(Constants::TASK_CATEGORY_COMPILE)); Core::Id(Constants::TASK_CATEGORY_COMPILE));
newTask(task); newTask(task);
return; return;
} }
if (m_codesignRegExp.indexIn(lne) > -1) { match = m_codesignRegExp.match(lne);
if (match.hasMatch()) {
m_expectSnippet = true; m_expectSnippet = true;
Task task(Task::Error, Task task(Task::Error,
m_codesignRegExp.cap(1), match.captured(1),
Utils::FileName(), Utils::FileName(),
-1, -1,
Core::Id(Constants::TASK_CATEGORY_COMPILE)); Core::Id(Constants::TASK_CATEGORY_COMPILE));

View File

@@ -33,7 +33,7 @@
#include "gccparser.h" #include "gccparser.h"
#include "task.h" #include "task.h"
#include <QRegExp> #include <QRegularExpression>
namespace ProjectExplorer { namespace ProjectExplorer {
@@ -46,11 +46,11 @@ public:
void stdError(const QString &line); void stdError(const QString &line);
private: private:
QRegExp m_commandRegExp; QRegularExpression m_commandRegExp;
QRegExp m_inLineRegExp; QRegularExpression m_inLineRegExp;
QRegExp m_messageRegExp; QRegularExpression m_messageRegExp;
QRegExp m_summaryRegExp; QRegularExpression m_summaryRegExp;
QRegExp m_codesignRegExp; QRegularExpression m_codesignRegExp;
bool m_expectSnippet; bool m_expectSnippet;
}; };