Squ*_*rel 5 c macros templates doxygen c-preprocessor
我正在尝试使用Doxygen为C中的模拟模板生成文档而没有太大成功.我希望有人知道如何在doxygen预处理器中使宏技巧工作?我已经尝试过启用"MACRO_EXPANSION"而没有运气.
编辑:这个问题最变性的形式是:"我怎样才能使Doxygen以与C预处理器类似的方式处理预处理器指令#include?"
我在"test"文件夹中有以下代码(一个非常人为的例子):
templates.h
#ifndef TEMPLATES_H_
#define TEMPLATES_H_
#define CAT(X,Y) X##_##Y
#define TEMPLATE(X,Y) CAT(X,Y)
#endif // TEMPLATES_H_
Run Code Online (Sandbox Code Playgroud)
test.h
#ifndef TEST_H_
#define TEST_H_
#include "templates.h"
#ifdef TEST_T
#error "TEST_T cannot be defined prior to this compilation step"
#endif
#define TEST_T uint8_t
#include "test_template.h"
#undef TEST_T
#define TEST_T uint16_t
#include "test_template.h"
#undef TEST_T
#endif // TEST_H_
Run Code Online (Sandbox Code Playgroud)
test_template.h
#ifdef TEST_T
#include "templates.h"
TEST_T TEMPLATE(sum,TEST_T)(TEST_T a, TEST_T b);
#endif // ifdef TEST_T
Run Code Online (Sandbox Code Playgroud)
test.c的
#include "test.h"
#ifdef TEST_T
#error "TEST_T cannot be defined prior to this compilation step"
#endif
#define TEST_T uint8_t
#include "test_template.c"
#undef TEST_T
#define TEST_T uint16_t
#include "test_template.c"
#undef TEST_T
Run Code Online (Sandbox Code Playgroud)
test_template.c
#ifdef TEST_T
TEST_T TEMPLATE(sum,TEST_T)(TEST_T a, TEST_T b)
{
return a + b;
}
#endif // ifdef TEST_T
Run Code Online (Sandbox Code Playgroud)
在我的doxygen配置文件中:
test.cfg
# Doxyfile 1.8.13
PROJECT_NAME = "Test"
OUTPUT_DIRECTORY = "docs_test"
TAB_SIZE = 3
OPTIMIZE_OUTPUT_FOR_C = YES
INPUT = "../test"
RECURSIVE = YES
MACRO_EXPANSION = YES
# Temporary to extract all without tags
EXTRACT_ALL = YES
Run Code Online (Sandbox Code Playgroud)
但是,sum*函数的模板化版本不存在于doxygen(.h或.c文档)中; 例如,test.h在下面(虽然如果它出现在test_template.h中我会很高兴):
有什么想法吗?
来自 doxygen 文档: http://www.doxygen.nl/manual/preprocessing.html
如果您不确定 doxygen 预处理的效果是什么,您可以按如下方式运行 doxygen:
doxygen -d 预处理器
这将指示 doxygen 在预处理完成后将输入源转储到标准输出(提示:在配置文件中设置 QUIET = YES 和 WARNINGS = NO 以禁用任何其他输出)。
将其与真实 C 预处理器生成的输出进行比较,以确保 doxygen 扩展的内容实际上与 C 编译器看到的内容匹配。
您可能需要调整与 doxygen 中的预处理相关的配置变量才能使其工作。
话虽这么说,正如其他人评论的那样,我个人不会像这样使用 C 预处理器,但我同意这是个人意见问题。
一个可能出现的问题是:C 预处理器可以在扩展宏时生成代码,但不会生成注释,并且所有 doxygen 标记都嵌入在 C 注释中。
当然,doxygen 可能会发现有一个名为 sum_uint8_t 的函数,但要真正添加有关此函数的文档,源代码需要在源代码中显式添加“结构命令”。
请参阅 http://www.doxygen.nl/manua/docblocks.html#structuralcommands