summaryrefslogtreecommitdiffstats
path: root/tools/libclang/IndexingContext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/libclang/IndexingContext.cpp')
-rw-r--r--tools/libclang/IndexingContext.cpp79
1 files changed, 51 insertions, 28 deletions
diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp
index d4daa49..3368922 100644
--- a/tools/libclang/IndexingContext.cpp
+++ b/tools/libclang/IndexingContext.cpp
@@ -8,12 +8,11 @@
//===----------------------------------------------------------------------===//
#include "IndexingContext.h"
-#include "CXTranslationUnit.h"
#include "CIndexDiagnostic.h"
-
-#include "clang/Frontend/ASTUnit.h"
+#include "CXTranslationUnit.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclTemplate.h"
+#include "clang/Frontend/ASTUnit.h"
using namespace clang;
using namespace cxindex;
@@ -70,7 +69,7 @@ AttrListInfo::AttrListInfo(const Decl *D, IndexingContext &IdxCtx)
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);
+ CXCursor C = MakeCXCursor(A, D, IdxCtx.CXTU);
CXIdxLoc Loc = IdxCtx.getIndexLoc(A->getLocation());
switch (C.kind) {
default:
@@ -166,16 +165,16 @@ SourceLocation IndexingContext::CXXBasesListInfo::getBaseLoc(
if (TL.isNull())
return Loc;
- if (const QualifiedTypeLoc *QL = dyn_cast<QualifiedTypeLoc>(&TL))
- TL = QL->getUnqualifiedLoc();
+ if (QualifiedTypeLoc QL = TL.getAs<QualifiedTypeLoc>())
+ TL = QL.getUnqualifiedLoc();
- if (const ElaboratedTypeLoc *EL = dyn_cast<ElaboratedTypeLoc>(&TL))
- return EL->getNamedTypeLoc().getBeginLoc();
- if (const DependentNameTypeLoc *DL = dyn_cast<DependentNameTypeLoc>(&TL))
- return DL->getNameLoc();
- if (const DependentTemplateSpecializationTypeLoc *
- DTL = dyn_cast<DependentTemplateSpecializationTypeLoc>(&TL))
- return DTL->getTemplateNameLoc();
+ if (ElaboratedTypeLoc EL = TL.getAs<ElaboratedTypeLoc>())
+ return EL.getNamedTypeLoc().getBeginLoc();
+ if (DependentNameTypeLoc DL = TL.getAs<DependentNameTypeLoc>())
+ return DL.getNameLoc();
+ if (DependentTemplateSpecializationTypeLoc DTL =
+ TL.getAs<DependentTemplateSpecializationTypeLoc>())
+ return DTL.getTemplateNameLoc();
return Loc;
}
@@ -197,11 +196,11 @@ const char *ScratchAlloc::copyCStr(StringRef Str) {
void IndexingContext::setASTContext(ASTContext &ctx) {
Ctx = &ctx;
- static_cast<ASTUnit*>(CXTU->TUData)->setASTContext(&ctx);
+ cxtu::getASTUnit(CXTU)->setASTContext(&ctx);
}
void IndexingContext::setPreprocessor(Preprocessor &PP) {
- static_cast<ASTUnit*>(CXTU->TUData)->setPreprocessor(&PP);
+ cxtu::getASTUnit(CXTU)->setPreprocessor(&PP);
}
bool IndexingContext::isFunctionLocalDecl(const Decl *D) {
@@ -232,7 +231,9 @@ bool IndexingContext::shouldAbort() {
void IndexingContext::enteredMainFile(const FileEntry *File) {
if (File && CB.enteredMainFile) {
- CXIdxClientFile idxFile = CB.enteredMainFile(ClientData, (CXFile)File, 0);
+ CXIdxClientFile idxFile =
+ CB.enteredMainFile(ClientData,
+ static_cast<CXFile>(const_cast<FileEntry *>(File)), 0);
FileMap[File] = idxFile;
}
}
@@ -248,7 +249,8 @@ void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
ScratchAlloc SA(*this);
CXIdxIncludedFileInfo Info = { getIndexLoc(hashLoc),
SA.toCStr(filename),
- (CXFile)File,
+ static_cast<CXFile>(
+ const_cast<FileEntry *>(File)),
isImport, isAngled, isModuleImport };
CXIdxClientFile idxFile = CB.ppIncludedFile(ClientData, &Info);
FileMap[File] = idxFile;
@@ -264,7 +266,8 @@ void IndexingContext::importedModule(const ImportDecl *ImportD) {
std::string ModuleName = Mod->getFullModuleName();
CXIdxImportedASTFileInfo Info = {
- (CXFile)Mod->getASTFile(),
+ static_cast<CXFile>(
+ const_cast<FileEntry *>(Mod->getASTFile())),
Mod,
getIndexLoc(ImportD->getLocation()),
ImportD->isImplicit()
@@ -278,7 +281,8 @@ void IndexingContext::importedPCH(const FileEntry *File) {
return;
CXIdxImportedASTFileInfo Info = {
- (CXFile)File,
+ static_cast<CXFile>(
+ const_cast<FileEntry *>(File)),
/*module=*/NULL,
getIndexLoc(SourceLocation()),
/*isImplicit=*/false
@@ -365,8 +369,18 @@ bool IndexingContext::handleObjCContainer(const ObjCContainerDecl *D,
}
bool IndexingContext::handleFunction(const FunctionDecl *D) {
- DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
- D->isThisDeclarationADefinition());
+ bool isDef = D->isThisDeclarationADefinition();
+ bool isContainer = isDef;
+ bool isSkipped = false;
+ if (D->hasSkippedBody()) {
+ isSkipped = true;
+ isDef = true;
+ isContainer = false;
+ }
+
+ DeclInfo DInfo(!D->isFirstDeclaration(), isDef, isContainer);
+ if (isSkipped)
+ DInfo.flags |= CXIdxDeclFlag_Skipped;
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
}
@@ -549,8 +563,18 @@ bool IndexingContext::handleObjCCategoryImpl(const ObjCCategoryImplDecl *D) {
}
bool IndexingContext::handleObjCMethod(const ObjCMethodDecl *D) {
- DeclInfo DInfo(!D->isCanonicalDecl(), D->isThisDeclarationADefinition(),
- D->isThisDeclarationADefinition());
+ bool isDef = D->isThisDeclarationADefinition();
+ bool isContainer = isDef;
+ bool isSkipped = false;
+ if (D->hasSkippedBody()) {
+ isSkipped = true;
+ isDef = true;
+ isContainer = false;
+ }
+
+ DeclInfo DInfo(!D->isCanonicalDecl(), isDef, isContainer);
+ if (isSkipped)
+ DInfo.flags |= CXIdxDeclFlag_Skipped;
return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
}
@@ -625,8 +649,7 @@ bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc,
if (!D)
return false;
- CXCursor Cursor = E ? MakeCXCursor(const_cast<Expr*>(E),
- const_cast<Decl*>(cast<Decl>(DC)), CXTU)
+ CXCursor Cursor = E ? MakeCXCursor(E, cast<Decl>(DC), CXTU)
: getRefCursor(D, Loc);
return handleReference(D, Loc, Cursor, Parent, DC, E, Kind);
}
@@ -808,7 +831,7 @@ IndexingContext::getEntityContainer(const Decl *D) const {
if (const ClassTemplateDecl *ClassTempl = dyn_cast<ClassTemplateDecl>(D)) {
DC = ClassTempl->getTemplatedDecl();
- } if (const FunctionTemplateDecl *
+ } else if (const FunctionTemplateDecl *
FuncTempl = dyn_cast<FunctionTemplateDecl>(D)) {
DC = FuncTempl->getTemplatedDecl();
}
@@ -844,7 +867,7 @@ CXIdxLoc IndexingContext::getIndexLoc(SourceLocation Loc) const {
if (Loc.isInvalid())
return idxLoc;
- idxLoc.ptr_data[0] = (void*)this;
+ idxLoc.ptr_data[0] = const_cast<IndexingContext *>(this);
idxLoc.int_data = Loc.getRawEncoding();
return idxLoc;
}
@@ -870,7 +893,7 @@ void IndexingContext::translateLoc(SourceLocation Loc,
if (indexFile)
*indexFile = getIndexFile(FE);
if (file)
- *file = (void *)FE;
+ *file = const_cast<FileEntry *>(FE);
if (line)
*line = SM.getLineNumber(FID, FileOffset);
if (column)
OpenPOWER on IntegriCloud