From: Argyrios Kyrtzidis Date: Fri, 5 Oct 2012 00:22:24 +0000 (+0000) Subject: [libclang] Introduce CXCursor_ModuleImportDecl cursor kind, used for a module X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a01012e6bffa246810dc5c655a9a30082331fb2;p=clang [libclang] Introduce CXCursor_ModuleImportDecl cursor kind, used for a module import declaration. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165277 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index fba2ba8337..c2b1f25f83 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -2010,7 +2010,15 @@ enum CXCursorKind { CXCursor_MacroInstantiation = CXCursor_MacroExpansion, CXCursor_InclusionDirective = 503, CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective, - CXCursor_LastPreprocessing = CXCursor_InclusionDirective + CXCursor_LastPreprocessing = CXCursor_InclusionDirective, + + /* Extra Declarations */ + /** + * \brief A module import declaration. + */ + CXCursor_ModuleImportDecl = 600, + CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl, + CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl }; /** diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 1fc5d8f2ce..74a4958d93 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -2882,6 +2882,9 @@ CXCursorKind clang::getCursorKindForDecl(Decl *D) { case ObjCPropertyImplDecl::Synthesize: return CXCursor_ObjCSynthesizeDecl; } + + case Decl::Import: + return CXCursor_ModuleImportDecl; default: if (TagDecl *TD = dyn_cast(D)) { diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 5ad025a013..abe3eea4af 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -3047,6 +3047,10 @@ static CXString getDeclSpelling(Decl *D) { if (ObjCPropertyDecl *Property = PropImpl->getPropertyDecl()) return createCXString(Property->getIdentifier()->getName()); + if (ImportDecl *ImportD = dyn_cast(D)) + if (Module *Mod = ImportD->getImportedModule()) + return createCXString(Mod->getFullModuleName()); + return createCXString(""); } @@ -3248,6 +3252,18 @@ CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor C, return cxloc::translateSourceRange(Ctx, CID->getCategoryNameLoc()); } + if (C.kind == CXCursor_ModuleImportDecl) { + if (pieceIndex > 0) + return clang_getNullRange(); + if (ImportDecl *ImportD = dyn_cast_or_null(getCursorDecl(C))) { + ArrayRef Locs = ImportD->getIdentifierLocs(); + if (!Locs.empty()) + return cxloc::translateSourceRange(Ctx, + SourceRange(Locs.front(), Locs.back())); + } + return clang_getNullRange(); + } + // FIXME: A CXCursor_InclusionDirective should give the location of the // filename, but we don't keep track of this. @@ -3643,6 +3659,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) { return createCXString("ObjCDynamicDecl"); case CXCursor_CXXAccessSpecifier: return createCXString("CXXAccessSpecifier"); + case CXCursor_ModuleImportDecl: + return createCXString("ModuleImport"); } llvm_unreachable("Unhandled CXCursorKind"); @@ -3839,7 +3857,8 @@ unsigned clang_isInvalid(enum CXCursorKind K) { } unsigned clang_isDeclaration(enum CXCursorKind K) { - return K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl; + return (K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl) || + (K >= CXCursor_FirstExtraDecl && K <= CXCursor_LastExtraDecl); } unsigned clang_isReference(enum CXCursorKind K) { @@ -3986,7 +4005,7 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) { return cxloc::translateSourceLocation(getCursorContext(C), L); } - if (C.kind < CXCursor_FirstDecl || C.kind > CXCursor_LastDecl) + if (!clang_isDeclaration(C.kind)) return clang_getNullLocation(); Decl *D = getCursorDecl(C); @@ -4121,7 +4140,7 @@ static SourceRange getRawCursorExtent(CXCursor C) { return SourceRange(Start, End); } - if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl) { + if (clang_isDeclaration(C.kind)) { Decl *D = cxcursor::getCursorDecl(C); if (!D) return SourceRange(); @@ -4144,7 +4163,7 @@ static SourceRange getRawCursorExtent(CXCursor C) { /// \brief Retrieves the "raw" cursor extent, which is then extended to include /// the decl-specifier-seq for declarations. static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr) { - if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl) { + if (clang_isDeclaration(C.kind)) { Decl *D = cxcursor::getCursorDecl(C); if (!D) return SourceRange(); @@ -5108,7 +5127,7 @@ AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) { // Adjust the annotated range based specific declarations. const enum CXCursorKind cursorK = clang_getCursorKind(cursor); - if (cursorK >= CXCursor_FirstDecl && cursorK <= CXCursor_LastDecl) { + if (clang_isDeclaration(cursorK)) { Decl *D = cxcursor::getCursorDecl(cursor); SourceLocation StartLoc; diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index 15f818a244..f1bea30a9d 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -615,7 +615,7 @@ long long clang_getArraySize(CXType CT) { } CXString clang_getDeclObjCTypeEncoding(CXCursor C) { - if ((C.kind < CXCursor_FirstDecl) || (C.kind > CXCursor_LastDecl)) + if (!clang_isDeclaration(C.kind)) return cxstring::createCXString(""); Decl *D = static_cast(C.data[0]);