//===- CIndexHigh.cpp - Higher level API functions ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "IndexingContext.h"
#include "CXTranslationUnit.h"
#include "CIndexDiagnostic.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclTemplate.h"
using namespace clang;
using namespace cxindex;
using namespace cxcursor;
IndexingContext::ObjCProtocolListInfo::ObjCProtocolListInfo(
const ObjCProtocolList &ProtList,
IndexingContext &IdxCtx,
StrAdapter &SA) {
ObjCInterfaceDecl::protocol_loc_iterator LI = ProtList.loc_begin();
for (ObjCInterfaceDecl::protocol_iterator
I = ProtList.begin(), E = ProtList.end(); I != E; ++I, ++LI) {
SourceLocation Loc = *LI;
ObjCProtocolDecl *PD = *I;
ProtEntities.push_back(EntityInfo());
IdxCtx.getEntityInfo(PD, ProtEntities.back(), SA);
CXIdxObjCProtocolRefInfo ProtInfo = { 0,
MakeCursorObjCProtocolRef(PD, Loc, IdxCtx.CXTU),
IdxCtx.getIndexLoc(Loc) };
ProtInfos.push_back(ProtInfo);
}
for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i)
ProtInfos[i].protocol = &ProtEntities[i];
for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i)
Prots.push_back(&ProtInfos[i]);
}
IndexingContext::AttrListInfo::AttrListInfo(const Decl *D,
IndexingContext &IdxCtx,
StrAdapter &SA) {
for (AttrVec::const_iterator AttrI = D->attr_begin(), AttrE = D->attr_end();
AttrI != AttrE; ++AttrI) {
const Attr *A = *AttrI;
CXCursor C = MakeCXCursor(A, const_cast<Decl *>(D), IdxCtx.CXTU);
CXIdxLoc Loc = IdxCtx.getIndexLoc(A->getLocation());
switch (C.kind) {
default:
Attrs.push_back(AttrInfo(CXIdxAttr_Unexposed, C, Loc, A));
break;
case CXCursor_IBActionAttr:
Attrs.push_back(AttrInfo(CXIdxAttr_IBAction, C, Loc, A));
break;
case CXCursor_IBOutletAttr:
Attrs.push_back(AttrInfo(CXIdxAttr_IBOutlet, C, Loc, A));
break;
case CXCursor_IBOutletCollectionAttr:
IBCollAttrs.push_back(IBOutletCollectionInfo(C, Loc, A));
break;
}
}
for (unsigned i = 0, e = IBCollAttrs.size(); i != e; ++i) {
IBOutletCollectionInfo &IBInfo = IBCollAttrs[i];
CXAttrs.push_back(&IBInfo);
const IBOutletCollectionAttr *
IBAttr = cast<IBOutletCollectionAttr>(IBInfo.A);
IBInfo.IBCollInfo.attrInfo = &IBInfo;
IBInfo.IBCollInfo.classLoc = IdxCtx.getIndexLoc(IBAttr->getInterfaceLoc());
IBInfo.IBCollInfo.objcClass = 0;
IBInfo.IBCollInfo.classCursor = clang_getNullCursor();
QualType Ty = IBAttr->getInterface();
if (const ObjCInterfaceType *InterTy = Ty->getAs<ObjCInterfaceType>()) {
if (const ObjCInterfaceDecl *InterD = InterTy->getInterface()) {
IdxCtx.getEntityInfo(InterD, IBInfo.ClassInfo, SA);
IBInfo.IBCollInfo.objcClass = &IBInfo.ClassInfo;
IBInfo.IBCollInfo.classCursor = MakeCursorObjCClassRef(InterD,
IBAttr->getInterfaceLoc(), IdxCtx.CXTU);
}
}
}
for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
CXAttrs.push_back(&Attrs[i]);
}
IndexingContext::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D,
IndexingContext &IdxCtx,
IndexingContext::StrAdapter &SA) {
for (CXXRecordDecl::base_class_const_iterator
I = D->bases_begin(), E = D->bases_end(); I != E; ++I) {
const CXXBaseSpecifier &Base = *I;
BaseEntities.push_back(EntityInfo());
const NamedDecl *BaseD = 0;
if (const RecordType *RT = Base.getType()->getAs<RecordType>())
BaseD = RT->getDecl();
else if (const TypedefType *TDT = Base.getType()->getAs<TypedefType>())
BaseD = TDT->getDecl();
if