OSDN Git Service

* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Procedure>: Set default
[pf3gnuchains/gcc-fork.git] / gcc / ada / makeutl.adb
index 50b9fe2..ab00b50 100644 (file)
 --                                                                          --
 ------------------------------------------------------------------------------
 
+with ALI;      use ALI;
 with Debug;
+with Fname;
 with Osint;    use Osint;
 with Output;   use Output;
+with Opt;      use Opt;
 with Prj.Ext;
 with Prj.Util;
 with Snames;   use Snames;
@@ -154,6 +157,143 @@ package body Makeutl is
       end if;
    end Add_Linker_Option;
 
+   -------------------------
+   -- Base_Name_Index_For --
+   -------------------------
+
+   function Base_Name_Index_For
+     (Main            : String;
+      Main_Index      : Int;
+      Index_Separator : Character) return File_Name_Type
+   is
+      Result : File_Name_Type;
+
+   begin
+      Name_Len := 0;
+      Add_Str_To_Name_Buffer (Base_Name (Main));
+
+      --  Remove the extension, if any, that is the last part of the base name
+      --  starting with a dot and following some characters.
+
+      for J in reverse 2 .. Name_Len loop
+         if Name_Buffer (J) = '.' then
+            Name_Len := J - 1;
+            exit;
+         end if;
+      end loop;
+
+      --  Add the index info, if index is different from 0
+
+      if Main_Index > 0 then
+         Add_Char_To_Name_Buffer (Index_Separator);
+
+         declare
+            Img : constant String := Main_Index'Img;
+         begin
+            Add_Str_To_Name_Buffer (Img (2 .. Img'Last));
+         end;
+      end if;
+
+      Result := Name_Find;
+      return Result;
+   end Base_Name_Index_For;
+
+   ------------------------------
+   -- Check_Source_Info_In_ALI --
+   ------------------------------
+
+   function Check_Source_Info_In_ALI (The_ALI : ALI_Id) return Boolean is
+      Unit_Name : Name_Id;
+
+   begin
+      --  Loop through units
+
+      for U in ALIs.Table (The_ALI).First_Unit ..
+               ALIs.Table (The_ALI).Last_Unit
+      loop
+         --  Check if the file name is one of the source of the unit
+
+         Get_Name_String (Units.Table (U).Uname);
+         Name_Len  := Name_Len - 2;
+         Unit_Name := Name_Find;
+
+         if File_Not_A_Source_Of (Unit_Name, Units.Table (U).Sfile) then
+            return False;
+         end if;
+
+         --  Loop to do same check for each of the withed units
+
+         for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
+            declare
+               WR : ALI.With_Record renames Withs.Table (W);
+
+            begin
+               if WR.Sfile /= No_File then
+                  Get_Name_String (WR.Uname);
+                  Name_Len  := Name_Len - 2;
+                  Unit_Name := Name_Find;
+
+                  if File_Not_A_Source_Of (Unit_Name, WR.Sfile) then
+                     return False;
+                  end if;
+               end if;
+            end;
+         end loop;
+      end loop;
+
+      --  Loop to check subunits
+
+      for D in ALIs.Table (The_ALI).First_Sdep ..
+               ALIs.Table (The_ALI).Last_Sdep
+      loop
+         declare
+            SD : Sdep_Record renames Sdep.Table (D);
+
+         begin
+            Unit_Name := SD.Subunit_Name;
+
+            if Unit_Name /= No_Name then
+
+               --  For separates, the file is no longer associated with the
+               --  unit ("proc-sep.adb" is not associated with unit "proc.sep")
+               --  so we need to check whether the source file still exists in
+               --  the source tree: it will if it matches the naming scheme
+               --  (and then will be for the same unit).
+
+               if Find_Source
+                    (In_Tree   => Project_Tree,
+                     Project   => No_Project,
+                     Base_Name => SD.Sfile) = No_Source
+               then
+                  --  If this is not a runtime file or if, when gnatmake switch
+                  --  -a is used, we are not able to find this subunit in the
+                  --  source directories, then recompilation is needed.
+
+                  if not Fname.Is_Internal_File_Name (SD.Sfile)
+                    or else
+                      (Check_Readonly_Files
+                        and then Full_Source_Name (SD.Sfile) = No_File)
+                  then
+                     if Verbose_Mode then
+                        Write_Line
+                          ("While parsing ALI file, file "
+                           & Get_Name_String (SD.Sfile)
+                           & " is indicated as containing subunit "
+                           & Get_Name_String (Unit_Name)
+                           & " but this does not match what was found while"
+                           & " parsing the project. Will recompile");
+                     end if;
+
+                     return False;
+                  end if;
+               end if;
+            end if;
+         end;
+      end loop;
+
+      return True;
+   end Check_Source_Info_In_ALI;
+
    -----------------
    -- Create_Name --
    -----------------
@@ -229,7 +369,10 @@ package body Makeutl is
             return "";
          end if;
 
-         return Normalize_Pathname (Exec (Exec'First .. Path_Last - 4));
+         return Normalize_Pathname
+                  (Exec (Exec'First .. Path_Last - 4),
+                   Resolve_Links => Opt.Follow_Links_For_Dirs)
+           & Directory_Separator;
       end Get_Install_Dir;
 
    --  Beginning of Executable_Prefix_Path
@@ -248,16 +391,62 @@ package body Makeutl is
       --  directory prefix.
 
       declare
-         Path : constant String_Access := Locate_Exec_On_Path (Exec_Name);
+         Path : String_Access := Locate_Exec_On_Path (Exec_Name);
       begin
          if Path = null then
             return "";
          else
-            return Get_Install_Dir (Path.all);
+            declare
+               Dir : constant String := Get_Install_Dir (Path.all);
+            begin
+               Free (Path);
+               return Dir;
+            end;
          end if;
       end;
    end Executable_Prefix_Path;
 
+   --------------------------
+   -- File_Not_A_Source_Of --
+   --------------------------
+
+   function File_Not_A_Source_Of
+     (Uname : Name_Id;
+      Sfile : File_Name_Type) return Boolean
+   is
+      Unit : constant Unit_Index :=
+               Units_Htable.Get (Project_Tree.Units_HT, Uname);
+
+      At_Least_One_File : Boolean := False;
+
+   begin
+      if Unit /= No_Unit_Index then
+         for F in Unit.File_Names'Range loop
+            if Unit.File_Names (F) /= null then
+               At_Least_One_File := True;
+               if Unit.File_Names (F).File = Sfile then
+                  return False;
+               end if;
+            end if;
+         end loop;
+
+         if not At_Least_One_File then
+
+            --  The unit was probably created initially for a separate unit
+            --  (which are initially created as IMPL when both suffixes are the
+            --  same). Later on, Override_Kind changed the type of the file,
+            --  and the unit is no longer valid in fact.
+
+            return False;
+         end if;
+
+         Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
+         return True;
+      end if;
+
+      return False;
+   end File_Not_A_Source_Of;
+
    ----------
    -- Hash --
    ----------
@@ -306,10 +495,12 @@ package body Makeutl is
    -- Is_External_Assignment --
    ----------------------------
 
-   function Is_External_Assignment (Argv : String) return Boolean is
+   function Is_External_Assignment
+     (Tree : Prj.Tree.Project_Node_Tree_Ref;
+      Argv : String) return Boolean
+   is
       Start     : Positive := 3;
       Finish    : Natural := Argv'Last;
-      Equal_Pos : Natural;
 
       pragma Assert (Argv'First = 1);
       pragma Assert (Argv (1 .. 2) = "-X");
@@ -327,20 +518,9 @@ package body Makeutl is
          end if;
       end if;
 
-      Equal_Pos := Start;
-
-      while Equal_Pos <= Finish and then Argv (Equal_Pos) /= '=' loop
-         Equal_Pos := Equal_Pos + 1;
-      end loop;
-
-      if Equal_Pos = Start or else Equal_Pos > Finish then
-         return False;
-      else
-         Prj.Ext.Add
-           (External_Name => Argv (Start .. Equal_Pos - 1),
-            Value         => Argv (Equal_Pos + 1 .. Finish));
-         return True;
-      end if;
+      return Prj.Ext.Check
+        (Tree        => Tree,
+         Declaration => Argv (Start .. Finish));
    end Is_External_Assignment;
 
    ---------------
@@ -460,6 +640,7 @@ package body Makeutl is
 
       type File_And_Loc is record
          File_Name : File_Name_Type;
+         Index     : Int := 0;
          Location  : Source_Ptr := No_Location;
       end record;
 
@@ -484,7 +665,7 @@ package body Makeutl is
          Name_Len := 0;
          Add_Str_To_Name_Buffer (Name);
          Names.Increment_Last;
-         Names.Table (Names.Last) := (Name_Find, No_Location);
+         Names.Table (Names.Last) := (Name_Find, 0, No_Location);
       end Add_Main;
 
       ------------
@@ -497,6 +678,19 @@ package body Makeutl is
          Mains.Reset;
       end Delete;
 
+      ---------------
+      -- Get_Index --
+      ---------------
+
+      function Get_Index return Int is
+      begin
+         if Current in Names.First .. Names.Last then
+            return Names.Table (Current).Index;
+         else
+            return 0;
+         end if;
+      end Get_Index;
+
       ------------------
       -- Get_Location --
       ------------------
@@ -542,6 +736,17 @@ package body Makeutl is
          Current := 0;
       end Reset;
 
+      ---------------
+      -- Set_Index --
+      ---------------
+
+      procedure Set_Index (Index : Int) is
+      begin
+         if Names.Last > 0 then
+            Names.Table (Names.Last).Index := Index;
+         end if;
+      end Set_Index;
+
       ------------------
       -- Set_Location --
       ------------------
@@ -598,7 +803,8 @@ package body Makeutl is
      (Switch               : in out String_Access;
       Parent               : String;
       Including_L_Switch   : Boolean := True;
-      Including_Non_Switch : Boolean := True)
+      Including_Non_Switch : Boolean := True;
+      Including_RTS        : Boolean := False)
    is
    begin
       if Switch /= null then
@@ -628,13 +834,20 @@ package body Makeutl is
                then
                   Start := 4;
 
+               elsif Including_RTS
+                 and then Sw'Length >= 7
+                 and then Sw (2 .. 6) = "-RTS="
+               then
+                  Start := 7;
+
                else
                   return;
                end if;
 
                --  Because relative path arguments to --RTS= may be relative
                --  to the search directory prefix, those relative path
-               --  arguments are not converted.
+               --  arguments are converted only when they include directory
+               --  information.
 
                if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
                   if Parent'Length = 0 then
@@ -643,6 +856,19 @@ package body Makeutl is
                         & Sw
                         & """) are not allowed");
 
+                  elsif Including_RTS then
+                     for J in Start .. Sw'Last loop
+                        if Sw (J) = Directory_Separator then
+                           Switch :=
+                             new String'
+                               (Sw (1 .. Start - 1) &
+                                Parent &
+                                Directory_Separator &
+                                Sw (Start .. Sw'Last));
+                           return;
+                        end if;
+                     end loop;
+
                   else
                      Switch :=
                        new String'
@@ -722,4 +948,52 @@ package body Makeutl is
       return Result;
    end Unit_Index_Of;
 
+   -----------------
+   -- Verbose_Msg --
+   -----------------
+
+   procedure Verbose_Msg
+     (N1                : Name_Id;
+      S1                : String;
+      N2                : Name_Id := No_Name;
+      S2                : String  := "";
+      Prefix            : String := "  -> ";
+      Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
+   is
+   begin
+      if not Opt.Verbose_Mode
+        or else Minimum_Verbosity > Opt.Verbosity_Level
+      then
+         return;
+      end if;
+
+      Write_Str (Prefix);
+      Write_Str ("""");
+      Write_Name (N1);
+      Write_Str (""" ");
+      Write_Str (S1);
+
+      if N2 /= No_Name then
+         Write_Str (" """);
+         Write_Name (N2);
+         Write_Str (""" ");
+      end if;
+
+      Write_Str (S2);
+      Write_Eol;
+   end Verbose_Msg;
+
+   procedure Verbose_Msg
+     (N1                : File_Name_Type;
+      S1                : String;
+      N2                : File_Name_Type := No_File;
+      S2                : String  := "";
+      Prefix            : String := "  -> ";
+      Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
+   is
+   begin
+      Verbose_Msg
+        (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
+   end Verbose_Msg;
+
 end Makeutl;