-
Notifications
You must be signed in to change notification settings - Fork 15
/
TestImport.Mod
366 lines (295 loc) · 12.1 KB
/
TestImport.Mod
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
--------------------------- Preparation for subsequent test suites ----------
ORP.Compile @/s ~
MODULE M0; (*no error message*)
TYPE T0* = RECORD i: INTEGER END ;
END M0.
MODULE M1; (*no error message*)
TYPE T0* = RECORD i: INTEGER END ;
END M1.
MODULE M2; (*no error message*)
IMPORT M1;
TYPE T1* = RECORD (M1.T0) j: INTEGER END ;
VAR a: M1.T0; b: T1;
BEGIN a := b
END M2.
MODULE M3; (*no error message*)
IMPORT M0, M1, M2;
TYPE T2* = RECORD (M0.T0) k: INTEGER END ;
END M3.
MODULE M4; (*no error message*)
TYPE T3* = POINTER TO R3;
R3* = RECORD i: INTEGER END ;
END M4.
MODULE M5; (*no error message*)
IMPORT M4;
TYPE T4* = POINTER TO R4;
R4* = RECORD (M4.R3) j: INTEGER END ;
VAR a: M4.T3; b: T4;
BEGIN a := b
END M5.
MODULE M6; (*no error message*)
TYPE A* = RECORD i: INTEGER END ;
B* = A;
END M6.
MODULE M7; (*no error message*)
IMPORT M6;
VAR a*: M6.A; (*re-exports M6.A, but not M6.B*)
END M7.
MODULE M8; (*no error message*)
IMPORT M7, M6; (*M7 re-imports M6.A*)
VAR a*: M6.A; b*: M6.B;
BEGIN a := b
END M8.
--------------------------- Test suite A ------------------------------------
ORP.Compile @/s ~
MODULE A0; (*no error message*)
IMPORT M1, X := M2;
END A0.
MODULE A1; (*no error message, M0 imported under alias M1, M0 then reused as alias for M2*)
IMPORT M1 := M0, M0 := M2;
END A1.
MODULE A2; (*no error message, M0 imported under alias M1, M0 then reused as alias for M1 itself*)
IMPORT M1 := M0, M0 := M1;
END A2.
MODULE A3; (*no error message, M0 imported under alias M1, M1 then imported under another alias X*)
IMPORT M1 := M0, X := M1;
END A3.
MODULE A4; (*no error message, M0 imported under alias M1, M1 then imported under alias M0 => same as A2*)
IMPORT M1 := M0, M0 := M1;
END A4.
MODULE A5; (*no error message, M1 first explicitly imported, then re-imported by M2*)
IMPORT M1, M2;
END A5.
MODULE A6; (*no error message, M1 first explicitly imported, then re-imported by M2*)
IMPORT M0 := M1, M2;
END A6.
MODULE A7; (*no error message, M1 first re-imported by M2, then M0 explicitly imported under an alias M1*)
IMPORT M2, M1 := M0;
END A7.
--------------------------- Test suite B --------------------------------------
ORP.Compile @/s ~
MODULE B1; (*no error message*)
IMPORT M2;
TYPE T2* = RECORD (M2.T1) ch: CHAR END ; (*re-imports the type M1.T0, but module M1 remains invisible*)
VAR a: M2.T1; b: T2;
M1: INTEGER;
BEGIN a := b
END B1.
MODULE B2; (*no error message*)
IMPORT M2;
TYPE T2* = RECORD (M2.T1) ch: CHAR END ; (*re-imports the type M1.T0, but module M1 remains invisible*)
M1 = RECORD x: INTEGER END ;
T3 = POINTER TO M1;
VAR a: M2.T1; b: T2;
BEGIN a := b
END B2.
MODULE B3; (*no error message*)
IMPORT M0 := M1, M2;
VAR a: M0.T0; b: M2.T1;
BEGIN a := b
END B3.
MODULE B4; (*no error message*)
IMPORT M0 := M1, M1 := M2;
VAR a: M0.T0; b: M1.T1;
BEGIN a := b
END B4.
MODULE B5; (*no error message*)
IMPORT Y1 := M1, M2;
VAR a: Y1.T0; b: M2.T1;
BEGIN a := b
END B5.
MODULE B6; (*no error message*)
IMPORT D := Display, Oberon; (*module Display is explicitly imported before it is re-imported by module Oberon*)
VAR m1: D.FrameMsg; m2: Oberon.InputMsg;
PROCEDURE Handle(V: D.Frame; VAR M: D.FrameMsg);
BEGIN
CASE M OF
Oberon.InputMsg: m2 := M |
D.FrameMsg: m1 := M
END
END Handle;
END B6.
MODULE B7; (*no error message*)
IMPORT M2, M1 := M0; (*M2 re-imports M1, but there is no conflict with the alias name M1*)
VAR a: M1.T0; b: M2.T1;
BEGIN (*a := b*) (*this, however, WOULD be an illegal assignment, because M1.T0 is in fact M0.T0 here*)
END B7.
MODULE B8; (*no error mesage*)
IMPORT M1 := M0, M2; (*M2 re-imports M1, but there is no conflict with the alias name M1*)
VAR a: M1.T0; b: M2.T1;
BEGIN (*a := b*) (*this, however, WOULD be an illegal assignment, because M1.T0 is in fact M0.T0 here*)
END B8.
--------------------------- Test suite C ------------------------------------
ORP.Compile @/s ~
MODULE C1; (*no error message*)
IMPORT M1, M2;
VAR a: M1.T0; b: M2.T1;
BEGIN a := b
END C1.
MODULE C2; (*no error message*)
IMPORT M2, M1; (*M1 is first-reimported by M2, then M1 is explicitly imported*)
VAR a: M1.T0; b: M2.T1;
BEGIN a := b
END C2.
MODULE C3; (*no error message*)
IMPORT M4, M5;
VAR a: M4.T3; b: M5.T4;
BEGIN a := b
END C3.
MODULE C4; (*no error message*)
IMPORT M5, M4; (*M4 is first-reimported by M5, then M4 is explicitly imported*)
VAR a: M4.T3; b: M5.T4;
BEGIN a := b
END C4.
---------------------------------------------------------------
MODULE C5;
TYPE T5* = RECORD END ;
END C5.
MODULE C6;
IMPORT C5; (*this imports C5.T5*)
TYPE T6* = RECORD END ;
T5Alias1* = C5.T5; (*this re-exports C5.T5 to clients of C6*)
VAR r2*: C5.T5; (*this also re-exports C5.T5 to clients of C6*)
END C6.
MODULE C7;
IMPORT C6; (*this re-imports C5.T5, even though C7 does not explicitly import C5*)
TYPE T5Alias2* = C6.T5Alias1; (*this re-exports the original type C5.T5*)
VAR r3*: C6.T5Alias1; (*this also re-exports the original type C5.T5*)
r4*: T5Alias2; (*this also re-exports the original type C5.T5*)
END C7.
MODULE C8;
IMPORT C7; (*this re-imports C5.T5, even though C8 does not explicitly import C5*)
VAR r4*: C7.T5Alias2; (*this re-exports the original type C5.T5*)
END C8.
ORP.Compile @/s ~
ORTool.DecSym C5.smb ~ # shows C5.T5
ORTool.DecSym C6.smb ~ # shows C5.T5
ORTool.DecSym C7.smb ~ # shows C5.T5
ORTool.DecSym C8.smb ~ # shows C5.T5
--------------------------- Test suite D (should produce error messages) ------------------------------------
ORP.Compile @/s ~
MODULE D1;
IMPORT M0, M0; (*mult def*)
END D1.
MODULE D2;
IMPORT M0, M0 := M1; (*mult def*)
END D2.
MODULE D3;
IMPORT M0 := M1, M0; (*mult def*)
END D3.
MODULE D4;
IMPORT M0 := M1, M0 := M1; (*mult def*)
END D4.
MODULE D5;
IMPORT X := M0, X := M1; (*mult def*)
END D5.
MODULE D6;
IMPORT M0, X := M0; (*mult def*)
END D6.
MODULE D7;
IMPORT X := M0, M0; (*mult def*)
END D7.
MODULE D8;
IMPORT X := M0, Y := M0; (*mult def*)
END D8.
MODULE D9;
IMPORT M0, X := M0, Y := M0; (*2x mult def*)
END D9.
--------------------------- Test suite E (should produce error messages) ------------------------------------
ORP.Compile @/s ~
MODULE E1; (*mult def*)
IMPORT M0 := M1, M1; (*because a module M1 is imported under *two* different names M0 and M1*)
VAR a: M0.T0; b: M1.T0;
BEGIN a := b
END E1.
MODULE E2; (*mult def*)
IMPORT M0 := M1, M3, M0; (*because the name M0 is used twice, once as an alias, once as a module name*)
TYPE T3* = RECORD (M3.T2) ch: CHAR END ;
VAR a: M3.T2; b: T3; c: M0.T0;
BEGIN a := b; c := b
END E2.
MODULE E3; (*mult def*)
IMPORT M0 := M1, M0 := M3; (*because the name M0 is used twice as an alias*)
END E3.
MODULE E4; (*mult def*)
IMPORT M0, M0 := M1, M3; (*because the name M0 is used twice, once as an alias, once as a module name*)
TYPE T3* = RECORD (M3.T2) ch: CHAR END ;
VAR a: M3.T2; b: T3; c: M0.T0;
BEGIN a := b; c := b
END E4.
MODULE E5; (*mult def*)
IMPORT M2, M1 := M0, M1; (*M2 re-imports M1, no conflict with alias name M1, but conflict with explicit import M1*)
VAR a: M1.T0; b: M2.T1; (*Note:the direct import of M1 converts a previous re-import of M1 into an explicit one*)
END E5. (*This must be detected: after the conversion, M1 is an explicit import, THEN conflict with M1*)
--------------------------- Test suite F (should produce error messages) ------------------------------------
ORP.Compile @/s ~
MODULE F1;
TYPE T = RECORD i, j*: INTEGER END ; (*invalid field export of field j*)
V* = T; (*type T not exported*)
R* = RECORD a*, b*: T END ; (*type T not exported*)
VAR c, d: T;
e*, f: T; (*type T not exported*)
g*, h*: RECORD i, j*, k*: INTEGER END ;
m, n*: RECORD i, j*, k*: INTEGER END ; (*invalid field export*)
END F1.
MODULE F2;
TYPE T1 = RECORD i*, j: INTEGER END ; (*invalid field export of field i*)
T2* = RECORD i*, j: T1 END ; (*type T1 not exported*)
T3* = RECORD i*, j: CHAR END;
T4* = RECORD i: CHAR;
j*: RECORD
s*: RECORD u*: T1 END ; (*type T1 not exported*)
END ;
k: RECORD
m*: INTEGER; (*invalid field export of field m, because k is not exported*)
n: RECORD p*: T1 END ; (*invalid field export of field p because k and n are nor exported, type T1 not exported*)
END ;
q*: RECORD
r*, s: INTEGER;
t*: RECORD u*: T1 END ; (*type T1 not exported*)
END ;
END ;
P1* = POINTER TO T1; (*type T1 not exported*)
VAR a*: T1; (*type T1 not exported*)
b*, c*: RECORD i*, j: T1 END ; (*type T1 not exported*)
END F2.
MODULE F3;
TYPE T1 = RECORD i*, j: INTEGER END ; (*invalid field export of field i*)
T2* = ARRAY 2 OF ARRAY 4 OF
RECORD i*, j: T1 END ; (*type T1 not exported*)
P1* = POINTER TO T1; (*type T1 not exported*)
P2* = POINTER TO T2;
P3 = POINTER TO T2;
T3* = RECORD p1: T1;
q*: RECORD r*: P1 END ;
s*: RECORD t*: P3 END ; (*type P3 not exported*)
END ;
END F3.
MODULE F4;
TYPE R = RECORD i: INTEGER END ;
A* = ARRAY 10 OF R; (*type R not exported*)
VAR a*, b: ARRAY 10 OF R; (*type R not exported*)
END F4.
MODULE F5;
TYPE T = RECORD k: INTEGER END ;
VAR a*: RECORD
b: RECORD
c*: RECORD x: T END ; (*invalid field exxport*)
d: RECORD y*: T END ; (*invalid field export*)
e: ARRAY 10 OF T;
END ;
m*: RECORD
p: RECORD y*: T END ; (*invalid field export*)
q*: ARRAY 10 OF T; (*type T must be exported*)
END ;
END ;
END F5.
---------- Note: The following is allowed ----------
MODULE F6;
TYPE P* = POINTER TO R;
R = RECORD i: INTEGER END ; (*this is allowed*)
VAR a, b*: POINTER TO R; (*this is allowed*)
END F6.
ORP.Compile @/s ~
F4.Go ~
System.Free F4 ~