[PATCH] D58478: [index-while-building] FileIndexRecord
This revision was automatically updated to reflect the committed changes. Closed by commit rC355035: [clang][index-while-building] FileIndexRecord (authored by jkorous, committed by ). Changed prior to commit: https://reviews.llvm.org/D58478?vs=187863=188614#toc Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58478/new/ https://reviews.llvm.org/D58478 Files: include/clang/Index/DeclOccurrence.h lib/Index/CMakeLists.txt lib/Index/FileIndexRecord.cpp lib/Index/FileIndexRecord.h Index: include/clang/Index/DeclOccurrence.h === --- include/clang/Index/DeclOccurrence.h +++ include/clang/Index/DeclOccurrence.h @@ -0,0 +1,42 @@ +//===--- DeclOccurrence.h - An occurrence of a decl within a file -===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#ifndef LLVM_CLANG_INDEX_DECLOCCURRENCE_H +#define LLVM_CLANG_INDEX_DECLOCCURRENCE_H + +#include "clang/Basic/LLVM.h" +#include "clang/Index/IndexSymbol.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" + +namespace clang { +class Decl; + +namespace index { + +struct DeclOccurrence { + SymbolRoleSet Roles; + unsigned Offset; + const Decl *Dcl; + SmallVector Relations; + + DeclOccurrence(SymbolRoleSet R, unsigned Offset, const Decl *D, + ArrayRef Relations) + : Roles(R), Offset(Offset), Dcl(D), +Relations(Relations.begin(), Relations.end()) {} + + friend bool operator<(const DeclOccurrence , const DeclOccurrence ) { +return LHS.Offset < RHS.Offset; + } +}; + +} // namespace index +} // namespace clang + +#endif Index: lib/Index/CMakeLists.txt === --- lib/Index/CMakeLists.txt +++ lib/Index/CMakeLists.txt @@ -6,6 +6,7 @@ add_clang_library(clangIndex CodegenNameGenerator.cpp CommentToXML.cpp + FileIndexRecord.cpp IndexBody.cpp IndexDecl.cpp IndexingAction.cpp Index: lib/Index/FileIndexRecord.h === --- lib/Index/FileIndexRecord.h +++ lib/Index/FileIndexRecord.h @@ -0,0 +1,58 @@ +//===--- FileIndexRecord.h - Index data per file --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#ifndef LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H +#define LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H + +#include "clang/Basic/SourceLocation.h" +#include "clang/Index/DeclOccurrence.h" +#include "clang/Index/IndexSymbol.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" +#include + +namespace clang { +class IdentifierInfo; + +namespace index { + +/// Stores the declaration occurrences seen in a particular source or header +/// file of a translation unit +class FileIndexRecord { +private: + FileID FID; + bool IsSystem; + std::vector Decls; + +public: + FileIndexRecord(FileID FID, bool IsSystem) : FID(FID), IsSystem(IsSystem) {} + + ArrayRef getDeclOccurrencesSortedByOffset() const { +return Decls; + } + + FileID getFileID() const { return FID; } + bool isSystem() const { return IsSystem; } + + /// Adds an occurrence of the canonical declaration \c D at the supplied + /// \c Offset + /// + /// \param Roles the roles the occurrence fulfills in this position. + /// \param Offset the offset in the file of this occurrence. + /// \param D the canonical declaration this is an occurrence of. + /// \param Relations the set of symbols related to this occurrence. + void addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, const Decl *D, +ArrayRef Relations); + void print(llvm::raw_ostream ) const; +}; + +} // end namespace index +} // end namespace clang + +#endif Index: lib/Index/FileIndexRecord.cpp === --- lib/Index/FileIndexRecord.cpp +++ lib/Index/FileIndexRecord.cpp @@ -0,0 +1,59 @@ +//===--- FileIndexRecord.cpp - Index data per file ===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "FileIndexRecord.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/DeclTemplate.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/Path.h" + +using namespace clang; +using namespace clang::index; + +void FileIndexRecord::addDeclOccurence(SymbolRoleSet
[PATCH] D58478: [index-while-building] FileIndexRecord
nathawes accepted this revision. nathawes added a comment. This revision is now accepted and ready to land. Looks good to me. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58478/new/ https://reviews.llvm.org/D58478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D58478: [index-while-building] FileIndexRecord
jkorous added a comment. ping -c 1 CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58478/new/ https://reviews.llvm.org/D58478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D58478: [index-while-building] FileIndexRecord
jkorous marked 3 inline comments as done. jkorous added a comment. Done. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58478/new/ https://reviews.llvm.org/D58478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D58478: [index-while-building] FileIndexRecord
jkorous updated this revision to Diff 187863. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58478/new/ https://reviews.llvm.org/D58478 Files: clang/include/clang/Index/DeclOccurrence.h clang/lib/Index/CMakeLists.txt clang/lib/Index/FileIndexRecord.cpp clang/lib/Index/FileIndexRecord.h Index: clang/lib/Index/FileIndexRecord.h === --- /dev/null +++ clang/lib/Index/FileIndexRecord.h @@ -0,0 +1,57 @@ +//===--- FileIndexRecord.h - Index data per file *- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H +#define LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H + +#include "clang/Basic/SourceLocation.h" +#include "clang/Index/DeclOccurrence.h" +#include "clang/Index/IndexSymbol.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" +#include + +namespace clang { +class IdentifierInfo; + +namespace index { + +/// Stores the declaration occurrences seen in a particular source or header +/// file of a translation unit +class FileIndexRecord { +private: + FileID FID; + bool IsSystem; + std::vector Decls; + +public: + FileIndexRecord(FileID FID, bool IsSystem) : FID(FID), IsSystem(IsSystem) {} + + ArrayRef getDeclOccurrencesSortedByOffset() const { +return Decls; + } + + FileID getFileID() const { return FID; } + bool isSystem() const { return IsSystem; } + + /// Adds an occurrence of the canonical declaration \c D at the supplied + /// \c Offset + /// + /// \param Roles the roles the occurrence fulfills in this position. + /// \param Offset the offset in the file of this occurrence. + /// \param D the canonical declaration this is an occurrence of. + /// \param Relations the set of symbols related to this occurrence. + void addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, const Decl *D, +ArrayRef Relations); + void print(llvm::raw_ostream ) const; +}; + +} // end namespace index +} // end namespace clang + +#endif // LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H Index: clang/lib/Index/FileIndexRecord.cpp === --- /dev/null +++ clang/lib/Index/FileIndexRecord.cpp @@ -0,0 +1,59 @@ +//===--- FileIndexRecord.cpp - Index data per file --*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "FileIndexRecord.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/DeclTemplate.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/Path.h" + +using namespace clang; +using namespace clang::index; + +void FileIndexRecord::addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, + const Decl *D, + ArrayRef Relations) { + assert(D->isCanonicalDecl() && + "Occurrences should be associated with their canonical decl"); + + auto IsNextOccurence = [&]() -> bool { +if (Decls.empty()) + return true; +auto = Decls.back(); +return Last.Offset < Offset; + }; + + if (IsNextOccurence()) { +Decls.emplace_back(Roles, Offset, D, Relations); +return; + } + + DeclOccurrence NewInfo(Roles, Offset, D, Relations); + auto It = std::upper_bound(Decls.begin(), Decls.end(), NewInfo); + Decls.insert(It, std::move(NewInfo)); +} + +void FileIndexRecord::print(llvm::raw_ostream ) const { + OS << "DECLS BEGIN ---\n"; + for (auto : Decls) { +const Decl *D = DclInfo.Dcl; +SourceManager = D->getASTContext().getSourceManager(); +SourceLocation Loc = SM.getFileLoc(D->getLocation()); +PresumedLoc PLoc = SM.getPresumedLoc(Loc); +OS << llvm::sys::path::filename(PLoc.getFilename()) << ':' << PLoc.getLine() + << ':' << PLoc.getColumn(); + +if (auto ND = dyn_cast(D)) { + OS << ' ' << ND->getNameAsString(); +} + +OS << '\n'; + } + OS << "DECLS END ---\n"; +} Index: clang/lib/Index/CMakeLists.txt === --- clang/lib/Index/CMakeLists.txt +++ clang/lib/Index/CMakeLists.txt @@ -6,6 +6,7 @@ add_clang_library(clangIndex CodegenNameGenerator.cpp CommentToXML.cpp + FileIndexRecord.cpp IndexBody.cpp IndexDecl.cpp IndexingAction.cpp Index: clang/include/clang/Index/DeclOccurrence.h === --- /dev/null +++ clang/include/clang/Index/DeclOccurrence.h @@ -0,0 +1,41 @@ +//===- DeclOccurrence.h - An occurrence of a
[PATCH] D58478: [index-while-building] FileIndexRecord
Eugene.Zelenko added inline comments. Comment at: clang/include/clang/Index/DeclOccurrence.h:1 +//===--- DeclOccurrence.h - An occurrence of a decl within a file - C++ -*-===// +// Tag should contain *- C++ -*, so you could remove dashes at beginning and equal signs to fit. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58478/new/ https://reviews.llvm.org/D58478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D58478: [index-while-building] FileIndexRecord
jkorous added a comment. Thanks Eugene. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58478/new/ https://reviews.llvm.org/D58478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D58478: [index-while-building] FileIndexRecord
jkorous updated this revision to Diff 187848. jkorous marked 5 inline comments as done. jkorous added a comment. - license - remove auto CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58478/new/ https://reviews.llvm.org/D58478 Files: clang/include/clang/Index/DeclOccurrence.h clang/lib/Index/CMakeLists.txt clang/lib/Index/FileIndexRecord.cpp clang/lib/Index/FileIndexRecord.h Index: clang/lib/Index/FileIndexRecord.h === --- /dev/null +++ clang/lib/Index/FileIndexRecord.h @@ -0,0 +1,57 @@ +//===--- FileIndexRecord.h - Index data per file *- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H +#define LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H + +#include "clang/Basic/SourceLocation.h" +#include "clang/Index/DeclOccurrence.h" +#include "clang/Index/IndexSymbol.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" +#include + +namespace clang { +class IdentifierInfo; + +namespace index { + +/// Stores the declaration occurrences seen in a particular source or header +/// file of a translation unit +class FileIndexRecord { +private: + FileID FID; + bool IsSystem; + std::vector Decls; + +public: + FileIndexRecord(FileID FID, bool IsSystem) : FID(FID), IsSystem(IsSystem) {} + + ArrayRef getDeclOccurrencesSortedByOffset() const { +return Decls; + } + + FileID getFileID() const { return FID; } + bool isSystem() const { return IsSystem; } + + /// Adds an occurrence of the canonical declaration \c D at the supplied + /// \c Offset + /// + /// \param Roles the roles the occurrence fulfills in this position. + /// \param Offset the offset in the file of this occurrence. + /// \param D the canonical declaration this is an occurrence of. + /// \param Relations the set of symbols related to this occurrence. + void addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, const Decl *D, +ArrayRef Relations); + void print(llvm::raw_ostream ) const; +}; + +} // end namespace index +} // end namespace clang + +#endif // LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H Index: clang/lib/Index/FileIndexRecord.cpp === --- /dev/null +++ clang/lib/Index/FileIndexRecord.cpp @@ -0,0 +1,59 @@ +//===--- FileIndexRecord.cpp - Index data per file ===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "FileIndexRecord.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/DeclTemplate.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/Path.h" + +using namespace clang; +using namespace clang::index; + +void FileIndexRecord::addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, + const Decl *D, + ArrayRef Relations) { + assert(D->isCanonicalDecl() && + "Occurrences should be associated with their canonical decl"); + + auto IsNextOccurence = [&]() -> bool { +if (Decls.empty()) + return true; +auto = Decls.back(); +return Last.Offset < Offset; + }; + + if (IsNextOccurence()) { +Decls.emplace_back(Roles, Offset, D, Relations); +return; + } + + DeclOccurrence NewInfo(Roles, Offset, D, Relations); + auto It = std::upper_bound(Decls.begin(), Decls.end(), NewInfo); + Decls.insert(It, std::move(NewInfo)); +} + +void FileIndexRecord::print(llvm::raw_ostream ) const { + OS << "DECLS BEGIN ---\n"; + for (auto : Decls) { +const Decl *D = DclInfo.Dcl; +SourceManager = D->getASTContext().getSourceManager(); +SourceLocation Loc = SM.getFileLoc(D->getLocation()); +PresumedLoc PLoc = SM.getPresumedLoc(Loc); +OS << llvm::sys::path::filename(PLoc.getFilename()) << ':' << PLoc.getLine() + << ':' << PLoc.getColumn(); + +if (auto ND = dyn_cast(D)) { + OS << ' ' << ND->getNameAsString(); +} + +OS << '\n'; + } + OS << "DECLS END ---\n"; +} Index: clang/lib/Index/CMakeLists.txt === --- clang/lib/Index/CMakeLists.txt +++ clang/lib/Index/CMakeLists.txt @@ -6,6 +6,7 @@ add_clang_library(clangIndex CodegenNameGenerator.cpp CommentToXML.cpp + FileIndexRecord.cpp IndexBody.cpp IndexDecl.cpp IndexingAction.cpp Index: clang/include/clang/Index/DeclOccurrence.h === --- /dev/null +++
[PATCH] D58478: [index-while-building] FileIndexRecord
Eugene.Zelenko added inline comments. Comment at: clang/include/clang/Index/DeclOccurrence.h:1 +//===--- DeclOccurrence.h - An occurrence of a decl within a file -===// +// Missing C++ tag. See other headers as example. Comment at: clang/include/clang/Index/DeclOccurrence.h:5 +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. License should be updated. Comment at: clang/include/clang/Index/DeclOccurrence.h:42 + +#endif Missing comment with header guard. Comment at: clang/lib/Index/FileIndexRecord.cpp:45 + for (auto : Decls) { +auto D = DclInfo.Dcl; +SourceManager = D->getASTContext().getSourceManager(); Type is not obvious, so auto should not be used. Comment at: clang/lib/Index/FileIndexRecord.h:1 +//===--- FileIndexRecord.h - Index data per file --===// +// Missing C++ tag. See other headers as example. Comment at: clang/lib/Index/FileIndexRecord.h:5 +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. License should be updated. Comment at: clang/lib/Index/FileIndexRecord.h:58 + +#endif Missing comment with header guard. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58478/new/ https://reviews.llvm.org/D58478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D58478: [index-while-building] FileIndexRecord
jkorous created this revision. jkorous added reviewers: dexonsmith, nathawes, akyrtzi, arphaman, ioeric, malaperle. Herald added subscribers: cfe-commits, jdoerfert, mgorny. Herald added a project: clang. Basic data structures for index Tests are missing from this patch - will be covered properly by tests for the whole feature. I'm just trying to split it into smaller patches to make it easier for reviewers. This (with minor changes) was LGTM'ed here https://reviews.llvm.org/D39050. Adding original reviewers. Repository: rC Clang https://reviews.llvm.org/D58478 Files: clang/include/clang/Index/DeclOccurrence.h clang/lib/Index/CMakeLists.txt clang/lib/Index/FileIndexRecord.cpp clang/lib/Index/FileIndexRecord.h Index: clang/lib/Index/FileIndexRecord.h === --- /dev/null +++ clang/lib/Index/FileIndexRecord.h @@ -0,0 +1,58 @@ +//===--- FileIndexRecord.h - Index data per file --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#ifndef LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H +#define LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H + +#include "clang/Basic/SourceLocation.h" +#include "clang/Index/DeclOccurrence.h" +#include "clang/Index/IndexSymbol.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" +#include + +namespace clang { +class IdentifierInfo; + +namespace index { + +/// Stores the declaration occurrences seen in a particular source or header +/// file of a translation unit +class FileIndexRecord { +private: + FileID FID; + bool IsSystem; + std::vector Decls; + +public: + FileIndexRecord(FileID FID, bool IsSystem) : FID(FID), IsSystem(IsSystem) {} + + ArrayRef getDeclOccurrencesSortedByOffset() const { +return Decls; + } + + FileID getFileID() const { return FID; } + bool isSystem() const { return IsSystem; } + + /// Adds an occurrence of the canonical declaration \c D at the supplied + /// \c Offset + /// + /// \param Roles the roles the occurrence fulfills in this position. + /// \param Offset the offset in the file of this occurrence. + /// \param D the canonical declaration this is an occurrence of. + /// \param Relations the set of symbols related to this occurrence. + void addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, const Decl *D, +ArrayRef Relations); + void print(llvm::raw_ostream ) const; +}; + +} // end namespace index +} // end namespace clang + +#endif Index: clang/lib/Index/FileIndexRecord.cpp === --- /dev/null +++ clang/lib/Index/FileIndexRecord.cpp @@ -0,0 +1,59 @@ +//===--- FileIndexRecord.cpp - Index data per file ===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "FileIndexRecord.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/DeclTemplate.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/Path.h" + +using namespace clang; +using namespace clang::index; + +void FileIndexRecord::addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, + const Decl *D, + ArrayRef Relations) { + assert(D->isCanonicalDecl() && + "Occurrences should be associated with their canonical decl"); + + auto IsNextOccurence = [&]() -> bool { +if (Decls.empty()) + return true; +auto = Decls.back(); +return Last.Offset < Offset; + }; + + if (IsNextOccurence()) { +Decls.emplace_back(Roles, Offset, D, Relations); +return; + } + + DeclOccurrence NewInfo(Roles, Offset, D, Relations); + auto It = std::upper_bound(Decls.begin(), Decls.end(), NewInfo); + Decls.insert(It, std::move(NewInfo)); +} + +void FileIndexRecord::print(llvm::raw_ostream ) const { + OS << "DECLS BEGIN ---\n"; + for (auto : Decls) { +auto D = DclInfo.Dcl; +SourceManager = D->getASTContext().getSourceManager(); +SourceLocation Loc = SM.getFileLoc(D->getLocation()); +PresumedLoc PLoc = SM.getPresumedLoc(Loc); +OS << llvm::sys::path::filename(PLoc.getFilename()) << ':' << PLoc.getLine() + << ':' << PLoc.getColumn(); + +if (auto ND = dyn_cast(D)) { + OS << ' ' << ND->getNameAsString(); +} + +OS << '\n'; + } + OS << "DECLS END ---\n"; +} Index: clang/lib/Index/CMakeLists.txt === --- clang/lib/Index/CMakeLists.txt +++ clang/lib/Index/CMakeLists.txt @@ -6,6 +6,7 @@ add_clang_library(clangIndex