clang: lib/Index/IndexingContext.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
17
18using namespace clang;
19using namespace index;
20
22 if (auto *attr = D->getAttr()) {
23 return attr->getGeneratedDeclaration();
24 }
25 return false;
26}
27
30}
31
34}
35
38}
39
42}
43
46}
47
50}
51
56}
57
62 if (!DC)
64
66 if (isa(D)) {
67 D = cast(D)->getPropertyDecl();
68 }
69 return handleDeclOccurrence(D, Loc, false, cast(DC),
70 Roles, Relations,
71 nullptr, OrigD, DC);
72}
73
79 const Expr *RefE) {
81 return true;
82
85 isa(D))) {
86 return true;
87 }
88 return handleDeclOccurrence(D, Loc, true, Parent, Roles, Relations,
89 RefE, nullptr, DC);
90}
91
96 if (!Mod)
97 return;
99 DataConsumer);
102}
103
106 return true;
107
110 if (!IdLocs.empty())
111 Loc = IdLocs.back();
112 else
114
118 return true;
119
123 return true;
124
128 return true;
131 break;
132 }
133 }
134
136 if (!ImportD->isImplicit() && Mod->Parent && !IdLocs.empty()) {
138 DataConsumer);
139 }
140
144
146}
147
151 SD = dyn_cast(D)) {
152 TKind = SD->getSpecializationKind();
153 } else if (const FunctionDecl *FD = dyn_cast(D)) {
154 TKind = FD->getTemplateSpecializationKind();
155 } else if (auto *VD = dyn_cast(D)) {
156 TKind = VD->getTemplateSpecializationKind();
157 } else if (const auto *RD = dyn_cast(D)) {
158 if (RD->getInstantiatedFromMemberClass())
159 TKind = RD->getTemplateSpecializationKind();
160 } else if (const auto *ED = dyn_cast(D)) {
161 if (ED->getInstantiatedFromMemberEnum())
162 TKind = ED->getTemplateSpecializationKind();
163 } else if (isa(D) || isa(D) ||
164 isa(D)) {
167 }
168 switch (TKind) {
170
171
172
173 return isa(D);
175 return false;
179 return true;
180 }
181 llvm_unreachable("invalid TemplateSpecializationKind");
182}
183
184bool IndexingContext::shouldIgnoreIfImplicit(const Decl *D) {
185 if (isa(D))
186 return false;
187 if (isa(D))
188 return false;
189 if (isa(D))
190 return false;
191 if (isa(D))
192 return false;
193 if (isa(D))
194 return false;
195 return true;
196}
197
200 if (const auto *CTSD =
201 dyn_cast(D->getDeclContext()))
203 else if (const auto *RD = dyn_cast(D->getDeclContext()))
205 return nullptr;
206}
207
210 SD = dyn_cast(D)) {
211 const auto *Template = SD->getTemplateInstantiationPattern();
212 if (Template)
213 return Template;
214
215
216 return SD->getSpecializedTemplate()->getTemplatedDecl();
217 } else if (const FunctionDecl *FD = dyn_cast(D)) {
218 return FD->getTemplateInstantiationPattern();
219 } else if (auto *VD = dyn_cast(D)) {
220 return VD->getTemplateInstantiationPattern();
221 } else if (const auto *RD = dyn_cast(D)) {
222 return RD->getInstantiatedFromMemberClass();
223 } else if (const auto *ED = dyn_cast(D)) {
224 return ED->getInstantiatedFromMemberEnum();
225 } else if (isa(D) || isa(D)) {
226 const auto *ND = cast(D);
229 for (const NamedDecl *BaseND : Pattern->lookup(ND->getDeclName())) {
230 if (BaseND->isImplicit())
231 continue;
232 if (BaseND->getKind() == ND->getKind())
233 return BaseND;
234 }
235 }
236 } else if (const auto *ECD = dyn_cast(D)) {
237 if (const auto *ED = dyn_cast(ECD->getDeclContext())) {
239 for (const NamedDecl *BaseECD : Pattern->lookup(ECD->getDeclName()))
240 return BaseECD;
241 }
242 }
243 }
244 return nullptr;
245}
246
248 if (auto VD = dyn_cast(D))
249 return VD->isThisDeclarationADefinition(Ctx);
250
251 if (auto FD = dyn_cast(D))
252 return FD->isThisDeclarationADefinition();
253
254 if (auto TD = dyn_cast(D))
255 return TD->isThisDeclarationADefinition();
256
257 if (auto MD = dyn_cast(D))
258 return MD->isThisDeclarationADefinition() || isa(ContainerDC);
259
261 isa(D) || isa(D) || isa(D) ||
263 return true;
264
265 return false;
266}
267
268
271 !isa(ND)) || isa(ND);
272}
273
276 return nullptr;
277 for (;; Parent = cast(Parent->getDeclContext())) {
278 if (isa(Parent))
279 return nullptr;
280 if (isa(Parent) || isa(Parent))
281 continue;
282 if (auto NS = dyn_cast(Parent)) {
283 if (NS->isAnonymousNamespace())
284 continue;
285 } else if (auto RD = dyn_cast(Parent)) {
286 if (RD->isAnonymousStructOrUnion())
287 continue;
288 } else if (auto ND = dyn_cast(Parent)) {
290 continue;
291 }
293 }
294}
295
298 if (auto TD = dyn_cast(D)) {
299 if (auto TTD = TD->getTemplatedDecl()) {
300 D = TTD;
302 }
303 }
304
305 return D;
306}
307
310 if (!IsRef)
311 return true;
312
313 auto acceptForRelation = [](SymbolRoleSet roles) -> bool {
314 bool accept = false;
316 switch (r) {
323 accept = true;
324 return false;
340 return true;
341 }
342 llvm_unreachable("Unsupported SymbolRole value!");
343 });
344 return accept;
345 };
346
347 for (auto &Rel : Relations) {
348 if (acceptForRelation(Rel.Roles))
349 return true;
350 }
351
352 return false;
353}
354
359 const Expr *OrigE,
360 const Decl *OrigD,
362 if (D->isImplicit() && !isa(D))
363 return true;
365 return true;
366
370 return true;
371
375 return true;
376
380 return true;
383 return true;
384 break;
386 break;
387 }
388 }
389
390 if (!OrigD)
391 OrigD = D;
392
394 if (!IsRef)
395 return true;
397 if ()
398 return true;
400 }
401
402 if (IsRef)
406 else
408
413
415 FinalRelations.reserve(Relations.size()+1);
416
418 auto It = llvm::find_if(FinalRelations, [&](SymbolRelation Elem) -> bool {
420 });
421 if (It != FinalRelations.end()) {
422 It->Roles |= Rel.Roles;
423 } else {
424 FinalRelations.push_back(Rel);
425 }
426 Roles |= Rel.Roles;
427 };
428
434 });
435 } else {
439 });
440 }
441 }
442
443 for (auto &Rel : Relations) {
445 Rel.RelatedSymbol->getCanonicalDecl()));
446 }
447
450}
451
455 if (!shouldIndexMacroOccurrence(false, Loc))
456 return;
459}
460
464 if (!shouldIndexMacroOccurrence(false, Loc))
465 return;
468}
469
473 if (!shouldIndexMacroOccurrence(true, Loc))
474 return;
477}
478
479bool IndexingContext::shouldIndexMacroOccurrence(bool IsRef,
482 return false;
483
486 break;
488 if (!IsRef)
489 return true;
490 break;
492 return true;
493 }
494
498 return false;
499
503 return false;
504
506}
Defines the clang::ASTContext interface.
Defines the C++ template declaration subclasses.
static bool shouldSkipNamelessDecl(const NamedDecl *ND)
Whether the given NamedDecl should be skipped because it has no name.
static const Decl * adjustParent(const Decl *Parent)
static void reportModuleReferences(const Module *Mod, ArrayRef< SourceLocation > IdLocs, const ImportDecl *ImportD, IndexDataConsumer &DataConsumer)
static bool isGeneratedDecl(const Decl *D)
static bool isDeclADefinition(const Decl *D, const DeclContext *ContainerDC, ASTContext &Ctx)
static bool shouldReportOccurrenceForSystemDeclOnlyMode(bool IsRef, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations)
static const Decl * adjustTemplateImplicitInstantiation(const Decl *D)
static const CXXRecordDecl * getDeclContextForTemplateInstationPattern(const Decl *D)
static const Decl * getCanonicalDecl(const Decl *D)
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
const LangOptions & getLangOpts() const
Represents a C++ struct/union/class.
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
Represents a class template specialization, which refers to a class template with a given set of temp...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
bool isInvalidDecl() const
SourceLocation getLocation() const
DeclContext * getDeclContext()
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
bool isEmpty() const
Evaluates true when this declaration name is empty.
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
This represents one expression.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a function declaration or definition.
One of these records is kept for each identifier that is lexed.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
ArrayRef< SourceLocation > getIdentifierLocs() const
Retrieves the locations of each of the identifiers that make up the complete module name in the impor...
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Encapsulates the data about a macro definition (e.g.
Describes a module or submodule.
Module * Parent
The parent of this module.
This represents a decl that may have a name.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
This is a discriminated union of FileInfo and ExpansionInfo.
const FileInfo & getFile() const
virtual bool handleDeclOccurrence(const Decl *D, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations, SourceLocation Loc, ASTNodeInfo ASTNode)
virtual bool handleMacroOccurrence(const IdentifierInfo *Name, const MacroInfo *MI, SymbolRoleSet Roles, SourceLocation Loc)
virtual bool handleModuleOccurrence(const ImportDecl *ImportD, const Module *Mod, SymbolRoleSet Roles, SourceLocation Loc)
bool shouldIndexImplicitInstantiation() const
bool importedModule(const ImportDecl *ImportD)
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations={})
bool shouldIndex(const Decl *D)
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations={}, const Expr *RefE=nullptr)
bool shouldIndexFunctionLocalSymbols() const
void handleMacroReference(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MD)
bool shouldIndexTemplateParameters() const
bool shouldIndexParametersInDeclarations() const
void handleMacroUndefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
static bool isTemplateImplicitInstantiation(const Decl *D)
const LangOptions & getLangOpts() const
void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc, const MacroInfo &MI)
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
SymbolRole
Set of roles that are attributed to symbol occurrences.
@ RelationSpecializationOf
bool isFunctionLocalSymbol(const Decl *D)
bool applyForEachSymbolRoleInterruptible(SymbolRoleSet Roles, llvm::function_ref< bool(SymbolRole)> Fn)
The JSON file list parser is used to communicate input to InstallAPI.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
SystemSymbolFilterKind SystemSymbolFilter
bool IndexParametersInDeclarations
bool IndexImplicitInstantiation
bool IndexTemplateParameters
Represents a relation to another symbol for a symbol occurrence.
const Decl * RelatedSymbol