-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdump_tree.py
69 lines (49 loc) · 2.2 KB
/
dump_tree.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
import sys
import os
import platform
# set path to franca module before import
sys.path.append(os.getcwd() + "/build/lib."
+ platform.system().lower() + "-"
+ platform.machine() + "-"
+ ".".join(platform.python_version_tuple()[0:2]))
import franca
root = franca.package()
franca.builder.parse_and_build(root, "printengine.fidl")
def print_typecollection(tc, indent) :
indent += " "
print indent + "typecollection " + tc.name()
for t in tc.types:
#
# XXX beware to always ask if the type is a union before trying struct
# else this seems to yield wrong results
#
if isinstance(t, franca.union) :
print(indent + " " + t.name() + " is union")
if t.has_base() :
print indent + " is based on " + t.base().name() + " (" + t.base().fqn("::") + ")"
elif isinstance(t, franca.struct) :
print(indent + " " + t.name() + " is struct")
if t.has_base() :
print indent + " is based on " + t.base().name() + " (" + t.base().fqn("::") + ")"
elif isinstance(t, franca.enumeration) :
print(indent + " " + t.name() + " is enum")
if t.has_base() :
print indent + " is based on " + t.base().name() + " (" + t.base().fqn("::") + ")"
elif isinstance(t, franca.typedef) :
print(indent + " " + t.name() + " is typedef to real type " + t.real_type().name())
elif isinstance(t, franca.array) :
print(indent + " " + t.name() + " is array of " + t.element_type().name())
elif isinstance(t, franca.map) :
print(indent + " " + t.name() + " is map of [" + t.key_type().name() + ", " + t.value_type().name() + "]")
else :
print "XXXXXXXXXXXXX UNKNOWN TYPE XXXXXXXXXXXXXXXXXXXXXXXXXX"
print(indent + " " + " fqn " + t.fqn("::"))
print(indent + " " + " typeid = " + t.type_id())
def print_package(pck,indent) :
if pck.name() :
print indent + "package " + pck.name()
for tc in pck.typecollections :
print_typecollection(tc, indent)
for p in pck.packages :
print_package(p, indent + " ")
print_package(root,"")