Hi everyone,
Just following up on my previous email.
I've now worked through the design with Devansh, and we have a clear
approach for handling and storing the documentation comments.
Before I start implementing it, I'd like to ask one thing: would you prefer
that I submit the changes as one complete patch covering all the affected
files, or split them into smaller patches for easier review?
I'd also appreciate your thoughts on the remaining questions from my
previous email, especially the ".rdb" size impact and the annotation prefix
("doc:" or "docs:").
Thanks for your time!
Best,
Mohamed
في الثلاثاء، ٣ نوفمبر ٢٠٢٦, ١١:٠١ م Mohamed Amr <[email protected]>
كتب:
>
> Hi everyone,
>
> I'm Mohamed Amr, a third-year computer science student. My GSoC 2026
> proposal for "Documentation support for Codemaker tools" was not selected,
> but I have kept working on the project since then because I think the
> feature is worth having. Devansh Varshney has been reviewing the design
> with me, and here I bring the open questions so that you can weigh in
> before I write code.
>
> Where the documentation gets lost
>
> I traced the whole path of an IDL declaration. parse() maps the file into
> memory and creates the Flex scanner with (yylex_init_extra), so the scanner
> and the parser share one SourceProviderScannerData. The scanner turns the
> text into tokens, and the Bison parser uses them to build temporary pads
> (for example the interface pad with directMethods and directAttributes),
> which are moved into the final unoidl entities when the declaration ends.
> SourceFileProvider then takes the finished entities from data->entities,
> and from there they go through the Manager, unoidl-write, the .rdb,
> UnoidlProvider, and finally cppumaker.
>
> The entity model already has a std::vector<OUString> annotations on
> entities, methods, attributes and members, and the .rdb writer and reader
> already store and restore every string in it. There is also an existing
> pipeline for the deprecated state: the scanner returns TOK_DEPRECATED,
> deprecated_opt turns it into a bool, annotations(bool) turns that into the
> "deprecated" string for each entity or member, and cppumaker reads it with
> isDeprecated() and prints it with dumpDeprecation(). So the infrastructure
> is there and I wanted to reuse it.
>
> The documentation is dropped in two places. The scanner enters its doc
> state for /** ... */ and throws the text away (only @deprecated produces a
> token). And cppumaker only looks at the "deprecated" annotation, so even if
> text reached the entities it would not be printed.
>
> What I tried first
>
> I spent a good while on the association problem, and Devansh's test cases
> were very helpful. A single pending string in the scanner data fails,
> because the interface-level annotations() call runs after all its members
> were parsed, so the method docs overwrite it. A stack fails too:
> annotations() is called for every member whether or not it is documented,
> so an undocumented method would consume its interface's comment, and Bison
> look-ahead can make the scanner read the next comment before the current
> rule is reduced.
>
> The design I settled on
>
> The documentation travels as a token with its own semantic value, so it
> belongs to the grammar rule of the declaration and not to shared state. The
> difficult part was choosing that value, because of what real IDL files
> contain: several consecutive blocks before one declaration (ChartAxis.idl),
> and comments that contain @deprecated. If the value were only text, I would
> lose the deprecated information or need two tokens from one comment, and
> the lexer returns one token per call. So the scanner reads the whole
> comment and returns one token carrying a small struct:
>
> struct DocumentationData {
> OString text;
> bool deprecated = false;
> };
>
> While scanning, when it meets @deprecated it sets the flag, skips the tag
> and keeps reading to the closing */. The flag is per comment, so nothing
> stale is left behind after a parse error.
>
> Consecutive blocks are merged with a left-recursive rule:
>
> documentation_list:
> TOK_DOCUMENTATION { $$ = $1; }
> | documentation_list TOK_DOCUMENTATION
> {
> $$ = $1;
> if (!$$->text.isEmpty() && !$2->text.isEmpty())
> $$->text += "\n\n";
> $$->text += $2->text;
> $$->deprecated = $$->deprecated || $2->deprecated;
> delete $2;
> }
> ;
>
> deprecated_opt is reused as the optional symbol at the start of every
> declaration. It now returns a DocumentationData pointer (or nullptr), so
> the positions of the other $n values do not shift. annotations() takes that
> pointer, adds "deprecated" when the flag is set, adds "docs:" followed by
> the text (converted to OUString), and deletes the object. In cppumaker,
> isDeprecated() and dumpDeprecation() stay as they are, and I add two
> helpers: one that finds the docs: annotation and returns the text, and one
> that prints it as a /** ... */ block before interfaces, methods and
> attributes.
>
> Because the entity model, the .rdb writer and the reader already carry
> arbitrary strings, I do not expect to change them. I will verify that with
> a round-trip test.
>
> and by this implementation i answered for the tow most difficult
> questions :
> 1- how will documentation will be attached to the target declaration ?
> 2- how will i store it
>
> Questions I would appreciate your opinion on
>
> 1. Annotation name: "docs:" or "doc:"?
> 2. Storing all comments will increase the .rdb size. Is that acceptable,
> or should it be optional?
> 3. The %destructor for <sval> is commented out in the parser, and the new
> value is heap allocated. I plan to audit the ownership first, then enable a
> destructor if it can be done without double deletion. Any concerns?
> 4. Merging consecutive blocks with a blank line (ChartAxis.idl): is that
> the intended behaviour?
> 5. A doc comment before "module" currently has no place to go. I plan to
> accept it in the grammar and ignore it. OK?
> 6. Should /// stay unsupported for current time?
>
> Nothing is implemented yet. I attached an investigation matrix with the
> stages, comment forms and entities, and a longer report that explains the
> reasoning hoping to read it i explain everything. My plan is to agree on
> the design with you, then send small patches, aiming to finish by 30
> December.
>
> Thanks for your time,
> Mohamed Amr
> UNO IDL Documentation Report
> <https://docs.google.com/document/d/1bid3ZlfDDlg7MKV0VsQHgmz5EBT1qaAg/edit?usp=drive_link&ouid=102752957677252098820&rtpof=true&sd=true>
> IDL_Documentation_Matrix
> <https://docs.google.com/spreadsheets/d/14bgqKuQ7Ie75XxZeWyqXEa0Zu0leBH5x/edit?usp=drive_link&ouid=102752957677252098820&rtpof=true&sd=true>
>