-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_symbols.py
83 lines (65 loc) · 3.25 KB
/
list_symbols.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import sys
import clang.cindex
from clang.cindex import CursorKind
import pdb
import pprint
from collections import defaultdict
from optparse import OptionParser
from ast_helpers import get_translation_unit
def main( options, args ):
tu = get_translation_unit( args[0], options )
dump_func( tu.cursor, args[0], options )
def dump_func( node, filename, options ):
"""
Dump all the unified symbol resolution strings for the functions
in the given ast
"""
if node.kind == CursorKind.TRANSLATION_UNIT:
for child in node.get_children():
dump_func( child, filename, options )
return
if ( options.no_decl == False and
not ( options.no_includes and node.location.file.name != filename ) ):
if ( node.kind == CursorKind.FUNCTION_DECL or
node.kind == CursorKind.CXX_METHOD ):
print( "Found function declaration %s on line %d. USR: %s" %
( node.spelling, node.location.line, node.get_usr() ) )
if options.no_call == False:
if ( node.kind == CursorKind.CALL_EXPR ):
print( "Found function use %s on line %d. USR: %s" %
( node.spelling, int( node.location.line ), node.referenced.get_usr() ) )
for child in node.get_children():
dump_func( child, filename, options )
if __name__ == '__main__':
parser = OptionParser()
parser.add_option( "", "--no-includes", dest="no_includes",
help="Skip definitions in included files",
action="store_true", default=False )
parser.add_option( "", "--no-decl", dest="no_decl",
help="Don't report USR for function declarations",
action="store_true", default=False )
parser.add_option( "", "--no-call", dest="no_call",
help="Don't report USR for function calls",
action="store_true", default=False )
parser.add_option( "-x", "--language", dest="language",
help=( "Treat input files as having this language. "
+ "Equivalent to clang's -x. Try c++ or c" ),
metavar="LANGUAGE", default="c++" )
parser.add_option( "-s", "--std", dest="standard",
help=( "Specity the language standard to compile for. "
+ "Equivalent to clan's -std=. "
+ "Try c++17 or c89" ),
metavar="LANGUAGE", default="c++17" )
parser.add_option( "-I", "--include", dest="include_path",
help=( "Directory to be added to include search path. "
+ "For multiple directories, comma separate." ),
metavar="FILE", default=None )
parser.add_option( "-f", dest="clang_flags",
help=( "any flags to be passed directly to clang "
+ "(for multiple flags, enclose in quotes)"),
metavar="FLAGS", default=None )
parser.add_option( "-v", action="store_true", dest="verbose",
help="Verbose mode makes more dbg output",
default=False )
( options, args ) = parser.parse_args()
main( options, args )