[cfe-dev] [clang] declspec(property...) advice

Eric Niebler eric at boostpro.com
Wed Dec 8 09:56:26 PST 2010


I'm currently working on getting the front-end to eat Microsoft's
__declspec(property...) extension.

http://msdn.microsoft.com/en-us/library/yhfk0thd%28v=VS.100%29.aspx

I've gotten things to the point where I can parse it and generate a
PropertyAttr attached to the FieldDecl. The PropertyAttr has two string
attributes representing the name of the getter and setter member
functions. I am wondering if this is the best way to represent this in
the AST. My impression of how the feature is used is that expressions
are rewritten:

  "a = x.foo"  becomes  "a = x.getFoo()"
  "x.foo = a"  becomes  "x.setFoo(a)"
  "x.foo += 1" becomes  "x.setFoo(x.getFoo() + 1)"

Also, when generating the layout for the class and the
constructors/destructors/assign methods, these pseudo-fields should be
ignored. These are all non-trivial rewrites. A few questions:

1) In your opinion, is having a normal FieldDecl in the AST with an
attribute the way to go? Or should there be an entirely different kind
of Decl for these pseudo-fields?

2) If the attribute is the right approach, is storing the getters and
setters as strings sensible? FWIW, Microsoft doesn't catch typos in the
getter/setter declaration until the property is actually referenced,
which seems to suggest that its doing a fairly primitive rewrite at the
point of use. So strings would work, IIUC. It does not eagerly perform
name lookup of the getters and setters within the class definition.

3) Where should the rewrite happen? Is it OK to leave in references to
the pseudo-field in the AST, or should the AST reflect what will
actually be executed -- invocations of the getters and setters? My
instinct tells me that the AST should have the pseudo-field, not the
getters and setters. Anything else might confuse things like IDEs.

Thanks in advance,

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com



More information about the cfe-dev mailing list