1 //===--- StmtIterator.cpp - Iterators for Statements ------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines internal methods for StmtIterator.
12 //===----------------------------------------------------------------------===//
14 #include "clang/AST/StmtIterator.h"
15 #include "clang/AST/Decl.h"
17 using namespace clang;
19 // FIXME: Add support for dependent-sized array types in C++?
20 // Does it even make sense to build a CFG for an uninstantiated template?
21 static inline const VariableArrayType *FindVA(const Type* t) {
22 while (const ArrayType *vt = dyn_cast<ArrayType>(t)) {
23 if (const VariableArrayType *vat = dyn_cast<VariableArrayType>(vt))
24 if (vat->getSizeExpr())
27 t = vt->getElementType().getTypePtr();
33 void StmtIteratorBase::NextVA() {
36 const VariableArrayType *p = getVAPtr();
37 p = FindVA(p->getElementType().getTypePtr());
44 if (VarDecl* VD = dyn_cast<VarDecl>(decl))
50 else if (inDeclGroup()) {
51 if (VarDecl* VD = dyn_cast<VarDecl>(*DGI))
58 assert (inSizeOfTypeVA());
64 void StmtIteratorBase::NextDecl(bool ImmediateAdvance) {
65 assert (getVAPtr() == NULL);
70 // FIXME: SIMPLIFY AWAY.
73 else if (HandleDecl(decl))
77 assert(inDeclGroup());
82 for ( ; DGI != DGE; ++DGI)
90 bool StmtIteratorBase::HandleDecl(Decl* D) {
92 if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
93 if (const VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) {
101 else if (TypedefDecl* TD = dyn_cast<TypedefDecl>(D)) {
102 if (const VariableArrayType* VAPtr =
103 FindVA(TD->getUnderlyingType().getTypePtr())) {
108 else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(D)) {
109 if (ECD->getInitExpr())
116 StmtIteratorBase::StmtIteratorBase(Decl *d, Stmt **s)
117 : stmt(s), decl(d), RawVAPtr(d ? DeclMode : 0) {
122 StmtIteratorBase::StmtIteratorBase(Decl** dgi, Decl** dge)
123 : stmt(0), DGI(dgi), RawVAPtr(DeclGroupMode), DGE(dge) {
127 StmtIteratorBase::StmtIteratorBase(const VariableArrayType* t)
128 : stmt(0), decl(0), RawVAPtr(SizeOfTypeVAMode) {
129 RawVAPtr |= reinterpret_cast<uintptr_t>(t);
132 Stmt*& StmtIteratorBase::GetDeclExpr() const {
134 if (const VariableArrayType* VAPtr = getVAPtr()) {
135 assert (VAPtr->SizeExpr);
136 return const_cast<Stmt*&>(VAPtr->SizeExpr);
139 assert (inDecl() || inDeclGroup());
142 VarDecl* VD = cast<VarDecl>(*DGI);
143 return *VD->getInitAddress();
148 if (VarDecl* VD = dyn_cast<VarDecl>(decl)) {
150 return *VD->getInitAddress();
153 EnumConstantDecl* ECD = cast<EnumConstantDecl>(decl);