ソースを参照

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

Jonas Maebe 4 年 前
コミット
ff3f812d97
3 ファイル変更19 行追加2 行削除
  1. 1 0
      .gitattributes
  2. 5 2
      compiler/scanner.pas
  3. 13 0
      tests/webtbs/tw38492.pp

+ 1 - 0
.gitattributes

@@ -18768,6 +18768,7 @@ tests/webtbs/tw3841.pp svneol=native#text/plain
 tests/webtbs/tw38412.pp svneol=native#text/pascal
 tests/webtbs/tw38413.pp svneol=native#text/pascal
 tests/webtbs/tw38429.pp svneol=native#text/pascal
+tests/webtbs/tw38492.pp svneol=native#text/plain
 tests/webtbs/tw38497.pp svneol=native#text/pascal
 tests/webtbs/tw38527.pp svneol=native#text/plain
 tests/webtbs/tw38549.pp svneol=native#text/plain

+ 5 - 2
compiler/scanner.pas

@@ -1649,6 +1649,7 @@ type
           mac: tmacro;
           macrocount,
           len: integer;
+          foundmacro: boolean;
         begin
           if not eval then
             begin
@@ -1657,6 +1658,7 @@ type
             end;
 
           mac:=nil;
+          foundmacro:=false;
           { Substitue macros and compiler variables with their content/value.
             For real macros also do recursive substitution. }
           macrocount:=0;
@@ -1684,6 +1686,7 @@ type
                   move(mac.buftext^,hs[1],len);
                   searchstr:=upcase(hs);
                   mac.is_used:=true;
+                  foundmacro:=true;
                 end
               else
                 begin
@@ -1702,9 +1705,9 @@ type
           result:=texprvalue.try_parse_number(searchstr);
           if not assigned(result) then
             begin
-              if assigned(mac) and (searchstr='FALSE') then
+              if foundmacro and (searchstr='FALSE') then
                 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)
               else if (m_mac in current_settings.modeswitches) 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.