Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 1 | //===- CIndexHigh.cpp - Higher level API functions ------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "IndexingContext.h" |
| 11 | #include "CXTranslationUnit.h" |
| 12 | #include "CIndexDiagnostic.h" |
| 13 | |
| 14 | #include "clang/Frontend/ASTUnit.h" |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 15 | #include "clang/AST/DeclCXX.h" |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclTemplate.h" |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace clang; |
| 19 | using namespace cxindex; |
| 20 | using namespace cxcursor; |
| 21 | |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 22 | IndexingContext::ObjCProtocolListInfo::ObjCProtocolListInfo( |
| 23 | const ObjCProtocolList &ProtList, |
| 24 | IndexingContext &IdxCtx, |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 25 | ScratchAlloc &SA) { |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 26 | ObjCInterfaceDecl::protocol_loc_iterator LI = ProtList.loc_begin(); |
| 27 | for (ObjCInterfaceDecl::protocol_iterator |
| 28 | I = ProtList.begin(), E = ProtList.end(); I != E; ++I, ++LI) { |
| 29 | SourceLocation Loc = *LI; |
| 30 | ObjCProtocolDecl *PD = *I; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 31 | ProtEntities.push_back(EntityInfo()); |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 32 | IdxCtx.getEntityInfo(PD, ProtEntities.back(), SA); |
| 33 | CXIdxObjCProtocolRefInfo ProtInfo = { 0, |
| 34 | MakeCursorObjCProtocolRef(PD, Loc, IdxCtx.CXTU), |
| 35 | IdxCtx.getIndexLoc(Loc) }; |
| 36 | ProtInfos.push_back(ProtInfo); |
Argyrios Kyrtzidis | 90fd67a | 2011-12-15 00:04:56 +0000 | [diff] [blame] | 37 | |
| 38 | if (IdxCtx.suppressRefs()) |
| 39 | IdxCtx.markEntityOccurrenceInFile(PD, Loc); |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i) |
| 43 | ProtInfos[i].protocol = &ProtEntities[i]; |
| 44 | |
| 45 | for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i) |
| 46 | Prots.push_back(&ProtInfos[i]); |
| 47 | } |
| 48 | |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 49 | |
| 50 | IBOutletCollectionInfo::IBOutletCollectionInfo( |
| 51 | const IBOutletCollectionInfo &other) |
| 52 | : AttrInfo(CXIdxAttr_IBOutletCollection, other.cursor, other.loc, A) { |
| 53 | |
| 54 | IBCollInfo.attrInfo = this; |
| 55 | IBCollInfo.classCursor = other.IBCollInfo.classCursor; |
| 56 | IBCollInfo.classLoc = other.IBCollInfo.classLoc; |
| 57 | if (other.IBCollInfo.objcClass) { |
| 58 | ClassInfo = other.ClassInfo; |
| 59 | IBCollInfo.objcClass = &ClassInfo; |
| 60 | } else |
| 61 | IBCollInfo.objcClass = 0; |
| 62 | } |
| 63 | |
| 64 | AttrListInfo::AttrListInfo(const Decl *D, |
| 65 | IndexingContext &IdxCtx, |
| 66 | ScratchAlloc &SA) : ref_cnt(0) { |
| 67 | if (!D->hasAttrs()) |
| 68 | return; |
| 69 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 70 | for (AttrVec::const_iterator AttrI = D->attr_begin(), AttrE = D->attr_end(); |
| 71 | AttrI != AttrE; ++AttrI) { |
| 72 | const Attr *A = *AttrI; |
| 73 | CXCursor C = MakeCXCursor(A, const_cast<Decl *>(D), IdxCtx.CXTU); |
| 74 | CXIdxLoc Loc = IdxCtx.getIndexLoc(A->getLocation()); |
| 75 | switch (C.kind) { |
| 76 | default: |
| 77 | Attrs.push_back(AttrInfo(CXIdxAttr_Unexposed, C, Loc, A)); |
| 78 | break; |
| 79 | case CXCursor_IBActionAttr: |
| 80 | Attrs.push_back(AttrInfo(CXIdxAttr_IBAction, C, Loc, A)); |
| 81 | break; |
| 82 | case CXCursor_IBOutletAttr: |
| 83 | Attrs.push_back(AttrInfo(CXIdxAttr_IBOutlet, C, Loc, A)); |
| 84 | break; |
| 85 | case CXCursor_IBOutletCollectionAttr: |
| 86 | IBCollAttrs.push_back(IBOutletCollectionInfo(C, Loc, A)); |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | for (unsigned i = 0, e = IBCollAttrs.size(); i != e; ++i) { |
| 92 | IBOutletCollectionInfo &IBInfo = IBCollAttrs[i]; |
| 93 | CXAttrs.push_back(&IBInfo); |
| 94 | |
| 95 | const IBOutletCollectionAttr * |
| 96 | IBAttr = cast<IBOutletCollectionAttr>(IBInfo.A); |
| 97 | IBInfo.IBCollInfo.attrInfo = &IBInfo; |
| 98 | IBInfo.IBCollInfo.classLoc = IdxCtx.getIndexLoc(IBAttr->getInterfaceLoc()); |
| 99 | IBInfo.IBCollInfo.objcClass = 0; |
| 100 | IBInfo.IBCollInfo.classCursor = clang_getNullCursor(); |
| 101 | QualType Ty = IBAttr->getInterface(); |
| 102 | if (const ObjCInterfaceType *InterTy = Ty->getAs<ObjCInterfaceType>()) { |
| 103 | if (const ObjCInterfaceDecl *InterD = InterTy->getInterface()) { |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 104 | IdxCtx.getEntityInfo(InterD, IBInfo.ClassInfo, SA); |
| 105 | IBInfo.IBCollInfo.objcClass = &IBInfo.ClassInfo; |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 106 | IBInfo.IBCollInfo.classCursor = MakeCursorObjCClassRef(InterD, |
| 107 | IBAttr->getInterfaceLoc(), IdxCtx.CXTU); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | for (unsigned i = 0, e = Attrs.size(); i != e; ++i) |
| 113 | CXAttrs.push_back(&Attrs[i]); |
| 114 | } |
| 115 | |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 116 | AttrListInfo::AttrListInfo(const AttrListInfo &other) { |
| 117 | assert(other.ref_cnt == 0 && |
| 118 | "Should not copy an AttrListInfo that is ref-counted"); |
| 119 | ref_cnt = 0; |
| 120 | |
| 121 | Attrs = other.Attrs; |
| 122 | IBCollAttrs = other.IBCollAttrs; |
| 123 | |
| 124 | for (unsigned i = 0, e = IBCollAttrs.size(); i != e; ++i) |
| 125 | CXAttrs.push_back(&IBCollAttrs[i]); |
| 126 | |
| 127 | for (unsigned i = 0, e = Attrs.size(); i != e; ++i) |
| 128 | CXAttrs.push_back(&Attrs[i]); |
| 129 | } |
| 130 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 131 | IndexingContext::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D, |
| 132 | IndexingContext &IdxCtx, |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 133 | ScratchAlloc &SA) { |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 134 | for (CXXRecordDecl::base_class_const_iterator |
| 135 | I = D->bases_begin(), E = D->bases_end(); I != E; ++I) { |
| 136 | const CXXBaseSpecifier &Base = *I; |
| 137 | BaseEntities.push_back(EntityInfo()); |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 138 | const NamedDecl *BaseD = 0; |
Argyrios Kyrtzidis | b526a87 | 2011-12-07 20:44:15 +0000 | [diff] [blame] | 139 | QualType T = Base.getType(); |
| 140 | SourceLocation Loc = getBaseLoc(Base); |
| 141 | |
| 142 | if (const TypedefType *TDT = T->getAs<TypedefType>()) { |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 143 | BaseD = TDT->getDecl(); |
Argyrios Kyrtzidis | b526a87 | 2011-12-07 20:44:15 +0000 | [diff] [blame] | 144 | } else if (const TemplateSpecializationType * |
| 145 | TST = T->getAs<TemplateSpecializationType>()) { |
| 146 | BaseD = TST->getTemplateName().getAsTemplateDecl(); |
| 147 | } else if (const RecordType *RT = T->getAs<RecordType>()) { |
| 148 | BaseD = RT->getDecl(); |
| 149 | } |
| 150 | |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 151 | if (BaseD) |
| 152 | IdxCtx.getEntityInfo(BaseD, BaseEntities.back(), SA); |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 153 | CXIdxBaseClassInfo BaseInfo = { 0, |
| 154 | MakeCursorCXXBaseSpecifier(&Base, IdxCtx.CXTU), |
Argyrios Kyrtzidis | b526a87 | 2011-12-07 20:44:15 +0000 | [diff] [blame] | 155 | IdxCtx.getIndexLoc(Loc) }; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 156 | BaseInfos.push_back(BaseInfo); |
| 157 | } |
| 158 | |
| 159 | for (unsigned i = 0, e = BaseInfos.size(); i != e; ++i) { |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 160 | if (BaseEntities[i].name && BaseEntities[i].USR) |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 161 | BaseInfos[i].base = &BaseEntities[i]; |
| 162 | } |
| 163 | |
| 164 | for (unsigned i = 0, e = BaseInfos.size(); i != e; ++i) |
| 165 | CXBases.push_back(&BaseInfos[i]); |
| 166 | } |
| 167 | |
Argyrios Kyrtzidis | b526a87 | 2011-12-07 20:44:15 +0000 | [diff] [blame] | 168 | SourceLocation IndexingContext::CXXBasesListInfo::getBaseLoc( |
| 169 | const CXXBaseSpecifier &Base) const { |
| 170 | SourceLocation Loc = Base.getSourceRange().getBegin(); |
| 171 | TypeLoc TL; |
| 172 | if (Base.getTypeSourceInfo()) |
| 173 | TL = Base.getTypeSourceInfo()->getTypeLoc(); |
| 174 | if (TL.isNull()) |
| 175 | return Loc; |
| 176 | |
| 177 | if (const QualifiedTypeLoc *QL = dyn_cast<QualifiedTypeLoc>(&TL)) |
| 178 | TL = QL->getUnqualifiedLoc(); |
| 179 | |
| 180 | if (const ElaboratedTypeLoc *EL = dyn_cast<ElaboratedTypeLoc>(&TL)) |
| 181 | return EL->getNamedTypeLoc().getBeginLoc(); |
| 182 | if (const DependentNameTypeLoc *DL = dyn_cast<DependentNameTypeLoc>(&TL)) |
| 183 | return DL->getNameLoc(); |
| 184 | if (const DependentTemplateSpecializationTypeLoc * |
| 185 | DTL = dyn_cast<DependentTemplateSpecializationTypeLoc>(&TL)) |
| 186 | return DTL->getNameLoc(); |
| 187 | |
| 188 | return Loc; |
| 189 | } |
| 190 | |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 191 | const char *ScratchAlloc::toCStr(StringRef Str) { |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 192 | if (Str.empty()) |
| 193 | return ""; |
| 194 | if (Str.data()[Str.size()] == '\0') |
| 195 | return Str.data(); |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 196 | return copyCStr(Str); |
| 197 | } |
| 198 | |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 199 | const char *ScratchAlloc::copyCStr(StringRef Str) { |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 200 | char *buf = IdxCtx.StrScratch.Allocate<char>(Str.size() + 1); |
| 201 | std::uninitialized_copy(Str.begin(), Str.end(), buf); |
| 202 | buf[Str.size()] = '\0'; |
| 203 | return buf; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void IndexingContext::setASTContext(ASTContext &ctx) { |
| 207 | Ctx = &ctx; |
| 208 | static_cast<ASTUnit*>(CXTU->TUData)->setASTContext(&ctx); |
| 209 | } |
| 210 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 211 | bool IndexingContext::shouldAbort() { |
| 212 | if (!CB.abortQuery) |
| 213 | return false; |
| 214 | return CB.abortQuery(ClientData, 0); |
| 215 | } |
| 216 | |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 217 | void IndexingContext::enteredMainFile(const FileEntry *File) { |
| 218 | if (File && CB.enteredMainFile) { |
| 219 | CXIdxClientFile idxFile = CB.enteredMainFile(ClientData, (CXFile)File, 0); |
| 220 | FileMap[File] = idxFile; |
| 221 | } |
| 222 | } |
| 223 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 224 | void IndexingContext::ppIncludedFile(SourceLocation hashLoc, |
| 225 | StringRef filename, |
| 226 | const FileEntry *File, |
| 227 | bool isImport, bool isAngled) { |
| 228 | if (!CB.ppIncludedFile) |
| 229 | return; |
| 230 | |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 231 | ScratchAlloc SA(*this); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 232 | CXIdxIncludedFileInfo Info = { getIndexLoc(hashLoc), |
| 233 | SA.toCStr(filename), |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 234 | (CXFile)File, |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 235 | isImport, isAngled }; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 236 | CXIdxClientFile idxFile = CB.ppIncludedFile(ClientData, &Info); |
| 237 | FileMap[File] = idxFile; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 240 | void IndexingContext::startedTranslationUnit() { |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 241 | CXIdxClientContainer idxCont = 0; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 242 | if (CB.startedTranslationUnit) |
| 243 | idxCont = CB.startedTranslationUnit(ClientData, 0); |
| 244 | addContainerInMap(Ctx->getTranslationUnitDecl(), idxCont); |
| 245 | } |
| 246 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 247 | void IndexingContext::handleDiagnosticSet(CXDiagnostic CXDiagSet) { |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 248 | if (!CB.diagnostic) |
| 249 | return; |
| 250 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 251 | CB.diagnostic(ClientData, CXDiagSet, 0); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 254 | bool IndexingContext::handleDecl(const NamedDecl *D, |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 255 | SourceLocation Loc, CXCursor Cursor, |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 256 | DeclInfo &DInfo) { |
Argyrios Kyrtzidis | 144b6c0 | 2011-11-18 00:26:46 +0000 | [diff] [blame] | 257 | if (!CB.indexDeclaration || !D) |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 258 | return false; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 259 | if (D->isImplicit() && shouldIgnoreIfImplicit(D)) |
| 260 | return false; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 261 | |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 262 | ScratchAlloc SA(*this); |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 263 | getEntityInfo(D, DInfo.EntInfo, SA); |
Argyrios Kyrtzidis | db4d7a5 | 2012-01-14 02:05:51 +0000 | [diff] [blame] | 264 | if ((!indexFunctionLocalSymbols() && !DInfo.EntInfo.USR) |
| 265 | || Loc.isInvalid()) |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 266 | return false; |
Argyrios Kyrtzidis | 144b6c0 | 2011-11-18 00:26:46 +0000 | [diff] [blame] | 267 | |
Argyrios Kyrtzidis | c2be04e | 2011-12-13 18:47:35 +0000 | [diff] [blame] | 268 | if (suppressRefs()) |
| 269 | markEntityOccurrenceInFile(D, Loc); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 270 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 271 | DInfo.entityInfo = &DInfo.EntInfo; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 272 | DInfo.cursor = Cursor; |
| 273 | DInfo.loc = getIndexLoc(Loc); |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 274 | DInfo.isImplicit = D->isImplicit(); |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 275 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 276 | AttrListInfo AttrList(D, *this, SA); |
| 277 | DInfo.attributes = AttrList.getAttrs(); |
| 278 | DInfo.numAttributes = AttrList.getNumAttrs(); |
| 279 | |
Argyrios Kyrtzidis | b1febb6 | 2011-12-07 20:44:19 +0000 | [diff] [blame] | 280 | getContainerInfo(D->getDeclContext(), DInfo.SemanticContainer); |
| 281 | getContainerInfo(D->getLexicalDeclContext(), DInfo.LexicalContainer); |
| 282 | DInfo.semanticContainer = &DInfo.SemanticContainer; |
| 283 | DInfo.lexicalContainer = &DInfo.LexicalContainer; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 284 | if (DInfo.isContainer) { |
| 285 | getContainerInfo(getEntityContainer(D), DInfo.DeclAsContainer); |
| 286 | DInfo.declAsContainer = &DInfo.DeclAsContainer; |
| 287 | } |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 288 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 289 | CB.indexDeclaration(ClientData, &DInfo); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 290 | return true; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 293 | bool IndexingContext::handleObjCContainer(const ObjCContainerDecl *D, |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 294 | SourceLocation Loc, CXCursor Cursor, |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 295 | ObjCContainerDeclInfo &ContDInfo) { |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 296 | ContDInfo.ObjCContDeclInfo.declInfo = &ContDInfo; |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 297 | return handleDecl(D, Loc, Cursor, ContDInfo); |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 300 | bool IndexingContext::handleFunction(const FunctionDecl *D) { |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 301 | DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(), |
| 302 | D->isThisDeclarationADefinition()); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 303 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 306 | bool IndexingContext::handleVar(const VarDecl *D) { |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 307 | DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(), |
| 308 | /*isContainer=*/false); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 309 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 312 | bool IndexingContext::handleField(const FieldDecl *D) { |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 313 | DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true, |
| 314 | /*isContainer=*/false); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 315 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 318 | bool IndexingContext::handleEnumerator(const EnumConstantDecl *D) { |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 319 | DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true, |
| 320 | /*isContainer=*/false); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 321 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 324 | bool IndexingContext::handleTagDecl(const TagDecl *D) { |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 325 | if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(D)) |
| 326 | return handleCXXRecordDecl(CXXRD, D); |
| 327 | |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 328 | DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(), |
| 329 | D->isThisDeclarationADefinition()); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 330 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 333 | bool IndexingContext::handleTypedefName(const TypedefNameDecl *D) { |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 334 | DeclInfo DInfo(!D->isFirstDeclaration(), /*isDefinition=*/true, |
| 335 | /*isContainer=*/false); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 336 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 337 | } |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 338 | |
Douglas Gregor | 375bb14 | 2011-12-27 22:43:10 +0000 | [diff] [blame] | 339 | bool IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) { |
Argyrios Kyrtzidis | c2be04e | 2011-12-13 18:47:35 +0000 | [diff] [blame] | 340 | // For @class forward declarations, suppress them the same way as references. |
Douglas Gregor | 375bb14 | 2011-12-27 22:43:10 +0000 | [diff] [blame] | 341 | if (!D->isThisDeclarationADefinition()) { |
| 342 | if (suppressRefs() && markEntityOccurrenceInFile(D, D->getLocation())) |
Argyrios Kyrtzidis | c2be04e | 2011-12-13 18:47:35 +0000 | [diff] [blame] | 343 | return false; // already occurred. |
Douglas Gregor | 375bb14 | 2011-12-27 22:43:10 +0000 | [diff] [blame] | 344 | |
| 345 | // FIXME: This seems like the wrong definition for redeclaration. |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 346 | bool isRedeclaration = D->hasDefinition() || D->getPreviousDecl(); |
Douglas Gregor | 375bb14 | 2011-12-27 22:43:10 +0000 | [diff] [blame] | 347 | ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, isRedeclaration, |
| 348 | /*isImplementation=*/false); |
| 349 | return handleObjCContainer(D, D->getLocation(), |
| 350 | MakeCursorObjCClassRef(D, D->getLocation(), |
| 351 | CXTU), |
| 352 | ContDInfo); |
Argyrios Kyrtzidis | c2be04e | 2011-12-13 18:47:35 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 355 | ScratchAlloc SA(*this); |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 356 | |
| 357 | CXIdxBaseClassInfo BaseClass; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 358 | EntityInfo BaseEntity; |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 359 | BaseClass.cursor = clang_getNullCursor(); |
| 360 | if (ObjCInterfaceDecl *SuperD = D->getSuperClass()) { |
| 361 | getEntityInfo(SuperD, BaseEntity, SA); |
| 362 | SourceLocation SuperLoc = D->getSuperClassLoc(); |
| 363 | BaseClass.base = &BaseEntity; |
| 364 | BaseClass.cursor = MakeCursorObjCSuperClassRef(SuperD, SuperLoc, CXTU); |
| 365 | BaseClass.loc = getIndexLoc(SuperLoc); |
Argyrios Kyrtzidis | 90fd67a | 2011-12-15 00:04:56 +0000 | [diff] [blame] | 366 | |
| 367 | if (suppressRefs()) |
| 368 | markEntityOccurrenceInFile(SuperD, SuperLoc); |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 371 | ObjCProtocolList EmptyProtoList; |
Douglas Gregor | 5e2a1ff | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 372 | ObjCProtocolListInfo ProtInfo(D->isThisDeclarationADefinition() |
| 373 | ? D->getReferencedProtocols() |
| 374 | : EmptyProtoList, |
Douglas Gregor | 2e5c15b | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 375 | *this, SA); |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 376 | |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 377 | ObjCInterfaceDeclInfo InterInfo(D); |
| 378 | InterInfo.ObjCProtoListInfo = ProtInfo.getListInfo(); |
| 379 | InterInfo.ObjCInterDeclInfo.containerInfo = &InterInfo.ObjCContDeclInfo; |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 380 | InterInfo.ObjCInterDeclInfo.superInfo = D->getSuperClass() ? &BaseClass : 0; |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 381 | InterInfo.ObjCInterDeclInfo.protocols = &InterInfo.ObjCProtoListInfo; |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 382 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 383 | return handleObjCContainer(D, D->getLocation(), getCursor(D), InterInfo); |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 384 | } |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 385 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 386 | bool IndexingContext::handleObjCImplementation( |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 387 | const ObjCImplementationDecl *D) { |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 388 | ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/false, |
Argyrios Kyrtzidis | e7bbab9 | 2011-11-15 06:20:24 +0000 | [diff] [blame] | 389 | /*isRedeclaration=*/true, |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 390 | /*isImplementation=*/true); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 391 | return handleObjCContainer(D, D->getLocation(), getCursor(D), ContDInfo); |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 392 | } |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 393 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 394 | bool IndexingContext::handleObjCProtocol(const ObjCProtocolDecl *D) { |
Douglas Gregor | bd9482d | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 395 | if (!D->isThisDeclarationADefinition()) { |
| 396 | if (suppressRefs() && markEntityOccurrenceInFile(D, D->getLocation())) |
| 397 | return false; // already occurred. |
| 398 | |
| 399 | // FIXME: This seems like the wrong definition for redeclaration. |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 400 | bool isRedeclaration = D->hasDefinition() || D->getPreviousDecl(); |
Douglas Gregor | bd9482d | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 401 | ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, |
| 402 | isRedeclaration, |
| 403 | /*isImplementation=*/false); |
| 404 | return handleObjCContainer(D, D->getLocation(), |
| 405 | MakeCursorObjCProtocolRef(D, D->getLocation(), |
| 406 | CXTU), |
| 407 | ContDInfo); |
| 408 | } |
| 409 | |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 410 | ScratchAlloc SA(*this); |
Douglas Gregor | 5e2a1ff | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 411 | ObjCProtocolList EmptyProtoList; |
| 412 | ObjCProtocolListInfo ProtListInfo(D->isThisDeclarationADefinition() |
| 413 | ? D->getReferencedProtocols() |
| 414 | : EmptyProtoList, |
| 415 | *this, SA); |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 416 | |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 417 | ObjCProtocolDeclInfo ProtInfo(D); |
| 418 | ProtInfo.ObjCProtoRefListInfo = ProtListInfo.getListInfo(); |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 419 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 420 | return handleObjCContainer(D, D->getLocation(), getCursor(D), ProtInfo); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 423 | bool IndexingContext::handleObjCCategory(const ObjCCategoryDecl *D) { |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 424 | ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/false); |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 425 | EntityInfo ClassEntity; |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 426 | ScratchAlloc SA(*this); |
Argyrios Kyrtzidis | 21ee570 | 2011-11-15 06:20:16 +0000 | [diff] [blame] | 427 | const ObjCInterfaceDecl *IFaceD = D->getClassInterface(); |
| 428 | SourceLocation ClassLoc = D->getLocation(); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 429 | SourceLocation CategoryLoc = D->IsClassExtension() ? ClassLoc |
| 430 | : D->getCategoryNameLoc(); |
Argyrios Kyrtzidis | c6b4a50 | 2011-11-16 02:34:59 +0000 | [diff] [blame] | 431 | getEntityInfo(IFaceD, ClassEntity, SA); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 432 | |
Argyrios Kyrtzidis | c2be04e | 2011-12-13 18:47:35 +0000 | [diff] [blame] | 433 | if (suppressRefs()) |
| 434 | markEntityOccurrenceInFile(IFaceD, ClassLoc); |
| 435 | |
Argyrios Kyrtzidis | c10a4c8 | 2011-12-13 18:47:45 +0000 | [diff] [blame] | 436 | ObjCProtocolListInfo ProtInfo(D->getReferencedProtocols(), *this, SA); |
| 437 | |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 438 | CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo; |
Argyrios Kyrtzidis | c6b4a50 | 2011-11-16 02:34:59 +0000 | [diff] [blame] | 439 | if (IFaceD) { |
| 440 | CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity; |
| 441 | CatDInfo.ObjCCatDeclInfo.classCursor = |
| 442 | MakeCursorObjCClassRef(IFaceD, ClassLoc, CXTU); |
| 443 | } else { |
| 444 | CatDInfo.ObjCCatDeclInfo.objcClass = 0; |
| 445 | CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor(); |
| 446 | } |
Argyrios Kyrtzidis | 21ee570 | 2011-11-15 06:20:16 +0000 | [diff] [blame] | 447 | CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc); |
Argyrios Kyrtzidis | c10a4c8 | 2011-12-13 18:47:45 +0000 | [diff] [blame] | 448 | CatDInfo.ObjCProtoListInfo = ProtInfo.getListInfo(); |
| 449 | CatDInfo.ObjCCatDeclInfo.protocols = &CatDInfo.ObjCProtoListInfo; |
| 450 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 451 | return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 454 | bool IndexingContext::handleObjCCategoryImpl(const ObjCCategoryImplDecl *D) { |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 455 | const ObjCCategoryDecl *CatD = D->getCategoryDecl(); |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 456 | ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/true); |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 457 | EntityInfo ClassEntity; |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 458 | ScratchAlloc SA(*this); |
Argyrios Kyrtzidis | 3e340a6 | 2011-11-16 02:35:05 +0000 | [diff] [blame] | 459 | const ObjCInterfaceDecl *IFaceD = CatD->getClassInterface(); |
| 460 | SourceLocation ClassLoc = D->getLocation(); |
Argyrios Kyrtzidis | c699400 | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 461 | SourceLocation CategoryLoc = D->getCategoryNameLoc(); |
Argyrios Kyrtzidis | 3e340a6 | 2011-11-16 02:35:05 +0000 | [diff] [blame] | 462 | getEntityInfo(IFaceD, ClassEntity, SA); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 463 | |
Argyrios Kyrtzidis | 6ec43ad | 2011-11-12 02:16:30 +0000 | [diff] [blame] | 464 | CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo; |
Argyrios Kyrtzidis | 3e340a6 | 2011-11-16 02:35:05 +0000 | [diff] [blame] | 465 | if (IFaceD) { |
| 466 | CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity; |
| 467 | CatDInfo.ObjCCatDeclInfo.classCursor = |
| 468 | MakeCursorObjCClassRef(IFaceD, ClassLoc, CXTU); |
| 469 | } else { |
| 470 | CatDInfo.ObjCCatDeclInfo.objcClass = 0; |
| 471 | CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor(); |
| 472 | } |
| 473 | CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc); |
Argyrios Kyrtzidis | c10a4c8 | 2011-12-13 18:47:45 +0000 | [diff] [blame] | 474 | CatDInfo.ObjCCatDeclInfo.protocols = 0; |
| 475 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 476 | return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 479 | bool IndexingContext::handleObjCMethod(const ObjCMethodDecl *D) { |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 480 | DeclInfo DInfo(!D->isCanonicalDecl(), D->isThisDeclarationADefinition(), |
| 481 | D->isThisDeclarationADefinition()); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 482 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 485 | bool IndexingContext::handleSynthesizedObjCProperty( |
| 486 | const ObjCPropertyImplDecl *D) { |
| 487 | ObjCPropertyDecl *PD = D->getPropertyDecl(); |
| 488 | return handleReference(PD, D->getLocation(), getCursor(D), 0, D->getDeclContext()); |
| 489 | } |
| 490 | |
| 491 | bool IndexingContext::handleSynthesizedObjCMethod(const ObjCMethodDecl *D, |
| 492 | SourceLocation Loc) { |
| 493 | DeclInfo DInfo(/*isRedeclaration=*/true, /*isDefinition=*/true, |
| 494 | /*isContainer=*/false); |
| 495 | return handleDecl(D, Loc, getCursor(D), DInfo); |
| 496 | } |
| 497 | |
| 498 | bool IndexingContext::handleObjCProperty(const ObjCPropertyDecl *D) { |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 499 | DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/false, |
| 500 | /*isContainer=*/false); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 501 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Argyrios Kyrtzidis | 68478b0 | 2011-12-07 05:52:06 +0000 | [diff] [blame] | 504 | bool IndexingContext::handleNamespace(const NamespaceDecl *D) { |
| 505 | DeclInfo DInfo(/*isRedeclaration=*/!D->isOriginalNamespace(), |
| 506 | /*isDefinition=*/true, |
| 507 | /*isContainer=*/true); |
| 508 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
| 509 | } |
| 510 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 511 | bool IndexingContext::handleClassTemplate(const ClassTemplateDecl *D) { |
| 512 | return handleCXXRecordDecl(D->getTemplatedDecl(), D); |
| 513 | } |
| 514 | |
| 515 | bool IndexingContext::handleFunctionTemplate(const FunctionTemplateDecl *D) { |
| 516 | DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(), |
| 517 | /*isDefinition=*/D->isThisDeclarationADefinition(), |
| 518 | /*isContainer=*/D->isThisDeclarationADefinition()); |
| 519 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
| 520 | } |
| 521 | |
| 522 | bool IndexingContext::handleTypeAliasTemplate(const TypeAliasTemplateDecl *D) { |
| 523 | DeclInfo DInfo(/*isRedeclaration=*/!D->isCanonicalDecl(), |
| 524 | /*isDefinition=*/true, /*isContainer=*/false); |
| 525 | return handleDecl(D, D->getLocation(), getCursor(D), DInfo); |
| 526 | } |
| 527 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 528 | bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 529 | const NamedDecl *Parent, |
| 530 | const DeclContext *DC, |
Argyrios Kyrtzidis | aca19be | 2011-10-18 15:50:50 +0000 | [diff] [blame] | 531 | const Expr *E, |
| 532 | CXIdxEntityRefKind Kind) { |
Argyrios Kyrtzidis | d6c8209 | 2011-11-16 02:35:01 +0000 | [diff] [blame] | 533 | if (!D) |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 534 | return false; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 535 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 536 | CXCursor Cursor = E ? MakeCXCursor(const_cast<Expr*>(E), |
| 537 | const_cast<Decl*>(cast<Decl>(DC)), CXTU) |
| 538 | : getRefCursor(D, Loc); |
| 539 | return handleReference(D, Loc, Cursor, Parent, DC, E, Kind); |
| 540 | } |
| 541 | |
| 542 | bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, |
| 543 | CXCursor Cursor, |
| 544 | const NamedDecl *Parent, |
| 545 | const DeclContext *DC, |
| 546 | const Expr *E, |
| 547 | CXIdxEntityRefKind Kind) { |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 548 | if (!CB.indexEntityReference) |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 549 | return false; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 550 | |
| 551 | if (!D) |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 552 | return false; |
| 553 | if (Loc.isInvalid()) |
| 554 | return false; |
Argyrios Kyrtzidis | 2249074 | 2012-01-14 00:11:49 +0000 | [diff] [blame] | 555 | if (!indexFunctionLocalSymbols() && D->getParentFunctionOrMethod()) |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 556 | return false; |
| 557 | if (isNotFromSourceFile(D->getLocation())) |
| 558 | return false; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 559 | if (D->isImplicit() && shouldIgnoreIfImplicit(D)) |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 560 | return false; |
Argyrios Kyrtzidis | 144b6c0 | 2011-11-18 00:26:46 +0000 | [diff] [blame] | 561 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 562 | if (suppressRefs()) { |
| 563 | if (markEntityOccurrenceInFile(D, Loc)) |
| 564 | return false; // already occurred. |
Argyrios Kyrtzidis | c6b4a50 | 2011-11-16 02:34:59 +0000 | [diff] [blame] | 565 | } |
| 566 | |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 567 | ScratchAlloc SA(*this); |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 568 | EntityInfo RefEntity, ParentEntity; |
| 569 | getEntityInfo(D, RefEntity, SA); |
| 570 | if (!RefEntity.USR) |
| 571 | return false; |
| 572 | |
| 573 | getEntityInfo(Parent, ParentEntity, SA); |
| 574 | |
| 575 | ContainerInfo Container; |
| 576 | getContainerInfo(DC, Container); |
| 577 | |
Argyrios Kyrtzidis | b1febb6 | 2011-12-07 20:44:19 +0000 | [diff] [blame] | 578 | CXIdxEntityRefInfo Info = { Kind, |
| 579 | Cursor, |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 580 | getIndexLoc(Loc), |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 581 | &RefEntity, |
Argyrios Kyrtzidis | c6b4a50 | 2011-11-16 02:34:59 +0000 | [diff] [blame] | 582 | Parent ? &ParentEntity : 0, |
Argyrios Kyrtzidis | b1febb6 | 2011-12-07 20:44:19 +0000 | [diff] [blame] | 583 | &Container }; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 584 | CB.indexEntityReference(ClientData, &Info); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 585 | return true; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 588 | bool IndexingContext::isNotFromSourceFile(SourceLocation Loc) const { |
| 589 | if (Loc.isInvalid()) |
| 590 | return true; |
| 591 | SourceManager &SM = Ctx->getSourceManager(); |
| 592 | SourceLocation FileLoc = SM.getFileLoc(Loc); |
| 593 | FileID FID = SM.getFileID(FileLoc); |
| 594 | return SM.getFileEntryForID(FID) == 0; |
| 595 | } |
| 596 | |
| 597 | void IndexingContext::addContainerInMap(const DeclContext *DC, |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 598 | CXIdxClientContainer container) { |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 599 | if (!DC) |
| 600 | return; |
| 601 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 602 | ContainerMapTy::iterator I = ContainerMap.find(DC); |
| 603 | if (I == ContainerMap.end()) { |
| 604 | if (container) |
| 605 | ContainerMap[DC] = container; |
| 606 | return; |
| 607 | } |
| 608 | // Allow changing the container of a previously seen DeclContext so we |
| 609 | // can handle invalid user code, like a function re-definition. |
| 610 | if (container) |
| 611 | I->second = container; |
| 612 | else |
| 613 | ContainerMap.erase(I); |
| 614 | } |
| 615 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 616 | CXIdxClientEntity IndexingContext::getClientEntity(const Decl *D) const { |
| 617 | if (!D) |
| 618 | return 0; |
| 619 | EntityMapTy::const_iterator I = EntityMap.find(D); |
| 620 | if (I == EntityMap.end()) |
| 621 | return 0; |
| 622 | return I->second; |
| 623 | } |
| 624 | |
| 625 | void IndexingContext::setClientEntity(const Decl *D, CXIdxClientEntity client) { |
| 626 | if (!D) |
| 627 | return; |
| 628 | EntityMap[D] = client; |
| 629 | } |
| 630 | |
| 631 | bool IndexingContext::handleCXXRecordDecl(const CXXRecordDecl *RD, |
| 632 | const NamedDecl *OrigD) { |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 633 | if (RD->isThisDeclarationADefinition()) { |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 634 | ScratchAlloc SA(*this); |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 635 | CXXClassDeclInfo CXXDInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(), |
| 636 | /*isDefinition=*/RD->isThisDeclarationADefinition()); |
| 637 | CXXBasesListInfo BaseList(RD, *this, SA); |
| 638 | CXXDInfo.CXXClassInfo.declInfo = &CXXDInfo; |
| 639 | CXXDInfo.CXXClassInfo.bases = BaseList.getBases(); |
| 640 | CXXDInfo.CXXClassInfo.numBases = BaseList.getNumBases(); |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 641 | |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 642 | return handleDecl(OrigD, OrigD->getLocation(), getCursor(OrigD), CXXDInfo); |
| 643 | } |
| 644 | |
| 645 | DeclInfo DInfo(/*isRedeclaration=*/!OrigD->isCanonicalDecl(), |
| 646 | /*isDefinition=*/RD->isThisDeclarationADefinition(), |
| 647 | /*isContainer=*/RD->isThisDeclarationADefinition()); |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 648 | return handleDecl(OrigD, OrigD->getLocation(), getCursor(OrigD), DInfo); |
| 649 | } |
| 650 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 651 | bool IndexingContext::markEntityOccurrenceInFile(const NamedDecl *D, |
| 652 | SourceLocation Loc) { |
Argyrios Kyrtzidis | c2be04e | 2011-12-13 18:47:35 +0000 | [diff] [blame] | 653 | if (!D || Loc.isInvalid()) |
| 654 | return true; |
| 655 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 656 | SourceManager &SM = Ctx->getSourceManager(); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 657 | D = getEntityDecl(D); |
| 658 | |
Argyrios Kyrtzidis | c2be04e | 2011-12-13 18:47:35 +0000 | [diff] [blame] | 659 | std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SM.getFileLoc(Loc)); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 660 | FileID FID = LocInfo.first; |
| 661 | if (FID.isInvalid()) |
| 662 | return true; |
| 663 | |
| 664 | const FileEntry *FE = SM.getFileEntryForID(FID); |
| 665 | if (!FE) |
| 666 | return true; |
| 667 | RefFileOccurence RefOccur(FE, D); |
| 668 | std::pair<llvm::DenseSet<RefFileOccurence>::iterator, bool> |
| 669 | res = RefFileOccurences.insert(RefOccur); |
| 670 | if (!res.second) |
| 671 | return true; // already in map. |
| 672 | |
| 673 | return false; |
| 674 | } |
| 675 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 676 | const NamedDecl *IndexingContext::getEntityDecl(const NamedDecl *D) const { |
| 677 | assert(D); |
| 678 | D = cast<NamedDecl>(D->getCanonicalDecl()); |
| 679 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 680 | if (const ObjCImplementationDecl * |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 681 | ImplD = dyn_cast<ObjCImplementationDecl>(D)) { |
| 682 | return getEntityDecl(ImplD->getClassInterface()); |
| 683 | |
| 684 | } else if (const ObjCCategoryImplDecl * |
| 685 | CatImplD = dyn_cast<ObjCCategoryImplDecl>(D)) { |
| 686 | return getEntityDecl(CatImplD->getCategoryDecl()); |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 687 | } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 688 | if (FunctionTemplateDecl *TemplD = FD->getDescribedFunctionTemplate()) |
| 689 | return getEntityDecl(TemplD); |
| 690 | } else if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { |
| 691 | if (ClassTemplateDecl *TemplD = RD->getDescribedClassTemplate()) |
| 692 | return getEntityDecl(TemplD); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | return D; |
| 696 | } |
| 697 | |
| 698 | const DeclContext * |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 699 | IndexingContext::getEntityContainer(const Decl *D) const { |
| 700 | const DeclContext *DC = dyn_cast<DeclContext>(D); |
| 701 | if (DC) |
| 702 | return DC; |
| 703 | |
| 704 | if (const ClassTemplateDecl *ClassTempl = dyn_cast<ClassTemplateDecl>(D)) { |
| 705 | DC = ClassTempl->getTemplatedDecl(); |
| 706 | } if (const FunctionTemplateDecl * |
| 707 | FuncTempl = dyn_cast<FunctionTemplateDecl>(D)) { |
| 708 | DC = FuncTempl->getTemplatedDecl(); |
| 709 | } |
| 710 | |
| 711 | return DC; |
| 712 | } |
| 713 | |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 714 | CXIdxClientContainer |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 715 | IndexingContext::getClientContainerForDC(const DeclContext *DC) const { |
| 716 | if (!DC) |
| 717 | return 0; |
| 718 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 719 | ContainerMapTy::const_iterator I = ContainerMap.find(DC); |
Argyrios Kyrtzidis | 3e340a6 | 2011-11-16 02:35:05 +0000 | [diff] [blame] | 720 | if (I == ContainerMap.end()) |
| 721 | return 0; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 722 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 723 | return I->second; |
| 724 | } |
| 725 | |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 726 | CXIdxClientFile IndexingContext::getIndexFile(const FileEntry *File) { |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 727 | if (!File) |
| 728 | return 0; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 729 | |
| 730 | FileMapTy::iterator FI = FileMap.find(File); |
| 731 | if (FI != FileMap.end()) |
| 732 | return FI->second; |
| 733 | |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 734 | return 0; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | CXIdxLoc IndexingContext::getIndexLoc(SourceLocation Loc) const { |
| 738 | CXIdxLoc idxLoc = { {0, 0}, 0 }; |
| 739 | if (Loc.isInvalid()) |
| 740 | return idxLoc; |
| 741 | |
| 742 | idxLoc.ptr_data[0] = (void*)this; |
| 743 | idxLoc.int_data = Loc.getRawEncoding(); |
| 744 | return idxLoc; |
| 745 | } |
| 746 | |
| 747 | void IndexingContext::translateLoc(SourceLocation Loc, |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 748 | CXIdxClientFile *indexFile, CXFile *file, |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 749 | unsigned *line, unsigned *column, |
| 750 | unsigned *offset) { |
| 751 | if (Loc.isInvalid()) |
| 752 | return; |
| 753 | |
| 754 | SourceManager &SM = Ctx->getSourceManager(); |
| 755 | Loc = SM.getFileLoc(Loc); |
| 756 | |
| 757 | std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc); |
| 758 | FileID FID = LocInfo.first; |
| 759 | unsigned FileOffset = LocInfo.second; |
| 760 | |
| 761 | if (FID.isInvalid()) |
| 762 | return; |
| 763 | |
| 764 | const FileEntry *FE = SM.getFileEntryForID(FID); |
| 765 | if (indexFile) |
| 766 | *indexFile = getIndexFile(FE); |
| 767 | if (file) |
| 768 | *file = (void *)FE; |
| 769 | if (line) |
| 770 | *line = SM.getLineNumber(FID, FileOffset); |
| 771 | if (column) |
| 772 | *column = SM.getColumnNumber(FID, FileOffset); |
| 773 | if (offset) |
| 774 | *offset = FileOffset; |
| 775 | } |
| 776 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 777 | void IndexingContext::getEntityInfo(const NamedDecl *D, |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 778 | EntityInfo &EntityInfo, |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 779 | ScratchAlloc &SA) { |
Argyrios Kyrtzidis | c6b4a50 | 2011-11-16 02:34:59 +0000 | [diff] [blame] | 780 | if (!D) |
| 781 | return; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 782 | |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 783 | D = getEntityDecl(D); |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 784 | EntityInfo.cursor = getCursor(D); |
| 785 | EntityInfo.Dcl = D; |
| 786 | EntityInfo.IndexCtx = this; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 787 | EntityInfo.kind = CXIdxEntity_Unexposed; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 788 | EntityInfo.templateKind = CXIdxEntity_NonTemplate; |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 789 | EntityInfo.lang = CXIdxEntityLang_C; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 790 | |
Argyrios Kyrtzidis | 643d3ce | 2011-12-15 00:05:00 +0000 | [diff] [blame] | 791 | if (D->hasAttrs()) { |
| 792 | AttrListInfo *attrs = SA.allocate<AttrListInfo>(); |
| 793 | new (attrs) AttrListInfo(D, *this, SA); |
| 794 | EntityInfo.AttrList = attrs; |
| 795 | EntityInfo.attributes = attrs->getAttrs(); |
| 796 | EntityInfo.numAttributes = attrs->getNumAttrs(); |
| 797 | } |
| 798 | |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 799 | if (const TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 800 | switch (TD->getTagKind()) { |
| 801 | case TTK_Struct: |
| 802 | EntityInfo.kind = CXIdxEntity_Struct; break; |
| 803 | case TTK_Union: |
| 804 | EntityInfo.kind = CXIdxEntity_Union; break; |
| 805 | case TTK_Class: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 806 | EntityInfo.kind = CXIdxEntity_CXXClass; |
| 807 | EntityInfo.lang = CXIdxEntityLang_CXX; |
| 808 | break; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 809 | case TTK_Enum: |
| 810 | EntityInfo.kind = CXIdxEntity_Enum; break; |
| 811 | } |
| 812 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 813 | if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D)) { |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 814 | // FIXME: isPOD check is not sufficient, a POD can contain methods, |
| 815 | // we want a isCStructLike check. |
| 816 | if (CXXRec->hasDefinition() && !CXXRec->isPOD()) |
| 817 | EntityInfo.lang = CXIdxEntityLang_CXX; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | if (isa<ClassTemplatePartialSpecializationDecl>(D)) { |
| 821 | EntityInfo.templateKind = CXIdxEntity_TemplatePartialSpecialization; |
| 822 | } else if (isa<ClassTemplateSpecializationDecl>(D)) { |
| 823 | EntityInfo.templateKind = CXIdxEntity_TemplateSpecialization; |
| 824 | } |
| 825 | |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 826 | } else { |
| 827 | switch (D->getKind()) { |
| 828 | case Decl::Typedef: |
| 829 | EntityInfo.kind = CXIdxEntity_Typedef; break; |
| 830 | case Decl::Function: |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 831 | EntityInfo.kind = CXIdxEntity_Function; |
| 832 | break; |
Argyrios Kyrtzidis | db4d7a5 | 2012-01-14 02:05:51 +0000 | [diff] [blame] | 833 | case Decl::ParmVar: |
| 834 | EntityInfo.kind = CXIdxEntity_Variable; |
| 835 | break; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 836 | case Decl::Var: |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 837 | EntityInfo.kind = CXIdxEntity_Variable; |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 838 | if (isa<CXXRecordDecl>(D->getDeclContext())) { |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 839 | EntityInfo.kind = CXIdxEntity_CXXStaticVariable; |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 840 | EntityInfo.lang = CXIdxEntityLang_CXX; |
| 841 | } |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 842 | break; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 843 | case Decl::Field: |
Argyrios Kyrtzidis | da5f2d2 | 2011-12-05 22:05:28 +0000 | [diff] [blame] | 844 | EntityInfo.kind = CXIdxEntity_Field; |
| 845 | if (const CXXRecordDecl * |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 846 | CXXRec = dyn_cast<CXXRecordDecl>(D->getDeclContext())) { |
| 847 | // FIXME: isPOD check is not sufficient, a POD can contain methods, |
| 848 | // we want a isCStructLike check. |
Argyrios Kyrtzidis | da5f2d2 | 2011-12-05 22:05:28 +0000 | [diff] [blame] | 849 | if (!CXXRec->isPOD()) |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 850 | EntityInfo.lang = CXIdxEntityLang_CXX; |
| 851 | } |
Argyrios Kyrtzidis | da5f2d2 | 2011-12-05 22:05:28 +0000 | [diff] [blame] | 852 | break; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 853 | case Decl::EnumConstant: |
| 854 | EntityInfo.kind = CXIdxEntity_EnumConstant; break; |
| 855 | case Decl::ObjCInterface: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 856 | EntityInfo.kind = CXIdxEntity_ObjCClass; |
| 857 | EntityInfo.lang = CXIdxEntityLang_ObjC; |
| 858 | break; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 859 | case Decl::ObjCProtocol: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 860 | EntityInfo.kind = CXIdxEntity_ObjCProtocol; |
| 861 | EntityInfo.lang = CXIdxEntityLang_ObjC; |
| 862 | break; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 863 | case Decl::ObjCCategory: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 864 | EntityInfo.kind = CXIdxEntity_ObjCCategory; |
| 865 | EntityInfo.lang = CXIdxEntityLang_ObjC; |
| 866 | break; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 867 | case Decl::ObjCMethod: |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 868 | if (cast<ObjCMethodDecl>(D)->isInstanceMethod()) |
| 869 | EntityInfo.kind = CXIdxEntity_ObjCInstanceMethod; |
| 870 | else |
| 871 | EntityInfo.kind = CXIdxEntity_ObjCClassMethod; |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 872 | EntityInfo.lang = CXIdxEntityLang_ObjC; |
Argyrios Kyrtzidis | c71d554 | 2011-11-14 22:39:19 +0000 | [diff] [blame] | 873 | break; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 874 | case Decl::ObjCProperty: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 875 | EntityInfo.kind = CXIdxEntity_ObjCProperty; |
| 876 | EntityInfo.lang = CXIdxEntityLang_ObjC; |
| 877 | break; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 878 | case Decl::ObjCIvar: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 879 | EntityInfo.kind = CXIdxEntity_ObjCIvar; |
| 880 | EntityInfo.lang = CXIdxEntityLang_ObjC; |
| 881 | break; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 882 | case Decl::Namespace: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 883 | EntityInfo.kind = CXIdxEntity_CXXNamespace; |
| 884 | EntityInfo.lang = CXIdxEntityLang_CXX; |
| 885 | break; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 886 | case Decl::NamespaceAlias: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 887 | EntityInfo.kind = CXIdxEntity_CXXNamespaceAlias; |
| 888 | EntityInfo.lang = CXIdxEntityLang_CXX; |
| 889 | break; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 890 | case Decl::CXXConstructor: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 891 | EntityInfo.kind = CXIdxEntity_CXXConstructor; |
| 892 | EntityInfo.lang = CXIdxEntityLang_CXX; |
| 893 | break; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 894 | case Decl::CXXDestructor: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 895 | EntityInfo.kind = CXIdxEntity_CXXDestructor; |
| 896 | EntityInfo.lang = CXIdxEntityLang_CXX; |
| 897 | break; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 898 | case Decl::CXXConversion: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 899 | EntityInfo.kind = CXIdxEntity_CXXConversionFunction; |
| 900 | EntityInfo.lang = CXIdxEntityLang_CXX; |
| 901 | break; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 902 | case Decl::CXXMethod: { |
| 903 | const CXXMethodDecl *MD = cast<CXXMethodDecl>(D); |
| 904 | if (MD->isStatic()) |
| 905 | EntityInfo.kind = CXIdxEntity_CXXStaticMethod; |
| 906 | else |
| 907 | EntityInfo.kind = CXIdxEntity_CXXInstanceMethod; |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 908 | EntityInfo.lang = CXIdxEntityLang_CXX; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 909 | break; |
| 910 | } |
| 911 | case Decl::ClassTemplate: |
| 912 | EntityInfo.kind = CXIdxEntity_CXXClass; |
| 913 | EntityInfo.templateKind = CXIdxEntity_Template; |
| 914 | break; |
| 915 | case Decl::FunctionTemplate: |
| 916 | EntityInfo.kind = CXIdxEntity_Function; |
| 917 | EntityInfo.templateKind = CXIdxEntity_Template; |
| 918 | if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>( |
| 919 | cast<FunctionTemplateDecl>(D)->getTemplatedDecl())) { |
| 920 | if (isa<CXXConstructorDecl>(MD)) |
| 921 | EntityInfo.kind = CXIdxEntity_CXXConstructor; |
| 922 | else if (isa<CXXDestructorDecl>(MD)) |
| 923 | EntityInfo.kind = CXIdxEntity_CXXDestructor; |
| 924 | else if (isa<CXXConversionDecl>(MD)) |
| 925 | EntityInfo.kind = CXIdxEntity_CXXConversionFunction; |
| 926 | else { |
| 927 | if (MD->isStatic()) |
| 928 | EntityInfo.kind = CXIdxEntity_CXXStaticMethod; |
| 929 | else |
| 930 | EntityInfo.kind = CXIdxEntity_CXXInstanceMethod; |
| 931 | } |
| 932 | } |
| 933 | break; |
| 934 | case Decl::TypeAliasTemplate: |
| 935 | EntityInfo.kind = CXIdxEntity_CXXTypeAlias; |
| 936 | EntityInfo.templateKind = CXIdxEntity_Template; |
| 937 | break; |
| 938 | case Decl::TypeAlias: |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 939 | EntityInfo.kind = CXIdxEntity_CXXTypeAlias; |
| 940 | EntityInfo.lang = CXIdxEntityLang_CXX; |
| 941 | break; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 942 | default: |
| 943 | break; |
| 944 | } |
| 945 | } |
| 946 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 947 | if (EntityInfo.kind == CXIdxEntity_Unexposed) |
| 948 | return; |
| 949 | |
| 950 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 951 | if (FD->getTemplatedKind() == |
| 952 | FunctionDecl::TK_FunctionTemplateSpecialization) |
| 953 | EntityInfo.templateKind = CXIdxEntity_TemplateSpecialization; |
| 954 | } |
| 955 | |
Argyrios Kyrtzidis | 838d3c2 | 2011-12-07 20:44:12 +0000 | [diff] [blame] | 956 | if (EntityInfo.templateKind != CXIdxEntity_NonTemplate) |
| 957 | EntityInfo.lang = CXIdxEntityLang_CXX; |
| 958 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 959 | if (IdentifierInfo *II = D->getIdentifier()) { |
| 960 | EntityInfo.name = SA.toCStr(II->getName()); |
| 961 | |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 962 | } else if (isa<TagDecl>(D) || isa<FieldDecl>(D) || isa<NamespaceDecl>(D)) { |
| 963 | EntityInfo.name = 0; // anonymous tag/field/namespace. |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 964 | |
| 965 | } else { |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 966 | llvm::SmallString<256> StrBuf; |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 967 | { |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 968 | llvm::raw_svector_ostream OS(StrBuf); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 969 | D->printName(OS); |
| 970 | } |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 971 | EntityInfo.name = SA.copyCStr(StrBuf.str()); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 974 | { |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 975 | llvm::SmallString<512> StrBuf; |
| 976 | bool Ignore = getDeclCursorUSR(D, StrBuf); |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 977 | if (Ignore) { |
Argyrios Kyrtzidis | 144b6c0 | 2011-11-18 00:26:46 +0000 | [diff] [blame] | 978 | EntityInfo.USR = 0; |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 979 | } else { |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 980 | EntityInfo.USR = SA.copyCStr(StrBuf.str()); |
Argyrios Kyrtzidis | dd93c59 | 2011-11-11 00:23:36 +0000 | [diff] [blame] | 981 | } |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 982 | } |
| 983 | } |
| 984 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 985 | void IndexingContext::getContainerInfo(const DeclContext *DC, |
| 986 | ContainerInfo &ContInfo) { |
| 987 | ContInfo.cursor = getCursor(cast<Decl>(DC)); |
| 988 | ContInfo.DC = DC; |
| 989 | ContInfo.IndexCtx = this; |
| 990 | } |
| 991 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 992 | CXCursor IndexingContext::getRefCursor(const NamedDecl *D, SourceLocation Loc) { |
| 993 | if (const TypeDecl *TD = dyn_cast<TypeDecl>(D)) |
| 994 | return MakeCursorTypeRef(TD, Loc, CXTU); |
| 995 | if (const ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) |
| 996 | return MakeCursorObjCClassRef(ID, Loc, CXTU); |
| 997 | if (const ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) |
| 998 | return MakeCursorObjCProtocolRef(PD, Loc, CXTU); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 999 | if (const TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) |
| 1000 | return MakeCursorTemplateRef(Template, Loc, CXTU); |
| 1001 | if (const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(D)) |
| 1002 | return MakeCursorNamespaceRef(Namespace, Loc, CXTU); |
| 1003 | if (const NamespaceAliasDecl *Namespace = dyn_cast<NamespaceAliasDecl>(D)) |
| 1004 | return MakeCursorNamespaceRef(Namespace, Loc, CXTU); |
| 1005 | if (const FieldDecl *Field = dyn_cast<FieldDecl>(D)) |
| 1006 | return MakeCursorMemberRef(Field, Loc, CXTU); |
| 1007 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 1008 | return clang_getNullCursor(); |
| 1009 | } |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 1010 | |
| 1011 | bool IndexingContext::shouldIgnoreIfImplicit(const NamedDecl *D) { |
Argyrios Kyrtzidis | 37f4057 | 2011-11-23 20:27:26 +0000 | [diff] [blame] | 1012 | if (isa<ObjCInterfaceDecl>(D)) |
| 1013 | return false; |
| 1014 | if (isa<ObjCCategoryDecl>(D)) |
| 1015 | return false; |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 1016 | if (isa<ObjCIvarDecl>(D)) |
| 1017 | return false; |
| 1018 | if (isa<ObjCMethodDecl>(D)) |
| 1019 | return false; |
| 1020 | return true; |
| 1021 | } |