FileIndexRecord.h 2.5 KB

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