OSDN Git Service

* s-linux-sparc.ads: New file.
[pf3gnuchains/gcc-fork.git] / gcc / ada / switch-m.adb
index dc3fe56..a7a8d19 100644 (file)
@@ -6,18 +6,17 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2001-2006, Free Software Foundation, Inc.         --
+--          Copyright (C) 2001-2009, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
 -- for  more details.  You should have  received  a copy of the GNU General --
--- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
--- Boston, MA 02110-1301, USA.                                              --
+-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
+-- http://www.gnu.org/licenses for a complete copy of the license.          --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
 ------------------------------------------------------------------------------
 
 with Debug;    use Debug;
+with Makeutl;  use Makeutl;
 with Osint;    use Osint;
 with Opt;      use Opt;
+with Prj;      use Prj;
+with Prj.Ext;  use Prj.Ext;
 with Table;
 
 package body Switch.M is
@@ -82,7 +84,7 @@ package body Switch.M is
          if Switches = null then
             Switches := new Argument_List (1 .. Initial_Number_Of_Switches);
 
-         --  otherwise, if Switches is full, extend it
+         --  Otherwise, if Switches is full, extend it
 
          elsif Last = Switches'Last then
             declare
@@ -118,9 +120,7 @@ package body Switch.M is
          --  Add a new component in the table.
 
          Switches (Last) := new String'(S);
-         Normalized_Switches.Increment_Last;
-         Normalized_Switches.Table (Normalized_Switches.Last) :=
-           Switches (Last);
+         Normalized_Switches.Append (Switches (Last));
       end Add_Switch_Component;
 
    --  Start of processing for Normalize_Compiler_Switches
@@ -152,17 +152,59 @@ package body Switch.M is
             when False =>
 
                --  All switches that don't start with -gnat stay as is,
-               --  except -v and -pg
+               --  except -pg, -Wall, -k8, -w
 
-               if Switch_Chars = "-pg" then
+               if Switch_Chars = "-pg" or else Switch_Chars = "-p" then
 
                   --  The gcc driver converts -pg to -p, so that is what
                   --  is stored in the ALI file.
 
                   Add_Switch_Component ("-p");
 
-               elsif C /= 'v' then
+               elsif Switch_Chars = "-Wall" then
+
+                  --  The gcc driver adds -gnatwa when -Wall is used
+
+                  Add_Switch_Component ("-gnatwa");
+                  Add_Switch_Component ("-Wall");
+
+               elsif Switch_Chars = "-k8" then
+
+                  --  The gcc driver transforms -k8 into -gnatk8
+
+                  Add_Switch_Component ("-gnatk8");
+
+               elsif Switch_Chars = "-w" then
+
+                  --  The gcc driver adds -gnatws when -w is used
+
+                  Add_Switch_Component ("-gnatws");
+                  Add_Switch_Component ("-w");
+
+               elsif Switch_Chars'Length > 6
+                 and then
+                   Switch_Chars (Switch_Chars'First .. Switch_Chars'First + 5)
+                                                             = "--RTS="
+               then
                   Add_Switch_Component (Switch_Chars);
+
+                  --  When --RTS=mtp is used, the gcc driver adds -mrtp
+
+                  if Switch_Chars = "--RTS=mtp" then
+                     Add_Switch_Component ("-mrtp");
+                  end if;
+
+               --  Take only into account switches that are transmitted to
+               --  gnat1 by the gcc driver and stored by gnat1 in the ALI file.
+
+               else
+                  case C is
+                     when 'O' | 'W' | 'w' | 'f' | 'd' | 'g' | 'm' =>
+                        Add_Switch_Component (Switch_Chars);
+
+                     when others =>
+                        null;
+                  end case;
                end if;
 
                return;
@@ -226,14 +268,16 @@ package body Switch.M is
 
                   when 'e' =>
 
-                     --  Only -gnateD and -gnatep= need storing in ALI file
+                     --  Store -gnateD, -gnatep= and -gnateG in the ALI file.
+                     --  The other -gnate switches do not need to be stored.
 
                      Storing (First_Stored) := 'e';
                      Ptr := Ptr + 1;
 
                      if Ptr > Max
                        or else (Switch_Chars (Ptr) /= 'D'
-                                  and then Switch_Chars (Ptr) /= 'p')
+                                 and then Switch_Chars (Ptr) /= 'G'
+                                 and then Switch_Chars (Ptr) /= 'p')
                      then
                         Last := 0;
                         return;
