Explorar o código

* fixed checking for defined/undefined macro's in the configuration file
(#undef'ed macro's still caused #ifdef/#ifndef to return resp.
true/false)

git-svn-id: trunk@10872 -

Jonas Maebe %!s(int64=17) %!d(string=hai) anos
pai
achega
a324744cbe
Modificáronse 3 ficheiros con 23 adicións e 11 borrados
  1. 3 3
      compiler/options.pas
  2. 2 8
      compiler/scanner.pas
  3. 18 0
      compiler/symtable.pas

+ 3 - 3
compiler/options.pas

@@ -1658,7 +1658,7 @@ begin
               RemoveSep(opts);
               s:=upper(GetName(opts));
               if level=0 then
-               skip[level]:=not (assigned(search_macro(s)) or (s='COMMON'));
+               skip[level]:=not defined_macro(s) or (s='COMMON');
             end
            else
             if (s='IFDEF') then
@@ -1670,7 +1670,7 @@ begin
                   stopOptions(1);
                 end;
                inc(Level);
-               skip[level]:=(skip[level-1] or not assigned(search_macro(upper(GetName(opts)))));
+               skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
              end
            else
             if (s='IFNDEF') then
@@ -1682,7 +1682,7 @@ begin
                   stopOptions(1);
                 end;
                inc(Level);
-               skip[level]:=(skip[level-1] or assigned(search_macro(upper(GetName(opts)))));
+               skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
              end
            else
             if (s='ELSE') then

+ 2 - 8
compiler/scanner.pas

@@ -432,10 +432,7 @@ implementation
         valuedescr:= hs;
         if hs='' then
           Message(scan_e_error_in_preproc_expr);
-        mac:=tmacro(search_macro(hs));
-        if assigned(mac) then
-          mac.is_used:=true;
-        isdef:= assigned(mac) and mac.defined;
+        isdef:=defined_macro(hs);
       end;
 
     procedure dir_ifdef;
@@ -453,10 +450,7 @@ implementation
         valuedescr:= hs;
         if hs='' then
           Message(scan_e_error_in_preproc_expr);
-        mac:=tmacro(search_macro(hs));
-        if assigned(mac) then
-          mac.is_used:=true;
-        isnotdef:= not (assigned(mac) and mac.defined);
+        isnotdef:=not defined_macro(hs);
       end;
 
     procedure dir_ifndef;

+ 18 - 0
compiler/symtable.pas

@@ -203,6 +203,9 @@ interface
     {Looks for macro s (must be given in upper case) in the macrosymbolstack, }
     {and returns it if found. Returns nil otherwise.}
     function  search_macro(const s : string):tsym;
+    { Additionally to searching for a macro, also checks whether it's still }
+    { actually defined (could be disable using "undef")                     }
+    function  defined_macro(const s : string):boolean;
 
 {*** Object Helpers ***}
     procedure search_class_overloads(aprocsym : tprocsym);
@@ -1876,6 +1879,21 @@ implementation
       end;
 
 
+    function defined_macro(const s : string):boolean;
+      var
+        mac: tmacro;
+      begin
+        mac:=tmacro(search_macro(s));
+        if assigned(mac) then
+          begin
+            mac.is_used:=true;
+            defined_macro:=mac.defined;
+          end
+        else
+          defined_macro:=false;
+      end;
+
+
 {****************************************************************************
                               Object Helpers
 ****************************************************************************}