2007-10-18 04:24:38 +04:00
|
|
|
//===--- StmtIterator.cpp - Iterators for Statements ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 22:59:25 +03:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-10-18 04:24:38 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines internal methods for StmtIterator.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/StmtIterator.h"
|
|
|
|
#include "clang/AST/Decl.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
2008-12-06 02:32:09 +03:00
|
|
|
// FIXME: Add support for dependent-sized array types in C++?
|
|
|
|
// Does it even make sense to build a CFG for an uninstantiated template?
|
2007-10-29 23:50:16 +03:00
|
|
|
static inline VariableArrayType* FindVA(Type* t) {
|
|
|
|
while (ArrayType* vt = dyn_cast<ArrayType>(t)) {
|
|
|
|
if (VariableArrayType* vat = dyn_cast<VariableArrayType>(vt))
|
|
|
|
if (vat->getSizeExpr())
|
|
|
|
return vat;
|
|
|
|
|
|
|
|
t = vt->getElementType().getTypePtr();
|
|
|
|
}
|
2007-10-26 02:24:19 +04:00
|
|
|
|
2007-10-29 23:50:16 +03:00
|
|
|
return NULL;
|
2007-10-26 02:24:19 +04:00
|
|
|
}
|
|
|
|
|
2007-10-29 23:50:16 +03:00
|
|
|
void StmtIteratorBase::NextVA() {
|
|
|
|
assert (getVAPtr());
|
2007-10-18 20:25:40 +04:00
|
|
|
|
2007-10-29 23:50:16 +03:00
|
|
|
VariableArrayType* p = getVAPtr();
|
|
|
|
p = FindVA(p->getElementType().getTypePtr());
|
|
|
|
setVAPtr(p);
|
2007-10-18 20:25:40 +04:00
|
|
|
|
2008-10-08 03:35:42 +04:00
|
|
|
if (p)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (inDecl()) {
|
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(decl))
|
|
|
|
if (VD->Init)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NextDecl();
|
|
|
|
}
|
|
|
|
else if (inDeclGroup()) {
|
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(*DGI))
|
|
|
|
if (VD->Init)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NextDecl();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert (inSizeOfTypeVA());
|
2008-05-21 09:06:46 +04:00
|
|
|
assert(!decl);
|
2007-12-15 01:52:23 +03:00
|
|
|
RawVAPtr = 0;
|
2008-05-21 09:06:46 +04:00
|
|
|
}
|
2007-10-18 22:19:31 +04:00
|
|
|
}
|
|
|
|
|
2007-10-29 23:50:16 +03:00
|
|
|
void StmtIteratorBase::NextDecl(bool ImmediateAdvance) {
|
|
|
|
assert (getVAPtr() == NULL);
|
2007-10-18 22:19:31 +04:00
|
|
|
|
2008-10-08 03:04:14 +04:00
|
|
|
if (inDecl()) {
|
|
|
|
assert (decl);
|
|
|
|
|
|
|
|
if (ImmediateAdvance)
|
|
|
|
decl = decl->getNextDeclarator();
|
|
|
|
|
|
|
|
for ( ; decl ; decl = decl->getNextDeclarator())
|
|
|
|
if (HandleDecl(decl))
|
2007-10-29 23:50:16 +03:00
|
|
|
return;
|
2008-10-08 03:04:14 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert (inDeclGroup());
|
|
|
|
|
|
|
|
if (ImmediateAdvance)
|
|
|
|
++DGI;
|
|
|
|
|
|
|
|
for ( ; DGI != DGE; ++DGI)
|
|
|
|
if (HandleDecl(*DGI))
|
2007-10-30 00:38:03 +03:00
|
|
|
return;
|
2008-10-08 03:04:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RawVAPtr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StmtIteratorBase::HandleDecl(Decl* D) {
|
|
|
|
|
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
|
|
|
|
if (VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) {
|
|
|
|
setVAPtr(VAPtr);
|
|
|
|
return true;
|
2007-10-30 00:38:03 +03:00
|
|
|
}
|
2008-10-08 03:04:14 +04:00
|
|
|
|
|
|
|
if (VD->getInit())
|
|
|
|
return true;
|
2007-10-18 22:19:31 +04:00
|
|
|
}
|
2008-10-08 03:04:14 +04:00
|
|
|
else if (TypedefDecl* TD = dyn_cast<TypedefDecl>(D)) {
|
|
|
|
if (VariableArrayType* VAPtr =
|
|
|
|
FindVA(TD->getUnderlyingType().getTypePtr())) {
|
|
|
|
setVAPtr(VAPtr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(D)) {
|
|
|
|
if (ECD->getInitExpr())
|
|
|
|
return true;
|
2007-10-30 00:23:58 +03:00
|
|
|
}
|
2008-10-08 03:04:14 +04:00
|
|
|
|
|
|
|
return false;
|
2007-10-29 23:50:16 +03:00
|
|
|
}
|
|
|
|
|
2009-01-20 04:17:11 +03:00
|
|
|
StmtIteratorBase::StmtIteratorBase(Decl* d)
|
2007-10-29 23:50:16 +03:00
|
|
|
: decl(d), RawVAPtr(DeclMode) {
|
|
|
|
assert (decl);
|
|
|
|
NextDecl(false);
|
2007-10-18 20:25:40 +04:00
|
|
|
}
|
2007-10-18 04:24:38 +04:00
|
|
|
|
2008-10-08 03:04:14 +04:00
|
|
|
StmtIteratorBase::StmtIteratorBase(Decl** dgi, Decl** dge)
|
|
|
|
: DGI(dgi), RawVAPtr(DeclGroupMode), DGE(dge) {
|
|
|
|
NextDecl(false);
|
|
|
|
}
|
|
|
|
|
2007-12-15 01:52:23 +03:00
|
|
|
StmtIteratorBase::StmtIteratorBase(VariableArrayType* t)
|
2008-10-08 03:04:14 +04:00
|
|
|
: decl(0), RawVAPtr(SizeOfTypeVAMode) {
|
2007-12-15 01:52:23 +03:00
|
|
|
RawVAPtr |= reinterpret_cast<uintptr_t>(t);
|
|
|
|
}
|
|
|
|
|
2007-10-26 02:24:19 +04:00
|
|
|
Stmt*& StmtIteratorBase::GetDeclExpr() const {
|
2008-10-08 03:04:14 +04:00
|
|
|
|
|
|
|
if (inDeclGroup()) {
|
|
|
|
VarDecl* VD = cast<VarDecl>(*DGI);
|
|
|
|
return VD->Init;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (inDecl() || inSizeOfTypeVA());
|
|
|
|
|
2007-10-29 23:50:16 +03:00
|
|
|
if (VariableArrayType* VAPtr = getVAPtr()) {
|
|
|
|
assert (VAPtr->SizeExpr);
|
2008-05-30 20:14:41 +04:00
|
|
|
return VAPtr->SizeExpr;
|
2007-10-26 02:24:19 +04:00
|
|
|
}
|
2008-10-08 03:04:14 +04:00
|
|
|
|
|
|
|
assert (inDecl());
|
2007-10-29 23:50:16 +03:00
|
|
|
|
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(decl)) {
|
|
|
|
assert (VD->Init);
|
2008-05-30 20:14:41 +04:00
|
|
|
return VD->Init;
|
2007-10-29 23:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
EnumConstantDecl* ECD = cast<EnumConstantDecl>(decl);
|
2008-05-30 20:14:41 +04:00
|
|
|
return ECD->Init;
|
2007-10-18 04:24:38 +04:00
|
|
|
}
|