作为一种快速解决方法,我使用 python 制作了这个 Doxygen 输入过滤器。它假定您有一个.cs 源文件,其中一个包含静态方法的主类。它有点杂乱无章,因为它没有进行正确的语法解析,但它对我有用;)
它采用.cs 输入文件,获取类名并将其添加到类中找到的任何静态函数调用之前,以将someStaticMethod 之类的调用替换为Class1.someStaticMethod
要使用,只需将其添加到 Doxygen 配置中:
FILTER_PATTERNS = *.cs=DocPreprocess.bat
bat 文件只是 python 脚本的包装器,如下所示:
@echo off
cd %~dp0
C:\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\python.exe DocPreprocess.py %1
只需确保 bat 文件位于路径上或 Doxygen 启动文件夹中。
DocPreprocess.py
>
import re
import sys
original = open(sys.argv[1],"rb").read();
#remove quoted sections and char literal braces
regex = re.compile('"([^"]*)"', re.IGNORECASE)
buffer = regex.sub("", original).replace("'{'","").replace("'}'","")
#remove comments
newbuffer = ""
for l in buffer.splitlines():
code,_,comment = l.partition(r"//")
newbuffer += code
buffer = " ".join(newbuffer.split())
#get static functions and main class name
depth = 0
classname = ""
classdepth = 0
funcs = []
while True:
nopen = buffer.find("{")
nclose = buffer.find("}")
if nclose==-1 and nopen>-1: nclose=nopen+1
if nclose>-1 and nopen==-1: nopen=nclose+1
if nclose==-1 and nopen==-1: break
if nopen < nclose:
chunk,_,buffer = buffer.partition("{")
depth+=1
else:
chunk,_,buffer = buffer.partition("}")
depth-=1
chunk = chunk.strip()
if "public class" in chunk and classname == "":
classname = chunk.split()[-1]
classdepth = depth
if classdepth and depth > classdepth and "static" in chunk and chunk.endswith(")"):
funcs.append(chunk.rpartition("(")[0].split()[-1])
#replace
fixed = ""
for l in original.splitlines():
words = l.split()
stripped = l.strip()
if "static" in words[0:3] or stripped.startswith("//") or stripped.startswith("#"):
#ignore function defs and comments
fixed += l + "\n"
continue
for f in funcs:
newname = classname+"."+f
l=l.replace(newname,"[[TEMPTOKEN]]")
l=l.replace(f,newname)
l=l.replace("[[TEMPTOKEN]]",newname)
fixed += l + "\n"
#output fixed file to stdout
print fixed
这只是为了得到我想要的东西,我仍然很想看到一个真正的解决方案,让 Doxygen 自动执行此操作。
谢谢
汤姆