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" |
Ted Kremenek | c325e7f | 2007-10-18 18:19:31 +0000 | [diff] [blame^] | 15 | #include "clang/AST/Expr.h" |
Ted Kremenek | 9caf8b1 | 2007-10-18 00:24:38 +0000 | [diff] [blame] | 16 | #include "clang/AST/Decl.h" |
| 17 | |
| 18 | using namespace clang; |
| 19 | |
Ted Kremenek | c325e7f | 2007-10-18 18:19:31 +0000 | [diff] [blame^] | 20 | void StmtIteratorBase::NextDecl() { |
| 21 | assert (FirstDecl && Ptr.D); |
| 22 | |
| 23 | do Ptr.D = Ptr.D->getNextDeclarator(); |
| 24 | while (Ptr.D != NULL && !isa<VarDecl>(Ptr.D)); |
Ted Kremenek | c7c326a | 2007-10-18 16:25:40 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Ted Kremenek | c325e7f | 2007-10-18 18:19:31 +0000 | [diff] [blame^] | 27 | StmtIteratorBase::StmtIteratorBase(ScopedDecl* d) { |
Ted Kremenek | c7c326a | 2007-10-18 16:25:40 +0000 | [diff] [blame] | 28 | assert (d); |
| 29 | |
Ted Kremenek | c325e7f | 2007-10-18 18:19:31 +0000 | [diff] [blame^] | 30 | while (d != NULL) { |
| 31 | if (VarDecl* V = dyn_cast<VarDecl>(d)) |
| 32 | if (V->getInit()) break; |
| 33 | |
| 34 | d = d->getNextDeclarator(); |
| 35 | } |
| 36 | |
| 37 | FirstDecl = d; |
| 38 | Ptr.D = d; |
| 39 | } |
| 40 | |
| 41 | void StmtIteratorBase::PrevDecl() { |
| 42 | assert (FirstDecl); |
| 43 | assert (Ptr.D != FirstDecl); |
Ted Kremenek | c7c326a | 2007-10-18 16:25:40 +0000 | [diff] [blame] | 44 | |
| 45 | // March through the list of decls until we find the decl just before |
| 46 | // the one we currently point |
| 47 | |
Ted Kremenek | c325e7f | 2007-10-18 18:19:31 +0000 | [diff] [blame^] | 48 | ScopedDecl* d = FirstDecl; |
| 49 | ScopedDecl* lastVD = d; |
Ted Kremenek | c7c326a | 2007-10-18 16:25:40 +0000 | [diff] [blame] | 50 | |
Ted Kremenek | c325e7f | 2007-10-18 18:19:31 +0000 | [diff] [blame^] | 51 | while (d->getNextDeclarator() != Ptr.D) { |
| 52 | if (VarDecl* V = dyn_cast<VarDecl>(d)) |
| 53 | if (V->getInit()) |
| 54 | lastVD = d; |
| 55 | |
| 56 | d = d->getNextDeclarator(); |
| 57 | } |
| 58 | |
| 59 | Ptr.D = lastVD; |
Ted Kremenek | c7c326a | 2007-10-18 16:25:40 +0000 | [diff] [blame] | 60 | } |
Ted Kremenek | 9caf8b1 | 2007-10-18 00:24:38 +0000 | [diff] [blame] | 61 | |
Ted Kremenek | c325e7f | 2007-10-18 18:19:31 +0000 | [diff] [blame^] | 62 | Stmt* StmtIteratorBase::GetInitializer() const { |
| 63 | return cast<VarDecl>(Ptr.D)->getInit(); |
Ted Kremenek | 9caf8b1 | 2007-10-18 00:24:38 +0000 | [diff] [blame] | 64 | } |