LCOV - code coverage report
Current view: top level - clang/tools/extra/clangd/index - SymbolCollector.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 0 5 0.0 %
Date: 2018-06-17 00:07:59 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===--- SymbolCollector.h ---------------------------------------*- 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             : #include "CanonicalIncludes.h"
      11             : #include "Index.h"
      12             : #include "clang/AST/ASTContext.h"
      13             : #include "clang/AST/Decl.h"
      14             : #include "clang/Index/IndexDataConsumer.h"
      15             : #include "clang/Index/IndexSymbol.h"
      16             : #include "clang/Sema/CodeCompleteConsumer.h"
      17             : 
      18             : namespace clang {
      19             : namespace clangd {
      20             : 
      21             : /// \brief Collect declarations (symbols) from an AST.
      22             : /// It collects most declarations except:
      23             : /// - Implicit declarations
      24             : /// - Anonymous declarations (anonymous enum/class/struct, etc)
      25             : /// - Declarations in anonymous namespaces
      26             : /// - Local declarations (in function bodies, blocks, etc)
      27             : /// - Declarations in main files
      28             : /// - Template specializations
      29             : /// - Library-specific private declarations (e.g. private declaration generated
      30             : /// by protobuf compiler)
      31             : ///
      32             : /// See also shouldFilterDecl().
      33             : ///
      34             : /// Clients (e.g. clangd) can use SymbolCollector together with
      35             : /// index::indexTopLevelDecls to retrieve all symbols when the source file is
      36             : /// changed.
      37           0 : class SymbolCollector : public index::IndexDataConsumer {
      38             : public:
      39           0 :   struct Options {
      40             :     /// When symbol paths cannot be resolved to absolute paths (e.g. files in
      41             :     /// VFS that does not have absolute path), combine the fallback directory
      42             :     /// with symbols' paths to get absolute paths. This must be an absolute
      43             :     /// path.
      44             :     std::string FallbackDir;
      45             :     /// Specifies URI schemes that can be used to generate URIs for file paths
      46             :     /// in symbols. The list of schemes will be tried in order until a working
      47             :     /// scheme is found. If no scheme works, symbol location will be dropped.
      48             :     std::vector<std::string> URISchemes = {"file"};
      49             :     bool CollectIncludePath = false;
      50             :     /// If set, this is used to map symbol #include path to a potentially
      51             :     /// different #include path.
      52             :     const CanonicalIncludes *Includes = nullptr;
      53             :     // Populate the Symbol.References field.
      54             :     bool CountReferences = false;
      55             :   };
      56             : 
      57             :   SymbolCollector(Options Opts);
      58             : 
      59             :   void initialize(ASTContext &Ctx) override;
      60             : 
      61           0 :   void setPreprocessor(std::shared_ptr<Preprocessor> PP) override {
      62             :     this->PP = std::move(PP);
      63           0 :   }
      64             : 
      65             :   bool
      66             :   handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles,
      67             :                       ArrayRef<index::SymbolRelation> Relations,
      68             :                       SourceLocation Loc,
      69             :                       index::IndexDataConsumer::ASTNodeInfo ASTNode) override;
      70             : 
      71           0 :   SymbolSlab takeSymbols() { return std::move(Symbols).build(); }
      72             : 
      73             :   void finish() override;
      74             : 
      75             : private:
      76             :   const Symbol *addDeclaration(const NamedDecl &, SymbolID);
      77             :   void addDefinition(const NamedDecl &, const Symbol &DeclSymbol);
      78             : 
      79             :   // All Symbols collected from the AST.
      80             :   SymbolSlab::Builder Symbols;
      81             :   ASTContext *ASTCtx;
      82             :   std::shared_ptr<Preprocessor> PP;
      83             :   std::shared_ptr<GlobalCodeCompletionAllocator> CompletionAllocator;
      84             :   std::unique_ptr<CodeCompletionTUInfo> CompletionTUInfo;
      85             :   Options Opts;
      86             :   // Decls referenced from the current TU, flushed on finish().
      87             :   llvm::DenseSet<const NamedDecl *> ReferencedDecls;
      88             :   // Maps canonical declaration provided by clang to canonical declaration for
      89             :   // an index symbol, if clangd prefers a different declaration than that
      90             :   // provided by clang. For example, friend declaration might be considered
      91             :   // canonical by clang but should not be considered canonical in the index
      92             :   // unless it's a definition.
      93             :   llvm::DenseMap<const Decl *, const Decl *> CanonicalDecls;
      94             : };
      95             : 
      96             : } // namespace clangd
      97             : } // namespace clang

Generated by: LCOV version 1.13