File: cache.h

package info (click to toggle)
kdevelop 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 73,508 kB
  • sloc: cpp: 291,803; python: 4,322; javascript: 3,518; sh: 1,316; ansic: 703; xml: 414; php: 95; lisp: 66; makefile: 31; sed: 12
file content (117 lines) | stat: -rw-r--r-- 3,594 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
    SPDX-FileCopyrightText: 2013 Sven Brauch <svenbrauch@googlemail.com>
    SPDX-FileCopyrightText: 2014 Denis Steckelmacher <steckdenis@yahoo.fr>

    SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/

#ifndef __CACHE_H__
#define __CACHE_H__

#include "duchainexport.h"
#include <serialization/indexedstring.h>
#include <util/path.h>

#include <QHash>
#include <QString>
#include <QFileInfoList>
#include <QList>
#include <QSet>
#include <QMutex>

class QStringList;

namespace QmlJS
{

/**
 * Cache for values that may be slow to compute (search paths, things
 * involving QStandardPaths, etc)
 */
class KDEVQMLJSDUCHAIN_EXPORT Cache
{
private:
    Cache();

public:
    static Cache& instance();

    /**
     * List of the paths in which the modules will be looked for
     */
    KDevelop::Path::List libraryPaths(const KDevelop::IndexedString& baseFile) const;

    /**
     * Path corresponding to a module name
     *
     * The path returned can either be the one of a module file shipped with
     * kdev-qmljs, or the path of a directory containing the module components
     * (one .qml file per component, and possibly .so files if the module has
     * native components)
     *
     * @param version If not null, the file being looked for is "uri_version.qml".
     *                If null, then the untouched uri is used for searching.
     */
    QString modulePath(const KDevelop::IndexedString& baseFile, const QString& uri,
                       const QString& version = QStringLiteral("2.0"));

    /**
     * Return the list of the paths of the given files.
     *
     * Files having a name ending in ".so" are replaced with the path of their
     * qmlplugindump dump.
     */
    QStringList getFileNames(const QFileInfoList& fileInfos);

    /**
     * Set the custom include directories list of a file
     */
    void setFileCustomIncludes(const KDevelop::IndexedString& file,
                               const KDevelop::Path::List& dirs);

    /**
     * Add a dependency between two URLs
     */
    void addDependency(const KDevelop::IndexedString& file, const KDevelop::IndexedString& dependency);

    /**
     * List of the files that depend on a given URL
     */
    QList<KDevelop::IndexedString> filesThatDependOn(const KDevelop::IndexedString& file);

    /**
     * List of the dependencies of a file
     */
    QList<KDevelop::IndexedString> dependencies(const KDevelop::IndexedString& file);

    /**
     * Return whether a file is up to date (all its dependencies are up to date
     * and the file has been freshly parsed)
     */
    bool isUpToDate(const KDevelop::IndexedString& file);
    void setUpToDate(const KDevelop::IndexedString& file, bool upToDate);

private:
    KDevelop::Path::List libraryPaths_internal(const KDevelop::IndexedString& baseFile) const;

    struct PluginDumpExecutable {
        QString executable;
        QString quickVersion;       // Version of QtQuick that should be imported when this qmlplugindump is used

        PluginDumpExecutable(const QString& e, const QString &v)
        : executable(e), quickVersion(v)
        {}
    };

    mutable QMutex m_mutex;
    QHash<QString, QString> m_modulePaths;
    QList<PluginDumpExecutable> m_pluginDumpExecutables;
    QHash<KDevelop::IndexedString, QSet<KDevelop::IndexedString>> m_dependees;
    QHash<KDevelop::IndexedString, QSet<KDevelop::IndexedString>> m_dependencies;
    QHash<KDevelop::IndexedString, bool> m_isUpToDate;
    QHash<KDevelop::IndexedString, KDevelop::Path::List> m_includeDirs;
};

}

#endif