]> granicus.if.org Git - clang/commitdiff
Move declaration of 'PathDiagnostic' to the end of PathDiagnostic.h and add PathDiagn...
authorTed Kremenek <kremenek@apple.com>
Fri, 27 Mar 2009 15:24:36 +0000 (15:24 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 27 Mar 2009 15:24:36 +0000 (15:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67842 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathDiagnostic.h

index 9d71093fc8347d63ac95e5a1b526e50d45cb4d89..e9ee76c030b654b8e59aa072bd0f99f2a00dfb08 100644 (file)
@@ -49,8 +49,6 @@ public:
 // Path-sensitive diagnostics.
 //===----------------------------------------------------------------------===//
   
-class PathDiagnosticPiece;
-  
 class PathDiagnosticLocation {
 private:
   enum Kind { Range, SingleLoc, Statement } K;
@@ -84,128 +82,6 @@ public:
   const PathDiagnosticLocation &getEnd() const { return End; }
 };
 
-class PathDiagnostic {
-  std::deque<PathDiagnosticPiece*> path;
-  unsigned Size;
-  std::string BugType;
-  std::string Desc;
-  std::string Category;
-  std::deque<std::string> OtherDesc;
-  
-public:  
-  PathDiagnostic();
-  
-  PathDiagnostic(const char* bugtype, const char* desc, const char* category);
-  
-  PathDiagnostic(const std::string& bugtype, const std::string& desc, 
-                 const std::string& category);
-  
-  ~PathDiagnostic();
-  
-  const std::string& getDescription() const { return Desc; }
-  const std::string& getBugType() const { return BugType; }
-  const std::string& getCategory() const { return Category; }  
-  
-  typedef std::deque<std::string>::const_iterator meta_iterator;
-  meta_iterator meta_begin() const { return OtherDesc.begin(); }
-  meta_iterator meta_end() const { return OtherDesc.end(); }
-  void addMeta(const std::string& s) { OtherDesc.push_back(s); }
-  void addMeta(const char* s) { OtherDesc.push_back(s); }
-
-  void push_front(PathDiagnosticPiece* piece) {
-    path.push_front(piece);
-    ++Size;
-  }
-  
-  void push_back(PathDiagnosticPiece* piece) {
-    path.push_back(piece);
-    ++Size;
-  }
-  
-  PathDiagnosticPiece* back() {
-    return path.back();
-  }
-  
-  const PathDiagnosticPiece* back() const {
-    return path.back();
-  }
-  
-  unsigned size() const { return Size; }
-  bool empty() const { return Size == 0; }
-  
-  void resetPath(bool deletePieces = true);
-  
-  class iterator {
-  public:  
-    typedef std::deque<PathDiagnosticPiece*>::iterator ImplTy;
-    
-    typedef PathDiagnosticPiece              value_type;
-    typedef value_type&                      reference;
-    typedef value_type*                      pointer;
-    typedef ptrdiff_t                        difference_type;
-    typedef std::bidirectional_iterator_tag  iterator_category;
-    
-  private:
-    ImplTy I;
-    
-  public:
-    iterator(const ImplTy& i) : I(i) {}
-    
-    bool operator==(const iterator& X) const { return I == X.I; }
-    bool operator!=(const iterator& X) const { return I != X.I; }
-    
-    PathDiagnosticPiece& operator*() const { return **I; }
-    PathDiagnosticPiece* operator->() const { return *I; }
-    
-    iterator& operator++() { ++I; return *this; }
-    iterator& operator--() { --I; return *this; }
-  };
-  
-  class const_iterator {
-  public:  
-    typedef std::deque<PathDiagnosticPiece*>::const_iterator ImplTy;
-    
-    typedef const PathDiagnosticPiece        value_type;
-    typedef value_type&                      reference;
-    typedef value_type*                      pointer;
-    typedef ptrdiff_t                        difference_type;
-    typedef std::bidirectional_iterator_tag  iterator_category;
-    
-  private:
-    ImplTy I;
-    
-  public:
-    const_iterator(const ImplTy& i) : I(i) {}
-    
-    bool operator==(const const_iterator& X) const { return I == X.I; }
-    bool operator!=(const const_iterator& X) const { return I != X.I; }
-    
-    reference operator*() const { return **I; }
-    pointer operator->() const { return *I; }
-    
-    const_iterator& operator++() { ++I; return *this; }
-    const_iterator& operator--() { --I; return *this; }
-  };
-  
-  typedef std::reverse_iterator<iterator>       reverse_iterator;
-  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;  
-  
-  
-  // forward iterator creation methods.
-  
-  iterator begin() { return path.begin(); }
-  iterator end() { return path.end(); }
-  
-  const_iterator begin() const { return path.begin(); }
-  const_iterator end() const { return path.end(); }
-  
-  // reverse iterator creation methods.
-  reverse_iterator rbegin()            { return reverse_iterator(end()); }
-  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
-  reverse_iterator rend()              { return reverse_iterator(begin()); }
-  const_reverse_iterator rend() const { return const_reverse_iterator(begin());}
-};
-
 //===----------------------------------------------------------------------===//
 // Path "pieces" for path-sensitive diagnostics.
 //===----------------------------------------------------------------------===//  
@@ -395,5 +271,135 @@ public:
   }
 };
 
