diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2020-04-08 17:45:39 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2020-04-09 14:49:32 +0000 |
commit | 45ba9fcd535e4cfd5f057149b1ca4bb4dfed5bdb (patch) | |
tree | 3e3246ccf3d971e69004182007bd1b726b88b8bf /src/plugins/projectexplorer/gccparser.cpp | |
parent | fa517bd72aa21ea82072af27ce98030c4ff028f2 (diff) |
Output parsers: Replace the chaining approach
Use "flat" aggregation instead.
This is another step towards the formatter/parser merger.
Along the way, also fix some some subclasses (mostly in BareMetal) that
erroneously forwarded handled output to other parsers.
Task-number: QTCREATORBUG-22665
Change-Id: I12947349ca663d2e6bbfc99efd069d69e2b54969
Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/projectexplorer/gccparser.cpp')
-rw-r--r-- | src/plugins/projectexplorer/gccparser.cpp | 133 |
1 files changed, 63 insertions, 70 deletions
diff --git a/src/plugins/projectexplorer/gccparser.cpp b/src/plugins/projectexplorer/gccparser.cpp index a96e0b2cf2..22fc040ed0 100644 --- a/src/plugins/projectexplorer/gccparser.cpp +++ b/src/plugins/projectexplorer/gccparser.cpp @@ -59,27 +59,75 @@ GccParser::GccParser() // optional .exe postfix m_regExpGccNames.setPattern(QLatin1String(COMMAND_PATTERN)); QTC_CHECK(m_regExpGccNames.isValid()); +} + +Core::Id GccParser::id() +{ + return Core::Id("ProjectExplorer.OutputParser.Gcc"); +} + +QList<IOutputParser *> GccParser::gccParserSuite() +{ + return {new GccParser, new Internal::LldParser, new LdParser}; +} + +void GccParser::newTask(const Task &task) +{ + doFlush(); + m_currentTask = task; + m_lines = 1; +} + +void GccParser::doFlush() +{ + if (m_currentTask.isNull()) + return; + Task t = m_currentTask; + m_currentTask.clear(); + emit addTask(t, m_lines, 1); + m_lines = 0; +} - appendOutputParser(new Internal::LldParser); - appendOutputParser(new LdParser); +void GccParser::amendDescription(const QString &desc, bool monospaced) +{ + if (m_currentTask.isNull()) + return; + int start = m_currentTask.description.count() + 1; + m_currentTask.description.append(QLatin1Char('\n')); + m_currentTask.description.append(desc); + if (monospaced) { + QTextLayout::FormatRange fr; + fr.start = start; + fr.length = desc.count() + 1; + fr.format.setFont(TextEditor::TextEditorSettings::fontSettings().font()); + fr.format.setFontStyleHint(QFont::Monospace); + m_currentTask.formats.append(fr); + } + ++m_lines; + return; } -void GccParser::stdError(const QString &line) +IOutputParser::Status GccParser::doHandleLine(const QString &line, OutputFormat type) { - QString lne = rightTrimmed(line); + if (type == StdOutFormat) { + // TODO: The "flush on channel switch" logic could possibly also done centrally. + // But see MSVC with the stdout/stderr switches because of jom + doFlush(); + return Status::NotHandled; + } + + const QString lne = rightTrimmed(line); // Blacklist some lines to not handle them: if (lne.startsWith(QLatin1String("TeamBuilder ")) || lne.startsWith(QLatin1String("distcc["))) { - IOutputParser::handleLine(line, StdErrFormat); - return; + return Status::NotHandled; } // Handle misc issues: - if (lne.startsWith(QLatin1String("ERROR:")) || - lne == QLatin1String("* cpp failed")) { + if (lne.startsWith(QLatin1String("ERROR:")) || lne == QLatin1String("* cpp failed")) { newTask(CompileTask(Task::Error, lne /* description */)); - return; + return Status::InProgress; } QRegularExpressionMatch match = m_regExpGccNames.match(lne); @@ -93,7 +141,7 @@ void GccParser::stdError(const QString &line) description = description.mid(7); } newTask(CompileTask(type, description)); - return; + return Status::InProgress; } match = m_regExp.match(lne); @@ -114,7 +162,7 @@ void GccParser::stdError(const QString &line) description = match.captured(5) + description; newTask(CompileTask(type, description, absoluteFilePath(filename), lineno)); - return; + return Status::InProgress; } match = m_regExpIncluded.match(lne); @@ -123,69 +171,14 @@ void GccParser::stdError(const QString &line) lne.trimmed() /* description */, absoluteFilePath(Utils::FilePath::fromUserInput(match.captured(1))), match.captured(3).toInt() /* linenumber */)); - return; + return Status::InProgress; } else if (lne.startsWith(' ') && !m_currentTask.isNull()) { amendDescription(lne, true); - return; + return Status::InProgress; } doFlush(); - IOutputParser::handleLine(line, StdErrFormat); -} - -void GccParser::stdOutput(const QString &line) -{ - doFlush(); - IOutputParser::handleLine(line, StdOutFormat); -} - -Core::Id GccParser::id() -{ - return Core::Id("ProjectExplorer.OutputParser.Gcc"); -} - -void GccParser::newTask(const Task &task) -{ - doFlush(); - m_currentTask = task; - m_lines = 1; -} - -void GccParser::doFlush() -{ - if (m_currentTask.isNull()) - return; - Task t = m_currentTask; - m_currentTask.clear(); - emit addTask(t, m_lines, 1); - m_lines = 0; -} - -void GccParser::amendDescription(const QString &desc, bool monospaced) -{ - if (m_currentTask.isNull()) - return; - int start = m_currentTask.description.count() + 1; - m_currentTask.description.append(QLatin1Char('\n')); - m_currentTask.description.append(desc); - if (monospaced) { - QTextLayout::FormatRange fr; - fr.start = start; - fr.length = desc.count() + 1; - fr.format.setFont(TextEditor::TextEditorSettings::fontSettings().font()); - fr.format.setFontStyleHint(QFont::Monospace); - m_currentTask.formats.append(fr); - } - ++m_lines; - return; -} - -void GccParser::handleLine(const QString &line, OutputFormat type) -{ - if (type == StdOutFormat) - stdOutput(line); - else - stdError(line); + return Status::NotHandled; } // Unit tests: @@ -1130,7 +1123,7 @@ void ProjectExplorerPlugin::testGccOutputParsers_data() void ProjectExplorerPlugin::testGccOutputParsers() { OutputParserTester testbench; - testbench.appendOutputParser(new GccParser); + testbench.setLineParsers(GccParser::gccParserSuite()); QFETCH(QString, input); QFETCH(OutputParserTester::Channel, inputChannel); QFETCH(Tasks, tasks); |