* fix conversion of true/false macro definitions to boolean values

(mantis #38492)
   o since the macro lookups are recursive, "mac" will usually be nil
     afterwards (unless we found an undefined macro)

git-svn-id: trunk@49160 -
(cherry picked from commit ff3f812d97)
This commit is contained in:
Jonas Maebe 2021-04-10 10:56:02 +00:00 committed by florian
parent 8ed9c79c23
commit abf89eea0d
2 changed files with 18 additions and 2 deletions

View File

@ -1606,6 +1606,7 @@ type
mac: tmacro; mac: tmacro;
macrocount, macrocount,
len: integer; len: integer;
foundmacro: boolean;
begin begin
if not eval then if not eval then
begin begin
@ -1614,6 +1615,7 @@ type
end; end;
mac:=nil; mac:=nil;
foundmacro:=false;
{ Substitue macros and compiler variables with their content/value. { Substitue macros and compiler variables with their content/value.
For real macros also do recursive substitution. } For real macros also do recursive substitution. }
macrocount:=0; macrocount:=0;
@ -1641,6 +1643,7 @@ type
move(mac.buftext^,hs[1],len); move(mac.buftext^,hs[1],len);
searchstr:=upcase(hs); searchstr:=upcase(hs);
mac.is_used:=true; mac.is_used:=true;
foundmacro:=true;
end end
else else
begin begin
@ -1659,9 +1662,9 @@ type
result:=texprvalue.try_parse_number(searchstr); result:=texprvalue.try_parse_number(searchstr);
if not assigned(result) then if not assigned(result) then
begin begin
if assigned(mac) and (searchstr='FALSE') then if foundmacro and (searchstr='FALSE') then
result:=texprvalue.create_bool(false) result:=texprvalue.create_bool(false)
else if assigned(mac) and (searchstr='TRUE') then else if foundmacro and (searchstr='TRUE') then
result:=texprvalue.create_bool(true) result:=texprvalue.create_bool(true)
else if (m_mac in current_settings.modeswitches) and else if (m_mac in current_settings.modeswitches) and
(not assigned(mac) or not mac.defined) and (not assigned(mac) or not mac.defined) and

13
tests/webtbs/tw38492.pp Normal file
View File

@ -0,0 +1,13 @@
{ %opt=-Sm -dmydefine:=false }
{$mode macpas}
{$setc def := mydefine}
program setcbug;
begin
{$ifc def}
writeln( 'mydefine is true')
halt(1);
{$elsec}
writeln( 'mydefine is false')
{$endc}
end.