This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][Ada] Small cleanups in make.adb


I found these unrelated issues while working on the multi-source
compile mode (see http://gcc.gnu.org/ml/gcc/2009-04/msg00380.html)
but I believe it is better not to lump in these changes with the
upcoming big patch for that new feature.

Bootstrapped and tested on i686-pc-linux-gnu.


2009-06-24  Oliver Kellogg  <okellogg@users.sourceforge.net>

	* make.adb: Fix nit in documentation of Q.
	(Arguments_Collected): Unneeded, remove.
	(Change_To_Object_Directory): Use Project directly.
	Don't reference Main_Project here, caller passes it in
	as needed. Add pragma Assert to ensure caller does not
	pass in No_Project.
	(Compile): Add new parameter, Project. Let procedure
	Collect_Arguments_And_Compile provide the proper value. Call
	Change_To_Object_Directory here instead of...
	(Collect_Arguments_And_Compile): here. Remove conditional
	call to Collect_Arguments, the condition is never true.


Index: gcc/ada/make.adb
===================================================================
--- gcc/ada/make.adb	(revision 148916)
+++ gcc/ada/make.adb	(working copy)
@@ -147,7 +147,7 @@
    --  Q_Front and Q.Last - 1 are the elements currently in the Q. When the Q
    --  is initialized Q_Front = Q.First = Q.Last. After Compile_Sources has
    --  terminated its execution, Q_Front = Q.Last and the elements contained
-   --  between Q.Front and Q.Last-1 are those that were explored and thus
+   --  between Q.First and Q.Last-1 are those that were explored and thus
    --  marked by Compile_Sources. Whenever the Q is reinitialized, the elements
    --  between Q.First and Q.Last - 1 are unmarked.
 
@@ -518,10 +518,6 @@
    Last_Argument : Natural := 0;
    --  Last index of arguments in Arguments above
 
-   Arguments_Collected : Boolean := False;
-   --  Set to True when the arguments for the next invocation of the compiler
-   --  have been collected.
-
    Arguments_Project : Project_Id;
    --  Project id, if any, of the source to be compiled
 
@@ -1378,32 +1374,23 @@
    --------------------------------
 
    procedure Change_To_Object_Directory (Project : Project_Id) is
-      Actual_Project   : Project_Id;
       Object_Directory : Path_Name_Type;
 
    begin
-      --  For sources outside of any project, compilation occurs in the object
-      --  directory of the main project, otherwise we use the project given.
+      pragma Assert (Project /= No_Project);
 
-      if Project = No_Project then
-         Actual_Project := Main_Project;
-      else
-         Actual_Project := Project;
-      end if;
-
       --  Nothing to do if the current working directory is already the correct
       --  object directory.
 
-      if Project_Of_Current_Object_Directory /= Actual_Project then
-         Project_Of_Current_Object_Directory := Actual_Project;
-         Object_Directory := Actual_Project.Object_Directory.Name;
+      if Project_Of_Current_Object_Directory /= Project then
+         Project_Of_Current_Object_Directory := Project;
+         Object_Directory := Project.Object_Directory.Name;
 
-         --  Set the working directory to the object directory of the actual
-         --  project.
+         --  Set the working directory to the object directory of the project.
 
          if Verbose_Mode then
             Write_Str  ("Changing to object directory of """);
-            Write_Name (Actual_Project.Display_Name);
+            Write_Name (Project.Display_Name);
             Write_Str  (""": """);
             Write_Name (Object_Directory);
             Write_Line ("""");
@@ -1418,9 +1405,9 @@
       when Directory_Error =>
          Make_Failed ("unable to change to object directory """ &
                       Path_Or_File_Name
-                        (Actual_Project.Object_Directory.Name) &
+                        (Project.Object_Directory.Name) &
                       """ of project " &
-                      Get_Name_String (Actual_Project.Display_Name));
+                      Get_Name_String (Project.Display_Name));
    end Change_To_Object_Directory;
 
    -----------
@@ -2318,7 +2305,6 @@
       Args           : Argument_List)
    is
    begin
-      Arguments_Collected := True;
       Arguments_Project := No_Project;
       Last_Argument := 0;
       Add_Arguments (Args);
@@ -2620,12 +2606,12 @@
       --  Check if s-stalib.adb needs to be compiled
 
       procedure Collect_Arguments_And_Compile
-        (Source_File  : File_Name_Type;
-         Source_Index : Int);
+        (Source_Index : Int);
       --  Collect arguments from project file (if any) and compile
 
       function Compile
-        (S            : File_Name_Type;
+        (Project      : Project_Id;
+         S            : File_Name_Type;
          L            : File_Name_Type;
          Source_Index : Int;
          Args         : Argument_List) return Process_Id;
@@ -2827,8 +2813,7 @@
       -----------------------------------
 
       procedure Collect_Arguments_And_Compile
-        (Source_File  : File_Name_Type;
-         Source_Index : Int)
+        (Source_Index : Int)
       is
       begin
          --  Process_Created will be set True if an attempt is made to compile
@@ -2836,13 +2821,6 @@
 
          Process_Created := False;
 
-         --  If arguments not yet collected (in Check), collect them now
-
-         if not Arguments_Collected then
-            Collect_Arguments
-              (Source_File, Source_Index, Source_File = Main_Source, Args);
-         end if;
-
          --  If we use mapping file (-P or -C switches), then get one
 
          if Create_Mapping_File then
@@ -2886,13 +2864,10 @@
                   end;
                end if;
 
-               --  Change to object directory of the project file, if necessary
-
-               Change_To_Object_Directory (Arguments_Project);
-
                Pid :=
                  Compile
-                   (File_Name_Type (Arguments_Path_Name),
+                   (Arguments_Project,
+                    File_Name_Type (Arguments_Path_Name),
                     Lib_File,
                     Source_Index,
                     Arguments (1 .. Last_Argument));
@@ -2900,14 +2875,8 @@
             end if;
 
          else
-            --  If this is a source outside of any project file, make sure it
-            --  will be compiled in object directory of the main project file.
-
-            if Main_Project /= No_Project then
-               Change_To_Object_Directory (Arguments_Project);
-            end if;
-
-            Pid := Compile (Full_Source_File, Lib_File, Source_Index,
+            Pid := Compile (Main_Project,
+                            Full_Source_File, Lib_File, Source_Index,
                             Arguments (1 .. Last_Argument));
             Process_Created := True;
          end if;
@@ -2918,7 +2887,8 @@
       -------------
 
       function Compile
-        (S            : File_Name_Type;
+        (Project      : Project_Id;
+         S            : File_Name_Type;
          L            : File_Name_Type;
          Source_Index : Int;
          Args         : Argument_List) return Process_Id
@@ -3100,6 +3070,10 @@
          Comp_Last := Comp_Last + 1;
          Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
 
+         if Project /= No_Project then
+            Change_To_Object_Directory (Project);
+         end if;
+
          GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
 
          Comp_Last := Comp_Last + 1;
@@ -3111,6 +3085,11 @@
             Make_Failed ("error, unable to locate " & Gcc.all);
          end if;
 
+         --  Change to object directory of the project file, if necessary
+         if Project /= No_Project then
+            Change_To_Object_Directory (Project);
+         end if;
+
          return
            GNAT.OS_Lib.Non_Blocking_Spawn
              (Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
@@ -3340,8 +3319,6 @@
                --  The source file that we are checking can be located
 
                else
-                  Arguments_Collected := False;
-
                   Collect_Arguments (Source_File, Source_Index,
                                      Source_File = Main_Source, Args);
 
@@ -3429,8 +3406,7 @@
                         --  Start the compilation and record it. We can do
                         --  this because there is at least one free process.
 
-                        Collect_Arguments_And_Compile
-                          (Source_File, Source_Index);
+                        Collect_Arguments_And_Compile (Source_Index);
 
                         --  Make sure we could successfully start
                         --  the Compilation.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]