[cfe-commits] r165277 - in /cfe/trunk: include/clang-c/Index.h lib/Sema/SemaCodeComplete.cpp tools/libclang/CIndex.cpp tools/libclang/CXType.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Oct 4 17:22:24 PDT 2012


Author: akirtzidis
Date: Thu Oct  4 19:22:24 2012
New Revision: 165277

URL: http://llvm.org/viewvc/llvm-project?rev=165277&view=rev
Log:
[libclang] Introduce CXCursor_ModuleImportDecl cursor kind, used for a module
import declaration.

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/tools/libclang/CIndex.cpp
    cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=165277&r1=165276&r2=165277&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Oct  4 19:22:24 2012
@@ -2010,7 +2010,15 @@
   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
 };
 
 /**

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=165277&r1=165276&r2=165277&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Oct  4 19:22:24 2012
@@ -2882,6 +2882,9 @@
       case ObjCPropertyImplDecl::Synthesize:
         return CXCursor_ObjCSynthesizeDecl;
       }
+
+      case Decl::Import:
+        return CXCursor_ModuleImportDecl;
       
     default:
       if (TagDecl *TD = dyn_cast<TagDecl>(D)) {

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=165277&r1=165276&r2=165277&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Oct  4 19:22:24 2012
@@ -3047,6 +3047,10 @@
       if (ObjCPropertyDecl *Property = PropImpl->getPropertyDecl())
         return createCXString(Property->getIdentifier()->getName());
     
+    if (ImportDecl *ImportD = dyn_cast<ImportDecl>(D))
+      if (Module *Mod = ImportD->getImportedModule())
+        return createCXString(Mod->getFullModuleName());
+
     return createCXString("");
   }
   
@@ -3248,6 +3252,18 @@
       return cxloc::translateSourceRange(Ctx, CID->getCategoryNameLoc());
   }
 
+  if (C.kind == CXCursor_ModuleImportDecl) {
+    if (pieceIndex > 0)
+      return clang_getNullRange();
+    if (ImportDecl *ImportD = dyn_cast_or_null<ImportDecl>(getCursorDecl(C))) {
+      ArrayRef<SourceLocation> 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 @@
     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_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 @@
     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 @@
     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 @@
 /// \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 @@
 
   // 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;

Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=165277&r1=165276&r2=165277&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Thu Oct  4 19:22:24 2012
@@ -615,7 +615,7 @@
 }
 
 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<Decl*>(C.data[0]);





More information about the cfe-commits mailing list