[cfe-commits] r55037 - in /cfe/trunk: include/clang/AST/DeclBase.h include/clang/AST/DeclObjC.h lib/AST/DeclBase.cpp lib/AST/DeclObjC.cpp lib/Sema/SemaDecl.cpp
Ted Kremenek
kremenek at apple.com
Tue Aug 19 20:26:34 PDT 2008
Author: kremenek
Date: Tue Aug 19 22:26:33 2008
New Revision: 55037
URL: http://llvm.org/viewvc/llvm-project?rev=55037&view=rev
Log:
Added ObjCAtDefsFieldDecl to represent FieldDecls created by @defs.
This fixes an ownership issue where FieldDecls could be owned both by an ObjCInterfaceDecl and a RecordDecl.
Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=55037&r1=55036&r2=55037&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Tue Aug 19 22:26:33 2008
@@ -45,6 +45,7 @@
Field,
CXXField,
ObjCIvar,
+ ObjCAtDefsField,
ObjCCategory,
ObjCCategoryImpl,
ObjCImplementation,
@@ -84,7 +85,7 @@
// For each non-leaf class, we now define a mapping to the first/last member
// of the class, to allow efficient classof.
NamedFirst = Field , NamedLast = ParmVar,
- FieldFirst = Field , FieldLast = ObjCIvar,
+ FieldFirst = Field , FieldLast = ObjCAtDefsField,
ScopedFirst = Namespace , ScopedLast = ParmVar,
TypeFirst = Typedef , TypeLast = CXXClass,
TagFirst = Enum , TagLast = CXXClass,
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=55037&r1=55036&r2=55037&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Tue Aug 19 22:26:33 2008
@@ -508,6 +508,26 @@
unsigned DeclAccess : 3;
};
+
+/// ObjCAtDefsFieldDecl - Represents a field declaration created by an
+/// @defs(...).
+class ObjCAtDefsFieldDecl : public FieldDecl {
+private:
+ ObjCAtDefsFieldDecl(SourceLocation L, IdentifierInfo *Id,
+ QualType T, Expr *BW)
+ : FieldDecl(ObjCAtDefsField, L, Id, T, BW) {}
+
+public:
+ static ObjCAtDefsFieldDecl *Create(ASTContext &C, SourceLocation L,
+ IdentifierInfo *Id, QualType T,
+ Expr *BW);
+
+ virtual void Destroy(ASTContext& C);
+
+ // Implement isa/cast/dyncast/etc.
+ static bool classof(const Decl *D) { return D->getKind() == ObjCAtDefsField; }
+ static bool classof(const ObjCAtDefsFieldDecl *D) { return true; }
+};
/// ObjCProtocolDecl - Represents a protocol declaration. ObjC protocols
/// declare a pure abstract type (i.e no instance variables are permitted).
Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=55037&r1=55036&r2=55037&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Tue Aug 19 22:26:33 2008
@@ -41,6 +41,7 @@
static unsigned nForwardProtocolDecls = 0;
static unsigned nCategoryDecls = 0;
static unsigned nIvarDecls = 0;
+static unsigned nAtDefsFieldDecls = 0;
static unsigned nObjCImplementationDecls = 0;
static unsigned nObjCCategoryImpl = 0;
static unsigned nObjCCompatibleAlias = 0;
@@ -91,7 +92,7 @@
int(nFuncs+nVars+nParmVars+nFieldDecls+nSUC+nCXXFieldDecls+nCXXSUC+
nEnumDecls+nEnumConst+nTypedef+nInterfaceDecls+nClassDecls+
nMethodDecls+nProtocolDecls+nCategoryDecls+nIvarDecls+
- nNamespaces));
+ nAtDefsFieldDecls+nNamespaces));
fprintf(stderr, " %d namespace decls, %d each (%d bytes)\n",
nNamespaces, (int)sizeof(NamespaceDecl),
int(nNamespaces*sizeof(NamespaceDecl)));
@@ -106,6 +107,9 @@
fprintf(stderr, " %d field decls, %d each (%d bytes)\n",
nFieldDecls, (int)sizeof(FieldDecl),
int(nFieldDecls*sizeof(FieldDecl)));
+ fprintf(stderr, " %d @defs generated field decls, %d each (%d bytes)\n",
+ nAtDefsFieldDecls, (int)sizeof(ObjCAtDefsFieldDecl),
+ int(nAtDefsFieldDecls*sizeof(ObjCAtDefsFieldDecl)));
fprintf(stderr, " %d struct/union/class decls, %d each (%d bytes)\n",
nSUC, (int)sizeof(RecordDecl),
int(nSUC*sizeof(RecordDecl)));
@@ -209,6 +213,7 @@
case ObjCForwardProtocol: nForwardProtocolDecls++; break;
case ObjCCategory: nCategoryDecls++; break;
case ObjCIvar: nIvarDecls++; break;
+ case ObjCAtDefsField: nAtDefsFieldDecls++; break;
case ObjCImplementation: nObjCImplementationDecls++; break;
case ObjCCategoryImpl: nObjCCategoryImpl++; break;
case ObjCCompatibleAlias: nObjCCompatibleAlias++; break;
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=55037&r1=55036&r2=55037&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Tue Aug 19 22:26:33 2008
@@ -94,6 +94,19 @@
return new (Mem) ObjCIvarDecl(L, Id, T, ac, BW);
}
+
+ObjCAtDefsFieldDecl
+*ObjCAtDefsFieldDecl::Create(ASTContext &C, SourceLocation L,
+ IdentifierInfo *Id, QualType T, Expr *BW) {
+ void *Mem = C.getAllocator().Allocate<ObjCAtDefsFieldDecl>();
+ return new (Mem) ObjCAtDefsFieldDecl(L, Id, T, BW);
+}
+
+void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) {
+ this->~ObjCAtDefsFieldDecl();
+ C.getAllocator().Deallocate((void *)this);
+}
+
ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C,
SourceLocation L,
IdentifierInfo *Id) {
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=55037&r1=55036&r2=55037&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Aug 19 22:26:33 2008
@@ -1794,11 +1794,21 @@
/// Collect the instance variables declared in an Objective-C object. Used in
/// the creation of structures from objects using the @defs directive.
-static void CollectIvars(ObjCInterfaceDecl *Class,
+static void CollectIvars(ObjCInterfaceDecl *Class, ASTContext& Ctx,
llvm::SmallVectorImpl<Sema::DeclTy*> &ivars) {
if (Class->getSuperClass())
- CollectIvars(Class->getSuperClass(), ivars);
- ivars.append(Class->ivar_begin(), Class->ivar_end());
+ CollectIvars(Class->getSuperClass(), Ctx, ivars);
+
+ // For each ivar, create a fresh ObjCAtDefsFieldDecl.
+ for (ObjCInterfaceDecl::ivar_iterator I=Class->ivar_begin(), E=Class->ivar_end();
+ I!=E; ++I) {
+
+ ObjCIvarDecl* ID = *I;
+ ivars.push_back(ObjCAtDefsFieldDecl::Create(Ctx, ID->getLocation(),
+ ID->getIdentifier(),
+ ID->getType(),
+ ID->getBitWidth()));
+ }
}
/// Called whenever @defs(ClassName) is encountered in the source. Inserts the
@@ -1813,7 +1823,7 @@
return;
}
// Collect the instance variables
- CollectIvars(Class, Decls);
+ CollectIvars(Class, Context, Decls);
}
QualType Sema::TryFixInvalidVariablyModifiedType(QualType T) {
More information about the cfe-commits
mailing list