[cfe-commits] r119441 - /cfe/trunk/tools/libclang/CIndex.cpp

Ted Kremenek kremenek at apple.com
Tue Nov 16 16:50:45 PST 2010


Author: kremenek
Date: Tue Nov 16 18:50:45 2010
New Revision: 119441

URL: http://llvm.org/viewvc/llvm-project?rev=119441&view=rev
Log:
CursorVisitor: migrate handling of
AddrLabelExpr to data-recursion algorithm, and
unify that reasoning with GotoStmt.

Modified:
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=119441&r1=119440&r2=119441&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Nov 16 18:50:45 2010
@@ -136,7 +136,7 @@
 public:
   enum Kind { DeclVisitKind, StmtVisitKind, MemberExprPartsKind,
               TypeLocVisitKind, OverloadExprPartsKind,
-              DeclRefExprPartsKind };
+              DeclRefExprPartsKind, LabelRefVisitKind };
 protected:
   void *dataA;
   void *dataB;
@@ -338,7 +338,6 @@
   // Expression visitors
   bool VisitOffsetOfExpr(OffsetOfExpr *E);
   bool VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E);
-  bool VisitAddrLabelExpr(AddrLabelExpr *E);
   bool VisitDesignatedInitExpr(DesignatedInitExpr *E);
   bool VisitCXXUuidofExpr(CXXUuidofExpr *E);
   bool VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
@@ -1481,10 +1480,6 @@
   return VisitExpr(E);
 }
 
-bool CursorVisitor::VisitAddrLabelExpr(AddrLabelExpr *E) {
-  return Visit(MakeCursorLabelRef(E->getLabel(), E->getLabelLoc(), TU));
-}
-
 bool CursorVisitor::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
   // Visit the designators.
   typedef DesignatedInitExpr::Designator Designator;
@@ -1673,6 +1668,20 @@
   }
 };
 
+class LabelRefVisit : public VisitorJob {
+public:
+  LabelRefVisit(LabelStmt *LS, SourceLocation labelLoc, CXCursor parent)
+    : VisitorJob(parent, VisitorJob::LabelRefVisitKind, LS,
+                 (void*) labelLoc.getRawEncoding()) {}
+  
+  static bool classof(const VisitorJob *VJ) {
+    return VJ->getKind() == VisitorJob::LabelRefVisitKind;
+  }
+  LabelStmt *get() const { return static_cast<LabelStmt*>(dataA); }
+  SourceLocation getLoc() const { 
+    return SourceLocation::getFromRawEncoding((unsigned)(uintptr_t) dataB); }
+};
+
 class EnqueueVisitor : public StmtVisitor<EnqueueVisitor, void> {
   VisitorWorkList &WL;
   CXCursor Parent;
@@ -1680,6 +1689,7 @@
   EnqueueVisitor(VisitorWorkList &wl, CXCursor parent)
     : WL(wl), Parent(parent) {}
 
+  void VisitAddrLabelExpr(AddrLabelExpr *E);
   void VisitBlockExpr(BlockExpr *B);
   void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
   void VisitCompoundStmt(CompoundStmt *S);
@@ -1693,6 +1703,7 @@
   void VisitDeclStmt(DeclStmt *S);
   void VisitExplicitCastExpr(ExplicitCastExpr *E);
   void VisitForStmt(ForStmt *FS);
+  void VisitGotoStmt(GotoStmt *GS);
   void VisitIfStmt(IfStmt *If);
   void VisitInitListExpr(InitListExpr *IE);
   void VisitMemberExpr(MemberExpr *M);
@@ -1739,6 +1750,9 @@
   VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
   std::reverse(I, E);
 }
+void EnqueueVisitor::VisitAddrLabelExpr(AddrLabelExpr *E) {
+  WL.push_back(LabelRefVisit(E->getLabel(), E->getLabelLoc(), Parent));
+}
 void EnqueueVisitor::VisitBlockExpr(BlockExpr *B) {
   AddDecl(B->getBlockDecl());
 }
@@ -1814,6 +1828,9 @@
   AddDecl(FS->getConditionVariable());
   AddStmt(FS->getInit());
 }
+void EnqueueVisitor::VisitGotoStmt(GotoStmt *GS) {
+  WL.push_back(LabelRefVisit(GS->getLabel(), GS->getLabelLoc(), Parent));
+}
 void EnqueueVisitor::VisitIfStmt(IfStmt *If) {
   AddStmt(If->getElse());
   AddStmt(If->getThen());
@@ -1908,6 +1925,14 @@
           return true;
         continue;
       }
+      case VisitorJob::LabelRefVisitKind: {
+        LabelStmt *LS = cast<LabelRefVisit>(&LI)->get();
+        if (Visit(MakeCursorLabelRef(LS,
+                                     cast<LabelRefVisit>(&LI)->getLoc(),
+                                     TU)))
+          return true;
+        continue;
+      }
       case VisitorJob::StmtVisitKind: {
         Stmt *S = cast<StmtVisit>(&LI)->get();
         if (!S)
@@ -1917,29 +1942,16 @@
         CXCursor Cursor = MakeCXCursor(S, StmtParent, TU);
         
         switch (S->getStmtClass()) {
-          case Stmt::GotoStmtClass: {
-            GotoStmt *GS = cast<GotoStmt>(S);
-            if (Visit(MakeCursorLabelRef(GS->getLabel(),
-                                         GS->getLabelLoc(), TU))) {
-              return true;
-            }
-            continue;
-          }
           // Cases not yet handled by the data-recursion
           // algorithm.
           case Stmt::OffsetOfExprClass:
           case Stmt::SizeOfAlignOfExprClass:
-          case Stmt::AddrLabelExprClass:
-          case Stmt::TypesCompatibleExprClass:
-          case Stmt::VAArgExprClass:
           case Stmt::DesignatedInitExprClass:
-          case Stmt::CXXTypeidExprClass:
           case Stmt::CXXUuidofExprClass:
           case Stmt::CXXScalarValueInitExprClass:
           case Stmt::CXXPseudoDestructorExprClass:
           case Stmt::UnaryTypeTraitExprClass:
           case Stmt::DependentScopeDeclRefExprClass:
-          case Stmt::CXXUnresolvedConstructExprClass:
           case Stmt::CXXDependentScopeMemberExprClass:
             if (Visit(Cursor))
               return true;





More information about the cfe-commits mailing list