瀏覽代碼

fpc: compiler:
- complete $WARN switch parsing and add a stab to change message state
- reimplement way of message hiding by -vm switch (by Dmitry Boyarintsev)
(note: $WARN switch does not work at the moment since state handling is not yet implemented)

git-svn-id: trunk@14809 -

paul 15 年之前
父節點
當前提交
a8381c8b32
共有 9 個文件被更改,包括 546 次插入445 次删除
  1. 19 19
      compiler/cmsgs.pas
  2. 1 1
      compiler/comphook.pas
  3. 8 0
      compiler/globtype.pas
  4. 4 2
      compiler/msg/errore.msg
  5. 3 2
      compiler/msgidx.inc
  6. 385 384
      compiler/msgtxt.inc
  7. 64 4
      compiler/scandir.pas
  8. 5 0
      compiler/switches.pas
  9. 57 33
      compiler/verbose.pas

+ 19 - 19
compiler/cmsgs.pas

@@ -25,6 +25,9 @@ unit cmsgs;
 
 
 interface
 interface
 
 
+uses
+  globtype;
+
 const
 const
   maxmsgidxparts = 20;
   maxmsgidxparts = 20;
 
 
@@ -34,6 +37,9 @@ type
   TArrayOfPChar = array[0..1000] of pchar;
   TArrayOfPChar = array[0..1000] of pchar;
   PArrayOfPChar = ^TArrayOfPChar;
   PArrayOfPChar = ^TArrayOfPChar;
 
 
+  TArrayOfState = array[0..1000] of tmsgstate;
+  PArrayOfState = ^TArrayOfState;
+
   PMessage=^TMessage;
   PMessage=^TMessage;
   TMessage=object
   TMessage=object
     msgfilename : string;
     msgfilename : string;
@@ -45,6 +51,7 @@ type
     msgtxt      : pchar;
     msgtxt      : pchar;
     msgidx      : array[1..maxmsgidxparts] of PArrayOfPChar;
     msgidx      : array[1..maxmsgidxparts] of PArrayOfPChar;
     msgidxmax   : array[1..maxmsgidxparts] of longint;
     msgidxmax   : array[1..maxmsgidxparts] of longint;
+    msgstates   : array[1..maxmsgidxparts] of PArrayOfState;
     constructor Init(n:longint;const idxmax:array of longint);
     constructor Init(n:longint;const idxmax:array of longint);
     destructor  Done;
     destructor  Done;
     function  LoadIntern(p:pointer;n:longint):boolean;
     function  LoadIntern(p:pointer;n:longint):boolean;
@@ -109,8 +116,12 @@ begin
   for i:=1 to n do
   for i:=1 to n do
    begin
    begin
      msgidxmax[i]:=idxmax[i-1];
      msgidxmax[i]:=idxmax[i-1];
+     { create array of msgidx }
      getmem(msgidx[i],msgidxmax[i]*sizeof(pointer));
      getmem(msgidx[i],msgidxmax[i]*sizeof(pointer));
      fillchar(msgidx[i]^,msgidxmax[i]*sizeof(pointer),0);
      fillchar(msgidx[i]^,msgidxmax[i]*sizeof(pointer),0);
+     { create array of states }
+     getmem(msgstates[i],msgidxmax[i]*sizeof(tmsgstate));
+     fillchar(msgstates[i]^,msgidxmax[i]*sizeof(tmsgstate),0);
    end;
    end;
 end;
 end;
 
 
@@ -120,7 +131,10 @@ var
   i : longint;
   i : longint;
 begin
 begin
   for i:=1 to msgparts do
   for i:=1 to msgparts do
+  begin
    freemem(msgidx[i],msgidxmax[i]*sizeof(pointer));
    freemem(msgidx[i],msgidxmax[i]*sizeof(pointer));
+   freemem(msgstates[i],msgidxmax[i]*sizeof(tmsgstate));
+  end;
   if msgallocsize>0 then
   if msgallocsize>0 then
    begin
    begin
      freemem(msgtxt,msgsize);
      freemem(msgtxt,msgsize);
