<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Dec 29, 2012, at 1:03 AM, Francois Pichet <<a href="mailto:pichet2000@gmail.com">pichet2000@gmail.com</a>> wrote:</div><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Dec 22, 2012 at 10:11 AM, <a href="mailto:endlessroad1991@gmail.com">endlessroad1991@gmail.com</a> <span dir="ltr"><<a href="mailto:endlessroad1991@gmail.com" target="_blank">endlessroad1991@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Some guy from PathScale told me that AMP headers doesn't contain subscriptable property. And I looked at ATL headers, neither do they. So for these purposed, subscriptable property is not necessary.<div>
And I still think that subscriptable property is kind of messy...</div>
<div>So I only implement non-subscriptable property.</div><div><br></div><div>Brief:</div><div>- Add a MSPropertyDecl, parallel to FieldDecl. Now property is separated from Field.</div><div>- Add a MSPropertyRefExpr. It seems to be necessary, because we can't just create a PseudoObjectExpr.</div>

<div><br></div><div>Current status:</div><div>- Non-subscriptable property only.</div><div>- Property can be inherited.</div><div>- Get, Set, =, +=/-=/..., ++/-- works correctly.</div><div>- Property type can be incomplete type, as function return type.</div>

<div><br></div><div>Patch, and a "difficult" testcase attached.</div><div>I'm quite happy with this version, because it's much simpler and cleaner.</div><div>John - Thank you very much, for the MSPropertyDecl and PseudoObjectExpr tips. They are really crucial to this patch.</div>
</blockquote><div><div><br></div><div><br></div><div>More comments:</div><div><br></div><div>+  NamedDecl *NewFD;</div><div>+  AttributeList *MSPropertyAttr = 0;</div><div>+  for (auto it = D.getDeclSpec().getAttributes().getList();</div>
<div>+       it != 0; it = it->getNext())</div><div>+    if (it->getName()->getName() == "property") {</div><div>+      MSPropertyAttr = it;</div><div>+      break;</div><div>+    }</div><div>+  if (MSPropertyAttr) {</div>
<div>+    llvm::StringRef GetterName = MSPropertyAttr->getScopeName() ?</div><div>+      MSPropertyAttr->getScopeName()->getName() : StringRef();</div><div>+    llvm::StringRef SetterName = MSPropertyAttr->getParameterName() ?</div>
<div>+      MSPropertyAttr->getParameterName()->getName() : StringRef();</div><div>+    NewFD = new (Context) MSPropertyDecl(Decl::MSProperty, Record, Loc,</div><div>+                                         II, T, TInfo, TSSL,</div>
<div>+                                         GetterName, SetterName);</div><div>+    NewFD->setAccess(AS);</div><div>+  } else {</div><div>+    NewFD = CheckFieldDecl(II, T, TInfo, Record, Loc, Mutable, BitWidth,</div>
<div>+                           InitStyle, TSSL, AS, PrevDecl, &D);</div><div>+  }</div><div><br></div><div>I think this code should be in Sema::ActOnCXXMemberDeclarator and not in Sema::HandleField. A property is not a field and HandleField should continue to return a FieldDecl*. </div>
<div><br></div><div>Also you need to protect this code with Sema.getOptions().MicrosoftExt</div><div><br></div><div> </div><div><div>+static ExprResult</div><div>+BuildMSPropertyRefExpr(ASTContext &Context, Expr *BaseExpr, bool IsArrow,</div>
<div>+                       const DeclarationNameInfo &MemberNameInfo,</div><div>+                       MSPropertyDecl *PD) {</div><div>+  return new (Context) MSPropertyRefExpr(BaseExpr, PD, IsArrow,</div><div>+                                         Context.PseudoObjectTy, VK_LValue,</div>
<div><br></div><div>The type of the expression should be PD->getType() and not Context.PseudoObjectTy.</div><div>Otherwise you won't be able to use a MSPropertyRefExpr in the context of a larger expression.</div></div></div></div></div></div></blockquote><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div><div>
<br></div><div>For example:</div><div><div>class C {</div><div>public:</div><div>  int operator[](int i){ return i;}</div><div>};</div><div><br></div><div>struct S {</div><div>   C v;</div><div>   C getprop() { return v; }</div>
<div>   __declspec(property(get = getprop)) C the_prop;</div><div>};</div><div>int main()</div><div>{</div><div>   S s;</div><div>   int a = s.the_prop[3];</div><div>  printf("%d", a);</div><div>}</div><div>this must print 3.</div>
<div><br></div><div>This is *not* a property indexer. The result of the MSPropertyRefExpr expression must be class C to allow for the operator[] to be used. C++ AMP which use ms property extensively will contains code like that.</div></div></div></div></div></div></div></blockquote><div><br></div></div>No, it is correct for the expression to have pseudo-object type here.  In most contexts, expressions of pseudo-object type automatically undergo lvalue-to-rvalue conversion before any further analysis is performed.  The subscript-expression code will have to be modified to specially check for possible property indexers when the base has pseudo-object type, and (if so) propagate the pseudo-object type "outwards".<br><div><br></div><div>John.</div></body></html>