<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Feb 17, 2011, at 11:16 PM, Eric Niebler wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>For my work on MS and Borland properties, I need to be able transform<br>post-inc and post-dec expressions like "obj.prop++" into some equivalent<br>expression that uses getter and setter methods. (Prefix ops are simple<br>because they don't require the creation of a temporary to store the<br>result of the expression.)<br><br>I'm thinking of approaching the problem like this: "obj.prop++" is<br>replaced with "obj.__builtin_postinc_Obj_Prop()", where that member is<br>generated on-demand and injected in the Obj class. The member would<br>essentially be:<br><br>  PropTy Obj::__builtin_postinc_Obj_Prop() {<br>    PropTy tmp = this->getProp();<br>    this->setProp(tmp + 1);<br>    return tmp;<br>  }<br><br>Two questions:<br><br>1) Is this the correct approach? Or is there a simpler/easier way?<br>2) Is there any precedent in clang for this? I'm looking for code I can<br>crib from, or routines I could reuse.<br></div></blockquote><div><br></div>I think you want to make some sort of PropertyAccessOperator</div><div>expression.  It would work basically like BinaryConditionalOperator</div><div>does, which is to say, it would bind the result of an expression</div><div>(the base of the property) to an OpaqueValueExpr, then perform</div><div>an arbitrary expression using that.  For source fidelity, it would also</div><div>preserve the original member expression (and RHS, where applicable).</div><div><br></div><div>As a more concrete example, "obj.prop++" would look something like this:</div><div><br></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">  (PropertyAccessOperator int</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">    # The original operand, for source fidelity</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">    (MemberExpr int lvalue property</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">      (DeclRefExpr "obj" Obj lvalue))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">    # The opaque value expression</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">    (OpaqueValueExpr 0xabcdef Obj lvalue)</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">    # The expression whose result the OpaqueValueExpr will be bound to</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">    (DeclRefExpr "obj" Obj lvalue)</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">    # The expression to evaluate, expressed in terms of the OVE</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">    (CXXMemberCallExpr void</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">      (MemberExpr void(int) .setBase</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">        (OpaqueValueExpr 0xabcdef Obj lvalue))</span></font></div><div><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; ">      (CXXMemberCallExpr int</span></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">        (MemberExpr PropTy() .getBase</span></font></div><div><font class="Apple-style-span" face="Monaco" size="2"><span class="Apple-style-span" style="font-size: 10px;">          (OpaqueValueExpr 0xabcdef Obj lvalue)))))</span></font></div><div><br></div><div>Hmm.  Unfortunately, I'm not sure how to indicate what the result of the</div><div>operation should be.</div><div><br></div><div>John.</div></body></html>