OSDN Git Service

2009-07-07 Manuel López-Ibáñez <manu@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-nmsc.adb
index 2bd72bf..5977a8a 100644 (file)
@@ -28,7 +28,6 @@ with GNAT.Directory_Operations;  use GNAT.Directory_Operations;
 with GNAT.HTable;
 
 with Err_Vars; use Err_Vars;
-with Fmap;     use Fmap;
 with Hostparm;
 with MLib.Tgt;
 with Opt;      use Opt;
@@ -94,6 +93,9 @@ package body Prj.Nmsc is
    --  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 ???
 
@@ -240,7 +242,6 @@ package body Prj.Nmsc is
       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);
@@ -275,12 +276,17 @@ package body Prj.Nmsc is
    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;
@@ -311,12 +317,6 @@ package body Prj.Nmsc is
    --  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);
@@ -356,10 +356,10 @@ package body Prj.Nmsc is
       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;
@@ -376,25 +376,29 @@ package body Prj.Nmsc is
    --  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().
@@ -409,6 +413,10 @@ package body Prj.Nmsc is
    --
    --  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;
@@ -433,8 +441,8 @@ package body Prj.Nmsc is
    --  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.
@@ -459,22 +467,22 @@ package body Prj.Nmsc is
    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.
@@ -482,7 +490,7 @@ package body Prj.Nmsc is
    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);
@@ -523,13 +531,16 @@ package body Prj.Nmsc is
    --  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;
@@ -554,13 +565,16 @@ package body Prj.Nmsc is
       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;
@@ -683,7 +697,6 @@ package body Prj.Nmsc is
       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)
@@ -716,11 +729,6 @@ package body Prj.Nmsc is
       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.
@@ -820,8 +828,11 @@ package body Prj.Nmsc is
       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
@@ -872,8 +883,8 @@ package body Prj.Nmsc is
             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;
@@ -895,23 +906,20 @@ package body Prj.Nmsc is
          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
 
@@ -919,11 +927,11 @@ package body Prj.Nmsc is
             --  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);
 
@@ -1669,7 +1677,9 @@ package body Prj.Nmsc is
 
                      --  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
 
@@ -1728,18 +1738,24 @@ package body Prj.Nmsc is
 
                            --  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;
@@ -2395,8 +2411,7 @@ package body Prj.Nmsc is
       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
@@ -2406,7 +2421,7 @@ package body Prj.Nmsc is
               (Project,
                In_Tree,
                "?no compiler specified for language %%" &
-               ", ignoring all its sources",
+                 ", ignoring all its sources",
                No_Location);
 
             if Lang_Index = Project.Languages then
@@ -2533,6 +2548,7 @@ package body Prj.Nmsc is
       Iter      : Source_Iterator;
       Source    : Source_Id;
       Project_2 : Project_Id;
+      Other     : Source_Id;
 
    begin
       if not Interfaces.Default then
@@ -2573,9 +2589,11 @@ package body Prj.Nmsc is
                         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
@@ -2681,18 +2699,23 @@ package body Prj.Nmsc is
    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
@@ -2718,6 +2741,9 @@ package body Prj.Nmsc is
       --  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 --
       ------------------
@@ -2971,7 +2997,6 @@ package body Prj.Nmsc is
          Source            : Source_Id;
          Source_To_Replace : Source_Id := No_Source;
          Other_Project     : Project_Id;
-         Other_Part        : Source_Id := No_Source;
          Iter              : Source_Iterator;
 
       begin
@@ -3049,8 +3074,6 @@ package body Prj.Nmsc is
 
                if Source /= No_Source then
                   if Source.Kind /= Kind then
-                     Other_Part := Source;
-
                      loop
                         Next (Iter);
                         Source := Prj.Element (Iter);
@@ -3066,10 +3089,6 @@ package body Prj.Nmsc is
                      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;
 
@@ -3094,7 +3113,6 @@ package body Prj.Nmsc is
                      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,
@@ -3111,131 +3129,100 @@ package body Prj.Nmsc is
       ---------------------------
 
       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;
 
       -----------------------------
@@ -3260,8 +3247,8 @@ package body Prj.Nmsc is
             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
 
@@ -3366,18 +3353,133 @@ package body Prj.Nmsc is
          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;
@@ -3385,7 +3487,7 @@ package body Prj.Nmsc is
                Check_Naming_Multi_Lang;
          end case;
       end if;
-   end Check_Naming_Schemes;
+   end Check_Package_Naming;
 
    ------------------------------
    -- Check_Library_Attributes --
@@ -4079,182 +4181,67 @@ package body Prj.Nmsc is
       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 :=
@@ -4286,6 +4273,7 @@ package body Prj.Nmsc is
                         "no languages defined for this project",
                         Project.Location);
                      Def_Lang_Id := No_Name;
+
                   else
                      Def_Lang_Id := Name_Ada;
                   end if;
@@ -4298,27 +4286,17 @@ package body Prj.Nmsc is
             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
@@ -4342,34 +4320,10 @@ package body Prj.Nmsc is
                      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;
