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