Debian Codegraph @

gcc/testsuite/gm2/iso/run/pass/adrunbounded3.mod

raw
1 (* Copyright (C) 2018 Free Software Foundation, Inc. *)
2 (* This file is part of GNU Modula-2.
3
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 3, or (at your option) any later
7 version.
8
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with gm2; see the file COPYING. If not, write to the Free Software
16 Foundation, 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA. *)
18
19 MODULE adrunbounded3 ;
20
21 FROM libc IMPORT printf, exit ;
22 FROM SYSTEM IMPORT ADDRESS, ADR ;
23
24
25 CONST
26 MaxDim = 3 ;
27
28 TYPE
29 Vector = ARRAY [1..MaxDim] OF REAL;
30 Matrix = ARRAY [1..MaxDim] OF Vector;
31
32
33 (*
34 assert -
35 *)
36
37 PROCEDURE assert (b: BOOLEAN; file: ARRAY OF CHAR; line: CARDINAL; message: ARRAY OF CHAR) ;
38 BEGIN
39 IF NOT b
40 THEN
41 printf ("%s:%d: assert failed: %s\n", file, line, message) ;
42 exit (1)
43 END
44 END assert ;
45
46
47 (*
48 inner -
49 *)
50
51 PROCEDURE inner (VAR m: ARRAY OF REAL) ;
52 VAR
53 b: ADDRESS ;
54 BEGIN
55 b := ADR (m) ;
56 assert (a = b, __FILE__, __LINE__, "a = b")
57 END inner ;
58
59
60 (*
61 test -
62 *)
63
64 PROCEDURE test (VAR m: ARRAY OF ARRAY OF REAL) ;
65 VAR
66 u0, u1, u2: ADDRESS ;
67 i : CARDINAL ;
68 BEGIN
69 u0 := ADR (m) ;
70 assert (a0 = u0, __FILE__, __LINE__, "a0 = u0") ;
71 u1 := ADR (m[0]) ;
72 assert (a0 = u1, __FILE__, __LINE__, "a0 = u1") ;
73 u2 := ADR (m[0][0]) ;
74 assert (a0 = u2, __FILE__, __LINE__, "a0 = u2") ;
75 FOR i := 0 TO MaxDim-1 DO
76 a := ADR (m[i]) ;
77 printf ("a = %p\n", a) ;
78 inner (m[i])
79 END
80 END test ;
81
82
83 VAR
84 m : Matrix ;
85 a, a0, a1, a2: ADDRESS ;
86 BEGIN
87 a0 := ADR (m) ;
88 a1 := ADR (m[1]) ;
89 a2 := ADR (m[1][1]) ;
90 assert (a0 = a1, __FILE__, __LINE__, "a0 = a1") ;
91 assert (a0 = a2, __FILE__, __LINE__, "a0 = a2") ;
92 test (m)
93 END adrunbounded3.