From f4659ecc820df356d77482f9f043be7cd66fd0e8 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 9 Feb 2017 17:02:47 +0100 Subject: [PATCH] qmake: Introduce tree structure into QmakePriFiles Change-Id: I0071c54a08d4775a34ab91e61be25f98352a5ed0 Reviewed-by: Tim Jenssen --- .../qmakeprojectmanager/qmakeparsernodes.cpp | 40 ++++++++++++++----- .../qmakeprojectmanager/qmakeparsernodes.h | 9 ++++- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp index 7cc99098a8e..66976ce1e41 100644 --- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp @@ -216,6 +216,7 @@ Q_LOGGING_CATEGORY(qmakeParse, "qtc.qmake.parsing"); uint qHash(Variable key, uint seed) { return ::qHash(static_cast(key), seed); } namespace Internal { + class QmakeEvalInput { public: @@ -293,9 +294,20 @@ FileName QmakePriFile::directoryPath() const return filePath().parentDir(); } +QmakePriFile *QmakePriFile::parent() const +{ + return m_parent; +} + +QVector QmakePriFile::children() const +{ + return m_children; +} + QmakePriFile::~QmakePriFile() { watchFolders(QSet()); + qDeleteAll(m_children); } void QmakePriFile::scheduleUpdate() @@ -419,10 +431,6 @@ void QmakePriFile::processValues(QmakePriFileEvalResult &result) void QmakePriFile::update(const Internal::QmakePriFileEvalResult &result) { - // add project file node - if (fileNodes().isEmpty()) - addNode(new FileNode(filePath(), FileType::Project, false)); - m_recursiveEnumerateFiles = result.recursiveEnumerateFiles; watchFolders(result.folders.toSet()); @@ -958,6 +966,20 @@ void QmakePriFile::changeFiles(const QString &mimeType, includeFile->deref(); } +void QmakePriFile::addChild(QmakePriFile *pf) +{ + QTC_ASSERT(!m_children.contains(pf), return); + QTC_ASSERT(!pf->parent(), return); + m_children.append(pf); + pf->setParent(this); +} + +void QmakePriFile::setParent(QmakePriFile *p) +{ + QTC_ASSERT(!m_parent, return); + m_parent = p; +} + bool QmakePriFile::setProVariable(const QString &var, const QStringList &values, const QString &scope, int flags) { if (!prepareForChange()) @@ -1748,9 +1770,9 @@ void QmakeProFile::applyEvaluate(QmakeEvalResult *evalResult) for (QmakeIncludedPriFile *priFile : tree->children) { // Loop preventation, make sure that exact same node is not in our parent chain bool loop = false; - Node *n = pn; - while ((n = n->parentFolderNode())) { - if (dynamic_cast(n) && n->filePath() == priFile->name) { + QmakePriFile *n = pn; + while ((n = n->parent())) { + if (n->filePath() == priFile->name) { loop = true; break; } @@ -1761,14 +1783,14 @@ void QmakeProFile::applyEvaluate(QmakeEvalResult *evalResult) if (priFile->proFile) { QmakePriFile *qmakePriFileNode = new QmakePriFile(m_project, this, priFile->name); - pn->addNode(qmakePriFileNode); + pn->addChild(qmakePriFileNode); qmakePriFileNode->setIncludedInExactParse( (result->state == QmakeEvalResult::EvalOk) && pn->includedInExactParse()); qmakePriFileNode->update(priFile->result); toCompare.append(qMakePair(qmakePriFileNode, priFile)); } else { QmakeProFile *qmakeProFileNode = new QmakeProFile(m_project, priFile->name); - pn->addNode(qmakeProFileNode); + pn->addChild(qmakeProFileNode); qmakeProFileNode->setIncludedInExactParse( result->exactSubdirs.contains(qmakeProFileNode->filePath()) && pn->includedInExactParse()); diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.h b/src/plugins/qmakeprojectmanager/qmakeparsernodes.h index a8010a8a5ed..7303006587f 100644 --- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.h +++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.h @@ -101,7 +101,6 @@ enum class Variable { uint qHash(Variable key, uint seed = 0); namespace Internal { - class QmakeEvalInput; class QmakeEvalResult; class QmakePriFileEvalResult; @@ -119,6 +118,9 @@ public: Utils::FileName filePath() const; Utils::FileName directoryPath() const; + QmakePriFile *parent() const; + QVector children() const; + void update(const Internal::QmakePriFileEvalResult &result); // ProjectNode interface @@ -181,8 +183,11 @@ protected: ChangeType change, Change mode = Change::Save); + void addChild(QmakePriFile *pf); private: + void setParent(QmakePriFile *p); + bool prepareForChange(); static bool ensureWriteableProFile(const QString &file); static QPair readProFile(const QString &file); @@ -206,6 +211,8 @@ private: QmakeProject *m_project = nullptr; QmakeProFile *m_qmakeProFile = nullptr; + QmakePriFile *m_parent = nullptr; + QVector m_children; std::unique_ptr m_priFileDocument;