我正在尝试使用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?
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] 删除。
我来说两句