@@ -380,26 +394,12 @@ var
   hp: pchar;
   hp: pchar;
   i, txtbegin: longint;
   i, txtbegin: longint;
 begin
 begin
-   result:=false;
-  if ((nr div 1000) < low(msgidx)) or
-     ((nr div 1000) > msgparts) then
+  result:=false;
+  i:=nr div 1000;
+  if (i < low(msgstates)) or
+     (i > msgparts) then
     exit;
     exit;
-  hp := GetPChar(nr);
-  if (hp=nil) then
-    exit;
-  txtbegin:=-1;
-  for i:=0 to 4 do
-    begin
-      if hp[i]=#0 then
-        exit;
-      if hp[i]='_' then
-        begin
-          txtbegin:=i;
-          break;
-        end;
-    end;
-  for i:=0 to txtbegin-1 do
-    hp[i]:='_';
+  msgstates[i]^[nr mod 1000]:=ms_off;
   result:=true;
   result:=true;
 end;
 end;
 
 

+ 1 - 1
compiler/comphook.pas

@@ -76,7 +76,7 @@ type
     currentsource : string;   { filename }
     currentsource : string;   { filename }
     currentline,
     currentline,
     currentcolumn : longint;  { current line and column }
     currentcolumn : longint;  { current line and column }
-		currentmodulestate : string[20];
+    currentmodulestate : string[20];
   { Total Status }
   { Total Status }
     compiledlines : longint;  { the number of lines which are compiled }
     compiledlines : longint;  { the number of lines which are compiled }
     errorcount,
     errorcount,

+ 8 - 0
compiler/globtype.pas

@@ -477,6 +477,14 @@ interface
        link_smart   = $4;
        link_smart   = $4;
        link_shared  = $8;
        link_shared  = $8;
 
 
+    type
+      { a message state }
+      tmsgstate = (
+        ms_on,    // turn on output
+        ms_off,   // turn off output
+        ms_error  // cast to error
+      );
+
 implementation
 implementation
 
 
 end.
 end.

+ 4 - 2
compiler/msg/errore.msg

@@ -128,7 +128,7 @@ general_i_number_of_notes=01023_I_$1 note(s) issued
 #
 #
 # Scanner
 # Scanner
 #
 #
-# 02086 is the last used one
+# 02087 is the last used one
 #
 #
 % \section{Scanner messages.}
 % \section{Scanner messages.}
 % This section lists the messages that the scanner emits. The scanner takes
 % This section lists the messages that the scanner emits. The scanner takes
@@ -344,7 +344,7 @@ scan_w_minstacksize_not_support=02077_W_MINSTACKSIZE is not supported by the tar
 % The \var{\{\$MINSTACKSIZE\}} directive is not supported by the target OS.
 % The \var{\{\$MINSTACKSIZE\}} directive is not supported by the target OS.
 scan_w_maxstacksize_not_support=02078_W_MAXSTACKSIZE is not supported by the target OS
 scan_w_maxstacksize_not_support=02078_W_MAXSTACKSIZE is not supported by the target OS
 % The \var{\{\$MAXSTACKSIZE\}} directive is not supported by the target OS.
 % The \var{\{\$MAXSTACKSIZE\}} directive is not supported by the target OS.
-scanner_e_illegal_warn_state=02079_E_Illegal state for $WARN directive
+scanner_e_illegal_warn_state=02079_E_Illegal state "$1" for $WARN directive
 % Only ON and OFF can be used as state with a \var{\{\$WARN\}} compiler directive.
 % Only ON and OFF can be used as state with a \var{\{\$WARN\}} compiler directive.
 scan_e_only_packset=02080_E_Illegal set packing value
 scan_e_only_packset=02080_E_Illegal set packing value
 % Only 0, 1, 2, 4, 8, DEFAULT and NORMAL are allowed as packset parameters.
 % Only 0, 1, 2, 4, 8, DEFAULT and NORMAL are allowed as packset parameters.
