/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/tools/libclang/CXIndexDataConsumer.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- CXIndexDataConsumer.cpp - Index data consumer for libclang----------===// |
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 "CXIndexDataConsumer.h" |
10 | | #include "CIndexDiagnostic.h" |
11 | | #include "CXTranslationUnit.h" |
12 | | #include "clang/AST/Attr.h" |
13 | | #include "clang/AST/DeclCXX.h" |
14 | | #include "clang/AST/DeclTemplate.h" |
15 | | #include "clang/AST/DeclVisitor.h" |
16 | | #include "clang/Frontend/ASTUnit.h" |
17 | | |
18 | | using namespace clang; |
19 | | using namespace clang::index; |
20 | | using namespace cxindex; |
21 | | using namespace cxcursor; |
22 | | |
23 | | namespace { |
24 | | class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> { |
25 | | CXIndexDataConsumer &DataConsumer; |
26 | | SourceLocation DeclLoc; |
27 | | const DeclContext *LexicalDC; |
28 | | |
29 | | public: |
30 | | IndexingDeclVisitor(CXIndexDataConsumer &dataConsumer, SourceLocation Loc, |
31 | | const DeclContext *lexicalDC) |
32 | 365 | : DataConsumer(dataConsumer), DeclLoc(Loc), LexicalDC(lexicalDC) { } |
33 | | |
34 | 89 | bool VisitFunctionDecl(const FunctionDecl *D) { |
35 | 89 | DataConsumer.handleFunction(D); |
36 | 89 | return true; |
37 | 89 | } |
38 | | |
39 | 55 | bool VisitVarDecl(const VarDecl *D) { |
40 | 55 | DataConsumer.handleVar(D); |
41 | 55 | return true; |
42 | 55 | } |
43 | | |
44 | 13 | bool VisitFieldDecl(const FieldDecl *D) { |
45 | 13 | DataConsumer.handleField(D); |
46 | 13 | return true; |
47 | 13 | } |
48 | | |
49 | 0 | bool VisitMSPropertyDecl(const MSPropertyDecl *D) { |
50 | 0 | return true; |
51 | 0 | } |
52 | | |
53 | 2 | bool VisitEnumConstantDecl(const EnumConstantDecl *D) { |
54 | 2 | DataConsumer.handleEnumerator(D); |
55 | 2 | return true; |
56 | 2 | } |
57 | | |
58 | 12 | bool VisitTypedefNameDecl(const TypedefNameDecl *D) { |
59 | 12 | DataConsumer.handleTypedefName(D); |
60 | 12 | return true; |
61 | 12 | } |
62 | | |
63 | 39 | bool VisitTagDecl(const TagDecl *D) { |
64 | 39 | DataConsumer.handleTagDecl(D); |
65 | 39 | return true; |
66 | 39 | } |
67 | | |
68 | 27 | bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) { |
69 | 27 | DataConsumer.handleObjCInterface(D); |
70 | 27 | return true; |
71 | 27 | } |
72 | | |
73 | 5 | bool VisitObjCProtocolDecl(const ObjCProtocolDecl *D) { |
74 | 5 | DataConsumer.handleObjCProtocol(D); |
75 | 5 | return true; |
76 | 5 | } |
77 | | |
78 | 4 | bool VisitObjCImplementationDecl(const ObjCImplementationDecl *D) { |
79 | 4 | DataConsumer.handleObjCImplementation(D); |
80 | 4 | return true; |
81 | 4 | } |
82 | | |
83 | 5 | bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { |
84 | 5 | DataConsumer.handleObjCCategory(D); |
85 | 5 | return true; |
86 | 5 | } |
87 | | |
88 | 0 | bool VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) { |
89 | 0 | DataConsumer.handleObjCCategoryImpl(D); |
90 | 0 | return true; |
91 | 0 | } |
92 | | |
93 | 48 | bool VisitObjCMethodDecl(const ObjCMethodDecl *D) { |
94 | 48 | if (isa<ObjCImplDecl>(LexicalDC) && !D->isThisDeclarationADefinition()9 ) |
95 | 6 | DataConsumer.handleSynthesizedObjCMethod(D, DeclLoc, LexicalDC); |
96 | 42 | else |
97 | 42 | DataConsumer.handleObjCMethod(D, DeclLoc); |
98 | 48 | return true; |
99 | 48 | } |
100 | | |
101 | 8 | bool VisitObjCPropertyDecl(const ObjCPropertyDecl *D) { |
102 | 8 | DataConsumer.handleObjCProperty(D); |
103 | 8 | return true; |
104 | 8 | } |
105 | | |
106 | 4 | bool VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) { |
107 | 4 | DataConsumer.handleSynthesizedObjCProperty(D); |
108 | 4 | return true; |
109 | 4 | } |
110 | | |
111 | 8 | bool VisitNamespaceDecl(const NamespaceDecl *D) { |
112 | 8 | DataConsumer.handleNamespace(D); |
113 | 8 | return true; |
114 | 8 | } |
115 | | |
116 | 1 | bool VisitUsingDecl(const UsingDecl *D) { |
117 | 1 | return true; |
118 | 1 | } |
119 | | |
120 | 0 | bool VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) { |
121 | 0 | return true; |
122 | 0 | } |
123 | | |
124 | 0 | bool VisitClassTemplateDecl(const ClassTemplateDecl *D) { |
125 | 0 | DataConsumer.handleClassTemplate(D); |
126 | 0 | return true; |
127 | 0 | } |
128 | | |
129 | | bool VisitClassTemplateSpecializationDecl(const |
130 | 2 | ClassTemplateSpecializationDecl *D) { |
131 | 2 | DataConsumer.handleTagDecl(D); |
132 | 2 | return true; |
133 | 2 | } |
134 | | |
135 | 0 | bool VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { |
136 | 0 | DataConsumer.handleFunctionTemplate(D); |
137 | 0 | return true; |
138 | 0 | } |
139 | | |
140 | 0 | bool VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) { |
141 | 0 | DataConsumer.handleTypeAliasTemplate(D); |
142 | 0 | return true; |
143 | 0 | } |
144 | | |
145 | 43 | bool VisitImportDecl(const ImportDecl *D) { |
146 | 43 | DataConsumer.importedModule(D); |
147 | 43 | return true; |
148 | 43 | } |
149 | | }; |
150 | | |
151 | 1.91k | CXSymbolRole getSymbolRole(SymbolRoleSet Role) { |
152 | | // CXSymbolRole mirrors low 9 bits of clang::index::SymbolRole. |
153 | 1.91k | return CXSymbolRole(static_cast<uint32_t>(Role) & ((1 << 9) - 1)); |
154 | 1.91k | } |
155 | | } |
156 | | |
157 | | bool CXIndexDataConsumer::handleDeclOccurrence( |
158 | | const Decl *D, SymbolRoleSet Roles, ArrayRef<SymbolRelation> Relations, |
159 | 2.23k | SourceLocation Loc, ASTNodeInfo ASTNode) { |
160 | 2.23k | Loc = getASTContext().getSourceManager().getFileLoc(Loc); |
161 | | |
162 | 2.23k | if (Roles & (unsigned)SymbolRole::Reference) { |
163 | 1.91k | const NamedDecl *ND = dyn_cast<NamedDecl>(D); |
164 | 1.91k | if (!ND) |
165 | 0 | return true; |
166 | | |
167 | 1.91k | if (auto *ObjCID = dyn_cast_or_null<ObjCInterfaceDecl>(ASTNode.OrigD)) { |
168 | 27 | if (!ObjCID->isThisDeclarationADefinition() && |
169 | 27 | ObjCID->getLocation() == Loc9 ) { |
170 | | // The libclang API treats this as ObjCClassRef declaration. |
171 | 6 | IndexingDeclVisitor(*this, Loc, nullptr).Visit(ObjCID); |
172 | 6 | return true; |
173 | 6 | } |
174 | 27 | } |
175 | 1.91k | if (auto *ObjCPD = dyn_cast_or_null<ObjCProtocolDecl>(ASTNode.OrigD)) { |
176 | 5 | if (!ObjCPD->isThisDeclarationADefinition() && |
177 | 5 | ObjCPD->getLocation() == Loc1 ) { |
178 | | // The libclang API treats this as ObjCProtocolRef declaration. |
179 | 1 | IndexingDeclVisitor(*this, Loc, nullptr).Visit(ObjCPD); |
180 | 1 | return true; |
181 | 1 | } |
182 | 5 | } |
183 | | |
184 | 1.91k | CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct; |
185 | 1.91k | if (Roles & (unsigned)SymbolRole::Implicit) { |
186 | 8 | Kind = CXIdxEntityRef_Implicit; |
187 | 8 | } |
188 | 1.91k | CXSymbolRole CXRole = getSymbolRole(Roles); |
189 | | |
190 | 1.91k | CXCursor Cursor; |
191 | 1.91k | if (ASTNode.OrigE) { |
192 | 1.81k | Cursor = cxcursor::MakeCXCursor(ASTNode.OrigE, |
193 | 1.81k | cast<Decl>(ASTNode.ContainerDC), |
194 | 1.81k | getCXTU()); |
195 | 1.81k | } else { |
196 | 94 | if (ASTNode.OrigD) { |
197 | 94 | if (auto *OrigND = dyn_cast<NamedDecl>(ASTNode.OrigD)) |
198 | 94 | Cursor = getRefCursor(OrigND, Loc); |
199 | 0 | else |
200 | 0 | Cursor = MakeCXCursor(ASTNode.OrigD, CXTU); |
201 | 94 | } else { |
202 | 0 | Cursor = getRefCursor(ND, Loc); |
203 | 0 | } |
204 | 94 | } |
205 | 1.91k | handleReference(ND, Loc, Cursor, |
206 | 1.91k | dyn_cast_or_null<NamedDecl>(ASTNode.Parent), |
207 | 1.91k | ASTNode.ContainerDC, ASTNode.OrigE, Kind, CXRole); |
208 | | |
209 | 1.91k | } else { |
210 | 315 | const DeclContext *LexicalDC = ASTNode.ContainerDC; |
211 | 315 | if (!LexicalDC) { |
212 | 0 | for (const auto &SymRel : Relations) { |
213 | 0 | if (SymRel.Roles & (unsigned)SymbolRole::RelationChildOf) |
214 | 0 | LexicalDC = dyn_cast<DeclContext>(SymRel.RelatedSymbol); |
215 | 0 | } |
216 | 0 | } |
217 | 315 | IndexingDeclVisitor(*this, Loc, LexicalDC).Visit(ASTNode.OrigD); |
218 | 315 | } |
219 | | |
220 | 2.22k | return !shouldAbort(); |
221 | 2.23k | } |
222 | | |
223 | | bool CXIndexDataConsumer::handleModuleOccurrence(const ImportDecl *ImportD, |
224 | | const Module *Mod, |
225 | | SymbolRoleSet Roles, |
226 | 45 | SourceLocation Loc) { |
227 | 45 | if (Roles & (SymbolRoleSet)SymbolRole::Declaration) |
228 | 43 | IndexingDeclVisitor(*this, SourceLocation(), nullptr).Visit(ImportD); |
229 | 45 | return !shouldAbort(); |
230 | 45 | } |
231 | | |
232 | 48 | void CXIndexDataConsumer::finish() { |
233 | 48 | indexDiagnostics(); |
234 | 48 | } |
235 | | |
236 | | |
237 | | CXIndexDataConsumer::ObjCProtocolListInfo::ObjCProtocolListInfo( |
238 | | const ObjCProtocolList &ProtList, |
239 | | CXIndexDataConsumer &IdxCtx, |
240 | 30 | ScratchAlloc &SA) { |
241 | 30 | ObjCInterfaceDecl::protocol_loc_iterator LI = ProtList.loc_begin(); |
242 | 30 | for (ObjCInterfaceDecl::protocol_iterator |
243 | 32 | I = ProtList.begin(), E = ProtList.end(); I != E; ++I, ++LI2 ) { |
244 | 2 | SourceLocation Loc = *LI; |
245 | 2 | ObjCProtocolDecl *PD = *I; |
246 | 2 | ProtEntities.push_back(EntityInfo()); |
247 | 2 | IdxCtx.getEntityInfo(PD, ProtEntities.back(), SA); |
248 | 2 | CXIdxObjCProtocolRefInfo ProtInfo = { nullptr, |
249 | 2 | MakeCursorObjCProtocolRef(PD, Loc, IdxCtx.CXTU), |
250 | 2 | IdxCtx.getIndexLoc(Loc) }; |
251 | 2 | ProtInfos.push_back(ProtInfo); |
252 | | |
253 | 2 | if (IdxCtx.shouldSuppressRefs()) |
254 | 1 | IdxCtx.markEntityOccurrenceInFile(PD, Loc); |
255 | 2 | } |
256 | | |
257 | 32 | for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i2 ) |
258 | 2 | ProtInfos[i].protocol = &ProtEntities[i]; |
259 | | |
260 | 32 | for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i2 ) |
261 | 2 | Prots.push_back(&ProtInfos[i]); |
262 | 30 | } |
263 | | |
264 | | |
265 | | IBOutletCollectionInfo::IBOutletCollectionInfo( |
266 | | const IBOutletCollectionInfo &other) |
267 | 3 | : AttrInfo(CXIdxAttr_IBOutletCollection, other.cursor, other.loc, other.A) { |
268 | | |
269 | 3 | IBCollInfo.attrInfo = this; |
270 | 3 | IBCollInfo.classCursor = other.IBCollInfo.classCursor; |
271 | 3 | IBCollInfo.classLoc = other.IBCollInfo.classLoc; |
272 | 3 | if (other.IBCollInfo.objcClass) { |
273 | 0 | ClassInfo = other.ClassInfo; |
274 | 0 | IBCollInfo.objcClass = &ClassInfo; |
275 | 0 | } else |
276 | 3 | IBCollInfo.objcClass = nullptr; |
277 | 3 | } |
278 | | |
279 | | AttrListInfo::AttrListInfo(const Decl *D, CXIndexDataConsumer &IdxCtx) |
280 | 42 | : SA(IdxCtx), ref_cnt(0) { |
281 | | |
282 | 42 | if (!D->hasAttrs()) |
283 | 0 | return; |
284 | | |
285 | 45 | for (const auto *A : D->attrs())42 { |
286 | 45 | CXCursor C = MakeCXCursor(A, D, IdxCtx.CXTU); |
287 | 45 | CXIdxLoc Loc = IdxCtx.getIndexLoc(A->getLocation()); |
288 | 45 | switch (C.kind) { |
289 | 42 | default: |
290 | 42 | Attrs.push_back(AttrInfo(CXIdxAttr_Unexposed, C, Loc, A)); |
291 | 42 | break; |
292 | 0 | case CXCursor_IBActionAttr: |
293 | 0 | Attrs.push_back(AttrInfo(CXIdxAttr_IBAction, C, Loc, A)); |
294 | 0 | break; |
295 | 0 | case CXCursor_IBOutletAttr: |
296 | 0 | Attrs.push_back(AttrInfo(CXIdxAttr_IBOutlet, C, Loc, A)); |
297 | 0 | break; |
298 | 3 | case CXCursor_IBOutletCollectionAttr: |
299 | 3 | IBCollAttrs.push_back(IBOutletCollectionInfo(C, Loc, A)); |
300 | 3 | break; |
301 | 45 | } |
302 | 45 | } |
303 | | |
304 | 45 | for (unsigned i = 0, e = IBCollAttrs.size(); 42 i != e; ++i3 ) { |
305 | 3 | IBOutletCollectionInfo &IBInfo = IBCollAttrs[i]; |
306 | 3 | CXAttrs.push_back(&IBInfo); |
307 | | |
308 | 3 | const IBOutletCollectionAttr * |
309 | 3 | IBAttr = cast<IBOutletCollectionAttr>(IBInfo.A); |
310 | 3 | SourceLocation InterfaceLocStart = |
311 | 3 | IBAttr->getInterfaceLoc()->getTypeLoc().getBeginLoc(); |
312 | 3 | IBInfo.IBCollInfo.attrInfo = &IBInfo; |
313 | 3 | IBInfo.IBCollInfo.classLoc = IdxCtx.getIndexLoc(InterfaceLocStart); |
314 | 3 | IBInfo.IBCollInfo.objcClass = nullptr; |
315 | 3 | IBInfo.IBCollInfo.classCursor = clang_getNullCursor(); |
316 | 3 | QualType Ty = IBAttr->getInterface(); |
317 | 3 | if (const ObjCObjectType *ObjectTy = Ty->getAs<ObjCObjectType>()) { |
318 | 3 | if (const ObjCInterfaceDecl *InterD = ObjectTy->getInterface()) { |
319 | 3 | IdxCtx.getEntityInfo(InterD, IBInfo.ClassInfo, SA); |
320 | 3 | IBInfo.IBCollInfo.objcClass = &IBInfo.ClassInfo; |
321 | 3 | IBInfo.IBCollInfo.classCursor = |
322 | 3 | MakeCursorObjCClassRef(InterD, InterfaceLocStart, IdxCtx.CXTU); |
323 | 3 | } |
324 | 3 | } |
325 | 3 | } |
326 | | |
327 | 84 | for (unsigned i = 0, e = Attrs.size(); i != e; ++i42 ) |
328 | 42 | CXAttrs.push_back(&Attrs[i]); |
329 | 42 | } |
330 | | |
331 | | IntrusiveRefCntPtr<AttrListInfo> |
332 | 42 | AttrListInfo::create(const Decl *D, CXIndexDataConsumer &IdxCtx) { |
333 | 42 | ScratchAlloc SA(IdxCtx); |
334 | 42 | AttrListInfo *attrs = SA.allocate<AttrListInfo>(); |
335 | 42 | return new (attrs) AttrListInfo(D, IdxCtx); |
336 | 42 | } |
337 | | |
338 | | CXIndexDataConsumer::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D, |
339 | | CXIndexDataConsumer &IdxCtx, |
340 | 34 | ScratchAlloc &SA) { |
341 | 34 | for (const auto &Base : D->bases()) { |
342 | 3 | BaseEntities.push_back(EntityInfo()); |
343 | 3 | const NamedDecl *BaseD = nullptr; |
344 | 3 | QualType T = Base.getType(); |
345 | 3 | SourceLocation Loc = getBaseLoc(Base); |
346 | | |
347 | 3 | if (const TypedefType *TDT = T->getAs<TypedefType>()) { |
348 | 0 | BaseD = TDT->getDecl(); |
349 | 3 | } else if (const TemplateSpecializationType * |
350 | 3 | TST = T->getAs<TemplateSpecializationType>()) { |
351 | 1 | BaseD = TST->getTemplateName().getAsTemplateDecl(); |
352 | 2 | } else if (const RecordType *RT = T->getAs<RecordType>()) { |
353 | 2 | BaseD = RT->getDecl(); |
354 | 2 | } |
355 | | |
356 | 3 | if (BaseD) |
357 | 3 | IdxCtx.getEntityInfo(BaseD, BaseEntities.back(), SA); |
358 | 3 | CXIdxBaseClassInfo BaseInfo = { nullptr, |
359 | 3 | MakeCursorCXXBaseSpecifier(&Base, IdxCtx.CXTU), |
360 | 3 | IdxCtx.getIndexLoc(Loc) }; |
361 | 3 | BaseInfos.push_back(BaseInfo); |
362 | 3 | } |
363 | | |
364 | 37 | for (unsigned i = 0, e = BaseInfos.size(); i != e; ++i3 ) { |
365 | 3 | if (BaseEntities[i].name && BaseEntities[i].USR) |
366 | 3 | BaseInfos[i].base = &BaseEntities[i]; |
367 | 3 | } |
368 | | |
369 | 37 | for (unsigned i = 0, e = BaseInfos.size(); i != e; ++i3 ) |
370 | 3 | CXBases.push_back(&BaseInfos[i]); |
371 | 34 | } |
372 | | |
373 | | SourceLocation CXIndexDataConsumer::CXXBasesListInfo::getBaseLoc( |
374 | 3 | const CXXBaseSpecifier &Base) const { |
375 | 3 | SourceLocation Loc = Base.getSourceRange().getBegin(); |
376 | 3 | TypeLoc TL; |
377 | 3 | if (Base.getTypeSourceInfo()) |
378 | 3 | TL = Base.getTypeSourceInfo()->getTypeLoc(); |
379 | 3 | if (TL.isNull()) |
380 | 0 | return Loc; |
381 | | |
382 | 3 | if (QualifiedTypeLoc QL = TL.getAs<QualifiedTypeLoc>()) |
383 | 0 | TL = QL.getUnqualifiedLoc(); |
384 | | |
385 | 3 | if (ElaboratedTypeLoc EL = TL.getAs<ElaboratedTypeLoc>()) |
386 | 0 | return EL.getNamedTypeLoc().getBeginLoc(); |
387 | 3 | if (DependentNameTypeLoc DL = TL.getAs<DependentNameTypeLoc>()) |
388 | 0 | return DL.getNameLoc(); |
389 | 3 | if (DependentTemplateSpecializationTypeLoc DTL = |
390 | 3 | TL.getAs<DependentTemplateSpecializationTypeLoc>()) |
391 | 0 | return DTL.getTemplateNameLoc(); |
392 | | |
393 | 3 | return Loc; |
394 | 3 | } |
395 | | |
396 | 2.34k | const char *ScratchAlloc::toCStr(StringRef Str) { |
397 | 2.34k | if (Str.empty()) |
398 | 0 | return ""; |
399 | 2.34k | if (Str.data()[Str.size()] == '\0') |
400 | 2.32k | return Str.data(); |
401 | 19 | return copyCStr(Str); |
402 | 2.34k | } |
403 | | |
404 | 6.00k | const char *ScratchAlloc::copyCStr(StringRef Str) { |
405 | 6.00k | char *buf = IdxCtx.StrScratch.Allocate<char>(Str.size() + 1); |
406 | 6.00k | std::uninitialized_copy(Str.begin(), Str.end(), buf); |
407 | 6.00k | buf[Str.size()] = '\0'; |
408 | 6.00k | return buf; |
409 | 6.00k | } |
410 | | |
411 | 87 | void CXIndexDataConsumer::setASTContext(ASTContext &ctx) { |
412 | 87 | Ctx = &ctx; |
413 | 87 | cxtu::getASTUnit(CXTU)->setASTContext(&ctx); |
414 | 87 | } |
415 | | |
416 | 87 | void CXIndexDataConsumer::setPreprocessor(std::shared_ptr<Preprocessor> PP) { |
417 | 87 | cxtu::getASTUnit(CXTU)->setPreprocessor(std::move(PP)); |
418 | 87 | } |
419 | | |
420 | 1.87k | bool CXIndexDataConsumer::isFunctionLocalDecl(const Decl *D) { |
421 | 1.87k | assert(D); |
422 | | |
423 | 1.87k | if (!D->getParentFunctionOrMethod()) |
424 | 1.87k | return false; |
425 | | |
426 | 0 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) { |
427 | 0 | switch (ND->getFormalLinkage()) { |
428 | 0 | case NoLinkage: |
429 | 0 | case InternalLinkage: |
430 | 0 | return true; |
431 | 0 | case VisibleNoLinkage: |
432 | 0 | case ModuleInternalLinkage: |
433 | 0 | case UniqueExternalLinkage: |
434 | 0 | llvm_unreachable("Not a sema linkage"); |
435 | 0 | case ModuleLinkage: |
436 | 0 | case ExternalLinkage: |
437 | 0 | return false; |
438 | 0 | } |
439 | 0 | } |
440 | | |
441 | 0 | return true; |
442 | 0 | } |
443 | | |
444 | 2.44k | bool CXIndexDataConsumer::shouldAbort() { |
445 | 2.44k | if (!CB.abortQuery) |
446 | 0 | return false; |
447 | 2.44k | return CB.abortQuery(ClientData, nullptr); |
448 | 2.44k | } |
449 | | |
450 | 48 | void CXIndexDataConsumer::enteredMainFile(const FileEntry *File) { |
451 | 48 | if (File && CB.enteredMainFile42 ) { |
452 | 42 | CXIdxClientFile idxFile = |
453 | 42 | CB.enteredMainFile(ClientData, |
454 | 42 | static_cast<CXFile>(const_cast<FileEntry *>(File)), |
455 | 42 | nullptr); |
456 | 42 | FileMap[File] = idxFile; |
457 | 42 | } |
458 | 48 | } |
459 | | |
460 | | void CXIndexDataConsumer::ppIncludedFile(SourceLocation hashLoc, |
461 | | StringRef filename, |
462 | | Optional<FileEntryRef> File, |
463 | | bool isImport, bool isAngled, |
464 | 45 | bool isModuleImport) { |
465 | 45 | if (!CB.ppIncludedFile) |
466 | 0 | return; |
467 | | |
468 | 45 | const FileEntry *FE = File ? &File->getFileEntry() : nullptr0 ; |
469 | | |
470 | 45 | ScratchAlloc SA(*this); |
471 | 45 | CXIdxIncludedFileInfo Info = { getIndexLoc(hashLoc), |
472 | 45 | SA.toCStr(filename), |
473 | 45 | static_cast<CXFile>( |
474 | 45 | const_cast<FileEntry *>(FE)), |
475 | 45 | isImport, isAngled, isModuleImport }; |
476 | 45 | CXIdxClientFile idxFile = CB.ppIncludedFile(ClientData, &Info); |
477 | 45 | FileMap[FE] = idxFile; |
478 | 45 | } |
479 | | |
480 | 43 | void CXIndexDataConsumer::importedModule(const ImportDecl *ImportD) { |
481 | 43 | if (!CB.importedASTFile) |
482 | 0 | return; |
483 | | |
484 | 43 | Module *Mod = ImportD->getImportedModule(); |
485 | 43 | if (!Mod) |
486 | 0 | return; |
487 | | |
488 | | // If the imported module is part of the top-level module that we're |
489 | | // indexing, it doesn't correspond to an imported AST file. |
490 | | // FIXME: This assumes that AST files and top-level modules directly |
491 | | // correspond, which is unlikely to remain true forever. |
492 | 43 | if (Module *SrcMod = ImportD->getImportedOwningModule()) |
493 | 26 | if (SrcMod->getTopLevelModule() == Mod->getTopLevelModule()) |
494 | 23 | return; |
495 | | |
496 | 20 | FileEntry *FE = nullptr; |
497 | 20 | if (auto File = Mod->getASTFile()) |
498 | 20 | FE = const_cast<FileEntry *>(&File->getFileEntry()); |
499 | 20 | CXIdxImportedASTFileInfo Info = {static_cast<CXFile>(FE), Mod, |
500 | 20 | getIndexLoc(ImportD->getLocation()), |
501 | 20 | ImportD->isImplicit()}; |
502 | 20 | CXIdxClientASTFile astFile = CB.importedASTFile(ClientData, &Info); |
503 | 20 | (void)astFile; |
504 | 20 | } |
505 | | |
506 | 4 | void CXIndexDataConsumer::importedPCH(const FileEntry *File) { |
507 | 4 | if (!CB.importedASTFile) |
508 | 0 | return; |
509 | | |
510 | 4 | CXIdxImportedASTFileInfo Info = { |
511 | 4 | static_cast<CXFile>( |
512 | 4 | const_cast<FileEntry *>(File)), |
513 | 4 | /*module=*/nullptr, |
514 | 4 | getIndexLoc(SourceLocation()), |
515 | 4 | /*isImplicit=*/false |
516 | 4 | }; |
517 | 4 | CXIdxClientASTFile astFile = CB.importedASTFile(ClientData, &Info); |
518 | 4 | (void)astFile; |
519 | 4 | } |
520 | | |
521 | 48 | void CXIndexDataConsumer::startedTranslationUnit() { |
522 | 48 | CXIdxClientContainer idxCont = nullptr; |
523 | 48 | if (CB.startedTranslationUnit) |
524 | 48 | idxCont = CB.startedTranslationUnit(ClientData, nullptr); |
525 | 48 | addContainerInMap(Ctx->getTranslationUnitDecl(), idxCont); |
526 | 48 | } |
527 | | |
528 | 57 | void CXIndexDataConsumer::indexDiagnostics() { |
529 | 57 | if (!hasDiagnosticCallback()) |
530 | 0 | return; |
531 | | |
532 | 57 | CXDiagnosticSetImpl *DiagSet = cxdiag::lazyCreateDiags(getCXTU()); |
533 | 57 | handleDiagnosticSet(DiagSet); |
534 | 57 | } |
535 | | |
536 | 57 | void CXIndexDataConsumer::handleDiagnosticSet(CXDiagnostic CXDiagSet) { |
537 | 57 | if (!CB.diagnostic) |
538 | 0 | return; |
539 | | |
540 | 57 | CB.diagnostic(ClientData, CXDiagSet, nullptr); |
541 | 57 | } |
542 | | |
543 | | bool CXIndexDataConsumer::handleDecl(const NamedDecl *D, |
544 | | SourceLocation Loc, CXCursor Cursor, |
545 | | DeclInfo &DInfo, |
546 | | const DeclContext *LexicalDC, |
547 | 316 | const DeclContext *SemaDC) { |
548 | 316 | if (!CB.indexDeclaration || !D) |
549 | 0 | return false; |
550 | 316 | if (D->isImplicit() && shouldIgnoreIfImplicit(D)14 ) |
551 | 0 | return false; |
552 | | |
553 | 316 | ScratchAlloc SA(*this); |
554 | 316 | getEntityInfo(D, DInfo.EntInfo, SA); |
555 | 316 | if ((!shouldIndexFunctionLocalSymbols() && !DInfo.EntInfo.USR295 ) |
556 | 316 | || Loc.isInvalid()) |
557 | 0 | return false; |
558 | | |
559 | 316 | if (!LexicalDC) |
560 | 310 | LexicalDC = D->getLexicalDeclContext(); |
561 | | |
562 | 316 | if (shouldSuppressRefs()) |
563 | 15 | markEntityOccurrenceInFile(D, Loc); |
564 | | |
565 | 316 | DInfo.entityInfo = &DInfo.EntInfo; |
566 | 316 | DInfo.cursor = Cursor; |
567 | 316 | DInfo.loc = getIndexLoc(Loc); |
568 | 316 | DInfo.isImplicit = D->isImplicit(); |
569 | | |
570 | 316 | DInfo.attributes = DInfo.EntInfo.attributes; |
571 | 316 | DInfo.numAttributes = DInfo.EntInfo.numAttributes; |
572 | | |
573 | 316 | if (!SemaDC) |
574 | 310 | SemaDC = D->getDeclContext(); |
575 | 316 | getContainerInfo(SemaDC, DInfo.SemanticContainer); |
576 | 316 | DInfo.semanticContainer = &DInfo.SemanticContainer; |
577 | | |
578 | 316 | if (LexicalDC == SemaDC) { |
579 | 303 | DInfo.lexicalContainer = &DInfo.SemanticContainer; |
580 | 303 | } else if (13 isTemplateImplicitInstantiation(D)13 ) { |
581 | | // Implicit instantiations have the lexical context of where they were |
582 | | // instantiated first. We choose instead the semantic context because: |
583 | | // 1) at the time that we see the instantiation we have not seen the |
584 | | // function where it occurred yet. |
585 | | // 2) the lexical context of the first instantiation is not useful |
586 | | // information anyway. |
587 | 0 | DInfo.lexicalContainer = &DInfo.SemanticContainer; |
588 | 13 | } else { |
589 | 13 | getContainerInfo(LexicalDC, DInfo.LexicalContainer); |
590 | 13 | DInfo.lexicalContainer = &DInfo.LexicalContainer; |
591 | 13 | } |
592 | | |
593 | 316 | if (DInfo.isContainer) { |
594 | 125 | getContainerInfo(getEntityContainer(D), DInfo.DeclAsContainer); |
595 | 125 | DInfo.declAsContainer = &DInfo.DeclAsContainer; |
596 | 125 | } |
597 | | |
598 | 316 | CB.indexDeclaration(ClientData, &DInfo); |
599 | 316 | return true; |
600 | 316 | } |
601 | | |
602 | | bool CXIndexDataConsumer::handleObjCContainer(const ObjCContainerDecl *D, |
603 | | SourceLocation Loc, CXCursor Cursor, |
604 | 40 | ObjCContainerDeclInfo &ContDInfo) { |
605 | 40 | ContDInfo.ObjCContDeclInfo.declInfo = &ContDInfo; |
606 | 40 | return handleDecl(D, Loc, Cursor, ContDInfo); |
607 | 40 | } |
608 | | |
609 | 89 | bool CXIndexDataConsumer::handleFunction(const FunctionDecl *D) { |
610 | 89 | bool isDef = D->isThisDeclarationADefinition(); |
611 | 89 | bool isContainer = isDef; |
612 | 89 | bool isSkipped = false; |
613 | 89 | if (D->hasSkippedBody()) { |
614 | 9 | isSkipped = true; |
615 | 9 | isDef = true; |
616 | 9 | isContainer = false; |
617 | 9 | } |
618 | | |
619 | 89 | DeclInfo DInfo(!D->isFirstDecl(), isDef, isContainer); |
620 | 89 | if (isSkipped) |
621 | 9 | DInfo.flags |= CXIdxDeclFlag_Skipped; |
622 | 89 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
623 | 89 | } |
624 | | |
625 | 55 | bool CXIndexDataConsumer::handleVar(const VarDecl *D) { |
626 | 55 | DeclInfo DInfo(!D->isFirstDecl(), D->isThisDeclarationADefinition(), |
627 | 55 | /*isContainer=*/false); |
628 | 55 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
629 | 55 | } |
630 | | |
631 | 13 | bool CXIndexDataConsumer::handleField(const FieldDecl *D) { |
632 | 13 | DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true, |
633 | 13 | /*isContainer=*/false); |
634 | 13 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
635 | 13 | } |
636 | | |
637 | 2 | bool CXIndexDataConsumer::handleEnumerator(const EnumConstantDecl *D) { |
638 | 2 | DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true, |
639 | 2 | /*isContainer=*/false); |
640 | 2 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
641 | 2 | } |
642 | | |
643 | 41 | bool CXIndexDataConsumer::handleTagDecl(const TagDecl *D) { |
644 | 41 | if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(D)) |
645 | 35 | return handleCXXRecordDecl(CXXRD, D); |
646 | | |
647 | 6 | DeclInfo DInfo(!D->isFirstDecl(), D->isThisDeclarationADefinition(), |
648 | 6 | D->isThisDeclarationADefinition()); |
649 | 6 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
650 | 41 | } |
651 | | |
652 | 12 | bool CXIndexDataConsumer::handleTypedefName(const TypedefNameDecl *D) { |
653 | 12 | DeclInfo DInfo(!D->isFirstDecl(), /*isDefinition=*/true, |
654 | 12 | /*isContainer=*/false); |
655 | 12 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
656 | 12 | } |
657 | | |
658 | 27 | bool CXIndexDataConsumer::handleObjCInterface(const ObjCInterfaceDecl *D) { |
659 | | // For @class forward declarations, suppress them the same way as references. |
660 | 27 | if (!D->isThisDeclarationADefinition()) { |
661 | 6 | if (shouldSuppressRefs() && markEntityOccurrenceInFile(D, D->getLocation())2 ) |
662 | 1 | return false; // already occurred. |
663 | | |
664 | | // FIXME: This seems like the wrong definition for redeclaration. |
665 | 5 | bool isRedeclaration = D->hasDefinition() || D->getPreviousDecl()4 ; |
666 | 5 | ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, isRedeclaration, |
667 | 5 | /*isImplementation=*/false); |
668 | 5 | return handleObjCContainer(D, D->getLocation(), |
669 | 5 | MakeCursorObjCClassRef(D, D->getLocation(), |
670 | 5 | CXTU), |
671 | 5 | ContDInfo); |
672 | 6 | } |
673 | | |
674 | 21 | ScratchAlloc SA(*this); |
675 | | |
676 | 21 | CXIdxBaseClassInfo BaseClass; |
677 | 21 | EntityInfo BaseEntity; |
678 | 21 | BaseClass.cursor = clang_getNullCursor(); |
679 | 21 | if (ObjCInterfaceDecl *SuperD = D->getSuperClass()) { |
680 | 3 | getEntityInfo(SuperD, BaseEntity, SA); |
681 | 3 | SourceLocation SuperLoc = D->getSuperClassLoc(); |
682 | 3 | BaseClass.base = &BaseEntity; |
683 | 3 | BaseClass.cursor = MakeCursorObjCSuperClassRef(SuperD, SuperLoc, CXTU); |
684 | 3 | BaseClass.loc = getIndexLoc(SuperLoc); |
685 | | |
686 | 3 | if (shouldSuppressRefs()) |
687 | 1 | markEntityOccurrenceInFile(SuperD, SuperLoc); |
688 | 3 | } |
689 | | |
690 | 21 | ObjCProtocolList EmptyProtoList; |
691 | 21 | ObjCProtocolListInfo ProtInfo(D->isThisDeclarationADefinition() |
692 | 21 | ? D->getReferencedProtocols() |
693 | 21 | : EmptyProtoList0 , |
694 | 21 | *this, SA); |
695 | | |
696 | 21 | ObjCInterfaceDeclInfo InterInfo(D); |
697 | 21 | InterInfo.ObjCProtoListInfo = ProtInfo.getListInfo(); |
698 | 21 | InterInfo.ObjCInterDeclInfo.containerInfo = &InterInfo.ObjCContDeclInfo; |
699 | 21 | InterInfo.ObjCInterDeclInfo.superInfo = D->getSuperClass() ? &BaseClass3 |
700 | 21 | : nullptr18 ; |
701 | 21 | InterInfo.ObjCInterDeclInfo.protocols = &InterInfo.ObjCProtoListInfo; |
702 | | |
703 | 21 | return handleObjCContainer(D, D->getLocation(), getCursor(D), InterInfo); |
704 | 27 | } |
705 | | |
706 | | bool CXIndexDataConsumer::handleObjCImplementation( |
707 | 4 | const ObjCImplementationDecl *D) { |
708 | 4 | ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/false, |
709 | 4 | /*isRedeclaration=*/true, |
710 | 4 | /*isImplementation=*/true); |
711 | 4 | return handleObjCContainer(D, D->getLocation(), getCursor(D), ContDInfo); |
712 | 4 | } |
713 | | |
714 | 5 | bool CXIndexDataConsumer::handleObjCProtocol(const ObjCProtocolDecl *D) { |
715 | 5 | if (!D->isThisDeclarationADefinition()) { |
716 | 1 | if (shouldSuppressRefs() && markEntityOccurrenceInFile(D, D->getLocation())0 ) |
717 | 0 | return false; // already occurred. |
718 | | |
719 | | // FIXME: This seems like the wrong definition for redeclaration. |
720 | 1 | bool isRedeclaration = D->hasDefinition() || D->getPreviousDecl(); |
721 | 1 | ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, |
722 | 1 | isRedeclaration, |
723 | 1 | /*isImplementation=*/false); |
724 | 1 | return handleObjCContainer(D, D->getLocation(), |
725 | 1 | MakeCursorObjCProtocolRef(D, D->getLocation(), |
726 | 1 | CXTU), |
727 | 1 | ContDInfo); |
728 | 1 | } |
729 | | |
730 | 4 | ScratchAlloc SA(*this); |
731 | 4 | ObjCProtocolList EmptyProtoList; |
732 | 4 | ObjCProtocolListInfo ProtListInfo(D->isThisDeclarationADefinition() |
733 | 4 | ? D->getReferencedProtocols() |
734 | 4 | : EmptyProtoList0 , |
735 | 4 | *this, SA); |
736 | | |
737 | 4 | ObjCProtocolDeclInfo ProtInfo(D); |
738 | 4 | ProtInfo.ObjCProtoRefListInfo = ProtListInfo.getListInfo(); |
739 | | |
740 | 4 | return handleObjCContainer(D, D->getLocation(), getCursor(D), ProtInfo); |
741 | 5 | } |
742 | | |
743 | 5 | bool CXIndexDataConsumer::handleObjCCategory(const ObjCCategoryDecl *D) { |
744 | 5 | ScratchAlloc SA(*this); |
745 | | |
746 | 5 | ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/false); |
747 | 5 | EntityInfo ClassEntity; |
748 | 5 | const ObjCInterfaceDecl *IFaceD = D->getClassInterface(); |
749 | 5 | SourceLocation ClassLoc = D->getLocation(); |
750 | 5 | SourceLocation CategoryLoc = D->IsClassExtension() ? ClassLoc1 |
751 | 5 | : D->getCategoryNameLoc()4 ; |
752 | 5 | getEntityInfo(IFaceD, ClassEntity, SA); |
753 | | |
754 | 5 | if (shouldSuppressRefs()) |
755 | 1 | markEntityOccurrenceInFile(IFaceD, ClassLoc); |
756 | | |
757 | 5 | ObjCProtocolListInfo ProtInfo(D->getReferencedProtocols(), *this, SA); |
758 | | |
759 | 5 | CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo; |
760 | 5 | if (IFaceD) { |
761 | 5 | CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity; |
762 | 5 | CatDInfo.ObjCCatDeclInfo.classCursor = |
763 | 5 | MakeCursorObjCClassRef(IFaceD, ClassLoc, CXTU); |
764 | 5 | } else { |
765 | 0 | CatDInfo.ObjCCatDeclInfo.objcClass = nullptr; |
766 | 0 | CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor(); |
767 | 0 | } |
768 | 5 | CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc); |
769 | 5 | CatDInfo.ObjCProtoListInfo = ProtInfo.getListInfo(); |
770 | 5 | CatDInfo.ObjCCatDeclInfo.protocols = &CatDInfo.ObjCProtoListInfo; |
771 | | |
772 | 5 | return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo); |
773 | 5 | } |
774 | | |
775 | 0 | bool CXIndexDataConsumer::handleObjCCategoryImpl(const ObjCCategoryImplDecl *D) { |
776 | 0 | ScratchAlloc SA(*this); |
777 | |
|
778 | 0 | const ObjCCategoryDecl *CatD = D->getCategoryDecl(); |
779 | 0 | ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/true); |
780 | 0 | EntityInfo ClassEntity; |
781 | 0 | const ObjCInterfaceDecl *IFaceD = CatD->getClassInterface(); |
782 | 0 | SourceLocation ClassLoc = D->getLocation(); |
783 | 0 | SourceLocation CategoryLoc = D->getCategoryNameLoc(); |
784 | 0 | getEntityInfo(IFaceD, ClassEntity, SA); |
785 | |
|
786 | 0 | if (shouldSuppressRefs()) |
787 | 0 | markEntityOccurrenceInFile(IFaceD, ClassLoc); |
788 | |
|
789 | 0 | CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo; |
790 | 0 | if (IFaceD) { |
791 | 0 | CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity; |
792 | 0 | CatDInfo.ObjCCatDeclInfo.classCursor = |
793 | 0 | MakeCursorObjCClassRef(IFaceD, ClassLoc, CXTU); |
794 | 0 | } else { |
795 | 0 | CatDInfo.ObjCCatDeclInfo.objcClass = nullptr; |
796 | 0 | CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor(); |
797 | 0 | } |
798 | 0 | CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc); |
799 | 0 | CatDInfo.ObjCCatDeclInfo.protocols = nullptr; |
800 | |
|
801 | 0 | return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo); |
802 | 0 | } |
803 | | |
804 | | bool CXIndexDataConsumer::handleObjCMethod(const ObjCMethodDecl *D, |
805 | 42 | SourceLocation Loc) { |
806 | 42 | bool isDef = D->isThisDeclarationADefinition(); |
807 | 42 | bool isContainer = isDef; |
808 | 42 | bool isSkipped = false; |
809 | 42 | if (D->hasSkippedBody()) { |
810 | 0 | isSkipped = true; |
811 | 0 | isDef = true; |
812 | 0 | isContainer = false; |
813 | 0 | } |
814 | | |
815 | 42 | DeclInfo DInfo(!D->isCanonicalDecl(), isDef, isContainer); |
816 | 42 | if (isSkipped) |
817 | 0 | DInfo.flags |= CXIdxDeclFlag_Skipped; |
818 | 42 | return handleDecl(D, Loc, getCursor(D), DInfo); |
819 | 42 | } |
820 | | |
821 | | bool CXIndexDataConsumer::handleSynthesizedObjCProperty( |
822 | 4 | const ObjCPropertyImplDecl *D) { |
823 | 4 | ObjCPropertyDecl *PD = D->getPropertyDecl(); |
824 | 4 | auto *DC = D->getDeclContext(); |
825 | 4 | return handleReference(PD, D->getLocation(), getCursor(D), |
826 | 4 | dyn_cast<NamedDecl>(DC), DC); |
827 | 4 | } |
828 | | |
829 | | bool CXIndexDataConsumer::handleSynthesizedObjCMethod(const ObjCMethodDecl *D, |
830 | | SourceLocation Loc, |
831 | 6 | const DeclContext *LexicalDC) { |
832 | 6 | DeclInfo DInfo(/*isRedeclaration=*/true, /*isDefinition=*/true, |
833 | 6 | /*isContainer=*/false); |
834 | 6 | return handleDecl(D, Loc, getCursor(D), DInfo, LexicalDC, D->getDeclContext()); |
835 | 6 | } |
836 | | |
837 | 8 | bool CXIndexDataConsumer::handleObjCProperty(const ObjCPropertyDecl *D) { |
838 | 8 | ScratchAlloc SA(*this); |
839 | | |
840 | 8 | ObjCPropertyDeclInfo DInfo; |
841 | 8 | EntityInfo GetterEntity; |
842 | 8 | EntityInfo SetterEntity; |
843 | | |
844 | 8 | DInfo.ObjCPropDeclInfo.declInfo = &DInfo; |
845 | | |
846 | 8 | if (ObjCMethodDecl *Getter = D->getGetterMethodDecl()) { |
847 | 8 | getEntityInfo(Getter, GetterEntity, SA); |
848 | 8 | DInfo.ObjCPropDeclInfo.getter = &GetterEntity; |
849 | 8 | } else { |
850 | 0 | DInfo.ObjCPropDeclInfo.getter = nullptr; |
851 | 0 | } |
852 | 8 | if (ObjCMethodDecl *Setter = D->getSetterMethodDecl()) { |
853 | 7 | getEntityInfo(Setter, SetterEntity, SA); |
854 | 7 | DInfo.ObjCPropDeclInfo.setter = &SetterEntity; |
855 | 7 | } else { |
856 | 1 | DInfo.ObjCPropDeclInfo.setter = nullptr; |
857 | 1 | } |
858 | | |
859 | 8 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
860 | 8 | } |
861 | | |
862 | 8 | bool CXIndexDataConsumer::handleNamespace(const NamespaceDecl *D) { |
863 | 8 | DeclInfo DInfo(/*isRedeclaration=*/!D->isOriginalNamespace(), |
864 | 8 | /*isDefinition=*/true, |
865 | 8 | /*isContainer=*/true); |
866 | 8 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
867 | 8 | } |
868 | | |
869 | 0 | bool CXIndexDataConsumer::handleClassTemplate(const ClassTemplateDecl *D) { |
870 | 0 | return handleCXXRecordDecl(D->getTemplatedDecl(), D); |
871 | 0 | } |
872 | | |
873 | 0 | bool CXIndexDataConsumer::handleFunctionTemplate(const FunctionTemplateDecl *D) { |
874 | 0 | DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(), |
875 | 0 | /*isDefinition=*/D->isThisDeclarationADefinition(), |
876 | 0 | /*isContainer=*/D->isThisDeclarationADefinition()); |
877 | 0 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
878 | 0 | } |
879 | | |
880 | 0 | bool CXIndexDataConsumer::handleTypeAliasTemplate(const TypeAliasTemplateDecl *D) { |
881 | 0 | DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(), |
882 | 0 | /*isDefinition=*/true, /*isContainer=*/false); |
883 | 0 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
884 | 0 | } |
885 | | |
886 | | bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc, |
887 | | CXCursor Cursor, |
888 | | const NamedDecl *Parent, |
889 | | const DeclContext *DC, |
890 | | const Expr *E, |
891 | | CXIdxEntityRefKind Kind, |
892 | 1.91k | CXSymbolRole Role) { |
893 | 1.91k | if (!CB.indexEntityReference) |
894 | 0 | return false; |
895 | | |
896 | 1.91k | if (!D || !DC) |
897 | 0 | return false; |
898 | 1.91k | if (Loc.isInvalid()) |
899 | 2 | return false; |
900 | 1.91k | if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalDecl(D)1.87k ) |
901 | 0 | return false; |
902 | 1.91k | if (isNotFromSourceFile(D->getLocation())) |
903 | 0 | return false; |
904 | 1.91k | if (D->isImplicit() && shouldIgnoreIfImplicit(D)0 ) |
905 | 0 | return false; |
906 | | |
907 | 1.91k | if (shouldSuppressRefs()) { |
908 | 11 | if (markEntityOccurrenceInFile(D, Loc)) |
909 | 11 | return false; // already occurred. |
910 | 11 | } |
911 | | |
912 | 1.90k | ScratchAlloc SA(*this); |
913 | 1.90k | EntityInfo RefEntity, ParentEntity; |
914 | 1.90k | getEntityInfo(D, RefEntity, SA); |
915 | 1.90k | if (!RefEntity.USR) |
916 | 0 | return false; |
917 | | |
918 | 1.90k | getEntityInfo(Parent, ParentEntity, SA); |
919 | | |
920 | 1.90k | ContainerInfo Container; |
921 | 1.90k | getContainerInfo(DC, Container); |
922 | | |
923 | 1.90k | CXIdxEntityRefInfo Info = { Kind, |
924 | 1.90k | Cursor, |
925 | 1.90k | getIndexLoc(Loc), |
926 | 1.90k | &RefEntity, |
927 | 1.90k | Parent ? &ParentEntity1.89k : nullptr7 , |
928 | 1.90k | &Container, |
929 | 1.90k | Role }; |
930 | 1.90k | CB.indexEntityReference(ClientData, &Info); |
931 | 1.90k | return true; |
932 | 1.90k | } |
933 | | |
934 | 1.91k | bool CXIndexDataConsumer::isNotFromSourceFile(SourceLocation Loc) const { |
935 | 1.91k | if (Loc.isInvalid()) |
936 | 0 | return true; |
937 | 1.91k | SourceManager &SM = Ctx->getSourceManager(); |
938 | 1.91k | SourceLocation FileLoc = SM.getFileLoc(Loc); |
939 | 1.91k | FileID FID = SM.getFileID(FileLoc); |
940 | 1.91k | return SM.getFileEntryForID(FID) == nullptr; |
941 | 1.91k | } |
942 | | |
943 | | void CXIndexDataConsumer::addContainerInMap(const DeclContext *DC, |
944 | 173 | CXIdxClientContainer container) { |
945 | 173 | if (!DC) |
946 | 0 | return; |
947 | | |
948 | 173 | ContainerMapTy::iterator I = ContainerMap.find(DC); |
949 | 173 | if (I == ContainerMap.end()) { |
950 | 173 | if (container) |
951 | 173 | ContainerMap[DC] = container; |
952 | 173 | return; |
953 | 173 | } |
954 | | // Allow changing the container of a previously seen DeclContext so we |
955 | | // can handle invalid user code, like a function re-definition. |
956 | 0 | if (container) |
957 | 0 | I->second = container; |
958 | 0 | else |
959 | 0 | ContainerMap.erase(I); |
960 | 0 | } |
961 | | |
962 | 0 | CXIdxClientEntity CXIndexDataConsumer::getClientEntity(const Decl *D) const { |
963 | 0 | if (!D) |
964 | 0 | return nullptr; |
965 | 0 | EntityMapTy::const_iterator I = EntityMap.find(D); |
966 | 0 | if (I == EntityMap.end()) |
967 | 0 | return nullptr; |
968 | 0 | return I->second; |
969 | 0 | } |
970 | | |
971 | 0 | void CXIndexDataConsumer::setClientEntity(const Decl *D, CXIdxClientEntity client) { |
972 | 0 | if (!D) |
973 | 0 | return; |
974 | 0 | EntityMap[D] = client; |
975 | 0 | } |
976 | | |
977 | | bool CXIndexDataConsumer::handleCXXRecordDecl(const CXXRecordDecl *RD, |
978 | 35 | const NamedDecl *OrigD) { |
979 | 35 | if (RD->isThisDeclarationADefinition()) { |
980 | 34 | ScratchAlloc SA(*this); |
981 | 34 | CXXClassDeclInfo CXXDInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(), |
982 | 34 | /*isDefinition=*/RD->isThisDeclarationADefinition()); |
983 | 34 | CXXBasesListInfo BaseList(RD, *this, SA); |
984 | 34 | CXXDInfo.CXXClassInfo.declInfo = &CXXDInfo; |
985 | 34 | CXXDInfo.CXXClassInfo.bases = BaseList.getBases(); |
986 | 34 | CXXDInfo.CXXClassInfo.numBases = BaseList.getNumBases(); |
987 | | |
988 | 34 | if (shouldSuppressRefs()) { |
989 | | // Go through bases and mark them as referenced. |
990 | 5 | for (unsigned i = 0, e = BaseList.getNumBases(); i != e; ++i2 ) { |
991 | 2 | const CXIdxBaseClassInfo *baseInfo = BaseList.getBases()[i]; |
992 | 2 | if (baseInfo->base) { |
993 | 2 | const NamedDecl *BaseD = BaseList.BaseEntities[i].Dcl; |
994 | 2 | SourceLocation |
995 | 2 | Loc = SourceLocation::getFromRawEncoding(baseInfo->loc.int_data); |
996 | 2 | markEntityOccurrenceInFile(BaseD, Loc); |
997 | 2 | } |
998 | 2 | } |
999 | 3 | } |
1000 | | |
1001 | 34 | return handleDecl(OrigD, OrigD->getLocation(), getCursor(OrigD), CXXDInfo); |
1002 | 34 | } |
1003 | | |
1004 | 1 | DeclInfo DInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(), |
1005 | 1 | /*isDefinition=*/RD->isThisDeclarationADefinition(), |
1006 | 1 | /*isContainer=*/RD->isThisDeclarationADefinition()); |
1007 | 1 | return handleDecl(OrigD, OrigD->getLocation(), getCursor(OrigD), DInfo); |
1008 | 35 | } |
1009 | | |
1010 | | bool CXIndexDataConsumer::markEntityOccurrenceInFile(const NamedDecl *D, |
1011 | 33 | SourceLocation Loc) { |
1012 | 33 | if (!D || Loc.isInvalid()) |
1013 | 0 | return true; |
1014 | | |
1015 | 33 | SourceManager &SM = Ctx->getSourceManager(); |
1016 | 33 | D = getEntityDecl(D); |
1017 | | |
1018 | 33 | std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SM.getFileLoc(Loc)); |
1019 | 33 | FileID FID = LocInfo.first; |
1020 | 33 | if (FID.isInvalid()) |
1021 | 0 | return true; |
1022 | | |
1023 | 33 | const FileEntry *FE = SM.getFileEntryForID(FID); |
1024 | 33 | if (!FE) |
1025 | 0 | return true; |
1026 | 33 | RefFileOccurrence RefOccur(FE, D); |
1027 | 33 | std::pair<llvm::DenseSet<RefFileOccurrence>::iterator, bool> |
1028 | 33 | res = RefFileOccurrences.insert(RefOccur); |
1029 | 33 | return !res.second; // already in map |
1030 | 33 | } |
1031 | | |
1032 | 4.20k | const NamedDecl *CXIndexDataConsumer::getEntityDecl(const NamedDecl *D) const { |
1033 | 4.20k | assert(D); |
1034 | 0 | D = cast<NamedDecl>(D->getCanonicalDecl()); |
1035 | | |
1036 | 4.20k | if (const ObjCImplementationDecl * |
1037 | 4.20k | ImplD = dyn_cast<ObjCImplementationDecl>(D)) { |
1038 | 6 | return getEntityDecl(ImplD->getClassInterface()); |
1039 | | |
1040 | 4.20k | } else if (const ObjCCategoryImplDecl * |
1041 | 4.20k | CatImplD = dyn_cast<ObjCCategoryImplDecl>(D)) { |
1042 | 0 | return getEntityDecl(CatImplD->getCategoryDecl()); |
1043 | 4.20k | } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
1044 | 3.69k | if (FunctionTemplateDecl *TemplD = FD->getDescribedFunctionTemplate()) |
1045 | 2 | return getEntityDecl(TemplD); |
1046 | 3.69k | } else if (const CXXRecordDecl *511 RD511 = dyn_cast<CXXRecordDecl>(D)) { |
1047 | 86 | if (ClassTemplateDecl *TemplD = RD->getDescribedClassTemplate()) |
1048 | 20 | return getEntityDecl(TemplD); |
1049 | 86 | } |
1050 | | |
1051 | 4.17k | return D; |
1052 | 4.20k | } |
1053 | | |
1054 | | const DeclContext * |
1055 | 125 | CXIndexDataConsumer::getEntityContainer(const Decl *D) const { |
1056 | 125 | const DeclContext *DC = dyn_cast<DeclContext>(D); |
1057 | 125 | if (DC) |
1058 | 125 | return DC; |
1059 | | |
1060 | 0 | if (const ClassTemplateDecl *ClassTempl = dyn_cast<ClassTemplateDecl>(D)) { |
1061 | 0 | DC = ClassTempl->getTemplatedDecl(); |
1062 | 0 | } else if (const FunctionTemplateDecl * |
1063 | 0 | FuncTempl = dyn_cast<FunctionTemplateDecl>(D)) { |
1064 | 0 | DC = FuncTempl->getTemplatedDecl(); |
1065 | 0 | } |
1066 | |
|
1067 | 0 | return DC; |
1068 | 125 | } |
1069 | | |
1070 | | CXIdxClientContainer |
1071 | 2.53k | CXIndexDataConsumer::getClientContainerForDC(const DeclContext *DC) const { |
1072 | 2.53k | if (!DC) |
1073 | 0 | return nullptr; |
1074 | | |
1075 | 2.53k | ContainerMapTy::const_iterator I = ContainerMap.find(DC); |
1076 | 2.53k | if (I == ContainerMap.end()) |
1077 | 28 | return nullptr; |
1078 | | |
1079 | 2.50k | return I->second; |
1080 | 2.53k | } |
1081 | | |
1082 | 2.40k | CXIdxClientFile CXIndexDataConsumer::getIndexFile(const FileEntry *File) { |
1083 | 2.40k | if (!File) |
1084 | 0 | return nullptr; |
1085 | | |
1086 | 2.40k | FileMapTy::iterator FI = FileMap.find(File); |
1087 | 2.40k | if (FI != FileMap.end()) |
1088 | 2.40k | return FI->second; |
1089 | | |
1090 | 0 | return nullptr; |
1091 | 2.40k | } |
1092 | | |
1093 | 2.34k | CXIdxLoc CXIndexDataConsumer::getIndexLoc(SourceLocation Loc) const { |
1094 | 2.34k | CXIdxLoc idxLoc = { {nullptr, nullptr}, 0 }; |
1095 | 2.34k | if (Loc.isInvalid()) |
1096 | 22 | return idxLoc; |
1097 | | |
1098 | 2.32k | idxLoc.ptr_data[0] = const_cast<CXIndexDataConsumer *>(this); |
1099 | 2.32k | idxLoc.int_data = Loc.getRawEncoding(); |
1100 | 2.32k | return idxLoc; |
1101 | 2.34k | } |
1102 | | |
1103 | | void CXIndexDataConsumer::translateLoc(SourceLocation Loc, |
1104 | | CXIdxClientFile *indexFile, CXFile *file, |
1105 | | unsigned *line, unsigned *column, |
1106 | 2.40k | unsigned *offset) { |
1107 | 2.40k | if (Loc.isInvalid()) |
1108 | 0 | return; |
1109 | | |
1110 | 2.40k | SourceManager &SM = Ctx->getSourceManager(); |
1111 | 2.40k | Loc = SM.getFileLoc(Loc); |
1112 | | |
1113 | 2.40k | std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc); |
1114 | 2.40k | FileID FID = LocInfo.first; |
1115 | 2.40k | unsigned FileOffset = LocInfo.second; |
1116 | | |
1117 | 2.40k | if (FID.isInvalid()) |
1118 | 0 | return; |
1119 | | |
1120 | 2.40k | const FileEntry *FE = SM.getFileEntryForID(FID); |
1121 | 2.40k | if (indexFile) |
1122 | 2.40k | *indexFile = getIndexFile(FE); |
1123 | 2.40k | if (file) |
1124 | 0 | *file = const_cast<FileEntry *>(FE); |
1125 | 2.40k | if (line) |
1126 | 2.40k | *line = SM.getLineNumber(FID, FileOffset); |
1127 | 2.40k | if (column) |
1128 | 2.40k | *column = SM.getColumnNumber(FID, FileOffset); |
1129 | 2.40k | if (offset) |
1130 | 0 | *offset = FileOffset; |
1131 | 2.40k | } |
1132 | | |
1133 | | static CXIdxEntityKind getEntityKindFromSymbolKind(SymbolKind K, SymbolLanguage L); |
1134 | | static CXIdxEntityCXXTemplateKind |
1135 | | getEntityKindFromSymbolProperties(SymbolPropertySet K); |
1136 | | static CXIdxEntityLanguage getEntityLangFromSymbolLang(SymbolLanguage L); |
1137 | | |
1138 | | void CXIndexDataConsumer::getEntityInfo(const NamedDecl *D, |
1139 | | EntityInfo &EntityInfo, |
1140 | 4.15k | ScratchAlloc &SA) { |
1141 | 4.15k | if (!D) |
1142 | 7 | return; |
1143 | | |
1144 | 4.14k | D = getEntityDecl(D); |
1145 | 4.14k | EntityInfo.cursor = getCursor(D); |
1146 | 4.14k | EntityInfo.Dcl = D; |
1147 | 4.14k | EntityInfo.IndexCtx = this; |
1148 | | |
1149 | 4.14k | SymbolInfo SymInfo = getSymbolInfo(D); |
1150 | 4.14k | EntityInfo.kind = getEntityKindFromSymbolKind(SymInfo.Kind, SymInfo.Lang); |
1151 | 4.14k | EntityInfo.templateKind = getEntityKindFromSymbolProperties(SymInfo.Properties); |
1152 | 4.14k | EntityInfo.lang = getEntityLangFromSymbolLang(SymInfo.Lang); |
1153 | | |
1154 | 4.14k | if (D->hasAttrs()) { |
1155 | 42 | EntityInfo.AttrList = AttrListInfo::create(D, *this); |
1156 | 42 | EntityInfo.attributes = EntityInfo.AttrList->getAttrs(); |
1157 | 42 | EntityInfo.numAttributes = EntityInfo.AttrList->getNumAttrs(); |
1158 | 42 | } |
1159 | | |
1160 | 4.14k | if (EntityInfo.kind == CXIdxEntity_Unexposed) |
1161 | 0 | return; |
1162 | | |
1163 | 4.14k | if (IdentifierInfo *II = D->getIdentifier()) { |
1164 | 2.30k | EntityInfo.name = SA.toCStr(II->getName()); |
1165 | | |
1166 | 2.30k | } else if (1.84k isa<TagDecl>(D)1.84k || isa<FieldDecl>(D)1.84k || isa<NamespaceDecl>(D)1.84k ) { |
1167 | 3 | EntityInfo.name = nullptr; // anonymous tag/field/namespace. |
1168 | | |
1169 | 1.84k | } else { |
1170 | 1.84k | SmallString<256> StrBuf; |
1171 | 1.84k | { |
1172 | 1.84k | llvm::raw_svector_ostream OS(StrBuf); |
1173 | 1.84k | D->printName(OS); |
1174 | 1.84k | } |
1175 | 1.84k | EntityInfo.name = SA.copyCStr(StrBuf.str()); |
1176 | 1.84k | } |
1177 | | |
1178 | 4.14k | { |
1179 | 4.14k | SmallString<512> StrBuf; |
1180 | 4.14k | bool Ignore = getDeclCursorUSR(D, StrBuf); |
1181 | 4.14k | if (Ignore) { |
1182 | 0 | EntityInfo.USR = nullptr; |
1183 | 4.14k | } else { |
1184 | 4.14k | EntityInfo.USR = SA.copyCStr(StrBuf.str()); |
1185 | 4.14k | } |
1186 | 4.14k | } |
1187 | 4.14k | } |
1188 | | |
1189 | | void CXIndexDataConsumer::getContainerInfo(const DeclContext *DC, |
1190 | 2.35k | ContainerInfo &ContInfo) { |
1191 | 2.35k | ContInfo.cursor = getCursor(cast<Decl>(DC)); |
1192 | 2.35k | ContInfo.DC = DC; |
1193 | 2.35k | ContInfo.IndexCtx = this; |
1194 | 2.35k | } |
1195 | | |
1196 | 94 | CXCursor CXIndexDataConsumer::getRefCursor(const NamedDecl *D, SourceLocation Loc) { |
1197 | 94 | if (const TypeDecl *TD = dyn_cast<TypeDecl>(D)) |
1198 | 50 | return MakeCursorTypeRef(TD, Loc, CXTU); |
1199 | 44 | if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) |
1200 | 21 | return MakeCursorObjCClassRef(ID, Loc, CXTU); |
1201 | 23 | if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) |
1202 | 3 | return MakeCursorObjCProtocolRef(PD, Loc, CXTU); |
1203 | 20 | if (const TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) |
1204 | 2 | return MakeCursorTemplateRef(Template, Loc, CXTU); |
1205 | 18 | if (const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(D)) |
1206 | 10 | return MakeCursorNamespaceRef(Namespace, Loc, CXTU); |
1207 | 8 | if (const NamespaceAliasDecl *Namespace = dyn_cast<NamespaceAliasDecl>(D)) |
1208 | 0 | return MakeCursorNamespaceRef(Namespace, Loc, CXTU); |
1209 | 8 | if (const FieldDecl *Field = dyn_cast<FieldDecl>(D)) |
1210 | 0 | return MakeCursorMemberRef(Field, Loc, CXTU); |
1211 | 8 | if (const VarDecl *Var = dyn_cast<VarDecl>(D)) |
1212 | 8 | return MakeCursorVariableRef(Var, Loc, CXTU); |
1213 | | |
1214 | 0 | return clang_getNullCursor(); |
1215 | 8 | } |
1216 | | |
1217 | 14 | bool CXIndexDataConsumer::shouldIgnoreIfImplicit(const Decl *D) { |
1218 | 14 | if (isa<ObjCInterfaceDecl>(D)) |
1219 | 0 | return false; |
1220 | 14 | if (isa<ObjCCategoryDecl>(D)) |
1221 | 0 | return false; |
1222 | 14 | if (isa<ObjCIvarDecl>(D)) |
1223 | 0 | return false; |
1224 | 14 | if (isa<ObjCMethodDecl>(D)) |
1225 | 14 | return false; |
1226 | 0 | if (isa<ImportDecl>(D)) |
1227 | 0 | return false; |
1228 | 0 | return true; |
1229 | 0 | } |
1230 | | |
1231 | 13 | bool CXIndexDataConsumer::isTemplateImplicitInstantiation(const Decl *D) { |
1232 | 13 | if (const ClassTemplateSpecializationDecl * |
1233 | 13 | SD = dyn_cast<ClassTemplateSpecializationDecl>(D)) { |
1234 | 0 | return SD->getSpecializationKind() == TSK_ImplicitInstantiation; |
1235 | 0 | } |
1236 | 13 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
1237 | 5 | return FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation; |
1238 | 5 | } |
1239 | 8 | return false; |
1240 | 13 | } |
1241 | | |
1242 | 4.14k | static CXIdxEntityKind getEntityKindFromSymbolKind(SymbolKind K, SymbolLanguage Lang) { |
1243 | 4.14k | switch (K) { |
1244 | 0 | case SymbolKind::Unknown: |
1245 | 0 | case SymbolKind::Module: |
1246 | 0 | case SymbolKind::Macro: |
1247 | 0 | case SymbolKind::ClassProperty: |
1248 | 0 | case SymbolKind::Using: |
1249 | 0 | case SymbolKind::TemplateTypeParm: |
1250 | 0 | case SymbolKind::TemplateTemplateParm: |
1251 | 0 | case SymbolKind::NonTypeTemplateParm: |
1252 | 0 | case SymbolKind::Concept: |
1253 | 0 | return CXIdxEntity_Unexposed; |
1254 | | |
1255 | 2 | case SymbolKind::Enum: return CXIdxEntity_Enum; |
1256 | 32 | case SymbolKind::Struct: return CXIdxEntity_Struct; |
1257 | 1 | case SymbolKind::Union: return CXIdxEntity_Union; |
1258 | 27 | case SymbolKind::TypeAlias: |
1259 | 27 | if (Lang == SymbolLanguage::CXX) |
1260 | 1 | return CXIdxEntity_CXXTypeAlias; |
1261 | 26 | return CXIdxEntity_Typedef; |
1262 | 1.86k | case SymbolKind::Function: return CXIdxEntity_Function; |
1263 | 122 | case SymbolKind::Variable: return CXIdxEntity_Variable; |
1264 | 20 | case SymbolKind::Field: |
1265 | 20 | if (Lang == SymbolLanguage::ObjC) |
1266 | 5 | return CXIdxEntity_ObjCIvar; |
1267 | 15 | return CXIdxEntity_Field; |
1268 | 6 | case SymbolKind::EnumConstant: return CXIdxEntity_EnumConstant; |
1269 | 113 | case SymbolKind::Class: |
1270 | 113 | if (Lang == SymbolLanguage::ObjC) |
1271 | 62 | return CXIdxEntity_ObjCClass; |
1272 | 51 | return CXIdxEntity_CXXClass; |
1273 | 9 | case SymbolKind::Protocol: |
1274 | 9 | if (Lang == SymbolLanguage::ObjC) |
1275 | 9 | return CXIdxEntity_ObjCProtocol; |
1276 | 0 | return CXIdxEntity_CXXInterface; |
1277 | 10 | case SymbolKind::Extension: return CXIdxEntity_ObjCCategory; |
1278 | 1.87k | case SymbolKind::InstanceMethod: |
1279 | 1.87k | if (Lang == SymbolLanguage::ObjC) |
1280 | 59 | return CXIdxEntity_ObjCInstanceMethod; |
1281 | 1.81k | return CXIdxEntity_CXXInstanceMethod; |
1282 | 15 | case SymbolKind::ClassMethod: return CXIdxEntity_ObjCClassMethod; |
1283 | 0 | case SymbolKind::StaticMethod: return CXIdxEntity_CXXStaticMethod; |
1284 | 12 | case SymbolKind::InstanceProperty: return CXIdxEntity_ObjCProperty; |
1285 | 0 | case SymbolKind::StaticProperty: return CXIdxEntity_CXXStaticVariable; |
1286 | 18 | case SymbolKind::Namespace: return CXIdxEntity_CXXNamespace; |
1287 | 0 | case SymbolKind::NamespaceAlias: return CXIdxEntity_CXXNamespaceAlias; |
1288 | 11 | case SymbolKind::Constructor: return CXIdxEntity_CXXConstructor; |
1289 | 0 | case SymbolKind::Destructor: return CXIdxEntity_CXXDestructor; |
1290 | 0 | case SymbolKind::ConversionFunction: return CXIdxEntity_CXXConversionFunction; |
1291 | 10 | case SymbolKind::Parameter: return CXIdxEntity_Variable; |
1292 | 4.14k | } |
1293 | 0 | llvm_unreachable("invalid symbol kind"); |
1294 | 0 | } |
1295 | | |
1296 | | static CXIdxEntityCXXTemplateKind |
1297 | 4.14k | getEntityKindFromSymbolProperties(SymbolPropertySet K) { |
1298 | 4.14k | if (K & (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization) |
1299 | 2 | return CXIdxEntity_TemplatePartialSpecialization; |
1300 | 4.14k | if (K & (SymbolPropertySet)SymbolProperty::TemplateSpecialization) |
1301 | 3 | return CXIdxEntity_TemplateSpecialization; |
1302 | 4.14k | if (K & (SymbolPropertySet)SymbolProperty::Generic) |
1303 | 23 | return CXIdxEntity_Template; |
1304 | 4.11k | return CXIdxEntity_NonTemplate; |
1305 | 4.14k | } |
1306 | | |
1307 | 4.14k | static CXIdxEntityLanguage getEntityLangFromSymbolLang(SymbolLanguage L) { |
1308 | 4.14k | switch (L) { |
1309 | 2.05k | case SymbolLanguage::C: return CXIdxEntityLang_C; |
1310 | 172 | case SymbolLanguage::ObjC: return CXIdxEntityLang_ObjC; |
1311 | 1.91k | case SymbolLanguage::CXX: return CXIdxEntityLang_CXX; |
1312 | 0 | case SymbolLanguage::Swift: return CXIdxEntityLang_Swift; |
1313 | 4.14k | } |
1314 | 0 | llvm_unreachable("invalid symbol language"); |
1315 | 0 | } |