aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/Stmt.h17
-rw-r--r--lib/AST/Stmt.cpp6
2 files changed, 22 insertions, 1 deletions
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index 20b01cec55..210a142123 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -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; }
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index 689fe852d8..fbb369f387 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -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(); }