clang-tools  14.0.0git
ASTSignals.cpp
Go to the documentation of this file.
1 //===--- ASTSignals.cpp ------------------------------------------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "ASTSignals.h"
10 #include "AST.h"
11 #include "FindTarget.h"
12 
13 namespace clang {
14 namespace clangd {
16  ASTSignals Signals;
17  const SourceManager &SM = AST.getSourceManager();
19  AST.getASTContext(),
20  [&](ReferenceLoc Ref) {
21  for (const NamedDecl *ND : Ref.Targets) {
22  if (!isInsideMainFile(Ref.NameLoc, SM))
23  continue;
24  SymbolID ID = getSymbolID(ND);
25  if (!ID)
26  continue;
27  unsigned &SymbolCount = Signals.ReferencedSymbols[ID];
28  SymbolCount++;
29  // Process namespace only when we see the symbol for the first time.
30  if (SymbolCount != 1)
31  continue;
32  if (const auto *NSD = dyn_cast<NamespaceDecl>(ND->getDeclContext())) {
33  if (NSD->isAnonymousNamespace())
34  continue;
35  std::string NS = printNamespaceScope(*NSD);
36  if (!NS.empty())
37  Signals.RelatedNamespaces[NS]++;
38  }
39  }
40  },
41  AST.getHeuristicResolver());
42  return Signals;
43 }
44 } // namespace clangd
45 } // namespace clang
FindTarget.h
clang::clangd::ParsedAST::getHeuristicResolver
const HeuristicResolver * getHeuristicResolver() const
Definition: ParsedAST.h:117
ASTSignals.h
clang::clangd::ReferenceLoc
Information about a reference written in the source code, independent of the actual AST node that thi...
Definition: FindTarget.h:129
clang::clangd::ASTSignals
Signals derived from a valid AST of a file.
Definition: ASTSignals.h:26
clang::clangd::Ref
Represents a symbol occurrence in the source file.
Definition: Ref.h:87
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
SM
const SourceManager & SM
Definition: IncludeCleaner.cpp:127
clang::clangd::ParsedAST
Stores and provides access to parsed AST.
Definition: ParsedAST.h:49
clang::clangd::findExplicitReferences
void findExplicitReferences(const Stmt *S, llvm::function_ref< void(ReferenceLoc)> Out, const HeuristicResolver *Resolver)
Recursively traverse S and report all references explicitly written in the code.
Definition: FindTarget.cpp:1115
AST.h
clang::clangd::ASTSignals::derive
static ASTSignals derive(const ParsedAST &AST)
Definition: ASTSignals.cpp:15