[cfe-commits] r52059 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/AST/TranslationUnit.cpp
Ted Kremenek
kremenek at apple.com
Fri Jun 6 13:11:53 PDT 2008
Author: kremenek
Date: Fri Jun 6 15:11:53 2008
New Revision: 52059
URL: http://llvm.org/viewvc/llvm-project?rev=52059&view=rev
Log:
Implement "Destroy" and destructor for ObjCClassDecl, allowing us to reclaim its memory and the memory of the Decls it owns.
Modified:
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/AST/TranslationUnit.cpp
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=52059&r1=52058&r2=52059&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Jun 6 15:11:53 2008
@@ -646,7 +646,14 @@
}
NumForwardDecls = nElts;
}
+
+ virtual ~ObjCClassDecl();
+
public:
+
+ /// Destroy - Call destructors and release memory.
+ virtual void Destroy(ASTContext& C);
+
static ObjCClassDecl *Create(ASTContext &C, SourceLocation L,
ObjCInterfaceDecl **Elts, unsigned nElts);
@@ -657,6 +664,10 @@
ObjCInterfaceDecl** getForwardDecls() const { return ForwardDecls; }
int getNumForwardDecls() const { return NumForwardDecls; }
+ typedef ObjCInterfaceDecl * const * iterator;
+ iterator begin() const { return ForwardDecls; }
+ iterator end() const { return ForwardDecls+NumForwardDecls; }
+
static bool classof(const Decl *D) { return D->getKind() == ObjCClass; }
static bool classof(const ObjCClassDecl *D) { return true; }
};
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=52059&r1=52058&r2=52059&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Jun 6 15:11:53 2008
@@ -134,6 +134,23 @@
return new (Mem) ObjCClassDecl(L, Elts, nElts);
}
+ObjCClassDecl::~ObjCClassDecl() {
+ delete [] ForwardDecls;
+}
+
+void ObjCClassDecl::Destroy(ASTContext& C) {
+
+ // FIXME: There is no clear ownership policy now for referenced
+ // ObjCInterfaceDecls. Some of them can be forward declarations that
+ // are never later defined (in which case the ObjCClassDecl owns them)
+ // or the ObjCInterfaceDecl later becomes a real definition later. Ideally
+ // we should have separate objects for forward declarations and definitions,
+ // obviating this problem. Because of this situation, referenced
+ // ObjCInterfaceDecls are destroyed in ~TranslationUnit.
+
+ Decl::Destroy(C);
+}
+
ObjCForwardProtocolDecl *
ObjCForwardProtocolDecl::Create(ASTContext &C,
SourceLocation L,
Modified: cfe/trunk/lib/AST/TranslationUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TranslationUnit.cpp?rev=52059&r1=52058&r2=52059&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TranslationUnit.cpp (original)
+++ cfe/trunk/lib/AST/TranslationUnit.cpp Fri Jun 6 15:11:53 2008
@@ -57,13 +57,28 @@
// eventually be fixed when the ownership of ObjCPropertyDecls gets
// cleaned up.
if (ObjCProtocolDecl* PDecl = dyn_cast<ObjCProtocolDecl>(*I))
- for (ObjCInterfaceDecl::classprop_iterator PD=PDecl->classprop_begin(),
- ED=PDecl->classprop_end(); PD!=ED; ++PD) {
- if (!*PD || Killed.count(*PD)) continue;
- Killed.insert(*PD);
- (*PD)->Destroy(*Context);
+ for (ObjCProtocolDecl::classprop_iterator ID=PDecl->classprop_begin(),
+ ED=PDecl->classprop_end(); ID!=ED; ++ID) {
+ if (!*ID || Killed.count(*ID)) continue;
+ Killed.insert(*ID);
+ (*ID)->Destroy(*Context);
}
-
+
+ // FIXME: There is no clear ownership policy now for ObjCInterfaceDecls
+ // referenced by ObjCClassDecls. Some of them can be forward decls that
+ // are never later defined (in which case the ObjCClassDecl owns them)
+ // or the ObjCInterfaceDecl later becomes a real definition later.
+ // Ideally we should have separate objects for forward declarations and
+ // definitions, obviating this problem. Because of this situation,
+ // referenced ObjCInterfaceDecls are destroyed here.
+ if (ObjCClassDecl* CDecl = dyn_cast<ObjCClassDecl>(*I))
+ for (ObjCClassDecl::iterator ID=CDecl->begin(),
+ ED=CDecl->end(); ID!=ED; ++ID) {
+ if (!*ID || Killed.count(*ID)) continue;
+ Killed.insert(*ID);
+ (*ID)->Destroy(*Context);
+ }
+
(*I)->Destroy(*Context);
}
}
More information about the cfe-commits
mailing list