* add support for AND, OR, XOR and NOT of integer values in preprocessor directives (Delphi allows that as well)

+ added test

git-svn-id: trunk@45053 -
This commit is contained in:
svenbarth 2020-04-24 14:09:04 +00:00
parent ae2801c707
commit bd01182ff0
3 changed files with 123 additions and 0 deletions

1
.gitattributes vendored
View File

@ -13206,6 +13206,7 @@ tests/tbs/tb0667.pp svneol=native#text/pascal
tests/tbs/tb0668a.pp svneol=native#text/pascal
tests/tbs/tb0668b.pp svneol=native#text/pascal
tests/tbs/tb0669.pp svneol=native#text/pascal
tests/tbs/tb0670.pp svneol=native#text/pascal
tests/tbs/ub0060.pp svneol=native#text/plain
tests/tbs/ub0069.pp svneol=native#text/plain
tests/tbs/ub0119.pp svneol=native#text/plain

View File

@ -1146,6 +1146,12 @@ type
begin
if isBoolean then
result:=texprvalue.create_bool(not asBool)
else if is_ordinal(def) then
begin
result:=texprvalue.create_ord(value.valueord);
result.def:=def;
calc_not_ordvalue(result.value.valueord,result.def);
end
else
begin
error('Boolean', 'NOT');
@ -1162,6 +1168,14 @@ type
v.error('Boolean','OR');
result:=texprvalue.create_error;
end
else if is_ordinal(def) then
if is_ordinal(v.def) then
result:=texprvalue.create_ord(value.valueord or v.value.valueord)
else
begin
v.error('Ordinal','OR');
result:=texprvalue.create_error;
end
else
begin
error('Boolean','OR');
@ -1178,6 +1192,14 @@ type
v.error('Boolean','XOR');
result:=texprvalue.create_error;
end
else if is_ordinal(def) then
if is_ordinal(v.def) then
result:=texprvalue.create_ord(value.valueord xor v.value.valueord)
else
begin
v.error('Ordinal','XOR');
result:=texprvalue.create_error;
end
else
begin
error('Boolean','XOR');
@ -1194,6 +1216,14 @@ type
v.error('Boolean','AND');
result:=texprvalue.create_error;
end
else if is_ordinal(def) then
if is_ordinal(v.def) then
result:=texprvalue.create_ord(value.valueord and v.value.valueord)
else
begin
v.error('Ordinal','AND');
result:=texprvalue.create_error;
end
else
begin
error('Boolean','AND');

92
tests/tbs/tb0670.pp Normal file
View File

@ -0,0 +1,92 @@
{ %NORUN }
program tb0670;
const
Value1 = $06;
Value2 = $60;
Value3 = $6000;
Value4 = $60000000;
Value5 = $60000000000;
Value6 = $40;
Value7 = $4000;
Value8 = $40000000;
Value9 = $40000000000;
ValueNot1 = not Value1;
ValueNot2 = not Value2;
ValueNot3 = not Value3;
ValueNot4 = not Value4;
ValueNot5 = not Value5;
ValueOr1 = Value1 or Value2;
ValueOr2 = Value1 or Value3;
ValueOr3 = Value1 or Value4;
ValueOr4 = Value1 or Value5;
ValueAnd1 = Value2 and Value6;
ValueAnd2 = Value3 and Value7;
ValueAnd3 = Value4 and Value8;
ValueAnd4 = Value5 and Value9;
{ Test "not X" }
{$if not (not Value1 = ValueNot1)}
{$error 'not Value1 = ValueNot1'}
{$endif}
{$if not (not Value2 = ValueNot2)}
{$error 'not Value2 = ValueNot2'}
{$endif}
{$if not (not Value3 = ValueNot3)}
{$error 'not Value3 = ValueNot3'}
{$endif}
{$if not (not Value4 = ValueNot4)}
{$error 'not Value4 = ValueNot4'}
{$endif}
{$if not (not Value5 = ValueNot5)}
{$error 'not Value5 = ValueNot5'}
{$endif}
{ Test "X or Y" }
{$if Value1 or Value2 <> ValueOr1}
{$error 'Value1 or Value2 = ValueOr1'}
{$endif}
{$if Value1 or Value3 <> ValueOr2}
{$error 'Value1 or Value3 = ValueOr2'}
{$endif}
{$if Value1 or Value4 <> ValueOr3}
{$error 'Value1 or Value4 = ValueOr3'}
{$endif}
{$if Value1 or Value5 <> ValueOr4}
{$error 'Value1 or Value5 = ValueOr4'}
{$endif}
{ Test "X and Y" }
{$if Value2 and Value6 <> ValueAnd1 }
{$error 'Value2 and Value6 = ValueAnd1' }
{$endif}
{$if Value3 and Value7 <> ValueAnd2 }
{$error 'Value3 and Value7 = ValueAnd2' }
{$endif}
{$if Value4 and Value8 <> ValueAnd3 }
{$error 'Value4 and Value8 = ValueAnd3' }
{$endif}
{$if Value5 and Value9 <> ValueAnd4 }
{$error 'Value5 and Value9 = ValueAnd4' }
{$endif}
begin
end.