trait for (ddoc)-comments

Alex Rønne Petersen alex at lycus.org
Mon Aug 20 18:42:24 PDT 2012


On 19-08-2012 14:26, David wrote:
> I want to get the (ddoc)-comment of a certain function/member/struct …
> so I can generate help-messages at compiletime, without the need to
> duplicate the comments. Like pythons function.__doc__ or class.__doc__
> etc. is there anything planed for D, e.g. __traits(getComment, foo.bar)?
>
> If not what do you think of it, I would love this addition.

I implemented this somewhat trivially, so you can do:

/**
  * Magic.
  */
void foo() {}

pragma(msg, __traits(getDdoc, foo));

But one problem that quickly ruins the usefulness of this is that Ddoc 
comments are only gathered when -D is passed to DMD (and therefore 
D_Ddoc is defined).

One way to solve this problem is to always gather doc comments 
unconditionally. This is not optimal, however, because a lot of code is 
written with the assumption that doc comments should only be present 
when D_Ddoc is defined, so in many libraries you'll see code that goes like:

version (D_Ddoc)
{
     /**
      * Magic.
      */
     void foo();
}
else
{
     void foo()
     {
     }
}

So, I don't know. It seems like a mess to get working properly.

-- 
Alex Rønne Petersen
alex at lycus.org
http://lycus.org


More information about the Digitalmars-d mailing list