浏览代码

* 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 ff3f812d979e57b49463224a814c64e027670d2d)

Jonas Maebe 4 年之前
父节点
当前提交
abf89eea0d
共有 2 个文件被更改,包括 18 次插入2 次删除
  1. 5 2
      compiler/scanner.pas
  2. 13 0
      tests/webtbs/tw38492.pp

+ 5 - 2
compiler/scanner.pas

@@ -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 - 0
tests/webtbs/tw38492.pp

@@ -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.