+/// PathDiagnostic - PathDiagnostic objects represent a single path-sensitive
+///  diagnostic.  It represents an ordered-collection of PathDiagnosticPieces,
+///  each which represent the pieces of the path.
+class PathDiagnostic {
+  std::deque<PathDiagnosticPiece*> path;
+  unsigned Size;
+  std::string BugType;
+  std::string Desc;
+  std::string Category;
+  std::deque<std::string> OtherDesc;
+  
+public:  
+  PathDiagnostic();
+  
+  PathDiagnostic(const char* bugtype, const char* desc, const char* category);
+  
+  PathDiagnostic(const std::string& bugtype, const std::string& desc, 
+                 const std::string& category);
+  
+  ~PathDiagnostic();
+  
+  const std::string& getDescription() const { return Desc; }
+  const std::string& getBugType() const { return BugType; }
+  const std::string& getCategory() const { return Category; }  
+  
+  typedef std::deque<std::string>::const_iterator meta_iterator;
+  meta_iterator meta_begin() const { return OtherDesc.begin(); }
+  meta_iterator meta_end() const { return OtherDesc.end(); }
+  void addMeta(const std::string& s) { OtherDesc.push_back(s); }
+  void addMeta(const char* s) { OtherDesc.push_back(s); }
+  
+  FullSourceLoc getLocation() const {
+    assert(Size > 0 && "getLocation() requires a non-empty PathDiagnostic.");
+    return rbegin()->getLocation();
+  }
+  
+  void push_front(PathDiagnosticPiece* piece) {
+    path.push_front(piece);
+    ++Size;
+  }
+  
+  void push_back(PathDiagnosticPiece* piece) {
+    path.push_back(piece);
+    ++Size;
+  }
+  
+  PathDiagnosticPiece* back() {
+    return path.back();
+  }
+  
+  const PathDiagnosticPiece* back() const {
+    return path.back();
+  }
+  
+  unsigned size() const { return Size; }
+  bool empty() const { return Size == 0; }
+  
+  void resetPath(bool deletePieces = true);
+  
+  class iterator {
+  public:  
+    typedef std::deque<PathDiagnosticPiece*>::iterator ImplTy;
+    
+    typedef PathDiagnosticPiece              value_type;
+    typedef value_type&                      reference;
+    typedef value_type*                      pointer;
+    typedef ptrdiff_t                        difference_type;
+    typedef std::bidirectional_iterator_tag  iterator_category;
+    
+  private:
+    ImplTy I;
+    
+  public:
+    iterator(const ImplTy& i) : I(i) {}
+    
+    bool operator==(const iterator& X) const { return I == X.I; }
+    bool operator!=(const iterator& X) const { return I != X.I; }
+    
+    PathDiagnosticPiece& operator*() const { return **I; }
+    PathDiagnosticPiece* operator->() const { return *I; }
+    
+    iterator& operator++() { ++I; return *this; }
+    iterator& operator--() { --I; return *this; }
+  };
+  
+  class const_iterator {
+  public:  
+    typedef std::deque<PathDiagnosticPiece*>::const_iterator ImplTy;
+    
+    typedef const PathDiagnosticPiece        value_type;
+    typedef value_type&                      reference;
+    typedef value_type*                      pointer;
+    typedef ptrdiff_t                        difference_type;
+    typedef std::bidirectional_iterator_tag  iterator_category;
+    
+  private:
+    ImplTy I;
+    
+  public:
+    const_iterator(const ImplTy& i) : I(i) {}
+    
+    bool operator==(const const_iterator& X) const { return I == X.I; }
+    bool operator!=(const const_iterator& X) const { return I != X.I; }
+    
+    reference operator*() const { return **I; }
+    pointer operator->() const { return *I; }
+    
+    const_iterator& operator++() { ++I; return *this; }
+    const_iterator& operator--() { --I; return *this; }
+  };
+  
+  typedef std::reverse_iterator<iterator>       reverse_iterator;
+  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+  
+  // forward iterator creation methods.
+  
+  iterator begin() { return path.begin(); }
+  iterator end() { return path.end(); }
+  
+  const_iterator begin() const { return path.begin(); }
+  const_iterator end() const { return path.end(); }
+  
+  // reverse iterator creation methods.
+  reverse_iterator rbegin()            { return reverse_iterator(end()); }
+  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
+  reverse_iterator rend()              { return reverse_iterator(begin()); }
+  const_reverse_iterator rend() const { return const_reverse_iterator(begin());}
+};
+  
+  
 } //end clang namespace
 #endif