forked from EdgarGrimbergNOV/idl_parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
104 lines (88 loc) · 2.66 KB
/
example.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
"""
def test():
from idl_parser import parser
_parser = parser.IDLParser()
idl_str = '''
module my_module {
struct Time {
long sec;
long usec; //@optional
long nsec; //@optional
};
enum UNION_DESCRIMINATOR_KIND
{
DESCRIMINATOR_UNKNOWN,
DESCRIMINATOR_ULONGLONG,
DESCRIMINATOR_LONGLONG,
DESCRIMINATOR_DOUBLE,
DESCRIMINATOR_STRING,
DESCRIMINATOR_KIND_COUNT
};
union UnionType switch( UNION_DESCRIMINATOR_KIND )
{
case DESCRIMINATOR_UNKNOWN:
case DESCRIMINATOR_KIND_COUNT:
case DESCRIMINATOR_ULONGLONG:
unsigned long long ull_value;
case DESCRIMINATOR_LONGLONG:
long long ll_value;
case DESCRIMINATOR_DOUBLE:
double d_value;
case DESCRIMINATOR_STRING:
sequence<char> str_value;
};
typedef sequence<double> DoubleSeq;
struct TimedDoubleSeq {
Time tm;
DoubleSeq data; // Regular comment
};
enum RETURN_VALUE {
RETURN_OK,
RETURN_FAILED,
};
interface DataGetter {
RETURN_VALUE getData(out TimedDoubleSeq data);
};
};
'''
global_module = _parser.load(idl_str)
my_module = global_module.module_by_name('my_module')
dataGetter = my_module.interface_by_name('DataGetter')
print('DataGetter interface')
for m in dataGetter.methods:
print('- method:')
print(' name:', m.name)
print(' returns:', m.returns.name)
print(' arguments:')
for a in m.arguments:
print(' name:', a.name)
print(' type:', a.type)
print(' direction:', a.direction)
doubleSeq = my_module.typedef_by_name('DoubleSeq')
print('typedef %s %s' % (doubleSeq.type.name, doubleSeq.name))
unionType = my_module.union_by_name('UnionType')
print('descriminator kind: %s' % unionType.descriminator_kind)
for m in unionType.members:
print('- member:')
print(' name:', m.name)
print(' type:', m.type.name)
print('descriminator value associations:')
for a in m.descriminator_value_associations:
print(' %s' % a)
time = my_module.struct_by_name('Time')
print('Time')
for m in time.members:
print('- member:')
print(' name:', m.name)
print(' type:', m.type.name)
print(' annotation:', m.annotation)
timedDoubleSeq = my_module.struct_by_name('TimedDoubleSeq')
print('TimedDoubleSeq')
for m in timedDoubleSeq.members:
print('- member:')
print(' name:', m.name)
print(' type:', m.type.name)
print(' annotation:', m.annotation)
if __name__ == '__main__':
test()