procedure Load_Naming_Exceptions
(Project : Project_Id;
- In_Tree : Project_Tree_Ref;
- Data : in out Project_Data);
+ In_Tree : Project_Tree_Ref);
-- All source files in Data.First_Source are considered as naming
-- exceptions, and copied into the Source_Names and Unit_Exceptions tables
-- as appropriate.
procedure Add_Source
(Id : out Source_Id;
- Data : in out Project_Data;
In_Tree : Project_Tree_Ref;
Project : Project_Id;
- Lang : Name_Id;
Lang_Id : Language_Ptr;
Kind : Source_Kind;
File_Name : File_Name_Type;
procedure Remove_Source
(Id : Source_Id;
Replaced_By : Source_Id;
- Project : Project_Id;
- Data : in out Project_Data;
In_Tree : Project_Tree_Ref);
-- ??? needs comment
procedure Add_Source
(Id : out Source_Id;
- Data : in out Project_Data;
In_Tree : Project_Tree_Ref;
Project : Project_Id;
- Lang : Name_Id;
Lang_Id : Language_Ptr;
Kind : Source_Kind;
File_Name : File_Name_Type;
Index : Int := 0;
Source_To_Replace : Source_Id := No_Source)
is
- Source : constant Source_Id := Data.Last_Source;
Src_Data : Source_Data := No_Source_Data;
Config : constant Language_Config := Lang_Id.Config;
Write_Str (Get_Name_String (File_Name));
if Lang_Kind = Unit_Based then
- Write_Str (", Unit : ");
- Write_Str (Get_Name_String (Unit));
+ Write_Str (" Unit: ");
+ -- ??? in gprclean, it seems we sometimes pass an empty Unit name
+ -- (see test extended_projects)
+ if Unit /= No_Name then
+ Write_Str (Get_Name_String (Unit));
+ end if;
+ Write_Str (" Kind: ");
+ Write_Str (Source_Kind'Image (Kind));
end if;
Write_Eol;
Unit_Sources_Htable.Set (In_Tree.Unit_Sources_HT, Unit, Id);
end if;
- -- Add the source to the global list
-
- Src_Data.Next_In_Sources := In_Tree.First_Source;
- In_Tree.First_Source := Id;
-
- -- Add the source to the project list
-
- if Source = No_Source then
- Data.First_Source := Id;
- else
- In_Tree.Sources.Table (Source).Next_In_Project := Id;
- end if;
-
- Data.Last_Source := Id;
-
-- Add the source to the language list
Src_Data.Next_In_Lang := Lang_Id.First_Source;
In_Tree.Sources.Table (Id) := Src_Data;
if Source_To_Replace /= No_Source then
- Remove_Source (Source_To_Replace, Id, Project, Data, In_Tree);
+ Remove_Source (Source_To_Replace, Id, In_Tree);
end if;
end Add_Source;
When_No_Sources : Error_Warning;
Current_Dir : String)
is
- Data : Project_Data := In_Tree.Projects.Table (Project);
+ Data : Project_Data renames In_Tree.Projects.Table (Project);
Extending : Boolean := False;
begin
Alt_Lang : Alternate_Language_Id;
Alt_Lang_Data : Alternate_Language_Data;
Continuation : Boolean := False;
+ Iter : Source_Iterator;
begin
Language := Data.Languages;
while Language /= No_Language_Index loop
- Source := Data.First_Source;
- Source_Loop : while Source /= No_Source loop
- declare
- Src_Data : Source_Data renames
- In_Tree.Sources.Table (Source);
+ -- If there are no sources for this language, check whether
+ -- there are sources for which this is an alternate
+ -- language
- begin
- exit Source_Loop when Src_Data.Language = Language;
+ if Language.First_Source = No_Source then
+ Iter := For_Each_Source (In_Tree => In_Tree,
+ Project => Project);
+ Source_Loop : loop
+ Source := Element (Iter);
+ exit Source_Loop when Source = No_Source;
- Alt_Lang := Src_Data.Alternate_Languages;
+ declare
+ Src_Data : Source_Data renames
+ In_Tree.Sources.Table (Source);
- Alternate_Loop :
- while Alt_Lang /= No_Alternate_Language loop
- Alt_Lang_Data :=
- In_Tree.Alt_Langs.Table (Alt_Lang);
- exit Source_Loop
- when Alt_Lang_Data.Language = Language;
- Alt_Lang := Alt_Lang_Data.Next;
- end loop Alternate_Loop;
+ begin
+ exit Source_Loop when Src_Data.Language = Language;
+
+ Alt_Lang := Src_Data.Alternate_Languages;
+
+ Alternate_Loop :
+ while Alt_Lang /= No_Alternate_Language loop
+ Alt_Lang_Data :=
+ In_Tree.Alt_Langs.Table (Alt_Lang);
+ exit Source_Loop
+ when Alt_Lang_Data.Language = Language;
+ Alt_Lang := Alt_Lang_Data.Next;
+ end loop Alternate_Loop;
+ end;
- Source := Src_Data.Next_In_Project;
- end;
- end loop Source_Loop;
+ Next (Iter);
+ end loop Source_Loop;
- if Source = No_Source then
- Report_No_Sources
- (Project,
- Get_Name_String (Language.Display_Name),
- In_Tree,
- Data.Location,
- Continuation);
- Continuation := True;
+ if Source = No_Source then
+ Report_No_Sources
+ (Project,
+ Get_Name_String (Language.Display_Name),
+ In_Tree,
+ Data.Location,
+ Continuation);
+ Continuation := True;
+ end if;
end if;
Language := Language.Next;
List : String_List_Id;
Element : String_Element;
Name : File_Name_Type;
-
+ Iter : Source_Iterator;
Source : Source_Id;
-
Project_2 : Project_Id;
- Data_2 : Project_Data;
begin
if not Interfaces.Default then
-- later for the sources in the Interfaces list.
Project_2 := Project;
- Data_2 := Data;
- loop
- Source := Data_2.First_Source;
- while Source /= No_Source loop
- declare
- Src_Data : Source_Data renames
- In_Tree.Sources.Table (Source);
- begin
- Src_Data.In_Interfaces := False;
- Source := Src_Data.Next_In_Project;
- end;
- end loop;
-
- Project_2 := Data_2.Extends;
+ while Project_2 /= No_Project loop
+ Iter := For_Each_Source (In_Tree, Project_2);
- exit when Project_2 = No_Project;
+ loop
+ Source := Prj.Element (Iter);
+ exit when Source = No_Source;
+ In_Tree.Sources.Table (Source).In_Interfaces := False;
+ Next (Iter);
+ end loop;
- Data_2 := In_Tree.Projects.Table (Project_2);
+ Project_2 := In_Tree.Projects.Table (Project_2).Extends;
end loop;
List := Interfaces.Values;
Name := Canonical_Case_File_Name (Element.Value);
Project_2 := Project;
- Data_2 := Data;
Big_Loop :
- loop
- Source := Data_2.First_Source;
- while Source /= No_Source loop
+ while Project_2 /= No_Project loop
+ Iter := For_Each_Source (In_Tree, Project_2);
+
+ loop
+ Source := Prj.Element (Iter);
+ exit when Source = No_Source;
+
declare
Src_Data : Source_Data renames
In_Tree.Sources.Table (Source);
exit Big_Loop;
end if;
- Source := Src_Data.Next_In_Project;
+ Next (Iter);
end;
end loop;
- Project_2 := Data_2.Extends;
-
- exit Big_Loop when Project_2 = No_Project;
-
- Data_2 := In_Tree.Projects.Table (Project_2);
+ Project_2 := In_Tree.Projects.Table (Project_2).Extends;
end loop Big_Loop;
if Source = No_Source then
In_Tree.Projects.Table (Data.Extends).Interfaces_Defined;
if Data.Interfaces_Defined then
- Source := Data.First_Source;
- while Source /= No_Source loop
+ Iter := For_Each_Source (In_Tree, Project);
+ loop
+ Source := Prj.Element (Iter);
+ exit when Source = No_Source;
+
declare
Src_Data : Source_Data renames
In_Tree.Sources.Table (Source);
if not Src_Data.Declared_In_Interfaces then
Src_Data.In_Interfaces := False;
end if;
-
- Source := Src_Data.Next_In_Project;
end;
+
+ Next (Iter);
end loop;
end if;
end if;
Element : String_Element;
File_Name : File_Name_Type;
Source : Source_Id;
+ Iter : Source_Iterator;
begin
case Kind is
Element := In_Tree.String_Elements.Table (Element_Id);
File_Name := Canonical_Case_File_Name (Element.Value);
- Source := Data.First_Source;
- while Source /= No_Source
- and then In_Tree.Sources.Table (Source).File /= File_Name
+ Iter := For_Each_Source (In_Tree, Project);
loop
- Source := In_Tree.Sources.Table (Source).Next_In_Project;
+ Source := Prj.Element (Iter);
+ exit when Source = No_Source
+ or else In_Tree.Sources.Table (Source).File = File_Name;
+ Next (Iter);
end loop;
if Source = No_Source then
Add_Source
(Id => Source,
- Data => Data,
In_Tree => In_Tree,
Project => Project,
- Lang => Lang,
Lang_Id => Lang_Id,
Kind => Kind,
File_Name => File_Name,
Source_To_Replace : Source_Id := No_Source;
Other_Project : Project_Id;
Other_Part : Source_Id := No_Source;
+ Iter : Source_Iterator;
begin
case Kind is
-- Check if the source already exists
- Source := In_Tree.First_Source;
Source_To_Replace := No_Source;
+ Iter := For_Each_Source (In_Tree);
- while Source /= No_Source and then
- (In_Tree.Sources.Table (Source).Unit /= Unit or else
- In_Tree.Sources.Table (Source).Index /= Index)
loop
- Source := In_Tree.Sources.Table (Source).Next_In_Sources;
+ Source := Prj.Element (Iter);
+ exit when Source = No_Source
+ or else
+ (In_Tree.Sources.Table (Source).Unit = Unit and then
+ In_Tree.Sources.Table (Source).Index = Index);
+ Next (Iter);
end loop;
if Source /= No_Source then
Other_Part := Source;
loop
- Source :=
- In_Tree.Sources.Table (Source).Next_In_Sources;
+ Next (Iter);
+ Source := Prj.Element (Iter);
exit when Source = No_Source or else
(In_Tree.Sources.Table (Source).Unit = Unit
if Source = No_Source then
Add_Source
(Id => Source,
- Data => Data,
In_Tree => In_Tree,
Project => Project,
- Lang => Lang,
Lang_Id => Lang_Id,
Kind => Kind,
File_Name => File_Name,
procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
Proj_Data : Project_Data;
Src_Id : Source_Id;
+ Iter : Source_Iterator;
begin
if Proj /= No_Project then
-- have no sources. However, header files from non-Ada
-- languages are OK, as there is nothing to compile.
- Src_Id := Proj_Data.First_Source;
- while Src_Id /= No_Source loop
+ Iter := For_Each_Source (In_Tree, Proj);
+ loop
+ Src_Id := Prj.Element (Iter);
+ exit when Src_Id = No_Source;
+
declare
Src : Source_Data renames In_Tree.Sources.Table (Src_Id);
begin
exit when Src.Lang_Kind /= File_Based
or else Src.Kind /= Spec;
- Src_Id := Src.Next_In_Project;
end;
+ Next (Iter);
end loop;
if Src_Id /= No_Source then
OK : Boolean := True;
Source : Source_Id;
Next_Proj : Project_Id;
+ Iter : Source_Iterator;
begin
if Get_Mode = Multi_Language then
-- Multi_Language mode
Next_Proj := Data.Extends;
- Source := Data.First_Source;
+
+ Iter := For_Each_Source (In_Tree, Project);
loop
- while Source /= No_Source and then
- In_Tree.Sources.Table (Source).Unit /= Unit
+ while Prj.Element (Iter) /= No_Source and then
+ In_Tree.Sources.Table (Prj.Element (Iter)).Unit /=
+ Unit
loop
- Source :=
- In_Tree.Sources.Table (Source).Next_In_Project;
+ Next (Iter);
end loop;
+ Source := Prj.Element (Iter);
exit when Source /= No_Source or else
Next_Proj = No_Project;
- Source :=
- In_Tree.Projects.Table (Next_Proj).First_Source;
+ Iter := For_Each_Source (In_Tree, Next_Proj);
Next_Proj :=
In_Tree.Projects.Table (Next_Proj).Extends;
end loop;
declare
Source : Source_Id;
+ Iter : Source_Iterator;
begin
- Source := Data.First_Source;
- while Source /= No_Source loop
+ Iter := For_Each_Source (In_Tree, Project);
+ loop
+ Source := Prj.Element (Iter);
+ exit when Source = No_Source;
+
declare
Src_Data : Source_Data renames
In_Tree.Sources.Table (Source);
No_Location);
end if;
- Remove_Source (Source, No_Source, Project, Data, In_Tree);
+ Remove_Source (Source, No_Source, In_Tree);
end if;
-
- Source := Src_Data.Next_In_Project;
end;
+
+ Next (Iter);
end loop;
end;
Display_Language_Name : Name_Id;
Lang_Kind : Language_Kind;
Kind : Source_Kind := Spec;
+ Iter : Source_Iterator;
begin
Name_Len := Display_Path'Length;
else
-- Check if the same file name or unit is used in the prj tree
- Source := In_Tree.First_Source;
+ Iter := For_Each_Source (In_Tree);
Add_Src := True;
- while Source /= No_Source loop
+ loop
+ Source := Prj.Element (Iter);
+ exit when Source = No_Source;
+
declare
Src_Data : Source_Data renames
In_Tree.Sources.Table (Source);
end if;
end if;
- Source := Src_Data.Next_In_Sources;
end;
+ Next (Iter);
end loop;
if Add_Src then
Add_Source
(Id => Source,
- Data => Data,
In_Tree => In_Tree,
Project => Project,
- Lang => Language_Name,
Lang_Id => Language,
Lang_Kind => Lang_Kind,
Kind => Kind,
procedure Load_Naming_Exceptions
(Project : Project_Id;
- In_Tree : Project_Tree_Ref;
- Data : in out Project_Data)
+ In_Tree : Project_Tree_Ref)
is
Source : Source_Id;
File : File_Name_Type;
Unit : Name_Id;
+ Iter : Source_Iterator;
begin
Unit_Exceptions.Reset;
- Source := Data.First_Source;
- while Source /= No_Source loop
+ Iter := For_Each_Source (In_Tree, Project);
+ loop
+ Source := Prj.Element (Iter);
+ exit when Source = No_Source;
+
File := In_Tree.Sources.Table (Source).File;
Unit := In_Tree.Sources.Table (Source).Unit;
end;
end if;
- Source := In_Tree.Sources.Table (Source).Next_In_Project;
+ Next (Iter);
end loop;
end Load_Naming_Exceptions;
Data : in out Project_Data;
Current_Dir : String)
is
+ Iter : Source_Iterator;
+
procedure Process_Sources_In_Multi_Language_Mode;
-- Find all source files when in multi language mode
end loop For_Each_Unit;
when Multi_Language =>
- Source := In_Tree.First_Source;
- while Source /= No_Source loop
+ Iter := For_Each_Source (In_Tree);
+ loop
+ Source := Prj.Element (Iter);
+ exit when Source = No_Source;
+
if In_Tree.Sources.Table (Source).File = Excluded.File then
Exclude
(In_Tree.Sources.Table (Source).Project,
exit;
end if;
- Source := In_Tree.Sources.Table (Source).Next_In_Sources;
+ Next (Iter);
end loop;
OK := OK or Excluded.Found;
--------------------------------------------
procedure Process_Sources_In_Multi_Language_Mode is
+ Iter : Source_Iterator;
begin
-- Check that two sources of this project do not have the same object
-- file name.
begin
Object_File_Names.Reset;
- Src_Id := In_Tree.First_Source;
- while Src_Id /= No_Source loop
+ Iter := For_Each_Source (In_Tree);
+ loop
+ Src_Id := Prj.Element (Iter);
+ exit when Src_Id = No_Source;
+
declare
Src_Data : Source_Data renames
In_Tree.Sources.Table (Src_Id);
end case;
end if;
end if;
-
- Src_Id := Src_Data.Next_In_Sources;
end;
+
+ Next (Iter);
end loop;
end Check_Object_File_Names;
end Process_Sources_In_Multi_Language_Mode;
and then Data.Languages /= No_Language_Index)
then
if Get_Mode = Multi_Language then
- Load_Naming_Exceptions (Project, In_Tree, Data);
+ Load_Naming_Exceptions (Project, In_Tree);
end if;
Find_Explicit_Sources (Current_Dir, Project, In_Tree, Data);
procedure Remove_Source
(Id : Source_Id;
Replaced_By : Source_Id;
- Project : Project_Id;
- Data : in out Project_Data;
In_Tree : Project_Tree_Ref)
is
Src_Data : constant Source_Data := In_Tree.Sources.Table (Id);
In_Tree.Sources.Table (Id).Declared_In_Interfaces;
end if;
- -- Remove the source from the global source list
-
- Source := In_Tree.First_Source;
-
- if Source = Id then
- In_Tree.First_Source := Src_Data.Next_In_Sources;
-
- else
- while In_Tree.Sources.Table (Source).Next_In_Sources /= Id loop
- Source := In_Tree.Sources.Table (Source).Next_In_Sources;
- end loop;
-
- In_Tree.Sources.Table (Source).Next_In_Sources :=
- Src_Data.Next_In_Sources;
- end if;
-
- -- Remove the source from the project list
-
- if Src_Data.Project = Project then
- Source := Data.First_Source;
-
- if Source = Id then
- Data.First_Source := Src_Data.Next_In_Project;
-
- if Src_Data.Next_In_Project = No_Source then
- Data.Last_Source := No_Source;
- end if;
-
- else
- while In_Tree.Sources.Table (Source).Next_In_Project /= Id loop
- Source := In_Tree.Sources.Table (Source).Next_In_Project;
- end loop;
-
- In_Tree.Sources.Table (Source).Next_In_Project :=
- Src_Data.Next_In_Project;
-
- if Src_Data.Next_In_Project = No_Source then
- In_Tree.Projects.Table (Src_Data.Project).Last_Source := Source;
- end if;
- end if;
-
- else
- Source := In_Tree.Projects.Table (Src_Data.Project).First_Source;
-
- if Source = Id then
- In_Tree.Projects.Table (Src_Data.Project).First_Source :=
- Src_Data.Next_In_Project;
-
- if Src_Data.Next_In_Project = No_Source then
- In_Tree.Projects.Table (Src_Data.Project).Last_Source :=
- No_Source;
- end if;
-
- else
- while In_Tree.Sources.Table (Source).Next_In_Project /= Id loop
- Source := In_Tree.Sources.Table (Source).Next_In_Project;
- end loop;
-
- In_Tree.Sources.Table (Source).Next_In_Project :=
- Src_Data.Next_In_Project;
-
- if Src_Data.Next_In_Project = No_Source then
- In_Tree.Projects.Table (Src_Data.Project).Last_Source := Source;
- end if;
- end if;
- end if;
-
- -- Remove source from the language list
-
Source := Src_Data.Language.First_Source;
if Source = Id then
Naming_Exception : Boolean := False;
-- True if the source has an exceptional name
- Next_In_Sources : Source_Id := No_Source;
- -- Link to another source in the project tree
-
- Next_In_Project : Source_Id := No_Source;
- -- Link to another source in the project
-
Next_In_Lang : Source_Id := No_Source;
- -- Link to another source of the same language
+ -- Link to another source of the same language in the same project
end record;
No_Source_Data : constant Source_Data :=
Switches_Path => No_Path,
Switches_TS => Empty_Time_Stamp,
Naming_Exception => False,
- Next_In_Sources => No_Source,
- Next_In_Project => No_Source,
Next_In_Lang => No_Source);
package Source_Data_Table is new GNAT.Dynamic_Tables
-------------
-- Sources --
-------------
+ -- In multi-language mode, the sources for all languages including Ada
+ -- are accessible through the Source_Iterator type
Ada_Sources_Present : Boolean := True;
-- True if there are Ada sources in the project
-- True if there are non-Ada sources in the project
Ada_Sources : String_List_Id := Nil_String;
- -- The list of all the Ada source file names (gnatmake only)
-
- First_Source : Source_Id := No_Source;
- Last_Source : Source_Id := No_Source;
- -- Head and tail of the list of sources
+ -- The list of all the Ada source file names (gnatmake only).
Interfaces_Defined : Boolean := False;
-- True if attribute Interfaces is declared for the project or any
type Private_Project_Tree_Data is private;
-- Data for a project tree that is used only by the Project Manager
- type Project_Tree_Data is
- record
- -- sources of the project
+ type Source_Iterator is private;
+
+ function For_Each_Source
+ (In_Tree : Project_Tree_Ref;
+ Project : Project_Id := No_Project;
+ Language : Name_Id := No_Name) return Source_Iterator;
+ -- Returns an iterator for all the sources of a project tree, or a specific
+ -- project, or a specific language.
- First_Source : Source_Id := No_Source;
- --
+ function Element (Iter : Source_Iterator) return Source_Id;
+ -- Return the current source (or No_Source if there are no more sources)
- -- Tables
+ procedure Next (Iter : in out Source_Iterator);
+ -- Move on to the next source
+ type Project_Tree_Data is
+ record
Name_Lists : Name_List_Table.Instance;
String_Elements : String_Element_Table.Instance;
Variable_Elements : Variable_Element_Table.Instance;
-- Empty File_Name_Type (no characters). Initialized in procedure
-- Initialize.
+ type Source_Iterator is record
+ In_Tree : Project_Tree_Ref;
+
+ Project : Project_Id;
+ All_Projects : Boolean;
+ -- Current project and whether we should move on to the next
+
+ Language : Language_Ptr;
+ -- Current language processed
+
+ Language_Name : Name_Id;
+ -- Only sources of this language will be returned (or all if No_Name)
+
+ Current : Source_Id;
+ end record;
+
procedure Add_To_Buffer
(S : String;
To : in out String_Access;