Doxygen @code行号

neu*_*rte 10 doxygen

有没有办法在@code... @endcode块中显示代码行号?从doxygen手册中的截图看来,似乎有,但我无法找到doxygen本身的选项,或者标签语法来实现这一点.

我需要这个能够在代码块之后写出"在上面的代码中,第3行".

还测试了围栏代码块,仍然没有数字.

小智 1

简答

看来至少在当前版本(1.8.9)中添加了行号:


细节

Python 代码格式化程序

g_sourceFileDef如果计算结果为: Python 代码格式化程序包含行号TRUE

/*! start a new line of code, inserting a line number if g_sourceFileDef
 * is TRUE. If a definition starts at the current line, then the line
 * number is linked to the documentation of that definition.
 */
static void startCodeLine()
{
  //if (g_currentFontClass) { g_code->endFontClass(); }
  if (g_sourceFileDef)
Run Code Online (Sandbox Code Playgroud)

https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/pycode.l#L356

如果提供了(非零),则从FileDef *fd传递到parseCode/或其他情况下对其进行初始化:parsePythonCodenew FileDef(<...>)

g_sourceFileDef = fd;
<...>
if (fd==0)
{
  // create a dummy filedef for the example
  g_sourceFileDef = new FileDef("",(exName?exName:"generated"));
  cleanupSourceDef = TRUE;
}
Run Code Online (Sandbox Code Playgroud)

https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/pycode.l#L1458)所以似乎所有Python代码都包含行号

C 代码格式化程序

C 代码格式化程序有一个附加变量g_lineNumbers,并且包含行号,如果 和 的g_sourceFileDef计算g_lineNumbers结果为TRUE

/*! start a new line of code, inserting a line number if g_sourceFileDef
 * is TRUE. If a definition starts at the current line, then the line
 * number is linked to the documentation of that definition.
 */
static void startCodeLine()
{
  //if (g_currentFontClass) { g_code->endFontClass(); }
  if (g_sourceFileDef && g_lineNumbers)
Run Code Online (Sandbox Code Playgroud)

https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/code.l#L486

它们通过以下方式初始化:

g_sourceFileDef = fd;
g_lineNumbers = fd!=0 && showLineNumbers;
<...>
if (fd==0)
{
  // create a dummy filedef for the example
  g_sourceFileDef = new FileDef("",(exName?exName:"generated"));
  cleanupSourceDef = TRUE;
}
Run Code Online (Sandbox Code Playgroud)

https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/code.l#L3623

请注意,如果提供的值为 0,则g_lineNumbers保留FALSEfd

HtmlDoc访问者

在其中的parseCode调用中HtmlDocVisitor::visit,只有一个(对于DocInclude::IncWithLines,对应于\includelineno)传递非零fd: https: //github.com/doxygen/doxygen/blob/Release_1_8_9/src/htmldocvisitor.cpp#L540 所以这似乎是唯一的该命令将导致行号包含在 C 代码列表中