Try to plug some memory leaks...

1) Sema::ParseAST now constructs a TranslationUnit object to own the top-level Decls, which releases the top-level Decls upon exiting ParseAST.

2) Bug fix: TranslationUnit::~TranslationUnit handles the case where a Decl is added more than once as a top-level Decl.

3) Decl::Destroy is now a virtual method, obviating the need for a special dispatch based on DeclKind.

3) FunctionDecl::Destroy now releases its Body using its Destroy method.

4) Added Stmt::Destroy and Stmt::DestroyChildren, which recursively delete the child ASTs of a Stmt and call their dstors.  We may need to special case dstor/Destroy methods for particular Stmt subclasses that own other dynamically allocated objects besides AST nodes.

5) REGRESSION: We temporarily are not deallocating attributes; a FIXME is provided.

llvm-svn: 51286
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index f346be8..af981d9 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -403,11 +403,13 @@
       IsInline(isInline), IsImplicit(0), PreviousDeclaration(0) {}
 
   virtual ~FunctionDecl();
+  virtual void Destroy(ASTContext& C);
+
 public:
   static FunctionDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
                               IdentifierInfo *Id, QualType T, 
                               StorageClass S = None, bool isInline = false, 
-                              ScopedDecl *PrevDecl = 0);
+                              ScopedDecl *PrevDecl = 0);  
   
   /// getBody - Retrieve the body (definition) of the function. The
   /// function body might be in any of the (re-)declarations of this
@@ -488,7 +490,6 @@
   static FunctionDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
   
   friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
-  friend void Decl::Destroy(ASTContext& C) const;
 };
 
 
@@ -540,7 +541,8 @@
                    IdentifierInfo *Id, QualType T, Expr *E,
                    const llvm::APSInt &V, ScopedDecl *PrevDecl)
     : ValueDecl(EnumConstant, DC, L, Id, T, PrevDecl), Init(E), Val(V) {}
-  ~EnumConstantDecl() {}
+
+  virtual ~EnumConstantDecl() {}
 public:
 
   static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
@@ -569,7 +571,6 @@
   static EnumConstantDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
   
   friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
-  friend void Decl::Destroy(ASTContext& C) const;
 };
 
 
@@ -600,7 +601,8 @@
   TypedefDecl(DeclContext *DC, SourceLocation L,
               IdentifierInfo *Id, QualType T, ScopedDecl *PD) 
     : TypeDecl(Typedef, DC, L, Id, PD), UnderlyingType(T) {}
-  ~TypedefDecl() {}
+
+  virtual ~TypedefDecl() {}
 public:
   
   static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
@@ -622,7 +624,7 @@
   static TypedefDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
   
   friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
-  friend void Decl::Destroy(ASTContext& C) const;
+  
 };