LCOV - code coverage report
Current view: top level - clang/tools/extra/clangd/index - FileIndex.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 0 2 0.0 %
Date: 2018-02-19 17:12:42 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===--- FileIndex.h - Index for files. ---------------------------- 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             : // FileIndex implements SymbolIndex for symbols from a set of files. Symbols are
      11             : // maintained at source-file granuality (e.g. with ASTs), and files can be
      12             : // updated dynamically.
      13             : //
      14             : //===---------------------------------------------------------------------===//
      15             : 
      16             : #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_FILEINDEX_H
      17             : #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_FILEINDEX_H
      18             : 
      19             : #include "../ClangdUnit.h"
      20             : #include "Index.h"
      21             : #include "MemIndex.h"
      22             : 
      23             : namespace clang {
      24             : namespace clangd {
      25             : 
      26             : /// \brief A container of Symbols from several source files. It can be updated
      27             : /// at source-file granularity, replacing all symbols from one file with a new
      28             : /// set.
      29             : ///
      30             : /// This implements a snapshot semantics for symbols in a file. Each update to a
      31             : /// file will create a new snapshot for all symbols in the file. Snapshots are
      32             : /// managed with shared pointers that are shared between this class and the
      33             : /// users. For each file, this class only stores a pointer pointing to the
      34             : /// newest snapshot, and an outdated snapshot is deleted by the last owner of
      35             : /// the snapshot, either this class or the symbol index.
      36             : ///
      37             : /// The snapshot semantics keeps critical sections minimal since we only need
      38             : /// locking when we swap or obtain refereces to snapshots.
      39           0 : class FileSymbols {
      40             : public:
      41             :   /// \brief Updates all symbols in a file. If \p Slab is nullptr, symbols for
      42             :   /// \p Path will be removed.
      43             :   void update(PathRef Path, std::unique_ptr<SymbolSlab> Slab);
      44             : 
      45             :   // The shared_ptr keeps the symbols alive
      46             :   std::shared_ptr<std::vector<const Symbol *>> allSymbols();
      47             : 
      48             : private:
      49             :   mutable std::mutex Mutex;
      50             : 
      51             :   /// \brief Stores the latest snapshots for all active files.
      52             :   llvm::StringMap<std::shared_ptr<SymbolSlab>> FileToSlabs;
      53             : };
      54             : 
      55             : /// \brief This manages symbls from files and an in-memory index on all symbols.
      56           0 : class FileIndex : public SymbolIndex {
      57             : public:
      58             :   /// \brief Update symbols in \p Path with symbols in \p AST. If \p AST is
      59             :   /// nullptr, this removes all symbols in the file
      60             :   void update(PathRef Path, ParsedAST *AST);
      61             : 
      62             :   bool
      63             :   fuzzyFind(const FuzzyFindRequest &Req,
      64             :             llvm::function_ref<void(const Symbol &)> Callback) const override;
      65             : 
      66             : private:
      67             :   FileSymbols FSymbols;
      68             :   MemIndex Index;
      69             : };
      70             : 
      71             : } // namespace clangd
      72             : } // namespace clang
      73             : 
      74             : #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_FILEINDEX_H

Generated by: LCOV version 1.13