blob: 16d8223a06e1814837823af32c9bd6109a0d5331 [file] [log] [blame]
Ted Kremenek9caf8b12007-10-18 00:24:38 +00001//===--- 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
18using namespace clang;
19
Ted Kremenekc7c326a2007-10-18 16:25:40 +000020void 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
28void 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 Kremenek9caf8b12007-10-18 00:24:38 +000045
46Stmt*& 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}