From c924a33a056a6385d2bacfc2aea02ad3409643ad Mon Sep 17 00:00:00 2001 From: David Brown Date: Sat, 1 Oct 2016 10:49:25 +0100 Subject: [PATCH] Better set constant checking. --- src/compiler/OPB.Mod | 13 +++++++------ src/compiler/OPC.Mod | 2 +- src/compiler/OPM.Mod | 2 -- src/system/SYSTEM.h | 1 + 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/OPB.Mod b/src/compiler/OPB.Mod index 17b4be1b..a6b8cf67 100644 --- a/src/compiler/OPB.Mod +++ b/src/compiler/OPB.Mod @@ -830,13 +830,14 @@ MODULE OPB; (* RC 6.3.89 / 21.2.94 *) (* object model 17.1.93 *) ELSIF x^.typ^.form # OPT.Int THEN err(93) ELSIF x^.class = OPT.Nconst THEN k := x^.conval^.intval; - IF (0 <= k) & (k <= MAX(SYSTEM.SET64)) THEN x^.conval^.setval := {k}; SetSetType(x) + IF (0 <= k) & (k <= MAX(SYSTEM.SET64)) THEN + x^.conval^.setval := {}; INCL(x.conval.setval, k); ELSE err(202) - END ; - x^.obj := NIL - ELSE Convert(x, OPT.settyp) (* todo choose appropriate set type ? *) + END; + SetSetType(x); x^.obj := NIL + ELSE + Convert(x, OPT.settyp); x^.typ := OPT.settyp END; - x^.typ := OPT.settyp (* todo choose appropriate set type ? *) END SetElem; PROCEDURE CheckAssign(x: OPT.Struct; ynode: OPT.Node); (* x := y *) @@ -994,7 +995,7 @@ MODULE OPB; (* RC 6.3.89 / 21.2.94 *) (* object model 17.1.93 *) OPT.Bool: x := NewBoolConst(TRUE) | OPT.Char: x := NewIntConst(0FFH); x^.typ := OPT.chartyp | OPT.Int: x := NewIntConst(OPM.SignedMaximum(x.typ.size)) - | OPT.Set: x := NewIntConst(OPM.MaxSet); x^.typ := OPT.inttyp + | OPT.Set: x := NewIntConst(x.typ.size*8-1); x^.typ := OPT.inttyp | OPT.Real: x := NewRealConst(OPM.MaxReal, OPT.realtyp) | OPT.LReal: x := NewRealConst(OPM.MaxLReal, OPT.lrltyp) ELSE err(111) diff --git a/src/compiler/OPC.Mod b/src/compiler/OPC.Mod index 06252183..72e13291 100644 --- a/src/compiler/OPC.Mod +++ b/src/compiler/OPC.Mod @@ -1228,7 +1228,7 @@ MODULE OPC; (* copyright (c) J. Templ 12.7.95 / 3.7.96 *) PROCEDURE Constant* (con: OPT.Const; form: INTEGER); VAR i: INTEGER; s: SYSTEM.SET64; - hex: LONGINT; skipLeading: BOOLEAN; + hex: SYSTEM.INT64; skipLeading: BOOLEAN; BEGIN CASE form OF | OPT.Byte: OPM.WriteInt(con^.intval) diff --git a/src/compiler/OPM.Mod b/src/compiler/OPM.Mod index 1af3cde7..be89719c 100644 --- a/src/compiler/OPM.Mod +++ b/src/compiler/OPM.Mod @@ -93,7 +93,6 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) ShortintSize*, IntegerSize*, LongintSize*, SetSize*: INTEGER; - MaxSet*: INTEGER; MaxIndex*: SYSTEM.INT64; MinReal*, MaxReal*, MinLReal*, MaxLReal*: LONGREAL; @@ -344,7 +343,6 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *) |'V': ShortintSize := 1; IntegerSize := 4; LongintSize := 8; SetSize := 8 ELSE ShortintSize := 1; IntegerSize := 2; LongintSize := 4; SetSize := 4 END; - MaxSet := SetSize * 8 - 1; IF verbose IN Options THEN VerboseListSizes END; diff --git a/src/system/SYSTEM.h b/src/system/SYSTEM.h index 7c55807b..4e1bfe18 100644 --- a/src/system/SYSTEM.h +++ b/src/system/SYSTEM.h @@ -229,6 +229,7 @@ static inline double SYSTEM_ABSD(double i) {return i >= 0.0 ? i : -i;} #define __ODD(x) ((x)&1) #define __IN(x, s, size) (((unsigned int)(x))>(x))&1)) +// todo tested versions of SETOF and SETRNG: check that x, l and h fit size #define __SETOF(x, size) ((uint##size)1<<(x)) #define __SETRNG(l, h, size) ((~(uint##size)0<<(l))&~(uint##size)0>>(size-1-(h)))