Ted Kremenek | 9caf8b1 | 2007-10-18 00:24:38 +0000 | [diff] [blame] | 1 | //===--- StmtIterator.cpp - Iterators for Statements ------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Ted Kremenek and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines internal methods for StmtIterator. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/StmtIterator.h" |
| 15 | #include "clang/AST/Stmt.h" |
| 16 | #include "clang/AST/Decl.h" |
| 17 | |
| 18 | using namespace clang; |
| 19 | |
Ted Kremenek | c7c326a | 2007-10-18 16:25:40 +0000 | [diff] [blame^] | 20 | void StmtIterator::NextDecl() { |
| 21 | assert (D); |
| 22 | do D = D->getNextDeclarator(); |
| 23 | while (D != NULL && !isa<VarDecl>(D)); |
| 24 | |
| 25 | if (!D) S = NULL; |
| 26 | } |
| 27 | |
| 28 | void StmtIterator::PrevDecl() { |
| 29 | assert (isa<DeclStmt>(*S)); |
| 30 | DeclStmt* DS = cast<DeclStmt>(*S); |
| 31 | |
| 32 | ScopedDecl* d = DS->getDecl(); |
| 33 | assert (d); |
| 34 | |
| 35 | if (d == D) { assert(false) ; return; } |
| 36 | |
| 37 | // March through the list of decls until we find the decl just before |
| 38 | // the one we currently point |
| 39 | |
| 40 | while (d->getNextDeclarator() != D) |
| 41 | d = d->getNextDeclarator(); |
| 42 | |
| 43 | D = d; |
| 44 | } |
Ted Kremenek | 9caf8b1 | 2007-10-18 00:24:38 +0000 | [diff] [blame] | 45 | |
| 46 | Stmt*& StmtIterator::GetInitializer() const { |
| 47 | assert (D && isa<VarDecl>(D)); |
| 48 | assert (cast<VarDecl>(D)->Init); |
| 49 | return reinterpret_cast<Stmt*&>(cast<VarDecl>(D)->Init); |
| 50 | } |