Add DeclStmt::hasSolitaryDecl() and DeclStmt::getSolitaryDecl()

llvm-svn: 57204
This commit is contained in:
Ted Kremenek 2008-10-06 20:54:44 +00:00
parent 6271b0a83c
commit acf920dd39
2 changed files with 22 additions and 1 deletions

View File

@ -140,6 +140,7 @@ public:
/// the first statement can be an expression or a declaration. /// the first statement can be an expression or a declaration.
/// ///
class DeclStmt : public Stmt { class DeclStmt : public Stmt {
protected:
ScopedDecl *TheDecl; ScopedDecl *TheDecl;
SourceLocation StartLoc, EndLoc; SourceLocation StartLoc, EndLoc;
public: public:
@ -148,8 +149,24 @@ public:
virtual void Destroy(ASTContext& Ctx); 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; } const ScopedDecl *getDecl() const { return TheDecl; }
ScopedDecl *getDecl() { 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 getStartLoc() const { return StartLoc; }
SourceLocation getEndLoc() const { return EndLoc; } SourceLocation getEndLoc() const { return EndLoc; }

View File

@ -188,7 +188,7 @@ ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc,
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// DeclStmt // 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(); } Stmt::child_iterator DeclStmt::child_end() { return child_iterator(); }
DeclStmt::decl_iterator& DeclStmt::decl_iterator::operator++() { DeclStmt::decl_iterator& DeclStmt::decl_iterator::operator++() {
@ -196,6 +196,10 @@ DeclStmt::decl_iterator& DeclStmt::decl_iterator::operator++() {
return *this; return *this;
} }
bool DeclStmt::hasSolitaryDecl() const {
return TheDecl->getNextDeclarator() == 0;
}
// NullStmt // NullStmt
Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); } Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); }
Stmt::child_iterator NullStmt::child_end() { return child_iterator(); } Stmt::child_iterator NullStmt::child_end() { return child_iterator(); }