-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathzproto_lib.gsl
109 lines (102 loc) · 3.3 KB
/
zproto_lib.gsl
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
105
106
107
108
109
#
# Library functions
#
# This is a code generator built using the iMatix GSL code generation
# language. See https://github.com/imatix/gsl for details.
#
# Copyright (c) the Contributors as noted in the AUTHORS file.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
function expand_headers ()
for message
if !defined (message.id)
message.id = item ()
endif
for field where item () = 1
for class.header
for field as hfield
copy hfield before field
endfor
endfor
else
for class.header
for field as hfield
copy hfield to message
endfor
endfor
endfor
endfor
endfunction
function set_defaults ()
resolve_types ()
class.signature ?= 0
class.package_dir ?= "../include"
class.source_dir ?= "."
class.export_macro ?= ""
if class.export_macro <> ""
class.export_macro += " "
endif
for message
message.name = "$(message.name:c)"
for field
field.name = "$(field.name:c)"
if type = "number"
field.size ?= 1
if size = 1
field.ctype = "byte"
elsif size = 2
field.ctype = "uint16_t"
elsif size = 4
field.ctype = "uint32_t"
elsif size = 8
field.ctype = "uint64_t"
else
echo "E: bad size $(size) for $(name)"
endif
endif
for class.field as cfield where cfield.name = field.name
if cfield.type <> field.type
echo "E: field '$(name)' must have same type everywhere"
endif
else
copy field to class
endfor
endfor
endfor
endfunction
function resolve_types ()
for class.message
for field as original_field
for class.type where type.name = original_field.type
for type.field as type_field
new field before original_field
field.name = original_field.name + " " + type_field.name
field.type = type_field.type
field.size = type_field.size? 0
field. = type_field.?''
for original_field.test where test.name = type_field.name
copy test to field
endfor
endnew
endfor
delete original_field
endfor
endfor
endfor
endfunction
function resolve_includes ()
for class.include
if defined (include.filename)
my.include_file = class.load_file (filename)
if defined (my.include_file)
move my.include_file after include
else
echo "E: error loading include file: $(filename): $(xml.error?)"
endif
else
echo "E: required attribute 'filename' not defined"
endif
endfor
endfunction