Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Doxygen read double-slash C++ comments as markup

Tags:

c++

doxygen

I'm trying to set up automated Doxygen runs on our massive 78,000 file C++ codebase. It's doing okay with extracting basic type and hierarchy information, but I'd like to make it smarter about picking up the documentation comments that are already in place.

Most of the comments that have accumulated over the years do follow a general pattern, though not the pattern that Doxygen expected. Mostly they look like

// class description
class foo
{
   // returns ascii art of a fruit
   const char* apples( void ); 

   // does something to some other thing
   customtype_t baz( foo &other );

   enum
   {
      kBADGER, // an omnivorous mustelid
      kMUSHROOM, // tasty on pizza
      kSNAKE,  // oh no!
   };
}

Which are double-slashed, rather than the /// or //! style comments that Doxygen expects.

There are far too many files to go through searching and replacing all such comments, and many of my programmers are violently allergic to seeing triple-slashes in their code, so I'd like to find some way to make Doxygen read ordinary comments as JavaDoc comments, when they're in the right place. Is there a way to make Doxygen read // as ///?

I couldn't find any such configuration parameter, so I figure I'll need to transform the input somehow. In general the rule I'd use is:

  • if there is a line containing just a comment, immediately preceding a function/class/type/variable declaration, assume it is a /// comment.
  • if there is a declaration followed on the same line by a // comment, treat it as a ///<

But I don't know how to go about teaching Doxygen this rule. The two ways I can think of are:

  1. Write a program as an INPUT_FILTER, which parses the input C++ and transforms //s into ///s as above. But this kind of transform is too complicated to do as a regular expression, and I really don't want to have to write a full blown C++ parser just to feed input to another C++ parser! Also, spinning up an INPUT_FILTER program for each file slows down Doxygen unacceptably: it already takes over 30 minutes to run across our source, and adding an INPUT_FILTER makes it take over six hours.
  2. Modify the Doxygen source code to include the above comment rules. That seems like a scary amount of work in unfamiliar code.

Any other ideas?

like image 432
Crashworks Avatar asked Jun 28 '11 01:06

Crashworks


People also ask

How do I comment out a code in doxygen C++?

Once specified, you can generate the comment stub by typing the respective “///” or “/**” above a function, or by using the (Ctrl+/) shortcut.

How do you doxygen comment?

there are two kinds of special comments recognized (and processed) by doxygen: Comments that start with a /** delimiter and end with a */ delimiter. Comments that start with a /**< delimiter and end with a */ delimiter.

What is @brief in doxygen?

Putting the command @brief will generate a short description of the function when you generate the doxygen documentation. That short description can be extended if you want. Follow this answer to receive notifications.

What is triple slash in C++?

Overview Q & A Rating & Review. Generate xml documenation comment stubs in c++ files by typing three forward slashes. This functionality is already built into visual studio for c# code; this extension attempts to bring it to c++ as well. The /// needs to be entered on the line immediately preceding the function.


1 Answers

The answer is simple: You can't.

The special style of doxygen must be used, to mark a comment as documentation.

Doxygen does NOT only take comments, that precede the declaration. You also could use them everywhere in the code.

If you want to use the doxygen features, you would have to update the comments by hand, or write a script/tool that looks for declarations and preceding comments to change them.

You have to decide, choose one from the 3 solutions (your two, and the script, added as answer) or not using doxygen.

like image 79
Thomas Berger Avatar answered Sep 21 '22 02:09

Thomas Berger