@@ -362,6 +362,8 @@ scan_e_illegal_minfpconstprec=02085_E_Illegal minimal floating point constant pr
 scan_w_multiple_main_name_overrides=02086_W_Overriding name of "main" procedure multiple times, was previously set to "$1"
 scan_w_multiple_main_name_overrides=02086_W_Overriding name of "main" procedure multiple times, was previously set to "$1"
 % The name for the main entry procedure is specified more than once. Only the last
 % The name for the main entry procedure is specified more than once. Only the last
 % name will be used.
 % name will be used.
+scanner_w_illegal_warn_identifier=02087_W_Illegal identifier "$1" for $WARN directive
+% Identifier is not known by a \var{\{\$WARN\}} compiler directive.
 % \end{description}
 % \end{description}
 #
 #
 # Parser
 # Parser

+ 3 - 2
compiler/msgidx.inc

@@ -106,6 +106,7 @@ const
   scan_w_frameworks_darwin_only=02084;
   scan_w_frameworks_darwin_only=02084;
   scan_e_illegal_minfpconstprec=02085;
   scan_e_illegal_minfpconstprec=02085;
   scan_w_multiple_main_name_overrides=02086;
   scan_w_multiple_main_name_overrides=02086;
+  scanner_w_illegal_warn_identifier=02087;
   parser_e_syntax_error=03000;
   parser_e_syntax_error=03000;
   parser_e_dont_nest_interrupt=03004;
   parser_e_dont_nest_interrupt=03004;
   parser_w_proc_directive_ignored=03005;
   parser_w_proc_directive_ignored=03005;
@@ -851,9 +852,9 @@ const
   option_info=11024;
   option_info=11024;
   option_help_pages=11025;
   option_help_pages=11025;
 
 
-  MsgTxtSize = 55757;
+  MsgTxtSize = 55814;
 
 
   MsgIdxMax : array[1..20] of longint=(
   MsgIdxMax : array[1..20] of longint=(
-    24,87,287,95,80,51,110,22,202,63,
+    24,88,287,95,80,51,110,22,202,63,
     49,20,1,1,1,1,1,1,1,1
     49,20,1,1,1,1,1,1,1,1
   );
   );

文件差異過大導致無法顯示
+ 385 - 384
compiler/msgtxt.inc


+ 64 - 4
compiler/scandir.pas

@@ -1176,24 +1176,84 @@ unit scandir;
     { delphi compatible warn directive:
     { delphi compatible warn directive:
       $warn <identifier> on
       $warn <identifier> on
       $warn <identifier> off
       $warn <identifier> off
+      $warn <identifier> error
       not implemented yet
       not implemented yet
     }
     }
     procedure dir_warn;
     procedure dir_warn;
       var
       var
+        ident : string;
         state : string;
         state : string;
+        msgstate : tmsgstate;
       begin
       begin
         current_scanner.skipspace;
         current_scanner.skipspace;
-        current_scanner.readid;
+        ident:=current_scanner.readid;
         current_scanner.skipspace;
         current_scanner.skipspace;
         state:=current_scanner.readid;
         state:=current_scanner.readid;
-        if (upper(state)='ON') then
+
+        { support both delphi and fpc switches }
+        if (state='ON') or (state='+') then
+          msgstate:=ms_on
+        else
+        if (state='OFF') or (state='-') then
+          msgstate:=ms_off
+        else
+        if (state='ERROR') then
+          msgstate:=ms_error
+        else
+        begin
+          Message1(scanner_e_illegal_warn_state,state);
+          exit;
+        end;
+
+        if ident='CONSTRUCTING_ABSTRACT' then
+          recordpendingmessagestate(type_w_instance_with_abstract, msgstate)
+        else
+        if ident='IMPLICIT_VARIANTS' then
+          recordpendingmessagestate(parser_w_implicit_uses_of_variants_unit, msgstate)
+        else
+        if ident='NO_RETVAL' then
+          recordpendingmessagestate(sym_w_function_result_not_set, msgstate)
+        else
+        if ident='SYMBOL_DEPRECATED' then
           begin
           begin
