clang  14.0.0git
FileIndexRecord.h
Go to the documentation of this file.
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 
9 #ifndef LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H
10 #define LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H
11 
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include <vector>
18 
19 namespace clang {
20 class IdentifierInfo;
21 
22 namespace index {
23 
24 /// Stores the declaration occurrences seen in a particular source or header
25 /// file of a translation unit
27 private:
28  FileID FID;
29  bool IsSystem;
30  mutable bool IsSorted = false;
31  mutable std::vector<DeclOccurrence> Decls;
32 
33 public:
34  FileIndexRecord(FileID FID, bool IsSystem) : FID(FID), IsSystem(IsSystem) {}
35 
37 
38  FileID getFileID() const { return FID; }
39  bool isSystem() const { return IsSystem; }
40 
41  /// Adds an occurrence of the canonical declaration \c D at the supplied
42  /// \c Offset
43  ///
44  /// \param Roles the roles the occurrence fulfills in this position.
45  /// \param Offset the offset in the file of this occurrence.
46  /// \param D the canonical declaration this is an occurrence of.
47  /// \param Relations the set of symbols related to this occurrence.
48  void addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, const Decl *D,
49  ArrayRef<SymbolRelation> Relations);
50 
51  /// Adds an occurrence of the given macro at the supplied \c Offset.
52  ///
53  /// \param Roles the roles the occurrence fulfills in this position.
54  /// \param Offset the offset in the file of this occurrence.
55  /// \param Name the name of the macro.
56  /// \param MI the canonical declaration this is an occurrence of.
57  void addMacroOccurence(SymbolRoleSet Roles, unsigned Offset,
58  const IdentifierInfo *Name, const MacroInfo *MI);
59 
60  /// Remove any macro occurrences for header guards. When preprocessing, this
61  /// will only be accurate after HandleEndOfFile.
63 
64  void print(llvm::raw_ostream &OS, SourceManager &SM) const;
65 };
66 
67 } // end namespace index
68 } // end namespace clang
69 
70 #endif // LLVM_CLANG_LIB_INDEX_FILEINDEXRECORD_H
clang::index::FileIndexRecord::removeHeaderGuardMacros
void removeHeaderGuardMacros()
Remove any macro occurrences for header guards.
Definition: FileIndexRecord.cpp:47
clang::index::FileIndexRecord::getFileID
FileID getFileID() const
Definition: FileIndexRecord.h:38
clang::index::FileIndexRecord::addDeclOccurence
void addDeclOccurence(SymbolRoleSet Roles, unsigned Offset, const Decl *D, ArrayRef< SymbolRelation > Relations)
Adds an occurrence of the canonical declaration D at the supplied Offset.
Definition: FileIndexRecord.cpp:31
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:626
Offset
unsigned Offset
Definition: Format.cpp:2335
clang::index::FileIndexRecord::print
void print(llvm::raw_ostream &OS, SourceManager &SM) const
Definition: FileIndexRecord.cpp:57
DeclOccurrence.h
clang::index::FileIndexRecord
Stores the declaration occurrences seen in a particular source or header file of a translation unit.
Definition: FileIndexRecord.h:26
clang::index::FileIndexRecord::addMacroOccurence
void addMacroOccurence(SymbolRoleSet Roles, unsigned Offset, const IdentifierInfo *Name, const MacroInfo *MI)
Adds an occurrence of the given macro at the supplied Offset.
Definition: FileIndexRecord.cpp:40
clang::index::FileIndexRecord::FileIndexRecord
FileIndexRecord(FileID FID, bool IsSystem)
Definition: FileIndexRecord.h:34
SourceLocation.h
clang::index::FileIndexRecord::isSystem
bool isSystem() const
Definition: FileIndexRecord.h:39
llvm::ArrayRef
Definition: LLVM.h:34
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
IndexSymbol.h
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
clang::index::FileIndexRecord::getDeclOccurrencesSortedByOffset
ArrayRef< DeclOccurrence > getDeclOccurrencesSortedByOffset() const
Definition: FileIndexRecord.cpp:20
clang
Definition: CalledOnceCheck.h:17
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:40
unsigned
SM
#define SM(sm)
Definition: Cuda.cpp:78