diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2019-10-25 12:00:39 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2019-10-28 09:43:09 +0000 |
commit | 83c6a4d9220dbd1c34ec38b37139471ab279935c (patch) | |
tree | b4b7c3c9c13b068cf8c87d6c2f224ba5deaf95a8 /src/plugins/baremetal/iarewparser.cpp | |
parent | d6b29a89ec980e415cf4c3bdadd32ee850917e05 (diff) | |
download | qt-creator-83c6a4d9220dbd1c34ec38b37139471ab279935c.tar.gz |
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 <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/baremetal/iarewparser.cpp')
-rw-r--r-- | src/plugins/baremetal/iarewparser.cpp | 145 |
1 files changed, 83 insertions, 62 deletions
diff --git a/src/plugins/baremetal/iarewparser.cpp b/src/plugins/baremetal/iarewparser.cpp index 50e25706ca..93e97ac056 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(); } |