/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Index/FileIndexRecord.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- FileIndexRecord.cpp - Index data per file --------------*- 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 "FileIndexRecord.h" |
10 | | #include "clang/AST/ASTContext.h" |
11 | | #include "clang/AST/DeclTemplate.h" |
12 | | #include "clang/Basic/SourceManager.h" |
13 | | #include "llvm/ADT/SmallString.h" |
14 | | #include "llvm/Support/Path.h" |
15 | | |
16 | | using namespace clang; |
17 | | using namespace clang::index; |
18 | | |
19 | | ArrayRef<DeclOccurrence> |
20 | 0 | FileIndexRecord::getDeclOccurrencesSortedByOffset() const { |
21 | 0 | if (!IsSorted) { |
22 | 0 | llvm::stable_sort(Decls, |
23 | 0 | [](const DeclOccurrence &A, const DeclOccurrence &B) { |
24 | 0 | return A.Offset < B.Offset; |
25 | 0 | }); |
26 | 0 | IsSorted = true; |
27 | 0 | } |
28 | 0 | return Decls; |
29 | 0 | } |
30 | | |
31 | | void FileIndexRecord::addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, |
32 | | const Decl *D, |
33 | 0 | ArrayRef<SymbolRelation> Relations) { |
34 | 0 | assert(D->isCanonicalDecl() && |
35 | 0 | "Occurrences should be associated with their canonical decl"); |
36 | 0 | IsSorted = false; |
37 | 0 | Decls.emplace_back(Roles, Offset, D, Relations); |
38 | 0 | } |
39 | | |
40 | | void FileIndexRecord::addMacroOccurence(SymbolRoleSet Roles, unsigned Offset, |
41 | | const IdentifierInfo *Name, |
42 | 0 | const MacroInfo *MI) { |
43 | 0 | IsSorted = false; |
44 | 0 | Decls.emplace_back(Roles, Offset, Name, MI); |
45 | 0 | } |
46 | | |
47 | 0 | void FileIndexRecord::removeHeaderGuardMacros() { |
48 | 0 | llvm::erase_if(Decls, [](const DeclOccurrence &D) { |
49 | 0 | if (const auto *MI = D.DeclOrMacro.dyn_cast<const MacroInfo *>()) |
50 | 0 | return MI->isUsedForHeaderGuard(); |
51 | 0 | return false; |
52 | 0 | }); |
53 | 0 | } |
54 | | |
55 | 0 | void FileIndexRecord::print(llvm::raw_ostream &OS, SourceManager &SM) const { |
56 | 0 | OS << "DECLS BEGIN ---\n"; |
57 | 0 | for (auto &DclInfo : Decls) { |
58 | 0 | if (const auto *D = DclInfo.DeclOrMacro.dyn_cast<const Decl *>()) { |
59 | 0 | SourceLocation Loc = SM.getFileLoc(D->getLocation()); |
60 | 0 | PresumedLoc PLoc = SM.getPresumedLoc(Loc); |
61 | 0 | OS << llvm::sys::path::filename(PLoc.getFilename()) << ':' |
62 | 0 | << PLoc.getLine() << ':' << PLoc.getColumn(); |
63 | |
|
64 | 0 | if (const auto *ND = dyn_cast<NamedDecl>(D)) { |
65 | 0 | OS << ' ' << ND->getDeclName(); |
66 | 0 | } |
67 | 0 | } else { |
68 | 0 | const auto *MI = DclInfo.DeclOrMacro.get<const MacroInfo *>(); |
69 | 0 | SourceLocation Loc = SM.getFileLoc(MI->getDefinitionLoc()); |
70 | 0 | PresumedLoc PLoc = SM.getPresumedLoc(Loc); |
71 | 0 | OS << llvm::sys::path::filename(PLoc.getFilename()) << ':' |
72 | 0 | << PLoc.getLine() << ':' << PLoc.getColumn(); |
73 | 0 | OS << ' ' << DclInfo.MacroName->getName(); |
74 | 0 | } |
75 | |
|
76 | 0 | OS << '\n'; |
77 | 0 | } |
78 | 0 | OS << "DECLS END ---\n"; |
79 | 0 | } |