I'm looking for a 开发者_开发知识库c++ parser which is able to extract all the functions and methods with its signatures. Is there something like this?
I had a look at gccxml there I have the problem, that it is not able to use namespaces and its not fine when only a header file is present.
Most obvious options:
- ctags
- cscope
Just a sample of the GCC man page:
-fdump-noaddr -fdump-unnumbered -fdump-translation-unit[-n] -fdump-class-hierarchy[-n] -fdump-ipa-all -fdump-ipa-cgraph -fdump-ipa-inline
-fdump-statistics -fdump-tree-all -fdump-tree-original[-n] -fdump-tree-optimized[-n] -fdump-tree-cfg -fdump-tree-vcg -fdump-tree-alias -fdump-tree-ch -fdump-tree-ssa[-n] -fdump-tree-pre[-n] -fdump-tree-ccp[-n] -fdump-tree-dce[-n]
-fdump-tree-gimple[-raw] -fdump-tree-mudflap[-n] -fdump-tree-dom[-n] -fdump-tree-dse[-n] -fdump-tree-phiopt[-n] -fdump-tree-forwprop[-n] -fdump-tree-copyrename[-n] -fdump-tree-nrv -fdump-tree-vect -fdump-tree-sink -fdump-tree-sra[-n]
-fdump-tree-fre[-n] -fdump-tree-vrp
Also there is a gccxml backend
The Clang compiler obviously has the functionality to do this, if I remember correctly there's even an API to access the code tree generated by the parser.
You can use the -dump
option of the abi-compliance-checker tool to parse signatures of functions and methods from your header file(s):
abi-compliance-checker -lib NAME -dump DESC.xml -headers-only -stdout > api.dump
XML-descriptor (DESC.xml
) is the following:
<version>
VERSION
</version>
<headers>
/path(s)/to/headers/
</headers>
The tool works as following:
- Call
GCC
with-fdump-translation-unit
and a set of automagically generated-I...
options on the headers specified in the input XML-descriptor; - Parse the AST dump generated by the
GCC
; - Generate function signatures and type definitions in the Data::Dumper or XML format (if additional
-xml
option is provided).
The sample signature of int BZ2_bzRead ( int *bzerror, BZFILE *b, void *buf, int len )
function from bzlib.h
header looks like:
'228' => { 'Header' => 'bzlib.h', 'Line' => '160', 'Param' => { '0' => { 'algn' => '4', 'name' => 'bzerror', 'type' => '30' }, '1' => { 'algn' => '4', 'name' => 'b', 'type' => '16' }, '2' => { 'algn' => '4', 'name' => 'buf', 'type' => '68' }, '3' => { 'algn' => '4', 'name' => 'len', 'type' => '41' } }, 'Return' => '41', 'ShortName' => 'BZ2_bzRead' },
you could try compiling your code with the save-temps
flag set on gcc, this makes gcc output the files with macro unfolding and full signatures. these are the .ii files.
精彩评论