]> granicus.if.org Git - clang/commitdiff
Making some public members into private members. This also introduces a bit more...
authorAaron Ballman <aaron@aaronballman.com>
Thu, 17 Apr 2014 21:44:08 +0000 (21:44 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Thu, 17 Apr 2014 21:44:08 +0000 (21:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206503 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/Analyses/PostOrderCFGView.h
include/clang/Analysis/Analyses/ThreadSafetyCommon.h
lib/Analysis/ThreadSafety.cpp

index 4e3244e7b7ca9ff712beeef0cb4edbf5cfb3e1ac..9ceace748bb955dd09de3251fc10471c6aef2ee6 100644 (file)
@@ -76,14 +76,18 @@ private:
   BlockOrderTy BlockOrder;
 
 public:
-  typedef std::vector<const CFGBlock*>::reverse_iterator iterator;
+  typedef std::vector<const CFGBlock *>::reverse_iterator iterator;
+  typedef std::vector<const CFGBlock *>::const_reverse_iterator const_iterator;
 
   PostOrderCFGView(const CFG *cfg);
 
   iterator begin() { return Blocks.rbegin(); }
   iterator end()   { return Blocks.rend(); }
 
-  bool empty() { return begin() == end(); }
+  const_iterator begin() const { return Blocks.rbegin(); }
+  const_iterator end() const { return Blocks.rend(); }
+
+  bool empty() const { return begin() == end(); }
 
   struct BlockOrderCompare;
   friend struct BlockOrderCompare;
index cff0781666df138f0be6113fbf3313e1ca3f972b..2b693cf0e460c2b8fa3b12ebef302ef3d4ff2f85 100644 (file)
@@ -84,8 +84,7 @@ class CFGVisitor {
 // Walks the clang CFG, and invokes methods on a given CFGVisitor.
 class CFGWalker {
 public:
-  CFGWalker() :
-    CFGraph(nullptr), FDecl(nullptr), ACtx(nullptr), SortedGraph(nullptr) {}
+  CFGWalker() : CFGraph(nullptr), ACtx(nullptr), SortedGraph(nullptr) {}
 
   // Initialize the CFGWalker.  This setup only needs to be done once, even
   // if there are multiple passes over the CFG.
@@ -95,8 +94,8 @@ public:
     if (!CFGraph)
       return false;
 
-    FDecl = dyn_cast_or_null<NamedDecl>(AC.getDecl());
-    if (!FDecl) // ignore anonymous functions
+    // Ignore anonymous functions.
+    if (!dyn_cast_or_null<NamedDecl>(AC.getDecl()))
       return false;
 
     SortedGraph = AC.getAnalysis<PostOrderCFGView>();
@@ -111,7 +110,7 @@ public:
   void walk(Visitor &V) {
     PostOrderCFGView::CFGBlockSet VisitedBlocks(CFGraph);
 
-    V.enterCFG(CFGraph, FDecl, &CFGraph->getEntry());
+    V.enterCFG(CFGraph, getDecl(), &CFGraph->getEntry());
 
     for (const auto *CurrBlock : *SortedGraph) {
       VisitedBlocks.insert(CurrBlock);
@@ -181,9 +180,15 @@ public:
     V.exitCFG(&CFGraph->getExit());
   }
 
-public:  // TODO: make these private.
+  const CFG *getGraph() const { return CFGraph; }
+  CFG *getGraph() { return CFGraph; }
+
+  const NamedDecl *getDecl() const { return cast<NamedDecl>(ACtx->getDecl()); }
+
+  const PostOrderCFGView *getSortedGraph() const { return SortedGraph; }
+
+private:
   CFG *CFGraph;
-  const NamedDecl *FDecl;
   AnalysisDeclContext *ACtx;
   PostOrderCFGView *SortedGraph;
 };
index b6a73bd2d891c0956f705c12ec98aa9599b3a4e4..63063e02c674eedb499f79e82e85dc33e995ecff 100644 (file)
@@ -1069,8 +1069,8 @@ public:
   }
 
   /// Builds the variable map.
-  void traverseCFG(CFG *CFGraph, PostOrderCFGView *SortedGraph,
-                     std::vector<CFGBlockInfo> &BlockInfo);
+  void traverseCFG(CFG *CFGraph, const PostOrderCFGView *SortedGraph,
+                   std::vector<CFGBlockInfo> &BlockInfo);
 
 protected:
   // Get the current context index
@@ -1289,15 +1289,13 @@ void LocalVariableMap::intersectBackEdge(Context C1, Context C2) {
 //   ...                 { y -> y1           | x3 = 2, x2 = 1, ... }
 //
 void LocalVariableMap::traverseCFG(CFG *CFGraph,
-                                   PostOrderCFGView *SortedGraph,
+                                   const PostOrderCFGView *SortedGraph,
                                    std::vector<CFGBlockInfo> &BlockInfo) {
   PostOrderCFGView::CFGBlockSet VisitedBlocks(CFGraph);
 
   CtxIndices.resize(CFGraph->getNumBlockIDs());
 
-  for (PostOrderCFGView::iterator I = SortedGraph->begin(),
-       E = SortedGraph->end(); I!= E; ++I) {
-    const CFGBlock *CurrBlock = *I;
+  for (const auto *CurrBlock : *SortedGraph) {
     int CurrBlockID = CurrBlock->getBlockID();
     CFGBlockInfo *CurrBlockInfo = &BlockInfo[CurrBlockID];
 
@@ -1376,11 +1374,9 @@ void LocalVariableMap::traverseCFG(CFG *CFGraph,
 /// Find the appropriate source locations to use when producing diagnostics for
 /// each block in the CFG.
 static void findBlockLocations(CFG *CFGraph,
-                               PostOrderCFGView *SortedGraph,
+                               const PostOrderCFGView *SortedGraph,
                                std::vector<CFGBlockInfo> &BlockInfo) {
-  for (PostOrderCFGView::iterator I = SortedGraph->begin(),
-       E = SortedGraph->end(); I!= E; ++I) {
-    const CFGBlock *CurrBlock = *I;
+  for (const auto *CurrBlock : *SortedGraph) {
     CFGBlockInfo *CurrBlockInfo = &BlockInfo[CurrBlock->getBlockID()];
 
     // Find the source location of the last statement in the block, if the
@@ -2374,8 +2370,8 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
   // AC.dumpCFG(true);
   // threadSafety::printSCFG(walker);
 
-  CFG *CFGraph = walker.CFGraph;
-  const NamedDecl *D = walker.FDecl;
+  CFG *CFGraph = walker.getGraph();
+  const NamedDecl *D = walker.getDecl();
 
   if (D->hasAttr<NoThreadSafetyAnalysisAttr>())
     return;
@@ -2395,7 +2391,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
   // We need to explore the CFG via a "topological" ordering.
   // That way, we will be guaranteed to have information about required
   // predecessor locksets when exploring a new block.
-  PostOrderCFGView *SortedGraph = walker.SortedGraph;
+  const PostOrderCFGView *SortedGraph = walker.getSortedGraph();
   PostOrderCFGView::CFGBlockSet VisitedBlocks(CFGraph);
 
   // Mark entry block as reachable
@@ -2465,9 +2461,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
               CapDiagKind);
   }
 
-  for (PostOrderCFGView::iterator I = SortedGraph->begin(),
-       E = SortedGraph->end(); I!= E; ++I) {
-    const CFGBlock *CurrBlock = *I;
+  for (const auto *CurrBlock : *SortedGraph) {
     int CurrBlockID = CurrBlock->getBlockID();
     CFGBlockInfo *CurrBlockInfo = &BlockInfo[CurrBlockID];