[cfe-dev] C++ Constructors & Destructors in the AST
Anders Carlsson
andersca at me.com
Sun Apr 26 13:41:38 PDT 2009
26 apr 2009 kl. 13.11 skrev Sebastian Redl:
> 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.
>
Cool, I'll change that!
> 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?
>
Sort of - You will have to do this check before you call the statement
action, because
statements can take more than one expression (like for statements).
I'm working on a design that involves something like
/// ActOnFinishFullExpr - Called whenever a full expression has
been parsed.
/// (C++ [intro.execution]p12.
virtual OwningExprResult ActOnFinishFullExpr(ExprArg Expr) {
return move(Expr);
}
where a client can return a new expr when a full expr is being created.
We also need to come up with a solid design where it's next to
impossible to forget to
have this callback invoked, I'm toying with the idea of adding a new
FullExprArg type,
and where the only way to create a FullExprArg from an ExprArg is to
go through this callback.
Anders
More information about the cfe-dev
mailing list