Property rewriting; I feel it's important. Is there still time?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Mar 10 08:48:00 PST 2010


On 03/10/2010 08:42 AM, Andrei Alexandrescu wrote:
> On 03/09/2010 09:48 PM, Chad J wrote:
>> I speak of the property rewriting where an expression like
>>
>> foo.prop++;
>>
>> is rewritten as
>>
>> auto t = foo.prop();
>> t++;
>> foo.prop(t);
>
> This particular example has a number of issues. First off you need to
> rewrite expressions, not statements. Consider:
>
> auto x = foo.prop++;
>
> You'd need to assign to x the old value of foo.prop. So one correct
> rewrite is
>
> foo.prop++
>
> into
>
> {auto t = foo.prop; auto t1 = t; ++t1; foo.prop = t1; return t;}()
>
> within an rvalue context, and into:
>
> {auto t = foo.prop; ++t; foo.prop = t; return t;}()
>
> within a void context.

The latter should be:

{auto t = foo.prop; ++t; foo.prop = t;}()

because there's no need to return a value.


Andrei



More information about the Digitalmars-d mailing list