LCOV - code coverage report
Current view: top level - clang/tools/extra/clangd - ClangdUnitStore.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 0 1 0.0 %
Date: 2017-09-14 15:23:50 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===--- ClangdUnitStore.h - A container of CppFiles -------------*-C++-*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===---------------------------------------------------------------------===//
       9             : 
      10             : #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDUNITSTORE_H
      11             : #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDUNITSTORE_H
      12             : 
      13             : #include <mutex>
      14             : 
      15             : #include "ClangdUnit.h"
      16             : #include "GlobalCompilationDatabase.h"
      17             : #include "Path.h"
      18             : #include "clang/Tooling/CompilationDatabase.h"
      19             : 
      20             : namespace clang {
      21             : namespace clangd {
      22             : 
      23             : /// Thread-safe mapping from FileNames to CppFile.
      24           0 : class CppFileCollection {
      25             : public:
      26             :   std::shared_ptr<CppFile>
      27             :   getOrCreateFile(PathRef File, PathRef ResourceDir,
      28             :                   GlobalCompilationDatabase &CDB,
      29             :                   std::shared_ptr<PCHContainerOperations> PCHs,
      30             :                   IntrusiveRefCntPtr<vfs::FileSystem> VFS) {
      31             :     std::lock_guard<std::mutex> Lock(Mutex);
      32             : 
      33             :     auto It = OpenedFiles.find(File);
      34             :     if (It == OpenedFiles.end()) {
      35             :       auto Command = getCompileCommand(CDB, File, ResourceDir);
      36             : 
      37             :       It = OpenedFiles
      38             :                .try_emplace(File, CppFile::Create(File, std::move(Command),
      39             :                                                   std::move(PCHs)))
      40             :                .first;
      41             :     }
      42             :     return It->second;
      43             :   }
      44             : 
      45             :   struct RecreateResult {
      46             :     /// A CppFile, stored in this CppFileCollection for the corresponding
      47             :     /// filepath after calling recreateFileIfCompileCommandChanged.
      48             :     std::shared_ptr<CppFile> FileInCollection;
      49             :     /// If a new CppFile had to be created to account for changed
      50             :     /// CompileCommand, a previous CppFile instance will be returned in this
      51             :     /// field.
      52             :     std::shared_ptr<CppFile> RemovedFile;
      53             :   };
      54             : 
      55             :   /// Similar to getOrCreateFile, but will replace a current CppFile for \p File
      56             :   /// with a new one if CompileCommand, provided by \p CDB has changed.
      57             :   /// If a currently stored CppFile had to be replaced, the previous instance
      58             :   /// will be returned in RecreateResult.RemovedFile.
      59             :   RecreateResult recreateFileIfCompileCommandChanged(
      60             :       PathRef File, PathRef ResourceDir, GlobalCompilationDatabase &CDB,
      61             :       std::shared_ptr<PCHContainerOperations> PCHs,
      62             :       IntrusiveRefCntPtr<vfs::FileSystem> VFS);
      63             : 
      64             :   std::shared_ptr<CppFile> getFile(PathRef File) {
      65             :     std::lock_guard<std::mutex> Lock(Mutex);
      66             : 
      67             :     auto It = OpenedFiles.find(File);
      68             :     if (It == OpenedFiles.end())
      69             :       return nullptr;
      70             :     return It->second;
      71             :   }
      72             : 
      73             :   /// Removes a CppFile, stored for \p File, if it's inside collection and
      74             :   /// returns it.
      75             :   std::shared_ptr<CppFile> removeIfPresent(PathRef File);
      76             : 
      77             : private:
      78             :   tooling::CompileCommand getCompileCommand(GlobalCompilationDatabase &CDB,
      79             :                                             PathRef File, PathRef ResourceDir);
      80             : 
      81             :   bool compileCommandsAreEqual(tooling::CompileCommand const &LHS,
      82             :                                tooling::CompileCommand const &RHS);
      83             : 
      84             :   std::mutex Mutex;
      85             :   llvm::StringMap<std::shared_ptr<CppFile>> OpenedFiles;
      86             : };
      87             : } // namespace clangd
      88             : } // namespace clang
      89             : 
      90             : #endif

Generated by: LCOV version 1.13