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