OSDN Git Service

2010-10-05 Ed Schonberg <schonberg@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / osint-b.adb
index a0ebff8..39b7a99 100644 (file)
@@ -6,35 +6,30 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2001-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2001-2010, 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,  59 Temple Place - Suite 330,  Boston, --
--- MA 02111-1307, 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 Hostparm;
-with Namet;   use Namet;
-with Opt;     use Opt;
+with Opt;      use Opt;
+with Output;   use Output;
+with Targparm; use Targparm;
 
 package body Osint.B is
 
-   Binder_Output_Time_Stamps_Set : Boolean := False;
-
-   Old_Binder_Output_Time_Stamp  : Time_Stamp_Type;
-   New_Binder_Output_Time_Stamp  : Time_Stamp_Type;
-   Recording_Time_From_Last_Bind : Boolean := False;
+   Current_List_File : File_Descriptor := Invalid_FD;
 
    -------------------------
    -- Close_Binder_Output --
@@ -47,16 +42,25 @@ package body Osint.B is
 
       if not Status then
          Fail
-           ("error while closing generated file ",
-            Get_Name_String (Output_File_Name));
+           ("error while closing generated file "
+            Get_Name_String (Output_File_Name));
       end if;
 
-      if Recording_Time_From_Last_Bind then
-         New_Binder_Output_Time_Stamp  := File_Stamp (Output_File_Name);
-         Binder_Output_Time_Stamps_Set := True;
-      end if;
    end Close_Binder_Output;
 
+   ---------------------
+   -- Close_List_File --
+   ---------------------
+
+   procedure Close_List_File is
+   begin
+      if Current_List_File /= Invalid_FD then
+         Close (Current_List_File);
+         Current_List_File := Invalid_FD;
+         Set_Standard_Output;
+      end if;
+   end Close_List_File;
+
    --------------------------
    -- Create_Binder_Output --
    --------------------------
@@ -71,10 +75,14 @@ package body Osint.B is
       Findex2   : Natural;
       Flength   : Natural;
 
+      Bind_File_Prefix_Len : Natural := 2;
+      --  Length of binder file prefix (normally set to 2 for b~, but gets
+      --  reset to 3 for VMS for b__).
+
    begin
       if Output_File_Name /= "" then
