OSDN Git Service

2009-08-17 Thomas Quinot <quinot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-util.adb
index 2f953a3..159ee83 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2001-2008, Free Software Foundation, Inc.         --
+--          Copyright (C) 2001-2009, 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- --
@@ -114,8 +114,7 @@ package body Prj.Util is
    is
       pragma Assert (Project /= No_Project);
 
-      The_Packages : constant Package_Id :=
-                       In_Tree.Projects.Table (Project).Decl.Packages;
+      The_Packages : constant Package_Id := Project.Decl.Packages;
 
       Builder_Package : constant Prj.Package_Id :=
                           Prj.Util.Value_Of
@@ -131,11 +130,9 @@ package body Prj.Util is
                         In_Package              => Builder_Package,
                         In_Tree                 => In_Tree);
 
-      Executable_Suffix : Variable_Value := Nil_Variable_Value;
-
       Executable_Suffix_Name : Name_Id := No_Name;
 
-      Naming : constant Naming_Data := In_Tree.Projects.Table (Project).Naming;
+      Lang   : Language_Ptr;
 
       Spec_Suffix : Name_Id := No_Name;
       Body_Suffix : Name_Id := No_Name;
@@ -144,8 +141,8 @@ package body Prj.Util is
       Body_Suffix_Length : Natural := 0;
 
       procedure Get_Suffixes
-        (B_Suffix : String;
-         S_Suffix : String);
+        (B_Suffix : File_Name_Type;
+         S_Suffix : File_Name_Type);
       --  Get the non empty suffixes in variables Spec_Suffix and Body_Suffix
 
       ------------------
@@ -153,22 +150,18 @@ package body Prj.Util is
       ------------------
 
       procedure Get_Suffixes
-        (B_Suffix : String;
-         S_Suffix : String)
+        (B_Suffix : File_Name_Type;
+         S_Suffix : File_Name_Type)
       is
       begin
-         if B_Suffix'Length > 0 then
-            Name_Len := B_Suffix'Length;
-            Name_Buffer (1 .. Name_Len) := B_Suffix;
-            Body_Suffix := Name_Find;
-            Body_Suffix_Length := B_Suffix'Length;
+         if B_Suffix /= No_File then
+            Body_Suffix := Name_Id (B_Suffix);
+            Body_Suffix_Length := Natural (Length_Of_Name (Body_Suffix));
          end if;
 
-         if S_Suffix'Length > 0 then
-            Name_Len := S_Suffix'Length;
-            Name_Buffer (1 .. Name_Len) := S_Suffix;
-            Spec_Suffix := Name_Find;
-            Spec_Suffix_Length := S_Suffix'Length;
+         if S_Suffix /= No_File then
+            Spec_Suffix := Name_Id (S_Suffix);
+            Spec_Suffix_Length := Natural (Length_Of_Name (Spec_Suffix));
          end if;
       end Get_Suffixes;
 
@@ -176,36 +169,21 @@ package body Prj.Util is
 
    begin
       if Ada_Main then
-         Get_Suffixes
-           (B_Suffix => Body_Suffix_Of (In_Tree, "ada", Naming),
-            S_Suffix => Spec_Suffix_Of (In_Tree, "ada", Naming));
-
+         Lang := Get_Language_From_Name (Project, "ada");
       elsif Language /= "" then
+         Lang := Get_Language_From_Name (Project, Language);
+      end if;
+
+      if Lang /= null then
          Get_Suffixes
-           (B_Suffix => Body_Suffix_Of (In_Tree, Language, Naming),
-            S_Suffix => Spec_Suffix_Of (In_Tree, Language, Naming));
+           (B_Suffix => Lang.Config.Naming_Data.Body_Suffix,
+            S_Suffix => Lang.Config.Naming_Data.Spec_Suffix);
       end if;
 
       if Builder_Package /= No_Package then
-         if Get_Mode = Multi_Language then
-            Executable_Suffix_Name :=
-              In_Tree.Projects.Table (Project).Config.Executable_Suffix;
+         Executable_Suffix_Name := Project.Config.Executable_Suffix;
 
-         else
-            Executable_Suffix := Prj.Util.Value_Of
-              (Variable_Name => Name_Executable_Suffix,
-               In_Variables  => In_Tree.Packages.Table
-                 (Builder_Package).Decl.Attributes,
-               In_Tree       => In_Tree);
-
-            if Executable_Suffix /= Nil_Variable_Value
-              and then not Executable_Suffix.Default
-            then
-               Executable_Suffix_Name := Executable_Suffix.Value;
-            end if;
-         end if;
-
-         if Executable = Nil_Variable_Value and Ada_Main then
+         if Executable = Nil_Variable_Value and then Ada_Main then
             Get_Name_String (Main);
 
             --  Try as index the name minus the implementation suffix or minus
