forked from qt-creator/qt-creator
CMakeParser: Get rid of the std::optional holding a container
There is no need to enclose a container inside the std::optional, as if the container is empty, it indicates that no values are in. Holding optional for a container class may lead to the confusing behavior, that the optional itself isn't empty, but holding an empty container. Instead, introduce a m_callStackDetected flag. Task-number: QTCREATORBUG-29965 Change-Id: If8d43e0633286c076e3da436eb61114aa68f4c35 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -129,20 +129,20 @@ OutputLineParser::Result CMakeOutputParser::handleLine(const QString &line, Outp
|
|||||||
m_errorOrWarningLine.function = match.captured(4);
|
m_errorOrWarningLine.function = match.captured(4);
|
||||||
|
|
||||||
return {Status::InProgress, linkSpecs};
|
return {Status::InProgress, linkSpecs};
|
||||||
}
|
|
||||||
else if (trimmedLine.startsWith(QLatin1String(" ")) && !m_lastTask.isNull() && !m_callStack) {
|
|
||||||
if (m_skippedFirstEmptyLine)
|
|
||||||
m_lastTask.details.append(QString());
|
|
||||||
m_lastTask.details.append(trimmedLine.mid(2));
|
|
||||||
return Status::InProgress;
|
|
||||||
} else if (trimmedLine.startsWith(QLatin1String(" ")) && !m_lastTask.isNull()) {
|
} else if (trimmedLine.startsWith(QLatin1String(" ")) && !m_lastTask.isNull()) {
|
||||||
match = m_sourceLineAndFunction.match(trimmedLine);
|
if (m_callStackDetected) {
|
||||||
if (match.hasMatch()) {
|
match = m_sourceLineAndFunction.match(trimmedLine);
|
||||||
CallStackLine stackLine;
|
if (match.hasMatch()) {
|
||||||
stackLine.file = absoluteFilePath(resolvePath(match.captured(1)));
|
CallStackLine stackLine;
|
||||||
stackLine.line = match.captured(2).toInt();
|
stackLine.file = absoluteFilePath(resolvePath(match.captured(1)));
|
||||||
stackLine.function = match.captured(3);
|
stackLine.line = match.captured(2).toInt();
|
||||||
m_callStack.value() << stackLine;
|
stackLine.function = match.captured(3);
|
||||||
|
m_callStack << stackLine;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (m_skippedFirstEmptyLine)
|
||||||
|
m_lastTask.details.append(QString());
|
||||||
|
m_lastTask.details.append(trimmedLine.mid(2));
|
||||||
}
|
}
|
||||||
return {Status::InProgress};
|
return {Status::InProgress};
|
||||||
} else if (trimmedLine.endsWith(QLatin1String("in cmake code at"))) {
|
} else if (trimmedLine.endsWith(QLatin1String("in cmake code at"))) {
|
||||||
@@ -160,7 +160,7 @@ OutputLineParser::Result CMakeOutputParser::handleLine(const QString &line, Outp
|
|||||||
// Do not pass on lines starting with "-- " or "* ". Those are typical CMake output
|
// Do not pass on lines starting with "-- " or "* ". Those are typical CMake output
|
||||||
return Status::InProgress;
|
return Status::InProgress;
|
||||||
} else if (trimmedLine.startsWith("Call Stack (most recent call first):")) {
|
} else if (trimmedLine.startsWith("Call Stack (most recent call first):")) {
|
||||||
m_callStack = QList<CallStackLine>();
|
m_callStackDetected = true;
|
||||||
return {Status::InProgress};
|
return {Status::InProgress};
|
||||||
}
|
}
|
||||||
return Status::NotHandled;
|
return Status::NotHandled;
|
||||||
@@ -214,19 +214,19 @@ void CMakeOutputParser::flush()
|
|||||||
t.summary = t.details.takeFirst();
|
t.summary = t.details.takeFirst();
|
||||||
m_lines += t.details.count();
|
m_lines += t.details.count();
|
||||||
|
|
||||||
if (m_callStack.has_value() && !m_callStack.value().isEmpty()) {
|
if (!m_callStack.isEmpty()) {
|
||||||
t.file = m_callStack.value().last().file;
|
t.file = m_callStack.last().file;
|
||||||
t.line = m_callStack.value().last().line;
|
t.line = m_callStack.last().line;
|
||||||
|
|
||||||
LinkSpecs specs;
|
LinkSpecs specs;
|
||||||
t.details << QString();
|
t.details << QString();
|
||||||
t.details << Tr::tr("Call stack:");
|
t.details << Tr::tr("Call stack:");
|
||||||
m_lines += 2;
|
m_lines += 2;
|
||||||
|
|
||||||
m_callStack->push_front(m_errorOrWarningLine);
|
m_callStack.push_front(m_errorOrWarningLine);
|
||||||
|
|
||||||
int offset = t.details.join('\n').size();
|
int offset = t.details.join('\n').size();
|
||||||
Utils::reverseForeach(m_callStack.value(), [&](const auto &line) {
|
Utils::reverseForeach(m_callStack, [&](const auto &line) {
|
||||||
const QString fileAndLine = QString("%1:%2").arg(line.file.path()).arg(line.line);
|
const QString fileAndLine = QString("%1:%2").arg(line.file.path()).arg(line.line);
|
||||||
const QString completeLine = QString(" %1%2").arg(fileAndLine).arg(line.function);
|
const QString completeLine = QString(" %1%2").arg(fileAndLine).arg(line.function);
|
||||||
|
|
||||||
@@ -247,7 +247,8 @@ void CMakeOutputParser::flush()
|
|||||||
scheduleTask(t, m_lines, 1);
|
scheduleTask(t, m_lines, 1);
|
||||||
m_lines = 0;
|
m_lines = 0;
|
||||||
|
|
||||||
m_callStack.reset();
|
m_callStack.clear();
|
||||||
|
m_callStackDetected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // CMakeProjectManager
|
} // CMakeProjectManager
|
||||||
|
@@ -49,7 +49,8 @@ private:
|
|||||||
int line = -1;
|
int line = -1;
|
||||||
QString function;
|
QString function;
|
||||||
};
|
};
|
||||||
std::optional<QList<CallStackLine>> m_callStack;
|
QList<CallStackLine> m_callStack;
|
||||||
|
bool m_callStackDetected = false;
|
||||||
CallStackLine m_errorOrWarningLine;
|
CallStackLine m_errorOrWarningLine;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user