summaryrefslogtreecommitdiffstats
path: root/clang/AST/StmtIterator.cpp
blob: d618db8147dad51d41669ef3a4d6f9a486ad648d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//===--- StmtIterator.cpp - Iterators for Statements ------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by Ted Kremenek and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines internal methods for StmtIterator.
//
//===----------------------------------------------------------------------===//

#include "clang/AST/StmtIterator.h"
#include "clang/AST/Expr.h"
#include "clang/AST/Decl.h"

using namespace clang;

void StmtIteratorBase::NextDecl() {
  assert (FirstDecl && Ptr.D);

  do Ptr.D = Ptr.D->getNextDeclarator();
  while (Ptr.D != NULL && !isa<VarDecl>(Ptr.D));
}

StmtIteratorBase::StmtIteratorBase(ScopedDecl* d) {
  assert (d);
  
  while (d != NULL) {
    if (VarDecl* V = dyn_cast<VarDecl>(d))
      if (V->getInit()) break;
    
    d = d->getNextDeclarator();
  }
  
  FirstDecl = d;
  Ptr.D = d;
}

void StmtIteratorBase::PrevDecl() {
  assert (FirstDecl);
  assert (Ptr.D != FirstDecl);
  
  // March through the list of decls until we find the decl just before
  // the one we currently point 
  
  ScopedDecl* d = FirstDecl;
  ScopedDecl* lastVD = d;
  
  while (d->getNextDeclarator() != Ptr.D) {
    if (VarDecl* V = dyn_cast<VarDecl>(d))
      if (V->getInit())
        lastVD = d;

    d = d->getNextDeclarator();
  }
  
  Ptr.D = lastVD;
}

Stmt* StmtIteratorBase::GetInitializer() const {
  return cast<VarDecl>(Ptr.D)->getInit();
}
OpenPOWER on IntegriCloud