BareMetal: Minimize nested blocks of code in KEIL parser

Change-Id: I420eb67683413730f67fce9dd103487380296548
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Denis Shienkov
2019-10-15 12:00:38 +03:00
parent e90a48e639
commit 1e54d45139

View File

@@ -92,34 +92,32 @@ bool KeilParser::parseArmWarningOrErrorDetailsMessage(const QString &lne)
{ {
const QRegularExpression re("^\"(.+)\", line (\\d+).*:\\s+(Warning|Error):(\\s+|.+)([#|L].+)$"); const QRegularExpression re("^\"(.+)\", line (\\d+).*:\\s+(Warning|Error):(\\s+|.+)([#|L].+)$");
const QRegularExpressionMatch match = re.match(lne); const QRegularExpressionMatch match = re.match(lne);
if (match.hasMatch()) { if (!match.hasMatch())
enum CaptureIndex { FilePathIndex = 1, LineNumberIndex, return false;
MessageTypeIndex, MessageNoteIndex, DescriptionIndex }; enum CaptureIndex { FilePathIndex = 1, LineNumberIndex,
const Utils::FilePath fileName = Utils::FilePath::fromUserInput( MessageTypeIndex, MessageNoteIndex, DescriptionIndex };
match.captured(FilePathIndex)); const Utils::FilePath fileName = Utils::FilePath::fromUserInput(
const int lineno = match.captured(LineNumberIndex).toInt(); match.captured(FilePathIndex));
const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); const int lineno = match.captured(LineNumberIndex).toInt();
const QString descr = match.captured(DescriptionIndex); const Task::TaskType type = taskType(match.captured(MessageTypeIndex));
const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE); const QString descr = match.captured(DescriptionIndex);
newTask(task); const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE);
return true; newTask(task);
} return true;
return false;
} }
bool KeilParser::parseArmErrorOrFatalErorrMessage(const QString &lne) bool KeilParser::parseArmErrorOrFatalErorrMessage(const QString &lne)
{ {
const QRegularExpression re("^(Error|Fatal error):\\s(.+)$"); const QRegularExpression re("^(Error|Fatal error):\\s(.+)$");
const QRegularExpressionMatch match = re.match(lne); const QRegularExpressionMatch match = re.match(lne);
if (match.hasMatch()) { if (!match.hasMatch())
enum CaptureIndex { MessageTypeIndex = 1, DescriptionIndex }; return false;
const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); enum CaptureIndex { MessageTypeIndex = 1, DescriptionIndex };
const QString descr = match.captured(DescriptionIndex); const Task::TaskType type = taskType(match.captured(MessageTypeIndex));
const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE); const QString descr = match.captured(DescriptionIndex);
newTask(task); const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE);
return true; newTask(task);
} return true;
return false;
} }
// MCS51 compiler specific parsers. // 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 QRegularExpression re("^\\*{3} (WARNING|ERROR) (\\w+) IN LINE (\\d+) OF (.+\\.\\S+): (.+)$");
const QRegularExpressionMatch match = re.match(lne); const QRegularExpressionMatch match = re.match(lne);
if (match.hasMatch()) { if (!match.hasMatch())
enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, LineNumberIndex, return false;
FilePathIndex, MessageTextIndex }; enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, LineNumberIndex,
const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); FilePathIndex, MessageTextIndex };
const int lineno = match.captured(LineNumberIndex).toInt(); const Task::TaskType type = taskType(match.captured(MessageTypeIndex));
const Utils::FilePath fileName = Utils::FilePath::fromUserInput( const int lineno = match.captured(LineNumberIndex).toInt();
match.captured(FilePathIndex)); const Utils::FilePath fileName = Utils::FilePath::fromUserInput(
const QString descr = QString("%1: %2").arg(match.captured(MessageCodeIndex), match.captured(FilePathIndex));
match.captured(MessageTextIndex)); const QString descr = QString("%1: %2").arg(match.captured(MessageCodeIndex),
const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE); match.captured(MessageTextIndex));
newTask(task); const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE);
return true; newTask(task);
} return true;
return false;
} }
bool KeilParser::parseMcs51WarningOrErrorDetailsMessage2(const QString &lne) bool KeilParser::parseMcs51WarningOrErrorDetailsMessage2(const QString &lne)
{ {
const QRegularExpression re("^\\*{3} (WARNING|ERROR) (#\\w+) IN (\\d+) \\((.+), LINE \\d+\\): (.+)$"); const QRegularExpression re("^\\*{3} (WARNING|ERROR) (#\\w+) IN (\\d+) \\((.+), LINE \\d+\\): (.+)$");
const QRegularExpressionMatch match = re.match(lne); const QRegularExpressionMatch match = re.match(lne);
if (match.hasMatch()) { if (!match.hasMatch())
enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, LineNumberIndex, return false;
FilePathIndex, MessageTextIndex }; enum CaptureIndex { MessageTypeIndex = 1, MessageCodeIndex, LineNumberIndex,
const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); FilePathIndex, MessageTextIndex };
const int lineno = match.captured(LineNumberIndex).toInt(); const Task::TaskType type = taskType(match.captured(MessageTypeIndex));
const Utils::FilePath fileName = Utils::FilePath::fromUserInput( const int lineno = match.captured(LineNumberIndex).toInt();
match.captured(FilePathIndex)); const Utils::FilePath fileName = Utils::FilePath::fromUserInput(
const QString descr = QString("%1: %2").arg(match.captured(MessageCodeIndex), match.captured(FilePathIndex));
match.captured(MessageTextIndex)); const QString descr = QString("%1: %2").arg(match.captured(MessageCodeIndex),
const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE); match.captured(MessageTextIndex));
newTask(task); const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE);
return true; newTask(task);
} return true;
return false;
} }
bool KeilParser::parseMcs51WarningOrFatalErrorMessage(const QString &lne) bool KeilParser::parseMcs51WarningOrFatalErrorMessage(const QString &lne)
{ {
const QRegularExpression re("^\\*{3} (WARNING|FATAL ERROR) (.+)$"); const QRegularExpression re("^\\*{3} (WARNING|FATAL ERROR) (.+)$");
const QRegularExpressionMatch match = re.match(lne); const QRegularExpressionMatch match = re.match(lne);
if (match.hasMatch()) { if (!match.hasMatch())
enum CaptureIndex { MessageTypeIndex = 1, MessageDescriptionIndex }; return false;
const Task::TaskType type = taskType(match.captured(MessageTypeIndex)); enum CaptureIndex { MessageTypeIndex = 1, MessageDescriptionIndex };
const QString descr = match.captured(MessageDescriptionIndex); const Task::TaskType type = taskType(match.captured(MessageTypeIndex));
const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE); const QString descr = match.captured(MessageDescriptionIndex);
newTask(task); const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE);
return true; newTask(task);
} return true;
return false;
} }
bool KeilParser::parseMcs51FatalErrorMessage2(const QString &lne) bool KeilParser::parseMcs51FatalErrorMessage2(const QString &lne)
{ {
const QRegularExpression re("^(A|C)51 FATAL[ |-]ERROR"); const QRegularExpression re("^(A|C)51 FATAL[ |-]ERROR");
const QRegularExpressionMatch match = re.match(lne); const QRegularExpressionMatch match = re.match(lne);
if (match.hasMatch()) { if (!match.hasMatch())
const QString key = match.captured(1); return false;
QString descr; const QString key = match.captured(1);
if (key == QLatin1Char('A')) QString descr;
descr = "Assembler fatal error"; if (key == QLatin1Char('A'))
else if (key == QLatin1Char('C')) descr = "Assembler fatal error";
descr = "Compiler fatal error"; else if (key == QLatin1Char('C'))
const Task task(Task::TaskType::Error, descr, {}, -1, descr = "Compiler fatal error";
Constants::TASK_CATEGORY_COMPILE); const Task task(Task::TaskType::Error, descr, {}, -1,
newTask(task); Constants::TASK_CATEGORY_COMPILE);
return true; newTask(task);
} return true;
return false;
} }
void KeilParser::stdError(const QString &line) void KeilParser::stdError(const QString &line)