[cfe-commits] r93599 - in /cfe/trunk/tools/CIndex: CIndex.cpp CXCursor.cpp CXCursor.h

Ted Kremenek kremenek at apple.com
Fri Jan 15 16:36:30 PST 2010


Author: kremenek
Date: Fri Jan 15 18:36:30 2010
New Revision: 93599

URL: http://llvm.org/viewvc/llvm-project?rev=93599&view=rev
Log:
Migrate Decl* -> cursorkind logic into CXCursor.cpp, and drastically tighten TUVisitor.

Modified:
    cfe/trunk/tools/CIndex/CIndex.cpp
    cfe/trunk/tools/CIndex/CXCursor.cpp
    cfe/trunk/tools/CIndex/CXCursor.h

Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=93599&r1=93598&r2=93599&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Fri Jan 15 18:36:30 2010
@@ -145,16 +145,18 @@
   // be suppressed.
   unsigned MaxPCHLevel;
 
-  void Call(enum CXCursorKind CK, NamedDecl *ND) {
-    // Filter any declarations that have a PCH level greater than what we allow.
-    if (ND->getPCHLevel() > MaxPCHLevel)
-      return;
-
-    // Filter any implicit declarations (since the source info will be bogus).
-    if (ND->isImplicit())
-      return;
+  void Call(const CXCursor &C) {
+    if (const Decl *D = getCursorDecl(C)) {
+      // Filter any declarations that have a PCH level greater than what 
+      // we allow.
+      if (D->getPCHLevel() > MaxPCHLevel)
+        return;
+
+      // Filter any implicit declarations (since the source info will be bogus).
+      if (D->isImplicit())
+        return;
+    }
 
-    CXCursor C = { CK, { ND, 0, 0 } };
     Callback(Root, C, CData);
   }
 
@@ -162,78 +164,27 @@
   TUVisitor(void *root, Iterator cback, CXClientData D, unsigned MaxPCHLevel) :
     Root(root), Callback(cback), CData(D), MaxPCHLevel(MaxPCHLevel) {}
 
+  void VisitDecl(Decl *D);
+  void VisitObjCClassDecl(ObjCClassDecl *D) {
+    // FIXME: Do something.
+  }
   void VisitDeclContext(DeclContext *DC);
-  void VisitFunctionDecl(FunctionDecl *ND);
-  void VisitObjCCategoryDecl(ObjCCategoryDecl *ND);
-  void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *ND);
-  void VisitObjCImplementationDecl(ObjCImplementationDecl *ND);
-  void VisitObjCInterfaceDecl(ObjCInterfaceDecl *ND);
-  void VisitObjCProtocolDecl(ObjCProtocolDecl *ND);
-  void VisitTagDecl(TagDecl *ND);
   void VisitTranslationUnitDecl(TranslationUnitDecl *D);
-  void VisitTypedefDecl(TypedefDecl *ND);
-  void VisitVarDecl(VarDecl *ND);
 };
 
+void TUVisitor::VisitDecl(Decl *D) {
+  Call(MakeCXCursor(D));
+}
+  
 void TUVisitor::VisitDeclContext(DeclContext *DC) {
   for (DeclContext::decl_iterator I = DC->decls_begin(), E = DC->decls_end();
        I != E; ++I)
     Visit(*I);
 }
