]> granicus.if.org Git - clang/commitdiff
Add DeclStmt::hasSolitaryDecl() and DeclStmt::getSolitaryDecl()
authorTed Kremenek <kremenek@apple.com>
Mon, 6 Oct 2008 20:54:44 +0000 (20:54 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 6 Oct 2008 20:54:44 +0000 (20:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57204 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Stmt.h
lib/AST/Stmt.cpp

index 20b01cec5571a89d0e40447cbb97ee5235804f98..210a142123d45f3e866c17ea4a642b954fd028b5 100644 (file)
@@ -140,6 +140,7 @@ public:
 /// the first statement can be an expression or a declaration.
 ///
 class DeclStmt : public Stmt {
+protected:
   ScopedDecl *TheDecl;
   SourceLocation StartLoc, EndLoc;
 public:
@@ -148,8 +149,24 @@ public:
   
   virtual void Destroy(ASTContext& Ctx);
 
+  // hasSolitaryDecl - This method returns true if this DeclStmt refers
+  // to a single Decl.
+  bool hasSolitaryDecl() const;
+  
   const ScopedDecl *getDecl() const { return TheDecl; }
   ScopedDecl *getDecl() { return TheDecl; }
+  
+  const ScopedDecl* getSolitaryDecl() const {
+    assert (hasSolitaryDecl() &&
+            "Caller assumes this DeclStmt points to one Decl*");
+    return TheDecl;
+  }
+  
+  ScopedDecl* getSolitaryDecl() {
+    assert (hasSolitaryDecl() &&
+            "Caller assumes this DeclStmt points to one Decl*");
+    return TheDecl;
+  }  
 
   SourceLocation getStartLoc() const { return StartLoc; }
   SourceLocation getEndLoc() const { return EndLoc; }
index 689fe852d8fe47c00db05f9492c670ab277b8b0e..fbb369f387e2291237a64cea6b3b4b39fa2da678 100644 (file)
@@ -188,7 +188,7 @@ ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc,
 //===----------------------------------------------------------------------===//
 
 // DeclStmt
-Stmt::child_iterator DeclStmt::child_begin() { return getDecl(); }
+Stmt::child_iterator DeclStmt::child_begin() { return TheDecl; }
 Stmt::child_iterator DeclStmt::child_end() { return child_iterator(); }
 
 DeclStmt::decl_iterator& DeclStmt::decl_iterator::operator++() {
@@ -196,6 +196,10 @@ DeclStmt::decl_iterator& DeclStmt::decl_iterator::operator++() {
   return *this;
 }
 
+bool DeclStmt::hasSolitaryDecl() const {
+  return TheDecl->getNextDeclarator() == 0;
+}
+
 // NullStmt
 Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); }
 Stmt::child_iterator NullStmt::child_end() { return child_iterator(); }