-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildDispatcher.py
169 lines (126 loc) · 4.29 KB
/
BuildDispatcher.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
162
163
164
165
166
167
168
169
from os.path import *
import glob
import re
names = []
matcher = re.compile(r"package\s+NMEA.Messages.(\S+)\s+is")
for path in glob.glob("src/messages/*.ads"):
with open(path) as inf:
for line in inf:
m = matcher.match(line)
if m:
names.append(m.group(1))
names.sort()
HEADER = """-- ----------------------------------------------------------------------------
--
-- Do not edit since this is generated code.
--
-- ----------------------------------------------------------------------------
"""
TEST_HEADER = """-- ----------------------------------------------------------------------------
--
-- Generated test application to be used as sample or baseline.
--
-- ----------------------------------------------------------------------------
"""
IMPORT = "with NMEA.Messages.%(name)s;"
CALL = """ procedure On_%(name)s (Self : in out Application_Interface;
Message : NMEA.Messages.%(name)s.%(name)s_Message) is null;
"""
TEST_CALL = """
overriding
procedure On_%(name)s (Self : in out Application;
Message : NMEA.Messages.%(name)s.%(name)s_Message);"""
TEST_PROCEDURE = """
overriding
procedure On_%(name)s (Self : in out Application;
Message : NMEA.Messages.%(name)s.%(name)s_Message) is
pragma Unreferenced (Self);
begin
Put_Line ("---------------------------------------------------");
Put_Line (Enclosing_Entity);
Put_Line (Message.Image);
Put_Line ("---------------------------------------------------");
end On_%(name)s;"""
SPEC = HEADER + """
%(imports)s
package NMEA.Abstract_Application is
type Application_Interface is limited interface;
%(calls)s
procedure Dispatch (App : in out Application_Interface'Class; Message : NMEA.Messages.Message'Class);
end NMEA.Abstract_Application;
"""
DISPATCH = """ elsif Message_Tag = NMEA.Messages.%(name)s.%(name)s_Message'Tag then
App.On_%(name)s (NMEA.Messages.%(name)s.%(name)s_Message (Message));"""
BODY = HEADER + """
with Ada.Tags; use Ada.Tags;
package body NMEA.Abstract_Application is
pragma Suppress_All;
pragma Warnings (Off);
--------------
-- Dispatch --
--------------
procedure Dispatch
(App : in out Application_Interface'Class;
Message : NMEA.Messages.Message'Class)
is
Message_Tag : constant Ada.Tags.Tag := Message'Tag;
begin
if False then
null;
%(dispatch)s
else
null;
end if;
end Dispatch;
end NMEA.Abstract_Application;
"""
TEST_SPEC = TEST_HEADER + """
%(imports)s
with Ada.Finalization;
with NMEA.Abstract_Application;
package NMEA.Tests.Test_Application is
type Application is new Ada.Finalization.Controlled and
NMEA.Abstract_Application.Application_Interface with
record
null;
end record;
function Is_Active (Self : Application) return Boolean;
%(calls)s
end NMEA.Tests.Test_Application;
"""
TEST_BODY = TEST_HEADER + """
with Ada.Text_IO;
with GNAT.Source_Info;
package body NMEA.Tests.Test_Application is
use Ada.Text_IO;
use GNAT.Source_Info;
function Is_Active (Self : Application) return Boolean is
pragma Unreferenced (Self);
begin
return True;
end Is_Active;
%(test_procedures)s
end NMEA.Tests.Test_Application;
"""
dispatch = []
imports = []
calls = []
test_calls = []
test_procedures=[]
for name in names:
imports.append(IMPORT % {"name": name})
calls.append(CALL % {"name": name})
test_calls.append(TEST_CALL % {"name": name})
dispatch.append(DISPATCH % {"name": name})
test_procedures.append(TEST_PROCEDURE % {"name": name})
with file("src/nmea-abstract_application.ads", "w") as spec:
spec.write(SPEC % {"imports": "\n".join(imports),
"calls": "\n".join(calls)})
with file("src/nmea-abstract_application.adb", "w") as body:
body.write(BODY % {"dispatch": "\n".join(dispatch)})
with file("tests/nmea-tests-test_application.ads", "w") as spec:
spec.write(TEST_SPEC % {"imports": "\n".join(imports),
"calls": "\n".join(test_calls)})
with file("tests/nmea-tests-test_application.adb", "w") as body:
body.write(TEST_BODY % {"imports": "\n".join(imports),
"test_procedures": "\n".join(test_procedures)})