@@ -251,7 +295,7 @@ package body Switch.M is
 
                      --  Processing for -gnatep=
 
-                     else
+                     elsif Switch_Chars (Ptr) = 'p' then
                         Ptr := Ptr + 1;
 
                         if Ptr = Max then
@@ -275,6 +319,9 @@ package body Switch.M is
                              Switch_Chars (Ptr .. Max);
                            Add_Switch_Component (To_Store);
                         end;
+
+                     elsif Switch_Chars (Ptr) = 'G' then
+                        Add_Switch_Component ("-gnateG");
                      end if;
 
                      return;
@@ -331,7 +378,8 @@ package body Switch.M is
                            Ptr := Ptr + 1;
 
                            if Ptr <= Max
-                             and then Switch_Chars (Ptr) = 's' then
+                             and then Switch_Chars (Ptr) = 's'
+                           then
                               Last_Stored := Last_Stored + 1;
                               Storing (Last_Stored) := 's';
                               Ptr := Ptr + 1;
@@ -359,48 +407,52 @@ package body Switch.M is
                         end if;
                      end if;
 
+                     --  Loop through remaining switch characters in string
+
                      while Ptr <= Max loop
                         C := Switch_Chars (Ptr);
                         Ptr := Ptr + 1;
 
-                        --  'w' should be skipped in -gnatw
+                        --  -gnatyMxxx
 
-                        if C /= 'w' or else Storing (First_Stored) /= 'w' then
-
-                           --  -gnatyMxxx
+                        if C = 'M' and then Storing (First_Stored) = 'y' then
+                           Last_Stored := First_Stored + 1;
+                           Storing (Last_Stored) := 'M';
+                           while Ptr <= Max loop
+                              C := Switch_Chars (Ptr);
+                              exit when C not in '0' .. '9';
+                              Last_Stored := Last_Stored + 1;
+                              Storing (Last_Stored) := C;
+                              Ptr := Ptr + 1;
+                           end loop;
 
-                           if C = 'M'
-                             and then Storing (First_Stored) = 'y' then
-                              Last_Stored := First_Stored + 1;
-                              Storing (Last_Stored) := 'M';
+                           --  If there is no digit after -gnatyM,
+                           --  the switch is invalid.
 
-                              while Ptr <= Max loop
-                                 C := Switch_Chars (Ptr);
-                                 exit when C not in '0' .. '9';
-                                 Last_Stored := Last_Stored + 1;
-                                 Storing (Last_Stored) := C;
-                                 Ptr := Ptr + 1;
-                              end loop;
+                           if Last_Stored = First_Stored + 1 then
+                              Last := 0;
+                              return;
 
