[cfe-commits] r52050 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Parse/ParseObjc.cpp

Ted Kremenek kremenek at apple.com
Fri Jun 6 09:45:15 PDT 2008


Author: kremenek
Date: Fri Jun  6 11:45:15 2008
New Revision: 52050

URL: http://llvm.org/viewvc/llvm-project?rev=52050&view=rev
Log:
Initial work on additional memory collection for ObjC AST objects.  We now
have Destroy methods of ObjcMethodDecl and ObjCInterfaceDecl which recursively
destroy their owned Decls and Stmts.  There are a few cases where it is not
clear what to do (FIXMEs included in the patch).

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Parse/ParseObjc.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=52050&r1=52049&r2=52050&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Jun  6 11:45:15 2008
@@ -109,8 +109,12 @@
     SelName(SelInfo), MethodDeclType(T), 
     ParamInfo(0), NumMethodParams(0),
     MethodAttrs(M), EndLoc(endLoc), Body(0), SelfDecl(0) {}
+
   ~ObjCMethodDecl();
 public:
+  
+  /// Destroy - Call destructors and release memory.
+  virtual void Destroy(ASTContext& C);
 
   static ObjCMethodDecl *Create(ASTContext &C,
                                 SourceLocation beginLoc, 
@@ -262,8 +266,14 @@
       ClassLoc(CLoc) {
         AllocIntfRefProtocols(numRefProtos);
       }
+  
+  ~ObjCInterfaceDecl();
+  
 public:
 
+  /// Destroy - Call destructors and release memory.
+  virtual void Destroy(ASTContext& C);
+
   static ObjCInterfaceDecl *Create(ASTContext &C,
                                    SourceLocation atLoc,
                                    unsigned numRefProtos, 

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=52050&r1=52049&r2=52050&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Jun  6 11:45:15 2008
@@ -35,6 +35,21 @@
                                   isVariadic, isSynthesized, impControl);
 }
 
+ObjCMethodDecl::~ObjCMethodDecl() {  
+  delete [] ParamInfo;
+  //delete [] MethodAttrs;  // FIXME: Also destroy the stored Expr*.
+}
+
+void ObjCMethodDecl::Destroy(ASTContext& C) {
+  if (Body) Body->Destroy(C);
+  if (SelfDecl) SelfDecl->Destroy(C);
+  
+  for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
+    if (*I) (*I)->Destroy(C);
+  
+  Decl::Destroy(C);
+}
+
 ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
                                              SourceLocation atLoc,
                                              unsigned numRefProtos,
@@ -47,6 +62,34 @@
                                      isInternal);
 }
 
+ObjCInterfaceDecl::~ObjCInterfaceDecl() {
+  delete [] Ivars;
+  delete [] InstanceMethods;
+  delete [] ClassMethods;
+  delete [] PropertyDecl;
+  // FIXME: CategoryList?
+}
+
+void ObjCInterfaceDecl::Destroy(ASTContext& C) {  
+  for (ivar_iterator I=ivar_begin(), E=ivar_end(); I!=E; ++I)
+    if (*I) (*I)->Destroy(C);
+  
+  for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I!=E; ++I)
+    if (*I) (*I)->Destroy(C);
+  
+  for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I!=E; ++I)
+    if (*I) (*I)->Destroy(C);
+  
+  // FIXME: Cannot destroy properties right now because the properties of
+  //  both the super class and this class are in this array.  This can
+  //  cause double-deletions.
+  //for (classprop_iterator I=classprop_begin(), E=classprop_end(); I!=E; ++I)
+//    if (*I) (*I)->Destroy(C);
+//  
+  Decl::Destroy(C);
+}
+
+
 ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L,
                                    IdentifierInfo *Id, QualType T) {
   void *Mem = C.getAllocator().Allocate<ObjCIvarDecl>();
@@ -135,10 +178,6 @@
   }
 }
 
-ObjCMethodDecl::~ObjCMethodDecl() {
-  delete[] ParamInfo;
-}
-
 /// FindPropertyDeclaration - Finds declaration of the property given its name
 /// in 'PropertyId' and returns it. It returns 0, if not found.
 ///

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=52050&r1=52049&r2=52050&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Fri Jun  6 11:45:15 2008
@@ -224,7 +224,7 @@
 ///
 void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
                                         tok::ObjCKeywordKind contextKey) {
-  llvm::SmallVector<DeclTy*, 32>  allMethods;
+  llvm::SmallVector<DeclTy*, 32> allMethods;
   llvm::SmallVector<DeclTy*, 16> allProperties;
   tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword;
   SourceLocation AtEndLoc;
@@ -314,8 +314,11 @@
     }
   }
   /// Insert collected methods declarations into the @interface object.
-  Actions.ActOnAtEnd(AtEndLoc, interfaceDecl, &allMethods[0], allMethods.size(), 
-                     &allProperties[0], allProperties.size());
+  Actions.ActOnAtEnd(AtEndLoc, interfaceDecl,
+                     allMethods.empty() ? 0 : &allMethods[0],
+                     allMethods.size(), 
+                     allProperties.empty() ? 0 : &allProperties[0],
+                     allProperties.size());
 }
 
 ///   Parse property attribute declarations.





More information about the cfe-commits mailing list