当函数作为参数传递给线程时,Doxygen无法识别函数调用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当函数作为参数传递给线程时,Doxygen无法识别函数调用相关的知识,希望对你有一定的参考价值。

简介

我使用doxygen(1.8.16版)记录了一些python项目。主要进程之一将某些子进程称为线程。不幸的是,这在氧气的调用图中无法识别。我想是因为这些函数是作为参数传递的(没有“()”)。

# functionA / functionB are not recognised as called functions by doxygen
t1 = Thread(target = functionA, args=(argA,argB))
t2 = Thread(target = functionB, args=(argC,argD))

t1.start()
t2.start()

t1.join()
t2.join()

有人间接调用函数时,有没有最佳实践或对doxygen进行修改或过滤以处理此类情况?

完整示例

示例文档的python文件

## @file 
#@brief This is a simple doxygen test document.

## @brief A test function
# This is a simple test function for doxygen.
# It calls two functions, <em> functionA, functionB </em> by spawning threads, which is not recognised by doxygen.
def test():        
    t1 = Thread(target = functionA, args=(argA,argB))
    t2 = Thread(target = functionB, args=(argC,argD))
    t1.start()
    t2.start()
    t1.join()
    t2.join()

## @brief Another test function
# This is a simple test function for doxygen.
# It calls two functions, <em> <functionA, functionB> directly, which is recognised by doxygen and reflected in the callgraph.
def test_serial():        
    functionA()
    functionB()    

## @brief One test function
# @param testParA \b =1 A test constant
# @return \b str A test return
def functionA():
    testParA = 1
    testVarA = "test"
    return testVarA

## @brief Another test function
# @param testParB \b ="test" A test constant
# @return \b int Another test return
def functionB():
    testParB = "test"
    testVarB = 1
    return testVarB

doxygen配置很长要在这里添加。您可以使用默认值,只需添加即可。请注意,带点的graphviz需要安装并可以找到(即添加到PATH环境中)

OPTIMIZE_OUTPUT_JAVA   = YES
EXTRACT_LOCAL_METHODS  = YES

REFERENCED_BY_RELATION = YES
REFERENCES_RELATION    = YES

HAVE_DOT               = YES
UML_LOOK               = YES

CALL_GRAPH             = YES
CALLER_GRAPH           = YES
答案

[除非有人找到更好的答案,否则这是一个对我有用的小技巧。只需在伪造的if块中在线程版本旁边包含标准函数调用即可。

def test():
  if False: #include in documentation, as doxygen does't recognise the threaded calls.
    functionA()
    functionB()        
  t1 = Thread(target = functionA, args=(argA,argB))
  t2 = Thread(target = functionB, args=(argC,argD))
  t1.start()
  t2.start()
  t1.join()
  t2.join()

以上是关于当函数作为参数传递给线程时,Doxygen无法识别函数调用的主要内容,如果未能解决你的问题,请参考以下文章

当我们将数组作为参数传递给其他函数时,数组的值如何变化? [复制]

AfxBeginThread 破坏了作为参数传递给线程函数的类中的 LPWSTR 值。为啥?

为啥函数的 dtors 被调用两次(多次),当作为函数的参数传递给线程时?

无法以 GET 类型的方法将字典作为参数传递给 WCF REST 服务

将 lambda 作为模板参数传递给函数指针函数模板化

如何将向量作为参数传递给另一个向量?