-- --
-- B o d y --
-- --
--- $Revision$
--- --
--- Copyright (C) 2001 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- --
--- 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. --
--- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
+-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-with GNAT.OS_Lib; use GNAT.OS_Lib;
-with Namet; use Namet;
+with Fmap;
with Opt;
-with Osint; use Osint;
-with Output; use Output;
-with Prj.Com; use Prj.Com;
-with Prj.Util;
-with Snames; use Snames;
-with Stringt; use Stringt;
-with Table;
+with Osint; use Osint;
+with Output; use Output;
+with Prj.Com; use Prj.Com;
+with Tempdir;
package body Prj.Env is
- type Naming_Id is new Nat;
- No_Naming : constant Naming_Id := 0;
-
- Ada_Path_Buffer : String_Access := new String (1 .. 1_000);
- -- A buffer where values for ADA_INCLUDE_PATH
- -- and ADA_OBJECTS_PATH are stored.
-
- Ada_Path_Length : Natural := 0;
- -- Index of the last valid character in Ada_Path_Buffer.
-
- package Namings is new Table.Table (
- Table_Component_Type => Naming_Data,
- Table_Index_Type => Naming_Id,
- Table_Low_Bound => 1,
- Table_Initial => 5,
- Table_Increment => 100,
- Table_Name => "Prj.Env.Namings");
-
- Default_Naming : constant Naming_Id := Namings.First;
-
- Global_Configuration_Pragmas : Name_Id;
- Local_Configuration_Pragmas : Name_Id;
+ Buffer_Initial : constant := 1_000;
+ -- Initial size of Buffer
-----------------------
-- Local Subprograms --
-----------------------
- function Body_Path_Name_Of (Unit : Unit_Id) return String;
- -- Returns the path name of the body of a unit.
- -- Compute it first, if necessary.
-
- function Spec_Path_Name_Of (Unit : Unit_Id) return String;
- -- Returns the path name of the spec of a unit.
- -- Compute it first, if necessary.
-
- procedure Add_To_Path (Path : String);
- -- Add Path to global variable Ada_Path_Buffer
- -- Increment Ada_Path_Length
+ package Source_Path_Table is new GNAT.Dynamic_Tables
+ (Table_Component_Type => Name_Id,
+ Table_Index_Type => Natural,
+ Table_Low_Bound => 1,
+ Table_Initial => 50,
+ Table_Increment => 100);
+ -- A table to store the source dirs before creating the source path file
+
+ package Object_Path_Table is new GNAT.Dynamic_Tables
+ (Table_Component_Type => Path_Name_Type,
+ Table_Index_Type => Natural,
+ Table_Low_Bound => 1,
+ Table_Initial => 50,
+ Table_Increment => 100);
+ -- A table to store the object dirs, before creating the object path file
+
+ procedure Add_To_Buffer
+ (S : String;
+ Buffer : in out String_Access;
+ Buffer_Last : in out Natural);
+ -- Add a string to Buffer, extending Buffer if needed
+
+ procedure Add_To_Path
+ (Source_Dirs : String_List_Id;
+ In_Tree : Project_Tree_Ref;
+ Buffer : in out String_Access;
+ Buffer_Last : in out Natural);
+ -- Add to Ada_Path_Buffer all the source directories in string list
+ -- Source_Dirs, if any.
+
+ procedure Add_To_Path
+ (Dir : String;
+ Buffer : in out String_Access;
+ Buffer_Last : in out Natural);
+ -- If Dir is not already in the global variable Ada_Path_Buffer, add it.
+ -- If Buffer_Last /= 0, prepend a Path_Separator character to Path.
+
+ procedure Add_To_Source_Path
+ (Source_Dirs : String_List_Id;
+ In_Tree : Project_Tree_Ref;
+ Source_Paths : in out Source_Path_Table.Instance);
+ -- Add to Ada_Path_B all the source directories in string list
+ -- Source_Dirs, if any. Increment Ada_Path_Length.
+
+ procedure Add_To_Object_Path
+ (Object_Dir : Path_Name_Type;
+ Object_Paths : in out Object_Path_Table.Instance);
+ -- Add Object_Dir to object path table. Make sure it is not duplicate
+ -- and it is the last one in the current table.
+
+ procedure Set_Path_File_Var (Name : String; Value : String);
+ -- Call Setenv, after calling To_Host_File_Spec
+
+ function Ultimate_Extension_Of
+ (Project : Project_Id) return Project_Id;
+ -- Return a project that is either Project or an extended ancestor of
+ -- Project that itself is not extended.
----------------------
-- Ada_Include_Path --
----------------------
- function Ada_Include_Path (Project : Project_Id) return String_Access is
+ function Ada_Include_Path
+ (Project : Project_Id;
+ In_Tree : Project_Tree_Ref;
+ Recursive : Boolean := False) return String
+ is
+ Buffer : String_Access;
+ Buffer_Last : Natural := 0;
- procedure Add (Project : Project_Id);
- -- Add all the source directories of a project to the path,
- -- only if this project has not been visited.
- -- Call itself recursively for projects being modified,
- -- and imported projects.
- -- Add the project to the list Seen if this is the first time
- -- we call Add for this project.
+ procedure Add (Project : Project_Id; Dummy : in out Boolean);
+ -- Add source dirs of Project to the path
---------
-- Add --
---------
- procedure Add (Project : Project_Id) is
+ procedure Add (Project : Project_Id; Dummy : in out Boolean) is
+ pragma Unreferenced (Dummy);
begin
- -- If Seen is empty, then the project cannot have been
- -- visited.
-
- if not Projects.Table (Project).Seen then
- Projects.Table (Project).Seen := True;
-
- declare
- Data : Project_Data := Projects.Table (Project);
- List : Project_List := Data.Imported_Projects;
-
- Current : String_List_Id := Data.Source_Dirs;
- Source_Dir : String_Element;
-
- begin
- -- Add to path all source directories of this project
-
- while Current /= Nil_String loop
- if Ada_Path_Length > 0 then
- Add_To_Path (Path => (1 => Path_Separator));
- end if;
-
- Source_Dir := String_Elements.Table (Current);
- String_To_Name_Buffer (Source_Dir.Value);
+ Add_To_Path (Project.Source_Dirs, In_Tree, Buffer, Buffer_Last);
+ end Add;
- declare
- New_Path : constant String :=
- Name_Buffer (1 .. Name_Len);
- begin
- Add_To_Path (New_Path);
- end;
+ procedure For_All_Projects is
+ new For_Every_Project_Imported (Boolean, Add);
- Current := Source_Dir.Next;
- end loop;
+ Dummy : Boolean := False;
- -- Call Add to the project being modified, if any
+ -- Start of processing for Ada_Include_Path
- if Data.Modifies /= No_Project then
- Add (Data.Modifies);
- end if;
+ begin
+ if Recursive then
- -- Call Add for each imported project, if any
+ -- If it is the first time we call this function for
+ -- this project, compute the source path
- while List /= Empty_Project_List loop
- Add (Project_Lists.Table (List).Project);
- List := Project_Lists.Table (List).Next;
- end loop;
- end;
+ if Project.Ada_Include_Path = null then
+ Buffer := new String (1 .. 4096);
+ For_All_Projects (Project, Dummy);
+ Project.Ada_Include_Path := new String'(Buffer (1 .. Buffer_Last));
+ Free (Buffer);
end if;
- end Add;
-
- -- Start of processing for Ada_Include_Path
-
- begin
- -- If it is the first time we call this function for
- -- this project, compute the source path
+ return Project.Ada_Include_Path.all;
- if Projects.Table (Project).Include_Path = null then
- Ada_Path_Length := 0;
-
- for Index in 1 .. Projects.Last loop
- Projects.Table (Index).Seen := False;
- end loop;
+ else
+ Buffer := new String (1 .. 4096);
+ Add_To_Path (Project.Source_Dirs, In_Tree, Buffer, Buffer_Last);
- Add (Project);
- Projects.Table (Project).Include_Path :=
- new String'(Ada_Path_Buffer (1 .. Ada_Path_Length));
+ declare
+ Result : constant String := Buffer (1 .. Buffer_Last);
+ begin
+ Free (Buffer);
+ return Result;
+ end;
end if;
-
- return Projects.Table (Project).Include_Path;
end Ada_Include_Path;
----------------------
function Ada_Objects_Path
(Project : Project_Id;
- Including_Libraries : Boolean := True)
- return String_Access is
+ Including_Libraries : Boolean := True) return String_Access
+ is
+ Buffer : String_Access;
+ Buffer_Last : Natural := 0;
- procedure Add (Project : Project_Id);
- -- Add all the object directory of a project to the path,
- -- only if this project has not been visited.
- -- Call itself recursively for projects being modified,
- -- and imported projects.
- -- Add the project to the list Seen if this is the first time
- -- we call Add for this project.
+ procedure Add (Project : Project_Id; Dummy : in out Boolean);
+ -- Add all the object directories of a project to the path
---------
-- Add --
---------
- procedure Add (Project : Project_Id) is
+ procedure Add (Project : Project_Id; Dummy : in out Boolean) is
+ pragma Unreferenced (Dummy);
+ Path : constant Path_Name_Type :=
+ Get_Object_Directory
+ (Project,
+ Including_Libraries => Including_Libraries,
+ Only_If_Ada => False);
begin
-
- -- If this project has not been seen yet
-
- if not Projects.Table (Project).Seen then
- Projects.Table (Project).Seen := True;
-
- declare
- Data : Project_Data := Projects.Table (Project);
- List : Project_List := Data.Imported_Projects;
-
- begin
- -- Add to path the object directory of this project
- -- except if we don't include library project and
- -- this is a library project.
-
- if (Data.Library and then Including_Libraries)
- or else
- (Data.Object_Directory /= No_Name
- and then
- (not Including_Libraries or else not Data.Library))
- then
- if Ada_Path_Length > 0 then
- Add_To_Path (Path => (1 => Path_Separator));
- end if;
-
- -- For a library project, att the library directory
-
- if Data.Library then
- declare
- New_Path : constant String :=
- Get_Name_String (Data.Library_Dir);
- begin
- Add_To_Path (New_Path);
- end;
- else
-
- -- For a non library project, add the object directory
- declare
- New_Path : constant String :=
- Get_Name_String (Data.Object_Directory);
- begin
- Add_To_Path (New_Path);
- end;
- end if;
- end if;
-
- -- Call Add to the project being modified, if any
-
- if Data.Modifies /= No_Project then
- Add (Data.Modifies);
- end if;
-
- -- Call Add for each imported project, if any
-
- while List /= Empty_Project_List loop
- Add (Project_Lists.Table (List).Project);
- List := Project_Lists.Table (List).Next;
- end loop;
- end;
-
+ if Path /= No_Path then
+ Add_To_Path (Get_Name_String (Path), Buffer, Buffer_Last);
end if;
end Add;
+ procedure For_All_Projects is
+ new For_Every_Project_Imported (Boolean, Add);
+
+ Dummy : Boolean := False;
+
-- Start of processing for Ada_Objects_Path
begin
-- If it is the first time we call this function for
-- this project, compute the objects path
- if Projects.Table (Project).Objects_Path = null then
- Ada_Path_Length := 0;
-
- for Index in 1 .. Projects.Last loop
- Projects.Table (Index).Seen := False;
- end loop;
+ if Project.Ada_Objects_Path = null then
+ Buffer := new String (1 .. 4096);
+ For_All_Projects (Project, Dummy);
- Add (Project);
- Projects.Table (Project).Objects_Path :=
- new String'(Ada_Path_Buffer (1 .. Ada_Path_Length));
+ Project.Ada_Objects_Path := new String'(Buffer (1 .. Buffer_Last));
+ Free (Buffer);
end if;
- return Projects.Table (Project).Objects_Path;
+ return Project.Ada_Objects_Path;
end Ada_Objects_Path;
- -----------------
- -- Add_To_Path --
- -----------------
+ -------------------
+ -- Add_To_Buffer --
+ -------------------
- procedure Add_To_Path (Path : String) is
- begin
- -- If Ada_Path_Buffer is too small, double it
+ procedure Add_To_Buffer
+ (S : String;
+ Buffer : in out String_Access;
+ Buffer_Last : in out Natural)
+ is
+ Last : constant Natural := Buffer_Last + S'Length;
- if Ada_Path_Length + Path'Length > Ada_Path_Buffer'Last then
+ begin
+ while Last > Buffer'Last loop
declare
- New_Ada_Path_Buffer : constant String_Access :=
- new String
- (1 .. Ada_Path_Buffer'Last +
- Ada_Path_Buffer'Last);
-
+ New_Buffer : constant String_Access :=
+ new String (1 .. 2 * Buffer'Last);
begin
- New_Ada_Path_Buffer (1 .. Ada_Path_Length) :=
- Ada_Path_Buffer (1 .. Ada_Path_Length);
- Ada_Path_Buffer := New_Ada_Path_Buffer;
+ New_Buffer (1 .. Buffer_Last) := Buffer (1 .. Buffer_Last);
+ Free (Buffer);
+ Buffer := New_Buffer;
end;
- end if;
-
- Ada_Path_Buffer
- (Ada_Path_Length + 1 .. Ada_Path_Length + Path'Length) := Path;
- Ada_Path_Length := Ada_Path_Length + Path'Length;
- end Add_To_Path;
+ end loop;
- -----------------------
- -- Body_Path_Name_Of --
- -----------------------
+ Buffer (Buffer_Last + 1 .. Last) := S;
+ Buffer_Last := Last;
+ end Add_To_Buffer;
- function Body_Path_Name_Of (Unit : Unit_Id) return String is
- Data : Unit_Data := Units.Table (Unit);
+ ------------------------
+ -- Add_To_Object_Path --
+ ------------------------
+ procedure Add_To_Object_Path
+ (Object_Dir : Path_Name_Type;
+ Object_Paths : in out Object_Path_Table.Instance)
+ is
begin
- -- If we don't know the path name of the body of this unit,
- -- we compute it, and we store it.
-
- if Data.File_Names (Body_Part).Path = No_Name then
- declare
- Current_Source : String_List_Id :=
- Projects.Table (Data.File_Names (Body_Part).Project).Sources;
- Path : GNAT.OS_Lib.String_Access;
-
- begin
- -- By default, put the file name
-
- Data.File_Names (Body_Part).Path :=
- Data.File_Names (Body_Part).Name;
+ -- Check if the directory is already in the table
- -- For each source directory
-
- while Current_Source /= Nil_String loop
- String_To_Name_Buffer
- (String_Elements.Table (Current_Source).Value);
- Path :=
- Locate_Regular_File
- (Namet.Get_Name_String
- (Data.File_Names (Body_Part).Name),
- Name_Buffer (1 .. Name_Len));
-
- -- If the file is in this directory,
- -- then we store the path, and we are done.
+ for Index in Object_Path_Table.First ..
+ Object_Path_Table.Last (Object_Paths)
+ loop
- if Path /= null then
- Name_Len := Path'Length;
- Name_Buffer (1 .. Name_Len) := Path.all;
- Data.File_Names (Body_Part).Path := Name_Enter;
- exit;
+ -- If it is, remove it, and add it as the last one
- else
- Current_Source :=
- String_Elements.Table (Current_Source).Next;
- end if;
+ if Object_Paths.Table (Index) = Object_Dir then
+ for Index2 in Index + 1 ..
+ Object_Path_Table.Last (Object_Paths)
+ loop
+ Object_Paths.Table (Index2 - 1) := Object_Paths.Table (Index2);
end loop;
- Units.Table (Unit) := Data;
- end;
- end if;
+ Object_Paths.Table
+ (Object_Path_Table.Last (Object_Paths)) := Object_Dir;
+ return;
+ end if;
+ end loop;
- -- Returned the value stored
+ -- The directory is not already in the table, add it
- return Namet.Get_Name_String (Data.File_Names (Body_Part).Path);
- end Body_Path_Name_Of;
+ Object_Path_Table.Append (Object_Paths, Object_Dir);
+ end Add_To_Object_Path;
- --------------------------------
- -- Create_Config_Pragmas_File --
- --------------------------------
+ -----------------
+ -- Add_To_Path --
+ -----------------
- procedure Create_Config_Pragmas_File
- (For_Project : Project_Id;
- Main_Project : Project_Id)
+ procedure Add_To_Path
+ (Source_Dirs : String_List_Id;
+ In_Tree : Project_Tree_Ref;
+ Buffer : in out String_Access;
+ Buffer_Last : in out Natural)
is
- File_Name : Temp_File_Name;
- File : File_Descriptor := Invalid_FD;
+ Current : String_List_Id := Source_Dirs;
+ Source_Dir : String_Element;
+ begin
+ while Current /= Nil_String loop
+ Source_Dir := In_Tree.String_Elements.Table (Current);
+ Add_To_Path (Get_Name_String (Source_Dir.Display_Value),
+ Buffer, Buffer_Last);
+ Current := Source_Dir.Next;
+ end loop;
+ end Add_To_Path;
- The_Packages : Package_Id;
- Gnatmake : Prj.Package_Id;
- Compiler : Prj.Package_Id;
+ procedure Add_To_Path
+ (Dir : String;
+ Buffer : in out String_Access;
+ Buffer_Last : in out Natural)
+ is
+ Len : Natural;
+ New_Buffer : String_Access;
+ Min_Len : Natural;
- Current_Unit : Unit_Id := Units.First;
+ function Is_Present (Path : String; Dir : String) return Boolean;
+ -- Return True if Dir is part of Path
- First_Project : Project_List := Empty_Project_List;
+ ----------------
+ -- Is_Present --
+ ----------------
- Current_Project : Project_List;
- Current_Naming : Naming_Id;
+ function Is_Present (Path : String; Dir : String) return Boolean is
+ Last : constant Integer := Path'Last - Dir'Length + 1;
- Global_Attribute : Variable_Value := Nil_Variable_Value;
- Local_Attribute : Variable_Value := Nil_Variable_Value;
+ begin
+ for J in Path'First .. Last loop
- Global_Attribute_Present : Boolean := False;
- Local_Attribute_Present : Boolean := False;
+ -- Note: the order of the conditions below is important, since
+ -- it ensures a minimal number of string comparisons.
- procedure Check (Project : Project_Id);
+ if (J = Path'First
+ or else Path (J - 1) = Path_Separator)
+ and then
+ (J + Dir'Length > Path'Last
+ or else Path (J + Dir'Length) = Path_Separator)
+ and then Dir = Path (J .. J + Dir'Length - 1)
+ then
+ return True;
+ end if;
+ end loop;
- procedure Check_Temp_File;
- -- Check that a temporary file has been opened.
- -- If not, create one, and put its name in the project data,
- -- with the indication that it is a temporary file.
+ return False;
+ end Is_Present;
- procedure Copy_File (Name : String_Id);
- -- Copy a configuration pragmas file into the temp file.
+ -- Start of processing for Add_To_Path
- procedure Put
- (Unit_Name : Name_Id;
- File_Name : Name_Id;
- Unit_Kind : Spec_Or_Body);
- -- Put an SFN pragma in the temporary file.
+ begin
+ if Is_Present (Buffer (1 .. Buffer_Last), Dir) then
- procedure Put (File : File_Descriptor; S : String);
+ -- Dir is already in the path, nothing to do
- procedure Put_Line (File : File_Descriptor; S : String);
+ return;
+ end if;
- -----------
- -- Check --
- -----------
+ Min_Len := Buffer_Last + Dir'Length;
- procedure Check (Project : Project_Id) is
- Data : constant Project_Data := Projects.Table (Project);
+ if Buffer_Last > 0 then
- begin
- if Current_Verbosity = High then
- Write_Str ("Checking project file """);
- Write_Str (Namet.Get_Name_String (Data.Name));
- Write_Str (""".");
- Write_Eol;
- end if;
+ -- Add 1 for the Path_Separator character
+
+ Min_Len := Min_Len + 1;
+ end if;
+
+ -- If Ada_Path_Buffer is too small, increase it
- -- Is this project in the list of the visited project?
+ Len := Buffer'Last;
- Current_Project := First_Project;
- while Current_Project /= Empty_Project_List
- and then Project_Lists.Table (Current_Project).Project /= Project
+ if Len < Min_Len then
loop
- Current_Project := Project_Lists.Table (Current_Project).Next;
+ Len := Len * 2;
+ exit when Len >= Min_Len;
end loop;
- -- If it is not, put it in the list, and visit it
+ New_Buffer := new String (1 .. Len);
+ New_Buffer (1 .. Buffer_Last) := Buffer (1 .. Buffer_Last);
+ Free (Buffer);
+ Buffer := New_Buffer;
+ end if;
- if Current_Project = Empty_Project_List then
- Project_Lists.Increment_Last;
- Project_Lists.Table (Project_Lists.Last) :=
- (Project => Project, Next => First_Project);
- First_Project := Project_Lists.Last;
+ if Buffer_Last > 0 then
+ Buffer_Last := Buffer_Last + 1;
+ Buffer (Buffer_Last) := Path_Separator;
+ end if;
- -- Is the naming scheme of this project one that we know?
+ Buffer (Buffer_Last + 1 .. Buffer_Last + Dir'Length) := Dir;
+ Buffer_Last := Buffer_Last + Dir'Length;
+ end Add_To_Path;
- Current_Naming := Default_Naming;
- while Current_Naming <= Namings.Last and then
- not Same_Naming_Scheme
- (Left => Namings.Table (Current_Naming),
- Right => Data.Naming) loop
- Current_Naming := Current_Naming + 1;
- end loop;
+ ------------------------
+ -- Add_To_Source_Path --
+ ------------------------
- -- If we don't know it, add it
+ procedure Add_To_Source_Path
+ (Source_Dirs : String_List_Id;
+ In_Tree : Project_Tree_Ref;
+ Source_Paths : in out Source_Path_Table.Instance)
+ is
+ Current : String_List_Id := Source_Dirs;
+ Source_Dir : String_Element;
+ Add_It : Boolean;
- if Current_Naming > Namings.Last then
- Namings.Increment_Last;
- Namings.Table (Namings.Last) := Data.Naming;
+ begin
+ -- Add each source directory
- -- We need a temporary file to be created
+ while Current /= Nil_String loop
+ Source_Dir := In_Tree.String_Elements.Table (Current);
+ Add_It := True;
- Check_Temp_File;
+ -- Check if the source directory is already in the table
- -- Put the SFN pragmas for the naming scheme
+ for Index in Source_Path_Table.First ..
+ Source_Path_Table.Last (Source_Paths)
+ loop
+ -- If it is already, no need to add it
- -- Spec
+ if Source_Paths.Table (Index) = Source_Dir.Value then
+ Add_It := False;
+ exit;
+ end if;
+ end loop;
- Put_Line
- (File, "pragma Source_File_Name");
- Put_Line
- (File, " (Spec_File_Name => ""*" &
- Namet.Get_Name_String (Data.Naming.Current_Spec_Suffix) &
- """,");
- Put_Line
- (File, " Casing => " &
- Image (Data.Naming.Casing) & ",");
- Put_Line
- (File, " Dot_Replacement => """ &
- Namet.Get_Name_String (Data.Naming.Dot_Replacement) &
- """);");
+ if Add_It then
+ Source_Path_Table.Append (Source_Paths, Source_Dir.Display_Value);
+ end if;
- -- and body
+ -- Next source directory
- Put_Line
- (File, "pragma Source_File_Name");
- Put_Line
- (File, " (Body_File_Name => ""*" &
- Namet.Get_Name_String (Data.Naming.Current_Impl_Suffix) &
- """,");
- Put_Line
- (File, " Casing => " &
- Image (Data.Naming.Casing) & ",");
- Put_Line
- (File, " Dot_Replacement => """ &
- Namet.Get_Name_String (Data.Naming.Dot_Replacement) &
- """);");
+ Current := Source_Dir.Next;
+ end loop;
+ end Add_To_Source_Path;
- -- and maybe separate
-
- if
- Data.Naming.Current_Impl_Suffix /= Data.Naming.Separate_Suffix
- then
- Put_Line
- (File, "pragma Source_File_Name");
- Put_Line
- (File, " (Subunit_File_Name => ""*" &
- Namet.Get_Name_String (Data.Naming.Separate_Suffix) &
- """,");
- Put_Line
- (File, " Casing => " &
- Image (Data.Naming.Casing) &
- ",");
- Put_Line
- (File, " Dot_Replacement => """ &
- Namet.Get_Name_String (Data.Naming.Dot_Replacement) &
- """);");
- end if;
- end if;
+ --------------------------------
+ -- Create_Config_Pragmas_File --
+ --------------------------------
- if Data.Modifies /= No_Project then
- Check (Data.Modifies);
- end if;
+ procedure Create_Config_Pragmas_File
+ (For_Project : Project_Id;
+ In_Tree : Project_Tree_Ref)
+ is
+ type Naming_Id is new Nat;
+ package Naming_Table is new GNAT.Dynamic_Tables
+ (Table_Component_Type => Lang_Naming_Data,
+ Table_Index_Type => Naming_Id,
+ Table_Low_Bound => 1,
+ Table_Initial => 5,
+ Table_Increment => 100);
+ Default_Naming : constant Naming_Id := Naming_Table.First;
+ Namings : Naming_Table.Instance;
+ -- Table storing the naming data for gnatmake/gprmake
+
+ Buffer : String_Access := new String (1 .. Buffer_Initial);
+ Buffer_Last : Natural := 0;
+
+ File_Name : Path_Name_Type := No_Path;
+ File : File_Descriptor := Invalid_FD;
- declare
- Current : Project_List := Data.Imported_Projects;
+ Current_Naming : Naming_Id;
+ Iter : Source_Iterator;
+ Source : Source_Id;
- begin
- while Current /= Empty_Project_List loop
- Check (Project_Lists.Table (Current).Project);
- Current := Project_Lists.Table (Current).Next;
- end loop;
- end;
- end if;
- end Check;
+ procedure Check (Project : Project_Id; State : in out Integer);
+ -- Recursive procedure that put in the config pragmas file any non
+ -- standard naming schemes, if it is not already in the file, then call
+ -- itself for any imported project.
- ---------------------
- -- Check_Temp_File --
- ---------------------
+ procedure Put (Source : Source_Id);
+ -- Put an SFN pragma in the temporary file
- procedure Check_Temp_File is
- begin
- if File = Invalid_FD then
- GNAT.OS_Lib.Create_Temp_File (File, Name => File_Name);
- if File = Invalid_FD then
- Osint.Fail
- ("unable to create temporary configuration pragmas file");
- elsif Opt.Verbose_Mode then
- Write_Str ("Creating temp file """);
- Write_Str (File_Name);
- Write_Line ("""");
- end if;
- end if;
- end Check_Temp_File;
+ procedure Put (S : String);
+ procedure Put_Line (S : String);
+ -- Output procedures, analogous to normal Text_IO procs of same name.
+ -- The text is put in Buffer, then it will be writen into a temporary
+ -- file with procedure Write_Temp_File below.
- ---------------
- -- Copy_File --
- ---------------
+ procedure Write_Temp_File;
+ -- Create a temporary file and put the content of the buffer in it
+
+ -----------
+ -- Check --
+ -----------
- procedure Copy_File (Name : in String_Id) is
- Input : File_Descriptor;
- Buffer : String (1 .. 1_000);
- Input_Length : Integer;
- Output_Length : Integer;
+ procedure Check (Project : Project_Id; State : in out Integer) is
+ pragma Unreferenced (State);
+ Lang : constant Language_Ptr :=
+ Get_Language_From_Name (Project, "ada");
+ Naming : Lang_Naming_Data;
begin
- Check_Temp_File;
- String_To_Name_Buffer (Name);
-
- if Opt.Verbose_Mode then
- Write_Str ("Copying config pragmas file """);
- Write_Str (Name_Buffer (1 .. Name_Len));
- Write_Line (""" into temp file");
+ if Current_Verbosity = High then
+ Write_Str ("Checking project file """);
+ Write_Str (Namet.Get_Name_String (Project.Name));
+ Write_Str (""".");
+ Write_Eol;
end if;
- declare
- Name : constant String :=
- Name_Buffer (1 .. Name_Len) & ASCII.NUL;
- begin
- Input := Open_Read (Name'Address, Binary);
- end;
+ if Lang = null then
+ if Current_Verbosity = High then
+ Write_Line (" Languages does not contain Ada, nothing to do");
+ end if;
- if Input = Invalid_FD then
- Osint.Fail
- ("cannot open configuration pragmas file " &
- Name_Buffer (1 .. Name_Len));
+ return;
end if;
- loop
- Input_Length := Read (Input, Buffer'Address, Buffer'Length);
- Output_Length := Write (File, Buffer'Address, Input_Length);
+ Naming := Lang.Config.Naming_Data;
- if Output_Length /= Input_Length then
- Osint.Fail ("disk full");
- end if;
+ -- Is the naming scheme of this project one that we know?
- exit when Input_Length < Buffer'Length;
+ Current_Naming := Default_Naming;
+ while Current_Naming <= Naming_Table.Last (Namings)
+ and then Namings.Table (Current_Naming).Dot_Replacement =
+ Naming.Dot_Replacement
+ and then Namings.Table (Current_Naming).Casing =
+ Naming.Casing
+ and then Namings.Table (Current_Naming).Separate_Suffix =
+ Naming.Separate_Suffix
+ loop
+ Current_Naming := Current_Naming + 1;
end loop;
- Close (Input);
-
- end Copy_File;
+ -- If we don't know it, add it
+
+ if Current_Naming > Naming_Table.Last (Namings) then
+ Naming_Table.Increment_Last (Namings);
+ Namings.Table (Naming_Table.Last (Namings)) := Naming;
+
+ -- Put the SFN pragmas for the naming scheme
+
+ -- Spec
+
+ Put_Line
+ ("pragma Source_File_Name_Project");
+ Put_Line
+ (" (Spec_File_Name => ""*" &
+ Get_Name_String (Naming.Spec_Suffix) & """,");
+ Put_Line
+ (" Casing => " &
+ Image (Naming.Casing) & ",");
+ Put_Line
+ (" Dot_Replacement => """ &
+ Get_Name_String (Naming.Dot_Replacement) & """);");
+
+ -- and body
+
+ Put_Line
+ ("pragma Source_File_Name_Project");
+ Put_Line
+ (" (Body_File_Name => ""*" &
+ Get_Name_String (Naming.Body_Suffix) & """,");
+ Put_Line
+ (" Casing => " &
+ Image (Naming.Casing) & ",");
+ Put_Line
+ (" Dot_Replacement => """ &
+ Get_Name_String (Naming.Dot_Replacement) &
+ """);");
+
+ -- and maybe separate
+
+ if Naming.Body_Suffix /= Naming.Separate_Suffix then
+ Put_Line ("pragma Source_File_Name_Project");
+ Put_Line
+ (" (Subunit_File_Name => ""*" &
+ Get_Name_String (Naming.Separate_Suffix) & """,");
+ Put_Line
+ (" Casing => " &
+ Image (Naming.Casing) & ",");
+ Put_Line
+ (" Dot_Replacement => """ &
+ Get_Name_String (Naming.Dot_Replacement) &
+ """);");
+ end if;
+ end if;
+ end Check;
---------
-- Put --
---------
- procedure Put
- (Unit_Name : Name_Id;
- File_Name : Name_Id;
- Unit_Kind : Spec_Or_Body)
- is
+ procedure Put (Source : Source_Id) is
begin
- -- A temporary file needs to be open
-
- Check_Temp_File;
-
-- Put the pragma SFN for the unit kind (spec or body)
- Put (File, "pragma Source_File_Name (");
- Put (File, Namet.Get_Name_String (Unit_Name));
+ Put ("pragma Source_File_Name_Project (");
+ Put (Namet.Get_Name_String (Source.Unit.Name));
- if Unit_Kind = Specification then
- Put (File, ", Spec_File_Name => """);
+ if Source.Kind = Spec then
+ Put (", Spec_File_Name => """);
else
- Put (File, ", Body_File_Name => """);
+ Put (", Body_File_Name => """);
end if;
- Put (File, Namet.Get_Name_String (File_Name));
- Put_Line (File, """);");
- end Put;
+ Put (Namet.Get_Name_String (Source.File));
+ Put ("""");
- procedure Put (File : File_Descriptor; S : String) is
- Last : Natural;
+ if Source.Index /= 0 then
+ Put (", Index =>");
+ Put (Source.Index'Img);
+ end if;
- begin
- Last := Write (File, S (S'First)'Address, S'Length);
+ Put_Line (");");
+ end Put;
- if Last /= S'Length then
- Osint.Fail ("Disk full");
- end if;
+ procedure Put (S : String) is
+ begin
+ Add_To_Buffer (S, Buffer, Buffer_Last);
if Current_Verbosity = High then
Write_Str (S);
-- Put_Line --
--------------
- procedure Put_Line (File : File_Descriptor; S : String) is
- S0 : String (1 .. S'Length + 1);
- Last : Natural;
+ procedure Put_Line (S : String) is
+ begin
+ -- Add an ASCII.LF to the string. As this config file is supposed to
+ -- be used only by the compiler, we don't care about the characters
+ -- for the end of line. In fact we could have put a space, but
+ -- it is more convenient to be able to read gnat.adc during
+ -- development, for which the ASCII.LF is fine.
+
+ Put (S);
+ Put (S => (1 => ASCII.LF));
+ end Put_Line;
+
+ ---------------------
+ -- Write_Temp_File --
+ ---------------------
+
+ procedure Write_Temp_File is
+ Status : Boolean := False;
+ Last : Natural;
begin
- -- Add an ASCII.LF to the string. As this gnat.adc
- -- is supposed to be used only by the compiler, we don't
- -- care about the characters for the end of line.
- -- The truth is we could have put a space, but it is
- -- more convenient to be able to read gnat.adc during
- -- development. And the development was done under UNIX.
- -- Hence the ASCII.LF.
-
- S0 (1 .. S'Length) := S;
- S0 (S0'Last) := ASCII.LF;
- Last := Write (File, S0'Address, S0'Length);
-
- if Last /= S'Length + 1 then
- Osint.Fail ("Disk full");
+ Tempdir.Create_Temp_File (File, File_Name);
+
+ if File /= Invalid_FD then
+ Last := Write (File, Buffer (1)'Address, Buffer_Last);
+
+ if Last = Buffer_Last then
+ Close (File, Status);
+ end if;
end if;
- if Current_Verbosity = High then
- Write_Line (S);
+ if not Status then
+ Prj.Com.Fail ("unable to create temporary file");
end if;
- end Put_Line;
+ end Write_Temp_File;
+
+ procedure Check_Imported_Projects is
+ new For_Every_Project_Imported (Integer, Check);
+
+ Dummy : Integer := 0;
-- Start of processing for Create_Config_Pragmas_File
begin
+ if not For_Project.Config_Checked then
+ Naming_Table.Init (Namings);
- if not Projects.Table (For_Project).Config_Checked then
-
- -- Remove any memory of processed naming schemes, if any
+ -- Check the naming schemes
- Namings.Set_Last (Default_Naming);
+ Check_Imported_Projects (For_Project, Dummy, Imported_First => False);
- -- Check the naming schemes
+ -- Visit all the files and process those that need an SFN pragma
- Check (For_Project);
+ Iter := For_Each_Source (In_Tree, For_Project);
+ while Element (Iter) /= No_Source loop
+ Source := Element (Iter);
- -- Visit all the units and process those that need an SFN pragma
+ if Source.Index >= 1
+ and then not Source.Locally_Removed
+ and then Source.Unit /= null
+ then
+ Put (Source);
+ end if;
- while Current_Unit <= Units.Last loop
- declare
- Unit : constant Unit_Data :=
- Units.Table (Current_Unit);
+ Next (Iter);
+ end loop;
- begin
- if Unit.File_Names (Specification).Needs_Pragma then
- Put (Unit.Name,
- Unit.File_Names (Specification).Name,
- Specification);
- end if;
+ -- If there are no non standard naming scheme, issue the GNAT
+ -- standard naming scheme. This will tell the compiler that
+ -- a project file is used and will forbid any pragma SFN.
- if Unit.File_Names (Body_Part).Needs_Pragma then
- Put (Unit.Name,
- Unit.File_Names (Body_Part).Name,
- Body_Part);
- end if;
+ if Buffer_Last = 0 then
- Current_Unit := Current_Unit + 1;
- end;
- end loop;
+ Put_Line ("pragma Source_File_Name_Project");
+ Put_Line (" (Spec_File_Name => ""*.ads"",");
+ Put_Line (" Dot_Replacement => ""-"",");
+ Put_Line (" Casing => lowercase);");
- The_Packages := Projects.Table (Main_Project).Decl.Packages;
- Gnatmake :=
- Prj.Util.Value_Of
- (Name => Name_Builder,
- In_Packages => The_Packages);
-
- if Gnatmake /= No_Package then
- Global_Attribute := Prj.Util.Value_Of
- (Variable_Name => Global_Configuration_Pragmas,
- In_Variables => Packages.Table (Gnatmake).Decl.Attributes);
- Global_Attribute_Present :=
- Global_Attribute /= Nil_Variable_Value
- and then String_Length (Global_Attribute.Value) > 0;
+ Put_Line ("pragma Source_File_Name_Project");
+ Put_Line (" (Body_File_Name => ""*.adb"",");
+ Put_Line (" Dot_Replacement => ""-"",");
+ Put_Line (" Casing => lowercase);");
end if;
- The_Packages := Projects.Table (For_Project).Decl.Packages;
- Compiler :=
- Prj.Util.Value_Of
- (Name => Name_Compiler,
- In_Packages => The_Packages);
-
- if Compiler /= No_Package then
- Local_Attribute := Prj.Util.Value_Of
- (Variable_Name => Local_Configuration_Pragmas,
- In_Variables => Packages.Table (Compiler).Decl.Attributes);
- Local_Attribute_Present :=
- Local_Attribute /= Nil_Variable_Value
- and then String_Length (Local_Attribute.Value) > 0;
- end if;
+ -- Close the temporary file
- if Global_Attribute_Present then
+ Write_Temp_File;
- if File /= Invalid_FD
- or else Local_Attribute_Present
- then
- Copy_File (Global_Attribute.Value);
- else
- String_To_Name_Buffer (Global_Attribute.Value);
- Projects.Table (For_Project).Config_File_Name := Name_Find;
- end if;
+ if Opt.Verbose_Mode then
+ Write_Str ("Created configuration file """);
+ Write_Str (Get_Name_String (File_Name));
+ Write_Line ("""");
end if;
- if Local_Attribute_Present then
+ For_Project.Config_File_Name := File_Name;
+ For_Project.Config_File_Temp := True;
+ For_Project.Config_Checked := True;
+ end if;
+
+ Free (Buffer);
+ end Create_Config_Pragmas_File;
+
+ --------------------
+ -- Create_Mapping --
+ --------------------
+
+ procedure Create_Mapping (In_Tree : Project_Tree_Ref) is
+ Data : Source_Id;
+ Iter : Source_Iterator;
- if File /= Invalid_FD then
- Copy_File (Local_Attribute.Value);
+ begin
+ Fmap.Reset_Tables;
+
+ Iter := For_Each_Source (In_Tree);
+ loop
+ Data := Element (Iter);
+ exit when Data = No_Source;
+ if Data.Unit /= No_Unit_Index then
+ if Data.Locally_Removed then
+ Fmap.Add_Forbidden_File_Name (Data.File);
else
- String_To_Name_Buffer (Local_Attribute.Value);
- Projects.Table (For_Project).Config_File_Name := Name_Find;
+ Fmap.Add_To_File_Map
+ (Unit_Name => Unit_Name_Type (Data.Unit.Name),
+ File_Name => Data.File,
+ Path_Name => File_Name_Type (Data.Path.Name));
end if;
-
end if;
- if File /= Invalid_FD then
- GNAT.OS_Lib.Close (File);
+ Next (Iter);
+ end loop;
+ end Create_Mapping;
- if Opt.Verbose_Mode then
- Write_Str ("Closing configuration file """);
- Write_Str (File_Name);
- Write_Line ("""");
- end if;
+ -------------------------
+ -- Create_Mapping_File --
+ -------------------------
- Name_Len := File_Name'Length;
- Name_Buffer (1 .. Name_Len) := File_Name;
- Projects.Table (For_Project).Config_File_Name := Name_Find;
- Projects.Table (For_Project).Config_File_Temp := True;
- end if;
+ procedure Create_Mapping_File
+ (Project : Project_Id;
+ Language : Name_Id;
+ In_Tree : Project_Tree_Ref;
+ Name : out Path_Name_Type)
+ is
+ File : File_Descriptor := Invalid_FD;
- Projects.Table (For_Project).Config_Checked := True;
+ Buffer : String_Access := new String (1 .. Buffer_Initial);
+ Buffer_Last : Natural := 0;
- end if;
+ procedure Put_Name_Buffer;
+ -- Put the line contained in the Name_Buffer in the global buffer
- end Create_Config_Pragmas_File;
+ procedure Process (Project : Project_Id; State : in out Integer);
+ -- Generate the mapping file for Project (not recursively)
- ------------------------------------
- -- File_Name_Of_Library_Unit_Body --
- ------------------------------------
+ ---------------------
+ -- Put_Name_Buffer --
+ ---------------------
- function File_Name_Of_Library_Unit_Body
- (Name : String;
- Project : Project_Id)
- return String
- is
- Data : constant Project_Data := Projects.Table (Project);
- Original_Name : String := Name;
+ procedure Put_Name_Buffer is
+ begin
+ Name_Len := Name_Len + 1;
+ Name_Buffer (Name_Len) := ASCII.LF;
- Extended_Spec_Name : String :=
- Name & Namet.Get_Name_String
- (Data.Naming.Current_Spec_Suffix);
- Extended_Body_Name : String :=
- Name & Namet.Get_Name_String
- (Data.Naming.Current_Impl_Suffix);
+ if Current_Verbosity = High then
+ Write_Str ("Mapping file: " & Name_Buffer (1 .. Name_Len));
+ end if;
- Unit : Unit_Data;
+ Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
+ end Put_Name_Buffer;
- The_Original_Name : Name_Id;
- The_Spec_Name : Name_Id;
- The_Body_Name : Name_Id;
+ -------------
+ -- Process --
+ -------------
- begin
- Canonical_Case_File_Name (Original_Name);
- Name_Len := Original_Name'Length;
- Name_Buffer (1 .. Name_Len) := Original_Name;
- The_Original_Name := Name_Find;
+ procedure Process (Project : Project_Id; State : in out Integer) is
+ pragma Unreferenced (State);
+ Source : Source_Id;
+ Suffix : File_Name_Type;
+ Iter : Source_Iterator;
- Canonical_Case_File_Name (Extended_Spec_Name);
- Name_Len := Extended_Spec_Name'Length;
- Name_Buffer (1 .. Name_Len) := Extended_Spec_Name;
- The_Spec_Name := Name_Find;
+ begin
+ Iter := For_Each_Source (In_Tree, Project, Language => Language);
- Canonical_Case_File_Name (Extended_Body_Name);
- Name_Len := Extended_Body_Name'Length;
- Name_Buffer (1 .. Name_Len) := Extended_Body_Name;
- The_Body_Name := Name_Find;
+ loop
+ Source := Prj.Element (Iter);
+ exit when Source = No_Source;
+
+ if Source.Replaced_By = No_Source
+ and then Source.Path.Name /= No_Path
+ and then
+ (Source.Language.Config.Kind = File_Based
+ or else Source.Unit /= No_Unit_Index)
+ then
+ if Source.Unit /= No_Unit_Index then
+ Get_Name_String (Source.Unit.Name);
- if Current_Verbosity = High then
+ if Source.Language.Config.Kind = Unit_Based then
+
+ -- ??? Mapping_Spec_Suffix could be set in the case of
+ -- gnatmake as well
+
+ Add_Char_To_Name_Buffer ('%');
+
+ if Source.Kind = Spec then
+ Add_Char_To_Name_Buffer ('s');
+ else
+ Add_Char_To_Name_Buffer ('b');
+ end if;
+
+ else
+ case Source.Kind is
+ when Spec =>
+ Suffix :=
+ Source.Language.Config.Mapping_Spec_Suffix;
+ when Impl | Sep =>
+ Suffix :=
+ Source.Language.Config.Mapping_Body_Suffix;
+ end case;
+
+ if Suffix /= No_File then
+ Add_Str_To_Name_Buffer
+ (Get_Name_String (Suffix));
+ end if;
+ end if;
+
+ Put_Name_Buffer;
+ end if;
+
+ Get_Name_String (Source.File);
+ Put_Name_Buffer;
+
+ if Source.Locally_Removed then
+ Name_Len := 1;
+ Name_Buffer (1) := '/';
+ else
+ Get_Name_String (Source.Path.Name);
+ end if;
+
+ Put_Name_Buffer;
+ end if;
+
+ Next (Iter);
+ end loop;
+ end Process;
+
+ procedure For_Every_Imported_Project is new
+ For_Every_Project_Imported (State => Integer, Action => Process);
+
+ Dummy : Integer := 0;
+
+ -- Start of processing for Create_Mapping_File
+
+ begin
+ For_Every_Imported_Project (Project, Dummy);
+
+ declare
+ Last : Natural;
+ Status : Boolean := False;
+
+ begin
+ Create_Temp_File (In_Tree, File, Name, "mapping");
+
+ if File /= Invalid_FD then
+ Last := Write (File, Buffer (1)'Address, Buffer_Last);
+
+ if Last = Buffer_Last then
+ GNAT.OS_Lib.Close (File, Status);
+ end if;
+ end if;
+
+ if not Status then
+ Prj.Com.Fail ("could not write mapping file");
+ end if;
+ end;
+
+ Free (Buffer);
+ end Create_Mapping_File;
+
+ ----------------------
+ -- Create_Temp_File --
+ ----------------------
+
+ procedure Create_Temp_File
+ (In_Tree : Project_Tree_Ref;
+ Path_FD : out File_Descriptor;
+ Path_Name : out Path_Name_Type;
+ File_Use : String)
+ is
+ begin
+ Tempdir.Create_Temp_File (Path_FD, Path_Name);
+
+ if Path_Name /= No_Path then
+ if Current_Verbosity = High then
+ Write_Line ("Create temp file (" & File_Use & ") "
+ & Get_Name_String (Path_Name));
+ end if;
+
+ Record_Temp_File (In_Tree, Path_Name);
+
+ else
+ Prj.Com.Fail
+ ("unable to create temporary " & File_Use & " file");
+ end if;
+ end Create_Temp_File;
+
+ --------------------------
+ -- Create_New_Path_File --
+ --------------------------
+
+ procedure Create_New_Path_File
+ (In_Tree : Project_Tree_Ref;
+ Path_FD : out File_Descriptor;
+ Path_Name : out Path_Name_Type)
+ is
+ begin
+ Create_Temp_File (In_Tree, Path_FD, Path_Name, "path file");
+ end Create_New_Path_File;
+
+ ------------------------------------
+ -- File_Name_Of_Library_Unit_Body --
+ ------------------------------------
+
+ function File_Name_Of_Library_Unit_Body
+ (Name : String;
+ Project : Project_Id;
+ In_Tree : Project_Tree_Ref;
+ Main_Project_Only : Boolean := True;
+ Full_Path : Boolean := False) return String
+ is
+ The_Project : Project_Id := Project;
+ Original_Name : String := Name;
+
+ Lang : constant Language_Ptr :=
+ Get_Language_From_Name (Project, "ada");
+
+ Unit : Unit_Index;
+ The_Original_Name : Name_Id;
+ The_Spec_Name : Name_Id;
+ The_Body_Name : Name_Id;
+
+ begin
+ -- ??? Same block in Project_Of
+ Canonical_Case_File_Name (Original_Name);
+ Name_Len := Original_Name'Length;
+ Name_Buffer (1 .. Name_Len) := Original_Name;
+ The_Original_Name := Name_Find;
+
+ if Lang /= null then
+ declare
+ Naming : constant Lang_Naming_Data := Lang.Config.Naming_Data;
+ Extended_Spec_Name : String :=
+ Name & Namet.Get_Name_String
+ (Naming.Spec_Suffix);
+ Extended_Body_Name : String :=
+ Name & Namet.Get_Name_String
+ (Naming.Body_Suffix);
+
+ begin
+ Canonical_Case_File_Name (Extended_Spec_Name);
+ Name_Len := Extended_Spec_Name'Length;
+ Name_Buffer (1 .. Name_Len) := Extended_Spec_Name;
+ The_Spec_Name := Name_Find;
+
+ Canonical_Case_File_Name (Extended_Body_Name);
+ Name_Len := Extended_Body_Name'Length;
+ Name_Buffer (1 .. Name_Len) := Extended_Body_Name;
+ The_Body_Name := Name_Find;
+ end;
+
+ else
+ Name_Len := Name'Length;
+ Name_Buffer (1 .. Name_Len) := Name;
+ Canonical_Case_File_Name (Name_Buffer);
+ The_Spec_Name := Name_Find;
+ The_Body_Name := The_Spec_Name;
+ end if;
+
+ if Current_Verbosity = High then
Write_Str ("Looking for file name of """);
Write_Str (Name);
Write_Char ('"');
Write_Eol;
Write_Str (" Extended Spec Name = """);
- Write_Str (Extended_Spec_Name);
+ Write_Str (Get_Name_String (The_Spec_Name));
Write_Char ('"');
Write_Eol;
Write_Str (" Extended Body Name = """);
- Write_Str (Extended_Body_Name);
+ Write_Str (Get_Name_String (The_Body_Name));
Write_Char ('"');
Write_Eol;
end if;
- -- For every unit
-
- for Current in reverse Units.First .. Units.Last loop
- Unit := Units.Table (Current);
-
- -- If it is a unit of the same project
-
- if Unit.File_Names (Body_Part).Project = Project then
- declare
- Current_Name : constant Name_Id :=
- Unit.File_Names (Body_Part).Name;
-
- begin
- -- If there is a body
+ -- For extending project, search in the extended project if the source
+ -- is not found. For non extending projects, this loop will be run only
+ -- once.
- if Current_Name /= No_Name then
- if Current_Verbosity = High then
- Write_Str (" Comparing with """);
- Write_Str (Get_Name_String (Current_Name));
- Write_Char ('"');
- Write_Eol;
- end if;
-
- -- If it has the name of the original name,
- -- return the original name
+ loop
+ -- Loop through units
- if Unit.Name = The_Original_Name
- or else Current_Name = The_Original_Name
- then
- if Current_Verbosity = High then
- Write_Line (" OK");
- end if;
+ Unit := Units_Htable.Get_First (In_Tree.Units_HT);
+ while Unit /= null loop
+ -- Check for body
- return Get_Name_String (Current_Name);
+ if not Main_Project_Only
+ or else
+ (Unit.File_Names (Impl) /= null
+ and then Unit.File_Names (Impl).Project = The_Project)
+ then
+ declare
+ Current_Name : File_Name_Type;
+ begin
+ -- Case of a body present
- -- If it has the name of the extended body name,
- -- return the extended body name
+ if Unit.File_Names (Impl) /= null then
+ Current_Name := Unit.File_Names (Impl).File;
- elsif Current_Name = The_Body_Name then
if Current_Verbosity = High then
- Write_Line (" OK");
+ Write_Str (" Comparing with """);
+ Write_Str (Get_Name_String (Current_Name));
+ Write_Char ('"');
+ Write_Eol;
end if;
- return Extended_Body_Name;
-
- else
- if Current_Verbosity = High then
- Write_Line (" not good");
+ -- If it has the name of the original name, return the
+ -- original name.
+
+ if Unit.Name = The_Original_Name
+ or else
+ Current_Name = File_Name_Type (The_Original_Name)
+ then
+ if Current_Verbosity = High then
+ Write_Line (" OK");
+ end if;
+
+ if Full_Path then
+ return Get_Name_String
+ (Unit.File_Names (Impl).Path.Name);
+
+ else
+ return Get_Name_String (Current_Name);
+ end if;
+
+ -- If it has the name of the extended body name,
+ -- return the extended body name
+
+ elsif Current_Name = File_Name_Type (The_Body_Name) then
+ if Current_Verbosity = High then
+ Write_Line (" OK");
+ end if;
+
+ if Full_Path then
+ return Get_Name_String
+ (Unit.File_Names (Impl).Path.Name);
+
+ else
+ return Get_Name_String (The_Body_Name);
+ end if;
+
+ else
+ if Current_Verbosity = High then
+ Write_Line (" not good");
+ end if;
end if;
end if;
- end if;
- end;
- end if;
+ end;
+ end if;
- -- If it is a unit of the same project
+ -- Check for spec
- if Units.Table (Current).File_Names (Specification).Project =
- Project
- then
- declare
- Current_Name : constant Name_Id :=
- Unit.File_Names (Specification).Name;
-
- begin
- -- If there is a spec
-
- if Current_Name /= No_Name then
- if Current_Verbosity = High then
- Write_Str (" Comparing with """);
- Write_Str (Get_Name_String (Current_Name));
- Write_Char ('"');
- Write_Eol;
- end if;
+ if not Main_Project_Only
+ or else
+ (Unit.File_Names (Spec) /= null
+ and then Unit.File_Names (Spec).Project =
+ The_Project)
+ then
+ declare
+ Current_Name : File_Name_Type;
- -- If it has the same name as the original name,
- -- return the original name
+ begin
+ -- Case of spec present
- if Unit.Name = The_Original_Name
- or else Current_Name = The_Original_Name
- then
+ if Unit.File_Names (Spec) /= null then
+ Current_Name := Unit.File_Names (Spec).File;
if Current_Verbosity = High then
- Write_Line (" OK");
+ Write_Str (" Comparing with """);
+ Write_Str (Get_Name_String (Current_Name));
+ Write_Char ('"');
+ Write_Eol;
end if;
- return Get_Name_String (Current_Name);
+ -- If name same as original name, return original name
+
+ if Unit.Name = The_Original_Name
+ or else
+ Current_Name = File_Name_Type (The_Original_Name)
+ then
+ if Current_Verbosity = High then
+ Write_Line (" OK");
+ end if;
+
+ if Full_Path then
+ return Get_Name_String
+ (Unit.File_Names (Spec).Path.Name);
+ else
+ return Get_Name_String (Current_Name);
+ end if;
+
+ -- If it has the same name as the extended spec name,
+ -- return the extended spec name.
+
+ elsif Current_Name = File_Name_Type (The_Spec_Name) then
+ if Current_Verbosity = High then
+ Write_Line (" OK");
+ end if;
+
+ if Full_Path then
+ return Get_Name_String
+ (Unit.File_Names (Spec).Path.Name);
+ else
+ return Get_Name_String (The_Spec_Name);
+ end if;
+
+ else
+ if Current_Verbosity = High then
+ Write_Line (" not good");
+ end if;
+ end if;
+ end if;
+ end;
+ end if;
- -- If it has the same name as the extended spec name,
- -- return the extended spec name
+ Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
+ end loop;
- elsif Current_Name = The_Spec_Name then
- if Current_Verbosity = High then
- Write_Line (" OK");
- end if;
+ -- If we are not in an extending project, give up
- return Extended_Spec_Name;
+ exit when not Main_Project_Only
+ or else The_Project.Extends = No_Project;
- else
- if Current_Verbosity = High then
- Write_Line (" not good");
- end if;
- end if;
- end if;
- end;
- end if;
+ -- Otherwise, look in the project we are extending
+ The_Project := The_Project.Extends;
end loop;
-- We don't know this file name, return an empty string
-------------------------
procedure For_All_Object_Dirs (Project : Project_Id) is
- Seen : Project_List := Empty_Project_List;
+ procedure For_Project (Prj : Project_Id; Dummy : in out Integer);
+ -- Get all object directories of Prj
- procedure Add (Project : Project_Id);
- -- Process a project. Remember the processes visited to avoid
- -- processing a project twice. Recursively process an eventual
- -- modified project, and all imported projects.
-
- ---------
- -- Add --
- ---------
-
- procedure Add (Project : Project_Id) is
- Data : constant Project_Data := Projects.Table (Project);
- List : Project_List := Data.Imported_Projects;
+ -----------------
+ -- For_Project --
+ -----------------
+ procedure For_Project (Prj : Project_Id; Dummy : in out Integer) is
+ pragma Unreferenced (Dummy);
begin
- -- If the list of visited project is empty, then
- -- for sure we never visited this project.
-
- if Seen = Empty_Project_List then
- Project_Lists.Increment_Last;
- Seen := Project_Lists.Last;
- Project_Lists.Table (Seen) :=
- (Project => Project, Next => Empty_Project_List);
-
- else
- -- Check if the project is in the list
-
- declare
- Current : Project_List := Seen;
-
- begin
- loop
- -- If it is, then there is nothing else to do
-
- if Project_Lists.Table (Current).Project = Project then
- return;
- end if;
+ -- ??? Set_Ada_Paths has a different behavior for library project
+ -- files, should we have the same ?
- exit when Project_Lists.Table (Current).Next =
- Empty_Project_List;
- Current := Project_Lists.Table (Current).Next;
- end loop;
-
- -- This project has never been visited, add it
- -- to the list.
-
- Project_Lists.Increment_Last;
- Project_Lists.Table (Current).Next := Project_Lists.Last;
- Project_Lists.Table (Project_Lists.Last) :=
- (Project => Project, Next => Empty_Project_List);
- end;
- end if;
-
- -- If there is an object directory, call Action
- -- with its name
-
- if Data.Object_Directory /= No_Name then
- Get_Name_String (Data.Object_Directory);
+ if Prj.Object_Directory /= No_Path_Information then
+ Get_Name_String (Prj.Object_Directory.Display_Name);
Action (Name_Buffer (1 .. Name_Len));
end if;
+ end For_Project;
- -- If we are extending a project, visit it
-
- if Data.Modifies /= No_Project then
- Add (Data.Modifies);
- end if;
-
- -- And visit all imported projects
-
- while List /= Empty_Project_List loop
- Add (Project_Lists.Table (List).Project);
- List := Project_Lists.Table (List).Next;
- end loop;
- end Add;
+ procedure Get_Object_Dirs is
+ new For_Every_Project_Imported (Integer, For_Project);
+ Dummy : Integer := 1;
-- Start of processing for For_All_Object_Dirs
begin
- -- Visit this project, and its imported projects,
- -- recursively
-
- Add (Project);
+ Get_Object_Dirs (Project, Dummy);
end For_All_Object_Dirs;
-------------------------
-- For_All_Source_Dirs --
-------------------------
- procedure For_All_Source_Dirs (Project : Project_Id) is
- Seen : Project_List := Empty_Project_List;
-
- procedure Add (Project : Project_Id);
- -- Process a project. Remember the processes visited to avoid
- -- processing a project twice. Recursively process an eventual
- -- modified project, and all imported projects.
+ procedure For_All_Source_Dirs
+ (Project : Project_Id;
+ In_Tree : Project_Tree_Ref)
+ is
+ procedure For_Project (Prj : Project_Id; Dummy : in out Integer);
+ -- Get all object directories of Prj
- ---------
- -- Add --
- ---------
+ -----------------
+ -- For_Project --
+ -----------------
- procedure Add (Project : Project_Id) is
- Data : constant Project_Data := Projects.Table (Project);
- List : Project_List := Data.Imported_Projects;
+ procedure For_Project (Prj : Project_Id; Dummy : in out Integer) is
+ pragma Unreferenced (Dummy);
+ Current : String_List_Id := Prj.Source_Dirs;
+ The_String : String_Element;
begin
- -- If the list of visited project is empty, then
- -- for sure we never visited this project.
-
- if Seen = Empty_Project_List then
- Project_Lists.Increment_Last;
- Seen := Project_Lists.Last;
- Project_Lists.Table (Seen) :=
- (Project => Project, Next => Empty_Project_List);
-
- else
- -- Check if the project is in the list
-
- declare
- Current : Project_List := Seen;
-
- begin
- loop
- -- If it is, then there is nothing else to do
-
- if Project_Lists.Table (Current).Project = Project then
- return;
- end if;
-
- exit when Project_Lists.Table (Current).Next =
- Empty_Project_List;
- Current := Project_Lists.Table (Current).Next;
- end loop;
-
- -- This project has never been visited, add it
- -- to the list.
-
- Project_Lists.Increment_Last;
- Project_Lists.Table (Current).Next := Project_Lists.Last;
- Project_Lists.Table (Project_Lists.Last) :=
- (Project => Project, Next => Empty_Project_List);
- end;
- end if;
-
- declare
- Current : String_List_Id := Data.Source_Dirs;
- The_String : String_Element;
-
- begin
- -- Call action with the name of every source directorie
+ -- If there are Ada sources, call action with the name of every
+ -- source directory.
+ if Has_Ada_Sources (Project) then
while Current /= Nil_String loop
- The_String := String_Elements.Table (Current);
- String_To_Name_Buffer (The_String.Value);
- Action (Name_Buffer (1 .. Name_Len));
+ The_String := In_Tree.String_Elements.Table (Current);
+ Action (Get_Name_String (The_String.Display_Value));
Current := The_String.Next;
end loop;
- end;
-
- -- If we are extending a project, visit it
-
- if Data.Modifies /= No_Project then
- Add (Data.Modifies);
end if;
+ end For_Project;
- -- And visit all imported projects
-
- while List /= Empty_Project_List loop
- Add (Project_Lists.Table (List).Project);
- List := Project_Lists.Table (List).Next;
- end loop;
- end Add;
+ procedure Get_Source_Dirs is
+ new For_Every_Project_Imported (Integer, For_Project);
+ Dummy : Integer := 1;
-- Start of processing for For_All_Source_Dirs
begin
- -- Visit this project, and its imported projects recursively
-
- Add (Project);
+ Get_Source_Dirs (Project, Dummy);
end For_All_Source_Dirs;
-------------------
procedure Get_Reference
(Source_File_Name : String;
+ In_Tree : Project_Tree_Ref;
Project : out Project_Id;
- Path : out Name_Id)
+ Path : out Path_Name_Type)
is
begin
+ -- Body below could use some comments ???
+
if Current_Verbosity > Default then
Write_Str ("Getting Reference_Of (""");
Write_Str (Source_File_Name);
declare
Original_Name : String := Source_File_Name;
- Unit : Unit_Data;
+ Unit : Unit_Index;
begin
Canonical_Case_File_Name (Original_Name);
-
- for Id in Units.First .. Units.Last loop
- Unit := Units.Table (Id);
-
- if (Unit.File_Names (Specification).Name /= No_Name
- and then
- Namet.Get_Name_String
- (Unit.File_Names (Specification).Name) = Original_Name)
- or else (Unit.File_Names (Specification).Path /= No_Name
- and then
- Namet.Get_Name_String
- (Unit.File_Names (Specification).Path) =
- Original_Name)
+ Unit := Units_Htable.Get_First (In_Tree.Units_HT);
+
+ while Unit /= null loop
+ if Unit.File_Names (Spec) /= null
+ and then Unit.File_Names (Spec).File /= No_File
+ and then
+ (Namet.Get_Name_String
+ (Unit.File_Names (Spec).File) = Original_Name
+ or else (Unit.File_Names (Spec).Path /=
+ No_Path_Information
+ and then
+ Namet.Get_Name_String
+ (Unit.File_Names (Spec).Path.Name) =
+ Original_Name))
then
- Project := Unit.File_Names (Specification).Project;
- Path := Unit.File_Names (Specification).Path;
+ Project := Ultimate_Extension_Of
+ (Project => Unit.File_Names (Spec).Project);
+ Path := Unit.File_Names (Spec).Path.Display_Name;
if Current_Verbosity > Default then
- Write_Str ("Done: Specification.");
+ Write_Str ("Done: Spec.");
Write_Eol;
end if;
return;
- elsif (Unit.File_Names (Body_Part).Name /= No_Name
- and then
- Namet.Get_Name_String
- (Unit.File_Names (Body_Part).Name) = Original_Name)
- or else (Unit.File_Names (Body_Part).Path /= No_Name
- and then Namet.Get_Name_String
- (Unit.File_Names (Body_Part).Path) =
- Original_Name)
+ elsif Unit.File_Names (Impl) /= null
+ and then Unit.File_Names (Impl).File /= No_File
+ and then
+ (Namet.Get_Name_String
+ (Unit.File_Names (Impl).File) = Original_Name
+ or else (Unit.File_Names (Impl).Path /=
+ No_Path_Information
+ and then Namet.Get_Name_String
+ (Unit.File_Names (Impl).Path.Name) =
+ Original_Name))
then
- Project := Unit.File_Names (Body_Part).Project;
- Path := Unit.File_Names (Body_Part).Path;
+ Project := Ultimate_Extension_Of
+ (Project => Unit.File_Names (Impl).Project);
+ Path := Unit.File_Names (Impl).Path.Display_Name;
if Current_Verbosity > Default then
Write_Str ("Done: Body.");
return;
end if;
+ Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
end loop;
end;
Project := No_Project;
- Path := No_Name;
+ Path := No_Path;
if Current_Verbosity > Default then
Write_Str ("Cannot be found.");
-- Initialize --
----------------
- procedure Initialize is
- Global : constant String := "global_configuration_pragmas";
- Local : constant String := "local_configuration_pragmas";
+ procedure Initialize (In_Tree : Project_Tree_Ref) is
begin
- -- Put the standard GNAT naming scheme in the Namings table
-
- Namings.Increment_Last;
- Namings.Table (Namings.Last) := Standard_Naming_Data;
- Name_Len := Global'Length;
- Name_Buffer (1 .. Name_Len) := Global;
- Global_Configuration_Pragmas := Name_Find;
- Name_Len := Local'Length;
- Name_Buffer (1 .. Name_Len) := Local;
- Local_Configuration_Pragmas := Name_Find;
+ In_Tree.Private_Part.Current_Source_Path_File := No_Path;
+ In_Tree.Private_Part.Current_Object_Path_File := No_Path;
end Initialize;
- ------------------------------------
- -- Path_Name_Of_Library_Unit_Body --
- ------------------------------------
-
- function Path_Name_Of_Library_Unit_Body
- (Name : String;
- Project : Project_Id)
- return String
- is
- Data : constant Project_Data := Projects.Table (Project);
- Original_Name : String := Name;
-
- Extended_Spec_Name : String :=
- Name & Namet.Get_Name_String
- (Data.Naming.Current_Spec_Suffix);
- Extended_Body_Name : String :=
- Name & Namet.Get_Name_String
- (Data.Naming.Current_Impl_Suffix);
-
- First : Unit_Id := Units.First;
- Current : Unit_Id;
- Unit : Unit_Data;
-
- begin
- Canonical_Case_File_Name (Original_Name);
- Canonical_Case_File_Name (Extended_Spec_Name);
- Canonical_Case_File_Name (Extended_Spec_Name);
-
- if Current_Verbosity = High then
- Write_Str ("Looking for path name of """);
- Write_Str (Name);
- Write_Char ('"');
- Write_Eol;
- Write_Str (" Extended Spec Name = """);
- Write_Str (Extended_Spec_Name);
- Write_Char ('"');
- Write_Eol;
- Write_Str (" Extended Body Name = """);
- Write_Str (Extended_Body_Name);
- Write_Char ('"');
- Write_Eol;
- end if;
-
- while First <= Units.Last
- and then Units.Table (First).File_Names (Body_Part).Project /= Project
- loop
- First := First + 1;
- end loop;
-
- Current := First;
- while Current <= Units.Last loop
- Unit := Units.Table (Current);
-
- if Unit.File_Names (Body_Part).Project = Project
- and then Unit.File_Names (Body_Part).Name /= No_Name
- then
- declare
- Current_Name : constant String :=
- Namet.Get_Name_String (Unit.File_Names (Body_Part).Name);
- begin
- if Current_Verbosity = High then
- Write_Str (" Comparing with """);
- Write_Str (Current_Name);
- Write_Char ('"');
- Write_Eol;
- end if;
-
- if Current_Name = Original_Name then
- if Current_Verbosity = High then
- Write_Line (" OK");
- end if;
-
- return Body_Path_Name_Of (Current);
-
- elsif Current_Name = Extended_Body_Name then
- if Current_Verbosity = High then
- Write_Line (" OK");
- end if;
-
- return Body_Path_Name_Of (Current);
-
- else
- if Current_Verbosity = High then
- Write_Line (" not good");
- end if;
- end if;
- end;
-
- elsif Unit.File_Names (Specification).Name /= No_Name then
- declare
- Current_Name : constant String :=
- Namet.Get_Name_String
- (Unit.File_Names (Specification).Name);
-
- begin
- if Current_Verbosity = High then
- Write_Str (" Comparing with """);
- Write_Str (Current_Name);
- Write_Char ('"');
- Write_Eol;
- end if;
-
- if Current_Name = Original_Name then
- if Current_Verbosity = High then
- Write_Line (" OK");
- end if;
-
- return Spec_Path_Name_Of (Current);
-
- elsif Current_Name = Extended_Spec_Name then
-
- if Current_Verbosity = High then
- Write_Line (" OK");
- end if;
-
- return Spec_Path_Name_Of (Current);
-
- else
- if Current_Verbosity = High then
- Write_Line (" not good");
- end if;
- end if;
- end;
- end if;
- Current := Current + 1;
- end loop;
-
- return "";
- end Path_Name_Of_Library_Unit_Body;
-
-------------------
-- Print_Sources --
-------------------
- procedure Print_Sources is
- Unit : Unit_Data;
+ -- Could use some comments in this body ???
+
+ procedure Print_Sources (In_Tree : Project_Tree_Ref) is
+ Unit : Unit_Index;
begin
Write_Line ("List of Sources:");
- for Id in Units.First .. Units.Last loop
- Unit := Units.Table (Id);
+ Unit := Units_Htable.Get_First (In_Tree.Units_HT);
+
+ while Unit /= No_Unit_Index loop
Write_Str (" ");
Write_Line (Namet.Get_Name_String (Unit.Name));
- if Unit.File_Names (Specification).Name /= No_Name then
- if Unit.File_Names (Specification).Project = No_Project then
+ if Unit.File_Names (Spec).File /= No_File then
+ if Unit.File_Names (Spec).Project = No_Project then
Write_Line (" No project");
else
Write_Str (" Project: ");
Get_Name_String
- (Projects.Table
- (Unit.File_Names (Specification).Project).Path_Name);
+ (Unit.File_Names (Spec).Project.Path.Name);
Write_Line (Name_Buffer (1 .. Name_Len));
end if;
Write_Str (" spec: ");
Write_Line
(Namet.Get_Name_String
- (Unit.File_Names (Specification).Name));
+ (Unit.File_Names (Spec).File));
end if;
- if Unit.File_Names (Body_Part).Name /= No_Name then
- if Unit.File_Names (Body_Part).Project = No_Project then
+ if Unit.File_Names (Impl).File /= No_File then
+ if Unit.File_Names (Impl).Project = No_Project then
Write_Line (" No project");
else
Write_Str (" Project: ");
Get_Name_String
- (Projects.Table
- (Unit.File_Names (Body_Part).Project).Path_Name);
+ (Unit.File_Names (Impl).Project.Path.Name);
Write_Line (Name_Buffer (1 .. Name_Len));
end if;
Write_Str (" body: ");
Write_Line
- (Namet.Get_Name_String
- (Unit.File_Names (Body_Part).Name));
+ (Namet.Get_Name_String (Unit.File_Names (Impl).File));
end if;
+ Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
end loop;
Write_Line ("end of List of Sources.");
end Print_Sources;
- -----------------------
- -- Spec_Path_Name_Of --
- -----------------------
+ ----------------
+ -- Project_Of --
+ ----------------
+
+ function Project_Of
+ (Name : String;
+ Main_Project : Project_Id;
+ In_Tree : Project_Tree_Ref) return Project_Id
+ is
+ Result : Project_Id := No_Project;
+
+ Original_Name : String := Name;
+
+ Lang : constant Language_Ptr :=
+ Get_Language_From_Name (Main_Project, "ada");
- function Spec_Path_Name_Of (Unit : Unit_Id) return String is
- Data : Unit_Data := Units.Table (Unit);
+ Unit : Unit_Index;
+
+ Current_Name : File_Name_Type;
+ The_Original_Name : File_Name_Type;
+ The_Spec_Name : File_Name_Type;
+ The_Body_Name : File_Name_Type;
begin
- if Data.File_Names (Specification).Path = No_Name then
+ -- ??? Same block in File_Name_Of_Library_Unit_Body
+ Canonical_Case_File_Name (Original_Name);
+ Name_Len := Original_Name'Length;
+ Name_Buffer (1 .. Name_Len) := Original_Name;
+ The_Original_Name := Name_Find;
+
+ if Lang /= null then
declare
- Current_Source : String_List_Id :=
- Projects.Table (Data.File_Names (Specification).Project).Sources;
- Path : GNAT.OS_Lib.String_Access;
+ Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
+ Extended_Spec_Name : String :=
+ Name & Namet.Get_Name_String
+ (Naming.Spec_Suffix);
+ Extended_Body_Name : String :=
+ Name & Namet.Get_Name_String
+ (Naming.Body_Suffix);
begin
- Data.File_Names (Specification).Path :=
- Data.File_Names (Specification).Name;
-
- while Current_Source /= Nil_String loop
- String_To_Name_Buffer
- (String_Elements.Table (Current_Source).Value);
- Path := Locate_Regular_File
- (Namet.Get_Name_String
- (Data.File_Names (Specification).Name),
- Name_Buffer (1 .. Name_Len));
-
- if Path /= null then
- Name_Len := Path'Length;
- Name_Buffer (1 .. Name_Len) := Path.all;
- Data.File_Names (Specification).Path := Name_Enter;
- exit;
- else
- Current_Source :=
- String_Elements.Table (Current_Source).Next;
- end if;
- end loop;
-
- Units.Table (Unit) := Data;
+ Canonical_Case_File_Name (Extended_Spec_Name);
+ Name_Len := Extended_Spec_Name'Length;
+ Name_Buffer (1 .. Name_Len) := Extended_Spec_Name;
+ The_Spec_Name := Name_Find;
+
+ Canonical_Case_File_Name (Extended_Body_Name);
+ Name_Len := Extended_Body_Name'Length;
+ Name_Buffer (1 .. Name_Len) := Extended_Body_Name;
+ The_Body_Name := Name_Find;
end;
+
+ else
+ The_Spec_Name := The_Original_Name;
+ The_Body_Name := The_Original_Name;
+ end if;
+
+ Unit := Units_Htable.Get_First (In_Tree.Units_HT);
+ while Unit /= null loop
+
+ -- Case of a body present
+
+ if Unit.File_Names (Impl) /= null then
+ Current_Name := Unit.File_Names (Impl).File;
+
+ -- If it has the name of the original name or the body name,
+ -- we have found the project.
+
+ if Unit.Name = Name_Id (The_Original_Name)
+ or else Current_Name = The_Original_Name
+ or else Current_Name = The_Body_Name
+ then
+ Result := Unit.File_Names (Impl).Project;
+ exit;
+ end if;
+ end if;
+
+ -- Check for spec
+
+ if Unit.File_Names (Spec) /= null then
+ Current_Name := Unit.File_Names (Spec).File;
+
+ -- If name same as the original name, or the spec name, we have
+ -- found the project.
+
+ if Unit.Name = Name_Id (The_Original_Name)
+ or else Current_Name = The_Original_Name
+ or else Current_Name = The_Spec_Name
+ then
+ Result := Unit.File_Names (Spec).Project;
+ exit;
+ end if;
+ end if;
+
+ Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
+ end loop;
+
+ -- Get the ultimate extending project
+
+ if Result /= No_Project then
+ while Result.Extended_By /= No_Project loop
+ Result := Result.Extended_By;
+ end loop;
+ end if;
+
+ return Result;
+ end Project_Of;
+
+ -------------------
+ -- Set_Ada_Paths --
+ -------------------
+
+ procedure Set_Ada_Paths
+ (Project : Project_Id;
+ In_Tree : Project_Tree_Ref;
+ Including_Libraries : Boolean)
+
+ is
+ Source_Paths : Source_Path_Table.Instance;
+ Object_Paths : Object_Path_Table.Instance;
+ -- List of source or object dirs. Only computed the first time this
+ -- procedure is called (since Source_FD is then reused)
+
+ Source_FD : File_Descriptor := Invalid_FD;
+ Object_FD : File_Descriptor := Invalid_FD;
+ -- The temporary files to store the paths. These are only created the
+ -- first time this procedure is called, and reused from then on.
+
+ Process_Source_Dirs : Boolean := False;
+ Process_Object_Dirs : Boolean := False;
+
+ Status : Boolean;
+ -- For calls to Close
+
+ Last : Natural;
+ Buffer : String_Access := new String (1 .. Buffer_Initial);
+ Buffer_Last : Natural := 0;
+
+ procedure Recursive_Add (Project : Project_Id; Dummy : in out Boolean);
+ -- Recursive procedure to add the source/object paths of extended/
+ -- imported projects.
+
+ -------------------
+ -- Recursive_Add --
+ -------------------
+
+ procedure Recursive_Add (Project : Project_Id; Dummy : in out Boolean) is
+ pragma Unreferenced (Dummy);
+
+ Path : Path_Name_Type;
+
+ begin
+ -- ??? This is almost the equivalent of For_All_Source_Dirs
+
+ if Process_Source_Dirs then
+
+ -- Add to path all source directories of this project if there are
+ -- Ada sources.
+
+ if Has_Ada_Sources (Project) then
+ Add_To_Source_Path (Project.Source_Dirs, In_Tree, Source_Paths);
+ end if;
+ end if;
+
+ if Process_Object_Dirs then
+ Path := Get_Object_Directory
+ (Project,
+ Including_Libraries => Including_Libraries,
+ Only_If_Ada => True);
+
+ if Path /= No_Path then
+ Add_To_Object_Path (Path, Object_Paths);
+ end if;
+ end if;
+ end Recursive_Add;
+
+ procedure For_All_Projects is
+ new For_Every_Project_Imported (Boolean, Recursive_Add);
+
+ Dummy : Boolean := False;
+
+ -- Start of processing for Set_Ada_Paths
+
+ begin
+ -- If it is the first time we call this procedure for this project,
+ -- compute the source path and/or the object path.
+
+ if Project.Include_Path_File = No_Path then
+ Source_Path_Table.Init (Source_Paths);
+ Process_Source_Dirs := True;
+ Create_New_Path_File
+ (In_Tree, Source_FD, Project.Include_Path_File);
+ end if;
+
+ -- For the object path, we make a distinction depending on
+ -- Including_Libraries.
+
+ if Including_Libraries then
+ if Project.Objects_Path_File_With_Libs = No_Path then
+ Object_Path_Table.Init (Object_Paths);
+ Process_Object_Dirs := True;
+ Create_New_Path_File
+ (In_Tree, Object_FD, Project.Objects_Path_File_With_Libs);
+ end if;
+
+ else
+ if Project.Objects_Path_File_Without_Libs = No_Path then
+ Object_Path_Table.Init (Object_Paths);
+ Process_Object_Dirs := True;
+ Create_New_Path_File
+ (In_Tree, Object_FD, Project.Objects_Path_File_Without_Libs);
+ end if;
end if;
- return Namet.Get_Name_String (Data.File_Names (Specification).Path);
- end Spec_Path_Name_Of;
+ -- If there is something to do, set Seen to False for all projects,
+ -- then call the recursive procedure Add for Project.
+
+ if Process_Source_Dirs or Process_Object_Dirs then
+ For_All_Projects (Project, Dummy);
+ end if;
+
+ -- Write and close any file that has been created. Source_FD is not set
+ -- when this subprogram is called a second time or more, since we reuse
+ -- the previous version of the file.
+
+ if Source_FD /= Invalid_FD then
+ Buffer_Last := 0;
+
+ for Index in Source_Path_Table.First ..
+ Source_Path_Table.Last (Source_Paths)
+ loop
+ Get_Name_String (Source_Paths.Table (Index));
+ Name_Len := Name_Len + 1;
+ Name_Buffer (Name_Len) := ASCII.LF;
+ Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
+ end loop;
+
+ Last := Write (Source_FD, Buffer (1)'Address, Buffer_Last);
+
+ if Last = Buffer_Last then
+ Close (Source_FD, Status);
+
+ else
+ Status := False;
+ end if;
+
+ if not Status then
+ Prj.Com.Fail ("could not write temporary file");
+ end if;
+ end if;
+
+ if Object_FD /= Invalid_FD then
+ Buffer_Last := 0;
+
+ for Index in Object_Path_Table.First ..
+ Object_Path_Table.Last (Object_Paths)
+ loop
+ Get_Name_String (Object_Paths.Table (Index));
+ Name_Len := Name_Len + 1;
+ Name_Buffer (Name_Len) := ASCII.LF;
+ Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
+ end loop;
+
+ Last := Write (Object_FD, Buffer (1)'Address, Buffer_Last);
+
+ if Last = Buffer_Last then
+ Close (Object_FD, Status);
+ else
+ Status := False;
+ end if;
+
+ if not Status then
+ Prj.Com.Fail ("could not write temporary file");
+ end if;
+ end if;
+
+ -- Set the env vars, if they need to be changed, and set the
+ -- corresponding flags.
+
+ if In_Tree.Private_Part.Current_Source_Path_File /=
+ Project.Include_Path_File
+ then
+ In_Tree.Private_Part.Current_Source_Path_File :=
+ Project.Include_Path_File;
+ Set_Path_File_Var
+ (Project_Include_Path_File,
+ Get_Name_String (In_Tree.Private_Part.Current_Source_Path_File));
+ end if;
+
+ if Including_Libraries then
+ if In_Tree.Private_Part.Current_Object_Path_File /=
+ Project.Objects_Path_File_With_Libs
+ then
+ In_Tree.Private_Part.Current_Object_Path_File :=
+ Project.Objects_Path_File_With_Libs;
+ Set_Path_File_Var
+ (Project_Objects_Path_File,
+ Get_Name_String
+ (In_Tree.Private_Part.Current_Object_Path_File));
+ end if;
+
+ else
+ if In_Tree.Private_Part.Current_Object_Path_File /=
+ Project.Objects_Path_File_Without_Libs
+ then
+ In_Tree.Private_Part.Current_Object_Path_File :=
+ Project.Objects_Path_File_Without_Libs;
+ Set_Path_File_Var
+ (Project_Objects_Path_File,
+ Get_Name_String
+ (In_Tree.Private_Part.Current_Object_Path_File));
+ end if;
+ end if;
+
+ Free (Buffer);
+ end Set_Ada_Paths;
+
+ -----------------------
+ -- Set_Path_File_Var --
+ -----------------------
+
+ procedure Set_Path_File_Var (Name : String; Value : String) is
+ Host_Spec : String_Access := To_Host_File_Spec (Value);
+ begin
+ if Host_Spec = null then
+ Prj.Com.Fail
+ ("could not convert file name """ & Value & """ to host spec");
+ else
+ Setenv (Name, Host_Spec.all);
+ Free (Host_Spec);
+ end if;
+ end Set_Path_File_Var;
+
+ ---------------------------
+ -- Ultimate_Extension_Of --
+ ---------------------------
+
+ function Ultimate_Extension_Of
+ (Project : Project_Id) return Project_Id
+ is
+ Result : Project_Id;
+
+ begin
+ Result := Project;
+ while Result.Extended_By /= No_Project loop
+ Result := Result.Extended_By;
+ end loop;
+
+ return Result;
+ end Ultimate_Extension_Of;
end Prj.Env;