sem_prag.adb (Analyze_Pragma): Add appropriate calls to Resolve_Suppressible in the...
[platform/upstream/gcc.git] / gcc / ada / gprep.adb
index 040a726..c4bf8e9 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2002-2007, Free Software Foundation, Inc.         --
+--          Copyright (C) 2002-2014, 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- --
@@ -23,8 +23,8 @@
 --                                                                          --
 ------------------------------------------------------------------------------
 
+with Atree;    use Atree;
 with Csets;
-with Err_Vars; use Err_Vars;
 with Errutil;
 with Namet;    use Namet;
 with Opt;
@@ -38,7 +38,8 @@ with Stringt;  use Stringt;
 with Switch;   use Switch;
 with Types;    use Types;
 
-with Ada.Text_IO;     use Ada.Text_IO;
+with Ada.Command_Line; use Ada.Command_Line;
+with Ada.Text_IO;      use Ada.Text_IO;
 
 with GNAT.Case_Util;            use GNAT.Case_Util;
 with GNAT.Command_Line;
@@ -55,6 +56,14 @@ package body GPrep is
    -- Argument Line Data --
    ------------------------
 
+   Unix_Line_Terminators : Boolean := False;
+   --  Set to True with option -T
+
+   type String_Array is array (Boolean) of String_Access;
+   Yes_No : constant String_Array :=
+     (False => new String'("YES"),
+      True  => new String'("NO"));
+
    Infile_Name  : Name_Id := No_Name;
    Outfile_Name : Name_Id := No_Name;
    Deffile_Name : Name_Id := No_Name;
@@ -83,9 +92,6 @@ package body GPrep is
    procedure Display_Copyright;
    --  Display the copyright notice
 
-   procedure Obsolescent_Check (S : Source_Ptr);
-   --  Null procedure, needed by instantiation of Scng below
-
    procedure Post_Scan;
    --  Null procedure, needed by instantiation of Scng below
 
@@ -95,7 +101,6 @@ package body GPrep is
       Errutil.Error_Msg_S,
       Errutil.Error_Msg_SC,
       Errutil.Error_Msg_SP,
-      Obsolescent_Check,
       Errutil.Style);
    --  The scanner for the preprocessor
 
@@ -161,16 +166,16 @@ package body GPrep is
 
    procedure Gnatprep is
    begin
-      --  Do some initializations (order is important here!)
+      --  Do some initializations (order is important here)
 
       Csets.Initialize;
-      Namet.Initialize;
       Snames.Initialize;
       Stringt.Initialize;
+      Prep.Initialize;
 
       --  Initialize the preprocessor
 
