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;
......
...@@ -578,8 +578,7 @@ package body Prj.Nmsc is ...@@ -578,8 +578,7 @@ package body Prj.Nmsc is
procedure Remove_Source procedure Remove_Source
(Id : Source_Id; (Id : Source_Id;
Replaced_By : Source_Id; Replaced_By : Source_Id);
In_Tree : Project_Tree_Ref);
-- ??? needs comment -- ??? needs comment
procedure Report_No_Sources procedure Report_No_Sources
...@@ -698,19 +697,13 @@ package body Prj.Nmsc is ...@@ -698,19 +697,13 @@ package body Prj.Nmsc is
Index : Int := 0; Index : Int := 0;
Source_To_Replace : Source_Id := No_Source) Source_To_Replace : Source_Id := No_Source)
is is
Src_Data : Source_Data := No_Source_Data;
Config : constant Language_Config := Lang_Id.Config; Config : constant Language_Config := Lang_Id.Config;
begin begin
-- This is a new source so create an entry for it in the Sources table Id := new Source_Data;
Source_Data_Table.Increment_Last (In_Tree.Sources);
Id := Source_Data_Table.Last (In_Tree.Sources);
if Current_Verbosity = High then if Current_Verbosity = High then
Write_Str ("Adding source #"); Write_Str ("Adding source File: ");
Write_Str (Id'Img);
Write_Str (", File : ");
Write_Str (Get_Name_String (File_Name)); Write_Str (Get_Name_String (File_Name));
if Lang_Kind = Unit_Based then if Lang_Kind = Unit_Based then
...@@ -727,39 +720,37 @@ package body Prj.Nmsc is ...@@ -727,39 +720,37 @@ package body Prj.Nmsc is
Write_Eol; Write_Eol;
end if; end if;
Src_Data.Project := Project; Id.Project := Project;
Src_Data.Language := Lang_Id; Id.Language := Lang_Id;
Src_Data.Lang_Kind := Lang_Kind; Id.Lang_Kind := Lang_Kind;
Src_Data.Compiled := Id.Compiled :=
Lang_Id.Config.Compiler_Driver /= Empty_File_Name; Lang_Id.Config.Compiler_Driver /= Empty_File_Name;
Src_Data.Kind := Kind; Id.Kind := Kind;
Src_Data.Alternate_Languages := Alternate_Languages; Id.Alternate_Languages := Alternate_Languages;
Src_Data.Other_Part := Other_Part; Id.Other_Part := Other_Part;
Src_Data.Object_Exists := Config.Object_Generated; Id.Object_Exists := Config.Object_Generated;
Src_Data.Object_Linked := Config.Objects_Linked; Id.Object_Linked := Config.Objects_Linked;
if Other_Part /= No_Source then if Other_Part /= No_Source then
In_Tree.Sources.Table (Other_Part).Other_Part := Id; Other_Part.Other_Part := Id;
end if; end if;
Src_Data.Unit := Unit; Id.Unit := Unit;
Src_Data.Index := Index; Id.Index := Index;
Src_Data.File := File_Name; Id.File := File_Name;
Src_Data.Display_File := Display_File; Id.Display_File := Display_File;
Src_Data.Dependency := Lang_Id.Config.Dependency_Kind; Id.Dependency := Lang_Id.Config.Dependency_Kind;
Src_Data.Dep_Name := Dependency_Name Id.Dep_Name := Dependency_Name (File_Name, Id.Dependency);
(File_Name, Src_Data.Dependency); Id.Naming_Exception := Naming_Exception;
Src_Data.Naming_Exception := Naming_Exception;
if Src_Data.Compiled and then Src_Data.Object_Exists then if Id.Compiled and then Id.Object_Exists then
Src_Data.Object := Id.Object := Object_Name (File_Name, Config.Object_File_Suffix);
Object_Name (File_Name, Config.Object_File_Suffix); Id.Switches := Switches_Name (File_Name);
Src_Data.Switches := Switches_Name (File_Name);
end if; end if;
if Path /= No_Path then if Path /= No_Path then
Src_Data.Path := (Path, Display_Path); Id.Path := (Path, Display_Path);
Source_Paths_Htable.Set (In_Tree.Source_Paths_HT, Path, Id); Source_Paths_Htable.Set (In_Tree.Source_Paths_HT, Path, Id);
end if; end if;
...@@ -772,13 +763,11 @@ package body Prj.Nmsc is ...@@ -772,13 +763,11 @@ package body Prj.Nmsc is
-- Add the source to the language list -- Add the source to the language list
Src_Data.Next_In_Lang := Lang_Id.First_Source; Id.Next_In_Lang := Lang_Id.First_Source;
Lang_Id.First_Source := Id; Lang_Id.First_Source := Id;
In_Tree.Sources.Table (Id) := Src_Data;
if Source_To_Replace /= No_Source then if Source_To_Replace /= No_Source then
Remove_Source (Source_To_Replace, Id, In_Tree); Remove_Source (Source_To_Replace, Id);
end if; end if;
end Add_Source; end Add_Source;
...@@ -926,26 +915,18 @@ package body Prj.Nmsc is ...@@ -926,26 +915,18 @@ package body Prj.Nmsc is
Project => Project); Project => Project);
Source_Loop : loop Source_Loop : loop
Source := Element (Iter); Source := Element (Iter);
exit Source_Loop when Source = No_Source; exit Source_Loop when Source = No_Source
or else Source.Language = Language;
declare
Src_Data : Source_Data renames
In_Tree.Sources.Table (Source);
begin
exit Source_Loop when Src_Data.Language = Language;
Alt_Lang := Src_Data.Alternate_Languages; Alt_Lang := Source.Alternate_Languages;
Alternate_Loop : Alternate_Loop :
while Alt_Lang /= No_Alternate_Language loop while Alt_Lang /= No_Alternate_Language loop
Alt_Lang_Data := Alt_Lang_Data := In_Tree.Alt_Langs.Table (Alt_Lang);
In_Tree.Alt_Langs.Table (Alt_Lang);
exit Source_Loop exit Source_Loop
when Alt_Lang_Data.Language = Language; when Alt_Lang_Data.Language = Language;
Alt_Lang := Alt_Lang_Data.Next; Alt_Lang := Alt_Lang_Data.Next;
end loop Alternate_Loop; end loop Alternate_Loop;
end;
Next (Iter); Next (Iter);
end loop Source_Loop; end loop Source_Loop;
...@@ -2554,7 +2535,7 @@ package body Prj.Nmsc is ...@@ -2554,7 +2535,7 @@ package body Prj.Nmsc is
loop loop
Source := Prj.Element (Iter); Source := Prj.Element (Iter);
exit when Source = No_Source; exit when Source = No_Source;
In_Tree.Sources.Table (Source).In_Interfaces := False; Source.In_Interfaces := False;
Next (Iter); Next (Iter);
end loop; end loop;
...@@ -2575,28 +2556,19 @@ package body Prj.Nmsc is ...@@ -2575,28 +2556,19 @@ package body Prj.Nmsc is
Source := Prj.Element (Iter); Source := Prj.Element (Iter);
exit when Source = No_Source; exit when Source = No_Source;
declare if Source.File = Name then
Src_Data : Source_Data renames if not Source.Locally_Removed then
In_Tree.Sources.Table (Source); Source.In_Interfaces := True;
Source.Declared_In_Interfaces := True;
begin
if Src_Data.File = Name then
if not Src_Data.Locally_Removed then
Src_Data.In_Interfaces := True;
Src_Data.Declared_In_Interfaces := True;
if Src_Data.Other_Part /= No_Source then if Source.Other_Part /= No_Source then
In_Tree.Sources.Table Source.Other_Part.In_Interfaces := True;
(Src_Data.Other_Part).In_Interfaces := True; Source.Other_Part.Declared_In_Interfaces := True;
In_Tree.Sources.Table
(Src_Data.Other_Part).Declared_In_Interfaces :=
True;
end if; end if;
if Current_Verbosity = High then if Current_Verbosity = High then
Write_Str (" interface: "); Write_Str (" interface: ");
Write_Line Write_Line (Get_Name_String (Source.Path.Name));
(Get_Name_String (Src_Data.Path.Name));
end if; end if;
end if; end if;
...@@ -2604,7 +2576,6 @@ package body Prj.Nmsc is ...@@ -2604,7 +2576,6 @@ package body Prj.Nmsc is
end if; end if;
Next (Iter); Next (Iter);
end;
end loop; end loop;
Project_2 := In_Tree.Projects.Table (Project_2).Extends; Project_2 := In_Tree.Projects.Table (Project_2).Extends;
...@@ -2637,15 +2608,9 @@ package body Prj.Nmsc is ...@@ -2637,15 +2608,9 @@ package body Prj.Nmsc is
Source := Prj.Element (Iter); Source := Prj.Element (Iter);
exit when Source = No_Source; exit when Source = No_Source;
declare if not Source.Declared_In_Interfaces then
Src_Data : Source_Data renames Source.In_Interfaces := False;
In_Tree.Sources.Table (Source);
begin
if not Src_Data.Declared_In_Interfaces then
Src_Data.In_Interfaces := False;
end if; end if;
end;
Next (Iter); Next (Iter);
end loop; end loop;
...@@ -2933,8 +2898,7 @@ package body Prj.Nmsc is ...@@ -2933,8 +2898,7 @@ package body Prj.Nmsc is
Iter := For_Each_Source (In_Tree, Project); Iter := For_Each_Source (In_Tree, Project);
loop loop
Source := Prj.Element (Iter); Source := Prj.Element (Iter);
exit when Source = No_Source exit when Source = No_Source or else Source.File = File_Name;
or else In_Tree.Sources.Table (Source).File = File_Name;
Next (Iter); Next (Iter);
end loop; end loop;
...@@ -2954,14 +2918,14 @@ package body Prj.Nmsc is ...@@ -2954,14 +2918,14 @@ package body Prj.Nmsc is
-- Check if the file name is already recorded for another -- Check if the file name is already recorded for another
-- language or another kind. -- language or another kind.
if In_Tree.Sources.Table (Source).Language /= Lang_Id then if Source.Language /= Lang_Id then
Error_Msg Error_Msg
(Project, (Project,
In_Tree, In_Tree,
"the same file cannot be a source of two languages", "the same file cannot be a source of two languages",
Element.Location); Element.Location);
elsif In_Tree.Sources.Table (Source).Kind /= Kind then elsif Source.Kind /= Kind then
Error_Msg Error_Msg
(Project, (Project,
In_Tree, In_Tree,
...@@ -3065,14 +3029,12 @@ package body Prj.Nmsc is ...@@ -3065,14 +3029,12 @@ package body Prj.Nmsc is
loop loop
Source := Prj.Element (Iter); Source := Prj.Element (Iter);
exit when Source = No_Source exit when Source = No_Source
or else or else (Source.Unit = Unit and then Source.Index = Index);
(In_Tree.Sources.Table (Source).Unit = Unit and then
In_Tree.Sources.Table (Source).Index = Index);
Next (Iter); Next (Iter);
end loop; end loop;
if Source /= No_Source then if Source /= No_Source then
if In_Tree.Sources.Table (Source).Kind /= Kind then if Source.Kind /= Kind then
Other_Part := Source; Other_Part := Source;
loop loop
...@@ -3080,18 +3042,15 @@ package body Prj.Nmsc is ...@@ -3080,18 +3042,15 @@ package body Prj.Nmsc is
Source := Prj.Element (Iter); Source := Prj.Element (Iter);
exit when Source = No_Source or else exit when Source = No_Source or else
(In_Tree.Sources.Table (Source).Unit = Unit (Source.Unit = Unit and then Source.Index = Index);
and then
In_Tree.Sources.Table (Source).Index = Index);
end loop; end loop;
end if; end if;
if Source /= No_Source then if Source /= No_Source then
Other_Project := In_Tree.Sources.Table (Source).Project; Other_Project := Source.Project;
if Is_Extending (Project, Other_Project, In_Tree) then if Is_Extending (Project, Other_Project, In_Tree) then
Other_Part := Other_Part := Source.Other_Part;
In_Tree.Sources.Table (Source).Other_Part;
-- Record the source to be removed -- Record the source to be removed
...@@ -3481,14 +3440,9 @@ package body Prj.Nmsc is ...@@ -3481,14 +3440,9 @@ package body Prj.Nmsc is
Iter := For_Each_Source (In_Tree, Proj); Iter := For_Each_Source (In_Tree, Proj);
loop loop
Src_Id := Prj.Element (Iter); Src_Id := Prj.Element (Iter);
exit when Src_Id = No_Source; exit when Src_Id = No_Source
or else Src_Id.Lang_Kind /= File_Based
declare or else Src_Id.Kind /= Spec;
Src : Source_Data renames In_Tree.Sources.Table (Src_Id);
begin
exit when Src.Lang_Kind /= File_Based
or else Src.Kind /= Spec;
end;
Next (Iter); Next (Iter);
end loop; end loop;
...@@ -4386,8 +4340,8 @@ package body Prj.Nmsc is ...@@ -4386,8 +4340,8 @@ package body Prj.Nmsc is
Prj.Util.Value_Of Prj.Util.Value_Of
(Name_Default_Language, Data.Decl.Attributes, In_Tree); (Name_Default_Language, Data.Decl.Attributes, In_Tree);
-- ??? Shouldn't these be set to False by default, and only set to True -- Shouldn't these be set to False by default, and only set to True when
-- when we actually find some source file ? -- we actually find some source file???
Data.Ada_Sources_Present := Data.Source_Dirs /= Nil_String; Data.Ada_Sources_Present := Data.Source_Dirs /= Nil_String;
Data.Other_Sources_Present := Data.Source_Dirs /= Nil_String; Data.Other_Sources_Present := Data.Source_Dirs /= Nil_String;
...@@ -4440,7 +4394,7 @@ package body Prj.Nmsc is ...@@ -4440,7 +4394,7 @@ package body Prj.Nmsc is
-- Attribute Languages is not specified. So, it defaults to -- Attribute Languages is not specified. So, it defaults to
-- a project of language Ada only. No sources of languages -- a project of language Ada only. No sources of languages
-- other than Ada -- other than Ada.
Data.Other_Sources_Present := False; Data.Other_Sources_Present := False;
...@@ -4458,7 +4412,7 @@ package body Prj.Nmsc is ...@@ -4458,7 +4412,7 @@ package body Prj.Nmsc is
NL_Id : Language_Ptr; NL_Id : Language_Ptr;
begin begin
-- Assume there are no language declared -- Assume there are no languages declared
Data.Ada_Sources_Present := False; Data.Ada_Sources_Present := False;
Data.Other_Sources_Present := False; Data.Other_Sources_Present := False;
...@@ -4487,7 +4441,8 @@ package body Prj.Nmsc is ...@@ -4487,7 +4441,8 @@ package body Prj.Nmsc is
Lang_Name := Name_Find; Lang_Name := Name_Find;
-- If the language was not already specified (duplicates -- If the language was not already specified (duplicates
-- are simply ignored) -- are simply ignored).
NL_Id := Data.Languages; NL_Id := Data.Languages;
while NL_Id /= No_Language_Index loop while NL_Id /= No_Language_Index loop
exit when Lang_Name = NL_Id.Name; exit when Lang_Name = NL_Id.Name;
...@@ -4496,6 +4451,7 @@ package body Prj.Nmsc is ...@@ -4496,6 +4451,7 @@ package body Prj.Nmsc is
if NL_Id = No_Language_Index then if NL_Id = No_Language_Index then
if Get_Mode = Ada_Only then if Get_Mode = Ada_Only then
-- Check for language Ada -- Check for language Ada
if Lang_Name = Name_Ada then if Lang_Name = Name_Ada then
...@@ -4514,6 +4470,7 @@ package body Prj.Nmsc is ...@@ -4514,6 +4470,7 @@ package body Prj.Nmsc is
if Lang_Name = Name_Ada then if Lang_Name = Name_Ada then
Index.Config.Kind := Unit_Based; Index.Config.Kind := Unit_Based;
Index.Config.Dependency_Kind := ALI_File; Index.Config.Dependency_Kind := ALI_File;
else else
Index.Config.Kind := File_Based; Index.Config.Kind := File_Based;
Index.Config.Dependency_Kind := None; Index.Config.Dependency_Kind := None;
...@@ -4734,8 +4691,8 @@ package body Prj.Nmsc is ...@@ -4734,8 +4691,8 @@ package body Prj.Nmsc is
Project, In_Tree, Extending) Project, In_Tree, Extending)
then then
-- There is a body for this unit. -- There is a body for this unit.
-- If there is no spec, we need to check -- If there is no spec, we need to check that it
-- that it is not a subunit. -- is not a subunit.
if The_Unit_Data.File_Names if The_Unit_Data.File_Names
(Specification).Name = No_File (Specification).Name = No_File
...@@ -4763,9 +4720,8 @@ package body Prj.Nmsc is ...@@ -4763,9 +4720,8 @@ package body Prj.Nmsc is
end; end;
end if; end if;
-- The unit is not a subunit, so we add -- The unit is not a subunit, so we add the
-- to the Interface ALIs the ALI file -- ALI file for its body to the Interface ALIs.
-- corresponding to the body.
Add_ALI_For Add_ALI_For
(The_Unit_Data.File_Names (Body_Part).Name); (The_Unit_Data.File_Names (Body_Part).Name);
...@@ -4788,9 +4744,9 @@ package body Prj.Nmsc is ...@@ -4788,9 +4744,9 @@ package body Prj.Nmsc is
Project, In_Tree, Extending) Project, In_Tree, Extending)
then then
-- The unit is part of the project, it has -- The unit is part of the project, it has a spec,
-- a spec, but no body. We add to the Interface -- but no body. We add the ALI for its spec to the
-- ALIs the ALI file corresponding to the spec. -- Interface ALIs.
Add_ALI_For Add_ALI_For
(The_Unit_Data.File_Names (Specification).Name); (The_Unit_Data.File_Names (Specification).Name);
...@@ -4813,8 +4769,7 @@ package body Prj.Nmsc is ...@@ -4813,8 +4769,7 @@ package body Prj.Nmsc is
loop loop
while Prj.Element (Iter) /= No_Source and then while Prj.Element (Iter) /= No_Source and then
In_Tree.Sources.Table (Prj.Element (Iter)).Unit /= Prj.Element (Iter).Unit /= Unit
Unit
loop loop
Next (Iter); Next (Iter);
end loop; end loop;
...@@ -4829,25 +4784,20 @@ package body Prj.Nmsc is ...@@ -4829,25 +4784,20 @@ package body Prj.Nmsc is
end loop; end loop;
if Source /= No_Source then if Source /= No_Source then
if In_Tree.Sources.Table (Source).Kind = Sep then if Source.Kind = Sep then
Source := No_Source; Source := No_Source;
elsif In_Tree.Sources.Table (Source).Kind = Spec elsif Source.Kind = Spec
and then and then Source.Other_Part /= No_Source
In_Tree.Sources.Table (Source).Other_Part /=
No_Source
then then
Source := In_Tree.Sources.Table (Source).Other_Part; Source := Source.Other_Part;
end if; end if;
end if; end if;
if Source /= No_Source then if Source /= No_Source then
if In_Tree.Sources.Table (Source).Project /= Project if Source.Project /= Project
and then and then
not Is_Extending not Is_Extending (Project, Source.Project, In_Tree)
(Project,
In_Tree.Sources.Table (Source).Project,
In_Tree)
then then
Source := No_Source; Source := No_Source;
end if; end if;
...@@ -4861,11 +4811,10 @@ package body Prj.Nmsc is ...@@ -4861,11 +4811,10 @@ package body Prj.Nmsc is
(Interfaces).Location); (Interfaces).Location);
else else
if In_Tree.Sources.Table (Source).Kind = Spec and then if Source.Kind = Spec and then
In_Tree.Sources.Table (Source).Other_Part /= Source.Other_Part /= No_Source
No_Source
then then
Source := In_Tree.Sources.Table (Source).Other_Part; Source := Source.Other_Part;
end if; end if;
String_Element_Table.Increment_Last String_Element_Table.Increment_Last
...@@ -4873,11 +4822,9 @@ package body Prj.Nmsc is ...@@ -4873,11 +4822,9 @@ package body Prj.Nmsc is
In_Tree.String_Elements.Table In_Tree.String_Elements.Table
(String_Element_Table.Last (String_Element_Table.Last
(In_Tree.String_Elements)) := (In_Tree.String_Elements)) :=
(Value => (Value => Name_Id (Source.Dep_Name),
Name_Id (In_Tree.Sources.Table (Source).Dep_Name),
Index => 0, Index => 0,
Display_Value => Display_Value => Name_Id (Source.Dep_Name),
Name_Id (In_Tree.Sources.Table (Source).Dep_Name),
Location => Location =>
In_Tree.String_Elements.Table In_Tree.String_Elements.Table
(Interfaces).Location, (Interfaces).Location,
...@@ -4922,7 +4869,7 @@ package body Prj.Nmsc is ...@@ -4922,7 +4869,7 @@ package body Prj.Nmsc is
else else
-- Library_Auto_Init cannot be "true" if auto init is not -- Library_Auto_Init cannot be "true" if auto init is not
-- supported -- supported.
Error_Msg Error_Msg
(Project, In_Tree, (Project, In_Tree,
...@@ -7291,26 +7238,20 @@ package body Prj.Nmsc is ...@@ -7291,26 +7238,20 @@ package body Prj.Nmsc is
Source := Prj.Element (Iter); Source := Prj.Element (Iter);
exit when Source = No_Source; exit when Source = No_Source;
declare if Source.Naming_Exception
Src_Data : Source_Data renames and then Source.Path = No_Path_Information
In_Tree.Sources.Table (Source);
begin
if Src_Data.Naming_Exception
and then Src_Data.Path = No_Path_Information
then then
if Src_Data.Unit /= No_Name then if Source.Unit /= No_Name then
Error_Msg_Name_1 := Name_Id (Src_Data.Display_File); Error_Msg_Name_1 := Name_Id (Source.Display_File);
Error_Msg_Name_2 := Name_Id (Src_Data.Unit); Error_Msg_Name_2 := Name_Id (Source.Unit);
Error_Msg Error_Msg
(Project, In_Tree, (Project, In_Tree,
"source file %% for unit %% not found", "source file %% for unit %% not found",
No_Location); No_Location);
end if; end if;
Remove_Source (Source, No_Source, In_Tree); Remove_Source (Source, No_Source);
end if; end if;
end;
Next (Iter); Next (Iter);
end loop; end loop;
...@@ -7704,8 +7645,7 @@ package body Prj.Nmsc is ...@@ -7704,8 +7645,7 @@ package body Prj.Nmsc is
Check_Name := True; Check_Name := True;
else else
In_Tree.Sources.Table (Name_Loc.Source).Path := Name_Loc.Source.Path := (Path_Id, Display_Path_Id);
(Path_Id, Display_Path_Id);
Source_Paths_Htable.Set Source_Paths_Htable.Set
(In_Tree.Source_Paths_HT, (In_Tree.Source_Paths_HT,
...@@ -7714,15 +7654,14 @@ package body Prj.Nmsc is ...@@ -7714,15 +7654,14 @@ package body Prj.Nmsc is
-- Check if this is a subunit -- Check if this is a subunit
if In_Tree.Sources.Table (Name_Loc.Source).Unit /= No_Name if Name_Loc.Source.Unit /= No_Name
and then and then Name_Loc.Source.Kind = Impl
In_Tree.Sources.Table (Name_Loc.Source).Kind = Impl
then then
Src_Ind := Sinput.P.Load_Project_File Src_Ind := Sinput.P.Load_Project_File
(Get_Name_String (Path_Id)); (Get_Name_String (Path_Id));
if Sinput.P.Source_File_Is_Subunit (Src_Ind) then if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
In_Tree.Sources.Table (Name_Loc.Source).Kind := Sep; Name_Loc.Source.Kind := Sep;
end if; end if;
end if; end if;
end if; end if;
...@@ -7766,35 +7705,30 @@ package body Prj.Nmsc is ...@@ -7766,35 +7705,30 @@ package body Prj.Nmsc is
Source := Prj.Element (Iter); Source := Prj.Element (Iter);
exit when Source = No_Source; exit when Source = No_Source;
declare
Src_Data : Source_Data renames
In_Tree.Sources.Table (Source);
begin
if Unit /= No_Name if Unit /= No_Name
and then Src_Data.Unit = Unit and then Source.Unit = Unit
and then and then
((Src_Data.Kind = Spec and then Kind = Impl) ((Source.Kind = Spec and then Kind = Impl)
or else or else
(Src_Data.Kind = Impl and then Kind = Spec)) (Source.Kind = Impl and then Kind = Spec))
then then
Other_Part := Source; Other_Part := Source;
elsif (Unit /= No_Name elsif (Unit /= No_Name
and then Src_Data.Unit = Unit and then Source.Unit = Unit
and then and then
(Src_Data.Kind = Kind (Source.Kind = Kind
or else or else
(Src_Data.Kind = Sep and then Kind = Impl) (Source.Kind = Sep and then Kind = Impl)
or else or else
(Src_Data.Kind = Impl and then Kind = Sep))) (Source.Kind = Impl and then Kind = Sep)))
or else or else
(Unit = No_Name and then Src_Data.File = File_Name) (Unit = No_Name and then Source.File = File_Name)
then then
-- Duplication of file/unit in same project is only -- Duplication of file/unit in same project is only
-- allowed if order of source directories is known. -- allowed if order of source directories is known.
if Project = Src_Data.Project then if Project = Source.Project then
if Data.Known_Order_Of_Source_Dirs then if Data.Known_Order_Of_Source_Dirs then
Add_Src := False; Add_Src := False;
...@@ -7822,12 +7756,12 @@ package body Prj.Nmsc is ...@@ -7822,12 +7756,12 @@ package body Prj.Nmsc is
-- unrelated projects. -- unrelated projects.
elsif Is_Extending elsif Is_Extending
(Project, Src_Data.Project, In_Tree) (Project, Source.Project, In_Tree)
then then
Source_To_Replace := Source; Source_To_Replace := Source;
elsif Unit /= No_Name elsif Unit /= No_Name
and then not Src_Data.Locally_Removed and then not Source.Locally_Removed
then then
Error_Msg_Name_1 := Unit; Error_Msg_Name_1 := Unit;
Error_Msg Error_Msg
...@@ -7842,9 +7776,8 @@ package body Prj.Nmsc is ...@@ -7842,9 +7776,8 @@ package body Prj.Nmsc is
(Project, In_Tree, "\ project %%, %%", No_Location); (Project, In_Tree, "\ project %%, %%", No_Location);
Error_Msg_Name_1 := Error_Msg_Name_1 :=
In_Tree.Projects.Table (Src_Data.Project).Name; In_Tree.Projects.Table (Source.Project).Name;
Error_Msg_Name_2 := Error_Msg_Name_2 := Name_Id (Source.Path.Display_Name);
Name_Id (Src_Data.Path.Display_Name);
Error_Msg Error_Msg
(Project, In_Tree, "\ project %%, %%", No_Location); (Project, In_Tree, "\ project %%, %%", No_Location);
...@@ -7852,7 +7785,6 @@ package body Prj.Nmsc is ...@@ -7852,7 +7785,6 @@ package body Prj.Nmsc is
end if; end if;
end if; end if;
end;
Next (Iter); Next (Iter);
end loop; end loop;
...@@ -8016,8 +7948,6 @@ package body Prj.Nmsc is ...@@ -8016,8 +7948,6 @@ package body Prj.Nmsc is
In_Tree : Project_Tree_Ref) In_Tree : Project_Tree_Ref)
is is
Source : Source_Id; Source : Source_Id;
File : File_Name_Type;
Unit : Name_Id;
Iter : Source_Iterator; Iter : Source_Iterator;
begin begin
...@@ -8028,13 +7958,10 @@ package body Prj.Nmsc is ...@@ -8028,13 +7958,10 @@ package body Prj.Nmsc is
Source := Prj.Element (Iter); Source := Prj.Element (Iter);
exit when Source = No_Source; exit when Source = No_Source;
File := In_Tree.Sources.Table (Source).File;
Unit := In_Tree.Sources.Table (Source).Unit;
-- An excluded file cannot also be an exception file name -- An excluded file cannot also be an exception file name
if Excluded_Sources_Htable.Get (File) /= No_File_Found then if Excluded_Sources_Htable.Get (Source.File) /= No_File_Found then
Error_Msg_File_1 := File; Error_Msg_File_1 := Source.File;
Error_Msg Error_Msg
(Project, In_Tree, (Project, In_Tree,
"{ cannot be both excluded and an exception file name", "{ cannot be both excluded and an exception file name",
...@@ -8042,38 +7969,37 @@ package body Prj.Nmsc is ...@@ -8042,38 +7969,37 @@ package body Prj.Nmsc is
end if; end if;
if Current_Verbosity = High then if Current_Verbosity = High then
Write_Str ("Naming exception: Putting source #"); Write_Str ("Naming exception: Putting source file ");
Write_Str (Source'Img); Write_Str (Get_Name_String (Source.File));
Write_Str (", file ");
Write_Str (Get_Name_String (File));
Write_Line (" in Source_Names"); Write_Line (" in Source_Names");
end if; end if;
Source_Names.Set Source_Names.Set
(K => File, (K => Source.File,
E => Name_Location' E => Name_Location'
(Name => File, (Name => Source.File,
Location => No_Location, Location => No_Location,
Source => Source, Source => Source,
Except => Unit /= No_Name, Except => Source.Unit /= No_Name,
Found => False)); Found => False));
-- If this is an Ada exception, record in table Unit_Exceptions -- If this is an Ada exception, record in table Unit_Exceptions
if Unit /= No_Name then if Source.Unit /= No_Name then
declare declare
Unit_Except : Unit_Exception := Unit_Exceptions.Get (Unit); Unit_Except : Unit_Exception :=
Unit_Exceptions.Get (Source.Unit);
begin begin
Unit_Except.Name := Unit; Unit_Except.Name := Source.Unit;
if In_Tree.Sources.Table (Source).Kind = Spec then if Source.Kind = Spec then
Unit_Except.Spec := File; Unit_Except.Spec := Source.File;
else else
Unit_Except.Impl := File; Unit_Except.Impl := Source.File;
end if; end if;
Unit_Exceptions.Set (Unit, Unit_Except); Unit_Exceptions.Set (Source.Unit, Unit_Except);
end; end;
end if; end if;
...@@ -8140,8 +8066,8 @@ package body Prj.Nmsc is ...@@ -8140,8 +8066,8 @@ package body Prj.Nmsc is
end if; end if;
if Source /= No_Source then if Source /= No_Source then
In_Tree.Sources.Table (Source).Locally_Removed := True; Source.Locally_Removed := True;
In_Tree.Sources.Table (Source).In_Interfaces := False; Source.In_Interfaces := False;
end if; end if;
if Current_Verbosity = High then if Current_Verbosity = High then
...@@ -8193,10 +8119,8 @@ package body Prj.Nmsc is ...@@ -8193,10 +8119,8 @@ package body Prj.Nmsc is
Source := Prj.Element (Iter); Source := Prj.Element (Iter);
exit when Source = No_Source; exit when Source = No_Source;
if In_Tree.Sources.Table (Source).File = Excluded.File then if Source.File = Excluded.File then
Exclude Exclude (Source.Project, No_Unit_Index, Specification);
(In_Tree.Sources.Table (Source).Project,
No_Unit_Index, Specification);
exit; exit;
end if; end if;
...@@ -8230,7 +8154,7 @@ package body Prj.Nmsc is ...@@ -8230,7 +8154,7 @@ package body Prj.Nmsc is
Src_Id : Source_Id; Src_Id : Source_Id;
Source_Name : File_Name_Type; Source_Name : File_Name_Type;
procedure Check_Object (Src_Data : Source_Data); procedure Check_Object (Src : Source_Id);
-- Check if object file name of the current source is already in -- Check if object file name of the current source is already in
-- hash table Object_File_Names. If it is, report an error. If it -- hash table Object_File_Names. If it is, report an error. If it
-- is not, put it there with the file name of the current source. -- is not, put it there with the file name of the current source.
...@@ -8239,12 +8163,12 @@ package body Prj.Nmsc is ...@@ -8239,12 +8163,12 @@ package body Prj.Nmsc is
-- Check_Object -- -- Check_Object --
------------------ ------------------
procedure Check_Object (Src_Data : Source_Data) is procedure Check_Object (Src : Source_Id) is
begin begin
Source_Name := Object_File_Names.Get (Src_Data.Object); Source_Name := Object_File_Names.Get (Src.Object);
if Source_Name /= No_File then if Source_Name /= No_File then
Error_Msg_File_1 := Src_Data.File; Error_Msg_File_1 := Src.File;
Error_Msg_File_2 := Source_Name; Error_Msg_File_2 := Source_Name;
Error_Msg Error_Msg
(Project, (Project,
...@@ -8253,7 +8177,7 @@ package body Prj.Nmsc is ...@@ -8253,7 +8177,7 @@ package body Prj.Nmsc is
No_Location); No_Location);
else else
Object_File_Names.Set (Src_Data.Object, Src_Data.File); Object_File_Names.Set (Src.Object, Src.File);
end if; end if;
end Check_Object; end Check_Object;
...@@ -8266,32 +8190,27 @@ package body Prj.Nmsc is ...@@ -8266,32 +8190,27 @@ package body Prj.Nmsc is
Src_Id := Prj.Element (Iter); Src_Id := Prj.Element (Iter);
exit when Src_Id = No_Source; exit when Src_Id = No_Source;
declare if Src_Id.Compiled and then Src_Id.Object_Exists
Src_Data : Source_Data renames and then Is_Extending (Project, Src_Id.Project, In_Tree)
In_Tree.Sources.Table (Src_Id);
begin
if Src_Data.Compiled and then Src_Data.Object_Exists
and then Is_Extending (Project, Src_Data.Project, In_Tree)
then then
if Src_Data.Unit = No_Name then if Src_Id.Unit = No_Name then
if Src_Data.Kind = Impl then if Src_Id.Kind = Impl then
Check_Object (Src_Data); Check_Object (Src_Id);
end if; end if;
else else
case Src_Data.Kind is case Src_Id.Kind is
when Spec => when Spec =>
if Src_Data.Other_Part = No_Source then if Src_Id.Other_Part = No_Source then
Check_Object (Src_Data); Check_Object (Src_Id);
end if; end if;
when Sep => when Sep =>
null; null;
when Impl => when Impl =>
if Src_Data.Other_Part /= No_Source then if Src_Id.Other_Part /= No_Source then
Check_Object (Src_Data); Check_Object (Src_Id);
else else
-- Check if it is a subunit -- Check if it is a subunit
...@@ -8300,22 +8219,20 @@ package body Prj.Nmsc is ...@@ -8300,22 +8219,20 @@ package body Prj.Nmsc is
Src_Ind : constant Source_File_Index := Src_Ind : constant Source_File_Index :=
Sinput.P.Load_Project_File Sinput.P.Load_Project_File
(Get_Name_String (Get_Name_String
(Src_Data.Path.Name)); (Src_Id.Path.Name));
begin begin
if Sinput.P.Source_File_Is_Subunit if Sinput.P.Source_File_Is_Subunit
(Src_Ind) (Src_Ind)
then then
In_Tree.Sources.Table (Src_Id).Kind := Src_Id.Kind := Sep;
Sep;
else else
Check_Object (Src_Data); Check_Object (Src_Id);
end if; end if;
end; end;
end if; end if;
end case; end case;
end if; end if;
end if; end if;
end;
Next (Iter); Next (Iter);
end loop; end loop;
...@@ -8716,36 +8633,32 @@ package body Prj.Nmsc is ...@@ -8716,36 +8633,32 @@ package body Prj.Nmsc is
procedure Remove_Source procedure Remove_Source
(Id : Source_Id; (Id : Source_Id;
Replaced_By : Source_Id; Replaced_By : Source_Id)
In_Tree : Project_Tree_Ref)
is is
Src_Data : constant Source_Data := In_Tree.Sources.Table (Id);
Source : Source_Id; Source : Source_Id;
begin begin
if Current_Verbosity = High then if Current_Verbosity = High then
Write_Str ("Removing source #"); Write_Str ("Removing source ");
Write_Line (Id'Img); Write_Line (Get_Name_String (Id.File));
end if; end if;
if Replaced_By /= No_Source then if Replaced_By /= No_Source then
In_Tree.Sources.Table (Id).Replaced_By := Replaced_By; Id.Replaced_By := Replaced_By;
In_Tree.Sources.Table (Replaced_By).Declared_In_Interfaces := Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
In_Tree.Sources.Table (Id).Declared_In_Interfaces;
end if; end if;
Source := Src_Data.Language.First_Source; Source := Id.Language.First_Source;
if Source = Id then if Source = Id then
Src_Data.Language.First_Source := Src_Data.Next_In_Lang; Id.Language.First_Source := Id.Next_In_Lang;
else else
while In_Tree.Sources.Table (Source).Next_In_Lang /= Id loop while Source.Next_In_Lang /= Id loop
Source := In_Tree.Sources.Table (Source).Next_In_Lang; Source := Source.Next_In_Lang;
end loop; end loop;
In_Tree.Sources.Table (Source).Next_In_Lang := Source.Next_In_Lang := Id.Next_In_Lang;
Src_Data.Next_In_Lang;
end if; end if;
end Remove_Source; end Remove_Source;
......
...@@ -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