clang-tools  16.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 #include "support/Trace.h"
13 
14 namespace clang {
15 namespace clangd {
17  trace::Span Span("ASTSignals::derive");
18  ASTSignals Signals;
19  const SourceManager &SM = AST.getSourceManager();
21  AST.getASTContext(),
22  [&](ReferenceLoc Ref) {
23  for (const NamedDecl *ND : Ref.Targets) {
24  if (!isInsideMainFile(Ref.NameLoc, SM))
25  continue;
26  SymbolID ID = getSymbolID(ND);
27  if (!ID)
28  continue;
29  unsigned &SymbolCount = Signals.ReferencedSymbols[ID];
30  SymbolCount++;
31  // Process namespace only when we see the symbol for the first time.
32  if (SymbolCount != 1)
33  continue;
34  if (const auto *NSD = dyn_cast<NamespaceDecl>(ND->getDeclContext())) {
35  if (NSD->isAnonymousNamespace())
36  continue;
37  std::string NS = printNamespaceScope(*NSD);
38  if (!NS.empty())
39  Signals.RelatedNamespaces[NS]++;
40  }
41  }
42  },
43  AST.getHeuristicResolver());
44  return Signals;
45 }
46 } // namespace clangd
47 } // namespace clang
Trace.h
FindTarget.h
clang::clangd::ParsedAST::getHeuristicResolver
const HeuristicResolver * getHeuristicResolver() const
Definition: ParsedAST.h:119
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:126
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:85
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::ParsedAST
Stores and provides access to parsed AST.
Definition: ParsedAST.h:46
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:1112
AST.h
clang::clangd::ASTSignals::derive
static ASTSignals derive(const ParsedAST &AST)
Definition: ASTSignals.cpp:16
clang::clangd::trace::Span
Records an event whose duration is the lifetime of the Span object.
Definition: Trace.h:143