Commit 5eed512d by Emmanuel Briot Committed by Arnaud Charlet

2009-04-24 Emmanuel Briot <briot@adacore.com>

	* prj-proc.adb, prj.adb, prj.ads, prj-nmsc.adb, prj-env.adb
	(Source_Iterator): new type.
        This removes the need for having the sources on three different
        lists at the project tree, project and language level. They are now
        on a single list.

From-SVN: r146689
parent 5876578b
2009-04-24 Emmanuel Briot <briot@adacore.com>
* prj-proc.adb, prj.adb, prj.ads, prj-nmsc.adb, prj-env.adb
(Source_Iterator): new type.
This removes the need for having the sources on three different
lists at the project tree, project and language level. They are now
on a single list.
2009-04-24 Emmanuel Briot <briot@adacore.com>
* gnatcmd.adb, prj.adb, prj.ads: Remove unused entities
2009-04-24 Ed Schonberg <schonberg@adacore.com>
......
......@@ -1054,6 +1054,7 @@ package body Prj.Env is
Suffix : File_Name_Type;
The_Unit_Data : Unit_Data;
Data : File_Name_Data;
Iter : Source_Iterator;
procedure Put_Name_Buffer;
-- Put the line contained in the Name_Buffer in the mapping file
......@@ -1200,8 +1201,12 @@ package body Prj.Env is
for Proj in Present'Range loop
if Present (Proj) then
Source := In_Tree.Projects.Table (Proj).First_Source;
while Source /= No_Source loop
Iter := For_Each_Source (In_Tree, Proj);
loop
Source := Prj.Element (Iter);
exit when Source = No_Source;
Src_Data := In_Tree.Sources.Table (Source);
if In_Tree.Sources.Table (Source).Language.Name = Language
......@@ -1234,7 +1239,7 @@ package body Prj.Env is
Put_Name_Buffer;
end if;
Source := Src_Data.Next_In_Project;
Next (Iter);
end loop;
end if;
end loop;
......
......@@ -291,12 +291,16 @@ package body Prj.Proc is
Source1 : Source_Id;
Name : Name_Id;
Source2 : Source_Id;
Iter : Source_Iterator;
begin
Unit_Htable.Reset;
Source1 := In_Tree.First_Source;
while Source1 /= No_Source loop
Iter := For_Each_Source (In_Tree);
loop
Source1 := Prj.Element (Iter);
exit when Source1 = No_Source;
Name := In_Tree.Sources.Table (Source1).Unit;
if Name /= No_Name then
......@@ -312,7 +316,7 @@ package body Prj.Proc is
end if;
end if;
Source1 := In_Tree.Sources.Table (Source1).Next_In_Sources;
Next (Iter);
end loop;
end;
end Check;
......
......@@ -108,8 +108,6 @@ package body Prj is
Ada_Sources_Present => True,
Other_Sources_Present => True,
Ada_Sources => Nil_String,
First_Source => No_Source,
Last_Source => No_Source,
Interfaces_Defined => False,
Imported_Directories_Switches => null,
Include_Path => null,
......@@ -157,6 +155,10 @@ package body Prj is
procedure Free_List (Languages : in out Language_Ptr);
-- Free memory allocated for the list of languages
procedure Language_Changed (Iter : in out Source_Iterator);
procedure Project_Changed (Iter : in out Source_Iterator);
-- Called when a new project or language was selected for this iterator.
-------------------
-- Add_To_Buffer --
-------------------
......@@ -388,6 +390,103 @@ package body Prj is
end Extend_Name;
---------------------
-- Project_Changed --
---------------------
procedure Project_Changed (Iter : in out Source_Iterator) is
begin
Iter.Language := Iter.In_Tree.Projects.Table (Iter.Project).Languages;
Language_Changed (Iter);
end Project_Changed;
----------------------
-- Language_Changed --
----------------------
procedure Language_Changed (Iter : in out Source_Iterator) is
begin
Iter.Current := No_Source;
if Iter.Language_Name /= No_Name then
while Iter.Language /= null
and then Iter.Language.Name /= Iter.Language_Name
loop
Iter.Language := Iter.Language.Next;
end loop;
end if;
-- If there is no matching language in this project, move to next
if Iter.Language = No_Language_Index then
if Iter.All_Projects then
Iter.Project := Iter.Project + 1;
if Iter.Project > Project_Table.Last (Iter.In_Tree.Projects) then
Iter.Project := No_Project;
else
Project_Changed (Iter);
end if;
else
Iter.Project := No_Project;
end if;
else
Iter.Current := Iter.Language.First_Source;
if Iter.Current = No_Source then
Iter.Language := Iter.Language.Next;
Language_Changed (Iter);
end if;
end if;
end Language_Changed;
---------------------
-- For_Each_Source --
---------------------
function For_Each_Source
(In_Tree : Project_Tree_Ref;
Project : Project_Id := No_Project;
Language : Name_Id := No_Name) return Source_Iterator
is
Iter : Source_Iterator;
begin
Iter := Source_Iterator'
(In_Tree => In_Tree,
Project => Project,
All_Projects => Project = No_Project,
Language_Name => Language,
Language => No_Language_Index,
Current => No_Source);
if Iter.Project = No_Project then
Iter.Project := Project_Table.First;
end if;
Project_Changed (Iter);
return Iter;
end For_Each_Source;
-------------
-- Element --
-------------
function Element (Iter : Source_Iterator) return Source_Id is
begin
return Iter.Current;
end Element;
----------
-- Next --
----------
procedure Next (Iter : in out Source_Iterator) is
begin
Iter.Current := Iter.In_Tree.Sources.Table (Iter.Current).Next_In_Lang;
if Iter.Current = No_Source then
Iter.Language := Iter.Language.Next;
Language_Changed (Iter);
end if;
end Next;
--------------------------------
-- For_Every_Project_Imported --
--------------------------------
......
......@@ -734,14 +734,8 @@ package Prj is
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 :=
......@@ -779,8 +773,6 @@ package Prj is
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
......@@ -1251,6 +1243,8 @@ package Prj is
-------------
-- 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
......@@ -1259,11 +1253,7 @@ package Prj is
-- 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
......@@ -1437,15 +1427,23 @@ package Prj is
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;
......@@ -1572,6 +1570,22 @@ private
-- 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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment