clang
20.0.0git
lib
Index
IndexingContext.cpp
Go to the documentation of this file.
1
//===- IndexingContext.cpp - Indexing context data ------------------------===//
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
#include "
IndexingContext.h
"
10
#include "
clang/AST/ASTContext.h
"
11
#include "
clang/AST/Attr.h
"
12
#include "
clang/AST/DeclObjC.h
"
13
#include "
clang/AST/DeclTemplate.h
"
14
#include "
clang/Basic/SourceLocation.h
"
15
#include "
clang/Basic/SourceManager.h
"
16
#include "
clang/Index/IndexDataConsumer.h
"
17
18
using namespace
clang
;
19
using namespace
index;
20
21
static
bool
isGeneratedDecl
(
const
Decl
*
D
) {
22
if
(
auto
*
attr
=
D
->
getAttr
<ExternalSourceSymbolAttr>()) {
23
return
attr
->getGeneratedDeclaration();
24
}
25
return
false
;
26
}
27
28
bool
IndexingContext::shouldIndex
(
const
Decl
*
D
) {
29
return
!
isGeneratedDecl
(
D
);
30
}
31
32
const
LangOptions
&
IndexingContext::getLangOpts
()
const
{
33
return
Ctx->
getLangOpts
();
34
}
35
36
bool
IndexingContext::shouldIndexFunctionLocalSymbols
()
const
{
37
return
IndexOpts.
IndexFunctionLocals
;
38
}
39
40
bool
IndexingContext::shouldIndexImplicitInstantiation
()
const
{
41
return
IndexOpts.
IndexImplicitInstantiation
;
42
}
43
44
bool
IndexingContext::shouldIndexParametersInDeclarations
()
const
{
45
return
IndexOpts.
IndexParametersInDeclarations
;
46
}
47
48
bool
IndexingContext::shouldIndexTemplateParameters
()
const
{
49
return
IndexOpts.
IndexTemplateParameters
;
50
}
51
52
bool
IndexingContext::handleDecl
(
const
Decl
*
D
,
53
SymbolRoleSet
Roles,
54
ArrayRef<SymbolRelation>
Relations) {
55
return
handleDecl
(
D
,
D
->
getLocation
(), Roles, Relations);
56
}
57
58
bool
IndexingContext::handleDecl
(
const
Decl
*
D
,
SourceLocation
Loc
,
59
SymbolRoleSet
Roles,
60
ArrayRef<SymbolRelation>
Relations,
61
const
DeclContext
*DC) {
62
if
(!DC)
63
DC =
D
->
getDeclContext
();
64
65
const
Decl
*OrigD =
D
;
66
if
(isa<ObjCPropertyImplDecl>(
D
)) {
67
D
= cast<ObjCPropertyImplDecl>(
D
)->getPropertyDecl();
68
}
69
return
handleDeclOccurrence(
D
,
Loc
,
/*IsRef=*/
false
, cast<Decl>(DC),
70
Roles, Relations,
71
nullptr
, OrigD, DC);
72
}
73
74
bool
IndexingContext::handleReference
(
const
NamedDecl
*
D
,
SourceLocation
Loc
,
75
const
NamedDecl
*
Parent
,
76
const
DeclContext
*DC,
77
SymbolRoleSet
Roles,
78
ArrayRef<SymbolRelation>
Relations,
79
const
Expr
*RefE) {
80
if
(!
shouldIndexFunctionLocalSymbols
() &&
isFunctionLocalSymbol
(
D
))
81
return
true
;
82
83
if
(!
shouldIndexTemplateParameters
() &&
84
(isa<NonTypeTemplateParmDecl>(
D
) || isa<TemplateTypeParmDecl>(
D
) ||
85
isa<TemplateTemplateParmDecl>(
D
))) {
86
return
true
;
87
}
88
return
handleDeclOccurrence(