[cfe-commits] r146067 - in /cfe/trunk: include/clang-c/Index.h tools/c-index-test/c-index-test.c tools/libclang/IndexingContext.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Dec 7 12:44:12 PST 2011


Author: akirtzidis
Date: Wed Dec  7 14:44:12 2011
New Revision: 146067

URL: http://llvm.org/viewvc/llvm-project?rev=146067&view=rev
Log:
[libclang] Introduce CXIdxEntityLanguage that indicates the language
of an indexed entity.

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/tools/c-index-test/c-index-test.c
    cfe/trunk/tools/libclang/IndexingContext.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=146067&r1=146066&r2=146067&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Wed Dec  7 14:44:12 2011
@@ -4134,11 +4134,17 @@
   CXIdxEntity_CXXConstructor        = 22,
   CXIdxEntity_CXXDestructor         = 23,
   CXIdxEntity_CXXConversionFunction = 24,
-  CXIdxEntity_CXXTypeAlias          = 25,
-  CXIdxEntity_CXXInstanceVariable   = 26
+  CXIdxEntity_CXXTypeAlias          = 25
 
 } CXIdxEntityKind;
 
+typedef enum {
+  CXIdxEntityLang_None = 0,
+  CXIdxEntityLang_C    = 1,
+  CXIdxEntityLang_ObjC = 2,
+  CXIdxEntityLang_CXX  = 3
+} CXIdxEntityLanguage;
+
 /**
  * \brief Extra C++ template information for an entity. This can apply to:
  * CXIdxEntity_Function
@@ -4159,6 +4165,7 @@
 typedef struct {
   CXIdxEntityKind kind;
   CXIdxEntityCXXTemplateKind templateKind;
+  CXIdxEntityLanguage lang;
   const char *name;
   const char *USR;
   CXCursor cursor;

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=146067&r1=146066&r2=146067&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Wed Dec  7 14:44:12 2011
@@ -1641,7 +1641,6 @@
   case CXIdxEntity_CXXNamespace: return "namespace";
   case CXIdxEntity_CXXNamespaceAlias: return "namespace-alias";
   case CXIdxEntity_CXXStaticVariable: return "c++-static-var";
-  case CXIdxEntity_CXXInstanceVariable: return "c++-instance-var";
   case CXIdxEntity_CXXStaticMethod: return "c++-static-method";
   case CXIdxEntity_CXXInstanceMethod: return "c++-instance-method";
   case CXIdxEntity_CXXConstructor: return "constructor";
@@ -1665,6 +1664,17 @@
   return 0;
 }
 
+static const char *getEntityLanguageString(CXIdxEntityLanguage kind) {
+  switch (kind) {
+  case CXIdxEntityLang_None: return "<none>";
+  case CXIdxEntityLang_C: return "C";
+  case CXIdxEntityLang_ObjC: return "ObjC";
+  case CXIdxEntityLang_CXX: return "C++";
+  }
+  assert(0 && "Garbage language kind");
+  return 0;
+}
+
 static void printEntityInfo(const char *cb,
                             CXClientData client_data,
                             const CXIdxEntityInfo *info) {
@@ -1684,6 +1694,7 @@
 
   printf("%s: kind: %s%s", cb, getEntityKindString(info->kind),
          getEntityTemplateKindString(info->templateKind));
+  printf(" | lang: %s", getEntityLanguageString(info->lang));
   printf(" | name: %s", name);
   printf(" | USR: %s", info->USR);
 }

Modified: cfe/trunk/tools/libclang/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=146067&r1=146066&r2=146067&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.cpp (original)
+++ cfe/trunk/tools/libclang/IndexingContext.cpp Wed Dec  7 14:44:12 2011
@@ -705,6 +705,7 @@
   EntityInfo.IndexCtx = this;
   EntityInfo.kind = CXIdxEntity_Unexposed;
   EntityInfo.templateKind = CXIdxEntity_NonTemplate;
+  EntityInfo.lang = CXIdxEntityLang_C;
 
   if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
     switch (TD->getTagKind()) {
@@ -713,15 +714,18 @@
     case TTK_Union:
       EntityInfo.kind = CXIdxEntity_Union; break;
     case TTK_Class:
-      EntityInfo.kind = CXIdxEntity_CXXClass; break;
+      EntityInfo.kind = CXIdxEntity_CXXClass;
+      EntityInfo.lang = CXIdxEntityLang_CXX;
+      break;
     case TTK_Enum:
       EntityInfo.kind = CXIdxEntity_Enum; break;
     }
 
     if (const CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(D)) {
-      if (TD->getTagKind() == TTK_Struct &&
-          CXXRec->hasDefinition() && !CXXRec->isPOD())
-        EntityInfo.kind = CXIdxEntity_CXXClass;
+      // FIXME: isPOD check is not sufficient, a POD can contain methods,
+      // we want a isCStructLike check.
+      if (CXXRec->hasDefinition() && !CXXRec->isPOD())
+        EntityInfo.lang = CXIdxEntityLang_CXX;
     }
 
     if (isa<ClassTemplatePartialSpecializationDecl>(D)) {
@@ -739,50 +743,77 @@
       break;
     case Decl::Var:
       EntityInfo.kind = CXIdxEntity_Variable;
-      if (isa<CXXRecordDecl>(D->getDeclContext()))
+      if (isa<CXXRecordDecl>(D->getDeclContext())) {
         EntityInfo.kind = CXIdxEntity_CXXStaticVariable;
+        EntityInfo.lang = CXIdxEntityLang_CXX;
+      }
       break;
     case Decl::Field:
       EntityInfo.kind = CXIdxEntity_Field;
       if (const CXXRecordDecl *
-            CXXRec = dyn_cast<CXXRecordDecl>(D->getDeclContext()))
+            CXXRec = dyn_cast<CXXRecordDecl>(D->getDeclContext())) {
+        // FIXME: isPOD check is not sufficient, a POD can contain methods,
+        // we want a isCStructLike check.
         if (!CXXRec->isPOD())
-          EntityInfo.kind = CXIdxEntity_CXXInstanceVariable;
+          EntityInfo.lang = CXIdxEntityLang_CXX;
+      }
       break;
     case Decl::EnumConstant:
       EntityInfo.kind = CXIdxEntity_EnumConstant; break;
     case Decl::ObjCInterface:
-      EntityInfo.kind = CXIdxEntity_ObjCClass; break;
+      EntityInfo.kind = CXIdxEntity_ObjCClass;
+      EntityInfo.lang = CXIdxEntityLang_ObjC;
+      break;
     case Decl::ObjCProtocol:
-      EntityInfo.kind = CXIdxEntity_ObjCProtocol; break;
+      EntityInfo.kind = CXIdxEntity_ObjCProtocol;
+      EntityInfo.lang = CXIdxEntityLang_ObjC;
+      break;
     case Decl::ObjCCategory:
-      EntityInfo.kind = CXIdxEntity_ObjCCategory; break;
+      EntityInfo.kind = CXIdxEntity_ObjCCategory;
+      EntityInfo.lang = CXIdxEntityLang_ObjC;
+      break;
     case Decl::ObjCMethod:
       if (cast<ObjCMethodDecl>(D)->isInstanceMethod())
         EntityInfo.kind = CXIdxEntity_ObjCInstanceMethod;
       else
         EntityInfo.kind = CXIdxEntity_ObjCClassMethod;
+      EntityInfo.lang = CXIdxEntityLang_ObjC;
       break;
     case Decl::ObjCProperty:
-      EntityInfo.kind = CXIdxEntity_ObjCProperty; break;
+      EntityInfo.kind = CXIdxEntity_ObjCProperty;
+      EntityInfo.lang = CXIdxEntityLang_ObjC;
+      break;
     case Decl::ObjCIvar:
-      EntityInfo.kind = CXIdxEntity_ObjCIvar; break;
+      EntityInfo.kind = CXIdxEntity_ObjCIvar;
+      EntityInfo.lang = CXIdxEntityLang_ObjC;
+      break;
     case Decl::Namespace:
-      EntityInfo.kind = CXIdxEntity_CXXNamespace; break;
+      EntityInfo.kind = CXIdxEntity_CXXNamespace;
+      EntityInfo.lang = CXIdxEntityLang_CXX;
+      break;
     case Decl::NamespaceAlias:
-      EntityInfo.kind = CXIdxEntity_CXXNamespaceAlias; break;
+      EntityInfo.kind = CXIdxEntity_CXXNamespaceAlias;
+      EntityInfo.lang = CXIdxEntityLang_CXX;
+      break;
     case Decl::CXXConstructor:
-      EntityInfo.kind = CXIdxEntity_CXXConstructor; break;
+      EntityInfo.kind = CXIdxEntity_CXXConstructor;
+      EntityInfo.lang = CXIdxEntityLang_CXX;
+      break;
     case Decl::CXXDestructor:
-      EntityInfo.kind = CXIdxEntity_CXXDestructor; break;
+      EntityInfo.kind = CXIdxEntity_CXXDestructor;
+      EntityInfo.lang = CXIdxEntityLang_CXX;
+      break;
     case Decl::CXXConversion:
-      EntityInfo.kind = CXIdxEntity_CXXConversionFunction; break;
+      EntityInfo.kind = CXIdxEntity_CXXConversionFunction;
+      EntityInfo.lang = CXIdxEntityLang_CXX;
+      break;
     case Decl::CXXMethod: {
       const CXXMethodDecl *MD = cast<CXXMethodDecl>(D);
       if (MD->isStatic())
         EntityInfo.kind = CXIdxEntity_CXXStaticMethod;
       else
         EntityInfo.kind = CXIdxEntity_CXXInstanceMethod;
+      EntityInfo.lang = CXIdxEntityLang_CXX;
       break;
     }
     case Decl::ClassTemplate:
@@ -813,7 +844,9 @@
       EntityInfo.templateKind = CXIdxEntity_Template;
       break;
     case Decl::TypeAlias:
-      EntityInfo.kind = CXIdxEntity_CXXTypeAlias; break;
+      EntityInfo.kind = CXIdxEntity_CXXTypeAlias;
+      EntityInfo.lang = CXIdxEntityLang_CXX;
+      break;
     default:
       break;
     }
@@ -828,6 +861,9 @@
       EntityInfo.templateKind = CXIdxEntity_TemplateSpecialization;
   }
 
+  if (EntityInfo.templateKind != CXIdxEntity_NonTemplate)
+    EntityInfo.lang = CXIdxEntityLang_CXX;
+
   if (IdentifierInfo *II = D->getIdentifier()) {
     EntityInfo.name = SA.toCStr(II->getName());
 





More information about the cfe-commits mailing list