-         Name_Buffer (Output_File_Name'Range) := Output_File_Name;
-         Name_Buffer (Output_File_Name'Last + 1) := ASCII.NUL;
+         Name_Buffer (1 .. Output_File_Name'Length) := Output_File_Name;
+         Name_Buffer (Output_File_Name'Length + 1)  := ASCII.NUL;
 
          if Typ = 's' then
             Name_Buffer (Output_File_Name'Last) := 's';
@@ -112,16 +120,24 @@ package body Osint.B is
 
          if Maximum_File_Name_Length > 0 then
 
+            if OpenVMS_On_Target and then Typ /= 'c' then
+               Bind_File_Prefix_Len := 3;
+            end if;
+
             --  Make room for the extra two characters in "b?"
 
-            while Int (Flength) > Maximum_File_Name_Length - 2 loop
+            while Int (Flength) >
+              Maximum_File_Name_Length - Nat (Bind_File_Prefix_Len)
+            loop
                Findex2 := Findex2 - 1;
                Flength := Findex2 - Findex1;
             end loop;
          end if;
 
-         Name_Buffer (3 .. Flength + 2) := File_Name (Findex1 .. Findex2 - 1);
-         Name_Buffer (Flength + 3) := '.';
+         Name_Buffer
+           (Bind_File_Prefix_Len + 1 .. Flength + Bind_File_Prefix_Len) :=
+              File_Name (Findex1 .. Findex2 - 1);
+         Name_Buffer (Flength + Bind_File_Prefix_Len + 1) := '.';
 
          --  C bind file, name is b_xxx.c
 
@@ -132,29 +148,26 @@ package body Osint.B is
             Name_Len := Flength + 4;
 
          --  Ada bind file, name is b~xxx.adb or b~xxx.ads
-         --  (with $ instead of ~ in VMS)
+         --  (with __ instead of ~ in VMS)
 
          else
-            if Hostparm.OpenVMS then
-               Name_Buffer (2) := '$';
+            if OpenVMS_On_Target then
+               Name_Buffer (2) := '_';
+               Name_Buffer (3) := '_';
             else
                Name_Buffer (2) := '~';
             end if;
 
-            Name_Buffer (Flength + 4) := 'a';
-            Name_Buffer (Flength + 5) := 'd';
-            Name_Buffer (Flength + 6) := Typ;
-            Name_Buffer (Flength + 7) := ASCII.NUL;
-            Name_Len := Flength + 6;
+            Name_Buffer (Flength + Bind_File_Prefix_Len + 2) := 'a';
+            Name_Buffer (Flength + Bind_File_Prefix_Len + 3) := 'd';
+            Name_Buffer (Flength + Bind_File_Prefix_Len + 4) := Typ;
+            Name_Buffer (Flength + Bind_File_Prefix_Len + 5) := ASCII.NUL;
+            Name_Len := Flength + Bind_File_Prefix_Len + 4;
          end if;
       end if;
 
       Bfile := Name_Find;
 
-      if Recording_Time_From_Last_Bind then
-         Old_Binder_Output_Time_Stamp := File_Stamp (Bfile);
-      end if;
-
       Create_File_And_Check (Output_FD, Text);
    end Create_Binder_Output;
 
@@ -170,79 +183,30 @@ package body Osint.B is
 
    function Next_Main_Lib_File return File_Name_Type renames Next_Main_File;
 
-   --------------------------------
-   -- Record_Time_From_Last_Bind --
-   --------------------------------
+   ---------------------------------
+   -- Set_Current_File_Name_Index --
+   ---------------------------------
 
-   procedure Record_Time_From_Last_Bind is
+   procedure Set_Current_File_Name_Index (To : Int) is
    begin
-      Recording_Time_From_Last_Bind := True;
-   end Record_Time_From_Last_Bind;
-
-   -------------------------
-   -- Time_From_Last_Bind --
-   -------------------------
+      Current_File_Name_Index := To;
+   end Set_Current_File_Name_Index;
 
-   function Time_From_Last_Bind return Nat is
-      Old_Y  : Nat;
-      Old_M  : Nat;
-      Old_D  : Nat;
-      Old_H  : Nat;
-      Old_Mi : Nat;
-      Old_S  : Nat;
-      New_Y  : Nat;
-      New_M  : Nat;
-      New_D  : Nat;
-      New_H  : Nat;
-      New_Mi : Nat;
-      New_S  : Nat;
-
-      type Month_Data is array (Int range 1 .. 12) of Int;
-      Cumul : constant Month_Data := (0, 0, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7);
-      --  Represents the difference in days from a period compared to the
-      --  same period if all months had 31 days, i.e:
-      --
-      --    Cumul (m) = 31x(m-1) - (number of days from 01/01 to m/01)
-
-      Res : Int;
+   -------------------
+   -- Set_List_File --
+   -------------------
 
+   procedure Set_List_File (Filename : String) is
    begin
-      if not Recording_Time_From_Last_Bind
-        or else not Binder_Output_Time_Stamps_Set
-        or else Old_Binder_Output_Time_Stamp = Empty_Time_Stamp
-      then
-         return Nat'Last;
-      end if;
-
-      Split_Time_Stamp
-       (Old_Binder_Output_Time_Stamp,
-        Old_Y, Old_M, Old_D, Old_H, Old_Mi, Old_S);
-
-      Split_Time_Stamp
-       (New_Binder_Output_Time_Stamp,
-        New_Y, New_M, New_D, New_H, New_Mi, New_S);
-
-      Res := New_Mi - Old_Mi;
-
-      --  60 minutes in an hour
-
-      Res := Res + 60 * (New_H  - Old_H);
-
-      --  24 hours in a day
+      pragma Assert (Current_List_File = Invalid_FD);
+      Current_List_File := Create_File (Filename, Text);
 
-      Res := Res + 60 * 24 * (New_D  - Old_D);
-
-      --  Almost 31 days in a month
-
-      Res := Res + 60 * 24 *
-        (31 * (New_M - Old_M) - Cumul (New_M) + Cumul (Old_M));
-
-      --  365 days in a year
-
-      Res := Res + 60 * 24 * 365 * (New_Y - Old_Y);
-
-      return Res;
-   end Time_From_Last_Bind;
+      if Current_List_File = Invalid_FD then
+         Fail ("cannot create list file: " & Filename);
+      else
+         Set_Output (Current_List_File);
+      end if;
+   end Set_List_File;
 
    -----------------------
    -- Write_Binder_Info --