[cfe-dev] question about OpaqueValueExpr (was: injecting a member function)

John McCall rjmccall at apple.com
Tue Feb 22 09:46:13 PST 2011


On Feb 22, 2011, at 1:37 AM, Eric Niebler wrote:
> On 2/19/2011 1:18 AM, John McCall wrote:
>> On Feb 18, 2011, at 1:49 AM, Eric Niebler wrote:
>>> On 2/18/2011 3:41 PM, John McCall wrote:
>>>> let tmp = obj in
>>>> tmp.setProp(tmp.getProp() + 1)
>>> 
>>> In practical terms, that means that, when evaluating tmp, evaluate obj
>>> (once), and thereafter all other times tmp is evaluated, just use the
>>> result already computed. And this Just Works wrt lvalues and rvalues.
>> 
>> Right.  When creating the OVE, you give it a type, value kind, and
>> value object kind matching the expression it gets bound to.
> 
> Here's a question. What if I create a OpaqueValueExpr, and I want it to
> be an lvalue (so I can mutate it in place), but the expression it gets
> bound to is actually an rvalue? Will that work? Or can I cast an rvalue
> to an lvalue somehow and bind the OVE to that?

OVEs need to match their underlying values perfectly, including in value kind.

> The reason I ask is because I want this:
> 
>  a.b += 42
> 
> to be rewritten as:
> 
>  let tmp = a
>  in tmp.set(tmp.get() += 42)
> 
> tmp.get() will (probably) be an rvalue, but for feature parity with MS,
> I need to use += instead of the (obvious and simpler) +.

Does this really need to be "tmp.set(tmp.get() += 42)"?  I would expect it
to just be "tmp.get() += 42" if tmp.get() happens to yield an lvalue.

Regardless, you need to be testing for this and building different ASTs
around it rather than trying to force invalid ASTs.

John.



More information about the cfe-dev mailing list