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 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)