[Reflex] Adding support for attributes

From: Jean-Francois Bastien <jfbastien_at_cae.com>
Date: Tue, 22 Jan 2008 12:22:23 -0500


Good morning,  

Please redirect me if roottalk isn't the proper place for Reflex discussions.  

I'm currently investigating using Reflex and it seems very promising aside from a few bugs for which I've submitted patches on Savannah. I'd like to use Reflex for its introspection abilities, but I'd also like to use it to add user metadata similarly to C# attributes and custom attributes: http://msdn2.microsoft.com/en-us/library/z0w1kczw.aspx

This feature isn't currently available in Reflex but I'd like to develop it and contribute it to Reflex. Before I modify anything, though, I'd like to have Reflex users' input on this. What follows is an explanation of what I want with reasons for the design choices I'd take.

The goal is to allow developers to extend and annotate their API and allow querying of these annotations through Reflex. A few use cases for attributes are:

Reflex already has what it calls properties. They're pretty close to doing what I want: they're tagged to a type and its subtypes (not to a type's instance), but they're only automatically extracted when the --comments or --iocomments option is specified and the only properties added are end of line comments. I think the runtime Reflex library itself therefore fully supports what I want, it's just the genreflex Python scripts that don't.

An option would be to use GCC's __attribute__: http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html GCC XML supports it:
http://www.gccxml.org/HTML/Running.html
It would be a question of defining a macro like: #define METADATA(...) __attribute__((gccxml(__VA_ARGS__))) Only when __GCCXML__ is defined, and then having the genreflex Python script do an addProperty after having parsed the "attributes" attribute from the generated XML file. I'm not very happy with this solution, though:

What I would instead do is fairly similar to what's currently done for properties that are extracted from comments: If the --attributes flag is passed to genreflex then I'd parse the lines of code around the current declaration and extract the attributes from them.

I would use a syntax that closely matches that of C# but I would surround or precede the square braces in comments (so it remains valid C++ and doesn't use a macro). Here is an example of what I'd like to be able to do (it's open to discussion, of course):

//[DisplayName("Meaningless Class"), Guid("12345678-1234-1234-1234-123456789abc")] //[AnotherAttribute("some value")]
class Foo
{
public:
  Foo();
  virtual ~Foo();

  //[Slot]
  void setValue(SignalSlotValues iValue);   //[Signal]
  void valueChanged(SignalSlotValues iValue);

  //[DisplayName("Valid signal/slot values")]   enum SignalSlotValues
  {
    eFoo1
  , eFoo2
  , eFoo3
  };

  void doSomething( /*[in]*/ Bar iFoo, /*[out]*/ Bar * oFoo);

private:
  //[DisplayName("Signal/slot value")]
  SignalSlotValues mValue;
};

This closely matches what C# does but differs in that:

I'd like to know what Reflex users and maintainers think of this. It shouldn't be long to develop but I'd like it to be designed properly and be in the official Reflex distribution.  

Jean-François Bastien Received on Tue Jan 22 2008 - 18:22:47 CET

This archive was generated by hypermail 2.2.0 : Tue Jan 22 2008 - 23:50:01 CET