1e5dd7070Spatrick //===--- FileIndexRecord.h - Index data per file ----------------*- C++ -*-===// 2e5dd7070Spatrick // 3e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information. 5e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e5dd7070Spatrick // 7e5dd7070Spatrick //===----------------------------------------------------------------------===// 8e5dd7070Spatrick 9e5dd7070Spatrick #ifndef LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H 10e5dd7070Spatrick #define LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H 11e5dd7070Spatrick 12e5dd7070Spatrick #include "clang/Basic/SourceLocation.h" 13e5dd7070Spatrick #include "clang/Index/DeclOccurrence.h" 14e5dd7070Spatrick #include "clang/Index/IndexSymbol.h" 15e5dd7070Spatrick #include "llvm/ADT/ArrayRef.h" 16e5dd7070Spatrick #include "llvm/ADT/SmallVector.h" 17e5dd7070Spatrick #include <vector> 18e5dd7070Spatrick 19e5dd7070Spatrick namespace clang { 20e5dd7070Spatrick class IdentifierInfo; 21e5dd7070Spatrick 22e5dd7070Spatrick namespace index { 23e5dd7070Spatrick 24e5dd7070Spatrick /// Stores the declaration occurrences seen in a particular source or header 25e5dd7070Spatrick /// file of a translation unit 26e5dd7070Spatrick class FileIndexRecord { 27e5dd7070Spatrick private: 28e5dd7070Spatrick FileID FID; 29e5dd7070Spatrick bool IsSystem; 30*a9ac8606Spatrick mutable bool IsSorted = false; 31*a9ac8606Spatrick mutable std::vector<DeclOccurrence> Decls; 32e5dd7070Spatrick 33e5dd7070Spatrick public: FileIndexRecord(FileID FID,bool IsSystem)34e5dd7070Spatrick FileIndexRecord(FileID FID, bool IsSystem) : FID(FID), IsSystem(IsSystem) {} 35e5dd7070Spatrick 36*a9ac8606Spatrick ArrayRef<DeclOccurrence> getDeclOccurrencesSortedByOffset() const; 37e5dd7070Spatrick getFileID()38e5dd7070Spatrick FileID getFileID() const { return FID; } isSystem()39e5dd7070Spatrick bool isSystem() const { return IsSystem; } 40e5dd7070Spatrick 41e5dd7070Spatrick /// Adds an occurrence of the canonical declaration \c D at the supplied 42e5dd7070Spatrick /// \c Offset 43e5dd7070Spatrick /// 44e5dd7070Spatrick /// \param Roles the roles the occurrence fulfills in this position. 45e5dd7070Spatrick /// \param Offset the offset in the file of this occurrence. 46e5dd7070Spatrick /// \param D the canonical declaration this is an occurrence of. 47e5dd7070Spatrick /// \param Relations the set of symbols related to this occurrence. 48e5dd7070Spatrick void addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, const Decl *D, 49e5dd7070Spatrick ArrayRef<SymbolRelation> Relations); 50*a9ac8606Spatrick 51*a9ac8606Spatrick /// Adds an occurrence of the given macro at the supplied \c Offset. 52*a9ac8606Spatrick /// 53*a9ac8606Spatrick /// \param Roles the roles the occurrence fulfills in this position. 54*a9ac8606Spatrick /// \param Offset the offset in the file of this occurrence. 55*a9ac8606Spatrick /// \param Name the name of the macro. 56*a9ac8606Spatrick /// \param MI the canonical declaration this is an occurrence of. 57*a9ac8606Spatrick void addMacroOccurence(SymbolRoleSet Roles, unsigned Offset, 58*a9ac8606Spatrick const IdentifierInfo *Name, const MacroInfo *MI); 59*a9ac8606Spatrick 60*a9ac8606Spatrick /// Remove any macro occurrences for header guards. When preprocessing, this 61*a9ac8606Spatrick /// will only be accurate after HandleEndOfFile. 62*a9ac8606Spatrick void removeHeaderGuardMacros(); 63*a9ac8606Spatrick 64*a9ac8606Spatrick void print(llvm::raw_ostream &OS, SourceManager &SM) const; 65e5dd7070Spatrick }; 66e5dd7070Spatrick 67e5dd7070Spatrick } // end namespace index 68e5dd7070Spatrick } // end namespace clang 69e5dd7070Spatrick 70e5dd7070Spatrick #endif // LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H 71