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-07-13 00:08:38 Functions: 0 2 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             : #include "clang/Lex/Preprocessor.h"
      23             : 
      24             : namespace clang {
      25             : namespace clangd {
      26             : 
      27             : /// \brief A container of Symbols from several source files. It can be updated
      28             : /// at source-file granularity, replacing all symbols from one file with a new
      29             : /// set.
      30             : ///
      31             : /// This implements a snapshot semantics for symbols in a file. Each update to a
      32             : /// file will create a new snapshot for all symbols in the file. Snapshots are
      33             : /// managed with shared pointers that are shared between this class and the
      34             : /// users. For each file, this class only stores a pointer pointing to the
      35             : /// newest snapshot, and an outdated snapshot is deleted by the last owner of
      36             : /// the snapshot, either this class or the symbol index.
      37             : ///
      38             : /// The snapshot semantics keeps critical sections minimal since we only need
      39             : /// locking when we swap or obtain refereces to snapshots.
      40           0 : class FileSymbols {
      41             : public:
      42             :   /// \brief Updates all symbols in a file. If \p Slab is nullptr, symbols for
      43             :   /// \p Path will be removed.
      44             :   void update(PathRef Path, std::unique_ptr<SymbolSlab> Slab);
      45             : 
      46             :   // The shared_ptr keeps the symbols alive
      47             :   std::shared_ptr<std::vector<const Symbol *>> allSymbols();
      48             : 
      49             : private:
      50             :   mutable std::mutex Mutex;
      51             : 
      52             :   /// \brief Stores the latest snapshots for all active files.
      53             :   llvm::StringMap<std::shared_ptr<SymbolSlab>> FileToSlabs;
      54             : };
      55             : 
      56             : /// \brief This manages symbls from files and an in-memory index on all symbols.
      57           0 : class FileIndex : public SymbolIndex {
      58             : public:
      59             :   /// If URISchemes is empty, the default schemes in SymbolCollector will be
      60             :   /// used.
      61             :   FileIndex(std::vector<std::string> URISchemes = {});
      62             : 
      63             :   /// \brief Update symbols in \p Path with symbols in \p AST. If \p AST is
      64             :   /// nullptr, this removes all symbols in the file.
      65             :   /// If \p AST is not null, \p PP cannot be null and it should be the
      66             :   /// preprocessor that was used to build \p AST.
      67             :   void update(PathRef Path, ASTContext *AST, std::shared_ptr<Preprocessor> PP);
      68             : 
      69             :   bool
      70             :   fuzzyFind(const FuzzyFindRequest &Req,
      71             :             llvm::function_ref<void(const Symbol &)> Callback) const override;
      72             : 
      73             :   void lookup(const LookupRequest &Req,
      74             :               llvm::function_ref<void(const Symbol &)> Callback) const override;
      75             : 
      76             : private:
      77             :   FileSymbols FSymbols;
      78             :   MemIndex Index;
      79             :   std::vector<std::string> URISchemes;
      80             : };
      81             : 
      82             : /// Retrieves namespace and class level symbols in \p AST.
      83             : /// Exposed to assist in unit tests.
      84             : /// If URISchemes is empty, the default schemes in SymbolCollector will be used.
      85             : SymbolSlab indexAST(ASTContext &AST, std::shared_ptr<Preprocessor> PP,
      86             :                     llvm::ArrayRef<std::string> URISchemes = {});
      87             : 
      88             : } // namespace clangd
      89             : } // namespace clang
      90             : 
      91             : #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_FILEINDEX_H

Generated by: LCOV version 1.13