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