gcc/testsuite/gm2/pim/run/pass/setcritical.mod
raw| 1 | (* Copyright (C) 2005 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 setcritical ; |
| 19 | |
| 20 | FROM libc IMPORT printf, exit ; |
| 21 | |
| 22 | TYPE |
| 23 | tokenum = (eoftok, plustok, minustok, timestok, dividetok, becomestok, ambersandtok, periodtok, commatok, semicolontok, lparatok, rparatok, lsbratok, rsbratok, lcbratok, rcbratok, uparrowtok, singlequotetok, equaltok, hashtok, lesstok, greatertok, lessgreatertok, lessequaltok, greaterequaltok, periodperiodtok, colontok, doublequotestok, bartok, andtok, arraytok, begintok, bytok, casetok, consttok, definitiontok, divtok, dotok, elsetok, elsiftok, endtok, exittok, exporttok, fortok, fromtok, iftok, implementationtok, importtok, intok, looptok, modtok, moduletok, nottok, oftok, ortok, pointertok, proceduretok, qualifiedtok, unqualifiedtok, recordtok, remtok, repeattok, returntok, settok, thentok, totok, typetok, untiltok, vartok, whiletok, withtok, asmtok, volatiletok, periodperiodperiodtok, datetok, linetok, filetok, attributetok, builtintok, integertok, identtok, realtok, stringtok) ; |
| 24 | |
| 25 | SetOfStop0 = SET OF [eoftok..begintok] ; |
| 26 | SetOfStop1 = SET OF [bytok..settok] ; |
| 27 | SetOfStop2 = SET OF [thentok..stringtok] ; |
| 28 | |
| 29 | VAR |
| 30 | e: INTEGER ; |
| 31 | |
| 32 | |
| 33 | (* |
| 34 | Assert - |
| 35 | *) |
| 36 | |
| 37 | PROCEDURE Assert (b: BOOLEAN; c: CARDINAL) ; |
| 38 | VAR |
| 39 | r: INTEGER ; |
| 40 | BEGIN |
| 41 | IF NOT b |
| 42 | THEN |
| 43 | r := printf("assert failed in sets, with bit %d\n", c) ; |
| 44 | e := 1 |
| 45 | END |
| 46 | END Assert ; |
| 47 | |
| 48 | PROCEDURE only0 (s: SetOfStop0; enumValue: tokenum) : BOOLEAN ; |
| 49 | VAR |
| 50 | i: tokenum ; |
| 51 | c: CARDINAL ; |
| 52 | BEGIN |
| 53 | (* just see if one bit has been set *) |
| 54 | i := eoftok ; |
| 55 | c := 0 ; |
| 56 | REPEAT |
| 57 | IF i IN s |
| 58 | THEN |
| 59 | INC(c) |
| 60 | END ; |
| 61 | INC(i) |
| 62 | UNTIL i>begintok ; |
| 63 | RETURN (c=1) AND (enumValue IN s) |
| 64 | END only0 ; |
| 65 | |
| 66 | PROCEDURE only1 (s: SetOfStop1; enumValue: tokenum) : BOOLEAN ; |
| 67 | VAR |
| 68 | i: tokenum ; |
| 69 | c: CARDINAL ; |
| 70 | BEGIN |
| 71 | (* just see if one bit has been set *) |
| 72 | i := bytok ; |
| 73 | c := 0 ; |
| 74 | REPEAT |
| 75 | IF i IN s |
| 76 | THEN |
| 77 | INC(c) |
| 78 | END ; |
| 79 | INC(i) |
| 80 | UNTIL i>settok ; |
| 81 | RETURN (c=1) AND (enumValue IN s) |
| 82 | END only1 ; |
| 83 | |
| 84 | PROCEDURE only2 (s: SetOfStop2; enumValue: tokenum) : BOOLEAN ; |
| 85 | VAR |
| 86 | i: tokenum ; |
| 87 | c: CARDINAL ; |
| 88 | BEGIN |
| 89 | (* just see if one bit has been set *) |
| 90 | i := thentok ; |
| 91 | c := 0 ; |
| 92 | FOR i := thentok TO stringtok DO |
| 93 | IF i IN s |
| 94 | THEN |
| 95 | INC(c) |
| 96 | END |
| 97 | END ; |
| 98 | RETURN (c=1) AND (enumValue IN s) |
| 99 | END only2 ; |
| 100 | |
| 101 | VAR |
| 102 | i : tokenum ; |
| 103 | s0: SetOfStop0 ; |
| 104 | s1: SetOfStop1 ; |
| 105 | s2: SetOfStop2 ; |
| 106 | BEGIN |
| 107 | e := 0 ; |
| 108 | s0 := SetOfStop0{} ; |
| 109 | s1 := SetOfStop1{} ; |
| 110 | s2 := SetOfStop2{} ; |
| 111 | FOR i := eoftok TO stringtok DO |
| 112 | IF ORD(i)<ORD(bytok) |
| 113 | THEN |
| 114 | INCL(s0, i) ; |
| 115 | Assert(only0(s0, i), ORD(i)) ; |
| 116 | EXCL(s0, i) |
| 117 | ELSIF ORD(i)<ORD(thentok) |
| 118 | THEN |
| 119 | INCL(s1, i) ; |
| 120 | Assert(only1(s1, i), ORD(i)) ; |
| 121 | EXCL(s1, i) |
| 122 | ELSE |
| 123 | INCL(s2, i) ; |
| 124 | Assert(only2(s2, i), ORD(i)) ; |
| 125 | EXCL(s2, i) |
| 126 | END |
| 127 | END ; |
| 128 | exit(e) |
| 129 | END setcritical. |