Prepare for typ.size aware version of OPV.Convert

This commit is contained in:
David Brown 2016-08-21 14:26:12 +01:00
parent c1228e4ae0
commit 731f2215aa
198 changed files with 368 additions and 334 deletions

View file

@ -574,29 +574,6 @@ MODULE OPC; (* copyright (c) J. Templ 12.7.95 / 3.7.96 *)
END
END Align;
(*
PROCEDURE Base0(typ: OPT.Struct): LONGINT;
BEGIN
CASE typ^.form OF
| OPM.Byte: RETURN 1
| OPM.Char: RETURN OPM.CharAlign
| OPM.Bool: RETURN OPM.BoolAlign
| OPM.SInt: RETURN OPM.SIntAlign
| OPM.Int: RETURN OPM.IntAlign
| OPM.LInt: RETURN OPM.LIntAlign
| OPM.Real: RETURN OPM.RealAlign
| OPM.LReal: RETURN OPM.LRealAlign
| OPM.Set: RETURN OPM.SetAlign
| OPM.Pointer: RETURN OPM.PointerAlign
| OPM.ProcTyp: RETURN OPM.ProcAlign
| OPM.Comp: IF typ^.comp = OPM.Record THEN RETURN typ^.align MOD 10000H
ELSE RETURN Base0(typ^.BaseTyp)
END
ELSE OPM.LogWStr("unhandled case in OPC.BaseAlignment, typ^form = "); OPM.LogWNum(typ^.form, 0); OPM.LogWLn;
END
END Base0;
*)
PROCEDURE SizeAlignment*(size: LONGINT): LONGINT;
VAR alignment: LONGINT;
BEGIN
@ -619,16 +596,7 @@ MODULE OPC; (* copyright (c) J. Templ 12.7.95 / 3.7.96 *)
alignment := BaseAlignment(typ.BaseTyp)
END
ELSE
(* Not a compound type, determine alignment from size *)
alignment := SizeAlignment(typ.size)
(*
IF alignment # Base0(typ) THEN
OPM.LogWStr("BaseAlignment. typ.form "); OPM.LogWNum(typ.form,1);
OPM.LogWStr(", typ.size "); OPM.LogWNum(typ.size,1);
OPM.LogWStr(", old alignment "); OPM.LogWNum(alignment,1);
OPM.LogWStr(", alignment based on size "); OPM.LogWNum(align,1); OPM.LogWLn
END;
*)
END;
RETURN alignment
END BaseAlignment;

View file