@@ -219,7 +197,8 @@ package body Prj.Util is
                Truncated : Boolean := False;
 
             begin
-               if Last > Natural (Length_Of_Name (Body_Suffix))
+               if Body_Suffix /= No_Name
+                 and then Last > Natural (Length_Of_Name (Body_Suffix))
                  and then Name (Last - Body_Suffix_Length + 1 .. Last) =
                             Get_Name_String (Body_Suffix)
                then
@@ -227,7 +206,8 @@ package body Prj.Util is
                   Last := Last - Body_Suffix_Length;
                end if;
 
-               if not Truncated
+               if Spec_Suffix /= No_Name
+                 and then not Truncated
                  and then Last > Spec_Suffix_Length
                  and then Name (Last - Spec_Suffix_Length + 1 .. Last) =
                             Get_Name_String (Spec_Suffix)
@@ -254,7 +234,8 @@ package body Prj.Util is
          --  possibly suffixed by the executable suffix.
 
          if Executable /= Nil_Variable_Value
-           and then Executable.Value /= Empty_Name
+           and then Executable.Value /= No_Name
+           and then Length_Of_Name (Executable.Value) /= 0
          then
             --  Get the executable name. If Executable_Suffix is defined,
             --  make sure that it will be the extension of the executable.
@@ -306,42 +287,24 @@ package body Prj.Util is
          Get_Name_String (Strip_Suffix (Main));
       end if;
 
-      if Executable_Suffix /= Nil_Variable_Value
-        and then not Executable_Suffix.Default
-      then
-         --  If attribute Executable_Suffix is specified, add this suffix
+      --  Get the executable name. If Executable_Suffix is defined in the
+      --  configuration, make sure that it will be the extension of the
+      --  executable.
 
-         declare
-            Suffix : constant String :=
-                       Get_Name_String (Executable_Suffix.Value);
-         begin
-            Name_Buffer (Name_Len + 1 .. Name_Len + Suffix'Length) := Suffix;
-            Name_Len := Name_Len + Suffix'Length;
-            return Name_Find;
-         end;
+      declare
+         Saved_EEOT : constant Name_Id := Executable_Extension_On_Target;
+         Result     : File_Name_Type;
 
-      else
-         --  Get the executable name. If Executable_Suffix is defined in the
-         --  configuration, make sure that it will be the extension of the
-         --  executable.
-
-         declare
-            Saved_EEOT : constant Name_Id := Executable_Extension_On_Target;
-            Result     : File_Name_Type;
-
-         begin
-            if In_Tree.Projects.Table (Project).Config.Executable_Suffix /=
-              No_Name
-            then
-               Executable_Extension_On_Target :=
-                 In_Tree.Projects.Table (Project).Config.Executable_Suffix;
-            end if;
+      begin
+         if Project.Config.Executable_Suffix /= No_Name then
+            Executable_Extension_On_Target :=
+              Project.Config.Executable_Suffix;
+         end if;
 
-            Result := Executable_Name (Name_Find);
-            Executable_Extension_On_Target := Saved_EEOT;
-            return Result;
-         end;
-      end if;
+         Result := Executable_Name (Name_Find);
+         Executable_Extension_On_Target := Saved_EEOT;
+         return Result;
+      end;
    end Executable_Of;
 
    --------------
@@ -599,20 +562,26 @@ package body Prj.Util is
 
       Real_Index_1 := Index;
 
-      if not Element.Index_Case_Sensitive or Force_Lower_Case_Index then
-         Get_Name_String (Index);
-         To_Lower (Name_Buffer (1 .. Name_Len));
-         Real_Index_1 := Name_Find;
+      if not Element.Index_Case_Sensitive or else Force_Lower_Case_Index then
+         if Index /= All_Other_Names then
+            Get_Name_String (Index);
+            To_Lower (Name_Buffer (1 .. Name_Len));
+            Real_Index_1 := Name_Find;
+         end if;
       end if;
 
       while Current /= No_Array_Element loop
          Element := In_Tree.Array_Elements.Table (Current);
          Real_Index_2 := Element.Index;
 
-         if not Element.Index_Case_Sensitive or Force_Lower_Case_Index then
-            Get_Name_String (Element.Index);
-            To_Lower (Name_Buffer (1 .. Name_Len));
-            Real_Index_2 := Name_Find;
+         if not Element.Index_Case_Sensitive
+           or else Force_Lower_Case_Index
+         then
+            if Element.Index /= All_Other_Names then
+               Get_Name_String (Element.Index);
+               To_Lower (Name_Buffer (1 .. Name_Len));
+               Real_Index_2 := Name_Find;
+            end if;
          end if;
 
          if Real_Index_1 = Real_Index_2 and then