1import traceback
2
3class Symbol(object):
4    def __init__(self, anchor, type, cppname):
5        self.anchor = anchor
6        self.type = type
7        self.cppname = cppname
8        #if anchor == 'ga586ebfb0a7fb604b35a23d85391329be':
9        #    print(repr(self))
10        #    traceback.print_stack()
11
12    def __repr__(self):
13        return '%s:%s@%s' % (self.type, self.cppname, self.anchor)
14
15def add_to_file(files_dict, file, anchor):
16    anchors = files_dict.setdefault(file, [])
17    anchors.append(anchor)
18
19
20def scan_namespace_constants(ns, ns_name, files_dict):
21    constants = ns.findall("./member[@kind='enumvalue']")
22    for c in constants:
23        c_name = c.find("./name").text
24        name = ns_name + '::' + c_name
25        file = c.find("./anchorfile").text
26        anchor = c.find("./anchor").text
27        #print('    CONST: {} => {}#{}'.format(name, file, anchor))
28        add_to_file(files_dict, file, Symbol(anchor, "const", name))
29
30def scan_namespace_functions(ns, ns_name, files_dict):
31    functions = ns.findall("./member[@kind='function']")
32    for f in functions:
33        f_name = f.find("./name").text
34        name = ns_name + '::' + f_name
35        file = f.find("./anchorfile").text
36        anchor = f.find("./anchor").text
37        #print('    FN: {} => {}#{}'.format(name, file, anchor))
38        add_to_file(files_dict, file, Symbol(anchor, "fn", name))
39
40def scan_class_methods(c, c_name, files_dict):
41    methods = c.findall("./member[@kind='function']")
42    for m in methods:
43        m_name = m.find("./name").text
44        name = c_name + '::' + m_name
45        file = m.find("./anchorfile").text
46        anchor = m.find("./anchor").text
47        #print('    Method: {} => {}#{}'.format(name, file, anchor))
48        add_to_file(files_dict, file, Symbol(anchor, "method", name))
49