[cfe-dev] [RFC] Preliminary patch to support MSVC __declspec(property)
Francois Pichet
pichet2000 at gmail.com
Sat Dec 29 01:03:49 PST 2012
On Sat, Dec 22, 2012 at 10:11 AM, endlessroad1991 at gmail.com <
endlessroad1991 at gmail.com> wrote:
> 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.
> And I still think that subscriptable property is kind of messy...
> So I only implement non-subscriptable property.
>
> Brief:
> - Add a MSPropertyDecl, parallel to FieldDecl. Now property is separated
> from Field.
> - Add a MSPropertyRefExpr. It seems to be necessary, because we can't just
> create a PseudoObjectExpr.
>
> Current status:
> - Non-subscriptable property only.
> - Property can be inherited.
> - Get, Set, =, +=/-=/..., ++/-- works correctly.
> - Property type can be incomplete type, as function return type.
>
> Patch, and a "difficult" testcase attached.
> I'm quite happy with this version, because it's much simpler and cleaner.
> John - Thank you very much, for the MSPropertyDecl and PseudoObjectExpr
> tips. They are really crucial to this patch.
>
More comments:
+ NamedDecl *NewFD;
+ AttributeList *MSPropertyAttr = 0;
+ for (auto it = D.getDeclSpec().getAttributes().getList();
+ it != 0; it = it->getNext())
+ if (it->getName()->getName() == "property") {
+ MSPropertyAttr = it;
+ break;
+ }
+ if (MSPropertyAttr) {
+ llvm::StringRef GetterName = MSPropertyAttr->getScopeName() ?
+ MSPropertyAttr->getScopeName()->getName() : StringRef();
+ llvm::StringRef SetterName = MSPropertyAttr->getParameterName() ?
+ MSPropertyAttr->getParameterName()->getName() : StringRef();
+ NewFD = new (Context) MSPropertyDecl(Decl::MSProperty, Record, Loc,
+ II, T, TInfo, TSSL,
+ GetterName, SetterName);
+ NewFD->setAccess(AS);
+ } else {
+ NewFD = CheckFieldDecl(II, T, TInfo, Record, Loc, Mutable, BitWidth,
+ InitStyle, TSSL, AS, PrevDecl, &D);
+ }
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*.
Also you need to protect this code with Sema.getOptions().MicrosoftExt
+static ExprResult
+BuildMSPropertyRefExpr(ASTContext &Context, Expr *BaseExpr, bool IsArrow,
+ const DeclarationNameInfo &MemberNameInfo,
+ MSPropertyDecl *PD) {
+ return new (Context) MSPropertyRefExpr(BaseExpr, PD, IsArrow,
+ Context.PseudoObjectTy, VK_LValue,
The type of the expression should be PD->getType() and not
Context.PseudoObjectTy.
Otherwise you won't be able to use a MSPropertyRefExpr in the context of a
larger expression.
For example:
class C {
public:
int operator[](int i){ return i;}
};
struct S {
C v;
C getprop() { return v; }
__declspec(property(get = getprop)) C the_prop;
};
int main()
{
S s;
int a = s.the_prop[3];
printf("%d", a);
}
this must print 3.
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121229/4ce53b89/attachment.html>
More information about the cfe-dev
mailing list