Debian Codegraph @

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

raw
1 (* Copyright (C) 2009 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 2, 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, Boston, MA 02110-1301, USA. *)
17
18 MODULE unbounded ;
19
20 FROM libc IMPORT exit, printf ;
21 FROM SYSTEM IMPORT ADR ;
22
23
24 PROCEDURE Assert (b: BOOLEAN; f: ARRAY OF CHAR; l: CARDINAL) ;
25 BEGIN
26 IF NOT b
27 THEN
28 printf ("%s:%d:failure\n", ADR (f), l) ;
29 exit (1)
30 END
31 END Assert ;
32
33
34 PROCEDURE test (VAR a: ARRAY OF ARRAY OF CHAR) ;
35 VAR
36 m, n: CARDINAL ;
37 BEGIN
38 m := HIGH (a) ;
39 n := HIGH (a[0]) ;
40 printf ("m = %d, n = %d\n", m, n);
41 a[1, 2] := 'a' ;
42 a[2, 1] := 'c'
43 END test ;
44
45
46 VAR
47 b : ARRAY [0..4], [0..5] OF CHAR ;
48 i, j: CARDINAL ;
49 BEGIN
50 FOR i := 0 TO 4 DO
51 FOR j := 0 TO 5 DO
52 b[i, j] := 'z'
53 END
54 END ;
55 test (b) ;
56 FOR i := 0 TO 4 DO
57 FOR j := 0 TO 5 DO
58 IF (i = 1) AND (j = 2)
59 THEN
60 Assert (b[1, 2] = 'a', __FILE__, __LINE__)
61 ELSIF (i = 2) AND (j = 1)
62 THEN
63 Assert (b[2, 1] = 'c', __FILE__, __LINE__)
64 ELSE
65 Assert (b[i, j] = 'z', __FILE__, __LINE__)
66 END
67 END
68 END
69 END unbounded.