[cfe-dev] destroy() information?

Chris Lattner clattner at apple.com
Mon Apr 7 23:34:24 PDT 2008


On Apr 7, 2008, at 4:01 PM, Sam Bishop wrote:

> Chris,
>
> Chris Lattner wrote:
>> Eventually we want to use Decl->destroy(ASTContext&) instead of
>> calling delete directly.  This was the second half of the
>> "Creatification" patch that I haven't gotten to yet.
>
> I'd like to implement this, if wouldn't mind giving me some pointers  
> on
> how you'd like it done.

Cool!   I was thinking of something sleazy like a non-virtual, const  
Destroy method in Decl.  Something like this:


void Decl::Destroy(ASTContext &C) const {
   switch (getKind()) {
   case FieldDecl:  cast<FieldDecl>(this)->~FieldDecl(); break;
   ... one case for each concrete Decl class ...
   }

   C.getAllocator().Delete(this);
}

and then make the Decl destructors private or protected, so they can't  
be directly called by clients.

What do you think?  Incidentally, things like this are very  
mechanical: maybe we should have a DeclNodes.def file like  
StmtNodes.def to automate it?

-Chris





More information about the cfe-dev mailing list