From 83c6a4d9220dbd1c34ec38b37139471ab279935c Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Fri, 25 Oct 2019 12:00:39 +0300 Subject: [PATCH] BareMetal: Improve IAR parser code a bit It is makes sense to move a handing code of each regexp to the separate method to simplify maintenance. Change-Id: I59d9c23ec1c1c4dabb8de8eb295353b4df072a33 Reviewed-by: Christian Kandeler --- src/plugins/baremetal/iarewparser.cpp | 145 +++++++++++++++----------- src/plugins/baremetal/iarewparser.h | 5 + 2 files changed, 88 insertions(+), 62 deletions(-) diff --git a/src/plugins/baremetal/iarewparser.cpp b/src/plugins/baremetal/iarewparser.cpp index 50e25706ca6..93e97ac056a 100644 --- a/src/plugins/baremetal/iarewparser.cpp +++ b/src/plugins/baremetal/iarewparser.cpp @@ -101,73 +101,96 @@ void IarParser::amendFilePath() m_expectFilePath = false; } +bool IarParser::parseErrorOrFatalErrorDetailsMessage1(const QString &lne) +{ + const QRegularExpression re("^(Error|Fatal error)\\[(.+)\\]:\\s(.+)\\s\\[(.+)$"); + const QRegularExpressionMatch match = re.match(lne); + if (!match.hasMatch()) + return false; + enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, + DescriptionIndex, FilepathBeginIndex }; + const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); + const QString descr = QString("[%1]: %2").arg(match.captured(MessageCodeIndex), + match.captured(DescriptionIndex)); + // This task has a file path, but this patch are split on + // some lines, which will be received later. + const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE); + newTask(task); + // Prepare first part of a file path. + QString firstPart = match.captured(FilepathBeginIndex); + firstPart.remove("referenced from "); + m_filePathParts.push_back(firstPart); + m_expectFilePath = true; + m_expectSnippet = false; + return true; +} + +bool IarParser::parseErrorOrFatalErrorDetailsMessage2(const QString &lne) +{ + const QRegularExpression re("^.*(Error|Fatal error)\\[(.+)\\]:\\s(.+)$"); + const QRegularExpressionMatch match = re.match(lne); + if (!match.hasMatch()) + return false; + enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, + DescriptionIndex }; + const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); + const QString descr = QString("[%1]: %2").arg(match.captured(MessageCodeIndex), + match.captured(DescriptionIndex)); + // This task has not a file path. The description details + // will be received later on the next lines. + const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE); + newTask(task); + m_expectSnippet = true; + m_expectFilePath = false; + m_expectDescription = false; + return true; +} + +bool IarParser::parseWarningOrErrorOrFatalErrorDetailsMessage1(const QString &lne) +{ + const QRegularExpression re("^\"(.+)\",(\\d+)?\\s+(Warning|Error|Fatal error)\\[(.+)\\].+$"); + const QRegularExpressionMatch match = re.match(lne); + if (!match.hasMatch()) + return false; + enum CaptureIndex { FilePathIndex = 1, LineNumberIndex, + MessageTypeIndex, MessageCodeIndex }; + const Utils::FilePath fileName = Utils::FilePath::fromUserInput( + match.captured(FilePathIndex)); + const int lineno = match.captured(LineNumberIndex).toInt(); + const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); + // A full description will be received later on next lines. + const Task task(type, {}, fileName, lineno, Constants::TASK_CATEGORY_COMPILE); + newTask(task); + const QString firstPart = QString("[%1]: ").arg(match.captured(MessageCodeIndex)); + m_descriptionParts.append(firstPart); + m_expectDescription = true; + m_expectSnippet = false; + m_expectFilePath = false; + return true; +} + +bool IarParser::parseErrorInCommandLineMessage(const QString &lne) +{ + if (!lne.startsWith("Error in command line")) + return false; + const Task task(Task::TaskType::Error, lne.trimmed(), {}, + -1, Constants::TASK_CATEGORY_COMPILE); + newTask(task); + return true; +} + void IarParser::stdError(const QString &line) { IOutputParser::stdError(line); const QString lne = rightTrimmed(line); - QRegularExpression re; - QRegularExpressionMatch match; - - re.setPattern("^(Error|Fatal error)\\[(.+)\\]:\\s(.+)\\s\\[(.+)$"); - match = re.match(lne); - if (match.hasMatch()) { - enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, - DescriptionIndex, FilepathBeginIndex }; - const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); - const QString descr = QString("[%1]: %2").arg(match.captured(MessageCodeIndex), - match.captured(DescriptionIndex)); - // This task has a file path, but this patch are split on - // some lines, which will be received later. - const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE); - newTask(task); - // Prepare first part of a file path. - QString firstPart = match.captured(FilepathBeginIndex); - firstPart.remove("referenced from "); - m_filePathParts.push_back(firstPart); - m_expectFilePath = true; - m_expectSnippet = false; + if (parseErrorOrFatalErrorDetailsMessage1(lne)) return; - } - - re.setPattern("^.*(Error|Fatal error)\\[(.+)\\]:\\s(.+)$"); - match = re.match(lne); - if (match.hasMatch()) { - enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, - DescriptionIndex }; - const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); - const QString descr = QString("[%1]: %2").arg(match.captured(MessageCodeIndex), - match.captured(DescriptionIndex)); - // This task has not a file path. The description details - // will be received later on the next lines. - const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE); - newTask(task); - m_expectSnippet = true; - m_expectFilePath = false; - m_expectDescription = false; + if (parseErrorOrFatalErrorDetailsMessage2(lne)) return; - } - - re.setPattern("^\"(.+)\",(\\d+)?\\s+(Warning|Error|Fatal error)\\[(.+)\\].+$"); - match = re.match(lne); - if (match.hasMatch()) { - enum CaptureIndex { FilePathIndex = 1, LineNumberIndex, - MessageTypeIndex, MessageCodeIndex }; - const Utils::FilePath fileName = Utils::FilePath::fromUserInput( - match.captured(FilePathIndex)); - const int lineno = match.captured(LineNumberIndex).toInt(); - const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); - // A full description will be received later on next lines. - const Task task(type, {}, fileName, lineno, Constants::TASK_CATEGORY_COMPILE); - newTask(task); - const QString firstPart = QString("[%1]: ").arg(match.captured(MessageCodeIndex)); - m_descriptionParts.append(firstPart); - m_expectDescription = true; - m_expectSnippet = false; - m_expectFilePath = false; + if (parseWarningOrErrorOrFatalErrorDetailsMessage1(lne)) return; - } if (lne.isEmpty()) { // @@ -201,12 +224,10 @@ void IarParser::stdOutput(const QString &line) IOutputParser::stdOutput(line); const QString lne = rightTrimmed(line); - if (!lne.startsWith("Error in command line")) + + if (!parseErrorInCommandLineMessage(lne)) return; - const Task task(Task::TaskType::Error, line.trimmed(), {}, - -1, Constants::TASK_CATEGORY_COMPILE); - newTask(task); doFlush(); } diff --git a/src/plugins/baremetal/iarewparser.h b/src/plugins/baremetal/iarewparser.h index 48348d4f6fa..d3fc2d1454f 100644 --- a/src/plugins/baremetal/iarewparser.h +++ b/src/plugins/baremetal/iarewparser.h @@ -46,6 +46,11 @@ private: void amendDescription(); void amendFilePath(); + bool parseErrorOrFatalErrorDetailsMessage1(const QString &lne); + bool parseErrorOrFatalErrorDetailsMessage2(const QString &lne); + bool parseWarningOrErrorOrFatalErrorDetailsMessage1(const QString &lne); + bool parseErrorInCommandLineMessage(const QString &lne); + void stdError(const QString &line) final; void stdOutput(const QString &line) final; void doFlush() final;