@ -717,33 +717,6 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *)
LIntSize := IntSize * 2;
SetSize := LIntSize;
(* Calculate all type alignments *)
(*
CharAlign := AlignSize(CharSize);
BoolAlign := AlignSize(BoolSize);
SIntAlign := AlignSize(SIntSize);
RecAlign := AlignSize(RecSize);
RealAlign := AlignSize(RealSize);
LRealAlign := AlignSize(LRealSize);
PointerAlign := AlignSize(PointerSize);
ProcAlign := AlignSize(ProcSize);
IntAlign := AlignSize(IntSize);
LIntAlign := AlignSize(LIntSize);
SetAlign := AlignSize(SetSize);
*)
(*
base := -2;
MinSInt := ASH(base, SIntSize*8-2);
MaxSInt := minusop(MinSInt + 1);
MinInt := ASH(base, IntSize*8-2);
MaxInt := minusop(MinInt + 1);
MinLInt := ASH(base, LIntSize*8-2);
MaxLInt := minusop(MinLInt +1);
*)
IF RealSize = 4 THEN MaxReal := 3.40282346D38
ELSIF RealSize = 8 THEN MaxReal := 1.7976931348623157D307 * 9.999999
(*should be 1.7976931348623157D308 *)
@ -754,13 +727,9 @@ MODULE OPM; (* RC 6.3.89 / 28.6.89, J.Templ 10.7.89 / 22.7.96 *)
(*should be 1.7976931348623157D308 *)
END ;
MinReal := -MaxReal;
MinReal := -MaxReal;
MinLReal := -MaxLReal;
MaxSet := SetSize * 8 - 1;
(*
MaxIndex := MaxLInt; (* shouldn't it be like max(int)? so that for loop will be safe, noch *)
*)
MaxSet := SetSize * 8 - 1;
MaxIndex := SignedMaximum(PointerSize);
IF Verbose THEN VerboseListSizes END;

View file

@ -290,14 +290,23 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
END
END Entier;
PROCEDURE Convert(n: OPT.Node; form, prec: INTEGER);
VAR from: INTEGER;
BEGIN from := n^.typ^.form;
IF form = OPM.Set THEN OPM.WriteString(SetOfFunc); Entier(n, MinPrec); OPM.Write(CloseParen)
ELSIF form = OPM.LInt THEN
PROCEDURE SizeCast(size: LONGINT);
BEGIN
IF size <= OPM.SIntSize THEN OPM.WriteString("(SHORTINT)")
ELSIF size <= OPM.IntSize THEN OPM.WriteString("(INTEGER)")
ELSE OPM.WriteString("(LONGINT)")
END
END SizeCast;
PROCEDURE Convert(n: OPT.Node; typ: OPT.Struct; prec: INTEGER);
VAR from, to: INTEGER;
BEGIN from := n^.typ^.form; to := typ.form;
IF to = OPM.Set THEN OPM.WriteString(SetOfFunc); Entier(n, MinPrec); OPM.Write(CloseParen)
ELSIF to = OPM.LInt THEN
IF from < OPM.LInt THEN OPM.WriteString("(LONGINT)") END ;
Entier(n, 9)
ELSIF form = OPM.Int THEN
ELSIF to = OPM.Int THEN
IF from < OPM.Int THEN OPM.WriteString("(int)"); expr(n, 9)
ELSE
IF OPM.ranchk IN OPM.opt THEN OPM.WriteString("__SHORT");
@ -307,14 +316,37 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
ELSE OPM.WriteString("(int)"); Entier(n, 9)
END
END
ELSIF form = OPM.SInt THEN
ELSIF to = OPM.SInt THEN
IF OPM.ranchk IN OPM.opt THEN OPM.WriteString("__SHORT");
IF SideEffects(n) THEN OPM.Write("F") END ;
OPM.Write(OpenParen); Entier(n, MinPrec);
OPM.WriteString(Comma); OPM.WriteInt(OPM.SignedMaximum(OPM.SIntSize) + 1); OPM.Write(CloseParen)
ELSE OPM.WriteString("(int)"); Entier(n, 9)
END
ELSIF form = OPM.Char THEN
(*
ELSIF to IN OPM.intSet THEN
IF from IN OPM.intSet
IF typ.size > n.typ.size (* Result is larger *)
SizeCast(typ.size); Entier(n, 9)
ELSIF typ.size = n.typ.size THEN
Entier(n, 9)
ELSE (* Result is smaller *)
IF OPM.ranchk IN OPM.opt THEN
OPM.WriteString("__SHORT"); IF SideEffects(n) THEN OPM.Write("F") END;
OPM.Write(OpenParen); Entier(n, MinPrec); OPM.WriteString(Comma);
OPM.WriteInt(OPM.SignedMaximum(typ.size) + 1); OPM.Write(CloseParen)
ELSE
SizeCast(typ.size); Entier(n, 9)
END
END
ELSE
IF (from < OPM.SInt) & (typ.size > OPM.SIntSize) THEN SizeCast(typ.size) END;
Entier(n, 9)
END
*)
ELSIF to = OPM.Char THEN
IF OPM.ranchk IN OPM.opt THEN OPM.WriteString("__CHR");
IF SideEffects(n) THEN OPM.Write("F") END ;
OPM.Write(OpenParen); Entier(n, MinPrec); OPM.Write(CloseParen)
@ -547,7 +579,7 @@ MODULE OPV; (* J. Templ 16.2.95 / 3.7.96
OPM.WriteString(Comma);
OPC.Andent(typ); OPM.WriteString(Comma);
OPM.WriteInt(typ^.extlev); OPM.Write(")")
| OPM.conv: Convert(l, form, exprPrec)
| OPM.conv: Convert(l, n.typ, exprPrec)
| OPM.abs: IF SideEffects(l) THEN
IF l^.typ^.form < OPM.Real THEN
IF l^.typ^.form < OPM.LInt THEN OPM.WriteString("(int)") END ;