clang-tools 19.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 "Headers.h"
13#include "support/Trace.h"
14#include "clang/AST/DeclObjC.h"
15
16namespace clang {
17namespace clangd {
19 trace::Span Span("ASTSignals::derive");
20 ASTSignals Signals;
22 AST.tuPath(), AST.getLangOpts(),
23 AST.getIncludeStructure().MainFileIncludes, AST.getLocalTopLevelDecls());
24 const SourceManager &SM = AST.getSourceManager();
26 AST.getASTContext(),
27 [&](ReferenceLoc Ref) {
28 for (const NamedDecl *ND : Ref.Targets) {
29 if (!isInsideMainFile(Ref.NameLoc, SM))
30 continue;
31 SymbolID ID = getSymbolID(ND);
32 if (!ID)
33 continue;
34 unsigned &SymbolCount = Signals.ReferencedSymbols[ID];
35 SymbolCount++;
36 // Process namespace only when we see the symbol for the first time.
37 if (SymbolCount != 1)
38 continue;
39 if (const auto *NSD = dyn_cast<NamespaceDecl>(ND->getDeclContext())) {
40 if (NSD->isAnonymousNamespace())
41 continue;
42 std::string NS = printNamespaceScope(*NSD);
43 if (!NS.empty())
44 Signals.RelatedNamespaces[NS]++;
45 }
46 }
47 },
48 AST.getHeuristicResolver());
49 return Signals;
50}
51} // namespace clangd
52} // namespace clang
Stores and provides access to parsed AST.
Definition: ParsedAST.h:46
Records an event whose duration is the lifetime of the Span object.
Definition: Trace.h:143
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.
Symbol::IncludeDirective preferredIncludeDirective(llvm::StringRef FileName, const LangOptions &LangOpts, ArrayRef< Inclusion > MainFileIncludes, ArrayRef< const Decl * > TopLevelDecls)
Infer the include directive to use for the given FileName.
Definition: AST.cpp:380
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Signals derived from a valid AST of a file.
Definition: ASTSignals.h:27
static ASTSignals derive(const ParsedAST &AST)
Definition: ASTSignals.cpp:18
Symbol::IncludeDirective InsertionDirective
Preferred preprocessor directive to use for inclusions by the file.
Definition: ASTSignals.h:34
Represents a symbol occurrence in the source file.
Definition: Ref.h:85
Information about a reference written in the source code, independent of the actual AST node that thi...
Definition: FindTarget.h:126