-
Notifications
You must be signed in to change notification settings - Fork 273
Convert documentation style for doxygen compatibility #869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@thk123 suggested just now that a good way of tackling this review might be to slightly modify the conversion script, so that it produces some kind of condensed diagnostic message whenever it makes a non-trivial formatting change. |
At present the conversion removes the 'author' annotation, as I believe this information is better managed by git blame. Is this likely to be problematic in terms of copyright ownership? Is there another reason for keeping the author field? |
By the way, I've so far found these three formats supported a little by qtcreator:
By "supported a little" I mean that when you type the first line and press return it auto-completes the rest of it, including all the parameter names. We should definitely consider whether it would make sense to use a format that is very easy to create with qtcreator. |
To be clear, does QTCreator require the leading and trailing triple slashes on an otherwise empty line? |
It seems like QTCreator has something which kicks in whenever you press return on a line which ends with three slashes in a row in it, and you're above a function. It adds in the rest of the text above. So to get rid of the first and last lines would require removing them manually afterwards, which is a little annoying. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked at a few files, as mentioned it would be good to have a list of functions which aren't completely erased by this change to hand review them.
I'm also not sure about not including the function name. I understand your argument, but worry that comments can sometimes go for walkies and it acts as a checksum that the comment is really about the function you are looking at.
I'll review the scripts tomorrow.
src/cbmc/cbmc_solvers.cpp
Outdated
|
||
/// Uses the options to pick an SMT 1.2 solver | ||
/// | ||
/// parameters: None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose in this case we don't really want this line, perhaps we can special case Parameters: None
(or even Parameters: followed by a single word) to mean no generated parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - this should probably be a special case in the conversion script, yes.
I think it would be better/simpler to update in this PR the linter to validate doxygen? |
@owen-jones-diffblue OK, then I think that's a pretty strong argument for having empty leading and trailing lines. I should also change @tautschnig I was asked to do this work by @forejtv and @peterschrammel a few weeks ago. Re. copyright headers, who should I talk to about the correct wording? (Also, is it legally permissible to retroactively add licence text to source code?) |
Thanks for all the answers; I agree with all that's been said/suggested. For the legalese, I'd suggest to get @kroening + @forejtv + @peterschrammel to agree one format. (Yes, the copyright has legal implications, not just "documentation"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a look at the convert script - looks good to me apart from one regex.
convert.py
Outdated
""" Extract the named fields of an old-style comment block. """ | ||
|
||
field_re = re.compile( | ||
r'(?:\n *(Purpose):(.*))|(?:\n *([a-zA-Z0-9]+?):\n?(.*?)?^$)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come only "Purpose" is allowed to be on one line. If you are worried about false positives, there aren't so many possible labels: Purpose, Input, Output, Module, Author, Name are all I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that most fields extend until the next empty line, but in a few files there are very long 'Purpose' fields with multiple paragraphs. Therefore, we want 'Purpose' fields to consume everything until the end of the block, because we know that 'Purpose' will always be the final field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't say I understand why this regex does this, but I am convinced it does based on debugex.
convert.py
Outdated
with open(file) as f: | ||
contents = f.read() | ||
|
||
doc_width = 75 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realise the current docs aren't quite the full file width, but it is there a reason for this or should the doc width be 80 just like the regular lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a misleading name, I think - this is the width used for wrapped text, but then the leading ///
is added to the beginning of each line, meaning that the actual width of the block is 79 columns. This could be 76, if we want to go to 80 columns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well dunno if worth it since doubt we'll use the script again, but maybe doc_width = 80 - strlen('/// ')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to constrain the width of documentation by default to 70 or 72 characters, just like Python coding guidelines do (even then those same coding guidelines otherwise use 80 characters). The reason is the added flexibility: if breaking words would make things look awkward then you can safely go a few characters beyond 70/72 and would still remain within the linters 80-characters hard block.
Thanks for the review @thk123. I've tried out CLion's documentation completion. This is the auto-generated comment for the given function declaration. This is with no configuration, after typing three slashes and hitting return: ///
/// \param os
/// \param foo
/// \return
std::ostream &operator<<(std::ostream &os, const Foo &foo); Looks like we should definitely use As both styles don't add empty lines separating parameters and returns, I wonder whether we should do the same. |
@reuk I found that option (it's in Tools > Options... > Text Editor > Completion > Documentation Comments). Unticking "Generate brief description" means I get this output:
It still has the same number of lines, but the second line is blank instead of having "\brief ". I don't think we should get too caught up with copying exactly what QT Creator does. I had a brief look and CLion doesn't produce the blank line at the top and bottom, so I'm fine with not having that. It doesn't have a blank line between different sections, so that seems to be standard and we should probably stick to it. |
Updated to include all changes mentioned, other than the linter patch and new legalese. Re. the text wrapping, I think it's probably best to wrap at 80 columns, like in the code. Most editors support automatic line-breaking at a certain column, but most editors don't support line-breaking on different columns depending on context. |
|
A few files contain legacy \defgroup definitions, which are down to function level. These will require further refinement as we improve the documentation. |
It also seems that the "files" section in doxygen is only populated if the file contains a \brief; without that a file does not show up there. A TO_BE_DOCUMENTED default value might also help there. |
67c7365
to
9b53eea
Compare
I had a look at the doxygen config. By enabling the |
Does this PR include an update to the coding standard, to specify what function header comments will have to look like? |
No, but it probably should. Waiting on @peterschrammel, @forejtv and @kroening to decide on header legalese so that I can update the linter to check for the proper header wording, and so I can update the coding standard in one go (to include info about function blocks, header blocks, class blocks etc.) |
@reuk Can you please put the following as the header in each file, appropriately wrapped?
|
6843eab
to
05669a5
Compare
I added a driver script that ignores certain files and folders, and re-ran the conversion using this script. |
This reverts commit 60c5091.
Attempts to format existing documentation blocks according to the LLVM doxygen guidelines.
Format is approximately:
Note that the function name is not given in the documentation, and there is no blank line between the docs and the function. It's obvious which function is being documented, without having to name it explicitly. Also note that, if the purpose/parameters/returns sections are not applicable to a given function, then they should be omitted.
In some cases, the existing documentation was not formatted to use lists of input parameters. In these cases, the conversion has added a
parameters:
prefix. Ideally, these cases should use the\param
format instead, but this would require manual editing.I think this is about as far as we can go in terms of automation, but there are some further changes that should be made:
Finally, it would be really nice if merges into master automatically rebuilt the documentation and published it online.