Skip to content
Snippets Groups Projects
Commit 9cfb8fa9 authored by Christoph Cullmann's avatar Christoph Cullmann 🍨
Browse files

Fix includedDefinitions, handle definition change in context switch

AcceptedPublic

Fix includedDefinitions, handle definition change in context switch.
They were missing, see PHP/HTML.
I cleaned up the code a bit to just use QVector, no need for a queue, the order is anyways arbitrary (but stable).

BUG: 397659

Differential Revision: https://phabricator.kde.org/D14952
parent 3ebb3c09
No related branches found
No related tags found
No related merge requests found
......@@ -192,16 +192,21 @@ private Q_SLOTS:
void testIncludedDefinitions()
{
auto def = m_repo.definitionForName(QLatin1String("C++"));
auto def = m_repo.definitionForName(QLatin1String("PHP (HTML)"));
QVERIFY(def.isValid());
auto defs = def.includedDefinitions();
const QStringList expectedDefinitionNames = {
QStringLiteral("ISO C++"),
QStringLiteral("GCCExtensions"),
QStringLiteral("Doxygen"),
QStringLiteral("PHP/PHP"),
QStringLiteral("Alerts"),
QStringLiteral("Modelines")
QStringLiteral("CSS/PHP"),
QStringLiteral("JavaScript/PHP"),
QStringLiteral("Doxygen"),
QStringLiteral("Modelines"),
QStringLiteral("HTML"),
QStringLiteral("CSS"),
QStringLiteral("SQL (MySQL)"),
QStringLiteral("JavaScript")
};
QStringList definitionNames;
for (auto d : defs) {
......
......@@ -34,7 +34,6 @@
#include <QFile>
#include <QHash>
#include <QJsonObject>
#include <QQueue>
#include <QStringList>
#include <QVector>
#include <QXmlStreamReader>
......@@ -241,22 +240,27 @@ QVector<Definition> Definition::includedDefinitions() const
{
d->load();
QVector<Definition> definitions;
QQueue<Definition> queue;
queue.enqueue(*this);
// init worklist and result used as guard with this definition
QVector<Definition> queue{*this};
QVector<Definition> definitions{*this};
while (!queue.isEmpty()) {
const auto definition = queue.dequeue();
definitions.push_back(definition);
// Iterate all context rules to find associated Definitions. This will
// automatically catch other Definitions referenced with IncludeRuldes.
foreach (const auto & context, definition.d->contexts) {
foreach (const auto &rule, context->rules()) {
if ((!definitions.contains(rule->definition())) &&
(!queue.contains(rule->definition())))
{
queue.enqueue(rule->definition());
// automatically catch other Definitions referenced with IncludeRuldes or ContextSwitch.
const auto definition = queue.takeLast();
for (const auto & context : definition.d->contexts) {
for (const auto &rule : context->rules()) {
// handle include rules like inclusion
if (!definitions.contains(rule->definition())) {
queue.push_back(rule->definition());
definitions.push_back(rule->definition());
}
// handle context switch context inclusion
if (auto switchContext = rule->context().context()) {
if (!definitions.contains(switchContext->definition())) {
queue.push_back(switchContext->definition());
definitions.push_back(switchContext->definition());
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment