forked from qt-creator/qt-creator
BareMetal: Improve KEIL 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: Ibd2c999f2ea48f51dca2ccfcbaada47e4c34e8a6 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -86,19 +86,12 @@ void KeilParser::amendDescription(const QString &desc)
|
|||||||
++m_lines;
|
++m_lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeilParser::stdError(const QString &line)
|
// ARM compiler specific parsers.
|
||||||
|
|
||||||
|
bool KeilParser::parseArmWarningOrErrorDetailsMessage(const QString &lne)
|
||||||
{
|
{
|
||||||
IOutputParser::stdError(line);
|
const QRegularExpression re("^\"(.+)\", line (\\d+).*:\\s+(Warning|Error):(\\s+|.+)([#|L].+)$");
|
||||||
|
const QRegularExpressionMatch match = re.match(lne);
|
||||||
const QString lne = rightTrimmed(line);
|
|
||||||
|
|
||||||
QRegularExpression re;
|
|
||||||
QRegularExpressionMatch match;
|
|
||||||
|
|
||||||
// ARM compiler specific patterns.
|
|
||||||
|
|
||||||
re.setPattern("^\"(.+)\", line (\\d+).*:\\s+(Warning|Error):(\\s+|.+)([#|L].+)$");
|
|
||||||
match = re.match(lne);
|
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
enum CaptureIndex { FilePathIndex = 1, LineNumberIndex,
|
enum CaptureIndex { FilePathIndex = 1, LineNumberIndex,
|
||||||
MessageTypeIndex, MessageNoteIndex, DescriptionIndex };
|
MessageTypeIndex, MessageNoteIndex, DescriptionIndex };
|
||||||
@@ -109,19 +102,113 @@ void KeilParser::stdError(const QString &line)
|
|||||||
const QString descr = match.captured(DescriptionIndex);
|
const QString descr = match.captured(DescriptionIndex);
|
||||||
const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE);
|
const Task task(type, descr, fileName, lineno, Constants::TASK_CATEGORY_COMPILE);
|
||||||
newTask(task);
|
newTask(task);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
re.setPattern("^(Error|Fatal error):\\s(.+)$");
|
bool KeilParser::parseArmErrorOrFatalErorrMessage(const QString &lne)
|
||||||
match = re.match(lne);
|
{
|
||||||
|
const QRegularExpression re("^(Error|Fatal error):\\s(.+)$");
|
||||||
|
const QRegularExpressionMatch match = re.match(lne);
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
enum CaptureIndex { MessageTypeIndex = 1, DescriptionIndex };
|
enum CaptureIndex { MessageTypeIndex = 1, DescriptionIndex };
|
||||||
const Task::TaskType type = taskType(match.captured(MessageTypeIndex));
|
const Task::TaskType type = taskType(match.captured(MessageTypeIndex));
|
||||||
const QString descr = match.captured(DescriptionIndex);
|
const QString descr = match.captured(DescriptionIndex);
|
||||||
const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE);
|
const Task task(type, descr, {}, -1, Constants::TASK_CATEGORY_COMPILE);
|
||||||
newTask(task);
|
newTask(task);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MCS51 compiler specific parsers.
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KeilParser::parseMcs51FatalErrorMessage1(const QString &lne)
|
||||||
|
{
|
||||||
|
const QRegularExpression re("^\\*{3} (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeilParser::stdError(const QString &line)
|
||||||
|
{
|
||||||
|
IOutputParser::stdError(line);
|
||||||
|
|
||||||
|
const QString lne = rightTrimmed(line);
|
||||||
|
|
||||||
|
// Check for ARM compiler specific patterns.
|
||||||
|
if (parseArmWarningOrErrorDetailsMessage(lne))
|
||||||
|
return;
|
||||||
|
if (parseArmErrorOrFatalErorrMessage(lne))
|
||||||
|
return;
|
||||||
|
|
||||||
if (lne.startsWith(QLatin1Char(' '))) {
|
if (lne.startsWith(QLatin1Char(' '))) {
|
||||||
amendDescription(lne);
|
amendDescription(lne);
|
||||||
@@ -137,65 +224,14 @@ void KeilParser::stdOutput(const QString &line)
|
|||||||
|
|
||||||
const QString lne = rightTrimmed(line);
|
const QString lne = rightTrimmed(line);
|
||||||
|
|
||||||
QRegularExpression re;
|
// Check for MSC51 compiler specific patterns.
|
||||||
QRegularExpressionMatch match;
|
const bool parsed = parseMcs51WarningOrErrorDetailsMessage1(lne)
|
||||||
|
|| parseMcs51WarningOrErrorDetailsMessage2(lne);
|
||||||
// MSC51 compiler specific patterns.
|
if (!parsed) {
|
||||||
|
if (parseMcs51FatalErrorMessage1(lne))
|
||||||
re.setPattern("^\\*{3} (WARNING|ERROR) (\\w+) IN LINE (\\d+) OF (.+\\.\\S+): (.+)$");
|
return;
|
||||||
match = re.match(lne);
|
if (parseMcs51FatalErrorMessage2(lne))
|
||||||
if (match.hasMatch()) {
|
return;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
re.setPattern("^\\*{3} (WARNING|ERROR) (#\\w+) IN (\\d+) \\((.+), LINE \\d+\\): (.+)$");
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
re.setPattern("^\\*{3} (FATAL ERROR) (.+)$");
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
re.setPattern("^(A|C)51 FATAL[ |-]ERROR");
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lne.startsWith(QLatin1Char(' '))) {
|
if (lne.startsWith(QLatin1Char(' '))) {
|
||||||
|
@@ -45,6 +45,16 @@ private:
|
|||||||
void newTask(const ProjectExplorer::Task &task);
|
void newTask(const ProjectExplorer::Task &task);
|
||||||
void amendDescription(const QString &desc);
|
void amendDescription(const QString &desc);
|
||||||
|
|
||||||
|
// ARM compiler specific parsers.
|
||||||
|
bool parseArmWarningOrErrorDetailsMessage(const QString &lne);
|
||||||
|
bool parseArmErrorOrFatalErorrMessage(const QString &lne);
|
||||||
|
|
||||||
|
// MCS51 compiler specific parsers.
|
||||||
|
bool parseMcs51WarningOrErrorDetailsMessage1(const QString &lne);
|
||||||
|
bool parseMcs51WarningOrErrorDetailsMessage2(const QString &lne);
|
||||||
|
bool parseMcs51FatalErrorMessage1(const QString &lne);
|
||||||
|
bool parseMcs51FatalErrorMessage2(const QString &lne);
|
||||||
|
|
||||||
void stdError(const QString &line) final;
|
void stdError(const QString &line) final;
|
||||||
void stdOutput(const QString &line) final;
|
void stdOutput(const QString &line) final;
|
||||||
void doFlush() final;
|
void doFlush() final;
|
||||||
|
Reference in New Issue
Block a user