From 1e54d45139519a66de5e06767310245ee0f7d728 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Tue, 15 Oct 2019 12:00:38 +0300 Subject: [PATCH] BareMetal: Minimize nested blocks of code in KEIL parser Change-Id: I420eb67683413730f67fce9dd103487380296548 Reviewed-by: hjk --- src/plugins/baremetal/keilparser.cpp | 138 +++++++++++++-------------- 1 file changed, 66 insertions(+), 72 deletions(-) diff --git a/src/plugins/baremetal/keilparser.cpp b/src/plugins/baremetal/keilparser.cpp index 2025cb22b6b..b41a71c6f2c 100644 --- a/src/plugins/baremetal/keilparser.cpp +++ b/src/plugins/baremetal/keilparser.cpp @@ -92,34 +92,32 @@ bool KeilParser::parseArmWarningOrErrorDetailsMessage(const QString &lne) { const QRegularExpression re("^\"(.+)\", line (\\d+).*:\\s+(Warning|Error):(\\s+|.+)([#|L].+)$"); const QRegularExpressionMatch match = re.match(lne); - if (match.hasMatch()) { - enum CaptureIndex { FilePathIndex = 1, LineNumberIndex, - MessageTypeIndex, MessageNoteIndex, DescriptionIndex }; - 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)); - const QString descr = match.captured(DescriptionIndex); - const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE); - newTask(task); - return true; - } - return false; + if (!match.hasMatch()) + return false; + enum CaptureIndex { FilePathIndex = 1, LineNumberIndex, + MessageTypeIndex, MessageNoteIndex, DescriptionIndex }; + 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)); + const QString descr = match.captured(DescriptionIndex); + const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE); + newTask(task); + return true; } bool KeilParser::parseArmErrorOrFatalErorrMessage(const QString &lne) { const QRegularExpression re("^(Error|Fatal error):\\s(.+)$"); const QRegularExpressionMatch match = re.match(lne); - if (match.hasMatch()) { - enum CaptureIndex { MessageTypeIndex = 1, DescriptionIndex }; - const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); - const QString descr = match.captured(DescriptionIndex); - const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE); - newTask(task); - return true; - } - return false; + if (!match.hasMatch()) + return false; + enum CaptureIndex { MessageTypeIndex = 1, DescriptionIndex }; + const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); + const QString descr = match.captured(DescriptionIndex); + const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE); + newTask(task); + return true; } // MCS51 compiler specific parsers. @@ -128,74 +126,70 @@ bool KeilParser::parseMcs51WarningOrErrorDetailsMessage1(const QString &lne) { const QRegularExpression re("^\\*{3} (WARNING|ERROR) (\\w+) IN LINE (\\d+) OF (.+\\.\\S+): (.+)$"); const QRegularExpressionMatch match = re.match(lne); - if (match.hasMatch()) { - enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, LineNumberIndex, - FilePathIndex, MessageTextIndex }; - const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); - const int lineno = match.captured(LineNumberIndex).toInt(); - const Utils::FilePath fileName = Utils::FilePath::fromUserInput( - match.captured(FilePathIndex)); - const QString descr = QString("%1: %2").arg(match.captured(MessageCodeIndex), - match.captured(MessageTextIndex)); - const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE); - newTask(task); - return true; - } - return false; + if (!match.hasMatch()) + return false; + enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, LineNumberIndex, + FilePathIndex, MessageTextIndex }; + const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); + const int lineno = match.captured(LineNumberIndex).toInt(); + const Utils::FilePath fileName = Utils::FilePath::fromUserInput( + match.captured(FilePathIndex)); + const QString descr = QString("%1: %2").arg(match.captured(MessageCodeIndex), + match.captured(MessageTextIndex)); + const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE); + newTask(task); + return true; } bool KeilParser::parseMcs51WarningOrErrorDetailsMessage2(const QString &lne) { const QRegularExpression re("^\\*{3} (WARNING|ERROR) (#\\w+) IN (\\d+) \\((.+), LINE \\d+\\): (.+)$"); const QRegularExpressionMatch match = re.match(lne); - if (match.hasMatch()) { - enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, LineNumberIndex, - FilePathIndex, MessageTextIndex }; - const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); - const int lineno = match.captured(LineNumberIndex).toInt(); - const Utils::FilePath fileName = Utils::FilePath::fromUserInput( - match.captured(FilePathIndex)); - const QString descr = QString("%1: %2").arg(match.captured(MessageCodeIndex), - match.captured(MessageTextIndex)); - const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE); - newTask(task); - return true; - } - return false; + if (!match.hasMatch()) + return false; + enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, LineNumberIndex, + FilePathIndex, MessageTextIndex }; + const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); + const int lineno = match.captured(LineNumberIndex).toInt(); + const Utils::FilePath fileName = Utils::FilePath::fromUserInput( + match.captured(FilePathIndex)); + const QString descr = QString("%1: %2").arg(match.captured(MessageCodeIndex), + match.captured(MessageTextIndex)); + const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE); + newTask(task); + return true; } bool KeilParser::parseMcs51WarningOrFatalErrorMessage(const QString &lne) { const QRegularExpression re("^\\*{3} (WARNING|FATAL ERROR) (.+)$"); const QRegularExpressionMatch match = re.match(lne); - if (match.hasMatch()) { - enum CaptureIndex { MessageTypeIndex = 1, MessageDescriptionIndex }; - const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); - const QString descr = match.captured(MessageDescriptionIndex); - const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE); - newTask(task); - return true; - } - return false; + if (!match.hasMatch()) + return false; + enum CaptureIndex { MessageTypeIndex = 1, MessageDescriptionIndex }; + const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); + const QString descr = match.captured(MessageDescriptionIndex); + const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE); + newTask(task); + return true; } bool KeilParser::parseMcs51FatalErrorMessage2(const QString &lne) { const QRegularExpression re("^(A|C)51 FATAL[ |-]ERROR"); const QRegularExpressionMatch match = re.match(lne); - if (match.hasMatch()) { - const QString key = match.captured(1); - QString descr; - if (key == QLatin1Char('A')) - descr = "Assembler fatal error"; - else if (key == QLatin1Char('C')) - descr = "Compiler fatal error"; - const Task task(Task::TaskType::Error, descr, {}, -1, - Constants::TASK_CATEGORY_COMPILE); - newTask(task); - return true; - } - return false; + if (!match.hasMatch()) + return false; + const QString key = match.captured(1); + QString descr; + if (key == QLatin1Char('A')) + descr = "Assembler fatal error"; + else if (key == QLatin1Char('C')) + descr = "Compiler fatal error"; + const Task task(Task::TaskType::Error, descr, {}, -1, + Constants::TASK_CATEGORY_COMPILE); + newTask(task); + return true; } void KeilParser::stdError(const QString &line)