xref: /freebsd-src/contrib/llvm-project/clang/lib/Index/FileIndexRecord.h (revision fe6060f10f634930ff71b7c50291ddc610da2475)
10b57cec5SDimitry Andric //===--- FileIndexRecord.h - Index data per file ----------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H
100b57cec5SDimitry Andric #define LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "clang/Basic/SourceLocation.h"
130b57cec5SDimitry Andric #include "clang/Index/DeclOccurrence.h"
140b57cec5SDimitry Andric #include "clang/Index/IndexSymbol.h"
150b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h"
160b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h"
170b57cec5SDimitry Andric #include <vector>
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric namespace clang {
200b57cec5SDimitry Andric class IdentifierInfo;
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric namespace index {
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric /// Stores the declaration occurrences seen in a particular source or header
250b57cec5SDimitry Andric /// file of a translation unit
260b57cec5SDimitry Andric class FileIndexRecord {
270b57cec5SDimitry Andric private:
280b57cec5SDimitry Andric   FileID FID;
290b57cec5SDimitry Andric   bool IsSystem;
30*fe6060f1SDimitry Andric   mutable bool IsSorted = false;
31*fe6060f1SDimitry Andric   mutable std::vector<DeclOccurrence> Decls;
320b57cec5SDimitry Andric 
330b57cec5SDimitry Andric public:
FileIndexRecord(FileID FID,bool IsSystem)340b57cec5SDimitry Andric   FileIndexRecord(FileID FID, bool IsSystem) : FID(FID), IsSystem(IsSystem) {}
350b57cec5SDimitry Andric 
36*fe6060f1SDimitry Andric   ArrayRef<DeclOccurrence> getDeclOccurrencesSortedByOffset() const;
370b57cec5SDimitry Andric 
getFileID()380b57cec5SDimitry Andric   FileID getFileID() const { return FID; }
isSystem()390b57cec5SDimitry Andric   bool isSystem() const { return IsSystem; }
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric   /// Adds an occurrence of the canonical declaration \c D at the supplied
420b57cec5SDimitry Andric   /// \c Offset
430b57cec5SDimitry Andric   ///
440b57cec5SDimitry Andric   /// \param Roles the roles the occurrence fulfills in this position.
450b57cec5SDimitry Andric   /// \param Offset the offset in the file of this occurrence.
460b57cec5SDimitry Andric   /// \param D the canonical declaration this is an occurrence of.
470b57cec5SDimitry Andric   /// \param Relations the set of symbols related to this occurrence.
480b57cec5SDimitry Andric   void addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, const Decl *D,
490b57cec5SDimitry Andric                         ArrayRef<SymbolRelation> Relations);
50*fe6060f1SDimitry Andric 
51*fe6060f1SDimitry Andric   /// Adds an occurrence of the given macro at the supplied \c Offset.
52*fe6060f1SDimitry Andric   ///
53*fe6060f1SDimitry Andric   /// \param Roles the roles the occurrence fulfills in this position.
54*fe6060f1SDimitry Andric   /// \param Offset the offset in the file of this occurrence.
55*fe6060f1SDimitry Andric   /// \param Name the name of the macro.
56*fe6060f1SDimitry Andric   /// \param MI the canonical declaration this is an occurrence of.
57*fe6060f1SDimitry Andric   void addMacroOccurence(SymbolRoleSet Roles, unsigned Offset,
58*fe6060f1SDimitry Andric                          const IdentifierInfo *Name, const MacroInfo *MI);
59*fe6060f1SDimitry Andric 
60*fe6060f1SDimitry Andric   /// Remove any macro occurrences for header guards. When preprocessing, this
61*fe6060f1SDimitry Andric   /// will only be accurate after HandleEndOfFile.
62*fe6060f1SDimitry Andric   void removeHeaderGuardMacros();
63*fe6060f1SDimitry Andric 
64*fe6060f1SDimitry Andric   void print(llvm::raw_ostream &OS, SourceManager &SM) const;
650b57cec5SDimitry Andric };
660b57cec5SDimitry Andric 
670b57cec5SDimitry Andric } // end namespace index
680b57cec5SDimitry Andric } // end namespace clang
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H
71