Mercurial > hg > CbC > CbC_llvm
comparison clang-tools-extra/clangd/ASTSignals.cpp @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
220:42394fc6a535 | 221:79ff65ed7e25 |
---|---|
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 { | |
15 ASTSignals ASTSignals::derive(const ParsedAST &AST) { | |
16 ASTSignals Signals; | |
17 const SourceManager &SM = AST.getSourceManager(); | |
18 findExplicitReferences( | |
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 |