+            recordpendingmessagestate(sym_w_deprecated_symbol, msgstate);
+            recordpendingmessagestate(sym_w_deprecated_symbol_with_msg, msgstate);
           end
           end
-        else if (upper(state)='OFF') then
+        else
+        if ident='SYMBOL_EXPERIMENTAL' then
+          recordpendingmessagestate(sym_w_experimental_symbol, msgstate)
+        else
+        if ident='SYMBOL_LIBRARY' then
+          recordpendingmessagestate(sym_w_library_symbol, msgstate)
+        else
+        if ident='SYMBOL_PLATFORM' then
+          recordpendingmessagestate(sym_w_non_portable_symbol, msgstate)
+        else
+        if ident='SYMBOL_UNIMPLEMENTED' then
+          recordpendingmessagestate(sym_w_non_implemented_symbol, msgstate)
+        else
+        if ident='UNIT_DEPRECATED' then
           begin
           begin
+            recordpendingmessagestate(sym_w_deprecated_unit, msgstate);
+            recordpendingmessagestate(sym_w_deprecated_unit_with_msg, msgstate);
           end
           end
         else
         else
-          Message1(scanner_e_illegal_warn_state,state);
+        if ident='UNIT_EXPERIMENTAL' then
+          recordpendingmessagestate(sym_w_experimental_unit, msgstate)
+        else
+        if ident='UNIT_LIBRARY' then
+          recordpendingmessagestate(sym_w_library_unit, msgstate)
+        else
+        if ident='UNIT_PLATFORM' then
+          recordpendingmessagestate(sym_w_non_portable_unit, msgstate)
+        else
+        if ident='UNIT_UNIMPLEMENTED' then
+          recordpendingmessagestate(sym_w_non_implemented_unit, msgstate)
+        else
+        if ident='ZERO_NIL_COMPAT' then
+          recordpendingmessagestate(type_w_zero_to_nil, msgstate)
+        else
+          Message1(scanner_w_illegal_warn_identifier,ident);
       end;
       end;
 
 
     procedure dir_warning;
     procedure dir_warning;

+ 5 - 0
compiler/switches.pas

@@ -32,6 +32,7 @@ procedure HandleSwitch(switch,state:char);
 function CheckSwitch(switch,state:char):boolean;
 function CheckSwitch(switch,state:char):boolean;
 
 
 procedure recordpendingverbosityswitch(sw: char; state: char);
 procedure recordpendingverbosityswitch(sw: char; state: char);
+procedure recordpendingmessagestate(msg: longint; state: tmsgstate);
 procedure recordpendinglocalswitch(sw: tlocalswitch; state: char);
 procedure recordpendinglocalswitch(sw: tlocalswitch; state: char);
 procedure recordpendinglocalfullswitch(const switches: tlocalswitches);
 procedure recordpendinglocalfullswitch(const switches: tlocalswitches);
 procedure recordpendingverbosityfullswitch(verbosity: longint);
 procedure recordpendingverbosityfullswitch(verbosity: longint);
@@ -263,6 +264,10 @@ procedure recordpendingverbosityswitch(sw: char; state: char);
     pendingstate.nextverbositystr:=pendingstate.nextverbositystr+sw+state;
     pendingstate.nextverbositystr:=pendingstate.nextverbositystr+sw+state;
   end;
   end;
 
 
+procedure recordpendingmessagestate(msg: longint; state: tmsgstate);
+  begin
+    { todo }
+  end;
 
 
 procedure recordpendinglocalswitch(sw: tlocalswitch; state: char);
 procedure recordpendinglocalswitch(sw: tlocalswitch; state: char);
   begin
   begin

+ 57 - 33
compiler/verbose.pas

@@ -179,7 +179,7 @@ implementation
 
 
     function ClearMessageVerbosity(s: string; var i: integer): boolean;
     function ClearMessageVerbosity(s: string; var i: integer): boolean;
       var
       var
-        tok : string;
+        tok  : string;
         code : longint;
         code : longint;
         msgnr: longint;
         msgnr: longint;
       begin
       begin
