[cfe-dev] C++ Constructors & Destructors in the AST

Sebastian Redl sebastian.redl at getdesigned.at
Sun Apr 26 13:11:01 PDT 2009


Anders Carlsson wrote:
>
> 26 apr 2009 kl. 04.35 skrev Sebastian Redl:
>
>> Especially CXXExprWithCleanup has me stumped. How is it going to be
>> used? Where is it inserted into the AST? What does it mean?
>
> A CXXExprWithCleanup represents a full expression that creates
> temporaries that needs to have their destructors called.
>
> For example the example above,
>
> T();
>
> would look something like
>
> (CXXExprWithCleanup
>   (CXXTemporaryObjectExpr("temp", "T::T")
>   ("temp"))
>
> In the first design that we came up with, we would have explicit
> CXXDestroyExprs that would be inserted after statements, but that
> won't work with things like the for loop condition expr. I plan to
> remove the CXXDestroyExpr node.
>
> Does this sound OK? Maybe we should rename CXXExprWithCleanup to
> CXXExprWithTemporaries? I'll add some documentation shortly.
I like the design, and I like WithTemporaries better.

So basically, we give Sema a SmallVector of temporaries that we've
created. All statement actions check this buffer, and if it's not empty,
a CXXExprWithTemporaries is created and wrapped around the current
statement, and gets all the temporaries added. Then the buffer is cleared.
Is this right?

Still doesn't solve the issue of conditional creation, though.

Sebastian



More information about the cfe-dev mailing list