[cfe-commits] r57204 - in /cfe/trunk: include/clang/AST/Stmt.h lib/AST/Stmt.cpp

Ted Kremenek kremenek at apple.com
Mon Oct 6 13:54:45 PDT 2008


Author: kremenek
Date: Mon Oct  6 15:54:44 2008
New Revision: 57204

URL: http://llvm.org/viewvc/llvm-project?rev=57204&view=rev
Log:
Add DeclStmt::hasSolitaryDecl() and DeclStmt::getSolitaryDecl()

Modified:
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/AST/Stmt.cpp

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=57204&r1=57203&r2=57204&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Mon Oct  6 15:54:44 2008
@@ -140,6 +140,7 @@
 /// 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 @@
   
   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; }

Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=57204&r1=57203&r2=57204&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Mon Oct  6 15:54:44 2008
@@ -188,7 +188,7 @@
 //===----------------------------------------------------------------------===//
 
 // 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 @@
   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(); }





More information about the cfe-commits mailing list