forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -101,73 +101,96 @@ void IarParser::amendFilePath()
|
|||||||
m_expectFilePath = false;
|
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)
|
void IarParser::stdError(const QString &line)
|
||||||
{
|
{
|
||||||
IOutputParser::stdError(line);
|
IOutputParser::stdError(line);
|
||||||
|
|
||||||
const QString lne = rightTrimmed(line);
|
const QString lne = rightTrimmed(line);
|
||||||
|
|
||||||
QRegularExpression re;
|
if (parseErrorOrFatalErrorDetailsMessage1(lne))
|
||||||
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;
|
|
||||||
return;
|
return;
|
||||||
}
|
if (parseErrorOrFatalErrorDetailsMessage2(lne))
|
||||||
|
|
||||||
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;
|
|
||||||
return;
|
return;
|
||||||
}
|
if (parseWarningOrErrorOrFatalErrorDetailsMessage1(lne))
|
||||||
|
|
||||||
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;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (lne.isEmpty()) {
|
if (lne.isEmpty()) {
|
||||||
//
|
//
|
||||||
@@ -201,12 +224,10 @@ void IarParser::stdOutput(const QString &line)
|
|||||||
IOutputParser::stdOutput(line);
|
IOutputParser::stdOutput(line);
|
||||||
|
|
||||||
const QString lne = rightTrimmed(line);
|
const QString lne = rightTrimmed(line);
|
||||||
if (!lne.startsWith("Error in command line"))
|
|
||||||
|
if (!parseErrorInCommandLineMessage(lne))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const Task task(Task::TaskType::Error, line.trimmed(), {},
|
|
||||||
-1, Constants::TASK_CATEGORY_COMPILE);
|
|
||||||
newTask(task);
|
|
||||||
doFlush();
|
doFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -46,6 +46,11 @@ private:
|
|||||||
void amendDescription();
|
void amendDescription();
|
||||||
void amendFilePath();
|
void amendFilePath();
|
||||||
|
|
||||||
|
bool parseErrorOrFatalErrorDetailsMessage1(const QString &lne);
|
||||||
|
bool parseErrorOrFatalErrorDetailsMessage2(const QString &lne);
|
||||||
|
bool parseWarningOrErrorOrFatalErrorDetailsMessage1(const QString &lne);
|
||||||
|
bool parseErrorInCommandLineMessage(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