__inline__ 和 __attribute__ 令人困惑的 Doxygen

__inline__ and __attribute__ confusing Doxygen

(已解决,解决方案见文末)

我在一个嵌入式 C 项目中,编写了一个仅包含静态强制内联函数的 .h 文件。我这样记录它们:

//----------------------------------------------------------------------------
// RECT WIDTH
/** Returns a source rectangle's width.
 *  The RECT_Width method calculates and returns a source rectangle's width.
 * 
 * @param r  A RECT structure that contains the specified source rectangle.
 * @return   The source rectangle's width.
 */
FORCE_INLINE __attribute__((unused))
static COORD RECT_Width(RECT r) {
    return r.Right-r.Left;
}

FORCE_INLINE 定义为

#define FORCE_INLINE  __attribute__((always_inline))

问题行将展开为:

__attribute__((always_inline)) __attribute__((unused))

__attribute__ 已添加到 EXCLUDE_SYSMBOLS 部分,因此它们不会被记录为函数。

问题是 Doxygen 似乎被行 FORCE_INLINE __attribute__((unused)) 搞糊涂了。它似乎不同步并跳过文件中间的几乎所有功能,除了一个功能。该函数的格式与其他函数完全相同。

Doxygen 还将一些函数的部分参数和代码片段记录为全局变量。

FORCE_INLINE RECT   r2
r   Left = MAX(r1.Left,r2.Left)
r   Top = MAX(r1.Top,r2.Top)
r   Right = MIN(r1.Right,r2.Right)
r   Bottom = MIN(r1.Bottom,r2.Bottom)
return  r
FORCE_INLINE POINT  p
FORCE_INLINE COORD  offset
FORCE_INLINE POINT  pos

我也试过打开MACRO_EXPANSIONEXPAND_ONLY_PREDEF并在EXPAND_AS_DEFINED部分添加FORCE_INLINE。没有区别。

我也试过将它们添加到 EXCLUDE_SYSMBOLS:

FORCE_INLINE
__attribute__

作为测试,我将 @fn 命令添加到 Doxygen 未看到的函数之一,并生成了该函数的所有文档。但是我不能将 @fn 添加到每个函数并将代码片段记录为全局变量。

有没有人知道如何让 Doxygen 忽略每个函数前面的 FORCE_INLINE __attribute__((unused))

解决方案
@KamilCuk 给了我一个主意,所以我将其添加到我的头文件中:

#if __DOXYGEN__
    #define FORCE_INLINE_SILENT
#else
    #define FORCE_INLINE_SILENT FORCE_INLINE __attribute__((unused))
#endif

然后用FORCE_INLINE_SILENT替换了FORCE_INLINE __attribute__((unused))FORCE_INLINE在另一个头文件中定义。

The problem is that Doxygen seems to get confused by the line FORCE_INLINE attribute((unused))

你应该处理它,以免混淆。例如:

#if __GNUC__
#define FORCE_INLINE  __attribute__((always_inline))
#else
// expands to nothing for others
#define FORCE_INLINE
#endif

或喜欢:

#if __DOXYGEN__
#define FORCE_INLINE
#endif

这样,doxygen 就什么也看不到了。您还需要以这种方式处理 __attribute__((unused)),并且通常将此类宏放在一个公共 header 中,以提供您的项目与不同编译器的兼容性。