File indexing completed on 2024-05-19 15:44:54

0001 /*
0002     SPDX-FileCopyrightText: 2013 Olivier de Gaalon <olivier.jg@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef CLANGINDEX_H
0008 #define CLANGINDEX_H
0009 
0010 #include "clanghelpers.h"
0011 
0012 #include "clangprivateexport.h"
0013 #include <serialization/indexedstring.h>
0014 
0015 #include <util/path.h>
0016 
0017 #include <QReadWriteLock>
0018 #include <QSharedPointer>
0019 
0020 #include <clang-c/Index.h>
0021 
0022 class ClangParsingEnvironment;
0023 class ClangPCH;
0024 
0025 class KDEVCLANGPRIVATE_EXPORT ClangIndex
0026 {
0027 public:
0028     ClangIndex();
0029     ~ClangIndex();
0030 
0031     CXIndex index() const;
0032 
0033     /**
0034      * @returns the existing ClangPCH for @p environment
0035      *
0036      * The PCH is created using @p environment if it doesn't exist
0037      * This function is thread safe.
0038      */
0039     QSharedPointer<const ClangPCH> pch(const ClangParsingEnvironment& environment);
0040 
0041     /**
0042      * Gets the currently pinned TU for @p url
0043      *
0044      * If the currently pinned TU does not import @p url, @p url is returned
0045      */
0046     KDevelop::IndexedString translationUnitForUrl(const KDevelop::IndexedString& url);
0047 
0048     /**
0049      * Pin @p tu as the translation unit to use when parsing @p url
0050      */
0051     void pinTranslationUnitForUrl(const KDevelop::IndexedString& tu, const KDevelop::IndexedString& url);
0052 
0053     /**
0054      * Unpin any translation unit currently pinned for @p url
0055      */
0056     void unpinTranslationUnitForUrl(const KDevelop::IndexedString& url);
0057 
0058 private:
0059     CXIndex m_index;
0060 
0061     QReadWriteLock m_pchLock;
0062     QHash<KDevelop::Path, QSharedPointer<const ClangPCH>> m_pch;
0063 
0064     QMutex m_mappingMutex;
0065     QHash<KDevelop::IndexedString, KDevelop::IndexedString> m_tuForUrl;
0066 };
0067 
0068 #endif //CLANGINDEX_H