Better set constant checking.

This commit is contained in:
David Brown 2016-10-01 10:49:25 +01:00
parent d344c9ce80
commit c924a33a05
4 changed files with 9 additions and 9 deletions

View file

@ -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^.typ^.form # OPT.Int THEN err(93)
ELSIF x^.class = OPT.Nconst THEN ELSIF x^.class = OPT.Nconst THEN
k := x^.conval^.intval; 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) ELSE err(202)
END; END;
x^.obj := NIL SetSetType(x); x^.obj := NIL
ELSE Convert(x, OPT.settyp) (* todo choose appropriate set type ? *) ELSE
Convert(x, OPT.settyp); x^.typ := OPT.settyp
END; END;
x^.typ := OPT.settyp (* todo choose appropriate set type ? *)
END SetElem; END SetElem;
PROCEDURE CheckAssign(x: OPT.Struct; ynode: OPT.Node); (* x := y *) 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.Bool: x := NewBoolConst(TRUE)
| OPT.Char: x := NewIntConst(0FFH); x^.typ := OPT.chartyp | OPT.Char: x := NewIntConst(0FFH); x^.typ := OPT.chartyp
| OPT.Int: x := NewIntConst(OPM.SignedMaximum(x.typ.size)) | 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.Real: x := NewRealConst(OPM.MaxReal, OPT.realtyp)
| OPT.LReal: x := NewRealConst(OPM.MaxLReal, OPT.lrltyp) | OPT.LReal: x := NewRealConst(OPM.MaxLReal, OPT.lrltyp)
ELSE err(111) ELSE err(111)

View file

@ -1228,7 +1228,7 @@ MODULE OPC; (* copyright (c) J. Templ 12.7.95 / 3.7.96 *)
PROCEDURE Constant* (con: OPT.Const; form: INTEGER); PROCEDURE Constant* (con: OPT.Const; form: INTEGER);
VAR i: INTEGER; s: SYSTEM.SET64; VAR i: INTEGER; s: SYSTEM.SET64;
hex: LONGINT; skipLeading: BOOLEAN; hex: SYSTEM.INT64; skipLeading: BOOLEAN;
BEGIN BEGIN
CASE form OF CASE form OF
| OPT.Byte: OPM.WriteInt(con^.intval) | OPT.Byte: OPM.WriteInt(con^.intval)

View file

@ -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; ShortintSize*, IntegerSize*, LongintSize*, SetSize*: INTEGER;
MaxSet*: INTEGER;
MaxIndex*: SYSTEM.INT64; MaxIndex*: SYSTEM.INT64;
MinReal*, MaxReal*, MinLReal*, MaxLReal*: LONGREAL; 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 |'V': ShortintSize := 1; IntegerSize := 4; LongintSize := 8; SetSize := 8
ELSE ShortintSize := 1; IntegerSize := 2; LongintSize := 4; SetSize := 4 ELSE ShortintSize := 1; IntegerSize := 2; LongintSize := 4; SetSize := 4
END; END;
MaxSet := SetSize * 8 - 1;
IF verbose IN Options THEN VerboseListSizes END; IF verbose IN Options THEN VerboseListSizes END;

View file

@ -229,6 +229,7 @@ static inline double SYSTEM_ABSD(double i) {return i >= 0.0 ? i : -i;}
#define __ODD(x) ((x)&1) #define __ODD(x) ((x)&1)
#define __IN(x, s, size) (((unsigned int)(x))<size && ((((uint##size)(s))>>(x))&1)) #define __IN(x, s, size) (((unsigned int)(x))<size && ((((uint##size)(s))>>(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 __SETOF(x, size) ((uint##size)1<<(x))
#define __SETRNG(l, h, size) ((~(uint##size)0<<(l))&~(uint##size)0>>(size-1-(h))) #define __SETRNG(l, h, size) ((~(uint##size)0<<(l))&~(uint##size)0>>(size-1-(h)))