Hey,
Reviving this stale thread. Sorry in advance for the lengthy email.
On 23:06:51 2019-01-24, Jani Nikula wrote:
On Wed, 23 Jan 2019, Jani Nikula <jani@xxxxxxxxxx> wrote:
On Wed, 23 Jan 2019, Bruno Santos <brunomanuelsantos@xxxxxxxxxxxxxxxxxx>
wrote:
On 20:37:19 2019-01-23, Jani Nikula wrote:
FWIW, in general, this is my rough list of priorities:
- Handle bog standard most common use cases.
- Implementation simplicity. If there's an edge case that requires a
fair amount of code or complexity, ignore it. In particular, if
there's a reasonable workaround.
- Principle of least surprise. What would the user mean to document?
Agree up to here...
- Doxygen/Javadoc/etc. compatibility.
This I think it's more of a /nice to have/, the same way we're not
putting particular emphasis on supporting additional syntaxes and all
that it entails.
With that said, this patch's behaviour is different from Doxygen, but
only in that Doxygen output is broken in the highlighted case.
We're in agreement here I think. Definitely no focus on any additional
or alternative syntaxes. More like, given more than one way to do
something, and all else being equal, follow what others did. And if
others do something stupid, opt for the sane choice instead.
I'd like Hawkmoth to offer a simple and straighforward alternative to
e.g. Doxygen+Breathe, and when simple is not enough, I won't hesitate to
recommend people to go for the more complicated alternatives. But the
basics need to be familiar enough.
For example, having both the tokenizer and AST passes is extra
complexity, but it's required to properly handle /** style comments and
to document macros.
As to this specific patch, there's something that feels a bit too quirky
now. I think one of the things you've overlooked is
cursor.is_anonymous(), which will make things quite a bit nicer. I'll
try to look at other things that we could get directly from clang,
particularly for avoiding the split/join on the cursor.type.spelling.
It's possible, but I tried cursor.is_anonymous before settling on an
ugly string search. I didn't follow it through to the C code, but I
suspect this means something quite different or at least it's broken for
me.
Clang does give the type a name, but it's a long string including the
path, filename and line of the declaration with the words 'anonymous
structure' or something. Not something I'd like to see in the
documentation to be honest, hence the replacement for '<anonymous>'.
FYI, I just retested it, and I can't get is_anonymous to do what I would
expect it to. Maybe an issue with my build only?
I'll need to play with this when I have the time. Now that the parser is
in a better shape, it's actually possible to do so!
Okay, it doesn't work.
However, cursor.spelling is always None for unnamed structs, unions and
enums.
I was able to make the simple case of anonymous enums work the way I
want. Patch below, against current master. However, that doesn't handle
variable definitions, and it breaks typedefs.
And the typedefs are another can of worms, both for enums and
structs/unions, and somewhat broken in current master already.
Typedefs of anonymous structs work as expected (without the patch at the
end):
/** documents type_t */
typedef struct { ... } type_t;
However named things get complicated:
/** documents struct named, not type_t */
typedef struct named { ... } type_t;
The typedef-struct.c test case even tests this, and I'm not sure I like
it. It is true the named one creates two usable types, 'struct named'
and 'type_t'.
I played with the code, and it seems to me fixing this would get pretty
complicated pretty fast. The comment gets attached to the struct, not
the typedef, and you can't get to the typedef except by traversing the
cursors at the top level.
Is it unreasonable to recommend either:
/** document type_t */
typedef struct { ... } type_t;
or:
/** document struct named */
struct named { ... };
/** document type_t */
typedef struct named type_t;
and discourage the combination of the latter?
Seems like the same thing when combining structs/unions/variables with
instances.
BR,
Jani.