-                              --  If there is no digit after -gnatyM,
-                              --  the switch is invalid.
+                           else
+                              Add_Switch_Component
+                                (Storing (Storing'First .. Last_Stored));
+                           end if;
 
-                              if Last_Stored = First_Stored + 1 then
-                                 Last := 0;
-                                 return;
+                        --  --gnatx.x
 
-                              else
-                                 Add_Switch_Component
-                                   (Storing (Storing'First .. Last_Stored));
-                              end if;
+                        elsif C = '.' and then Ptr <= Max then
+                           Storing (First_Stored + 1) := '.';
+                           Storing (First_Stored + 2) := Switch_Chars (Ptr);
+                           Ptr := Ptr + 1;
+                           Add_Switch_Component
+                             (Storing (Storing'First .. First_Stored + 2));
 
-                           --  All other switches are -gnatxx
+                        --  All other switches are -gnatxx
 
-                           else
-                              Storing (First_Stored + 1) := C;
-                              Add_Switch_Component
-                                (Storing (Storing'First .. First_Stored + 1));
-                           end if;
+                        else
+                           Storing (First_Stored + 1) := C;
+                           Add_Switch_Component
+                             (Storing (Storing'First .. First_Stored + 1));
                         end if;
                      end loop;
 
@@ -461,8 +513,7 @@ package body Switch.M is
    end Normalize_Compiler_Switches;
 
    function Normalize_Compiler_Switches
-     (Switch_Chars : String)
-      return         Argument_List
+     (Switch_Chars : String) return Argument_List
    is
       Last : Natural;
 
@@ -474,19 +525,26 @@ package body Switch.M is
       else
          return Global_Switches (Global_Switches'First .. Last);
       end if;
-
    end Normalize_Compiler_Switches;
 
    ------------------------
    -- Scan_Make_Switches --
    ------------------------
 
-   procedure Scan_Make_Switches (Switch_Chars : String) is
+   procedure Scan_Make_Switches
+     (Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
+      Switch_Chars      : String;
+      Success           : out Boolean)
+   is
       Ptr : Integer          := Switch_Chars'First;
       Max : constant Integer := Switch_Chars'Last;
       C   : Character        := ' ';
 
    begin
+      --  Assume a good switch
+
+      Success := True;
+
       --  Skip past the initial character (must be the switch character)
 
       if Ptr = Max then
@@ -496,70 +554,65 @@ package body Switch.M is
          Ptr := Ptr + 1;
       end if;
 
-      --  A little check, "gnat" at the start of a switch is not allowed
-      --  except for the compiler (where it was already removed)
+      --  A little check, "gnat" at the start of a switch is for the compiler
 
       if Switch_Chars'Length >= Ptr + 3
         and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
       then
-         Osint.Fail
-           ("invalid switch: """, Switch_Chars, """ (gnat not needed here)");
+         Success := False;
+         return;
       end if;
 
-      --  Loop to scan through switches given in switch string
-
-      Check_Switch : begin
-         C := Switch_Chars (Ptr);
-
-         --  Processing for a switch
-
-         case C is
-
-         when 'a' =>
-            Ptr := Ptr + 1;
-            Check_Readonly_Files := True;
-
-         --  Processing for b switch
+      C := Switch_Chars (Ptr);
 
-         when 'b' =>
-            Ptr := Ptr + 1;
-            Bind_Only  := True;
-            Make_Steps := True;
+      --  Multiple character switches
 
-         --  Processing for B switch
+      if Switch_Chars'Length > 2 then
+         if Switch_Chars = "--create-missing-dirs" then
+            Setup_Projects := True;
 
-         when 'B' =>
-            Ptr := Ptr + 1;
-            Build_Bind_And_Link_Full_Project := True;
+         elsif Switch_Chars'Length > Subdirs_Option'Length
+           and then
+             Switch_Chars
+               (Switch_Chars'First ..
+                Switch_Chars'First + Subdirs_Option'Length - 1) =
+                                                            Subdirs_Option
+         then
+            Subdirs :=
+              new String'
+                (Switch_Chars
+                  (Switch_Chars'First + Subdirs_Option'Length ..
+                   Switch_Chars'Last));
 
-         --  Processing for c switch
-
-         when 'c' =>
-            Ptr := Ptr + 1;
-            Compile_Only := True;
-            Make_Steps   := True;
+         elsif Switch_Chars (Ptr) = '-' then
+            Bad_Switch (Switch_Chars);
 
-         --  Processing for C switch
+         elsif Switch_Chars'Length > 3
+           and then Switch_Chars (Ptr .. Ptr + 1) = "aP"
+         then
+            Add_Search_Project_Directory
+              (Project_Node_Tree,
+               Switch_Chars (Ptr + 2 .. Switch_Chars'Last));
 
-         when 'C' =>
+         elsif C = 'v' and then Switch_Chars'Length = 3 then
             Ptr := Ptr + 1;
-            Create_Mapping_File := True;
-
-         --  Processing for D switch
+            Verbose_Mode := True;
 
-         when 'D' =>
-            Ptr := Ptr + 1;
+            case Switch_Chars (Ptr) is
+               when 'l' =>
+                  Verbosity_Level := Opt.Low;
 
-            if Object_Directory_Present then
-               Osint.Fail ("duplicate -D switch");
+               when 'm' =>
+                  Verbosity_Level := Opt.Medium;
 
-            else
-               Object_Directory_Present := True;
-            end if;
+               when 'h' =>
+                  Verbosity_Level := Opt.High;
 
-         --  Processing for d switch
+               when others =>
+                  Success := False;
+            end case;
 
-         when 'd' =>
+         elsif C = 'd' then
 
             --  Note: for the debug switch, the remaining characters in this
             --  switch field must all be debug flags, since all valid switch
@@ -580,17 +633,9 @@ package body Switch.M is
                end if;
             end loop;
 
-            return;
-
-         --  Processing for e switch
-
-         when 'e' =>
+         elsif C = 'e' then
             Ptr := Ptr + 1;
 
-            if Ptr > Max then
-               Bad_Switch (Switch_Chars);
-            end if;
-
             case Switch_Chars (Ptr) is
 
                --  Processing for eI switch
@@ -599,164 +644,220 @@ package body Switch.M is
                   Ptr := Ptr + 1;
                   Scan_Pos (Switch_Chars, Max, Ptr, Main_Index, C);
 
+                  if Ptr <= Max then
+                     Bad_Switch (Switch_Chars);
+                  end if;
+
                --  Processing for eL switch
 
                when 'L' =>
-                  Ptr := Ptr + 1;
-                  Follow_Links := True;
+                  if Ptr /= Max then
+                     Bad_Switch (Switch_Chars);
+
+                  else
+                     Follow_Links_For_Files := True;
+                     Follow_Links_For_Dirs  := True;
+                  end if;
+
+               --  Processing for eS switch
+
+               when 'S' =>
+                  if Ptr /= Max then
+                     Bad_Switch (Switch_Chars);
+
+                  else
+                     Commands_To_Stdout := True;
+                  end if;
 
                when others =>
                   Bad_Switch (Switch_Chars);
             end case;
 
-         --  Processing for f switch
-
-         when 'f' =>
+         elsif C = 'j' then
             Ptr := Ptr + 1;
-            Force_Compilations := True;
 
-         --  Processing for F switch
+            declare
+               Max_Proc : Pos;
+            begin
+               Scan_Pos (Switch_Chars, Max, Ptr, Max_Proc, C);
 
-         when 'F' =>
-            Ptr := Ptr + 1;
-            Full_Path_Name_For_Brief_Errors := True;
+               if Ptr <= Max then
+                  Bad_Switch (Switch_Chars);
 
-         --  Processing for h switch
+               else
+                  Maximum_Processes := Positive (Max_Proc);
+               end if;
+            end;
 
-         when 'h' =>
+         elsif C = 'w' and then Switch_Chars'Length = 3 then
             Ptr := Ptr + 1;
-            Usage_Requested := True;
 
-         --  Processing for i switch
+            if Switch_Chars = "-we" then
+               Warning_Mode := Treat_As_Error;
 
-         when 'i' =>
-            Ptr := Ptr + 1;
-            In_Place_Mode := True;
+            elsif Switch_Chars = "-wn" then
+               Warning_Mode := Normal;
 
-         --  Processing for j switch
+            elsif Switch_Chars = "-ws" then
+               Warning_Mode  := Suppress;
 
-         when 'j' =>
-            if Ptr = Max then
-               Bad_Switch (Switch_Chars);
+            else
+               Success := False;
             end if;
 
-            Ptr := Ptr + 1;
+         else
+            Success := False;
+         end if;
 
-            declare
-               Max_Proc : Pos;
-            begin
-               Scan_Pos (Switch_Chars, Max, Ptr, Max_Proc, C);
-               Maximum_Processes := Positive (Max_Proc);
-            end;
+      --  Single-character switches
 
-         --  Processing for k switch
+      else
+         Check_Switch : begin
 
-         when 'k' =>
-            Ptr := Ptr + 1;
-            Keep_Going := True;
+            case C is
 
-         --  Processing for l switch
+               when 'a' =>
+                  Check_Readonly_Files := True;
 
-         when 'l' =>
-            Ptr := Ptr + 1;
-            Link_Only  := True;
-            Make_Steps := True;
+               --  Processing for b switch
 
-         when 'M' =>
-            Ptr := Ptr + 1;
-            List_Dependencies := True;
+               when 'b' =>
+                  Bind_Only  := True;
+                  Make_Steps := True;
 
-         --  Processing for n switch
+               --  Processing for B switch
 
-         when 'n' =>
-            Ptr := Ptr + 1;
-            Do_Not_Execute := True;
+               when 'B' =>
+                  Build_Bind_And_Link_Full_Project := True;
 
-         --  Processing for o switch
+               --  Processing for c switch
 
-         when 'o' =>
-            Ptr := Ptr + 1;
+               when 'c' =>
+                  Compile_Only := True;
+                  Make_Steps   := True;
 
-            if Output_File_Name_Present then
-               Osint.Fail ("duplicate -o switch");
-            else
-               Output_File_Name_Present := True;
-            end if;
+               --  Processing for C switch
 
-         --  Processing for q switch
+               when 'C' =>
+                  Create_Mapping_File := True;
 
-         when 'q' =>
-            Ptr := Ptr + 1;
-            Quiet_Output := True;
+               --  Processing for D switch
 
-         --  Processing for R switch
+               when 'D' =>
+                  if Object_Directory_Present then
+                     Osint.Fail ("duplicate -D switch");
 
-         when 'R' =>
-            Ptr := Ptr + 1;
-            Run_Path_Option := False;
+                  else
+                     Object_Directory_Present := True;
+                  end if;
 
-         --  Processing for s switch
+               --  Processing for f switch
 
-         when 's' =>
-            Ptr := Ptr + 1;
-            Check_Switches := True;
+               when 'f' =>
+                  Force_Compilations := True;
 
-         --  Processing for S switch
+               --  Processing for F switch
 
-         when 'S' =>
-            Ptr := Ptr + 1;
-            Commands_To_Stdout := True;
+               when 'F' =>
+                  Full_Path_Name_For_Brief_Errors := True;
 
-         --  Processing for v switch
+               --  Processing for h switch
 
-         when 'v' =>
-            Ptr := Ptr + 1;
-            Verbose_Mode := True;
-            Verbosity_Level := Opt.High;
+               when 'h' =>
+                  Usage_Requested := True;
 
-            if Ptr <= Max then
-               case Switch_Chars (Ptr) is
-                  when 'l' =>
-                     Verbosity_Level := Opt.Low;
+               --  Processing for i switch
 
-                  when 'm' =>
-                     Verbosity_Level := Opt.Medium;
+               when 'i' =>
+                  In_Place_Mode := True;
 
-                  when 'h' =>
-                     Verbosity_Level := Opt.High;
+               --  Processing for j switch
 
-                  when others =>
-                     Bad_Switch (Switch_Chars);
-               end case;
+               when 'j' =>
+                  --  -j not followed by a number is an error
 
-               Ptr := Ptr + 1;
-            end if;
+                  Bad_Switch (Switch_Chars);
 
-         --  Processing for x switch
+               --  Processing for k switch
 
-         when 'x' =>
-            Ptr := Ptr + 1;
-            External_Unit_Compilation_Allowed := True;
+               when 'k' =>
+                  Keep_Going := True;
 
-         --  Processing for z switch
+               --  Processing for l switch
 
-         when 'z' =>
-            Ptr := Ptr + 1;
-            No_Main_Subprogram := True;
+               when 'l' =>
+                  Link_Only  := True;
+                  Make_Steps := True;
 
-         --  Anything else is an error (illegal switch character)
+               --  Processing for M switch
 
-         when others =>
-            Bad_Switch (Switch_Chars);
+               when 'M' =>
+                  List_Dependencies := True;
 
-         end case;
+               --  Processing for n switch
 
-         if Ptr <= Max then
-            Bad_Switch (Switch_Chars);
-         end if;
+               when 'n' =>
+                  Do_Not_Execute := True;
+
+               --  Processing for o switch
+
+               when 'o' =>
+                  if Output_File_Name_Present then
+                     Osint.Fail ("duplicate -o switch");
+                  else
+                     Output_File_Name_Present := True;
+                  end if;
+
+               --  Processing for p switch
+
+               when 'p' =>
+                  Setup_Projects := True;
+
+               --  Processing for q switch
+
+               when 'q' =>
+                  Quiet_Output := True;
 
-      end Check_Switch;
+               --  Processing for R switch
 
+               when 'R' =>
+                  Run_Path_Option := False;
+
+               --  Processing for s switch
+
+               when 's' =>
+                  Ptr := Ptr + 1;
+                  Check_Switches := True;
+
+               --  Processing for v switch
+
+               when 'v' =>
+                  Verbose_Mode := True;
+                  Verbosity_Level := Opt.High;
+
+                  --  Processing for x switch
+
+               when 'x' =>
+                  External_Unit_Compilation_Allowed := True;
+
+                  --  Processing for z switch
+
+               when 'z' =>
+                  No_Main_Subprogram := True;
+
+                  --  Any other small letter is an illegal switch
+
+               when others =>
+                  if C in 'a' .. 'z' then
+                     Bad_Switch (Switch_Chars);
+
+                  else
+                     Success := False;
+                  end if;
+
+            end case;
+         end Check_Switch;
+      end if;
    end Scan_Make_Switches;
 
 end Switch.M;