這個問題是從超級用戶遷移過來的,因為可以在 Stack Overflow 上回答。 11 小時前遷移 。
我在谷歌上真的找不到關于這個問題的東西。
我想從 .c/.h 檔案決議(獲取所有)函式定義和宣告。
我了解 ctags、cscope 和 clang (AST)。
因為我喜歡 ctags 的簡單性,所以我決定堅持使用它。
我遇到的一個問題是,如果 ctags 之間有換行符,則它們不會輸出整個引數串列,如下所示:
int my_function(
int a, int b
);
給出輸出:
$ ctags -x --c-kinds=fp so.c
my_function prototype 1 so.c int my_function(
這可以通過以下工具來解決indent:
$ indent -kr so.c -o so-fixed.c
$ ctags -x --c-kinds=fp so-fixed.c
my_function prototype 1 so-fixed.c int my_function(int a, int b);
好的,這完美地作業。直到您必須處理可變引數函式,例如:
int my_function(
int a, int b, ...
);
然后輸出indent對我來說不再可用:
int my_function(int a, int b, ...
);
這里更大的目標是交叉檢查頭檔案中定義的引數名稱與實際實作中使用的引數名稱。
所以像:
頭檔案.h
void my_function(int param);
impl.c
void my_function(int something_else) {
}
會被抓住。
最終我知道我可以使用 clang 和它的 AST 輸出。
但是,由于 AST 的復雜性,如果可能的話,這是我想避免的。
uj5u.com熱心網友回復:
這里更大的目標是交叉檢查頭檔案中定義的引數名稱與實際實作中使用的引數名稱。
為此,您可以將 clang-tidy 與https://clang.llvm.org/extra/clang-tidy/checks/readability-inconsistent-declaration-parameter-name.html 一起使用
uj5u.com熱心網友回復:
Universal Ctags提供了自定義外部參照輸出的功能。
$ cat /tmp/bar.c
int f(char /* int */ a,
// int b, ...
int
*c,
...
)
;
$ ~/bin/ctags -x --_xformat="%-16N %-10K %4n %-16F %{typeref} %{name}%{signature}" --kinds-C= p -o - /tmp/bar.c |sed -e 's/typename://'
f prototype 1 /tmp/bar.c int f(char a,int * c,...)
另見https://docs.ctags.io/en/latest/output-xref.html?highlight=_xformat#xformat
為了根據需要格式化回傳型別,您可能需要使用 sed。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/379852.html