@@ -247,7 +247,7 @@ implementation
                             status.print_source_path:=true;
                             status.print_source_path:=true;
                        end;
                        end;
                  'M' : if inverse or
                  'M' : if inverse or
-                          not ClearMessageVerbosity(s, i) then
+                         not ClearMessageVerbosity(s, i) then
                          begin
                          begin
                            result:=false;
                            result:=false;
                            exit
                            exit
@@ -542,12 +542,25 @@ implementation
          end;
          end;
       end;
       end;
 
 
+    function GetMessageState(m:longint):tmsgstate;
+      var
+        i: integer;
+      begin
+        i:=m div 1000;
+        { get the default state }
+        Result:=msg^.msgstates[i]^[m mod 1000];
+
+        { and search at the current unit settings }
+        { todo }
+      end;
 
 
     Procedure Msg2Comment(s:ansistring;w:longint;onqueue:tmsgqueueevent);
     Procedure Msg2Comment(s:ansistring;w:longint;onqueue:tmsgqueueevent);
       var
       var
         idx,i,v : longint;
         idx,i,v : longint;
         dostop  : boolean;
         dostop  : boolean;
         doqueue : boolean;
         doqueue : boolean;
+        st      : tmsgstate;
+        ch      : char;
       begin
       begin
       {Reset}
       {Reset}
         dostop:=false;
         dostop:=false;
@@ -562,47 +575,58 @@ implementation
           begin
           begin
             for i:=1 to idx do
             for i:=1 to idx do
              begin
              begin
-               case upcase(s[i]) of
+               ch:=upcase(s[i]);
+               case ch of
                 'F' :
                 'F' :
                   begin
                   begin
                     v:=v or V_Fatal;
                     v:=v or V_Fatal;
                     inc(status.errorcount);
                     inc(status.errorcount);
                     dostop:=true;
                     dostop:=true;
                   end;
                   end;
-                'E' :
+                'E','W','N','H':
                   begin
                   begin
-                    v:=v or V_Error;
-                    inc(status.errorcount);
+                    if ch='E' then
+                      st:=ms_error
+                    else
+                      st:=GetMessageState(w);
+                    if st=ms_error then
+                      begin
+                        v:=v or V_Error;
+                        inc(status.errorcount);
+                      end
+                    else if st<>ms_off then
+                      case ch of
+                       'W':
+                         begin
+                           v:=v or V_Warning;
+                           if CheckVerbosity(V_Warning) then
+                             if status.errorwarning then
+                              inc(status.errorcount)
+                             else
+                              inc(status.countWarnings);
+                         end;
+                       'N' :
+                         begin
+                           v:=v or V_Note;
+                           if CheckVerbosity(V_Note) then
+                             if status.errornote then
+                              inc(status.errorcount)
+                             else
+                              inc(status.countNotes);
+                         end;
+                       'H' :
+                         begin
+                           v:=v or V_Hint;
+                           if CheckVerbosity(V_Hint) then
+                             if status.errorhint then
+                              inc(status.errorcount)
+                             else
+                              inc(status.countHints);
+                         end;
+                      end;
                   end;
                   end;
                 'O' :
                 'O' :
                   v:=v or V_Normal;
                   v:=v or V_Normal;
-                'W':
-                  begin
-                    v:=v or V_Warning;
-                    if CheckVerbosity(V_Warning) then
-                      if status.errorwarning then
-                       inc(status.errorcount)
-                      else
-                       inc(status.countWarnings);
-                  end;
-                'N' :
-                  begin
-                    v:=v or V_Note;
-                    if CheckVerbosity(V_Note) then
-                      if status.errornote then
-                       inc(status.errorcount)
-                      else
-                       inc(status.countNotes);
-                  end;
-                'H' :
-                  begin
-                    v:=v or V_Hint;
-                    if CheckVerbosity(V_Hint) then
-                      if status.errorhint then
-                       inc(status.errorcount)
-                      else
-                       inc(status.countHints);
-                  end;
                 'I' :
                 'I' :
                   v:=v or V_Info;
                   v:=v or V_Info;
                 'L' :
                 'L' :

部分文件因文件數量過多而無法顯示