diff options
Diffstat (limited to 'tools/libclang')
-rw-r--r-- | tools/libclang/ARCMigrate.cpp | 98 | ||||
-rw-r--r-- | tools/libclang/CIndex.cpp | 125 | ||||
-rw-r--r-- | tools/libclang/CIndexCodeCompletion.cpp | 192 | ||||
-rw-r--r-- | tools/libclang/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tools/libclang/CXCursor.cpp | 23 | ||||
-rw-r--r-- | tools/libclang/CXCursor.h | 13 | ||||
-rw-r--r-- | tools/libclang/CXType.cpp | 6 | ||||
-rw-r--r-- | tools/libclang/Makefile | 5 | ||||
-rw-r--r-- | tools/libclang/libclang.darwin.exports | 6 | ||||
-rw-r--r-- | tools/libclang/libclang.exports | 6 |
10 files changed, 430 insertions, 47 deletions
diff --git a/tools/libclang/ARCMigrate.cpp b/tools/libclang/ARCMigrate.cpp new file mode 100644 index 0000000..39c7d84 --- /dev/null +++ b/tools/libclang/ARCMigrate.cpp @@ -0,0 +1,98 @@ +//===- ARCMigrate.cpp - Clang-C ARC Migration Library ---------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the main API hooks in the Clang-C ARC Migration library. +// +//===----------------------------------------------------------------------===// + +#include "clang-c/Index.h" + +#include "CXString.h" +#include "clang/ARCMigrate/ARCMT.h" +#include "clang/Frontend/TextDiagnosticBuffer.h" +#include "llvm/Support/FileSystem.h" + +using namespace clang; +using namespace arcmt; + +namespace { + +struct Remap { + std::vector<std::pair<std::string, std::string> > Vec; +}; + +} // anonymous namespace. + +//===----------------------------------------------------------------------===// +// libClang public APIs. +//===----------------------------------------------------------------------===// + +extern "C" { + +CXRemapping clang_getRemappings(const char *migrate_dir_path) { + bool Logging = ::getenv("LIBCLANG_LOGGING"); + + if (!migrate_dir_path) { + if (Logging) + llvm::errs() << "clang_getRemappings was called with NULL parameter\n"; + return 0; + } + + bool exists = false; + llvm::sys::fs::exists(migrate_dir_path, exists); + if (!exists) { + if (Logging) { + llvm::errs() << "Error by clang_getRemappings(\"" << migrate_dir_path + << "\")\n"; + llvm::errs() << "\"" << migrate_dir_path << "\" does not exist\n"; + } + return 0; + } + + TextDiagnosticBuffer diagBuffer; + llvm::OwningPtr<Remap> remap(new Remap()); + + bool err = arcmt::getFileRemappings(remap->Vec, migrate_dir_path,&diagBuffer); + + if (err) { + if (Logging) { + llvm::errs() << "Error by clang_getRemappings(\"" << migrate_dir_path + << "\")\n"; + for (TextDiagnosticBuffer::const_iterator + I = diagBuffer.err_begin(), E = diagBuffer.err_end(); I != E; ++I) + llvm::errs() << I->second << '\n'; + } + return 0; + } + + return remap.take(); +} + +unsigned clang_remap_getNumFiles(CXRemapping map) { + return static_cast<Remap *>(map)->Vec.size(); + +} + +void clang_remap_getFilenames(CXRemapping map, unsigned index, + CXString *original, CXString *transformed) { + if (original) + *original = cxstring::createCXString( + static_cast<Remap *>(map)->Vec[index].first, + /*DupString =*/ true); + if (transformed) + *transformed = cxstring::createCXString( + static_cast<Remap *>(map)->Vec[index].second, + /*DupString =*/ true); +} + +void clang_remap_dispose(CXRemapping map) { + delete static_cast<Remap *>(map); +} + +} // end: extern "C" diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 2a9d96d..50d56fc 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -544,8 +544,8 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) { // do so. PreprocessingRecord::iterator E, EEnd; for (llvm::tie(E, EEnd) = getPreprocessedEntities(); E != EEnd; ++E) { - if (MacroInstantiation *MI = dyn_cast<MacroInstantiation>(*E)) { - if (Visit(MakeMacroInstantiationCursor(MI, tu))) + if (MacroExpansion *ME = dyn_cast<MacroExpansion>(*E)) { + if (Visit(MakeMacroExpansionCursor(ME, tu))) return true; continue; @@ -1330,6 +1330,11 @@ bool CursorVisitor::VisitTemplateName(TemplateName Name, SourceLocation Loc) { return Visit(MakeCursorTemplateRef( Name.getAsQualifiedTemplateName()->getDecl(), Loc, TU)); + + case TemplateName::SubstTemplateTemplateParm: + return Visit(MakeCursorTemplateRef( + Name.getAsSubstTemplateTemplateParm()->getParameter(), + Loc, TU)); case TemplateName::SubstTemplateTemplateParmPack: return Visit(MakeCursorTemplateRef( @@ -2374,7 +2379,8 @@ CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx, unsigned clang_defaultEditingTranslationUnitOptions() { return CXTranslationUnit_PrecompiledPreamble | CXTranslationUnit_CacheCompletionResults | - CXTranslationUnit_CXXPrecompiledPreamble; + CXTranslationUnit_CXXPrecompiledPreamble | + CXTranslationUnit_CXXChainedPCH; } CXTranslationUnit @@ -2385,7 +2391,7 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, unsigned num_unsaved_files, struct CXUnsavedFile *unsaved_files) { unsigned Options = CXTranslationUnit_DetailedPreprocessingRecord | - CXTranslationUnit_NestedMacroInstantiations; + CXTranslationUnit_NestedMacroExpansions; return clang_parseTranslationUnit(CIdx, source_filename, command_line_args, num_command_line_args, unsaved_files, num_unsaved_files, @@ -2490,12 +2496,12 @@ static void clang_parseTranslationUnit_Impl(void *UserData) { Args->push_back(source_filename); // Do we need the detailed preprocessing record? - bool NestedMacroInstantiations = false; + bool NestedMacroExpansions = false; if (options & CXTranslationUnit_DetailedPreprocessingRecord) { Args->push_back("-Xclang"); Args->push_back("-detailed-preprocessing-record"); - NestedMacroInstantiations - = (options & CXTranslationUnit_NestedMacroInstantiations); + NestedMacroExpansions + = (options & CXTranslationUnit_NestedMacroExpansions); } unsigned NumErrors = Diags->getClient()->getNumErrors(); @@ -2515,7 +2521,7 @@ static void clang_parseTranslationUnit_Impl(void *UserData) { CacheCodeCompetionResults, CXXPrecompilePreamble, CXXChainedPCH, - NestedMacroInstantiations)); + NestedMacroExpansions)); if (NumErrors != Diags->getClient()->getNumErrors()) { // Make sure to check that 'Unit' is non-NULL. @@ -2588,9 +2594,9 @@ unsigned clang_defaultSaveOptions(CXTranslationUnit TU) { int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName, unsigned options) { if (!TU) - return 1; + return CXSaveError_InvalidTU; - int result = static_cast<ASTUnit *>(TU->TUData)->Save(FileName); + CXSaveError result = static_cast<ASTUnit *>(TU->TUData)->Save(FileName); if (getenv("LIBCLANG_RESOURCE_USAGE")) PrintLibclangResourceUsage(TU); return result; @@ -2800,7 +2806,7 @@ void clang_getInstantiationLocation(CXSourceLocation location, *static_cast<const SourceManager*>(location.ptr_data[0]); SourceLocation InstLoc = SM.getInstantiationLoc(Loc); - // Check that the FileID is invalid on the instantiation location. + // Check that the FileID is invalid on the expansion location. // This can manifest in invalid code. FileID fileID = SM.getFileID(InstLoc); bool Invalid = false; @@ -3145,8 +3151,8 @@ CXString clang_getCursorSpelling(CXCursor C) { return createCXString(""); } - if (C.kind == CXCursor_MacroInstantiation) - return createCXString(getCursorMacroInstantiation(C)->getName() + if (C.kind == CXCursor_MacroExpansion) + return createCXString(getCursorMacroExpansion(C)->getName() ->getNameStart()); if (C.kind == CXCursor_MacroDefinition) @@ -3346,8 +3352,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) { return createCXString("preprocessing directive"); case CXCursor_MacroDefinition: return createCXString("macro definition"); - case CXCursor_MacroInstantiation: - return createCXString("macro instantiation"); + case CXCursor_MacroExpansion: + return createCXString("macro expansion"); case CXCursor_InclusionDirective: return createCXString("inclusion directive"); case CXCursor_Namespace: @@ -3392,11 +3398,34 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) { return createCXString((const char*) 0); } +struct GetCursorData { + SourceLocation TokenBeginLoc; + CXCursor &BestCursor; + + GetCursorData(SourceLocation tokenBegin, CXCursor &outputCursor) + : TokenBeginLoc(tokenBegin), BestCursor(outputCursor) { } +}; + enum CXChildVisitResult GetCursorVisitor(CXCursor cursor, CXCursor parent, CXClientData client_data) { - CXCursor *BestCursor = static_cast<CXCursor *>(client_data); - + GetCursorData *Data = static_cast<GetCursorData *>(client_data); + CXCursor *BestCursor = &Data->BestCursor; + + if (clang_isExpression(cursor.kind) && + clang_isDeclaration(BestCursor->kind)) { + Decl *D = getCursorDecl(*BestCursor); + + // Avoid having the cursor of an expression replace the declaration cursor + // when the expression source range overlaps the declaration range. + // This can happen for C++ constructor expressions whose range generally + // include the variable declaration, e.g.: + // MyCXXClass foo; // Make sure pointing at 'foo' returns a VarDecl cursor. + if (D->getLocation().isValid() && Data->TokenBeginLoc.isValid() && + D->getLocation() == Data->TokenBeginLoc) + return CXChildVisit_Break; + } + // If our current best cursor is the construction of a temporary object, // don't replace that cursor with a type reference, because we want // clang_getCursor() to point at the constructor. @@ -3440,8 +3469,9 @@ CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) { // FIXME: Would be great to have a "hint" cursor, then walk from that // hint cursor upward until we find a cursor whose source range encloses // the region of interest, rather than starting from the translation unit. + GetCursorData ResultData(SLoc, Result); CXCursor Parent = clang_getTranslationUnitCursor(TU); - CursorVisitor CursorVis(TU, GetCursorVisitor, &Result, + CursorVisitor CursorVis(TU, GetCursorVisitor, &ResultData, Decl::MaxPCHLevel, true, SourceLocation(SLoc)); CursorVis.VisitChildren(Parent); } @@ -3532,6 +3562,10 @@ unsigned clang_isStatement(enum CXCursorKind K) { return K >= CXCursor_FirstStmt && K <= CXCursor_LastStmt; } +unsigned clang_isAttribute(enum CXCursorKind K) { + return K >= CXCursor_FirstAttr && K <= CXCursor_LastAttr; +} + unsigned clang_isTranslationUnit(enum CXCursorKind K) { return K == CXCursor_TranslationUnit; } @@ -3638,9 +3672,9 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) { return cxloc::translateSourceLocation(getCursorContext(C), L); } - if (C.kind == CXCursor_MacroInstantiation) { + if (C.kind == CXCursor_MacroExpansion) { SourceLocation L - = cxcursor::getCursorMacroInstantiation(C)->getSourceRange().getBegin(); + = cxcursor::getCursorMacroExpansion(C)->getSourceRange().getBegin(); return cxloc::translateSourceLocation(getCursorContext(C), L); } @@ -3725,8 +3759,8 @@ static SourceRange getRawCursorExtent(CXCursor C) { if (C.kind == CXCursor_PreprocessingDirective) return cxcursor::getCursorPreprocessingDirective(C); - if (C.kind == CXCursor_MacroInstantiation) - return cxcursor::getCursorMacroInstantiation(C)->getSourceRange(); + if (C.kind == CXCursor_MacroExpansion) + return cxcursor::getCursorMacroExpansion(C)->getSourceRange(); if (C.kind == CXCursor_MacroDefinition) return cxcursor::getCursorMacroDefinition(C)->getSourceRange(); @@ -3842,8 +3876,8 @@ CXCursor clang_getCursorReferenced(CXCursor C) { return clang_getNullCursor(); } - if (C.kind == CXCursor_MacroInstantiation) { - if (MacroDefinition *Def = getCursorMacroInstantiation(C)->getDefinition()) + if (C.kind == CXCursor_MacroExpansion) { + if (MacroDefinition *Def = getCursorMacroExpansion(C)->getDefinition()) return MakeMacroDefinitionCursor(Def, tu); } @@ -3911,7 +3945,7 @@ CXCursor clang_getCursorDefinition(CXCursor C) { WasReference = true; } - if (C.kind == CXCursor_MacroInstantiation) + if (C.kind == CXCursor_MacroExpansion) return clang_getCursorReferenced(C); if (!clang_isDeclaration(C.kind)) @@ -4107,8 +4141,17 @@ CXCursor clang_getCanonicalCursor(CXCursor C) { if (!clang_isDeclaration(C.kind)) return C; - if (Decl *D = getCursorDecl(C)) + if (Decl *D = getCursorDecl(C)) { + if (ObjCCategoryImplDecl *CatImplD = dyn_cast<ObjCCategoryImplDecl>(D)) + if (ObjCCategoryDecl *CatD = CatImplD->getCategoryDecl()) + return MakeCXCursor(CatD, getCursorTU(C)); + + if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) + if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) + return MakeCXCursor(IFD, getCursorTU(C)); + return MakeCXCursor(D->getCanonicalDecl(), getCursorTU(C)); + } return C; } @@ -4507,9 +4550,9 @@ AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) { } if (clang_isPreprocessing(cursor.kind)) { - // For macro instantiations, just note where the beginning of the macro - // instantiation occurs. - if (cursor.kind == CXCursor_MacroInstantiation) { + // For macro expansions, just note where the beginning of the macro + // expansion occurs. + if (cursor.kind == CXCursor_MacroExpansion) { Annotated[Loc.int_data] = cursor; return CXChildVisit_Recurse; } @@ -4626,6 +4669,24 @@ AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) { break; } + // Avoid having the cursor of an expression "overwrite" the annotation of the + // variable declaration that it belongs to. + // This can happen for C++ constructor expressions whose range generally + // include the variable declaration, e.g.: + // MyCXXClass foo; // Make sure we don't annotate 'foo' as a CallExpr cursor. + if (clang_isExpression(cursorK)) { + Expr *E = getCursorExpr(cursor); + if (Decl *D = getCursorParentDecl(cursor)) { + const unsigned I = NextToken(); + if (E->getLocStart().isValid() && D->getLocation().isValid() && + E->getLocStart() == D->getLocation() && + E->getLocStart() == GetTokenLoc(I)) { + Cursors[I] = updateC; + AdvanceToken(); + } + } + } + // Visit children to get their cursor information. const unsigned BeforeChildren = NextToken(); VisitChildren(cursor); @@ -4797,6 +4858,7 @@ static void clang_annotateTokensImpl(void *UserData) { llvm::StringSwitch<bool>(II->getName()) .Case("readonly", true) .Case("assign", true) + .Case("unsafe_unretained", true) .Case("readwrite", true) .Case("retain", true) .Case("copy", true) @@ -4804,6 +4866,8 @@ static void clang_annotateTokensImpl(void *UserData) { .Case("atomic", true) .Case("getter", true) .Case("setter", true) + .Case("strong", true) + .Case("weak", true) .Default(false)) Tokens[I].int_data[0] = CXToken_Keyword; } @@ -5354,10 +5418,9 @@ CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) { // How much memory is being used by the Preprocessor? Preprocessor &pp = astUnit->getPreprocessor(); - const llvm::BumpPtrAllocator &ppAlloc = pp.getPreprocessorAllocator(); createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_Preprocessor, - ppAlloc.getTotalMemory()); + pp.getTotalMemory()); if (PreprocessingRecord *pRec = pp.getPreprocessingRecord()) { createCXTUResourceUsageEntry(*entries, diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp index 0c8317e..832e2f2 100644 --- a/tools/libclang/CIndexCodeCompletion.cpp +++ b/tools/libclang/CIndexCodeCompletion.cpp @@ -235,6 +235,13 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults { /// \brief Allocator used to store code completion results. clang::CodeCompletionAllocator CodeCompletionAllocator; + + /// \brief Context under which completion occurred. + enum clang::CodeCompletionContext::Kind ContextKind; + + /// \brief A bitfield representing the acceptable completions for the + /// current context. + unsigned long long Contexts; }; /// \brief Tracks the number of code-completion result objects that are @@ -273,6 +280,177 @@ AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() { } // end extern "C" +static unsigned long long getContextsForContextKind( + enum CodeCompletionContext::Kind kind, + Sema &S) { + unsigned long long contexts = 0; + switch (kind) { + case CodeCompletionContext::CCC_OtherWithMacros: { + //We can allow macros here, but we don't know what else is permissible + //So we'll say the only thing permissible are macros + contexts = CXCompletionContext_MacroName; + break; + } + case CodeCompletionContext::CCC_TopLevel: + case CodeCompletionContext::CCC_ObjCIvarList: + case CodeCompletionContext::CCC_ClassStructUnion: + case CodeCompletionContext::CCC_Type: { + contexts = CXCompletionContext_AnyType | + CXCompletionContext_ObjCInterface; + if (S.getLangOptions().CPlusPlus) { + contexts |= CXCompletionContext_EnumTag | + CXCompletionContext_UnionTag | + CXCompletionContext_StructTag | + CXCompletionContext_ClassTag | + CXCompletionContext_NestedNameSpecifier; + } + break; + } + case CodeCompletionContext::CCC_Statement: { + contexts = CXCompletionContext_AnyType | + CXCompletionContext_ObjCInterface | + CXCompletionContext_AnyValue; + if (S.getLangOptions().CPlusPlus) { + contexts |= CXCompletionContext_EnumTag | + CXCompletionContext_UnionTag | + CXCompletionContext_StructTag | + CXCompletionContext_ClassTag | + CXCompletionContext_NestedNameSpecifier; + } + break; + } + case CodeCompletionContext::CCC_Expression: { + contexts = CXCompletionContext_AnyValue; + if (S.getLangOptions().CPlusPlus) { + contexts |= CXCompletionContext_AnyType | + CXCompletionContext_ObjCInterface | + CXCompletionContext_EnumTag | + CXCompletionContext_UnionTag | + CXCompletionContext_StructTag | + CXCompletionContext_ClassTag | + CXCompletionContext_NestedNameSpecifier; + } + break; + } + case CodeCompletionContext::CCC_ObjCMessageReceiver: { + contexts = CXCompletionContext_ObjCObjectValue | + CXCompletionContext_ObjCSelectorValue | + CXCompletionContext_ObjCInterface; + if (S.getLangOptions().CPlusPlus) { + contexts |= CXCompletionContext_CXXClassTypeValue | + CXCompletionContext_AnyType | + CXCompletionContext_EnumTag | + CXCompletionContext_UnionTag | + CXCompletionContext_StructTag | + CXCompletionContext_ClassTag | + CXCompletionContext_NestedNameSpecifier; + } + break; + } + case CodeCompletionContext::CCC_DotMemberAccess: { + contexts = CXCompletionContext_DotMemberAccess; + break; + } + case CodeCompletionContext::CCC_ArrowMemberAccess: { + contexts = CXCompletionContext_ArrowMemberAccess; + break; + } + case CodeCompletionContext::CCC_ObjCPropertyAccess: { + contexts = CXCompletionContext_ObjCPropertyAccess; + break; + } + case CodeCompletionContext::CCC_EnumTag: { + contexts = CXCompletionContext_EnumTag | + CXCompletionContext_NestedNameSpecifier; + break; + } + case CodeCompletionContext::CCC_UnionTag: { + contexts = CXCompletionContext_UnionTag | + CXCompletionContext_NestedNameSpecifier; + break; + } + case CodeCompletionContext::CCC_ClassOrStructTag: { + contexts = CXCompletionContext_StructTag | + CXCompletionContext_ClassTag | + CXCompletionContext_NestedNameSpecifier; + break; + } + case CodeCompletionContext::CCC_ObjCProtocolName: { + contexts = CXCompletionContext_ObjCProtocol; + break; + } + case CodeCompletionContext::CCC_Namespace: { + contexts = CXCompletionContext_Namespace; + break; + } + case CodeCompletionContext::CCC_PotentiallyQualifiedName: { + contexts = CXCompletionContext_NestedNameSpecifier; + break; + } + case CodeCompletionContext::CCC_MacroNameUse: { + contexts = CXCompletionContext_MacroName; + break; + } + case CodeCompletionContext::CCC_NaturalLanguage: { + contexts = CXCompletionContext_NaturalLanguage; + break; + } + case CodeCompletionContext::CCC_SelectorName: { + contexts = CXCompletionContext_ObjCSelectorName; + break; + } + case CodeCompletionContext::CCC_ParenthesizedExpression: { + contexts = CXCompletionContext_AnyType | + CXCompletionContext_ObjCInterface | + CXCompletionContext_AnyValue; + if (S.getLangOptions().CPlusPlus) { + contexts |= CXCompletionContext_EnumTag | + CXCompletionContext_UnionTag | + CXCompletionContext_StructTag | + CXCompletionContext_ClassTag | + CXCompletionContext_NestedNameSpecifier; + } + break; + } + case CodeCompletionContext::CCC_ObjCInstanceMessage: { + contexts = CXCompletionContext_ObjCInstanceMessage; + break; + } + case CodeCompletionContext::CCC_ObjCClassMessage: { + contexts = CXCompletionContext_ObjCClassMessage; + break; + } + case CodeCompletionContext::CCC_ObjCSuperclass: { + contexts = CXCompletionContext_ObjCInterface; + break; + } + case CodeCompletionContext::CCC_ObjCCategoryName: { + contexts = CXCompletionContext_ObjCCategory; + break; + } + case CodeCompletionContext::CCC_Other: + case CodeCompletionContext::CCC_ObjCInterface: + case CodeCompletionContext::CCC_ObjCImplementation: + case CodeCompletionContext::CCC_Name: + case CodeCompletionContext::CCC_MacroName: + case CodeCompletionContext::CCC_PreprocessorExpression: + case CodeCompletionContext::CCC_PreprocessorDirective: + case CodeCompletionContext::CCC_TypeQualifiers: { + //Only Clang results should be accepted, so we'll set all of the other + //context bits to 0 (i.e. the empty set) + contexts = CXCompletionContext_Unexposed; + break; + } + case CodeCompletionContext::CCC_Recovery: { + //We don't know what the current context is, so we'll return unknown + //This is the equivalent of setting all of the other context bits + contexts = CXCompletionContext_Unknown; + break; + } + } + return contexts; +} + namespace { class CaptureCompletionResults : public CodeCompleteConsumer { AllocatedCXCodeCompleteResults &AllocatedResults; @@ -298,6 +476,11 @@ namespace { R.CompletionString = StoredCompletion; StoredResults.push_back(R); } + + enum CodeCompletionContext::Kind kind = Context.getKind(); + + AllocatedResults.ContextKind = kind; + AllocatedResults.Contexts = getContextsForContextKind(kind, S); } virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, @@ -538,6 +721,15 @@ clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *ResultsIn, return new CXStoredDiagnostic(Results->Diagnostics[Index], Results->LangOpts); } +unsigned long long +clang_codeCompleteGetContexts(CXCodeCompleteResults *ResultsIn) { + AllocatedCXCodeCompleteResults *Results + = static_cast<AllocatedCXCodeCompleteResults*>(ResultsIn); + if (!Results) + return 0; + + return Results->Contexts; +} } // end extern "C" diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt index 7a6270d..f45389f 100644 --- a/tools/libclang/CMakeLists.txt +++ b/tools/libclang/CMakeLists.txt @@ -1,4 +1,6 @@ set(LLVM_USED_LIBS + clangARCMigrate + clangRewrite clangFrontend clangDriver clangSerialization @@ -14,6 +16,7 @@ set( LLVM_LINK_COMPONENTS ) set(SOURCES + ARCMigrate.cpp CIndex.cpp CIndexCXX.cpp CIndexCodeCompletion.cpp diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index b34370d..b3c57dc 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -92,6 +92,7 @@ CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, case Stmt::ObjCAtFinallyStmtClass: case Stmt::ObjCAtThrowStmtClass: case Stmt::ObjCAtSynchronizedStmtClass: + case Stmt::ObjCAutoreleasePoolStmtClass: case Stmt::ObjCForCollectionStmtClass: case Stmt::CXXCatchStmtClass: case Stmt::CXXTryStmtClass: @@ -99,6 +100,7 @@ CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, case Stmt::SEHTryStmtClass: case Stmt::SEHExceptStmtClass: case Stmt::SEHFinallyStmtClass: + case Stmt::MaterializeTemporaryExprClass: K = CXCursor_UnexposedStmt; break; @@ -167,7 +169,9 @@ CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, case Stmt::ObjCEncodeExprClass: case Stmt::ObjCSelectorExprClass: case Stmt::ObjCProtocolExprClass: - case Stmt::ObjCIsaExprClass: + case Stmt::ObjCIsaExprClass: + case Stmt::ObjCIndirectCopyRestoreExprClass: + case Stmt::ObjCBridgedCastExprClass: case Stmt::ShuffleVectorExprClass: case Stmt::BlockExprClass: case Stmt::OpaqueValueExprClass: @@ -179,6 +183,7 @@ CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, case Stmt::DeclRefExprClass: case Stmt::BlockDeclRefExprClass: + case Stmt::SubstNonTypeTemplateParmExprClass: case Stmt::SubstNonTypeTemplateParmPackExprClass: // FIXME: UnresolvedLookupExpr? // FIXME: DependentScopeDeclRefExpr? @@ -374,15 +379,15 @@ MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) { return static_cast<MacroDefinition *>(C.data[0]); } -CXCursor cxcursor::MakeMacroInstantiationCursor(MacroInstantiation *MI, - CXTranslationUnit TU) { - CXCursor C = { CXCursor_MacroInstantiation, { MI, 0, TU } }; +CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI, + CXTranslationUnit TU) { + CXCursor C = { CXCursor_MacroExpansion, { MI, 0, TU } }; return C; } -MacroInstantiation *cxcursor::getCursorMacroInstantiation(CXCursor C) { - assert(C.kind == CXCursor_MacroInstantiation); - return static_cast<MacroInstantiation *>(C.data[0]); +MacroExpansion *cxcursor::getCursorMacroExpansion(CXCursor C) { + assert(C.kind == CXCursor_MacroExpansion); + return static_cast<MacroExpansion *>(C.data[0]); } CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID, @@ -480,6 +485,10 @@ Attr *cxcursor::getCursorAttr(CXCursor Cursor) { return (Attr *)Cursor.data[1]; } +Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) { + return (Decl *)Cursor.data[0]; +} + ASTContext &cxcursor::getCursorContext(CXCursor Cursor) { return getCursorASTUnit(Cursor)->getASTContext(); } diff --git a/tools/libclang/CXCursor.h b/tools/libclang/CXCursor.h index 11f2500..68d09e7 100644 --- a/tools/libclang/CXCursor.h +++ b/tools/libclang/CXCursor.h @@ -31,7 +31,7 @@ class FieldDecl; class InclusionDirective; class LabelStmt; class MacroDefinition; -class MacroInstantiation; +class MacroExpansion; class NamedDecl; class ObjCInterfaceDecl; class ObjCProtocolDecl; @@ -134,13 +134,13 @@ CXCursor MakeMacroDefinitionCursor(MacroDefinition *, CXTranslationUnit TU); /// source range. MacroDefinition *getCursorMacroDefinition(CXCursor C); -/// \brief Create a macro instantiation cursor. -CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, - CXTranslationUnit TU); +/// \brief Create a macro expansion cursor. +CXCursor MakeMacroExpansionCursor(MacroExpansion *, + CXTranslationUnit TU); -/// \brief Unpack a given macro instantiation cursor to retrieve its +/// \brief Unpack a given macro expansion cursor to retrieve its /// source range. -MacroInstantiation *getCursorMacroInstantiation(CXCursor C); +MacroExpansion *getCursorMacroExpansion(CXCursor C); /// \brief Create an inclusion directive cursor. CXCursor MakeInclusionDirectiveCursor(InclusionDirective *, @@ -184,6 +184,7 @@ Decl *getCursorDecl(CXCursor Cursor); Expr *getCursorExpr(CXCursor Cursor); Stmt *getCursorStmt(CXCursor Cursor); Attr *getCursorAttr(CXCursor Cursor); +Decl *getCursorParentDecl(CXCursor Cursor); ASTContext &getCursorContext(CXCursor Cursor); ASTUnit *getCursorASTUnit(CXCursor Cursor); diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index 5af9553..45c7346 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -366,7 +366,11 @@ unsigned clang_isPODType(CXType X) { QualType T = GetQualType(X); if (!T.getTypePtrOrNull()) return 0; - return T->isPODType() ? 1 : 0; + + CXTranslationUnit TU = GetTU(X); + ASTUnit *AU = static_cast<ASTUnit*>(TU->TUData); + + return T.isPODType(AU->getASTContext()) ? 1 : 0; } CXString clang_getDeclObjCTypeEncoding(CXCursor C) { diff --git a/tools/libclang/Makefile b/tools/libclang/Makefile index e684652..375f7f2 100644 --- a/tools/libclang/Makefile +++ b/tools/libclang/Makefile @@ -16,8 +16,9 @@ LINK_LIBS_IN_SHARED = 1 SHARED_LIBRARY = 1 LINK_COMPONENTS := support mc -USEDLIBS = clangFrontend.a clangDriver.a clangSerialization.a clangParse.a \ - clangSema.a clangAnalysis.a clangAST.a clangLex.a clangBasic.a +USEDLIBS = clangARCMigrate.a clangRewrite.a clangFrontend.a clangDriver.a \ + clangSerialization.a \ + clangParse.a clangSema.a clangAnalysis.a clangAST.a clangLex.a clangBasic.a include $(CLANG_LEVEL)/Makefile diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports index 85dfcb6..bfc5be9 100644 --- a/tools/libclang/libclang.darwin.exports +++ b/tools/libclang/libclang.darwin.exports @@ -6,6 +6,7 @@ _clang_annotateTokens _clang_codeCompleteAt _clang_codeCompleteGetDiagnostic _clang_codeCompleteGetNumDiagnostics +_clang_codeCompleteGetContexts _clang_constructUSR_ObjCCategory _clang_constructUSR_ObjCClass _clang_constructUSR_ObjCIvar @@ -112,6 +113,7 @@ _clang_getTranslationUnitSpelling _clang_getTypeDeclaration _clang_getTypeKindSpelling _clang_hashCursor +_clang_isAttribute _clang_isConstQualifiedType _clang_isCursorDefinition _clang_isDeclaration @@ -135,3 +137,7 @@ _clang_toggleCrashRecovery _clang_tokenize _clang_visitChildren _clang_visitChildrenWithBlock +_clang_getRemappings +_clang_remap_getNumFiles +_clang_remap_getFilenames +_clang_remap_dispose diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index 403cd67..47b7030 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -6,6 +6,7 @@ clang_annotateTokens clang_codeCompleteAt clang_codeCompleteGetDiagnostic clang_codeCompleteGetNumDiagnostics +clang_codeCompleteGetContexts clang_constructUSR_ObjCCategory clang_constructUSR_ObjCClass clang_constructUSR_ObjCIvar @@ -112,6 +113,7 @@ clang_getTranslationUnitSpelling clang_getTypeDeclaration clang_getTypeKindSpelling clang_hashCursor +clang_isAttribute clang_isConstQualifiedType clang_isCursorDefinition clang_isDeclaration @@ -135,3 +137,7 @@ clang_toggleCrashRecovery clang_tokenize clang_visitChildren clang_visitChildrenWithBlock +clang_getRemappings +clang_remap_getNumFiles +clang_remap_getFilenames +clang_remap_dispose |