[cfe-commits] r60883 - in /cfe/trunk: Driver/RewriteBlocks.cpp Driver/RewriteObjC.cpp include/clang/AST/Decl.h lib/AST/ASTContext.cpp lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CodeGenTypes.cpp
Douglas Gregor
dgregor at apple.com
Thu Dec 11 09:59:29 PST 2008
Author: dgregor
Date: Thu Dec 11 11:59:21 2008
New Revision: 60883
URL: http://llvm.org/viewvc/llvm-project?rev=60883&view=rev
Log:
Actually distinguish between RecordDecl::field_iterator and RecordDecl::field_const_iterator, propagating the constness down to the FieldDecls.
Modified:
cfe/trunk/Driver/RewriteBlocks.cpp
cfe/trunk/Driver/RewriteObjC.cpp
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
Modified: cfe/trunk/Driver/RewriteBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteBlocks.cpp?rev=60883&r1=60882&r2=60883&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteBlocks.cpp (original)
+++ cfe/trunk/Driver/RewriteBlocks.cpp Thu Dec 11 11:59:21 2008
@@ -1134,7 +1134,7 @@
}
if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
if (RD->isDefinition()) {
- for (RecordDecl::field_const_iterator i = RD->field_begin(),
+ for (RecordDecl::field_iterator i = RD->field_begin(),
e = RD->field_end(); i != e; ++i) {
FieldDecl *FD = *i;
if (isBlockPointerType(FD->getType()))
Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=60883&r1=60882&r2=60883&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Thu Dec 11 11:59:21 2008
@@ -4438,7 +4438,7 @@
}
if (RecordDecl *RD = dyn_cast<RecordDecl>(D)) {
if (RD->isDefinition()) {
- for (RecordDecl::field_const_iterator i = RD->field_begin(),
+ for (RecordDecl::field_iterator i = RD->field_begin(),
e = RD->field_end(); i != e; ++i) {
FieldDecl *FD = *i;
if (isBlockPointerType(FD->getType()))
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=60883&r1=60882&r2=60883&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Dec 11 11:59:21 2008
@@ -1002,8 +1002,11 @@
return cast_or_null<RecordDecl>(TagDecl::getDefinition(C));
}
- // Iterator access to field members.
- class field_iterator {
+ // Iterator access to field members. The field iterator only visits
+ // the non-static data members of this class, ignoring any static
+ // data members, functions, constructors, destructors, etc.
+ class field_const_iterator {
+ protected:
/// Current - Current position within the sequence of declarations
/// in this record.
DeclContext::decl_iterator Current;
@@ -1020,15 +1023,16 @@
}
public:
- typedef FieldDecl* value_type;
- typedef FieldDecl* reference;
- typedef FieldDecl* pointer;
+ typedef FieldDecl const * value_type;
+ typedef FieldDecl const * reference;
+ typedef FieldDecl const * pointer;
typedef std::ptrdiff_t difference_type;
typedef std::forward_iterator_tag iterator_category;
- field_iterator() : Current(), End() { }
+ field_const_iterator() : Current(), End() { }
- field_iterator(DeclContext::decl_iterator C, DeclContext::decl_iterator E)
+ field_const_iterator(DeclContext::decl_iterator C,
+ DeclContext::decl_iterator E)
: Current(C), End(E) {
SkipToNextField();
}
@@ -1037,36 +1041,71 @@
pointer operator->() const { return cast<FieldDecl>(*Current); }
- field_iterator& operator++() {
+ field_const_iterator& operator++() {
++Current;
SkipToNextField();
return *this;
}
- field_iterator operator++(int) {
- field_iterator tmp(*this);
+ field_const_iterator operator++(int) {
+ field_const_iterator tmp(*this);
++(*this);
return tmp;
}
- friend bool operator==(const field_iterator& x, const field_iterator& y) {
+ friend bool
+ operator==(const field_const_iterator& x, const field_const_iterator& y) {
return x.Current == y.Current;
}
- friend bool operator!=(const field_iterator& x, const field_iterator& y) {
+ friend bool
+ operator!=(const field_const_iterator& x, const field_const_iterator& y) {
return x.Current != y.Current;
}
};
- typedef field_iterator field_const_iterator;
+ class field_iterator : public field_const_iterator {
+ public:
+ typedef FieldDecl* value_type;
+ typedef FieldDecl* reference;
+ typedef FieldDecl* pointer;
+
+ field_iterator() : field_const_iterator() { }
+
+ field_iterator(DeclContext::decl_iterator C, DeclContext::decl_iterator E)
+ : field_const_iterator(C, E) { }
+
+ reference operator*() const { return cast<FieldDecl>(*Current); }
+
+ pointer operator->() const { return cast<FieldDecl>(*Current); }
+
+ field_iterator& operator++() {
+ ++Current;
+ SkipToNextField();
+ return *this;
+ }
+
+ field_iterator operator++(int) {
+ field_iterator tmp(*this);
+ ++(*this);
+ return tmp;
+ }
+ };
- field_iterator field_begin() const {
+ field_iterator field_begin() {
return field_iterator(decls_begin(), decls_end());
}
- field_iterator field_end() const {
+ field_iterator field_end() {
return field_iterator(decls_end(), decls_end());
}
+ field_const_iterator field_begin() const {
+ return field_const_iterator(decls_begin(), decls_end());
+ }
+ field_const_iterator field_end() const {
+ return field_const_iterator(decls_end(), decls_end());
+ }
+
/// completeDefinition - Notes that the definition of this type is
/// now complete.
void completeDefinition(ASTContext& C);
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=60883&r1=60882&r2=60883&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Dec 11 11:59:21 2008
@@ -553,8 +553,8 @@
// Layout each field, for now, just sequentially, respecting alignment. In
// the future, this will need to be tweakable by targets.
unsigned FieldIdx = 0;
- for (RecordDecl::field_iterator Field = D->field_begin(),
- FieldEnd = D->field_end();
+ for (RecordDecl::field_const_iterator Field = D->field_begin(),
+ FieldEnd = D->field_end();
Field != FieldEnd; (void)++Field, ++FieldIdx)
NewEntry->LayoutField(*Field, FieldIdx, IsUnion, StructPacking, *this);
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=60883&r1=60882&r2=60883&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Dec 11 11:59:21 2008
@@ -191,7 +191,7 @@
/// getOrCreateRecordType - get structure or union type.
llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty,
llvm::DICompileUnit Unit) {
- const RecordDecl *Decl = Ty->getDecl();
+ RecordDecl *Decl = Ty->getDecl();
unsigned Tag;
if (Decl->isStruct())
@@ -236,8 +236,9 @@
const ASTRecordLayout &RL = M->getContext().getASTRecordLayout(Decl);
unsigned FieldNo = 0;
- for (RecordDecl::field_const_iterator I = Decl->field_begin(),
- E = Decl->field_end(); I != E; ++I, ++FieldNo) {
+ for (RecordDecl::field_iterator I = Decl->field_begin(),
+ E = Decl->field_end();
+ I != E; ++I, ++FieldNo) {
FieldDecl *Field = *I;
llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=60883&r1=60882&r2=60883&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Thu Dec 11 11:59:21 2008
@@ -480,8 +480,8 @@
std::vector<const llvm::Type*> LLVMFields;
unsigned curField = 0;
- for (RecordDecl::field_iterator Field = RD.field_begin(),
- FieldEnd = RD.field_end();
+ for (RecordDecl::field_const_iterator Field = RD.field_begin(),
+ FieldEnd = RD.field_end();
Field != FieldEnd; ++Field) {
uint64_t offset = RL.getFieldOffset(curField);
const llvm::Type *Ty = CGT.ConvertTypeRecursive(Field->getType());
@@ -531,8 +531,8 @@
/// all fields are added.
void RecordOrganizer::layoutUnionFields(const ASTRecordLayout &RL) {
unsigned curField = 0;
- for (RecordDecl::field_iterator Field = RD.field_begin(),
- FieldEnd = RD.field_end();
+ for (RecordDecl::field_const_iterator Field = RD.field_begin(),
+ FieldEnd = RD.field_end();
Field != FieldEnd; ++Field) {
// The offset should usually be zero, but bitfields could be strange
uint64_t offset = RL.getFieldOffset(curField);
More information about the cfe-commits
mailing list