简体   繁体   English

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

[英]Using Microsoft's Source-Code Annotation Language (SAL) with Doxygen?

I am trying to use Doxygen to document some C++ code that uses Microsoft's Source-Code Annotation Language (SAL) . 我正在尝试使用Doxygen记录一些使用Microsoft的源代码注释语言(SAL)的 C ++代码。 However, Doxygen does not parse certain annotation macros, like _Success_ , correctly. 但是,Doxygen无法正确解析某些注释宏,例如_Success_ In the case of the example function annotation , _Success_ , Doxygen misinterprets this macro as the function header/prototype. 在示例函数注释 _Success_的情况下,Doxygen将此宏误解为函数标头/原型。

Take the following example that contains the function annotation marker: 请看以下包含函数注释标记的示例:

/**
 *    @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;
}

With the example above, Doxygen will interpret _Success_() as the function header/prototype and thereby, creates documentation that is absolutely wrong. 在上面的示例中,Doxygen将_Success_()解释为函数头/原型,从而创建了绝对错误的文档。 Here is what the HTML Doxygen output appears like with and without the function annotation : 这是带有 带有 功能注释的HTML Doxygen输出的外观:

有和没有功能注释的比较

With the function annotation , Doxygen also says I have documented a parameter variable i that is not part of the list of arguments: 通过函数注释 ,Doxygen还说我记录了一个不属于参数列表的参数变量i

C:/.../Source.cpp:9: warning: argument 'i' of command @param is not found in the argument list of Success (return) C:/.../ Source.cpp:9:警告:在成功 (返回)的参数列表中找不到命令@param的参数'i'

Am I missing a configuration setting in the main Doxygen configuration file ? 我是否在Doxygen配置文件中缺少配置设置?
Or is SAL and Doxygen simply just incompatible? 还是SALDoxygen只是不兼容?

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." 经过一番研究的深入,我发现了一个问题上堆栈溢出是问同样的问题,但它没有被正确标记,并没有明确地说他/她是使用“微软的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 . 问题的答案参考了Doxygen手册的标题为: 预处理

A typically example where some help from the preprocessor is needed is when dealing with the language extension from Microsoft: __declspec . 一个典型的需要预处理器帮助的示例是在处理Microsoft的语言扩展时: __declspec The same goes for GNU's __attribute__ extension. GNU的__attribute__扩展也是如此。 [...] When nothing is done, doxygen will be confused and see __declspec as some sort of function. [...]什么也不做,doxygen会感到困惑,并将__declspec视为某种功能。 [...] [...]

Therefore, as pertaining to my example above, the settings that need to be configured in the Doxygen configuration file are as follows: 因此,关于我上面的示例,在Doxygen配置文件中需要配置的设置如下:

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 ." 基本上,这组配置意味着PREDEFINED部分中定义的宏将“ 在启动预处理器之前 ”进行完全扩展和评估。 But, these macros will expand to nothing as we provide "nothing" for the definition side of the equation (ie format: name=definition ). 但是,这些宏将扩展为空,因为我们为等式的定义端(即格式: name=definition )提供“无”。 Therefore, they are essentially ignored/removed while Doxygen builds the documentation documents. 因此,在Doxygen生成文档文档时,它们实际上将被忽略/删除。

Unfortunately , this does mean that one will need to continue to expand this PREDEFINED list to encapsulate, at least, all the SAL macros used in the source code. 不幸的是 ,这确实意味着人们将需要继续扩展这个PREDEFINED列表,以至少封装源代码中使用的所有SAL宏。 A better solution would to encapsulate all the SAL macros in this list, but future proofing is impossible as one will always be late at appending any new macros that are added later on. 一种更好的解决方案是将所有SAL宏封装在此列表中,但是将来的证明是不可能的,因为在以后添加任何新的宏时总是会很晚。 But, at least, there is a solution! 但是,至少有解决方案!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM