在Doxygen中使用Microsoft的源代码注释语言(SAL)?

代码狗狗

我正在尝试使用Doxygen记录一些使用Microsoft的源代码注释语言(SAL)的C ++代码但是,Doxygen无法_Success_正确解析某些注释宏,例如在该示例的情况下功能注释_Success_,Doxygen的曲解该宏为函数头/原型。

以包含函数注释标记的以下示例为例

/**
 *    @file
 *    Example with function annotation.
 */

#include <windows.h>
#include <sal.h>

/**
 *    @brief This is a function.
 *    @param i a random variable
 *    @return TRUE on every call.
 */
_Success_(return) // The SAL function annotation.
BOOL function(_In_ int i) {
    return TRUE;
}

在上面的示例中,Doxygen将解释_Success_()为函数标头/原型,从而创建绝对错误的文档。这里是出现什么HTML Doxygen的输出像没有功能注释

有和没有功能注释的比较

通过函数注释,Doxygen还说我记录了一个i不属于参数列表的参数变量:

C:/.../ Source.cpp:9:警告:在成功(返回)的参数列表中找不到命令@param的参数'i'

Am I missing a configuration setting in the main Doxygen configuration file?
Or is SAL and Doxygen simply just incompatible?

Code Doggo

Ah ha! After some further research, I found a question on Stack Overflow that asked this same question, except it wasn't tagged correctly and did not explicitly say s/he was using "Microsoft's SAL." This is why it took me awhile to find it. (I have updated the corresponding question to correct these missteps.)

The question's answer references the Doxygen manual section entitled: Preprocessing.

A typically example where some help from the preprocessor is needed is when dealing with the language extension from Microsoft: __declspec. The same goes for GNU's __attribute__ extension. [...] When nothing is done, doxygen will be confused and see __declspec as some sort of function. [...]

Therefore, as pertaining to my example above, the settings that need to be configured in the Doxygen configuration file are as follows:

ENABLE_PREPROCESSING   = YES
MACRO_EXPANSION        = YES
EXPAND_ONLY_PREDEF     = YES
PREDEFINED             = _Success_(x)= \
                         _In_=

Basically, this set of configurations means that the macros defined in the PREDEFINED section will be fully expanded and evaluated "before the preprocessor [has] started." But, these macros will expand to nothing as we provide "nothing" for the definition side of the equation (i.e. format: name=definition). Therefore, they are essentially ignored/removed while Doxygen builds the documentation documents.

不幸的是,这确实意味着需要继续扩展此PREDEFINED列表,以至少封装源代码中使用的所有SAL宏。一种更好的解决方案是将所有SAL宏封装在此列表中,但是将来的证明是不可能的,因为在以后添加任何新的时总是会很晚但是,至少有解决方案!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章