2010-04-15 62 views
8

我一直在嘗試使用Doxygen來記錄我的C++項目,但收效甚微:Doxygen無法識別某些宏,因此整個函數被錯誤解釋,並且大部分時間都不會生成文檔,即使它們有特殊的註釋塊。案例分析:對於上述類生成正確使用Doxygen

/** 
* \def  __MYLIB_FUNCTION_ATTRIBUTE(...) 
* \brief Some brief comment 
* \details Detailed doc 
* \sa  Some valid references 
*/ 
#define __MYLIB_FUNCTION_ATTRIBUTE(...) __attribute__(__VA_ARGS__) 

/** 
* \def  IN 
* \brief Tag for input arguments to a function 
* \details Blah... 
* \sa  OUT 
*/ 
#define IN 

/** 
* \def  OUT 
* \brief Tag for output arguments to a function 
* \details Blah... 
* \sa  IN 
*/ 
#define OUT 

class MyClass { 
public: 

    /** 
    * \fn  MyClass() 
    * \brief  Constructor for MyClass 
    * \details Hi! 
    */ 
    __MYLIB_FUNCTION_ATTRIBUTE(__always_inline__) 
    MyClass() { 
    } 

    /** 
    * \fn  const char *doNothing(const char *s IN) 
    * \brief  A weird function 
    * \details Some very weird doc 
    * \param[in] s No good parameter 
    */ 
    const char* __SXC_FUNCTION_ATTRIBUTE(__const__) doNothing(const char *s IN) { 
     return s; 
    } 
}; 

文檔一直缺少doNothingIN的描述被解釋爲功能!我在這裏做錯了什麼?

+0

什麼是MACRO_EXPANSION等的值。 (http://www.doxygen.nl/config.html#cfg_macro_expansion)在你的配置文件? – 2010-04-15 15:51:45

+0

@Eric:我認爲你遇到了問題頭! MACRO_EXPANSION設置爲YES,但是是否還需要指定其他包含目錄?目前所有使用的標題也都由Doxygen處理。我會回顧其餘的參數並回復你。 – themoondothshine 2010-04-15 15:59:46

+0

這裏是配置PARAMS: 'ENABLE_PREPROCESSING = YES MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = NO SEARCH_INCLUDES = YES' – themoondothshine 2010-04-15 16:07:43

回答

4

兩件事情:

1)doxygen的解析器不 「看」 到 「IN」 在doNothing(因爲它是在預處理階段去除),所以\ FN不應該包括它:const char* doNothing(const char* s)。順便說一下,這不是必須的:如果緊靠記錄在案的實體之前,Doxygen會自動將評論關聯起來。

2)我不知道是什麼__SXC_FUNCTION_ATTRIBUTE擴展到,但是,如果是類似__MYLIB_FUNCTION_ATTRIBUTE的東西,它可能混淆的Doxygen。作爲一種變通方法,您既可以在使用Doxygen的配置文件的預定區段定義這些宏不了了之,或者有條件地在源定義它們,就像這樣:

#ifdef DOXYGEN 
// Doxygen does not grok the normal definition of this 
#define __MYLIB_FUNCTION_ATTRIBUTE(...) 
#else 
#define __MYLIB_FUNCTION_ATTRIBUTE(...) __attribute__(__VA_ARGS__) 
#endif 

,並把預定義= Doxygen的在你的配置文件。

+0

@Eric:真棒!!你的解決方案工作起來很輕鬆!這絕對是+1。謝謝。 – themoondothshine 2010-04-16 17:22:17