-
Notifications
You must be signed in to change notification settings - Fork 12
/
rename.py
161 lines (140 loc) · 7.46 KB
/
rename.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python
# ---------------------------------------------------------------------------
# Copyright (C) 2020-2030, [email protected]
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and / or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions :
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# ---------------------------------------------------------------------------
import sys
import re
from os.path import *
header = """-------------------------------------------------------------------------------
-- --
-- 0MQ Ada-binding --
-- --
-- Z M Q . L O W _ L E V E L --
-- --
-- S p e c --
-- --
-- Copyright (C) 2020-2030, [email protected] --
-- --
-- Permission is hereby granted, free of charge, to any person obtaining a --
-- copy of this software and associated documentation files --
-- (the "Software"), to deal in the Software without restriction, including --
-- without limitation the rights to use, copy, modify, merge, publish, --
-- distribute, sublicense, and / or sell copies of the Software, and to --
-- permit persons to whom the Software is furnished to do so, subject to --
-- the following conditions : --
-- --
-- The above copyright notice and this permission notice shall be included --
-- in all copies or substantial portions of the Software. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
-- MERCHANTABILITY, --
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL --
-- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR --
-- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, --
-- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR --
-- OTHER DEALINGS IN THE SOFTWARE. --
-------------------------------------------------------------------------------
--
-- The contents of this file is derived from zmq.h using the
-- -fdump-ada-spec switch for gcc.
"""
renames = [["stddef_h.size_t", "size_t"],
["with stddef_h;", ""],
["with bits_stdint_uintn_h;", ""],
["with stdint_h;", " with Interfaces.C.Extensions;"],
["stdint_h.uint16_t", "Extensions.Unsigned_16"],
["stdint_h.int32_t", "Extensions.Signed_32"],
["stdint_h.uint8_t", "Extensions.Unsigned_8"],
["bits_stdint_uintn_h.uint32_t", "Interfaces.Unsigned_32"],
["bits_stdint_uintn_h.uint16_t", "Interfaces.Unsigned_16"],
["bits_stdint_uintn_h.uint8_t", "Interfaces.Unsigned_8"],
["package zmq_h is", """package ZMQ.Low_Level is
pragma Preelaborate;
pragma Warnings (Off);
package Defs is
-- This package is here to give a namespace to constants, since
-- identifiers in Ada are caseinsensetive.
"""],
["function zmq_errno", """ end Defs;
function zmq_errno"""],
["--**", "-- **"],
[" zmq_h ", " ZMQ.Low_Level "],
[" zmq_h;", " ZMQ.Low_Level;"]]
obslolete_functions = ["zmq_ctx_shutdown",
"zmq_ctx_term",
"zmq_term",
"zmq_sendmsg",
"zmq_recvmsg"]
def main(path):
dumped = False
with open(path) as f:
buffer = f.read()
for i in renames:
buffer = buffer.replace(i[0], i[1])
buffer = buffer.split("\n")
include_matcher = re.compile("(.+-- +)(/.+/include/)(.*)")
# -- unsupported macro: EFSM (ZMQ_HAUSNUMERO + 51)
e_matcher = re.compile(r""".+unsupported macro: (\w+) \((\w+) \+ (\w+)\).*""")
# -- unsupported macro: ZMQ_XREQ ZMQ_DEALER
r_matcher = re.compile(r""".+unsupported macro: (\w+) (\w+)$""")
for i in range(0, len(buffer)):
m = include_matcher.match(buffer[i])
if m:
buffer[i] = m.group(1) + m.group(3)
m = e_matcher.match(buffer[i])
if m:
buffer[i] = "%s : constant := %s + %s;" % (m.group(1), m.group(2), m.group(3))
m = r_matcher.match(buffer[i])
if m:
buffer[i] = "%s : constant := %s;" % (m.group(1), m.group(2))
for obslolete in obslolete_functions:
pattern = r'^.*pragma Import *\(C, *(%s), *"%s"\);' %\
(obslolete, obslolete)
if not dumped:
print (pattern)
matcher = re.compile(pattern)
if matcher.match(buffer[i]):
buffer[i] = " pragma Obsolescent;\n%s" % buffer[i]
dumped = True
buffer = "\n".join(buffer)
with open(path, "w") as f:
f.write(header)
f.write(buffer)
if not exists("zmq-case_exceptions.xml"):
matcher = re.compile(r"\w+ (zmq_\w+) .*")
with open("zmq-case_exceptions.xml", "w") as outf:
outf.write("""<?xml version="1.0" ?>
<exceptions>
<case_exceptions>
""")
with open(path) as inf:
for line in inf:
line = line.strip()
m = matcher.match(line)
if m:
outf.write(" <word>%s</word>\n" % m.group(1))
outf.write(""" </case_exceptions>
</exceptions>""")
if __name__ == "__main__":
main(sys.argv[1])