Commit 5d07d0cf 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_Id, Source_Data): use a real list to store sources rather than
	using an external table to store the elements. This makes code more
	efficient and more readable.

From-SVN: r146691
parent 5eed512d
2009-04-24 Emmanuel Briot <briot@adacore.com> 2009-04-24 Emmanuel Briot <briot@adacore.com>
* prj-proc.adb, prj.adb, prj.ads, prj-nmsc.adb, prj-env.adb * prj-proc.adb, prj.adb, prj.ads, prj-nmsc.adb, prj-env.adb
(Source_Id, Source_Data): use a real list to store sources rather than
using an external table to store the elements. This makes code more
efficient and more readable.
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. (Source_Iterator): new type.
This removes the need for having the sources on three different This removes the need for having the sources on three different
lists at the project tree, project and language level. They are now lists at the project tree, project and language level. They are now
......
...@@ -1050,7 +1050,6 @@ package body Prj.Env is ...@@ -1050,7 +1050,6 @@ package body Prj.Env is
-- will be set to True. -- will be set to True.
Source : Source_Id; Source : Source_Id;
Src_Data : Source_Data;
Suffix : File_Name_Type; Suffix : File_Name_Type;
The_Unit_Data : Unit_Data; The_Unit_Data : Unit_Data;
Data : File_Name_Data; Data : File_Name_Data;
...@@ -1207,22 +1206,20 @@ package body Prj.Env is ...@@ -1207,22 +1206,20 @@ package body Prj.Env is
Source := Prj.Element (Iter); Source := Prj.Element (Iter);
exit when Source = No_Source; exit when Source = No_Source;
Src_Data := In_Tree.Sources.Table (Source); if Source.Language.Name = Language
and then not Source.Locally_Removed
if In_Tree.Sources.Table (Source).Language.Name = Language and then Source.Replaced_By = No_Source
and then not Src_Data.Locally_Removed and then Source.Path.Name /= No_Path
and then Src_Data.Replaced_By = No_Source
and then Src_Data.Path.Name /= No_Path
then then
if Src_Data.Unit /= No_Name then if Source.Unit /= No_Name then
Get_Name_String (Src_Data.Unit); Get_Name_String (Source.Unit);
if Src_Data.Kind = Spec then if Source.Kind = Spec then
Suffix := Suffix :=
Src_Data.Language.Config.Mapping_Spec_Suffix; Source.Language.Config.Mapping_Spec_Suffix;
else else
Suffix := Suffix :=
Src_Data.Language.Config.Mapping_Body_Suffix; Source.Language.Config.Mapping_Body_Suffix;
end if; end if;
if Suffix /= No_File then if Suffix /= No_File then
...@@ -1232,10 +1229,10 @@ package body Prj.Env is ...@@ -1232,10 +1229,10 @@ package body Prj.Env is
Put_Name_Buffer; Put_Name_Buffer;
end if; end if;
Get_Name_String (Src_Data.File); Get_Name_String (Source.File);
Put_Name_Buffer; Put_Name_Buffer;
Get_Name_String (Src_Data.Path.Name); Get_Name_String (Source.Path.Name);
Put_Name_Buffer; Put_Name_Buffer;
end if; end if;
......
...@@ -301,7 +301,7 @@ package body Prj.Proc is ...@@ -301,7 +301,7 @@ package body Prj.Proc is
Source1 := Prj.Element (Iter); Source1 := Prj.Element (Iter);
exit when Source1 = No_Source; exit when Source1 = No_Source;
Name := In_Tree.Sources.Table (Source1).Unit; Name := Source1.Unit;
if Name /= No_Name then if Name /= No_Name then
Source2 := Unit_Htable.Get (Name); Source2 := Unit_Htable.Get (Name);
...@@ -311,8 +311,8 @@ package body Prj.Proc is ...@@ -311,8 +311,8 @@ package body Prj.Proc is
else else
Unit_Htable.Remove (Name); Unit_Htable.Remove (Name);
In_Tree.Sources.Table (Source1).Other_Part := Source2; Source1.Other_Part := Source2;
In_Tree.Sources.Table (Source2).Other_Part := Source1; Source2.Other_Part := Source1;
end if; end if;
end if; end if;
......
...@@ -153,7 +153,8 @@ package body Prj is ...@@ -153,7 +153,8 @@ package body Prj is
-- Free memory allocated for Project -- Free memory allocated for Project
procedure Free_List (Languages : in out Language_Ptr); procedure Free_List (Languages : in out Language_Ptr);
-- Free memory allocated for the list of languages procedure Free_List (Source : in out Source_Id);
-- Free memory allocated for the list of languages or sources
procedure Language_Changed (Iter : in out Source_Iterator); procedure Language_Changed (Iter : in out Source_Iterator);
procedure Project_Changed (Iter : in out Source_Iterator); procedure Project_Changed (Iter : in out Source_Iterator);
...@@ -480,7 +481,7 @@ package body Prj is ...@@ -480,7 +481,7 @@ package body Prj is
procedure Next (Iter : in out Source_Iterator) is procedure Next (Iter : in out Source_Iterator) is
begin begin
Iter.Current := Iter.In_Tree.Sources.Table (Iter.Current).Next_In_Lang; Iter.Current := Iter.Current.Next_In_Lang;
if Iter.Current = No_Source then if Iter.Current = No_Source then
Iter.Language := Iter.Language.Next; Iter.Language := Iter.Language.Next;
Language_Changed (Iter); Language_Changed (Iter);
...@@ -816,6 +817,22 @@ package body Prj is ...@@ -816,6 +817,22 @@ package body Prj is
-- Free_List -- -- Free_List --
--------------- ---------------
procedure Free_List (Source : in out Source_Id) is
procedure Unchecked_Free is new Ada.Unchecked_Deallocation
(Source_Data, Source_Id);
Tmp : Source_Id;
begin
while Source /= No_Source loop
Tmp := Source.Next_In_Lang;
Unchecked_Free (Source);
Source := Tmp;
end loop;
end Free_List;
---------------
-- Free_List --
---------------
procedure Free_List (Languages : in out Language_Ptr) is procedure Free_List (Languages : in out Language_Ptr) is
procedure Unchecked_Free is new Ada.Unchecked_Deallocation procedure Unchecked_Free is new Ada.Unchecked_Deallocation
(Language_Data, Language_Ptr); (Language_Data, Language_Ptr);
...@@ -823,6 +840,7 @@ package body Prj is ...@@ -823,6 +840,7 @@ package body Prj is
begin begin
while Languages /= null loop while Languages /= null loop
Tmp := Languages.Next; Tmp := Languages.Next;
Free_List (Languages.First_Source);
Unchecked_Free (Languages); Unchecked_Free (Languages);
Languages := Tmp; Languages := Tmp;
end loop; end loop;
...@@ -844,7 +862,6 @@ package body Prj is ...@@ -844,7 +862,6 @@ package body Prj is
Array_Table.Free (Tree.Arrays); Array_Table.Free (Tree.Arrays);
Package_Table.Free (Tree.Packages); Package_Table.Free (Tree.Packages);
Project_List_Table.Free (Tree.Project_Lists); Project_List_Table.Free (Tree.Project_Lists);
Source_Data_Table.Free (Tree.Sources);
Alternate_Language_Table.Free (Tree.Alt_Langs); Alternate_Language_Table.Free (Tree.Alt_Langs);
Unit_Table.Free (Tree.Units); Unit_Table.Free (Tree.Units);
Units_Htable.Reset (Tree.Units_HT); Units_Htable.Reset (Tree.Units_HT);
...@@ -892,7 +909,6 @@ package body Prj is ...@@ -892,7 +909,6 @@ package body Prj is
Array_Table.Init (Tree.Arrays); Array_Table.Init (Tree.Arrays);
Package_Table.Init (Tree.Packages); Package_Table.Init (Tree.Packages);
Project_List_Table.Init (Tree.Project_Lists); Project_List_Table.Init (Tree.Project_Lists);
Source_Data_Table.Init (Tree.Sources);
Alternate_Language_Table.Init (Tree.Alt_Langs); Alternate_Language_Table.Init (Tree.Alt_Langs);
Unit_Table.Init (Tree.Units); Unit_Table.Init (Tree.Units);
Units_Htable.Reset (Tree.Units_HT); Units_Htable.Reset (Tree.Units_HT);
......
...@@ -398,9 +398,10 @@ package Prj is ...@@ -398,9 +398,10 @@ package Prj is
Spec_Suffix => No_File, Spec_Suffix => No_File,
Body_Suffix => No_File); Body_Suffix => No_File);
type Source_Id is new Nat; type Source_Data;
type Source_Id is access Source_Data;
No_Source : constant Source_Id := 0; No_Source : constant Source_Id := null;
type Path_Syntax_Kind is type Path_Syntax_Kind is
(Canonical, (Canonical,
...@@ -629,7 +630,7 @@ package Prj is ...@@ -629,7 +630,7 @@ package Prj is
Language : Language_Ptr := No_Language_Index; Language : Language_Ptr := No_Language_Index;
-- Index of the language. This is an index into -- Index of the language. This is an index into
-- project_tree.languages_data -- Project_Tree.Languages_Data.
Lang_Kind : Language_Kind := File_Based; Lang_Kind : Language_Kind := File_Based;
-- Kind of the language -- Kind of the language
...@@ -645,8 +646,8 @@ package Prj is ...@@ -645,8 +646,8 @@ package Prj is
-- True when source is declared in attribute Interfaces -- True when source is declared in attribute Interfaces
Alternate_Languages : Alternate_Language_Id := No_Alternate_Language; Alternate_Languages : Alternate_Language_Id := No_Alternate_Language;
-- List of languages a header file may also be, in addition of -- List of languages a header file may also be, in addition of language
-- language Language_Name. -- Language_Name.
Kind : Source_Kind := Spec; Kind : Source_Kind := Spec;
-- Kind of the source: spec, body or subunit -- Kind of the source: spec, body or subunit
...@@ -775,14 +776,6 @@ package Prj is ...@@ -775,14 +776,6 @@ package Prj is
Naming_Exception => False, Naming_Exception => False,
Next_In_Lang => No_Source); Next_In_Lang => No_Source);
package Source_Data_Table is new GNAT.Dynamic_Tables
(Table_Component_Type => Source_Data,
Table_Index_Type => Source_Id,
Table_Low_Bound => 1,
Table_Initial => 1000,
Table_Increment => 100);
-- The table for the sources
package Source_Paths_Htable is new Simple_HTable package Source_Paths_Htable is new Simple_HTable
(Header_Num => Header_Num, (Header_Num => Header_Num,
Element => Source_Id, Element => Source_Id,
...@@ -1452,7 +1445,6 @@ package Prj is ...@@ -1452,7 +1445,6 @@ package Prj is
Packages : Package_Table.Instance; Packages : Package_Table.Instance;
Project_Lists : Project_List_Table.Instance; Project_Lists : Project_List_Table.Instance;
Projects : Project_Table.Instance; Projects : Project_Table.Instance;
Sources : Source_Data_Table.Instance;
Alt_Langs : Alternate_Language_Table.Instance; Alt_Langs : Alternate_Language_Table.Instance;
Units : Unit_Table.Instance; Units : Unit_Table.Instance;
Units_HT : Units_Htable.Instance; Units_HT : Units_Htable.Instance;
......
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