| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | #include "FileIndexRecord.h" |
| 11 | #include "clang/AST/ASTContext.h" |
| 12 | #include "clang/AST/DeclTemplate.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 | void FileIndexRecord::addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, |
| 20 | const Decl *D, |
| 21 | ArrayRef<SymbolRelation> Relations) { |
| 22 | (0) . __assert_fail ("D->isCanonicalDecl() && \"Occurrences should be associated with their canonical decl\"", "/home/seafit/code_projects/clang_source/clang/lib/Index/FileIndexRecord.cpp", 23, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D->isCanonicalDecl() && |
| 23 | (0) . __assert_fail ("D->isCanonicalDecl() && \"Occurrences should be associated with their canonical decl\"", "/home/seafit/code_projects/clang_source/clang/lib/Index/FileIndexRecord.cpp", 23, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Occurrences should be associated with their canonical decl"); |
| 24 | |
| 25 | auto IsNextOccurence = [&]() -> bool { |
| 26 | if (Decls.empty()) |
| 27 | return true; |
| 28 | auto &Last = Decls.back(); |
| 29 | return Last.Offset < Offset; |
| 30 | }; |
| 31 | |
| 32 | if (IsNextOccurence()) { |
| 33 | Decls.emplace_back(Roles, Offset, D, Relations); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | DeclOccurrence NewInfo(Roles, Offset, D, Relations); |
| 38 | |
| 39 | auto It = std::upper_bound(Decls.begin(), Decls.end(), NewInfo); |
| 40 | Decls.insert(It, std::move(NewInfo)); |
| 41 | } |
| 42 | |
| 43 | void FileIndexRecord::print(llvm::raw_ostream &OS) const { |
| 44 | OS << "DECLS BEGIN ---\n"; |
| 45 | for (auto &DclInfo : Decls) { |
| 46 | const Decl *D = DclInfo.Dcl; |
| 47 | SourceManager &SM = D->getASTContext().getSourceManager(); |
| 48 | SourceLocation Loc = SM.getFileLoc(D->getLocation()); |
| 49 | PresumedLoc PLoc = SM.getPresumedLoc(Loc); |
| 50 | OS << llvm::sys::path::filename(PLoc.getFilename()) << ':' << PLoc.getLine() |
| 51 | << ':' << PLoc.getColumn(); |
| 52 | |
| 53 | if (auto ND = dyn_cast<NamedDecl>(D)) { |
| 54 | OS << ' ' << ND->getNameAsString(); |
| 55 | } |
| 56 | |
| 57 | OS << '\n'; |
| 58 | } |
| 59 | OS << "DECLS END ---\n"; |
| 60 | } |
| 61 | |