OSDN Git Service

PR bootstrap/11932
[pf3gnuchains/gcc-fork.git] / gcc / ada / fname-uf.adb
index 3572d1a..9852688 100644 (file)
@@ -6,9 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---                            $Revision$
---                                                                          --
---          Copyright (C) 1992-2001, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2004, 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- --
 -- MA 02111-1307, USA.                                                      --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
--- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
 --                                                                          --
 ------------------------------------------------------------------------------
 
 with Alloc;
 with Debug;    use Debug;
-with Fmap;
+with Fmap;     use Fmap;
 with Krunch;
 with Namet;    use Namet;
 with Opt;      use Opt;
@@ -125,9 +123,9 @@ package body Fname.UF is
    -------------------
 
    function Get_File_Name
-     (Uname   : Unit_Name_Type;
-      Subunit : Boolean)
-      return    File_Name_Type
+     (Uname    : Unit_Name_Type;
+      Subunit  : Boolean;
+      May_Fail : Boolean := False) return File_Name_Type
    is
       Unit_Char : Character;
       --  Set to 's' or 'b' for spec or body or to 'u' for a subunit
@@ -140,6 +138,7 @@ package body Fname.UF is
 
       Pname : File_Name_Type := No_File;
       Fname : File_Name_Type := No_File;
+      --  Path name and File name for mapping
 
    begin
       --  Null or error name means that some previous error occurred
@@ -149,12 +148,12 @@ package body Fname.UF is
          raise Unrecoverable_Error;
       end if;
 
-      --  Look into the mapping from unit names to file names
+      --  Look in the map from unit names to file names
 
-      Fname := Fmap.File_Name_Of (Uname);
+      Fname := Mapped_File_Name (Uname);
 
       --  If the unit name is already mapped, return the corresponding
-      --  file name.
+      --  file name from the map.
 
       if Fname /= No_File then
          return Fname;
@@ -222,6 +221,9 @@ package body Fname.UF is
          Dot  : String_Ptr;
          Dotl : Natural;
 
+         Is_Predef : Boolean;
+         --  Set True for predefined file
+
          function C (N : Natural) return Character;
          --  Return N'th character of pattern
 
@@ -252,11 +254,25 @@ package body Fname.UF is
                if SFN_Patterns.Table (Pent).Typ = Unit_Char_Search then
                   Name_Len := 0;
 
+                  --  Determine if we have a predefined file name
+
+                  Name_Len := Uname'Length;
+                  Name_Buffer (1 .. Name_Len) := Uname;
+                  Is_Predef :=
+                    Is_Predefined_File_Name (Renamings_Included => True);
+
                   --  Found a match, execute the pattern
 
                   Name_Len := Uname'Length;
                   Name_Buffer (1 .. Name_Len) := Uname;
-                  Set_Casing (SFN_Patterns.Table (Pent).Cas);
+
+                  --  Apply casing, except that we do not do this for the case
+                  --  of a predefined library file. For the latter, we always
+                  --  use the all lower case name, regardless of the setting.
+
+                  if not Is_Predef then
+                     Set_Casing (SFN_Patterns.Table (Pent).Cas);
+                  end if;
 
                   --  If dot translation required do it
 
@@ -369,36 +385,48 @@ package body Fname.UF is
 
                   Fnam := File_Name_Type (Name_Find);
 
-                  --  If we are in the first search of the table, then
-                  --  we check if the file is present, and only accept
-                  --  the entry if it is indeed present. For the second
-                  --  search, we accept the entry without this check.
-
-                  --  If we only have two entries in the table, then there
-                  --  is no point in seeing if the file exists, since we
-                  --  will end up accepting it anyway on the second search,
-                  --  so just quit and accept it now to save time.
+                  --  If we are in the second search of the table, we accept
+                  --  the file name without checking, because we know that
+                  --  the file does not exist, except when May_Fail is True,
+                  --  in which case we return No_File.
 
-                  if No_File_Check or else SFN_Patterns.Last = 2 then
-                     return Fnam;
+                  if No_File_Check then
+                     if May_Fail then
+                        return No_File;
+                     else
+                        return Fnam;
+                     end if;
 
-                  --  Check if file exists and if so, return the entry
+                  --  Otherwise we check if the file exists
 
                   else
                      Pname := Find_File (Fnam, Source);
 
-                  --  Check if file exists and if so, return the entry
+                     --  If it does exist, we add it to the mappings and
+                     --  return the file name.
 
                      if Pname /= No_File then
 
                         --  Add to mapping, so that we don't do another
                         --  path search in Find_File for this file name
+                        --  and, if we use a mapping file, we are ready
+                        --  to update it at the end of this compilation
+                        --  for the benefit of other compilation processes.
+
+                        Add_To_File_Map (Get_File_Name.Uname, Fnam, Pname);
+                        return Fnam;
+
+                     --  If there are only two entries, they are those of
+                     --  the default GNAT naming scheme. The file does
+                     --  not exist, but there is no point doing the
+                     --  second search, because we will end up with the
+                     --  same file name. Just return the file name.
 
-                        Fmap.Add (Get_File_Name.Uname, Fnam, Pname);
+                     elsif SFN_Patterns.Last = 2 then
                         return Fnam;
 
-                     --  This entry does not match after all, because this is
-                     --  the first search loop, and the file does not exist.
+                     --  The file does not exist, but there may be other
+                     --  naming scheme. Keep on searching.
 
                      else
                         Fnam := No_File;