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;
|
|
|
|
|
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-05-21 09:06:46 +04:00
|
|
|
if (!p && inDecl()) {
|
2007-10-30 00:38:03 +03:00
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(decl))
|
|
|
|
if (VD->Init)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NextDecl();
|
2008-05-21 09:06:46 +04:00
|
|
|
} else if (inSizeOfTypeVA()) {
|
|
|
|
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) {
|
2007-12-15 02:40:56 +03:00
|
|
|
assert (inDecl());
|
2007-10-29 23:50:16 +03:00
|
|
|
assert (getVAPtr() == NULL);
|
|
|
|
assert (decl);
|
2007-10-18 20:25:40 +04:00
|
|
|
|
2007-10-29 23:50:16 +03:00
|
|
|
if (ImmediateAdvance) {
|
|
|
|
decl = decl->getNextDeclarator();
|
|
|
|
|
|
|
|
if (!decl) {
|
|
|
|
RawVAPtr = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-10-18 22:19:31 +04:00
|
|
|
|
2007-10-29 23:50:16 +03:00
|
|
|
for ( ; decl ; decl = decl->getNextDeclarator()) {
|
|
|
|
if (VarDecl* VD = dyn_cast<VarDecl>(decl)) {
|
|
|
|
if (VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) {
|
|
|
|
setVAPtr(VAPtr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VD->getInit())
|
|
|
|
return;
|
|
|
|
}
|
2007-10-30 00:38:03 +03:00
|
|
|
else if (TypedefDecl* TD = dyn_cast<TypedefDecl>(decl)) {
|
|
|
|
if (VariableArrayType* VAPtr =
|
|
|
|
FindVA(TD->getUnderlyingType().getTypePtr())) {
|
|
|
|
setVAPtr(VAPtr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-10-29 23:50:16 +03:00
|
|
|
else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(decl))
|
|
|
|
if (ECD->getInitExpr())
|
|
|
|
return;
|
2007-10-18 22:19:31 +04:00
|
|
|
}
|
2007-10-30 00:23:58 +03:00
|
|
|
|
|
|
|
if (!decl) {
|
|
|
|
RawVAPtr = 0;
|
|
|
|
return;
|
|
|
|
}
|
2007-10-29 23:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
StmtIteratorBase::StmtIteratorBase(ScopedDecl* d)
|
|
|
|
: decl(d), RawVAPtr(DeclMode) {
|
|
|
|
assert (decl);
|
|
|
|
NextDecl(false);
|
2007-10-18 20:25:40 +04:00
|
|
|
}
|
2007-10-18 04:24:38 +04:00
|
|
|
|
2007-12-15 01:52:23 +03:00
|
|
|
StmtIteratorBase::StmtIteratorBase(VariableArrayType* t)
|
2007-12-15 02:40:56 +03:00
|
|
|
: decl(NULL), 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 {
|
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
|
|
|
}
|
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
|
|
|
}
|