[cfe-dev] injecting a member function
Eric Niebler
eric at boostpro.com
Thu Feb 17 23:16:32 PST 2011
For my work on MS and Borland properties, I need to be able transform
post-inc and post-dec expressions like "obj.prop++" into some equivalent
expression that uses getter and setter methods. (Prefix ops are simple
because they don't require the creation of a temporary to store the
result of the expression.)
I'm thinking of approaching the problem like this: "obj.prop++" is
replaced with "obj.__builtin_postinc_Obj_Prop()", where that member is
generated on-demand and injected in the Obj class. The member would
essentially be:
PropTy Obj::__builtin_postinc_Obj_Prop() {
PropTy tmp = this->getProp();
this->setProp(tmp + 1);
return tmp;
}
Two questions:
1) Is this the correct approach? Or is there a simpler/easier way?
2) Is there any precedent in clang for this? I'm looking for code I can
crib from, or routines I could reuse.
Thanks in advance,
--
Eric Niebler
BoostPro Computing
http://www.boostpro.com
More information about the cfe-dev
mailing list