[cfe-commits] r45047 - in /cfe/trunk: AST/Expr.cpp AST/StmtIterator.cpp include/clang/AST/StmtIterator.h
Ted Kremenek
kremenek at apple.com
Fri Dec 14 15:40:57 PST 2007
Author: kremenek
Date: Fri Dec 14 17:40:56 2007
New Revision: 45047
URL: http://llvm.org/viewvc/llvm-project?rev=45047&view=rev
Log:
Added "mode" to StmtIterator to record if the expression being iterated
over is the subexpression of a sizeof(expression). Different clients
will wish to handle iteration over such subexpressions differently, and can
now easily query if they are iterating over such statements using the
StmtIterator's inSizeOfExpr().
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/AST/StmtIterator.cpp
cfe/trunk/include/clang/AST/StmtIterator.h
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=45047&r1=45046&r2=45047&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Fri Dec 14 17:40:56 2007
@@ -1028,10 +1028,10 @@
// UnaryOperator
Stmt::child_iterator UnaryOperator::child_begin() {
- return reinterpret_cast<Stmt**>(&Val);
+ return child_iterator(reinterpret_cast<Stmt**>(&Val),Opc==SizeOf);
}
Stmt::child_iterator UnaryOperator::child_end() {
- return reinterpret_cast<Stmt**>(&Val)+1;
+ return child_iterator(reinterpret_cast<Stmt**>(&Val)+1,Opc==SizeOf);
}
// SizeOfAlignOfTypeExpr
Modified: cfe/trunk/AST/StmtIterator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtIterator.cpp?rev=45047&r1=45046&r2=45047&view=diff
==============================================================================
--- cfe/trunk/AST/StmtIterator.cpp (original)
+++ cfe/trunk/AST/StmtIterator.cpp Fri Dec 14 17:40:56 2007
@@ -49,7 +49,7 @@
}
void StmtIteratorBase::NextDecl(bool ImmediateAdvance) {
- assert (inDeclMode());
+ assert (inDecl());
assert (getVAPtr() == NULL);
assert (decl);
@@ -97,7 +97,7 @@
}
StmtIteratorBase::StmtIteratorBase(VariableArrayType* t)
-: decl(NULL), RawVAPtr(VASizeMode) {
+: decl(NULL), RawVAPtr(SizeOfTypeVAMode) {
RawVAPtr |= reinterpret_cast<uintptr_t>(t);
}
Modified: cfe/trunk/include/clang/AST/StmtIterator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtIterator.h?rev=45047&r1=45046&r2=45047&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtIterator.h (original)
+++ cfe/trunk/include/clang/AST/StmtIterator.h Fri Dec 14 17:40:56 2007
@@ -25,20 +25,30 @@
class StmtIteratorBase {
protected:
- enum { DeclMode = 0x1, VASizeMode = 0x2, Flags = 0x3 };
+ enum { DeclMode = 0x1, SizeOfTypeVAMode = 0x2,
+ SizeExprMode = 0x3, Flags = 0x3 };
+
union { Stmt** stmt; ScopedDecl* decl; };
uintptr_t RawVAPtr;
- bool inDeclMode() const { return RawVAPtr & DeclMode ? true : false; }
- bool inVASizeMode() const { return RawVAPtr & VASizeMode ? true : false; }
- bool hasFlags() const { return RawVAPtr & Flags ? true : false; }
+ bool inDecl() const {
+ return RawVAPtr & DeclMode ? true : false;
+ }
+
+ bool inSizeOfTypeVA() const {
+ return RawVAPtr & SizeOfTypeVAMode ? true : false;
+ }
+
+ bool inSizeOfExpr() const {
+ return RawVAPtr & SizeExprMode ? true : false;
+ }
VariableArrayType* getVAPtr() const {
return reinterpret_cast<VariableArrayType*>(RawVAPtr & ~Flags);
}
void setVAPtr(VariableArrayType* P) {
- assert (inDeclMode() || inVASizeMode());
+ assert (inDecl() || inSizeOfTypeVA());
RawVAPtr = reinterpret_cast<uintptr_t>(P) | (RawVAPtr & Flags);
}
@@ -47,7 +57,10 @@
Stmt*& GetDeclExpr() const;
- StmtIteratorBase(Stmt** s) : stmt(s), RawVAPtr(0) {}
+ StmtIteratorBase(Stmt** s, bool inSizeOfExpr) : stmt(s), RawVAPtr(0) {
+ if (inSizeOfExpr) RawVAPtr = SizeExprMode;
+ }
+
StmtIteratorBase(ScopedDecl* d);
StmtIteratorBase(VariableArrayType* t);
StmtIteratorBase() : stmt(NULL), RawVAPtr(0) {}
@@ -63,16 +76,16 @@
StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
public:
StmtIteratorImpl() {}
- StmtIteratorImpl(Stmt** s) : StmtIteratorBase(s) {}
+ StmtIteratorImpl(Stmt** s, bool inSizeOfExpr) : StmtIteratorBase(s,inSizeOfExpr){}
StmtIteratorImpl(ScopedDecl* d) : StmtIteratorBase(d) {}
StmtIteratorImpl(VariableArrayType* t) : StmtIteratorBase(t) {}
DERIVED& operator++() {
- if (inDeclMode()) {
+ if (inDecl()) {
if (getVAPtr()) NextVA();
else NextDecl();
}
- else if (inVASizeMode())
+ else if (inSizeOfTypeVA())
NextVA();
else
++stmt;
@@ -95,7 +108,7 @@
}
REFERENCE operator*() const {
- return (REFERENCE) (hasFlags() ? GetDeclExpr() : *stmt);
+ return (REFERENCE) (inDecl() || inSizeOfTypeVA() ? GetDeclExpr() : *stmt);
}
REFERENCE operator->() const { return operator*(); }
@@ -103,7 +116,10 @@
struct StmtIterator : public StmtIteratorImpl<StmtIterator,Stmt*&> {
explicit StmtIterator() : StmtIteratorImpl<StmtIterator,Stmt*&>() {}
- StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator,Stmt*&>(S) {}
+
+ StmtIterator(Stmt** S, bool inSizeOfExpr=false)
+ : StmtIteratorImpl<StmtIterator,Stmt*&>(S,inSizeOfExpr) {}
+
StmtIterator(VariableArrayType* t):StmtIteratorImpl<StmtIterator,Stmt*&>(t) {}
StmtIterator(ScopedDecl* D) : StmtIteratorImpl<StmtIterator,Stmt*&>(D) {}
};
More information about the cfe-commits
mailing list