-      Prep.Initialize
+      Prep.Setup_Hooks
         (Error_Msg         => Errutil.Error_Msg'Access,
          Scan              => Scanner.Scan'Access,
          Set_Ignore_Errors => Errutil.Set_Ignore_Errors'Access,
@@ -201,14 +206,19 @@ package body GPrep is
 
          --  No input file specified, just output the usage and exit
 
-         Usage;
+         if Argument_Count = 0 then
+            Usage;
+         else
+            GNAT.Command_Line.Try_Help;
+         end if;
+
          return;
 
       elsif Outfile_Name = No_Name then
 
-         --  No output file specified, just output the usage and exit
+         --  No output file specified, exit
 
-         Usage;
+         GNAT.Command_Line.Try_Help;
          return;
       end if;
 
@@ -236,9 +246,9 @@ package body GPrep is
             Sinput.Main_Source_File := Deffile;
 
             if Deffile = No_Source_File then
-               Fail ("unable to find definition file """,
-                     Get_Name_String (Deffile_Name),
-                     """");
+               Fail ("unable to find definition file """
+                     & Get_Name_String (Deffile_Name)
+                     """");
             end if;
 
             Scanner.Initialize_Scanner (Deffile);
@@ -251,8 +261,9 @@ package body GPrep is
 
       if Total_Errors_Detected > 0 then
          Errutil.Finalize (Source_Type => "definition");
-         Fail ("errors in definition file """,
-               Get_Name_String (Deffile_Name), """");
+         Fail ("errors in definition file """
+               & Get_Name_String (Deffile_Name)
+               & """");
       end if;
 
       --  If -s switch was specified, print a sorted list of symbol names and
@@ -302,16 +313,6 @@ package body GPrep is
       New_Line (Outfile.all);
    end New_EOL_To_Outfile;
 
-   -----------------------
-   -- Obsolescent_Check --
-   -----------------------
-
-   procedure Obsolescent_Check (S : Source_Ptr) is
-      pragma Warnings (Off, S);
-   begin
-      null;
-   end Obsolescent_Check;
-
    ---------------
    -- Post_Scan --
    ---------------
@@ -475,17 +476,26 @@ package body GPrep is
       procedure Process_One_File is
          Infile : Source_File_Index;
 
+         Modified : Boolean;
+         pragma Warnings (Off, Modified);
+
       begin
          --  Create the output file (fails if this does not work)
 
          begin
-            Create (Text_Outfile, Out_File, Get_Name_String (Outfile_Name));
+            Create
+              (File => Text_Outfile,
+               Mode => Out_File,
+               Name => Get_Name_String (Outfile_Name),
+               Form => "Text_Translation=" &
+                       Yes_No (Unix_Line_Terminators).all);
 
          exception
             when others =>
                Fail
-                 ("unable to create output file """,
-                  Get_Name_String (Outfile_Name), """");
+                 ("unable to create output file """
+                  & Get_Name_String (Outfile_Name)
+                  & """");
          end;
 
          --  Load the input file
@@ -493,8 +503,9 @@ package body GPrep is
          Infile := Sinput.C.Load_File (Get_Name_String (Infile_Name));
 
          if Infile = No_Source_File then
-            Fail ("unable to find input file """,
-                  Get_Name_String (Infile_Name), """");
+            Fail ("unable to find input file """
+                  & Get_Name_String (Infile_Name)
+                  & """");
          end if;
 
          --  Set Main_Source_File to the input file for the benefit of
@@ -515,17 +526,17 @@ package body GPrep is
 
          --  Preprocess the input file
 
-         Prep.Preprocess;
+         Prep.Preprocess (Modified);
 
          --  In verbose mode, if there is no error, report it
 
-         if Opt.Verbose_Mode and then Err_Vars.Total_Errors_Detected = 0 then
+         if Opt.Verbose_Mode and then Total_Errors_Detected = 0 then
             Errutil.Finalize (Source_Type => "input");
          end if;
 
          --  If we had some errors, delete the output file, and report them
 
-         if Err_Vars.Total_Errors_Detected > 0 then
+         if Total_Errors_Detected > 0 then
             if Outfile /= Standard_Output then
                Delete (Text_Outfile);
             end if;
@@ -629,8 +640,9 @@ package body GPrep is
 
                         exception
                            when Directory_Error =>
-                              Fail ("could not create directory """,
-                                    Output, """");
+                              Fail ("could not create directory """
+                                    & Output
+                                    & """");
                         end;
                      end if;
 
@@ -714,7 +726,7 @@ package body GPrep is
 
       loop
          begin
-            Switch := GNAT.Command_Line.Getopt ("D: b c C r s u v");
+            Switch := GNAT.Command_Line.Getopt ("D: a b c C r s T u v");
 
             case Switch is
 
@@ -725,6 +737,10 @@ package body GPrep is
                   Process_Command_Line_Symbol_Definition
                     (S => GNAT.Command_Line.Parameter);
 
+               when 'a' =>
+                  Opt.No_Deletion := True;
+                  Opt.Undefined_Symbols_Are_False := True;
+
                when 'b' =>
                   Opt.Blank_Deleted_Lines := True;
 
@@ -740,6 +756,9 @@ package body GPrep is
                when 's' =>
                   Opt.List_Preprocessing_Symbols := True;
 
+               when 'T' =>
+                  Unix_Line_Terminators := True;
+
                when 'u' =>
                   Opt.Undefined_Symbols_Are_False := True;
 
@@ -754,7 +773,7 @@ package body GPrep is
             when GNAT.Command_Line.Invalid_Switch =>
                Write_Str ("Invalid Switch: -");
                Write_Line (GNAT.Command_Line.Full_Switch);
-               Usage;
+               GNAT.Command_Line.Try_Help;
                OS_Exit (1);
          end;
       end loop;
@@ -799,12 +818,14 @@ package body GPrep is
       Write_Line ("  deffile    Name of the definition file");
       Write_Eol;
       Write_Line ("gnatprep switches:");
+      Display_Usage_Version_And_Help;
       Write_Line ("   -b  Replace preprocessor lines by blank lines");
       Write_Line ("   -c  Keep preprocessor lines as comments");
       Write_Line ("   -C  Do symbol replacements within comments");
       Write_Line ("   -D  Associate symbol with value");
       Write_Line ("   -r  Generate Source_Reference pragma");
       Write_Line ("   -s  Print a sorted list of symbol names and values");
+      Write_Line ("   -T  Use LF as line terminators");
       Write_Line ("   -u  Treat undefined symbols as FALSE");
       Write_Line ("   -v  Verbose mode");
       Write_Eol;