xref: /llvm-project/clang/include/clang/Index/DeclOccurrence.h (revision 1fa7f05b709748e8a36936cbb5508070c8214354)
1 //===- DeclOccurrence.h - An occurrence of a decl within a 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_INDEX_DECLOCCURRENCE_H
10 #define LLVM_CLANG_INDEX_DECLOCCURRENCE_H
11 
12 #include "clang/AST/DeclBase.h"
13 #include "clang/Basic/LLVM.h"
14 #include "clang/Index/IndexSymbol.h"
15 #include "clang/Lex/MacroInfo.h"
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/PointerUnion.h"
18 #include "llvm/ADT/SmallVector.h"
19 
20 namespace clang {
21 namespace index {
22 
23 struct DeclOccurrence {
24   SymbolRoleSet Roles;
25   unsigned Offset;
26   llvm::PointerUnion<const Decl *, const MacroInfo *> DeclOrMacro;
27   const IdentifierInfo *MacroName = nullptr;
28   SmallVector<SymbolRelation, 3> Relations;
29 
30   DeclOccurrence(SymbolRoleSet R, unsigned Offset, const Decl *D,
31                  ArrayRef<SymbolRelation> Relations)
32       : Roles(R), Offset(Offset), DeclOrMacro(D), Relations(Relations) {}
33   DeclOccurrence(SymbolRoleSet R, unsigned Offset, const IdentifierInfo *Name,
34                  const MacroInfo *MI)
35       : Roles(R), Offset(Offset), DeclOrMacro(MI), MacroName(Name) {}
36 
37   friend bool operator<(const DeclOccurrence &LHS, const DeclOccurrence &RHS) {
38     return LHS.Offset < RHS.Offset;
39   }
40 };
41 
42 } // namespace index
43 } // namespace clang
44 
45 #endif // LLVM_CLANG_INDEX_DECLOCCURRENCE_H
46