aboutsummaryrefslogtreecommitdiff
path: root/tools/libclang/CIndex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/libclang/CIndex.cpp')
-rw-r--r--tools/libclang/CIndex.cpp203
1 files changed, 183 insertions, 20 deletions
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index fc8703aface1..00ef8c0bf424 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -22,10 +22,12 @@
#include "CXType.h"
#include "CursorVisitor.h"
#include "clang/AST/Attr.h"
+#include "clang/AST/Mangle.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticCategories.h"
#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Version.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Frontend/CompilerInstance.h"
@@ -40,6 +42,8 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Config/llvm-config.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/Mangler.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/Format.h"
@@ -1256,6 +1260,7 @@ bool CursorVisitor::VisitNestedNameSpecifier(NestedNameSpecifier *NNS,
case NestedNameSpecifier::TypeSpecWithTemplate:
case NestedNameSpecifier::Global:
case NestedNameSpecifier::Identifier:
+ case NestedNameSpecifier::Super:
break;
}
@@ -1297,6 +1302,7 @@ CursorVisitor::VisitNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier) {
case NestedNameSpecifier::Global:
case NestedNameSpecifier::Identifier:
+ case NestedNameSpecifier::Super:
break;
}
}
@@ -1828,6 +1834,7 @@ public:
void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *E);
void VisitCXXUuidofExpr(const CXXUuidofExpr *E);
void VisitCXXCatchStmt(const CXXCatchStmt *S);
+ void VisitCXXForRangeStmt(const CXXForRangeStmt *S);
void VisitDeclRefExpr(const DeclRefExpr *D);
void VisitDeclStmt(const DeclStmt *S);
void VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E);
@@ -1856,21 +1863,28 @@ public:
void VisitOpaqueValueExpr(const OpaqueValueExpr *E);
void VisitLambdaExpr(const LambdaExpr *E);
void VisitOMPExecutableDirective(const OMPExecutableDirective *D);
+ void VisitOMPLoopDirective(const OMPLoopDirective *D);
void VisitOMPParallelDirective(const OMPParallelDirective *D);
void VisitOMPSimdDirective(const OMPSimdDirective *D);
void VisitOMPForDirective(const OMPForDirective *D);
+ void VisitOMPForSimdDirective(const OMPForSimdDirective *D);
void VisitOMPSectionsDirective(const OMPSectionsDirective *D);
void VisitOMPSectionDirective(const OMPSectionDirective *D);
void VisitOMPSingleDirective(const OMPSingleDirective *D);
void VisitOMPMasterDirective(const OMPMasterDirective *D);
void VisitOMPCriticalDirective(const OMPCriticalDirective *D);
void VisitOMPParallelForDirective(const OMPParallelForDirective *D);
+ void VisitOMPParallelForSimdDirective(const OMPParallelForSimdDirective *D);
void VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective *D);
void VisitOMPTaskDirective(const OMPTaskDirective *D);
void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D);
void VisitOMPBarrierDirective(const OMPBarrierDirective *D);
void VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D);
void VisitOMPFlushDirective(const OMPFlushDirective *D);
+ void VisitOMPOrderedDirective(const OMPOrderedDirective *D);
+ void VisitOMPAtomicDirective(const OMPAtomicDirective *D);
+ void VisitOMPTargetDirective(const OMPTargetDirective *D);
+ void VisitOMPTeamsDirective(const OMPTeamsDirective *D);
private:
void AddDeclarationNameInfo(const Stmt *S);
@@ -1979,14 +1993,28 @@ void OMPClauseEnqueue::VisitOMPUntiedClause(const OMPUntiedClause *) {}
void OMPClauseEnqueue::VisitOMPMergeableClause(const OMPMergeableClause *) {}
+void OMPClauseEnqueue::VisitOMPReadClause(const OMPReadClause *) {}
+
+void OMPClauseEnqueue::VisitOMPWriteClause(const OMPWriteClause *) {}
+
+void OMPClauseEnqueue::VisitOMPUpdateClause(const OMPUpdateClause *) {}
+
+void OMPClauseEnqueue::VisitOMPCaptureClause(const OMPCaptureClause *) {}
+
+void OMPClauseEnqueue::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
+
template<typename T>
void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
- for (const auto *I : Node->varlists())
+ for (const auto *I : Node->varlists()) {
Visitor->AddStmt(I);
+ }
}
void OMPClauseEnqueue::VisitOMPPrivateClause(const OMPPrivateClause *C) {
VisitOMPClauseList(C);
+ for (const auto *E : C->private_copies()) {
+ Visitor->AddStmt(E);
+ }
}
void OMPClauseEnqueue::VisitOMPFirstprivateClause(
const OMPFirstprivateClause *C) {
@@ -2127,6 +2155,12 @@ void EnqueueVisitor::VisitCXXCatchStmt(const CXXCatchStmt *S) {
AddDecl(S->getExceptionDecl());
}
+void EnqueueVisitor::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
+ AddStmt(S->getBody());
+ AddStmt(S->getRangeInit());
+ AddDecl(S->getLoopVariable());
+}
+
void EnqueueVisitor::VisitDeclRefExpr(const DeclRefExpr *DR) {
if (DR->hasExplicitTemplateArgs()) {
AddExplicitTemplateArgs(&DR->getExplicitTemplateArgs());
@@ -2309,16 +2343,24 @@ void EnqueueVisitor::VisitOMPExecutableDirective(
EnqueueChildren(*I);
}
+void EnqueueVisitor::VisitOMPLoopDirective(const OMPLoopDirective *D) {
+ VisitOMPExecutableDirective(D);
+}
+
void EnqueueVisitor::VisitOMPParallelDirective(const OMPParallelDirective *D) {
VisitOMPExecutableDirective(D);
}
void EnqueueVisitor::VisitOMPSimdDirective(const OMPSimdDirective *D) {
- VisitOMPExecutableDirective(D);
+ VisitOMPLoopDirective(D);
}
void EnqueueVisitor::VisitOMPForDirective(const OMPForDirective *D) {
- VisitOMPExecutableDirective(D);
+ VisitOMPLoopDirective(D);
+}
+
+void EnqueueVisitor::VisitOMPForSimdDirective(const OMPForSimdDirective *D) {
+ VisitOMPLoopDirective(D);
}
void EnqueueVisitor::VisitOMPSectionsDirective(const OMPSectionsDirective *D) {
@@ -2344,7 +2386,12 @@ void EnqueueVisitor::VisitOMPCriticalDirective(const OMPCriticalDirective *D) {
void
EnqueueVisitor::VisitOMPParallelForDirective(const OMPParallelForDirective *D) {
- VisitOMPExecutableDirective(D);
+ VisitOMPLoopDirective(D);
+}
+
+void EnqueueVisitor::VisitOMPParallelForSimdDirective(
+ const OMPParallelForSimdDirective *D) {
+ VisitOMPLoopDirective(D);
}
void EnqueueVisitor::VisitOMPParallelSectionsDirective(
@@ -2373,6 +2420,22 @@ void EnqueueVisitor::VisitOMPFlushDirective(const OMPFlushDirective *D) {
VisitOMPExecutableDirective(D);
}
+void EnqueueVisitor::VisitOMPOrderedDirective(const OMPOrderedDirective *D) {
+ VisitOMPExecutableDirective(D);
+}
+
+void EnqueueVisitor::VisitOMPAtomicDirective(const OMPAtomicDirective *D) {
+ VisitOMPExecutableDirective(D);
+}
+
+void EnqueueVisitor::VisitOMPTargetDirective(const OMPTargetDirective *D) {
+ VisitOMPExecutableDirective(D);
+}
+
+void EnqueueVisitor::VisitOMPTeamsDirective(const OMPTeamsDirective *D) {
+ VisitOMPExecutableDirective(D);
+}
+
void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) {
EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S);
}
@@ -2755,13 +2818,14 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx,
CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
FileSystemOptions FileSystemOpts;
- IntrusiveRefCntPtr<DiagnosticsEngine> Diags;
- ASTUnit *AU = ASTUnit::LoadFromASTFile(ast_filename, Diags, FileSystemOpts,
- CXXIdx->getOnlyLocalDecls(), None,
- /*CaptureDiagnostics=*/true,
- /*AllowPCHWithCompilerErrors=*/true,
- /*UserFilesAreVolatile=*/true);
- *out_TU = MakeCXTranslationUnit(CXXIdx, AU);
+ IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
+ CompilerInstance::createDiagnostics(new DiagnosticOptions());
+ std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
+ ast_filename, Diags, FileSystemOpts, CXXIdx->getOnlyLocalDecls(), None,
+ /*CaptureDiagnostics=*/true,
+ /*AllowPCHWithCompilerErrors=*/true,
+ /*UserFilesAreVolatile=*/true);
+ *out_TU = MakeCXTranslationUnit(CXXIdx, AU.release());
return *out_TU ? CXError_Success : CXError_Failure;
}
@@ -2847,9 +2911,9 @@ static void clang_parseTranslationUnit_Impl(void *UserData) {
std::vector<ASTUnit::RemappedFile> > RemappedCleanup(RemappedFiles.get());
for (auto &UF : PTUI->unsaved_files) {
- llvm::MemoryBuffer *MB =
+ std::unique_ptr<llvm::MemoryBuffer> MB =
llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename);
- RemappedFiles->push_back(std::make_pair(UF.Filename, MB));
+ RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release()));
}
std::unique_ptr<std::vector<const char *>> Args(
@@ -3131,9 +3195,9 @@ static void clang_reparseTranslationUnit_Impl(void *UserData) {
std::vector<ASTUnit::RemappedFile> > RemappedCleanup(RemappedFiles.get());
for (auto &UF : RTUI->unsaved_files) {
- llvm::MemoryBuffer *MB =
+ std::unique_ptr<llvm::MemoryBuffer> MB =
llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename);
- RemappedFiles->push_back(std::make_pair(UF.Filename, MB));
+ RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release()));
}
if (!CXXUnit->Reparse(*RemappedFiles.get()))
@@ -3259,6 +3323,18 @@ int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID) {
return 0;
}
+int clang_File_isEqual(CXFile file1, CXFile file2) {
+ if (file1 == file2)
+ return true;
+
+ if (!file1 || !file2)
+ return false;
+
+ FileEntry *FEnt1 = static_cast<FileEntry *>(file1);
+ FileEntry *FEnt2 = static_cast<FileEntry *>(file2);
+ return FEnt1->getUniqueID() == FEnt2->getUniqueID();
+}
+
} // end: extern "C"
//===----------------------------------------------------------------------===//
@@ -3628,6 +3704,18 @@ CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor C,
return clang_getNullRange();
}
+ if (C.kind == CXCursor_CXXMethod || C.kind == CXCursor_Destructor ||
+ C.kind == CXCursor_ConversionFunction) {
+ if (pieceIndex > 0)
+ return clang_getNullRange();
+ if (const FunctionDecl *FD =
+ dyn_cast_or_null<FunctionDecl>(getCursorDecl(C))) {
+ DeclarationNameInfo FunctionName = FD->getNameInfo();
+ return cxloc::translateSourceRange(Ctx, FunctionName.getSourceRange());
+ }
+ return clang_getNullRange();
+ }
+
// FIXME: A CXCursor_InclusionDirective should give the location of the
// filename, but we don't keep track of this.
@@ -3647,6 +3735,37 @@ CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor C,
return cxloc::translateSourceRange(Ctx, Loc);
}
+CXString clang_Cursor_getMangling(CXCursor C) {
+ if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
+ return cxstring::createEmpty();
+
+ // Mangling only works for functions and variables.
+ const Decl *D = getCursorDecl(C);
+ if (!D || !(isa<FunctionDecl>(D) || isa<VarDecl>(D)))
+ return cxstring::createEmpty();
+
+ // First apply frontend mangling.
+ const NamedDecl *ND = cast<NamedDecl>(D);
+ ASTContext &Ctx = ND->getASTContext();
+ std::unique_ptr<MangleContext> MC(Ctx.createMangleContext());
+
+ std::string FrontendBuf;
+ llvm::raw_string_ostream FrontendBufOS(FrontendBuf);
+ MC->mangleName(ND, FrontendBufOS);
+
+ // Now apply backend mangling.
+ std::unique_ptr<llvm::DataLayout> DL(
+ new llvm::DataLayout(Ctx.getTargetInfo().getTargetDescription()));
+ llvm::Mangler BackendMangler(DL.get());
+
+ std::string FinalBuf;
+ llvm::raw_string_ostream FinalBufOS(FinalBuf);
+ BackendMangler.getNameWithPrefix(FinalBufOS,
+ llvm::Twine(FrontendBufOS.str()));
+
+ return cxstring::createDup(FinalBufOS.str());
+}
+
CXString clang_getCursorDisplayName(CXCursor C) {
if (!clang_isDeclaration(C.kind))
return clang_getCursorSpelling(C);
@@ -3997,6 +4116,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
return cxstring::createRef("attribute(global)");
case CXCursor_CUDAHostAttr:
return cxstring::createRef("attribute(host)");
+ case CXCursor_CUDASharedAttr:
+ return cxstring::createRef("attribute(shared)");
case CXCursor_PreprocessingDirective:
return cxstring::createRef("preprocessing directive");
case CXCursor_MacroDefinition:
@@ -4051,6 +4172,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
return cxstring::createRef("OMPSimdDirective");
case CXCursor_OMPForDirective:
return cxstring::createRef("OMPForDirective");
+ case CXCursor_OMPForSimdDirective:
+ return cxstring::createRef("OMPForSimdDirective");
case CXCursor_OMPSectionsDirective:
return cxstring::createRef("OMPSectionsDirective");
case CXCursor_OMPSectionDirective:
@@ -4063,6 +4186,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
return cxstring::createRef("OMPCriticalDirective");
case CXCursor_OMPParallelForDirective:
return cxstring::createRef("OMPParallelForDirective");
+ case CXCursor_OMPParallelForSimdDirective:
+ return cxstring::createRef("OMPParallelForSimdDirective");
case CXCursor_OMPParallelSectionsDirective:
return cxstring::createRef("OMPParallelSectionsDirective");
case CXCursor_OMPTaskDirective:
@@ -4075,6 +4200,14 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
return cxstring::createRef("OMPTaskwaitDirective");
case CXCursor_OMPFlushDirective:
return cxstring::createRef("OMPFlushDirective");
+ case CXCursor_OMPOrderedDirective:
+ return cxstring::createRef("OMPOrderedDirective");
+ case CXCursor_OMPAtomicDirective:
+ return cxstring::createRef("OMPAtomicDirective");
+ case CXCursor_OMPTargetDirective:
+ return cxstring::createRef("OMPTargetDirective");
+ case CXCursor_OMPTeamsDirective:
+ return cxstring::createRef("OMPTeamsDirective");
}
llvm_unreachable("Unhandled CXCursorKind");
@@ -6296,6 +6429,40 @@ static const Decl *maybeGetTemplateCursor(const Decl *D) {
return D;
}
+
+enum CX_StorageClass clang_Cursor_getStorageClass(CXCursor C) {
+ StorageClass sc = SC_None;
+ const Decl *D = getCursorDecl(C);
+ if (D) {
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+ sc = FD->getStorageClass();
+ } else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
+ sc = VD->getStorageClass();
+ } else {
+ return CX_SC_Invalid;
+ }
+ } else {
+ return CX_SC_Invalid;
+ }
+ switch (sc) {
+ case SC_None:
+ return CX_SC_None;
+ case SC_Extern:
+ return CX_SC_Extern;
+ case SC_Static:
+ return CX_SC_Static;
+ case SC_PrivateExtern:
+ return CX_SC_PrivateExtern;
+ case SC_OpenCLWorkGroupLocal:
+ return CX_SC_OpenCLWorkGroupLocal;
+ case SC_Auto:
+ return CX_SC_Auto;
+ case SC_Register:
+ return CX_SC_Register;
+ }
+ llvm_unreachable("Unhandled storage class!");
+}
+
CXCursor clang_getCursorSemanticParent(CXCursor cursor) {
if (clang_isDeclaration(cursor.kind)) {
if (const Decl *D = getCursorDecl(cursor)) {
@@ -6490,11 +6657,7 @@ CXModule clang_getModuleForFile(CXTranslationUnit TU, CXFile File) {
HeaderSearch &HS = Unit.getPreprocessor().getHeaderSearchInfo();
ModuleMap::KnownHeader Header = HS.findModuleForHeader(FE);
- if (Module *Mod = Header.getModule()) {
- if (Header.getRole() != ModuleMap::ExcludedHeader)
- return Mod;
- }
- return nullptr;
+ return Header.getModule();
}
CXFile clang_Module_getASTFile(CXModule CXMod) {