with GNAT.HTable;
with Err_Vars; use Err_Vars;
-with Fmap; use Fmap;
with Hostparm;
with MLib.Tgt;
with Opt; use Opt;
-- Hash table to store file names found in string list attribute
-- Source_Files or in a source list file, stored in hash table
-- Source_Names, used by procedure Get_Path_Names_And_Record_Sources.
+ --
+ -- ??? Should not be a global table, as it is needed only when processing
+ -- a project
-- More documentation needed on what unit exceptions are about ???
Naming_Exception : Boolean := False;
Path : Path_Information := No_Path_Information;
Alternate_Languages : Language_List := null;
- Other_Part : Source_Id := No_Source;
Unit : Name_Id := No_Name;
Index : Int := 0;
Source_To_Replace : Source_Id := No_Source);
procedure Check_Ada_Name (Name : String; Unit : out Name_Id);
-- Check that a name is a valid Ada unit name
- procedure Check_Naming_Schemes
+ procedure Check_Package_Naming
(Project : Project_Id;
In_Tree : Project_Tree_Ref;
- Is_Config_File : Boolean);
- -- Check the naming scheme part of Data.
- -- Is_Config_File should be True if Project is a config file (.cgpr)
+ Is_Config_File : Boolean;
+ Bodies : out Array_Element_Id;
+ Specs : out Array_Element_Id);
+ -- Check the naming scheme part of Data, and initialize the naming scheme
+ -- data in the config of the various languages. Is_Config_File should be
+ -- True if Project is a config file (.cgpr) This also returns the naming
+ -- scheme exceptions for unit-based languages (Bodies and Specs are
+ -- associative arrays mapping individual unit names to source file names).
procedure Check_Configuration
(Project : Project_Id;
-- Current_Dir should represent the current directory, and is passed for
-- efficiency to avoid system calls to recompute it.
- procedure Check_Package_Naming
- (Project : Project_Id;
- In_Tree : Project_Tree_Ref);
- -- Check package Naming of project Project in project tree In_Tree and
- -- modify its data Data accordingly.
-
procedure Check_Programming_Languages
(In_Tree : Project_Tree_Ref;
Project : Project_Id);
In_Tree : Project_Tree_Ref;
Explicit_Sources_Only : Boolean;
Proc_Data : in out Processing_Data);
- -- Find all Ada sources by traversing all source directories.
- -- If Explicit_Sources_Only is True, then the sources found must belong to
- -- the list of sources specified explicitly in the project file.
- -- If Explicit_Sources_Only is False, then all sources matching the naming
+ -- Find all Ada sources by traversing all source directories. If
+ -- Explicit_Sources_Only is True, then the sources found must belong to
+ -- the list of sources specified explicitly in the project file. If
+ -- Explicit_Sources_Only is False, then all sources matching the naming
-- scheme are recorded.
function Compute_Directory_Last (Dir : String) return Natural;
-- Error_Report.
procedure Search_Directories
- (Project : Project_Id;
- In_Tree : Project_Tree_Ref;
- For_All_Sources : Boolean);
- -- Search the source directories to find the sources.
- -- If For_All_Sources is True, check each regular file name against the
- -- naming schemes of the different languages. Otherwise consider only the
- -- file names in the hash table Source_Names.
+ (Project : Project_Id;
+ In_Tree : Project_Tree_Ref;
+ For_All_Sources : Boolean;
+ Allow_Duplicate_Basenames : Boolean);
+ -- Search the source directories to find the sources. If For_All_Sources is
+ -- True, check each regular file name against the naming schemes of the
+ -- different languages. Otherwise consider only the file names in the hash
+ -- table Source_Names. If Allow_Duplicate_Basenames, then files with the
+ -- same base names are authorized within a project for source-based
+ -- languages (never for unit based languages)
procedure Check_File
- (Project : Project_Id;
- In_Tree : Project_Tree_Ref;
- Path : Path_Name_Type;
- File_Name : File_Name_Type;
- Display_File_Name : File_Name_Type;
- For_All_Sources : Boolean);
+ (Project : Project_Id;
+ In_Tree : Project_Tree_Ref;
+ Path : Path_Name_Type;
+ File_Name : File_Name_Type;
+ Display_File_Name : File_Name_Type;
+ For_All_Sources : Boolean;
+ Allow_Duplicate_Basenames : Boolean);
-- Check if file File_Name is a valid source of the project. This is used
- -- in multi-language mode only.
- -- When the file matches one of the naming schemes, it is added to
- -- various htables through Add_Source and to Source_Paths_Htable.
+ -- in multi-language mode only. When the file matches one of the naming
+ -- schemes, it is added to various htables through Add_Source and to
+ -- Source_Paths_Htable.
--
-- Name is the name of the candidate file. It hasn't been normalized yet
-- and is the direct result of readdir().
--
-- If For_All_Sources is True, then all possible file names are analyzed
-- otherwise only those currently set in the Source_Names htable.
+ --
+ -- If Allow_Duplicate_Basenames, then files with the same base names are
+ -- authorized within a project for source-based languages (never for unit
+ -- based languages)
procedure Check_File_Naming_Schemes
(In_Tree : Project_Tree_Ref;
-- Free the internal hash tables used for checking naming exceptions
procedure Get_Directories
- (Project : Project_Id;
- In_Tree : Project_Tree_Ref;
+ (Project : Project_Id;
+ In_Tree : Project_Tree_Ref;
Current_Dir : String);
-- Get the object directory, the exec directory and the source directories
-- of a project.
procedure Find_Sources
(Project : Project_Id;
In_Tree : Project_Tree_Ref;
- Proc_Data : in out Processing_Data);
+ Proc_Data : in out Processing_Data;
+ Allow_Duplicate_Basenames : Boolean);
-- Process the Source_Files and Source_List_File attributes, and store
-- the list of source files into the Source_Names htable.
-- When these attributes are not defined, find all files matching the
-- naming schemes in the source directories.
+ -- If Allow_Duplicate_Basenames, then files with the same base names are
+ -- authorized within a project for source-based languages (never for unit
+ -- based languages)
procedure Compute_Unit_Name
- (File_Name : File_Name_Type;
- Dot_Replacement : File_Name_Type;
- Separate_Suffix : File_Name_Type;
- Body_Suffix : File_Name_Type;
- Spec_Suffix : File_Name_Type;
- Casing : Casing_Type;
- Kind : out Source_Kind;
- Unit : out Name_Id;
- In_Tree : Project_Tree_Ref);
+ (File_Name : File_Name_Type;
+ Naming : Lang_Naming_Data;
+ Kind : out Source_Kind;
+ Unit : out Name_Id;
+ In_Tree : Project_Tree_Ref);
-- Check whether the file matches the naming scheme. If it does,
-- compute its unit name. If Unit is set to No_Name on exit, none of the
-- other out parameters are relevant.
procedure Get_Unit
(In_Tree : Project_Tree_Ref;
Canonical_File_Name : File_Name_Type;
- Naming : Naming_Data;
+ Project : Project_Id;
Exception_Id : out Ada_Naming_Exception_Id;
Unit_Name : out Name_Id;
Unit_Kind : out Spec_Or_Body);
-- computing
procedure Look_For_Sources
- (Project : Project_Id;
- In_Tree : Project_Tree_Ref;
- Proc_Data : in out Processing_Data);
+ (Project : Project_Id;
+ In_Tree : Project_Tree_Ref;
+ Proc_Data : in out Processing_Data;
+ Allow_Duplicate_Basenames : Boolean);
-- Find all the sources of project Project in project tree In_Tree and
-- update its Data accordingly. This assumes that Data.First_Source has
-- been initialized with the list of excluded sources and special naming
- -- exceptions.
+ -- exceptions. If Allow_Duplicate_Basenames, then files with the same base
+ -- names are authorized within a project for source-based languages (never
+ -- for unit based languages)
function Path_Name_Of
(File_Name : File_Name_Type;
Location : Source_Ptr;
Source_Recorded : in out Boolean);
-- Put a unit in the list of units of a project, if the file name
- -- corresponds to a valid unit name.
- -- Ada_Language is a pointer to the Language_Data for "Ada" in Project.
+ -- corresponds to a valid unit name. Ada_Language is a pointer to the
+ -- Language_Data for "Ada" in Project.
procedure Remove_Source
(Id : Source_Id;
Replaced_By : Source_Id);
- -- ??? needs comment
+ -- Remove a file from the list of sources of a project.
+ -- This might be because the file is replaced by another one in an
+ -- extending project, or because a file was added as a naming exception
+ -- but was not found in the end.
procedure Report_No_Sources
(Project : Project_Id;
Naming_Exception : Boolean := False;
Path : Path_Information := No_Path_Information;
Alternate_Languages : Language_List := null;
- Other_Part : Source_Id := No_Source;
Unit : Name_Id := No_Name;
Index : Int := 0;
Source_To_Replace : Source_Id := No_Source)
Id.Language := Lang_Id;
Id.Kind := Kind;
Id.Alternate_Languages := Alternate_Languages;
- Id.Other_Part := Other_Part;
-
- if Other_Part /= No_Source then
- Other_Part.Other_Part := Id;
- end if;
-- Add the source id to the Unit_Sources_HT hash table, if the unit name
-- is not null.
Current_Dir : String;
Proc_Data : in out Processing_Data;
Is_Config_File : Boolean;
- Compiler_Driver_Mandatory : Boolean)
+ Compiler_Driver_Mandatory : Boolean;
+ Allow_Duplicate_Basenames : Boolean)
is
+ Specs : Array_Element_Id;
+ Bodies : Array_Element_Id;
Extending : Boolean := False;
begin
else
Error_Msg
(Project, In_Tree,
- "an abstract project needs to have no language, " &
- "no sources or no source directories",
+ "at least one of Source_Files, Source_Dirs or Languages " &
+ "must be declared empty for an abstract project",
Project.Location);
end if;
end;
Show_Source_Dirs (Project, In_Tree);
end if;
- Check_Package_Naming (Project, In_Tree);
-
Extending := Project.Extends /= No_Project;
- Check_Naming_Schemes (Project, In_Tree, Is_Config_File);
+ Check_Package_Naming (Project, In_Tree, Is_Config_File, Bodies, Specs);
if Get_Mode = Ada_Only then
- Prepare_Ada_Naming_Exceptions
- (Project.Naming.Bodies, In_Tree, Impl);
- Prepare_Ada_Naming_Exceptions
- (Project.Naming.Specs, In_Tree, Spec);
+ Prepare_Ada_Naming_Exceptions (Bodies, In_Tree, Impl);
+ Prepare_Ada_Naming_Exceptions (Specs, In_Tree, Spec);
end if;
-- Find the sources
if Project.Source_Dirs /= Nil_String then
- Look_For_Sources (Project, In_Tree, Proc_Data);
+ Look_For_Sources
+ (Project, In_Tree, Proc_Data, Allow_Duplicate_Basenames);
if Get_Mode = Ada_Only then
-- of this project file.
Warn_If_Not_Sources
- (Project, In_Tree, Project.Naming.Bodies,
+ (Project, In_Tree, Bodies,
Specs => False,
Extending => Extending);
Warn_If_Not_Sources
- (Project, In_Tree, Project.Naming.Specs,
+ (Project, In_Tree, Specs,
Specs => True,
Extending => Extending);
-- Attribute Separate_Suffix
- Separate_Suffix := File_Name_Type (Attribute.Value.Value);
+ Get_Name_String (Attribute.Value.Value);
+ Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
+ Separate_Suffix := Name_Find;
elsif Attribute.Name = Name_Casing then
-- Attribute Spec_Suffix (<language>)
+ Get_Name_String (Element.Value.Value);
+ Canonical_Case_File_Name
+ (Name_Buffer (1 .. Name_Len));
Lang_Index.Config.Naming_Data.Spec_Suffix :=
- File_Name_Type (Element.Value.Value);
+ Name_Find;
when Name_Implementation_Suffix | Name_Body_Suffix =>
+ Get_Name_String (Element.Value.Value);
+ Canonical_Case_File_Name
+ (Name_Buffer (1 .. Name_Len));
+
-- Attribute Body_Suffix (<language>)
Lang_Index.Config.Naming_Data.Body_Suffix :=
- File_Name_Type (Element.Value.Value);
-
+ Name_Find;
Lang_Index.Config.Naming_Data.Separate_Suffix :=
- File_Name_Type (Element.Value.Value);
+ Lang_Index.Config.Naming_Data.Body_Suffix;
when others =>
null;
Lang_Index := Project.Languages;
while Lang_Index /= No_Language_Index loop
-- For all languages, Compiler_Driver needs to be specified. This is
- -- only necessary if we do intend to compiler (not in GPS for
- -- instance)
+ -- only needed if we do intend to compile (not in GPS for instance).
if Compiler_Driver_Mandatory
and then Lang_Index.Config.Compiler_Driver = No_File
(Project,
In_Tree,
"?no compiler specified for language %%" &
- ", ignoring all its sources",
+ ", ignoring all its sources",
No_Location);
if Lang_Index = Project.Languages then
Iter : Source_Iterator;
Source : Source_Id;
Project_2 : Project_Id;
+ Other : Source_Id;
begin
if not Interfaces.Default then
Source.In_Interfaces := True;
Source.Declared_In_Interfaces := True;
- if Source.Other_Part /= No_Source then
- Source.Other_Part.In_Interfaces := True;
- Source.Other_Part.Declared_In_Interfaces := True;
+ Other := Other_Part (Source);
+
+ if Other /= No_Source then
+ Other.In_Interfaces := True;
+ Other.Declared_In_Interfaces := True;
end if;
if Current_Verbosity = High then
end Check_And_Normalize_Unit_Names;
--------------------------
- -- Check_Naming_Schemes --
+ -- Check_Package_Naming --
--------------------------
- procedure Check_Naming_Schemes
+ procedure Check_Package_Naming
(Project : Project_Id;
In_Tree : Project_Tree_Ref;
- Is_Config_File : Boolean)
+ Is_Config_File : Boolean;
+ Bodies : out Array_Element_Id;
+ Specs : out Array_Element_Id)
is
Naming_Id : constant Package_Id :=
Util.Value_Of (Name_Naming, Project.Decl.Packages, In_Tree);
Naming : Package_Element;
+ Ada_Body_Suffix_Loc : Source_Ptr := No_Location;
+ Ada_Spec_Suffix_Loc : Source_Ptr := No_Location;
+
procedure Check_Naming_Ada_Only;
-- Does Check_Naming_Schemes processing in Ada_Only mode.
-- If there is a package Naming, puts in Data.Naming the contents of
-- In Multi_Lang mode, process the naming exceptions for the two types
-- of languages we can have.
+ procedure Initialize_Naming_Data;
+ -- Initialize internal naming data for the various languages
+
------------------
-- Check_Common --
------------------
Source : Source_Id;
Source_To_Replace : Source_Id := No_Source;
Other_Project : Project_Id;
- Other_Part : Source_Id := No_Source;
Iter : Source_Iterator;
begin
if Source /= No_Source then
if Source.Kind /= Kind then
- Other_Part := Source;
-
loop
Next (Iter);
Source := Prj.Element (Iter);
Other_Project := Source.Project;
if Is_Extending (Project, Other_Project) then
- Other_Part := Source.Other_Part;
-
- -- Record the source to be removed
-
Source_To_Replace := Source;
Source := No_Source;
Kind => Kind,
File_Name => File_Name,
Display_File => File_Name_Type (Element.Value.Value),
- Other_Part => Other_Part,
Unit => Unit,
Index => Index,
Naming_Exception => True,
---------------------------
procedure Check_Naming_Ada_Only is
+ Ada : constant Language_Ptr :=
+ Get_Language_From_Name (Project, "ada");
+
Casing_Defined : Boolean;
- Spec_Suffix : File_Name_Type;
- Body_Suffix : File_Name_Type;
Sep_Suffix_Loc : Source_Ptr;
- Ada_Spec_Suffix : constant Variable_Value :=
- Prj.Util.Value_Of
- (Index => Name_Ada,
- Src_Index => 0,
- In_Array => Project.Naming.Spec_Suffix,
- In_Tree => In_Tree);
-
- Ada_Body_Suffix : constant Variable_Value :=
- Prj.Util.Value_Of
- (Index => Name_Ada,
- Src_Index => 0,
- In_Array => Project.Naming.Body_Suffix,
- In_Tree => In_Tree);
-
begin
- -- The default value of separate suffix should be the same as the
- -- body suffix, so we need to compute that first.
+ -- If no language, then nothing to do
- if Ada_Body_Suffix.Kind = Single
- and then Length_Of_Name (Ada_Body_Suffix.Value) /= 0
- then
- Body_Suffix := Canonical_Case_File_Name (Ada_Body_Suffix.Value);
- Project.Naming.Separate_Suffix := Body_Suffix;
- Set_Body_Suffix (In_Tree, "ada", Project.Naming, Body_Suffix);
-
- else
- Body_Suffix := Default_Ada_Body_Suffix;
- Project.Naming.Separate_Suffix := Body_Suffix;
- Set_Body_Suffix (In_Tree, "ada", Project.Naming, Body_Suffix);
+ if Ada = null then
+ return;
end if;
- Write_Attr ("Body_Suffix", Get_Name_String (Body_Suffix));
+ declare
+ Data : Lang_Naming_Data renames Ada.Config.Naming_Data;
- -- We'll need the dot replacement below, so compute it now
+ begin
+ -- The default value of separate suffix should be the same as the
+ -- body suffix, so we need to compute that first.
- Check_Common
- (Dot_Replacement => Project.Naming.Dot_Replacement,
- Casing => Project.Naming.Casing,
- Casing_Defined => Casing_Defined,
- Separate_Suffix => Project.Naming.Separate_Suffix,
- Sep_Suffix_Loc => Sep_Suffix_Loc);
+ Data.Separate_Suffix := Data.Body_Suffix;
+ Write_Attr ("Body_Suffix", Get_Name_String (Data.Body_Suffix));
- Project.Naming.Bodies :=
- Util.Value_Of (Name_Body, Naming.Decl.Arrays, In_Tree);
+ -- We'll need the dot replacement below, so compute it now
- if Project.Naming.Bodies /= No_Array_Element then
- Check_And_Normalize_Unit_Names
- (Project, In_Tree, Project.Naming.Bodies, "Naming.Bodies");
- end if;
+ Check_Common
+ (Dot_Replacement => Data.Dot_Replacement,
+ Casing => Data.Casing,
+ Casing_Defined => Casing_Defined,
+ Separate_Suffix => Data.Separate_Suffix,
+ Sep_Suffix_Loc => Sep_Suffix_Loc);
- Project.Naming.Specs :=
- Util.Value_Of (Name_Spec, Naming.Decl.Arrays, In_Tree);
+ Bodies := Util.Value_Of (Name_Body, Naming.Decl.Arrays, In_Tree);
- if Project.Naming.Specs /= No_Array_Element then
- Check_And_Normalize_Unit_Names
- (Project, In_Tree, Project.Naming.Specs, "Naming.Specs");
- end if;
+ if Bodies /= No_Array_Element then
+ Check_And_Normalize_Unit_Names
+ (Project, In_Tree, Bodies, "Naming.Bodies");
+ end if;
- -- Check Spec_Suffix
+ Specs := Util.Value_Of (Name_Spec, Naming.Decl.Arrays, In_Tree);
- if Ada_Spec_Suffix.Kind = Single
- and then Length_Of_Name (Ada_Spec_Suffix.Value) /= 0
- then
- Spec_Suffix := Canonical_Case_File_Name (Ada_Spec_Suffix.Value);
- Set_Spec_Suffix (In_Tree, "ada", Project.Naming, Spec_Suffix);
+ if Specs /= No_Array_Element then
+ Check_And_Normalize_Unit_Names
+ (Project, In_Tree, Specs, "Naming.Specs");
+ end if;
- if Is_Illegal_Suffix
- (Spec_Suffix, Project.Naming.Dot_Replacement)
- then
- Err_Vars.Error_Msg_File_1 := Spec_Suffix;
+ -- Check Spec_Suffix
+
+ if Is_Illegal_Suffix (Data.Spec_Suffix, Data.Dot_Replacement) then
+ Err_Vars.Error_Msg_File_1 := Data.Spec_Suffix;
Error_Msg
(Project, In_Tree,
"{ is illegal for Spec_Suffix",
- Ada_Spec_Suffix.Location);
+ Ada_Spec_Suffix_Loc);
end if;
- else
- Spec_Suffix := Default_Ada_Spec_Suffix;
- Set_Spec_Suffix (In_Tree, "ada", Project.Naming, Spec_Suffix);
- end if;
+ Write_Attr ("Spec_Suffix", Get_Name_String (Data.Spec_Suffix));
- Write_Attr ("Spec_Suffix", Get_Name_String (Spec_Suffix));
+ -- Check Body_Suffix
- -- Check Body_Suffix
-
- if Is_Illegal_Suffix
- (Body_Suffix, Project.Naming.Dot_Replacement)
- then
- Err_Vars.Error_Msg_File_1 := Body_Suffix;
- Error_Msg
- (Project, In_Tree,
- "{ is illegal for Body_Suffix",
- Ada_Body_Suffix.Location);
- end if;
+ if Is_Illegal_Suffix (Data.Body_Suffix, Data.Dot_Replacement) then
+ Err_Vars.Error_Msg_File_1 := Data.Body_Suffix;
+ Error_Msg
+ (Project, In_Tree,
+ "{ is illegal for Body_Suffix",
+ Ada_Body_Suffix_Loc);
+ end if;
- -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
- -- since that would cause a clear ambiguity. Note that we do allow a
- -- Spec_Suffix to have the same termination as one of these, which
- -- causes a potential ambiguity, but we resolve that my matching the
- -- longest possible suffix.
+ -- Spec_Suffix cannot be equal to Body_Suffix or Separate_Suffix,
+ -- since that would cause a clear ambiguity. Note that we do allow
+ -- a Spec_Suffix to have the same termination as one of these,
+ -- which causes a potential ambiguity, but we resolve that my
+ -- matching the longest possible suffix.
- if Spec_Suffix = Body_Suffix then
- Error_Msg
- (Project, In_Tree,
- "Body_Suffix (""" &
- Get_Name_String (Body_Suffix) &
- """) cannot be the same as Spec_Suffix.",
- Ada_Body_Suffix.Location);
- end if;
+ if Data.Spec_Suffix = Data.Body_Suffix then
+ Error_Msg
+ (Project, In_Tree,
+ "Body_Suffix ("""
+ & Get_Name_String (Data.Body_Suffix)
+ & """) cannot be the same as Spec_Suffix.",
+ Ada_Body_Suffix_Loc);
+ end if;
- if Body_Suffix /= Project.Naming.Separate_Suffix
- and then Spec_Suffix = Project.Naming.Separate_Suffix
- then
- Error_Msg
- (Project, In_Tree,
- "Separate_Suffix (""" &
- Get_Name_String (Project.Naming.Separate_Suffix) &
- """) cannot be the same as Spec_Suffix.",
- Sep_Suffix_Loc);
- end if;
+ if Data.Body_Suffix /= Data.Separate_Suffix
+ and then Data.Spec_Suffix = Data.Separate_Suffix
+ then
+ Error_Msg
+ (Project, In_Tree,
+ "Separate_Suffix ("""
+ & Get_Name_String (Data.Separate_Suffix)
+ & """) cannot be the same as Spec_Suffix.",
+ Sep_Suffix_Loc);
+ end if;
+ end;
end Check_Naming_Ada_Only;
-----------------------------
Separate_Suffix => Separate_Suffix,
Sep_Suffix_Loc => Sep_Suffix_Loc);
- -- For all unit based languages, if any, set the specified
- -- value of Dot_Replacement, Casing and/or Separate_Suffix. Do not
+ -- For all unit based languages, if any, set the specified value
+ -- of Dot_Replacement, Casing and/or Separate_Suffix. Do not
-- systematically overwrite, since the defaults come from the
-- configuration file
end loop;
end Check_Naming_Multi_Lang;
+ ----------------------------
+ -- Initialize_Naming_Data --
+ ----------------------------
+
+ procedure Initialize_Naming_Data is
+ Specs : Array_Element_Id :=
+ Util.Value_Of
+ (Name_Spec_Suffix,
+ Naming.Decl.Arrays,
+ In_Tree);
+
+ Impls : Array_Element_Id :=
+ Util.Value_Of
+ (Name_Body_Suffix,
+ Naming.Decl.Arrays,
+ In_Tree);
+
+ Lang : Language_Ptr;
+ Lang_Name : Name_Id;
+ Value : Variable_Value;
+ Extended : Project_Id;
+
+ begin
+ -- At this stage, the project already contains the default extensions
+ -- for the various languages. We now merge those suffixes read in the
+ -- user project, and they override the default.
+
+ while Specs /= No_Array_Element loop
+ Lang_Name := In_Tree.Array_Elements.Table (Specs).Index;
+ Lang := Get_Language_From_Name
+ (Project, Name => Get_Name_String (Lang_Name));
+
+ -- An extending project inherits its parent projects' languages
+ -- so if needed we should create entries for those languages
+
+ if Lang = null then
+ Extended := Project.Extends;
+
+ while Extended /= null loop
+ Lang := Get_Language_From_Name
+ (Extended, Name => Get_Name_String (Lang_Name));
+ exit when Lang /= null;
+
+ Extended := Extended.Extends;
+ end loop;
+
+ if Lang /= null then
+ Lang := new Language_Data'(Lang.all);
+ Lang.First_Source := null;
+ Lang.Next := Project.Languages;
+ Project.Languages := Lang;
+ end if;
+ end if;
+
+ -- If the language was not found in project or the projects it
+ -- extends
+
+ if Lang = null then
+ if Current_Verbosity = High then
+ Write_Line
+ ("Ignoring spec naming data for "
+ & Get_Name_String (Lang_Name)
+ & " since language is not defined for this project");
+ end if;
+ else
+ Value := In_Tree.Array_Elements.Table (Specs).Value;
+
+ if Lang.Name = Name_Ada then
+ Ada_Spec_Suffix_Loc := Value.Location;
+ end if;
+
+ if Value.Kind = Single then
+ Lang.Config.Naming_Data.Spec_Suffix :=
+ Canonical_Case_File_Name (Value.Value);
+ end if;
+ end if;
+
+ Specs := In_Tree.Array_Elements.Table (Specs).Next;
+ end loop;
+
+ while Impls /= No_Array_Element loop
+ Lang_Name := In_Tree.Array_Elements.Table (Impls).Index;
+ Lang := Get_Language_From_Name
+ (Project, Name => Get_Name_String (Lang_Name));
+
+ if Lang = null then
+ if Current_Verbosity = High then
+ Write_Line
+ ("Ignoring impl naming data for "
+ & Get_Name_String (Lang_Name)
+ & " since language is not defined for this project");
+ end if;
+ else
+ Value := In_Tree.Array_Elements.Table (Impls).Value;
+
+ if Lang.Name = Name_Ada then
+ Ada_Body_Suffix_Loc := Value.Location;
+ end if;
+
+ if Value.Kind = Single then
+ Lang.Config.Naming_Data.Body_Suffix :=
+ Canonical_Case_File_Name (Value.Value);
+ end if;
+ end if;
+
+ Impls := In_Tree.Array_Elements.Table (Impls).Next;
+ end loop;
+ end Initialize_Naming_Data;
+
-- Start of processing for Check_Naming_Schemes
begin
+ Specs := No_Array_Element;
+ Bodies := No_Array_Element;
+
-- No Naming package or parsing a configuration file? nothing to do
if Naming_Id /= No_Package and not Is_Config_File then
Naming := In_Tree.Packages.Table (Naming_Id);
if Current_Verbosity = High then
- Write_Line ("Checking package Naming.");
+ Write_Line ("Checking package Naming for project "
+ & Get_Name_String (Project.Name));
end if;
+ Initialize_Naming_Data;
+
case Get_Mode is
when Ada_Only =>
Check_Naming_Ada_Only;
Check_Naming_Multi_Lang;
end case;
end if;
- end Check_Naming_Schemes;
+ end Check_Package_Naming;
------------------------------
-- Check_Library_Attributes --
end if;
end Check_Library_Attributes;
- --------------------------
- -- Check_Package_Naming --
- --------------------------
+ ---------------------------------
+ -- Check_Programming_Languages --
+ ---------------------------------
- procedure Check_Package_Naming
- (Project : Project_Id;
- In_Tree : Project_Tree_Ref)
+ procedure Check_Programming_Languages
+ (In_Tree : Project_Tree_Ref;
+ Project : Project_Id)
is
- Naming_Id : constant Package_Id :=
- Util.Value_Of (Name_Naming, Project.Decl.Packages, In_Tree);
-
- Naming : Package_Element;
-
- begin
- -- If there is a package Naming, we will put in Data.Naming
- -- what is in this package Naming.
-
- if Naming_Id /= No_Package then
- Naming := In_Tree.Packages.Table (Naming_Id);
-
- if Current_Verbosity = High then
- Write_Line ("Checking ""Naming"".");
- end if;
-
- -- Check Spec_Suffix
-
- declare
- Spec_Suffixs : Array_Element_Id :=
- Util.Value_Of
- (Name_Spec_Suffix,
- Naming.Decl.Arrays,
- In_Tree);
-
- Suffix : Array_Element_Id;
- Element : Array_Element;
- Suffix2 : Array_Element_Id;
-
- begin
- -- If some suffixes have been specified, we make sure that
- -- for each language for which a default suffix has been
- -- specified, there is a suffix specified, either the one
- -- in the project file or if there were none, the default.
-
- if Spec_Suffixs /= No_Array_Element then
- Suffix := Project.Naming.Spec_Suffix;
-
- while Suffix /= No_Array_Element loop
- Element :=
- In_Tree.Array_Elements.Table (Suffix);
- Suffix2 := Spec_Suffixs;
-
- while Suffix2 /= No_Array_Element loop
- exit when In_Tree.Array_Elements.Table
- (Suffix2).Index = Element.Index;
- Suffix2 := In_Tree.Array_Elements.Table
- (Suffix2).Next;
- end loop;
-
- -- There is a registered default suffix, but no
- -- suffix specified in the project file.
- -- Add the default to the array.
-
- if Suffix2 = No_Array_Element then
- Array_Element_Table.Increment_Last
- (In_Tree.Array_Elements);
- In_Tree.Array_Elements.Table
- (Array_Element_Table.Last
- (In_Tree.Array_Elements)) :=
- (Index => Element.Index,
- Src_Index => Element.Src_Index,
- Index_Case_Sensitive => False,
- Value => Element.Value,
- Next => Spec_Suffixs);
- Spec_Suffixs := Array_Element_Table.Last
- (In_Tree.Array_Elements);
- end if;
-
- Suffix := Element.Next;
- end loop;
+ Languages : Variable_Value := Nil_Variable_Value;
+ Def_Lang : Variable_Value := Nil_Variable_Value;
+ Def_Lang_Id : Name_Id;
- -- Put the resulting array as the Spec suffixes
+ procedure Add_Language (Name, Display_Name : Name_Id);
+ -- Add a new language to the list of languages for the project.
+ -- Nothing is done if the language has already been defined
- Project.Naming.Spec_Suffix := Spec_Suffixs;
+ procedure Add_Language (Name, Display_Name : Name_Id) is
+ Lang : Language_Ptr := Project.Languages;
+ begin
+ while Lang /= No_Language_Index loop
+ if Name = Lang.Name then
+ return;
end if;
- end;
-
- -- Check Body_Suffix
-
- declare
- Impl_Suffixs : Array_Element_Id :=
- Util.Value_Of
- (Name_Body_Suffix,
- Naming.Decl.Arrays,
- In_Tree);
-
- Suffix : Array_Element_Id;
- Element : Array_Element;
- Suffix2 : Array_Element_Id;
-
- begin
- -- If some suffixes have been specified, we make sure that
- -- for each language for which a default suffix has been
- -- specified, there is a suffix specified, either the one
- -- in the project file or if there were none, the default.
-
- if Impl_Suffixs /= No_Array_Element then
- Suffix := Project.Naming.Body_Suffix;
- while Suffix /= No_Array_Element loop
- Element :=
- In_Tree.Array_Elements.Table (Suffix);
-
- Suffix2 := Impl_Suffixs;
- while Suffix2 /= No_Array_Element loop
- exit when In_Tree.Array_Elements.Table
- (Suffix2).Index = Element.Index;
- Suffix2 := In_Tree.Array_Elements.Table
- (Suffix2).Next;
- end loop;
- -- There is a registered default suffix, but no suffix was
- -- specified in the project file. Add default to the array.
-
- if Suffix2 = No_Array_Element then
- Array_Element_Table.Increment_Last
- (In_Tree.Array_Elements);
- In_Tree.Array_Elements.Table
- (Array_Element_Table.Last
- (In_Tree.Array_Elements)) :=
- (Index => Element.Index,
- Src_Index => Element.Src_Index,
- Index_Case_Sensitive => False,
- Value => Element.Value,
- Next => Impl_Suffixs);
- Impl_Suffixs := Array_Element_Table.Last
- (In_Tree.Array_Elements);
- end if;
+ Lang := Lang.Next;
+ end loop;
- Suffix := Element.Next;
- end loop;
+ Lang := new Language_Data'(No_Language_Data);
+ Lang.Next := Project.Languages;
+ Project.Languages := Lang;
+ Lang.Name := Name;
+ Lang.Display_Name := Display_Name;
- -- Put the resulting array as the implementation suffixes
+ if Name = Name_Ada then
+ Lang.Config.Kind := Unit_Based;
+ Lang.Config.Dependency_Kind := ALI_File;
- Project.Naming.Body_Suffix := Impl_Suffixs;
+ if Get_Mode = Ada_Only then
+ -- Create a default config for Ada (since there is no
+ -- configuration file to create it for us)
+ -- ??? We should do as GPS does and create a dummy config
+ -- file
+
+ Lang.Config.Naming_Data :=
+ (Dot_Replacement => File_Name_Type
+ (First_Name_Id + Character'Pos ('-')),
+ Casing => All_Lower_Case,
+ Separate_Suffix => Default_Ada_Body_Suffix,
+ Spec_Suffix => Default_Ada_Spec_Suffix,
+ Body_Suffix => Default_Ada_Body_Suffix);
end if;
- end;
-
- -- Get the exceptions, if any
-
- Project.Naming.Specification_Exceptions :=
- Util.Value_Of
- (Name_Specification_Exceptions,
- In_Arrays => Naming.Decl.Arrays,
- In_Tree => In_Tree);
-
- Project.Naming.Implementation_Exceptions :=
- Util.Value_Of
- (Name_Implementation_Exceptions,
- In_Arrays => Naming.Decl.Arrays,
- In_Tree => In_Tree);
- end if;
- end Check_Package_Naming;
- ---------------------------------
- -- Check_Programming_Languages --
- ---------------------------------
+ else
+ Lang.Config.Kind := File_Based;
+ end if;
+ end Add_Language;
- procedure Check_Programming_Languages
- (In_Tree : Project_Tree_Ref;
- Project : Project_Id)
- is
- Languages : Variable_Value := Nil_Variable_Value;
- Def_Lang : Variable_Value := Nil_Variable_Value;
- Def_Lang_Id : Name_Id;
+ -- Start of processing for Check_Programming_Languages
begin
- Project.Languages := No_Language_Index;
+ Project.Languages := null;
Languages :=
Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, In_Tree);
Def_Lang :=
"no languages defined for this project",
Project.Location);
Def_Lang_Id := No_Name;
+
else
Def_Lang_Id := Name_Ada;
end if;
end if;
if Def_Lang_Id /= No_Name then
- Project.Languages := new Language_Data'(No_Language_Data);
- Project.Languages.Name := Def_Lang_Id;
Get_Name_String (Def_Lang_Id);
Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
- Project.Languages.Display_Name := Name_Find;
-
- if Def_Lang_Id = Name_Ada then
- Project.Languages.Config.Kind := Unit_Based;
- Project.Languages.Config.Dependency_Kind := ALI_File;
- else
- Project.Languages.Config.Kind := File_Based;
- end if;
+ Add_Language
+ (Name => Def_Lang_Id,
+ Display_Name => Name_Find);
end if;
else
declare
- Current : String_List_Id := Languages.Values;
- Element : String_Element;
- Lang_Name : Name_Id;
- Index : Language_Ptr;
- NL_Id : Language_Ptr;
+ Current : String_List_Id := Languages.Values;
+ Element : String_Element;
begin
-- If there are no languages declared, there are no sources
Element := In_Tree.String_Elements.Table (Current);
Get_Name_String (Element.Value);
To_Lower (Name_Buffer (1 .. Name_Len));
- Lang_Name := Name_Find;
- -- If the language was not already specified (duplicates
- -- are simply ignored).
-
- NL_Id := Project.Languages;
- while NL_Id /= No_Language_Index loop
- exit when Lang_Name = NL_Id.Name;
- NL_Id := NL_Id.Next;
- end loop;
-
- if NL_Id = No_Language_Index then
- Index := new Language_Data'(No_Language_Data);
- Index.Name := Lang_Name;
- Index.Display_Name := Element.Value;
- Index.Next := Project.Languages;
-
- if Lang_Name = Name_Ada then
- Index.Config.Kind := Unit_Based;
- Index.Config.Dependency_Kind := ALI_File;
-
- else
- Index.Config.Kind := File_Based;
- Index.Config.Dependency_Kind := None;
- end if;
-
- Project.Languages := Index;
- end if;
+ Add_Language
+ (Name => Name_Find,
+ Display_Name => Element.Value);
Current := Element.Next;
end loop;
Extending : Boolean) return Boolean
is
Prj : Project_Id;
+
begin
if P = Root_Project then
return True;
-- Check that the unit is part of the project
if UData.File_Names (Impl) /= null
- and then UData.File_Names (Impl).Path.Name /= Slash
+ and then not UData.File_Names (Impl).Locally_Removed
then
if Check_Project
(UData.File_Names (Impl).Project,
Project, Extending)
then
- -- There is a body for this unit.
- -- If there is no spec, we need to check that it
- -- is not a subunit.
+ -- There is a body for this unit. If there is
+ -- no spec, we need to check that it is not a
+ -- subunit.
if UData.File_Names (Spec) = null then
declare
end if;
elsif UData.File_Names (Spec) /= null
- and then UData.File_Names (Spec).Path.Name /= Slash
+ and then not UData.File_Names (Spec).Locally_Removed
and then Check_Project
(UData.File_Names (Spec).Project,
Project, Extending)
if Source.Kind = Sep then
Source := No_Source;
elsif Source.Kind = Spec
- and then Source.Other_Part /= No_Source
+ and then Other_Part (Source) /= No_Source
then
- Source := Source.Other_Part;
+ Source := Other_Part (Source);
end if;
end if;
(Interfaces).Location);
else
- if Source.Kind = Spec and then
- Source.Other_Part /= No_Source
+ if Source.Kind = Spec
+ and then Other_Part (Source) /= No_Source
then
- Source := Source.Other_Part;
+ Source := Other_Part (Source);
end if;
String_Element_Table.Increment_Last
-----------------------
procedure Compute_Unit_Name
- (File_Name : File_Name_Type;
- Dot_Replacement : File_Name_Type;
- Separate_Suffix : File_Name_Type;
- Body_Suffix : File_Name_Type;
- Spec_Suffix : File_Name_Type;
- Casing : Casing_Type;
- Kind : out Source_Kind;
- Unit : out Name_Id;
- In_Tree : Project_Tree_Ref)
+ (File_Name : File_Name_Type;
+ Naming : Lang_Naming_Data;
+ Kind : out Source_Kind;
+ Unit : out Name_Id;
+ In_Tree : Project_Tree_Ref)
is
Filename : constant String := Get_Name_String (File_Name);
Last : Integer := Filename'Last;
Sep_Len : constant Integer :=
- Integer (Length_Of_Name (Separate_Suffix));
+ Integer (Length_Of_Name (Naming.Separate_Suffix));
Body_Len : constant Integer :=
- Integer (Length_Of_Name (Body_Suffix));
+ Integer (Length_Of_Name (Naming.Body_Suffix));
Spec_Len : constant Integer :=
- Integer (Length_Of_Name (Spec_Suffix));
+ Integer (Length_Of_Name (Naming.Spec_Suffix));
Standard_GNAT : constant Boolean :=
- Spec_Suffix = Default_Ada_Spec_Suffix
+ Naming.Spec_Suffix = Default_Ada_Spec_Suffix
and then
- Body_Suffix = Default_Ada_Body_Suffix;
+ Naming.Body_Suffix = Default_Ada_Body_Suffix;
Unit_Except : Unit_Exception;
Masked : Boolean := False;
+
begin
Unit := No_Name;
Kind := Spec;
- if Dot_Replacement = No_File then
+ if Naming.Dot_Replacement = No_File then
if Current_Verbosity = High then
Write_Line (" No dot_replacement specified");
end if;
+
return;
end if;
-- Choose the longest suffix that matches. If there are several matches,
-- give priority to specs, then bodies, then separates.
- if Separate_Suffix /= Body_Suffix
- and then Suffix_Matches (Filename, Separate_Suffix)
+ if Naming.Separate_Suffix /= Naming.Body_Suffix
+ and then Suffix_Matches (Filename, Naming.Separate_Suffix)
then
Last := Filename'Last - Sep_Len;
Kind := Sep;
end if;
if Filename'Last - Body_Len <= Last
- and then Suffix_Matches (Filename, Body_Suffix)
+ and then Suffix_Matches (Filename, Naming.Body_Suffix)
then
Last := Natural'Min (Last, Filename'Last - Body_Len);
Kind := Impl;
end if;
if Filename'Last - Spec_Len <= Last
- and then Suffix_Matches (Filename, Spec_Suffix)
+ and then Suffix_Matches (Filename, Naming.Spec_Suffix)
then
Last := Natural'Min (Last, Filename'Last - Spec_Len);
Kind := Spec;
if Current_Verbosity = High then
Write_Line (" No matching suffix");
end if;
+
return;
end if;
-- Check that the casing matches
if File_Names_Case_Sensitive then
- case Casing is
+ case Naming.Casing is
when All_Lower_Case =>
for J in Filename'First .. Last loop
if Is_Letter (Filename (J))
if Current_Verbosity = High then
Write_Line (" Invalid casing");
end if;
+
return;
end if;
end loop;
if Current_Verbosity = High then
Write_Line (" Invalid casing");
end if;
+
return;
end if;
end loop;
-- be any dot in the name.
declare
- Dot_Repl : constant String := Get_Name_String (Dot_Replacement);
+ Dot_Repl : constant String :=
+ Get_Name_String (Naming.Dot_Replacement);
begin
if Dot_Repl /= "." then
if Current_Verbosity = High then
Write_Line (" Invalid name, contains dot");
end if;
+
return;
end if;
end loop;
Replace_Into_Name_Buffer
(Filename (Filename'First .. Last), Dot_Repl, '.');
+
else
Name_Len := Last - Filename'First + 1;
Name_Buffer (1 .. Name_Len) := Filename (Filename'First .. Last);
S3 : constant Character := Name_Buffer (3);
begin
- if S1 = 'a'
+ if S1 = 'a'
or else S1 = 'g'
or else S1 = 'i'
or else S1 = 's'
procedure Get_Unit
(In_Tree : Project_Tree_Ref;
Canonical_File_Name : File_Name_Type;
- Naming : Naming_Data;
+ Project : Project_Id;
Exception_Id : out Ada_Naming_Exception_Id;
Unit_Name : out Name_Id;
Unit_Kind : out Spec_Or_Body)
Ada_Naming_Exceptions.Get (Canonical_File_Name);
VMS_Name : File_Name_Type;
Kind : Source_Kind;
+ Lang : Language_Ptr;
begin
if Info_Id = No_Ada_Naming_Exception
else
Exception_Id := No_Ada_Naming_Exception;
- Compute_Unit_Name
- (File_Name => Canonical_File_Name,
- Dot_Replacement => Naming.Dot_Replacement,
- Separate_Suffix => Naming.Separate_Suffix,
- Body_Suffix => Body_Suffix_Id_Of (In_Tree, Name_Ada, Naming),
- Spec_Suffix => Spec_Suffix_Id_Of (In_Tree, Name_Ada, Naming),
- Casing => Naming.Casing,
- Kind => Kind,
- Unit => Unit_Name,
- In_Tree => In_Tree);
+ Lang := Get_Language_From_Name (Project, "ada");
- case Kind is
- when Spec => Unit_Kind := Spec;
- when Impl | Sep => Unit_Kind := Impl;
- end case;
+ if Lang = null then
+ Unit_Name := No_Name;
+ Unit_Kind := Spec;
+ else
+ Compute_Unit_Name
+ (File_Name => Canonical_File_Name,
+ Naming => Lang.Config.Naming_Data,
+ Kind => Kind,
+ Unit => Unit_Name,
+ In_Tree => In_Tree);
+
+ case Kind is
+ when Spec => Unit_Kind := Spec;
+ when Impl | Sep => Unit_Kind := Impl;
+ end case;
+ end if;
end if;
end Get_Unit;
------------------
procedure Find_Sources
- (Project : Project_Id;
- In_Tree : Project_Tree_Ref;
- Proc_Data : in out Processing_Data)
+ (Project : Project_Id;
+ In_Tree : Project_Tree_Ref;
+ Proc_Data : in out Processing_Data;
+ Allow_Duplicate_Basenames : Boolean)
is
Sources : constant Variable_Value :=
Util.Value_Of
if Get_Mode = Ada_Only then
Find_Ada_Sources
- (Project, In_Tree, Explicit_Sources_Only => Has_Explicit_Sources,
- Proc_Data => Proc_Data);
+ (Project, In_Tree,
+ Explicit_Sources_Only => Has_Explicit_Sources,
+ Proc_Data => Proc_Data);
else
Search_Directories
(Project, In_Tree,
- For_All_Sources =>
- Sources.Default and then Source_List_File.Default);
+ For_All_Sources =>
+ Sources.Default and then Source_List_File.Default,
+ Allow_Duplicate_Basenames => Allow_Duplicate_Basenames);
end if;
-- Check if all exceptions have been found. For Ada, it is an error if
if not Header_File then
Compute_Unit_Name
(File_Name => File_Name,
- Dot_Replacement => Config.Naming_Data.Dot_Replacement,
- Separate_Suffix => Config.Naming_Data.Separate_Suffix,
- Body_Suffix => Config.Naming_Data.Body_Suffix,
- Spec_Suffix => Config.Naming_Data.Spec_Suffix,
- Casing => Config.Naming_Data.Casing,
+ Naming => Config.Naming_Data,
Kind => Kind,
Unit => Unit,
In_Tree => In_Tree);
procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
begin
- -- Remove reference in the unit, if necessary
+ -- If the file was previously already associated with a unit, change it
if Source.Unit /= null
and then Source.Kind in Spec_Or_Body
+ and then Source.Unit.File_Names (Source.Kind) /= null
then
+ -- If we had another file referencing the same unit (for instance it
+ -- was in an extended project), that source file is in fact invisible
+ -- from now on, and in particular doesn't belong to the same unit.
+
+ if Source.Unit.File_Names (Source.Kind) /= Source then
+ Source.Unit.File_Names (Source.Kind).Unit := No_Unit_Index;
+ end if;
+
Source.Unit.File_Names (Source.Kind) := null;
end if;
----------------
procedure Check_File
- (Project : Project_Id;
- In_Tree : Project_Tree_Ref;
- Path : Path_Name_Type;
- File_Name : File_Name_Type;
- Display_File_Name : File_Name_Type;
- For_All_Sources : Boolean)
+ (Project : Project_Id;
+ In_Tree : Project_Tree_Ref;
+ Path : Path_Name_Type;
+ File_Name : File_Name_Type;
+ Display_File_Name : File_Name_Type;
+ For_All_Sources : Boolean;
+ Allow_Duplicate_Basenames : Boolean)
is
Canonical_Path : constant Path_Name_Type :=
Path_Name_Type
Alternate_Languages : Language_List;
Language : Language_Ptr;
Source : Source_Id;
- Other_Part : Source_Id;
Add_Src : Boolean;
Src_Ind : Source_File_Index;
Unit : Name_Id;
else
if Name_Loc.Found then
-
-- Check if it is OK to have the same file name in several
-- source directories.
Check_Name := True;
else
+ -- ??? Issue: there could be several entries for the same
+ -- source file in the list of sources, in case the file
+ -- contains multiple units. We should share the data as much
+ -- as possible, and more importantly set the path for all
+ -- instances.
+
Name_Loc.Source.Path := (Canonical_Path, Path);
Source_Paths_Htable.Set
end if;
if Check_Name then
- Other_Part := No_Source;
-
Check_File_Naming_Schemes
(In_Tree => In_Tree,
Project => Project,
or else
(Source.Kind = Impl and then Kind = Spec))
then
- Other_Part := Source;
+ -- We found the "other_part (source)"
+
+ null;
elsif (Unit /= No_Name
and then Source.Unit /= No_Unit_Index
-- allowed if order of source directories is known.
if Project = Source.Project then
- if Project.Known_Order_Of_Source_Dirs then
- Add_Src := False;
-
- elsif Unit /= No_Name then
- Error_Msg_Name_1 := Unit;
- Error_Msg
- (Project, In_Tree, "duplicate unit %%",
- No_Location);
- Add_Src := False;
+ if Unit = No_Name then
+ if Allow_Duplicate_Basenames then
+ Add_Src := True;
+ elsif Project.Known_Order_Of_Source_Dirs then
+ Add_Src := False;
+ else
+ Error_Msg_File_1 := File_Name;
+ Error_Msg
+ (Project, In_Tree, "duplicate source file name {",
+ No_Location);
+ Add_Src := False;
+ end if;
else
- Error_Msg_File_1 := File_Name;
- Error_Msg
- (Project, In_Tree, "duplicate source file name {",
- No_Location);
- Add_Src := False;
+ if Project.Known_Order_Of_Source_Dirs then
+ Add_Src := False;
+ else
+ Error_Msg_Name_1 := Unit;
+ Error_Msg
+ (Project, In_Tree, "duplicate unit %%",
+ No_Location);
+ Add_Src := False;
+ end if;
end if;
-- Do not allow the same unit name in different projects,
Alternate_Languages => Alternate_Languages,
File_Name => File_Name,
Display_File => Display_File_Name,
- Other_Part => Other_Part,
Unit => Unit,
Path => (Canonical_Path, Path),
Source_To_Replace => Source_To_Replace);
------------------------
procedure Search_Directories
- (Project : Project_Id;
- In_Tree : Project_Tree_Ref;
- For_All_Sources : Boolean)
+ (Project : Project_Id;
+ In_Tree : Project_Tree_Ref;
+ For_All_Sources : Boolean;
+ Allow_Duplicate_Basenames : Boolean)
is
Source_Dir : String_List_Id;
Element : String_Element;
declare
Path_Name : constant String :=
- Normalize_Pathname
- (Name (1 .. Last),
- Directory => Source_Directory
- (Source_Directory'First .. Dir_Last),
- Resolve_Links => Opt.Follow_Links_For_Files,
- Case_Sensitive => True); -- no folding
+ Normalize_Pathname
+ (Name (1 .. Last),
+ Directory =>
+ Source_Directory
+ (Source_Directory'First ..
+ Dir_Last),
+ Resolve_Links =>
+ Opt.Follow_Links_For_Files,
+ Case_Sensitive => True);
+ -- Case_Sensitive set True (no folding)
Path : Path_Name_Type;
FF : File_Found :=
else
Check_File
- (Project => Project,
- In_Tree => In_Tree,
- Path => Path,
- File_Name => File_Name,
- Display_File_Name => Display_File_Name,
- For_All_Sources => For_All_Sources);
+ (Project => Project,
+ In_Tree => In_Tree,
+ Path => Path,
+ File_Name => File_Name,
+ Display_File_Name =>
+ Display_File_Name,
+ For_All_Sources => For_All_Sources,
+ Allow_Duplicate_Basenames =>
+ Allow_Duplicate_Basenames);
end if;
end;
end if;
----------------------
procedure Look_For_Sources
- (Project : Project_Id;
- In_Tree : Project_Tree_Ref;
- Proc_Data : in out Processing_Data)
+ (Project : Project_Id;
+ In_Tree : Project_Tree_Ref;
+ Proc_Data : in out Processing_Data;
+ Allow_Duplicate_Basenames : Boolean)
is
Iter : Source_Iterator;
Source : Source_Id := No_Source;
OK : Boolean;
Excluded : File_Found;
- Index : Unit_Index;
begin
Excluded := Excluded_Sources_Htable.Get_First;
OK := False;
-- ??? Don't we have a hash table to map files to Source_Id?
+ -- ??? Why can't simply iterate over the sources of the current
+ -- project, as opposed to the whole tree ?
Iter := For_Each_Source (In_Tree);
loop
or else Is_Extending (Project, Source.Project)
then
OK := True;
-
- if Source.Unit /= No_Unit_Index then
- Index :=
- Units_Htable.Get
- (In_Tree.Units_HT, Source.Unit.Name);
- if Index.File_Names (Source.Kind) /= null then
- Index.File_Names (Source.Kind).Path.Name := Slash;
- Index.File_Names (Source.Kind).Naming_Exception :=
- False;
-
- -- ??? Should we simply set (can be done from the
- -- source)
- -- Index.File_Names (Source.Kind) := null;
-
- end if;
- end if;
-
- if Source /= No_Source then
- Source.Locally_Removed := True;
- Source.In_Interfaces := False;
- end if;
+ Source.Locally_Removed := True;
+ Source.In_Interfaces := False;
if Current_Verbosity = High then
Write_Str ("Removing file ");
- Write_Line (Get_Name_String (Excluded.File));
+ Write_Line
+ (Get_Name_String (Excluded.File)
+ & " " & Get_Name_String (Source.Project.Name));
end if;
- Add_Forbidden_File_Name (Excluded.File);
-
else
Error_Msg
(Project, In_Tree,
Excluded.Location);
end if;
- exit;
+ -- We used to exit here, but in fact when a source is
+ -- overridden in an extended project we have only marked the
+ -- original source file if we stop here, not the one from
+ -- the extended project.
+ -- ??? We could exit (and thus be faster) if the loop could
+ -- be done only on the current project, but this isn't
+ -- compatible with the way gprbuild works with excluded
+ -- sources apparently
+
+ -- exit;
end if;
Next (Iter);
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.
else
case Src_Id.Kind is
when Spec =>
- if Src_Id.Other_Part = No_Source then
+ if Other_Part (Src_Id) = No_Source then
Check_Object (Src_Id);
end if;
null;
when Impl =>
- if Src_Id.Other_Part /= No_Source then
+ if Other_Part (Src_Id) /= No_Source then
Check_Object (Src_Id);
else
declare
Src_Ind : constant Source_File_Index :=
- Sinput.P.Load_Project_File
- (Get_Name_String
- (Src_Id.Path.Name));
+ Sinput.P.Load_Project_File
+ (Get_Name_String
+ (Src_Id.Path.Name));
begin
if Sinput.P.Source_File_Is_Subunit
- (Src_Ind)
+ (Src_Ind)
then
Override_Kind (Src_Id, Sep);
else
Load_Naming_Exceptions (Project, In_Tree);
end if;
- Find_Sources (Project, In_Tree, Proc_Data);
+ Find_Sources (Project, In_Tree, Proc_Data, Allow_Duplicate_Basenames);
Mark_Excluded_Sources;
if Get_Mode = Multi_Language then
if UData.File_Names (Unit_Kind) = null
or else
(UData.File_Names (Unit_Kind).File = Canonical_File
- and then UData.File_Names (Unit_Kind).Path.Name = Slash)
+ and then UData.File_Names (Unit_Kind).Locally_Removed)
or else Is_Extending
(Project.Extends, UData.File_Names (Unit_Kind).Project)
then
- if UData.File_Names (Unit_Kind) /= null
- and then UData.File_Names (Unit_Kind).Path.Name = Slash
- then
- Remove_Forbidden_File_Name
- (UData.File_Names (Unit_Kind).File);
- end if;
-
To_Record := True;
-- If the same file is already in the list, do not add it again
Path => (Canonical_Path, Path_Name),
Naming_Exception => Needs_Pragma,
Kind => Unit_Kind,
- Index => Unit_Ind,
- Other_Part => No_Source); -- ??? Can we find file ?
+ Index => Unit_Ind);
Source_Recorded := True;
end if;
end Record_Unit;
Get_Unit
(In_Tree => In_Tree,
Canonical_File_Name => Canonical_File,
- Naming => Project.Naming,
+ Project => Project,
Exception_Id => Exception_Id,
Unit_Name => Unit_Name,
Unit_Kind => Unit_Kind);
Replaced_By.Declared_In_Interfaces := Id.Declared_In_Interfaces;
end if;
+ Id.In_Interfaces := False;
+ Id.Locally_Removed := True;
+
+ -- ??? Should we remove the source from the unit ? The file is not used,
+ -- so probably should not be referenced from the unit. On the other hand
+ -- it might give useful additional info
+ -- if Id.Unit /= null then
+ -- Id.Unit.File_Names (Id.Kind) := null;
+ -- end if;
+
Source := Id.Language.First_Source;
if Source = Id then