@@ -4389,6 +4343,7 @@ package body Prj.Nmsc is
       Extending    : Boolean) return Boolean
    is
       Prj : Project_Id;
+
    begin
       if P = Root_Project then
          return True;
@@ -4564,15 +4519,15 @@ package body Prj.Nmsc is
                         --  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
@@ -4613,7 +4568,7 @@ package body Prj.Nmsc is
                            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)
@@ -4661,9 +4616,9 @@ package body Prj.Nmsc is
                         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;
 
@@ -4683,10 +4638,10 @@ package body Prj.Nmsc is
                                 (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
@@ -6116,62 +6071,60 @@ package body Prj.Nmsc is
    -----------------------
 
    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;
@@ -6181,13 +6134,14 @@ package body Prj.Nmsc is
          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))
@@ -6196,6 +6150,7 @@ package body Prj.Nmsc is
                      if Current_Verbosity = High then
                         Write_Line ("  Invalid casing");
                      end if;
+
                      return;
                   end if;
                end loop;
@@ -6208,6 +6163,7 @@ package body Prj.Nmsc is
                      if Current_Verbosity = High then
                         Write_Line ("  Invalid casing");
                      end if;
+
                      return;
                   end if;
                end loop;
@@ -6221,7 +6177,8 @@ package body Prj.Nmsc is
       --  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
@@ -6230,12 +6187,14 @@ package body Prj.Nmsc is
                   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);
@@ -6255,7 +6214,7 @@ package body Prj.Nmsc is
             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'
@@ -6347,7 +6306,7 @@ package body Prj.Nmsc is
    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)
@@ -6356,6 +6315,7 @@ package body Prj.Nmsc is
                    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
@@ -6379,21 +6339,24 @@ package body Prj.Nmsc is
 
       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;
 
@@ -6758,9 +6721,10 @@ package body Prj.Nmsc is
    ------------------
 
    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
@@ -6919,14 +6883,16 @@ package body Prj.Nmsc is
 
       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
@@ -7285,11 +7251,7 @@ package body Prj.Nmsc is
                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);
@@ -7317,11 +7279,20 @@ package body Prj.Nmsc is
 
    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;
 
@@ -7337,12 +7308,13 @@ package body Prj.Nmsc is
    ----------------
 
    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
@@ -7353,7 +7325,6 @@ package body Prj.Nmsc is
       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;
@@ -7369,7 +7340,6 @@ package body Prj.Nmsc is
 
       else
          if Name_Loc.Found then
-
             --  Check if it is OK to have the same file name in several
             --  source directories.
 
@@ -7390,6 +7360,12 @@ package body Prj.Nmsc is
                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
@@ -7414,8 +7390,6 @@ package body Prj.Nmsc is
       end if;
 
       if Check_Name then
-         Other_Part := No_Source;
-
          Check_File_Naming_Schemes
            (In_Tree               => In_Tree,
             Project               => Project,
@@ -7457,7 +7431,9 @@ package body Prj.Nmsc is
                        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
@@ -7475,22 +7451,29 @@ package body Prj.Nmsc is
                   --  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,
@@ -7539,7 +7522,6 @@ package body Prj.Nmsc is
                   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);
@@ -7553,9 +7535,10 @@ package body Prj.Nmsc is
    ------------------------
 
    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;
@@ -7628,12 +7611,16 @@ package body Prj.Nmsc is
 
                         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 :=
@@ -7658,12 +7645,15 @@ package body Prj.Nmsc is
 
                            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;
@@ -7759,9 +7749,10 @@ package body Prj.Nmsc is
    ----------------------
 
    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;
 
@@ -7779,7 +7770,6 @@ package body Prj.Nmsc is
          Source   : Source_Id := No_Source;
          OK       : Boolean;
          Excluded : File_Found;
-         Index    : Unit_Index;
 
       begin
          Excluded := Excluded_Sources_Htable.Get_First;
@@ -7787,6 +7777,8 @@ package body Prj.Nmsc is
             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
@@ -7798,35 +7790,16 @@ package body Prj.Nmsc is
                     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,
@@ -7834,7 +7807,16 @@ package body Prj.Nmsc is
                         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);
@@ -7858,6 +7840,7 @@ package body Prj.Nmsc is
 
       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.
@@ -7914,7 +7897,7 @@ package body Prj.Nmsc is
                   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;
 
@@ -7922,7 +7905,7 @@ package body Prj.Nmsc is
                            null;
 
                         when Impl =>
-                           if Src_Id.Other_Part /= No_Source then
+                           if Other_Part (Src_Id) /= No_Source then
                               Check_Object (Src_Id);
 
                            else
@@ -7930,12 +7913,12 @@ package body Prj.Nmsc is
 
                               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
@@ -7966,7 +7949,7 @@ package body Prj.Nmsc is
             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
@@ -8110,17 +8093,10 @@ package body Prj.Nmsc is
             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
@@ -8198,8 +8174,7 @@ package body Prj.Nmsc is
                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;
@@ -8223,7 +8198,7 @@ package body Prj.Nmsc is
       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);
@@ -8310,6 +8285,16 @@ package body Prj.Nmsc is
          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