2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2010-07-16 11:18:30 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Denis Mingulov
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-07-16 11:18:30 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-07-16 11:18:30 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-07-16 11:18:30 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-07-16 11:18:30 +02:00
|
|
|
|
|
|
|
|
#include "classviewparser.h"
|
|
|
|
|
#include "classviewconstants.h"
|
|
|
|
|
#include "classviewutils.h"
|
|
|
|
|
|
|
|
|
|
// cplusplus shared library. the same folder (cplusplus)
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <cplusplus/Symbol.h>
|
2010-07-16 11:18:30 +02:00
|
|
|
|
|
|
|
|
// other
|
2014-09-15 00:12:27 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2010-07-16 11:18:30 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
2017-12-06 10:27:27 +01:00
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
2010-07-16 11:18:30 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStandardItem>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QSet>
|
2019-07-05 13:43:54 +02:00
|
|
|
#include <QElapsedTimer>
|
2010-07-16 11:18:30 +02:00
|
|
|
|
|
|
|
|
enum { debug = false };
|
|
|
|
|
|
2013-09-05 11:46:07 +02:00
|
|
|
using namespace ProjectExplorer;
|
2019-11-15 18:42:11 +01:00
|
|
|
using namespace Utils;
|
2013-09-05 11:46:07 +02:00
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
namespace ClassView {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
// ----------------------------- ParserPrivate ---------------------------------
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-05-24 17:35:14 +02:00
|
|
|
\class ParserPrivate
|
|
|
|
|
\brief The ParserPrivate class defines private class data for the Parser
|
|
|
|
|
class.
|
2010-07-16 11:18:30 +02:00
|
|
|
\sa Parser
|
|
|
|
|
*/
|
2013-05-24 17:35:14 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class Parser
|
|
|
|
|
\brief The Parser class parses C++ information. Multithreading is supported.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void Parser::treeDataUpdate(QSharedPointer<QStandardItem> result)
|
|
|
|
|
|
|
|
|
|
Emits a signal about a tree data update.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-07-06 17:40:54 +02:00
|
|
|
class ParserPrivate
|
2010-07-16 11:18:30 +02:00
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
public:
|
2010-07-16 11:18:30 +02:00
|
|
|
//! Get document from documentList
|
|
|
|
|
CPlusPlus::Document::Ptr document(const QString &fileName) const;
|
|
|
|
|
|
2021-02-12 12:43:04 +01:00
|
|
|
struct DocumentCache {
|
|
|
|
|
unsigned treeRevision = 0;
|
2021-02-16 16:04:50 +01:00
|
|
|
ParserTreeItem::ConstPtr tree;
|
2021-02-12 12:43:04 +01:00
|
|
|
CPlusPlus::Document::Ptr document;
|
|
|
|
|
};
|
2021-02-12 11:09:17 +01:00
|
|
|
struct ProjectCache {
|
|
|
|
|
unsigned treeRevision = 0;
|
2021-02-16 16:04:50 +01:00
|
|
|
ParserTreeItem::ConstPtr tree;
|
2021-02-12 11:09:17 +01:00
|
|
|
QStringList fileList;
|
|
|
|
|
};
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-12 12:43:04 +01:00
|
|
|
// Project file path to its cached data
|
|
|
|
|
QHash<QString, DocumentCache> m_documentCache;
|
2021-02-12 11:09:17 +01:00
|
|
|
// Project file path to its cached data
|
|
|
|
|
QHash<QString, ProjectCache> m_projectCache;
|
2010-07-16 11:18:30 +02:00
|
|
|
|
|
|
|
|
// other
|
|
|
|
|
//! List for files which has to be parsed
|
|
|
|
|
QSet<QString> fileList;
|
|
|
|
|
|
|
|
|
|
//! Flat mode
|
2018-11-04 22:40:59 +01:00
|
|
|
bool flatMode = false;
|
2010-07-16 11:18:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CPlusPlus::Document::Ptr ParserPrivate::document(const QString &fileName) const
|
|
|
|
|
{
|
2021-02-12 12:43:04 +01:00
|
|
|
return m_documentCache.value(fileName).document;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------- Parser ---------------------------------
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Constructs the parser object.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
Parser::Parser(QObject *parent)
|
|
|
|
|
: QObject(parent),
|
2021-02-18 15:02:54 +01:00
|
|
|
d(new ParserPrivate())
|
2010-07-16 11:18:30 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Destructs the parser object.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
Parser::~Parser()
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
delete d;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Switches to flat mode (without subprojects) if \a flat returns \c true.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Parser::setFlatMode(bool flatMode)
|
|
|
|
|
{
|
2011-07-06 17:40:54 +02:00
|
|
|
if (flatMode == d->flatMode)
|
2010-07-16 11:18:30 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// change internal
|
2011-07-06 17:40:54 +02:00
|
|
|
d->flatMode = flatMode;
|
2010-07-16 11:18:30 +02:00
|
|
|
|
|
|
|
|
// regenerate and resend current tree
|
2021-02-08 12:22:21 +01:00
|
|
|
requestCurrentState();
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Parses the class and produces a new tree.
|
|
|
|
|
|
|
|
|
|
\sa addProject
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
ParserTreeItem::ConstPtr Parser::parse()
|
|
|
|
|
{
|
2021-02-15 17:11:11 +01:00
|
|
|
QScopedPointer<QElapsedTimer> timer;
|
|
|
|
|
if (debug) {
|
|
|
|
|
timer.reset(new QElapsedTimer());
|
|
|
|
|
timer->start();
|
|
|
|
|
}
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-16 16:04:50 +01:00
|
|
|
QHash<SymbolInformation, ParserTreeItem::ConstPtr> projectTrees;
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-15 17:11:11 +01:00
|
|
|
// TODO: move a call to SessionManager::projects() out of this thread
|
2017-03-01 17:53:15 +01:00
|
|
|
for (const Project *prj : SessionManager::projects()) {
|
2021-02-15 17:11:11 +01:00
|
|
|
const QString prjName(prj->displayName());
|
|
|
|
|
const QString prjType = prj->projectFilePath().toString();
|
|
|
|
|
const SymbolInformation inf(prjName, prjType);
|
2017-04-05 17:32:36 +02:00
|
|
|
|
2021-02-16 16:04:50 +01:00
|
|
|
ParserTreeItem::ConstPtr item = addFlatTree(prj);
|
2021-02-15 17:11:11 +01:00
|
|
|
if (item.isNull())
|
|
|
|
|
continue;
|
|
|
|
|
projectTrees.insert(inf, item);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-16 16:04:50 +01:00
|
|
|
ParserTreeItem::ConstPtr rootItem(new ParserTreeItem(projectTrees));
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-15 17:11:11 +01:00
|
|
|
if (debug) {
|
|
|
|
|
qDebug() << "Class View:" << QDateTime::currentDateTime().toString()
|
|
|
|
|
<< "Parsed in " << timer->elapsed() << "msecs.";
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-15 17:11:11 +01:00
|
|
|
return rootItem;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Parses the project with the \a projectId and adds the documents from the
|
|
|
|
|
\a fileList to the project. Updates the internal cached tree for this
|
|
|
|
|
project.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-16 16:04:50 +01:00
|
|
|
ParserTreeItem::ConstPtr Parser::getParseProjectTree(const QStringList &fileList,
|
2010-07-16 11:18:30 +02:00
|
|
|
const QString &projectId)
|
|
|
|
|
{
|
|
|
|
|
//! \todo Way to optimize - for documentUpdate - use old cached project and subtract
|
|
|
|
|
//! changed files only (old edition), and add curent editions
|
2021-02-15 17:11:11 +01:00
|
|
|
|
|
|
|
|
QList<ParserTreeItem::ConstPtr> docTrees;
|
2010-07-16 11:18:30 +02:00
|
|
|
unsigned revision = 0;
|
2021-02-15 17:11:11 +01:00
|
|
|
for (const QString &file : fileList) {
|
2011-07-06 17:40:54 +02:00
|
|
|
const CPlusPlus::Document::Ptr &doc = d->document(file);
|
2010-07-16 11:18:30 +02:00
|
|
|
if (doc.isNull())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
revision += doc->revision();
|
|
|
|
|
|
2021-02-15 17:11:11 +01:00
|
|
|
const ParserTreeItem::ConstPtr docTree = getCachedOrParseDocumentTree(doc);
|
|
|
|
|
if (docTree.isNull())
|
2010-07-16 11:18:30 +02:00
|
|
|
continue;
|
2021-02-15 17:11:11 +01:00
|
|
|
docTrees.append(docTree);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-16 16:04:50 +01:00
|
|
|
ParserTreeItem::ConstPtr item = ParserTreeItem::mergeTrees(Utils::FilePath::fromString(projectId), docTrees);
|
2021-02-15 17:11:11 +01:00
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
// update the cache
|
|
|
|
|
if (!projectId.isEmpty()) {
|
2021-02-12 11:09:17 +01:00
|
|
|
ParserPrivate::ProjectCache &projectCache = d->m_projectCache[projectId];
|
|
|
|
|
projectCache.tree = item;
|
|
|
|
|
projectCache.treeRevision = revision;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Gets the project with \a projectId from the cache if it is valid or parses
|
|
|
|
|
the project and adds the documents from the \a fileList to the project.
|
|
|
|
|
Updates the internal cached tree for this project.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-16 16:04:50 +01:00
|
|
|
ParserTreeItem::ConstPtr Parser::getCachedOrParseProjectTree(const QStringList &fileList,
|
2021-02-15 17:11:11 +01:00
|
|
|
const QString &projectId)
|
2010-07-16 11:18:30 +02:00
|
|
|
{
|
2021-02-12 11:09:17 +01:00
|
|
|
const auto it = d->m_projectCache.constFind(projectId);
|
|
|
|
|
if (it != d->m_projectCache.constEnd() && !it.value().tree.isNull()) {
|
2010-07-16 11:18:30 +02:00
|
|
|
// calculate project's revision
|
|
|
|
|
unsigned revision = 0;
|
2021-02-12 11:09:17 +01:00
|
|
|
for (const QString &file : fileList) {
|
2011-07-06 17:40:54 +02:00
|
|
|
const CPlusPlus::Document::Ptr &doc = d->document(file);
|
2010-07-16 11:18:30 +02:00
|
|
|
if (doc.isNull())
|
|
|
|
|
continue;
|
|
|
|
|
revision += doc->revision();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if even revision is the same, return cached project
|
2021-02-12 12:43:04 +01:00
|
|
|
if (revision == it.value().treeRevision)
|
2021-02-12 11:09:17 +01:00
|
|
|
return it.value().tree;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return getParseProjectTree(fileList, projectId);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Parses the document \a doc if it is in the project files and adds a tree to
|
|
|
|
|
the internal storage. Updates the internal cached tree for this document.
|
|
|
|
|
|
|
|
|
|
\sa parseDocument
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
ParserTreeItem::ConstPtr Parser::getParseDocumentTree(const CPlusPlus::Document::Ptr &doc)
|
|
|
|
|
{
|
|
|
|
|
if (doc.isNull())
|
|
|
|
|
return ParserTreeItem::ConstPtr();
|
|
|
|
|
|
|
|
|
|
const QString &fileName = doc->fileName();
|
2011-07-06 17:40:54 +02:00
|
|
|
if (!d->fileList.contains(fileName))
|
2010-07-16 11:18:30 +02:00
|
|
|
return ParserTreeItem::ConstPtr();
|
|
|
|
|
|
2021-02-16 16:04:50 +01:00
|
|
|
ParserTreeItem::ConstPtr itemPtr = ParserTreeItem::parseDocument(doc);
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-12 12:43:04 +01:00
|
|
|
d->m_documentCache.insert(fileName, { doc->revision(), itemPtr, doc } );
|
2010-07-16 11:18:30 +02:00
|
|
|
return itemPtr;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Gets the document \a doc from the cache or parses it if it is in the project
|
|
|
|
|
files and adds a tree to the internal storage.
|
|
|
|
|
|
|
|
|
|
\sa parseDocument
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
ParserTreeItem::ConstPtr Parser::getCachedOrParseDocumentTree(const CPlusPlus::Document::Ptr &doc)
|
|
|
|
|
{
|
|
|
|
|
if (doc.isNull())
|
|
|
|
|
return ParserTreeItem::ConstPtr();
|
|
|
|
|
|
|
|
|
|
const QString &fileName = doc->fileName();
|
2021-02-15 10:47:21 +01:00
|
|
|
const auto it = d->m_documentCache.constFind(fileName);
|
|
|
|
|
if (it != d->m_documentCache.constEnd() && !it.value().tree.isNull()
|
|
|
|
|
&& it.value().treeRevision == doc->revision()) {
|
|
|
|
|
return it.value().tree;
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
2011-09-19 10:02:45 +02:00
|
|
|
return getParseDocumentTree(doc);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
2021-02-18 15:02:54 +01:00
|
|
|
Parses the document list \a docs if they are in the project files and adds a tree to
|
2013-05-24 17:35:14 +02:00
|
|
|
the internal storage.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-18 15:02:54 +01:00
|
|
|
void Parser::updateDocuments(const QList<CPlusPlus::Document::Ptr> &docs)
|
2010-07-16 11:18:30 +02:00
|
|
|
{
|
2021-02-18 15:02:54 +01:00
|
|
|
for (const CPlusPlus::Document::Ptr &doc: docs) {
|
|
|
|
|
const QString &name = doc->fileName();
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-18 15:02:54 +01:00
|
|
|
// if it is external file (not in any of our projects)
|
|
|
|
|
if (!d->fileList.contains(name))
|
|
|
|
|
continue;
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-18 15:02:54 +01:00
|
|
|
getParseDocumentTree(doc);
|
|
|
|
|
}
|
|
|
|
|
requestCurrentState();
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Specifies the files that must be allowed for the parsing as a \a fileList.
|
|
|
|
|
Files outside of this list will not be in any tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Parser::setFileList(const QStringList &fileList)
|
|
|
|
|
{
|
2019-11-15 18:42:11 +01:00
|
|
|
d->fileList = Utils::toSet(fileList);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Removes the files defined in the \a fileList from the parsing.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Parser::removeFiles(const QStringList &fileList)
|
|
|
|
|
{
|
2017-02-21 12:33:35 +01:00
|
|
|
if (fileList.isEmpty())
|
2010-07-16 11:18:30 +02:00
|
|
|
return;
|
|
|
|
|
|
2021-02-12 10:32:54 +01:00
|
|
|
for (const QString &name : fileList) {
|
2011-07-06 17:40:54 +02:00
|
|
|
d->fileList.remove(name);
|
2021-02-12 12:43:04 +01:00
|
|
|
d->m_documentCache.remove(name);
|
2021-02-12 11:09:17 +01:00
|
|
|
d->m_projectCache.remove(name);
|
|
|
|
|
for (auto it = d->m_projectCache.begin(); it != d->m_projectCache.end(); ++it)
|
|
|
|
|
it.value().fileList.removeOne(name);
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
2021-02-17 18:36:11 +01:00
|
|
|
requestCurrentState();
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Fully resets the internal state of the code parser to \a snapshot.
|
|
|
|
|
*/
|
2010-07-16 11:18:30 +02:00
|
|
|
void Parser::resetData(const CPlusPlus::Snapshot &snapshot)
|
|
|
|
|
{
|
2021-02-15 10:47:21 +01:00
|
|
|
d->m_projectCache.clear();
|
|
|
|
|
d->m_documentCache.clear();
|
|
|
|
|
for (auto it = snapshot.begin(); it != snapshot.end(); ++it)
|
|
|
|
|
d->m_documentCache[it.key().toString()].document = it.value();
|
2010-07-16 11:18:30 +02:00
|
|
|
|
|
|
|
|
// recalculate file list
|
2019-12-17 14:07:53 +01:00
|
|
|
FilePaths fileList;
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-15 17:11:11 +01:00
|
|
|
// TODO: move a call to SessionManager::projects() out of this thread
|
2017-03-01 17:53:15 +01:00
|
|
|
for (const Project *prj : SessionManager::projects())
|
|
|
|
|
fileList += prj->files(Project::SourceFiles);
|
2019-11-15 18:42:11 +01:00
|
|
|
setFileList(Utils::transform(fileList, &FilePath::toString));
|
2010-07-16 11:18:30 +02:00
|
|
|
|
2021-02-08 12:22:21 +01:00
|
|
|
requestCurrentState();
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Fully resets the internal state of the code parser to the current state.
|
|
|
|
|
|
|
|
|
|
\sa resetData
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Parser::resetDataToCurrentState()
|
|
|
|
|
{
|
|
|
|
|
// get latest data
|
2015-02-15 23:13:28 +02:00
|
|
|
resetData(CppTools::CppModelManager::instance()->snapshot());
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:35:14 +02:00
|
|
|
/*!
|
|
|
|
|
Requests to emit a signal with the current tree state.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
void Parser::requestCurrentState()
|
|
|
|
|
{
|
2021-02-16 01:37:49 +01:00
|
|
|
// TODO: we need to have a fresh SessionManager data here, which we could pass to parse()
|
2021-02-16 14:01:16 +01:00
|
|
|
emit treeRegenerated(parse());
|
2010-07-16 11:18:30 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-15 17:11:11 +01:00
|
|
|
// TODO: don't use Project class in this thread
|
2017-04-05 17:32:36 +02:00
|
|
|
QStringList Parser::getAllFiles(const Project *project)
|
2013-12-04 13:46:12 +01:00
|
|
|
{
|
2017-04-05 17:32:36 +02:00
|
|
|
if (!project)
|
2021-02-12 11:09:17 +01:00
|
|
|
return {};
|
2013-12-04 13:46:12 +01:00
|
|
|
|
2021-02-12 11:09:17 +01:00
|
|
|
const QString projectPath = project->projectFilePath().toString();
|
2021-02-12 12:43:04 +01:00
|
|
|
const auto it = d->m_projectCache.constFind(projectPath);
|
|
|
|
|
if (it != d->m_projectCache.constEnd())
|
|
|
|
|
return it.value().fileList;
|
2013-12-04 13:46:12 +01:00
|
|
|
|
2021-02-12 11:09:17 +01:00
|
|
|
const QStringList fileList = Utils::transform(project->files(Project::SourceFiles),
|
|
|
|
|
&FilePath::toString);
|
|
|
|
|
d->m_projectCache[projectPath].fileList = fileList;
|
2013-12-04 13:46:12 +01:00
|
|
|
return fileList;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-15 17:11:11 +01:00
|
|
|
// TODO: don't use Project class in this thread
|
2021-02-16 16:04:50 +01:00
|
|
|
ParserTreeItem::ConstPtr Parser::addFlatTree(const Project *project)
|
2013-12-04 13:46:12 +01:00
|
|
|
{
|
2017-04-05 17:32:36 +02:00
|
|
|
if (!project)
|
2021-02-15 17:11:11 +01:00
|
|
|
return {};
|
2013-12-04 13:46:12 +01:00
|
|
|
|
2021-02-15 17:11:11 +01:00
|
|
|
const QStringList fileList = getAllFiles(project);
|
|
|
|
|
if (fileList.isEmpty())
|
|
|
|
|
return {};
|
2013-12-04 13:46:12 +01:00
|
|
|
|
2021-02-15 17:11:11 +01:00
|
|
|
return getCachedOrParseProjectTree(fileList, project->projectFilePath().toString());
|
2013-12-04 13:46:12 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-16 11:18:30 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ClassView
|