-  
-void TUVisitor::VisitFunctionDecl(FunctionDecl *ND) {
-  Call(ND->isThisDeclarationADefinition() ? CXCursor_FunctionDefn
-       : CXCursor_FunctionDecl, ND);
-}
-  
-void TUVisitor::VisitObjCCategoryDecl(ObjCCategoryDecl *ND) {
-  Call(CXCursor_ObjCCategoryDecl, ND);
-}
-
-void TUVisitor::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *ND) {
-  Call(CXCursor_ObjCCategoryDefn, ND);
-}
-
-void TUVisitor::VisitObjCImplementationDecl(ObjCImplementationDecl *ND) {
-  Call(CXCursor_ObjCClassDefn, ND);
-}
-  
-void TUVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ND) {
-  Call(CXCursor_ObjCInterfaceDecl, ND);
-}  
-
-void TUVisitor::VisitObjCProtocolDecl(ObjCProtocolDecl *ND) {
-  Call(CXCursor_ObjCProtocolDecl, ND);
-}
-  
-void TUVisitor::VisitTagDecl(TagDecl *ND) {
-  switch (ND->getTagKind()) {
-    case TagDecl::TK_struct:
-      Call(CXCursor_StructDecl, ND);
-      break;
-    case TagDecl::TK_class:
-      Call(CXCursor_ClassDecl, ND);
-      break;
-    case TagDecl::TK_union:
-      Call(CXCursor_UnionDecl, ND);
-      break;
-    case TagDecl::TK_enum:
-      Call(CXCursor_EnumDecl, ND);
-      break;
-  }
-}
-  
+    
 void TUVisitor::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
   VisitDeclContext(dyn_cast<DeclContext>(D));
 }
-  
-void TUVisitor::VisitTypedefDecl(TypedefDecl *ND) {
-  Call(CXCursor_TypedefDecl, ND);
-}
-
-void TUVisitor::VisitVarDecl(VarDecl *ND) {
-  Call(CXCursor_VarDecl, ND);
-}
 
 // Declaration visitor.
 class CDeclVisitor : public DeclVisitor<CDeclVisitor> {

Modified: cfe/trunk/tools/CIndex/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CXCursor.cpp?rev=93599&r1=93598&r2=93599&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CXCursor.cpp (original)
+++ cfe/trunk/tools/CIndex/CXCursor.cpp Fri Jan 15 18:36:30 2010
@@ -15,6 +15,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/Expr.h"
+#include "llvm/Support/ErrorHandling.h"
 
 using namespace clang;
 
@@ -29,6 +30,37 @@
   return C;  
 }
 
+static CXCursorKind GetCursorKind(Decl *D) {
+  switch (D->getKind()) {
+    case Decl::Function:  
+      return cast<FunctionDecl>(D)->isThisDeclarationADefinition()
+              ? CXCursor_FunctionDefn : CXCursor_FunctionDecl;
+    case Decl::ObjCCategory:       return CXCursor_ObjCCategoryDecl;
+    case Decl::ObjCCategoryImpl:   return CXCursor_ObjCCategoryDefn;
+    case Decl::ObjCImplementation: return CXCursor_ObjCClassDefn;
+    case Decl::ObjCInterface:      return CXCursor_ObjCInterfaceDecl;
+    case Decl::ObjCProtocol:       return CXCursor_ObjCProtocolDecl;
+    case Decl::Typedef:            return CXCursor_TypedefDecl;
+    case Decl::Var:                return CXCursor_VarDecl;
+    default:
+      if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
+        switch (TD->getTagKind()) {
+          case TagDecl::TK_struct: return CXCursor_StructDecl;
+          case TagDecl::TK_class:  return CXCursor_ClassDecl;
+          case TagDecl::TK_union:  return CXCursor_UnionDecl;
+          case TagDecl::TK_enum:   return CXCursor_EnumDecl;
+        }
+      }
+  }
+  
+  llvm_unreachable("Invalid Decl");
+  return CXCursor_NotImplemented;  
+}
+
+CXCursor cxcursor::MakeCXCursor(Decl *D) {
+  return MakeCXCursor(GetCursorKind(D), D);
+}
+
 Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
   return (Decl *)Cursor.data[0];
 }

Modified: cfe/trunk/tools/CIndex/CXCursor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CXCursor.h?rev=93599&r1=93598&r2=93599&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CXCursor.h (original)
+++ cfe/trunk/tools/CIndex/CXCursor.h Fri Jan 15 18:36:30 2010
@@ -27,6 +27,7 @@
   
 CXCursor MakeCXCursor(CXCursorKind K, clang::Decl *D);  
 CXCursor MakeCXCursor(CXCursorKind K, clang::Decl *D, clang::Stmt *S);
+CXCursor MakeCXCursor(clang::Decl *D);
 
 Decl *getCursorDecl(CXCursor Cursor);
 Expr *getCursorExpr(CXCursor Cursor);





More information about the cfe-commits mailing list