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 2cc5fc5..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 ???
 
@@ -192,11 +194,14 @@ package body Prj.Nmsc is
 
    procedure Find_Excluded_Sources
      (Project : Project_Id;
-      In_Tree : Project_Tree_Ref;
-      Data    : Project_Data);
+      In_Tree : Project_Tree_Ref);
    --  Find the list of files that should not be considered as source files
    --  for this project. Sets the list in the Excluded_Sources_Htable.
 
+   procedure Override_Kind (Source : Source_Id; Kind : Source_Kind);
+   --  Override the reference kind for a source file. This properly updates
+   --  the unit data if necessary.
+
    function Hash (Unit : Unit_Info) return Header_Num;
 
    type Name_And_Index is record
@@ -234,11 +239,9 @@ package body Prj.Nmsc is
       Kind                : Source_Kind;
       File_Name           : File_Name_Type;
       Display_File        : File_Name_Type;
-      Lang_Kind           : Language_Kind;
       Naming_Exception    : Boolean := False;
       Path                : Path_Information := No_Path_Information;
-      Alternate_Languages : Alternate_Language_Id := No_Alternate_Language;
-      Other_Part          : Source_Id := No_Source;
+      Alternate_Languages : Language_List := null;
       Unit                : Name_Id   := No_Name;
       Index               : Int       := 0;
       Source_To_Replace   : Source_Id := No_Source);
@@ -257,8 +260,8 @@ package body Prj.Nmsc is
    function Suffix_Matches
      (Filename : String;
       Suffix   : File_Name_Type) return Boolean;
-   --  True if the filename ends with the given suffix. It always returns False
-   --  if Suffix is No_Name
+   --  True if the file name ends with the given suffix. Always returns False
+   --  if Suffix is No_Name.
 
    procedure Replace_Into_Name_Buffer
      (Str         : String;
@@ -273,53 +276,50 @@ 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
-     (Data    : in out Project_Data;
-      Project : Project_Id;
-      In_Tree : Project_Tree_Ref);
-   --  Check the naming scheme part of Data
+   procedure Check_Package_Naming
+     (Project        : Project_Id;
+      In_Tree        : Project_Tree_Ref;
+      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;
-      In_Tree : Project_Tree_Ref;
-      Data    : in out Project_Data);
+     (Project                   : Project_Id;
+      In_Tree                   : Project_Tree_Ref;
+      Compiler_Driver_Mandatory : Boolean);
    --  Check the configuration attributes for the project
+   --  If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
+   --  for each language must be defined, or we will not look for its source
+   --  files.
 
    procedure Check_If_Externally_Built
      (Project : Project_Id;
-      In_Tree : Project_Tree_Ref;
-      Data    : in out Project_Data);
+      In_Tree : Project_Tree_Ref);
    --  Check attribute Externally_Built of project Project in project tree
    --  In_Tree and modify its data Data if it has the value "true".
 
    procedure Check_Interfaces
      (Project : Project_Id;
-      In_Tree : Project_Tree_Ref;
-      Data    : in out Project_Data);
+      In_Tree : Project_Tree_Ref);
    --  If a list of sources is specified in attribute Interfaces, set
    --  In_Interfaces only for the sources specified in the list.
 
    procedure Check_Library_Attributes
      (Project     : Project_Id;
-      In_Tree     : Project_Tree_Ref;
-      Current_Dir : String;
-      Data        : in out Project_Data);
+      In_Tree     : Project_Tree_Ref);
    --  Check the library attributes of project Project in project tree In_Tree
    --  and modify its data Data accordingly.
    --  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;
-      Data    : in out Project_Data);
-   --  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;
-      Data    : in out Project_Data);
+      Project : Project_Id);
    --  Check attribute Languages for the project with data Data in project
    --  tree In_Tree and set the components of Data for all the programming
    --  languages indicated in attribute Languages, if any.
@@ -327,7 +327,6 @@ package body Prj.Nmsc is
    function Check_Project
      (P            : Project_Id;
       Root_Project : Project_Id;
-      In_Tree      : Project_Tree_Ref;
       Extending    : Boolean) return Boolean;
    --  Returns True if P is Root_Project or, if Extending is True, a project
    --  extended by Root_Project.
@@ -335,7 +334,6 @@ package body Prj.Nmsc is
    procedure Check_Stand_Alone_Library
      (Project     : Project_Id;
       In_Tree     : Project_Tree_Ref;
-      Data        : in out Project_Data;
       Current_Dir : String;
       Extending   : Boolean);
    --  Check if project Project in project tree In_Tree is a Stand-Alone
@@ -356,12 +354,12 @@ package body Prj.Nmsc is
    procedure Find_Ada_Sources
      (Project               : Project_Id;
       In_Tree               : Project_Tree_Ref;
-      Data                  : in out Project_Data;
-      Explicit_Sources_Only : Boolean);
-   --  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
+      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
    --  scheme are recorded.
 
    function Compute_Directory_Last (Dir : String) return Natural;
@@ -378,27 +376,29 @@ package body Prj.Nmsc is
    --  Error_Report.
 
    procedure Search_Directories
-     (Project         : Project_Id;
-      In_Tree         : Project_Tree_Ref;
-      Data            : in out Project_Data;
-      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;
-      Data              : in out Project_Data;
-      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().
@@ -413,14 +413,17 @@ 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;
-      Data                  : in out Project_Data;
+      Project               : Project_Id;
       File_Name             : File_Name_Type;
-      Alternate_Languages   : out Alternate_Language_Id;
+      Alternate_Languages   : out Language_List;
       Language              : out Language_Ptr;
-      Language_Name         : out Name_Id;
       Display_Language_Name : out Name_Id;
       Unit                  : out Name_Id;
       Lang_Kind             : out Language_Kind;
@@ -438,10 +441,9 @@ 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;
-      Current_Dir : String;
-      Data    : in out Project_Data);
+     (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.
    --
@@ -450,8 +452,7 @@ package body Prj.Nmsc is
 
    procedure Get_Mains
      (Project : Project_Id;
-      In_Tree : Project_Tree_Ref;
-      Data    : in out Project_Data);
+      In_Tree : Project_Tree_Ref);
    --  Get the mains of a project from attribute Main, if it exists, and put
    --  them in the project data.
 
@@ -464,24 +465,24 @@ package body Prj.Nmsc is
    --  Source_Names.
 
    procedure Find_Sources
-     (Project     : Project_Id;
-      In_Tree     : Project_Tree_Ref;
-      Data        : in out Project_Data);
+     (Project   : Project_Id;
+      In_Tree   : Project_Tree_Ref;
+      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.
@@ -489,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);
@@ -509,32 +510,37 @@ package body Prj.Nmsc is
      (Project          : Project_Id;
       In_Tree          : Project_Tree_Ref;
       Name             : File_Name_Type;
-      Parent           : Path_Name_Type;
-      Dir              : out Path_Name_Type;
-      Display          : out Path_Name_Type;
+      Path             : out Path_Information;
+      Dir_Exists       : out Boolean;
       Create           : String := "";
-      Current_Dir      : String;
       Location         : Source_Ptr := No_Location;
+      Must_Exist       : Boolean := True;
       Externally_Built : Boolean := False);
-   --  Locate a directory. Name is the directory name. Parent is the root
-   --  directory, if Name a relative path name. Dir is set to the canonical
-   --  case path name of the directory, and Display is the directory path name
-   --  for display purposes. If the directory does not exist and Setup_Projects
+   --  Locate a directory. Name is the directory name.
+   --  Relative paths are resolved relative to the project's directory.
+   --  If the directory does not exist and Setup_Projects
    --  is True and Create is a non null string, an attempt is made to create
-   --  the directory. If the directory does not exist and Setup_Projects is
-   --  false, then Dir and Display are set to No_Name.
+   --  the directory.
+   --  If the directory does not exist, it is either created if Setup_Projects
+   --  is False (and then returned), or simply returned without checking for
+   --  its existence (if Must_Exist is False) or No_Path_Information is
+   --  returned. In all cases, Dir_Exists indicates whether the directory now
+   --  exists.
    --
-   --  Current_Dir should represent the current directory, and is passed for
-   --  efficiency to avoid system calls to recompute it.
+   --  Create is also used for debugging traces to show which path we are
+   --  computing
 
    procedure Look_For_Sources
-     (Project     : Project_Id;
-      In_Tree     : Project_Tree_Ref;
-      Data        : in out Project_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,18 +560,21 @@ package body Prj.Nmsc is
       Path_Name       : Path_Name_Type;
       Project         : Project_Id;
       In_Tree         : Project_Tree_Ref;
-      Data            : in out Project_Data;
+      Proc_Data       : in out Processing_Data;
       Ada_Language    : Language_Ptr;
       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;
@@ -577,7 +586,7 @@ package body Prj.Nmsc is
    --  when there are no sources for language Lang_Name.
 
    procedure Show_Source_Dirs
-     (Data : Project_Data; In_Tree : Project_Tree_Ref);
+     (Project : Project_Id; In_Tree : Project_Tree_Ref);
    --  List all the source directories of a project
 
    procedure Warn_If_Not_Sources
@@ -633,15 +642,27 @@ package body Prj.Nmsc is
      (Filename : String;
       Suffix   : File_Name_Type) return Boolean
    is
+      Min_Prefix_Length : Natural := 0;
    begin
-      if Suffix = No_File then
+      if Suffix = No_File or else Suffix = Empty_File then
          return False;
       end if;
 
       declare
          Suf : constant String := Get_Name_String (Suffix);
       begin
-         return Filename'Length > Suf'Length
+
+         --  The file name must end with the suffix (which is not an extension)
+         --  For instance a suffix "configure.in" must match a file with the
+         --  same name. To avoid dummy cases, though, a suffix starting with
+         --  '.' requires a file that is at least one character longer ('.cpp'
+         --  should not match a file with the same name)
+
+         if Suf (Suf'First) = '.' then
+            Min_Prefix_Length := 1;
+         end if;
+
+         return Filename'Length >= Suf'Length + Min_Prefix_Length
            and then Filename
              (Filename'Last - Suf'Length + 1 .. Filename'Last) = Suf;
       end;
@@ -673,16 +694,15 @@ package body Prj.Nmsc is
       Kind                : Source_Kind;
       File_Name           : File_Name_Type;
       Display_File        : File_Name_Type;
-      Lang_Kind           : Language_Kind;
       Naming_Exception    : Boolean := False;
       Path                : Path_Information := No_Path_Information;
-      Alternate_Languages : Alternate_Language_Id := No_Alternate_Language;
-      Other_Part          : Source_Id := No_Source;
+      Alternate_Languages : Language_List := null;
       Unit                : Name_Id   := No_Name;
       Index               : Int       := 0;
       Source_To_Replace   : Source_Id := No_Source)
    is
       Config   : constant Language_Config := Lang_Id.Config;
+      UData    : Unit_Index;
 
    begin
       Id := new Source_Data;
@@ -691,7 +711,7 @@ package body Prj.Nmsc is
          Write_Str ("Adding source File: ");
          Write_Str (Get_Name_String (File_Name));
 
-         if Lang_Kind = Unit_Based then
+         if Lang_Id.Config.Kind = Unit_Based then
             Write_Str (" Unit: ");
             --  ??? in gprclean, it seems we sometimes pass an empty Unit name
             --  (see test extended_projects)
@@ -707,29 +727,42 @@ package body Prj.Nmsc is
 
       Id.Project             := Project;
       Id.Language            := Lang_Id;
-      Id.Lang_Kind           := Lang_Kind;
-      Id.Compiled            := Lang_Id.Config.Compiler_Driver /=
-                                                             Empty_File_Name;
       Id.Kind                := Kind;
       Id.Alternate_Languages := Alternate_Languages;
-      Id.Other_Part          := Other_Part;
 
-      Id.Object_Exists       := Config.Object_Generated;
-      Id.Object_Linked       := Config.Objects_Linked;
+      --  Add the source id to the Unit_Sources_HT hash table, if the unit name
+      --  is not null.
+
+      if Unit /= No_Name then
+         Unit_Sources_Htable.Set (In_Tree.Unit_Sources_HT, Unit, Id);
+
+         --  ??? Record_Unit has already fetched that earlier, so this isn't
+         --  the most efficient way. But we can't really pass a parameter since
+         --  Process_Exceptions_Unit_Based and Check_File haven't looked it up.
+
+         UData := Units_Htable.Get (In_Tree.Units_HT, Unit);
+
+         if UData = No_Unit_Index then
+            UData      := new Unit_Data;
+            UData.Name := Unit;
+            Units_Htable.Set (In_Tree.Units_HT, Unit, UData);
+         end if;
+
+         Id.Unit := UData;
+
+         --  Note that this updates Unit information as well
 
-      if Other_Part /= No_Source then
-         Other_Part.Other_Part := Id;
+         Override_Kind (Id, Kind);
       end if;
 
-      Id.Unit                := Unit;
-      Id.Index               := Index;
-      Id.File                := File_Name;
-      Id.Display_File        := Display_File;
-      Id.Dependency          := Lang_Id.Config.Dependency_Kind;
-      Id.Dep_Name            := Dependency_Name (File_Name, Id.Dependency);
-      Id.Naming_Exception    := Naming_Exception;
+      Id.Index            := Index;
+      Id.File             := File_Name;
+      Id.Display_File     := Display_File;
+      Id.Dep_Name         := Dependency_Name
+                               (File_Name, Lang_Id.Config.Dependency_Kind);
+      Id.Naming_Exception := Naming_Exception;
 
-      if Id.Compiled and then Id.Object_Exists then
+      if Is_Compilable (Id) and then Config.Object_Generated then
          Id.Object   := Object_Name (File_Name, Config.Object_File_Suffix);
          Id.Switches := Switches_Name (File_Name);
       end if;
@@ -739,13 +772,6 @@ package body Prj.Nmsc is
          Source_Paths_Htable.Set (In_Tree.Source_Paths_HT, Path.Name, Id);
       end if;
 
-      --  Add the source id to the Unit_Sources_HT hash table, if the unit name
-      --  is not null.
-
-      if Unit /= No_Name then
-         Unit_Sources_Htable.Set (In_Tree.Unit_Sources_HT, Unit, Id);
-      end if;
-
       --  Add the source to the language list
 
       Id.Next_In_Lang := Lang_Id.First_Source;
@@ -762,8 +788,7 @@ package body Prj.Nmsc is
 
    function ALI_File_Name (Source : String) return String is
    begin
-      --  If the source name has an extension, then replace it with
-      --  the ALI suffix.
+      --  If the source name has extension, replace it with the ALI suffix
 
       for Index in reverse Source'First + 1 .. Source'Last loop
          if Source (Index) = '.' then
@@ -771,8 +796,7 @@ package body Prj.Nmsc is
          end if;
       end loop;
 
-      --  If there is no dot, or if it is the first character, just add the
-      --  ALI suffix.
+      --  If no dot, or if it is the first character, just add the ALI suffix
 
       return Source & ALI_Suffix;
    end ALI_File_Name;
@@ -797,13 +821,18 @@ package body Prj.Nmsc is
    -----------
 
    procedure Check
-     (Project         : Project_Id;
-      In_Tree         : Project_Tree_Ref;
-      Report_Error    : Put_Line_Access;
-      When_No_Sources : Error_Warning;
-      Current_Dir     : String)
+     (Project                   : Project_Id;
+      In_Tree                   : Project_Tree_Ref;
+      Report_Error              : Put_Line_Access;
+      When_No_Sources           : Error_Warning;
+      Current_Dir               : String;
+      Proc_Data                 : in out Processing_Data;
+      Is_Config_File            : Boolean;
+      Compiler_Driver_Mandatory : Boolean;
+      Allow_Duplicate_Basenames : Boolean)
    is
-      Data      : Project_Data renames In_Tree.Projects.Table (Project);
+      Specs : Array_Element_Id;
+      Bodies : Array_Element_Id;
       Extending : Boolean := False;
 
    begin
@@ -812,55 +841,85 @@ package body Prj.Nmsc is
 
       Recursive_Dirs.Reset;
 
-      Check_If_Externally_Built (Project, In_Tree, Data);
+      Check_If_Externally_Built (Project, In_Tree);
 
       --  Object, exec and source directories
 
-      Get_Directories (Project, In_Tree, Current_Dir, Data);
+      Get_Directories (Project, In_Tree, Current_Dir);
 
       --  Get the programming languages
 
-      Check_Programming_Languages (In_Tree, Project, Data);
+      Check_Programming_Languages (In_Tree, Project);
 
-      if Data.Qualifier = Dry and then Data.Source_Dirs /= Nil_String then
-         Error_Msg
-           (Project, In_Tree,
-            "an abstract project needs to have no language, no sources " &
-            "or no source directories",
-            Data.Location);
+      if Project.Qualifier = Dry
+        and then Project.Source_Dirs /= Nil_String
+      then
+         declare
+            Source_Dirs      : constant Variable_Value :=
+                                 Util.Value_Of
+                                   (Name_Source_Dirs,
+                                    Project.Decl.Attributes, In_Tree);
+            Source_Files     : constant Variable_Value :=
+                                 Util.Value_Of
+                                   (Name_Source_Files,
+                                    Project.Decl.Attributes, In_Tree);
+            Source_List_File : constant Variable_Value :=
+                                 Util.Value_Of
+                                   (Name_Source_List_File,
+                                    Project.Decl.Attributes, In_Tree);
+            Languages        : constant Variable_Value :=
+                                 Util.Value_Of
+                                   (Name_Languages,
+                                    Project.Decl.Attributes, In_Tree);
+
+         begin
+            if Source_Dirs.Values  = Nil_String
+              and then Source_Files.Values = Nil_String
+              and then Languages.Values = Nil_String
+              and then Source_List_File.Default
+            then
+               Project.Source_Dirs := Nil_String;
+
+            else
+               Error_Msg
+                 (Project, In_Tree,
+                  "at least one of Source_Files, Source_Dirs or Languages " &
+                  "must be declared empty for an abstract project",
+                  Project.Location);
+            end if;
+         end;
       end if;
 
       --  Check configuration in multi language mode
 
       if Must_Check_Configuration then
-         Check_Configuration (Project, In_Tree, Data);
+         Check_Configuration
+           (Project, In_Tree,
+            Compiler_Driver_Mandatory => Compiler_Driver_Mandatory);
       end if;
 
       --  Library attributes
 
-      Check_Library_Attributes (Project, In_Tree, Current_Dir, Data);
+      Check_Library_Attributes (Project, In_Tree);
 
       if Current_Verbosity = High then
-         Show_Source_Dirs (Data, In_Tree);
+         Show_Source_Dirs (Project, In_Tree);
       end if;
 
-      Check_Package_Naming (Project, In_Tree, Data);
-
-      Extending := Data.Extends /= No_Project;
+      Extending := Project.Extends /= No_Project;
 
-      Check_Naming_Schemes (Data, Project, In_Tree);
+      Check_Package_Naming (Project, In_Tree, Is_Config_File, Bodies, Specs);
 
       if Get_Mode = Ada_Only then
-         Prepare_Ada_Naming_Exceptions
-           (Data.Naming.Bodies, In_Tree, Body_Part);
-         Prepare_Ada_Naming_Exceptions
-           (Data.Naming.Specs, In_Tree, Specification);
+         Prepare_Ada_Naming_Exceptions (Bodies, In_Tree, Impl);
+         Prepare_Ada_Naming_Exceptions (Specs, In_Tree, Spec);
       end if;
 
       --  Find the sources
 
-      if Data.Source_Dirs /= Nil_String then
-         Look_For_Sources (Project, In_Tree, Data);
+      if Project.Source_Dirs /= Nil_String then
+         Look_For_Sources
+           (Project, In_Tree, Proc_Data, Allow_Duplicate_Basenames);
 
          if Get_Mode = Ada_Only then
 
@@ -868,28 +927,27 @@ package body Prj.Nmsc is
             --  of this project file.
 
             Warn_If_Not_Sources
-              (Project, In_Tree, Data.Naming.Bodies,
+              (Project, In_Tree, Bodies,
                Specs     => False,
                Extending => Extending);
             Warn_If_Not_Sources
-              (Project, In_Tree, Data.Naming.Specs,
+              (Project, In_Tree, Specs,
                Specs     => True,
                Extending => Extending);
 
          elsif Get_Mode = Multi_Language and then
-               (not Data.Externally_Built) and then
+               (not Project.Externally_Built) and then
                (not Extending)
          then
             declare
                Language      : Language_Ptr;
                Source        : Source_Id;
-               Alt_Lang      : Alternate_Language_Id;
-               Alt_Lang_Data : Alternate_Language_Data;
+               Alt_Lang      : Language_List;
                Continuation  : Boolean := False;
                Iter          : Source_Iterator;
 
             begin
-               Language := Data.Languages;
+               Language := Project.Languages;
                while Language /= No_Language_Index loop
 
                   --  If there are no sources for this language, check whether
@@ -905,14 +963,10 @@ package body Prj.Nmsc is
                           or else Source.Language = Language;
 
                         Alt_Lang := Source.Alternate_Languages;
-
-                        Alternate_Loop :
-                        while Alt_Lang /= No_Alternate_Language loop
-                           Alt_Lang_Data := In_Tree.Alt_Langs.Table (Alt_Lang);
-                           exit Source_Loop
-                           when Alt_Lang_Data.Language = Language;
-                           Alt_Lang := Alt_Lang_Data.Next;
-                        end loop Alternate_Loop;
+                        while Alt_Lang /= null loop
+                           exit Source_Loop when Alt_Lang.Language = Language;
+                           Alt_Lang := Alt_Lang.Next;
+                        end loop;
 
                         Next (Iter);
                      end loop Source_Loop;
@@ -922,7 +976,7 @@ package body Prj.Nmsc is
                           (Project,
                            Get_Name_String (Language.Display_Name),
                            In_Tree,
-                           Data.Location,
+                           Project.Location,
                            Continuation);
                         Continuation := True;
                      end if;
@@ -939,23 +993,19 @@ package body Prj.Nmsc is
          --  If a list of sources is specified in attribute Interfaces, set
          --  In_Interfaces only for the sources specified in the list.
 
-         Check_Interfaces (Project, In_Tree, Data);
+         Check_Interfaces (Project, In_Tree);
       end if;
 
       --  If it is a library project file, check if it is a standalone library
 
-      if Data.Library then
+      if Project.Library then
          Check_Stand_Alone_Library
-           (Project, In_Tree, Data, Current_Dir, Extending);
+           (Project, In_Tree, Current_Dir, Extending);
       end if;
 
       --  Put the list of Mains, if any, in the project data
 
-      Get_Mains (Project, In_Tree, Data);
-
-      --  Update the project data in the Projects table
-
-      In_Tree.Projects.Table (Project) := Data;
+      Get_Mains (Project, In_Tree);
 
       Free_Ada_Naming_Exceptions;
    end Check;
@@ -1149,9 +1199,9 @@ package body Prj.Nmsc is
    -------------------------
 
    procedure Check_Configuration
-     (Project : Project_Id;
-      In_Tree : Project_Tree_Ref;
-      Data    : in out Project_Data)
+     (Project                   : Project_Id;
+      In_Tree                   : Project_Tree_Ref;
+      Compiler_Driver_Mandatory : Boolean)
    is
       Dot_Replacement : File_Name_Type := No_File;
       Casing          : Casing_Type    := All_Lower_Case;
@@ -1163,13 +1213,6 @@ package body Prj.Nmsc is
       Prev_Index : Language_Ptr := No_Language_Index;
       --  The index of the previous language
 
-      Current_Language : Name_Id := No_Name;
-      --  The name of the language
-
-      procedure Get_Language_Index_Of (Language : Name_Id);
-      --  Get the language index of Language, if Language is one of the
-      --  languages of the project.
-
       procedure Process_Project_Level_Simple_Attributes;
       --  Process the simple attributes at the project level
 
@@ -1179,35 +1222,6 @@ package body Prj.Nmsc is
       procedure Process_Packages;
       --  Read the packages of the project
 
-      ---------------------------
-      -- Get_Language_Index_Of --
-      ---------------------------
-
-      procedure Get_Language_Index_Of (Language : Name_Id) is
-         Real_Language : Name_Id;
-
-      begin
-         Get_Name_String (Language);
-         To_Lower (Name_Buffer (1 .. Name_Len));
-         Real_Language := Name_Find;
-
-         --  Nothing to do if the language is the same as the current language
-
-         if Current_Language /= Real_Language then
-            Lang_Index := Data.Languages;
-            while Lang_Index /= No_Language_Index loop
-               exit when Lang_Index.Name = Real_Language;
-               Lang_Index := Lang_Index.Next;
-            end loop;
-
-            if Lang_Index = No_Language_Index then
-               Current_Language := No_Name;
-            else
-               Current_Language := Real_Language;
-            end if;
-         end if;
-      end Get_Language_Index_Of;
-
       ----------------------
       -- Process_Packages --
       ----------------------
@@ -1260,46 +1274,49 @@ package body Prj.Nmsc is
 
                      --  Get the name of the language
 
-                     Get_Language_Index_Of (Element.Index);
+                     Lang_Index :=
+                       Get_Language_From_Name
+                         (Project, Get_Name_String (Element.Index));
 
                      if Lang_Index /= No_Language_Index then
                         case Current_Array.Name is
-                        when Name_Driver =>
+                           when Name_Driver =>
 
-                           --  Attribute Driver (<language>)
+                              --  Attribute Driver (<language>)
 
-                           Lang_Index.Config.Binder_Driver :=
-                             File_Name_Type (Element.Value.Value);
+                              Lang_Index.Config.Binder_Driver :=
+                                File_Name_Type (Element.Value.Value);
 
-                        when Name_Required_Switches =>
-                           Put (Into_List =>
+                           when Name_Required_Switches =>
+                              Put
+                                (Into_List =>
                                    Lang_Index.Config.Binder_Required_Switches,
-                                From_List => Element.Value.Values,
-                                In_Tree   => In_Tree);
+                                 From_List => Element.Value.Values,
+                                 In_Tree   => In_Tree);
 
-                        when Name_Prefix =>
+                           when Name_Prefix =>
 
-                           --  Attribute Prefix (<language>)
+                              --  Attribute Prefix (<language>)
 
-                           Lang_Index.Config.Binder_Prefix :=
-                             Element.Value.Value;
+                              Lang_Index.Config.Binder_Prefix :=
+                                Element.Value.Value;
 
-                        when Name_Objects_Path =>
+                           when Name_Objects_Path =>
 
-                           --  Attribute Objects_Path (<language>)
+                              --  Attribute Objects_Path (<language>)
 
-                           Lang_Index.Config.Objects_Path :=
-                             Element.Value.Value;
+                              Lang_Index.Config.Objects_Path :=
+                                Element.Value.Value;
 
-                        when Name_Objects_Path_File =>
+                           when Name_Objects_Path_File =>
 
-                           --  Attribute Objects_Path (<language>)
+                              --  Attribute Objects_Path (<language>)
 
-                           Lang_Index.Config.Objects_Path_File :=
-                             Element.Value.Value;
+                              Lang_Index.Config.Objects_Path_File :=
+                                Element.Value.Value;
 
-                        when others =>
-                           null;
+                           when others =>
+                              null;
                         end case;
                      end if;
                   end if;
@@ -1333,7 +1350,7 @@ package body Prj.Nmsc is
                      --  Attribute Executable_Suffix: the suffix of the
                      --  executables.
 
-                     Data.Config.Executable_Suffix :=
+                     Project.Config.Executable_Suffix :=
                        Attribute.Value.Value;
                   end if;
                end if;
@@ -1368,7 +1385,8 @@ package body Prj.Nmsc is
 
                      --  Get the name of the language
 
-                     Get_Language_Index_Of (Element.Index);
+                     Lang_Index := Get_Language_From_Name
+                       (Project, Get_Name_String (Element.Index));
 
                      if Lang_Index /= No_Language_Index then
                         case Current_Array.Name is
@@ -1443,14 +1461,21 @@ package body Prj.Nmsc is
 
                            --  Attribute Driver (<language>)
 
-                           Get_Name_String (Element.Value.Value);
-
                            Lang_Index.Config.Compiler_Driver :=
-                               File_Name_Type (Element.Value.Value);
+                             File_Name_Type (Element.Value.Value);
 
-                        when Name_Required_Switches =>
+                        when Name_Required_Switches |
+                             Name_Leading_Required_Switches =>
                            Put (Into_List =>
-                                  Lang_Index.Config.Compiler_Required_Switches,
+                                  Lang_Index.Config.
+                                    Compiler_Leading_Required_Switches,
+                                From_List => Element.Value.Values,
+                                In_Tree   => In_Tree);
+
+                        when Name_Trailing_Required_Switches =>
+                           Put (Into_List =>
+                                  Lang_Index.Config.
+                                    Compiler_Trailing_Required_Switches,
                                 From_List => Element.Value.Values,
                                 In_Tree   => In_Tree);
 
@@ -1481,6 +1506,12 @@ package body Prj.Nmsc is
                                 Element.Value.Value;
                            end if;
 
+                        when Name_Object_File_Switches =>
+                           Put (Into_List =>
+                                  Lang_Index.Config.Object_File_Switches,
+                                From_List => Element.Value.Values,
+                                In_Tree   => In_Tree);
+
                         when Name_Pic_Option =>
 
                            --  Attribute Compiler_Pic_Option (<language>)
@@ -1646,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
 
@@ -1696,26 +1729,33 @@ package body Prj.Nmsc is
 
                   --  Get the name of the language
 
-                  Get_Language_Index_Of (Element.Index);
+                  Lang_Index := Get_Language_From_Name
+                    (Project, Get_Name_String (Element.Index));
 
                   if Lang_Index /= No_Language_Index then
                      case Current_Array.Name is
-                        when Name_Specification_Suffix | Name_Spec_Suffix =>
+                        when Name_Spec_Suffix | Name_Specification_Suffix =>
 
                            --  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;
@@ -1750,15 +1790,15 @@ package body Prj.Nmsc is
 
                      --  Attribute Linker'Driver: the default linker to use
 
-                     Data.Config.Linker :=
+                     Project.Config.Linker :=
                        Path_Name_Type (Attribute.Value.Value);
 
                      --  Linker'Driver is also used to link shared libraries
                      --  if the obsolescent attribute Library_GCC has not been
                      --  specified.
 
-                     if Data.Config.Shared_Lib_Driver = No_File then
-                        Data.Config.Shared_Lib_Driver :=
+                     if Project.Config.Shared_Lib_Driver = No_File then
+                        Project.Config.Shared_Lib_Driver :=
                           File_Name_Type (Attribute.Value.Value);
                      end if;
 
@@ -1767,17 +1807,16 @@ package body Prj.Nmsc is
                      --  Attribute Required_Switches: the minimum
                      --  options to use when invoking the linker
 
-                     Put (Into_List =>
-                            Data.Config.Minimum_Linker_Options,
+                     Put (Into_List => Project.Config.Minimum_Linker_Options,
                           From_List => Attribute.Value.Values,
                           In_Tree   => In_Tree);
 
                   elsif Attribute.Name = Name_Map_File_Option then
-                     Data.Config.Map_File_Option := Attribute.Value.Value;
+                     Project.Config.Map_File_Option := Attribute.Value.Value;
 
                   elsif Attribute.Name = Name_Max_Command_Line_Length then
                      begin
-                        Data.Config.Max_Command_Line_Length :=
+                        Project.Config.Max_Command_Line_Length :=
                           Natural'Value (Get_Name_String
                                          (Attribute.Value.Value));
 
@@ -1800,16 +1839,16 @@ package body Prj.Nmsc is
                         Name := Name_Find;
 
                         if Name = Name_None then
-                           Data.Config.Resp_File_Format := None;
+                           Project.Config.Resp_File_Format := None;
 
                         elsif Name = Name_Gnu then
-                           Data.Config.Resp_File_Format := GNU;
+                           Project.Config.Resp_File_Format := GNU;
 
                         elsif Name = Name_Object_List then
-                           Data.Config.Resp_File_Format := Object_List;
+                           Project.Config.Resp_File_Format := Object_List;
 
                         elsif Name = Name_Option_List then
-                           Data.Config.Resp_File_Format := Option_List;
+                           Project.Config.Resp_File_Format := Option_List;
 
                         else
                            Error_Msg
@@ -1821,8 +1860,7 @@ package body Prj.Nmsc is
                      end;
 
                   elsif Attribute.Name = Name_Response_File_Switches then
-                     Put (Into_List =>
-                            Data.Config.Resp_File_Options,
+                     Put (Into_List => Project.Config.Resp_File_Options,
                           From_List => Attribute.Value.Values,
                           In_Tree   => In_Tree);
                   end if;
@@ -1835,7 +1873,7 @@ package body Prj.Nmsc is
       --  Start of processing for Process_Packages
 
       begin
-         Packages := Data.Decl.Packages;
+         Packages := Project.Decl.Packages;
          while Packages /= No_Package loop
             Element := In_Tree.Packages.Table (Packages);
 
@@ -1891,7 +1929,7 @@ package body Prj.Nmsc is
       begin
          --  Process non associated array attribute at project level
 
-         Attribute_Id := Data.Decl.Attributes;
+         Attribute_Id := Project.Decl.Attributes;
          while Attribute_Id /= No_Variable loop
             Attribute :=
               In_Tree.Variable_Elements.Table (Attribute_Id);
@@ -1901,14 +1939,14 @@ package body Prj.Nmsc is
 
                   --  Attribute Target: the target specified
 
-                  Data.Config.Target := Attribute.Value.Value;
+                  Project.Config.Target := Attribute.Value.Value;
 
                elsif Attribute.Name = Name_Library_Builder then
 
                   --  Attribute Library_Builder: the application to invoke
                   --  to build libraries.
 
-                  Data.Config.Library_Builder :=
+                  Project.Config.Library_Builder :=
                     Path_Name_Type (Attribute.Value.Value);
 
                elsif Attribute.Name = Name_Archive_Builder then
@@ -1926,7 +1964,7 @@ package body Prj.Nmsc is
                         Attribute.Value.Location);
                   end if;
 
-                  Put (Into_List => Data.Config.Archive_Builder,
+                  Put (Into_List => Project.Config.Archive_Builder,
                        From_List => List,
                        In_Tree   => In_Tree);
 
@@ -1939,7 +1977,8 @@ package body Prj.Nmsc is
 
                   if List /= Nil_String then
                      Put
-                       (Into_List => Data.Config.Archive_Builder_Append_Option,
+                       (Into_List =>
+                          Project.Config.Archive_Builder_Append_Option,
                         From_List => List,
                         In_Tree   => In_Tree);
                   end if;
@@ -1960,7 +1999,7 @@ package body Prj.Nmsc is
                         Attribute.Value.Location);
                   end if;
 
-                  Put (Into_List => Data.Config.Archive_Indexer,
+                  Put (Into_List => Project.Config.Archive_Indexer,
                        From_List => List,
                        In_Tree   => In_Tree);
 
@@ -1980,12 +2019,12 @@ package body Prj.Nmsc is
                         Attribute.Value.Location);
                   end if;
 
-                  Put (Into_List => Data.Config.Lib_Partial_Linker,
+                  Put (Into_List => Project.Config.Lib_Partial_Linker,
                        From_List => List,
                        In_Tree   => In_Tree);
 
                elsif Attribute.Name = Name_Library_GCC then
-                  Data.Config.Shared_Lib_Driver :=
+                  Project.Config.Shared_Lib_Driver :=
                     File_Name_Type (Attribute.Value.Value);
                   Error_Msg
                     (Project,
@@ -1995,7 +2034,7 @@ package body Prj.Nmsc is
                      Attribute.Value.Location);
 
                elsif Attribute.Name = Name_Archive_Suffix then
-                  Data.Config.Archive_Suffix :=
+                  Project.Config.Archive_Suffix :=
                     File_Name_Type (Attribute.Value.Value);
 
                elsif Attribute.Name = Name_Linker_Executable_Option then
@@ -2013,7 +2052,7 @@ package body Prj.Nmsc is
                         Attribute.Value.Location);
                   end if;
 
-                  Put (Into_List => Data.Config.Linker_Executable_Option,
+                  Put (Into_List => Project.Config.Linker_Executable_Option,
                        From_List => List,
                        In_Tree   => In_Tree);
 
@@ -2033,7 +2072,8 @@ package body Prj.Nmsc is
                         Attribute.Value.Location);
                   end if;
 
-                  Data.Config.Linker_Lib_Dir_Option := Attribute.Value.Value;
+                  Project.Config.Linker_Lib_Dir_Option :=
+                    Attribute.Value.Value;
 
                elsif Attribute.Name = Name_Linker_Lib_Name_Option then
 
@@ -2051,7 +2091,8 @@ package body Prj.Nmsc is
                         Attribute.Value.Location);
                   end if;
 
-                  Data.Config.Linker_Lib_Name_Option := Attribute.Value.Value;
+                  Project.Config.Linker_Lib_Name_Option :=
+                    Attribute.Value.Value;
 
                elsif Attribute.Name = Name_Run_Path_Option then
 
@@ -2061,7 +2102,7 @@ package body Prj.Nmsc is
                   List := Attribute.Value.Values;
 
                   if List /= Nil_String then
-                     Put (Into_List => Data.Config.Run_Path_Option,
+                     Put (Into_List => Project.Config.Run_Path_Option,
                           From_List => List,
                           In_Tree   => In_Tree);
                   end if;
@@ -2070,7 +2111,7 @@ package body Prj.Nmsc is
                   declare
                      pragma Unsuppress (All_Checks);
                   begin
-                     Data.Config.Separate_Run_Path_Options :=
+                     Project.Config.Separate_Run_Path_Options :=
                        Boolean'Value (Get_Name_String (Attribute.Value.Value));
                   exception
                      when Constraint_Error =>
@@ -2087,7 +2128,7 @@ package body Prj.Nmsc is
                   declare
                      pragma Unsuppress (All_Checks);
                   begin
-                     Data.Config.Lib_Support :=
+                     Project.Config.Lib_Support :=
                        Library_Support'Value (Get_Name_String
                                               (Attribute.Value.Value));
                   exception
@@ -2102,18 +2143,18 @@ package body Prj.Nmsc is
                   end;
 
                elsif Attribute.Name = Name_Shared_Library_Prefix then
-                  Data.Config.Shared_Lib_Prefix :=
+                  Project.Config.Shared_Lib_Prefix :=
                     File_Name_Type (Attribute.Value.Value);
 
                elsif Attribute.Name = Name_Shared_Library_Suffix then
-                  Data.Config.Shared_Lib_Suffix :=
+                  Project.Config.Shared_Lib_Suffix :=
                     File_Name_Type (Attribute.Value.Value);
 
                elsif Attribute.Name = Name_Symbolic_Link_Supported then
                   declare
                      pragma Unsuppress (All_Checks);
                   begin
-                     Data.Config.Symbolic_Link_Supported :=
+                     Project.Config.Symbolic_Link_Supported :=
                        Boolean'Value (Get_Name_String
                                       (Attribute.Value.Value));
                   exception
@@ -2133,7 +2174,7 @@ package body Prj.Nmsc is
                   declare
                      pragma Unsuppress (All_Checks);
                   begin
-                     Data.Config.Lib_Maj_Min_Id_Supported :=
+                     Project.Config.Lib_Maj_Min_Id_Supported :=
                        Boolean'Value (Get_Name_String
                                       (Attribute.Value.Value));
                   exception
@@ -2151,7 +2192,7 @@ package body Prj.Nmsc is
                   declare
                      pragma Unsuppress (All_Checks);
                   begin
-                     Data.Config.Auto_Init_Supported :=
+                     Project.Config.Auto_Init_Supported :=
                        Boolean'Value (Get_Name_String (Attribute.Value.Value));
                   exception
                      when Constraint_Error =>
@@ -2168,7 +2209,7 @@ package body Prj.Nmsc is
                   List := Attribute.Value.Values;
 
                   if List /= Nil_String then
-                     Put (Into_List => Data.Config.Shared_Lib_Min_Options,
+                     Put (Into_List => Project.Config.Shared_Lib_Min_Options,
                           From_List => List,
                           In_Tree   => In_Tree);
                   end if;
@@ -2177,7 +2218,7 @@ package body Prj.Nmsc is
                   List := Attribute.Value.Values;
 
                   if List /= Nil_String then
-                     Put (Into_List => Data.Config.Lib_Version_Options,
+                     Put (Into_List => Project.Config.Lib_Version_Options,
                           From_List => List,
                           In_Tree   => In_Tree);
                   end if;
@@ -2202,7 +2243,7 @@ package body Prj.Nmsc is
       begin
          --  Process the associative array attributes at project level
 
-         Current_Array_Id := Data.Decl.Arrays;
+         Current_Array_Id := Project.Decl.Arrays;
          while Current_Array_Id /= No_Array loop
             Current_Array := In_Tree.Arrays.Table (Current_Array_Id);
 
@@ -2212,7 +2253,9 @@ package body Prj.Nmsc is
 
                --  Get the name of the language
 
-               Get_Language_Index_Of (Element.Index);
+               Lang_Index :=
+                 Get_Language_From_Name
+                   (Project, Get_Name_String (Element.Index));
 
                if Lang_Index /= No_Language_Index then
                   case Current_Array.Name is
@@ -2333,7 +2376,7 @@ package body Prj.Nmsc is
       --  For unit based languages, set Casing, Dot_Replacement and
       --  Separate_Suffix in Naming_Data.
 
-      Lang_Index := Data.Languages;
+      Lang_Index := Project.Languages;
       while Lang_Index /= No_Language_Index loop
          if Lang_Index.Name = Name_Ada then
             Lang_Index.Config.Naming_Data.Casing := Casing;
@@ -2353,35 +2396,36 @@ package body Prj.Nmsc is
       --  Give empty names to various prefixes/suffixes, if they have not
       --  been specified in the configuration.
 
-      if Data.Config.Archive_Suffix = No_File then
-         Data.Config.Archive_Suffix := Empty_File;
+      if Project.Config.Archive_Suffix = No_File then
+         Project.Config.Archive_Suffix := Empty_File;
       end if;
 
-      if Data.Config.Shared_Lib_Prefix = No_File then
-         Data.Config.Shared_Lib_Prefix := Empty_File;
+      if Project.Config.Shared_Lib_Prefix = No_File then
+         Project.Config.Shared_Lib_Prefix := Empty_File;
       end if;
 
-      if Data.Config.Shared_Lib_Suffix = No_File then
-         Data.Config.Shared_Lib_Suffix := Empty_File;
+      if Project.Config.Shared_Lib_Suffix = No_File then
+         Project.Config.Shared_Lib_Suffix := Empty_File;
       end if;
 
-      Lang_Index := Data.Languages;
+      Lang_Index := Project.Languages;
       while Lang_Index /= No_Language_Index loop
-         Current_Language := Lang_Index.Display_Name;
-
-         --  For all languages, Compiler_Driver needs to be specified
+         --  For all languages, Compiler_Driver needs to be specified. This is
+         --  only needed if we do intend to compile (not in GPS for instance).
 
-         if Lang_Index.Config.Compiler_Driver = No_File then
-            Error_Msg_Name_1 := Current_Language;
+         if Compiler_Driver_Mandatory
+           and then Lang_Index.Config.Compiler_Driver = No_File
+         then
+            Error_Msg_Name_1 := Lang_Index.Display_Name;
             Error_Msg
               (Project,
                In_Tree,
                "?no compiler specified for language %%" &
-               ", ignoring all its sources",
+                 ", ignoring all its sources",
                No_Location);
 
-            if Lang_Index = Data.Languages then
-               Data.Languages := Lang_Index.Next;
+            if Lang_Index = Project.Languages then
+               Project.Languages := Lang_Index.Next;
             else
                Prev_Index.Next := Lang_Index.Next;
             end if;
@@ -2425,7 +2469,7 @@ package body Prj.Nmsc is
             if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File and then
               Lang_Index.Config.Naming_Data.Body_Suffix = No_File
             then
-               Error_Msg_Name_1 := Current_Language;
+               Error_Msg_Name_1 := Lang_Index.Display_Name;
                Error_Msg
                  (Project,
                   In_Tree,
@@ -2444,13 +2488,12 @@ package body Prj.Nmsc is
 
    procedure Check_If_Externally_Built
      (Project : Project_Id;
-      In_Tree : Project_Tree_Ref;
-      Data    : in out Project_Data)
+      In_Tree : Project_Tree_Ref)
    is
       Externally_Built : constant Variable_Value :=
                            Util.Value_Of
                             (Name_Externally_Built,
-                             Data.Decl.Attributes, In_Tree);
+                             Project.Decl.Attributes, In_Tree);
 
    begin
       if not Externally_Built.Default then
@@ -2458,7 +2501,7 @@ package body Prj.Nmsc is
          To_Lower (Name_Buffer (1 .. Name_Len));
 
          if Name_Buffer (1 .. Name_Len) = "true" then
-            Data.Externally_Built := True;
+            Project.Externally_Built := True;
 
          elsif Name_Buffer (1 .. Name_Len) /= "false" then
             Error_Msg (Project, In_Tree,
@@ -2470,15 +2513,14 @@ package body Prj.Nmsc is
       --  A virtual project extending an externally built project is itself
       --  externally built.
 
-      if Data.Virtual and then Data.Extends /= No_Project then
-         Data.Externally_Built :=
-           In_Tree.Projects.Table (Data.Extends).Externally_Built;
+      if Project.Virtual and then Project.Extends /= No_Project then
+         Project.Externally_Built := Project.Extends.Externally_Built;
       end if;
 
       if Current_Verbosity = High then
          Write_Str ("Project is ");
 
-         if not Data.Externally_Built then
+         if not Project.Externally_Built then
             Write_Str ("not ");
          end if;
 
@@ -2492,13 +2534,12 @@ package body Prj.Nmsc is
 
    procedure Check_Interfaces
      (Project : Project_Id;
-      In_Tree : Project_Tree_Ref;
-      Data    : in out Project_Data)
+      In_Tree : Project_Tree_Ref)
    is
       Interfaces : constant Prj.Variable_Value :=
                      Prj.Util.Value_Of
                        (Snames.Name_Interfaces,
-                        Data.Decl.Attributes,
+                        Project.Decl.Attributes,
                         In_Tree);
 
       List      : String_List_Id;
@@ -2507,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
@@ -2525,7 +2567,7 @@ package body Prj.Nmsc is
                Next (Iter);
             end loop;
 
-            Project_2 := In_Tree.Projects.Table (Project_2).Extends;
+            Project_2 := Project_2.Extends;
          end loop;
 
          List := Interfaces.Values;
@@ -2547,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
@@ -2564,12 +2608,12 @@ package body Prj.Nmsc is
                   Next (Iter);
                end loop;
 
-               Project_2 := In_Tree.Projects.Table (Project_2).Extends;
+               Project_2 := Project_2.Extends;
             end loop Big_Loop;
 
             if Source = No_Source then
                Error_Msg_File_1 := File_Name_Type (Element.Value);
-               Error_Msg_Name_1 := Data.Name;
+               Error_Msg_Name_1 := Project.Name;
 
                Error_Msg
                  (Project,
@@ -2582,13 +2626,12 @@ package body Prj.Nmsc is
             List := Element.Next;
          end loop;
 
-         Data.Interfaces_Defined := True;
+         Project.Interfaces_Defined := True;
 
-      elsif Data.Extends /= No_Project then
-         Data.Interfaces_Defined :=
-           In_Tree.Projects.Table (Data.Extends).Interfaces_Defined;
+      elsif Project.Extends /= No_Project then
+         Project.Interfaces_Defined := Project.Extends.Interfaces_Defined;
 
-         if Data.Interfaces_Defined then
+         if Project.Interfaces_Defined then
             Iter := For_Each_Source (In_Tree, Project);
             loop
                Source := Prj.Element (Iter);
@@ -2656,18 +2699,23 @@ package body Prj.Nmsc is
    end Check_And_Normalize_Unit_Names;
 
    --------------------------
-   -- Check_Naming_Schemes --
+   -- Check_Package_Naming --
    --------------------------
 
-   procedure Check_Naming_Schemes
-     (Data    : in out Project_Data;
-      Project : Project_Id;
-      In_Tree : Project_Tree_Ref)
+   procedure Check_Package_Naming
+     (Project        : Project_Id;
+      In_Tree        : Project_Tree_Ref;
+      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, Data.Decl.Packages, In_Tree);
+                   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
@@ -2693,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 --
       ------------------
@@ -2897,8 +2948,7 @@ package body Prj.Nmsc is
                      Kind             => Kind,
                      File_Name        => File_Name,
                      Display_File     => File_Name_Type (Element.Value),
-                     Naming_Exception => True,
-                     Lang_Kind        => File_Based);
+                     Naming_Exception => True);
 
                else
                   --  Check if the file name is already recorded for another
@@ -2947,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
@@ -2975,7 +3024,7 @@ package body Prj.Nmsc is
 
                if Exceptions = No_Array_Element then
                   Exceptions := Value_Of
-                    (Name_Specification,
+                    (Name_Spec,
                      In_Arrays => Naming.Decl.Arrays,
                      In_Tree   => In_Tree);
                end if;
@@ -3008,6 +3057,8 @@ package body Prj.Nmsc is
             if Unit /= No_Name then
 
                --  Check if the source already exists
+               --  ??? In Ada_Only mode (Record_Unit), we use a htable for
+               --  efficiency
 
                Source_To_Replace := No_Source;
                Iter := For_Each_Source (In_Tree);
@@ -3015,38 +3066,35 @@ package body Prj.Nmsc is
                loop
                   Source := Prj.Element (Iter);
                   exit when Source = No_Source
-                    or else (Source.Unit = Unit and then Source.Index = Index);
+                    or else (Source.Unit /= null
+                              and then Source.Unit.Name = Unit
+                              and then Source.Index = Index);
                   Next (Iter);
                end loop;
 
                if Source /= No_Source then
                   if Source.Kind /= Kind then
-                     Other_Part := Source;
-
                      loop
                         Next (Iter);
                         Source := Prj.Element (Iter);
 
-                        exit when Source = No_Source or else
-                          (Source.Unit = Unit and then Source.Index = Index);
+                        exit when Source = No_Source
+                          or else (Source.Unit /= null
+                                    and then Source.Unit.Name = Unit
+                                    and then Source.Index = Index);
                      end loop;
                   end if;
 
                   if Source /= No_Source then
                      Other_Project := Source.Project;
 
-                     if Is_Extending (Project, Other_Project, In_Tree) then
-                        Other_Part := Source.Other_Part;
-
-                        --  Record the source to be removed
-
+                     if Is_Extending (Project, Other_Project) then
                         Source_To_Replace := Source;
                         Source := No_Source;
 
                      else
                         Error_Msg_Name_1 := Unit;
-                        Error_Msg_Name_2 :=
-                          In_Tree.Projects.Table (Other_Project).Name;
+                        Error_Msg_Name_2 := Other_Project.Name;
                         Error_Msg
                           (Project,
                            In_Tree,
@@ -3065,8 +3113,6 @@ package body Prj.Nmsc is
                      Kind         => Kind,
                      File_Name    => File_Name,
                      Display_File => File_Name_Type (Element.Value.Value),
-                     Lang_Kind    => Unit_Based,
-                     Other_Part   => Other_Part,
                      Unit         => Unit,
                      Index        => Index,
                      Naming_Exception => True,
@@ -3083,129 +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  => Data.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  => Data.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);
-            Data.Naming.Separate_Suffix := Body_Suffix;
-            Set_Body_Suffix (In_Tree, "ada", Data.Naming, Body_Suffix);
-
-         else
-            Body_Suffix := Default_Ada_Body_Suffix;
-            Data.Naming.Separate_Suffix := Body_Suffix;
-            Set_Body_Suffix (In_Tree, "ada", Data.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 => Data.Naming.Dot_Replacement,
-            Casing          => Data.Naming.Casing,
-            Casing_Defined  => Casing_Defined,
-            Separate_Suffix => Data.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));
 
-         Data.Naming.Bodies :=
-           Util.Value_Of (Name_Body, Naming.Decl.Arrays, In_Tree);
+            --  We'll need the dot replacement below, so compute it now
 
-         if Data.Naming.Bodies /= No_Array_Element then
-            Check_And_Normalize_Unit_Names
-              (Project, In_Tree, Data.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);
 
-         Data.Naming.Specs :=
-           Util.Value_Of (Name_Spec, Naming.Decl.Arrays, In_Tree);
+            Bodies := Util.Value_Of (Name_Body, Naming.Decl.Arrays, In_Tree);
 
-         if Data.Naming.Specs /= No_Array_Element then
-            Check_And_Normalize_Unit_Names
-              (Project, In_Tree, Data.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", Data.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, Data.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", Data.Naming, Spec_Suffix);
-         end if;
-
-         Write_Attr ("Spec_Suffix", Get_Name_String (Spec_Suffix));
+            Write_Attr ("Spec_Suffix", Get_Name_String (Data.Spec_Suffix));
 
-         --  Check Body_Suffix
+            --  Check Body_Suffix
 
-         if Is_Illegal_Suffix (Body_Suffix, Data.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 /= Data.Naming.Separate_Suffix
-           and then Spec_Suffix = Data.Naming.Separate_Suffix
-         then
-            Error_Msg
-              (Project, In_Tree,
-               "Separate_Suffix (""" &
-               Get_Name_String (Data.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;
 
       -----------------------------
@@ -3230,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
 
@@ -3239,7 +3256,7 @@ package body Prj.Nmsc is
            or else Casing_Defined
            or else Separate_Suffix /= No_File
          then
-            Lang_Id := Data.Languages;
+            Lang_Id := Project.Languages;
             while Lang_Id /= No_Language_Index loop
                if Lang_Id.Config.Kind = Unit_Based then
                   if Dot_Replacement /= No_File then
@@ -3263,7 +3280,7 @@ package body Prj.Nmsc is
 
          --  Next, get the spec and body suffixes
 
-         Lang_Id := Data.Languages;
+         Lang_Id := Project.Languages;
          while Lang_Id /= No_Language_Index loop
             Lang := Lang_Id.Name;
 
@@ -3278,7 +3295,7 @@ package body Prj.Nmsc is
             if Suffix = Nil_Variable_Value then
                Suffix := Value_Of
                  (Name                    => Lang,
-                  Attribute_Or_Array_Name => Name_Specification_Suffix,
+                  Attribute_Or_Array_Name => Name_Spec_Suffix,
                   In_Package              => Naming_Id,
                   In_Tree                 => In_Tree);
             end if;
@@ -3321,7 +3338,7 @@ package body Prj.Nmsc is
          --  Get the naming exceptions for all languages
 
          for Kind in Spec .. Impl loop
-            Lang_Id := Data.Languages;
+            Lang_Id := Project.Languages;
             while Lang_Id /= No_Language_Index loop
                case Lang_Id.Config.Kind is
                when File_Based =>
@@ -3336,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 In_Configuration then
+      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;
@@ -3355,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 --
@@ -3363,11 +3495,9 @@ package body Prj.Nmsc is
 
    procedure Check_Library_Attributes
      (Project     : Project_Id;
-      In_Tree     : Project_Tree_Ref;
-      Current_Dir : String;
-      Data        : in out Project_Data)
+      In_Tree     : Project_Tree_Ref)
    is
-      Attributes   : constant Prj.Variable_Id := Data.Decl.Attributes;
+      Attributes   : constant Prj.Variable_Id := Project.Decl.Attributes;
 
       Lib_Dir      : constant Prj.Variable_Value :=
                        Prj.Util.Value_Of
@@ -3393,7 +3523,7 @@ package body Prj.Nmsc is
                        Prj.Util.Value_Of
                          (Snames.Name_Library_Kind, Attributes, In_Tree);
 
-      Imported_Project_List : Project_List := Empty_Project_List;
+      Imported_Project_List : Project_List;
 
       Continuation : String_Access := No_Continuation_String'Access;
 
@@ -3409,15 +3539,12 @@ package body Prj.Nmsc is
       -------------------
 
       procedure Check_Library (Proj : Project_Id; Extends : Boolean) is
-         Proj_Data : Project_Data;
          Src_Id    : Source_Id;
          Iter      : Source_Iterator;
 
       begin
          if Proj /= No_Project then
-            Proj_Data := In_Tree.Projects.Table (Proj);
-
-            if not Proj_Data.Library then
+            if not Proj.Library then
 
                --  The only not library projects that are OK are those that
                --  have no sources. However, header files from non-Ada
@@ -3427,44 +3554,44 @@ package body Prj.Nmsc is
                loop
                   Src_Id := Prj.Element (Iter);
                   exit when Src_Id = No_Source
-                    or else Src_Id.Lang_Kind /= File_Based
+                    or else Src_Id.Language.Config.Kind /= File_Based
                     or else Src_Id.Kind /= Spec;
                   Next (Iter);
                end loop;
 
                if Src_Id /= No_Source then
-                  Error_Msg_Name_1 := Data.Name;
-                  Error_Msg_Name_2 := Proj_Data.Name;
+                  Error_Msg_Name_1 := Project.Name;
+                  Error_Msg_Name_2 := Proj.Name;
 
                   if Extends then
-                     if Data.Library_Kind /= Static then
+                     if Project.Library_Kind /= Static then
                         Error_Msg
                           (Project, In_Tree,
                            Continuation.all &
                            "shared library project %% cannot extend " &
                            "project %% that is not a library project",
-                           Data.Location);
+                           Project.Location);
                         Continuation := Continuation_String'Access;
                      end if;
 
                   elsif (not Unchecked_Shared_Lib_Imports)
-                        and then Data.Library_Kind /= Static
+                        and then Project.Library_Kind /= Static
                   then
                      Error_Msg
                        (Project, In_Tree,
                         Continuation.all &
                         "shared library project %% cannot import project %% " &
                         "that is not a shared library project",
-                        Data.Location);
+                        Project.Location);
                      Continuation := Continuation_String'Access;
                   end if;
                end if;
 
-            elsif Data.Library_Kind /= Static and then
-                  Proj_Data.Library_Kind = Static
+            elsif Project.Library_Kind /= Static and then
+                  Proj.Library_Kind = Static
             then
-               Error_Msg_Name_1 := Data.Name;
-               Error_Msg_Name_2 := Proj_Data.Name;
+               Error_Msg_Name_1 := Project.Name;
+               Error_Msg_Name_2 := Proj.Name;
 
                if Extends then
                   Error_Msg
@@ -3472,7 +3599,7 @@ package body Prj.Nmsc is
                      Continuation.all &
                      "shared library project %% cannot extend static " &
                      "library project %%",
-                     Data.Location);
+                     Project.Location);
                   Continuation := Continuation_String'Access;
 
                elsif not Unchecked_Shared_Lib_Imports then
@@ -3481,7 +3608,7 @@ package body Prj.Nmsc is
                      Continuation.all &
                      "shared library project %% cannot import static " &
                      "library project %%",
-                     Data.Location);
+                     Project.Location);
                   Continuation := Continuation_String'Access;
                end if;
 
@@ -3489,6 +3616,8 @@ package body Prj.Nmsc is
          end if;
       end Check_Library;
 
+      Dir_Exists : Boolean;
+
    --  Start of processing for Check_Library_Attributes
 
    begin
@@ -3496,54 +3625,49 @@ package body Prj.Nmsc is
 
       --  Special case of extending project
 
-      if Data.Extends /= No_Project then
-         declare
-            Extended_Data : constant Project_Data :=
-                              In_Tree.Projects.Table (Data.Extends);
+      if Project.Extends /= No_Project then
 
-         begin
-            --  If the project extended is a library project, we inherit the
-            --  library name, if it is not redefined; we check that the library
-            --  directory is specified.
+         --  If the project extended is a library project, we inherit the
+         --  library name, if it is not redefined; we check that the library
+         --  directory is specified.
 
-            if Extended_Data.Library then
-               if Data.Qualifier = Standard then
-                  Error_Msg
-                    (Project, In_Tree,
-                     "a standard project cannot extend a library project",
-                     Data.Location);
+         if Project.Extends.Library then
+            if Project.Qualifier = Standard then
+               Error_Msg
+                 (Project, In_Tree,
+                  "a standard project cannot extend a library project",
+                  Project.Location);
 
-               else
-                  if Lib_Name.Default then
-                     Data.Library_Name := Extended_Data.Library_Name;
-                  end if;
+            else
+               if Lib_Name.Default then
+                  Project.Library_Name := Project.Extends.Library_Name;
+               end if;
 
-                  if Lib_Dir.Default then
-                     if not Data.Virtual then
-                        Error_Msg
-                          (Project, In_Tree,
-                           "a project extending a library project must " &
-                           "specify an attribute Library_Dir",
-                           Data.Location);
+               if Lib_Dir.Default then
+                  if not Project.Virtual then
+                     Error_Msg
+                       (Project, In_Tree,
+                        "a project extending a library project must " &
+                        "specify an attribute Library_Dir",
+                        Project.Location);
 
-                     else
-                        --  For a virtual project extending a library project,
-                        --  inherit library directory.
+                  else
+                     --  For a virtual project extending a library project,
+                     --  inherit library directory.
 
-                        Data.Library_Dir := Extended_Data.Library_Dir;
-                        Library_Directory_Present := True;
-                     end if;
+                     Project.Library_Dir := Project.Extends.Library_Dir;
+                     Library_Directory_Present := True;
                   end if;
                end if;
             end if;
-         end;
+         end if;
       end if;
 
       pragma Assert (Lib_Name.Kind = Single);
 
       if Lib_Name.Value = Empty_String then
          if Current_Verbosity = High
-           and then Data.Library_Name = No_Name
+           and then Project.Library_Name = No_Name
          then
             Write_Line ("No library name");
          end if;
@@ -3551,12 +3675,13 @@ package body Prj.Nmsc is
       else
          --  There is no restriction on the syntax of library names
 
-         Data.Library_Name := Lib_Name.Value;
+         Project.Library_Name := Lib_Name.Value;
       end if;
 
-      if Data.Library_Name /= No_Name then
+      if Project.Library_Name /= No_Name then
          if Current_Verbosity = High then
-            Write_Attr ("Library name", Get_Name_String (Data.Library_Name));
+            Write_Attr
+              ("Library name", Get_Name_String (Project.Library_Name));
          end if;
 
          pragma Assert (Lib_Dir.Kind = Single);
@@ -3569,85 +3694,65 @@ package body Prj.Nmsc is
          else
             --  Find path name (unless inherited), check that it is a directory
 
-            if Data.Library_Dir = No_Path_Information then
+            if Project.Library_Dir = No_Path_Information then
                Locate_Directory
                  (Project,
                   In_Tree,
                   File_Name_Type (Lib_Dir.Value),
-                  Data.Directory.Display_Name,
-                  Data.Library_Dir.Name,
-                  Data.Library_Dir.Display_Name,
+                  Path             => Project.Library_Dir,
+                  Dir_Exists       => Dir_Exists,
                   Create           => "library",
-                  Current_Dir      => Current_Dir,
+                  Must_Exist       => False,
                   Location         => Lib_Dir.Location,
-                  Externally_Built => Data.Externally_Built);
-            end if;
+                  Externally_Built => Project.Externally_Built);
 
-            if Data.Library_Dir = No_Path_Information then
+            else
+               Dir_Exists :=
+                 Is_Directory
+                   (Get_Name_String
+                        (Project.Library_Dir.Display_Name));
+            end if;
 
+            if not Dir_Exists then
                --  Get the absolute name of the library directory that
                --  does not exist, to report an error.
 
-               declare
-                  Dir_Name : constant String :=
-                               Get_Name_String (Lib_Dir.Value);
-
-               begin
-                  if Is_Absolute_Path (Dir_Name) then
-                     Err_Vars.Error_Msg_File_1 :=
-                       File_Name_Type (Lib_Dir.Value);
-
-                  else
-                     Get_Name_String (Data.Directory.Display_Name);
-
-                     if Name_Buffer (Name_Len) /= Directory_Separator then
-                        Name_Len := Name_Len + 1;
-                        Name_Buffer (Name_Len) := Directory_Separator;
-                     end if;
-
-                     Name_Buffer
-                       (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
-                       Dir_Name;
-                     Name_Len := Name_Len + Dir_Name'Length;
-                     Err_Vars.Error_Msg_File_1 := Name_Find;
-                  end if;
-
-                  --  Report the error
-
-                  Error_Msg
-                    (Project, In_Tree,
-                     "library directory { does not exist",
-                     Lib_Dir.Location);
-               end;
+               Err_Vars.Error_Msg_File_1 :=
+                 File_Name_Type (Project.Library_Dir.Display_Name);
+               Error_Msg
+                 (Project, In_Tree,
+                  "library directory { does not exist",
+                  Lib_Dir.Location);
 
                --  The library directory cannot be the same as the Object
                --  directory.
 
-            elsif Data.Library_Dir.Name = Data.Object_Directory.Name then
+            elsif Project.Library_Dir.Name = Project.Object_Directory.Name then
                Error_Msg
                  (Project, In_Tree,
                   "library directory cannot be the same " &
                   "as object directory",
                   Lib_Dir.Location);
-               Data.Library_Dir := No_Path_Information;
+               Project.Library_Dir := No_Path_Information;
 
             else
                declare
                   OK       : Boolean := True;
                   Dirs_Id  : String_List_Id;
                   Dir_Elem : String_Element;
+                  Pid      : Project_List;
 
                begin
                   --  The library directory cannot be the same as a source
                   --  directory of the current project.
 
-                  Dirs_Id := Data.Source_Dirs;
+                  Dirs_Id := Project.Source_Dirs;
                   while Dirs_Id /= Nil_String loop
                      Dir_Elem := In_Tree.String_Elements.Table (Dirs_Id);
                      Dirs_Id  := Dir_Elem.Next;
 
-                     if
-                       Data.Library_Dir.Name = Path_Name_Type (Dir_Elem.Value)
+                     if Project.Library_Dir.Name =
+                       Path_Name_Type (Dir_Elem.Value)
                      then
                         Err_Vars.Error_Msg_File_1 :=
                           File_Name_Type (Dir_Elem.Value);
@@ -3666,23 +3771,24 @@ package body Prj.Nmsc is
                      --  The library directory cannot be the same as a source
                      --  directory of another project either.
 
-                     Project_Loop :
-                     for Pid in 1 .. Project_Table.Last (In_Tree.Projects) loop
-                        if Pid /= Project then
-                           Dirs_Id := In_Tree.Projects.Table (Pid).Source_Dirs;
+                     Pid := In_Tree.Projects;
+                     Project_Loop : loop
+                        exit Project_Loop when Pid = null;
+
+                        if Pid.Project /= Project then
+                           Dirs_Id := Pid.Project.Source_Dirs;
 
                            Dir_Loop : while Dirs_Id /= Nil_String loop
                               Dir_Elem :=
                                 In_Tree.String_Elements.Table (Dirs_Id);
                               Dirs_Id  := Dir_Elem.Next;
 
-                              if Data.Library_Dir.Name =
+                              if Project.Library_Dir.Name =
                                 Path_Name_Type (Dir_Elem.Value)
                               then
                                  Err_Vars.Error_Msg_File_1 :=
                                    File_Name_Type (Dir_Elem.Value);
-                                 Err_Vars.Error_Msg_Name_1 :=
-                                   In_Tree.Projects.Table (Pid).Name;
+                                 Err_Vars.Error_Msg_Name_1 := Pid.Project.Name;
 
                                  Error_Msg
                                    (Project, In_Tree,
@@ -3694,11 +3800,13 @@ package body Prj.Nmsc is
                               end if;
                            end loop Dir_Loop;
                         end if;
+
+                        Pid := Pid.Next;
                      end loop Project_Loop;
                   end if;
 
                   if not OK then
-                     Data.Library_Dir := No_Path_Information;
+                     Project.Library_Dir := No_Path_Information;
 
                   elsif Current_Verbosity = High then
 
@@ -3706,7 +3814,7 @@ package body Prj.Nmsc is
 
                      Write_Attr
                        ("Library directory",
-                        Get_Name_String (Data.Library_Dir.Display_Name));
+                        Get_Name_String (Project.Library_Dir.Display_Name));
                   end if;
                end;
             end if;
@@ -3714,15 +3822,14 @@ package body Prj.Nmsc is
 
       end if;
 
-      Data.Library :=
-        Data.Library_Dir /= No_Path_Information
-        and then
-      Data.Library_Name /= No_Name;
+      Project.Library :=
+        Project.Library_Dir /= No_Path_Information
+          and then Project.Library_Name /= No_Name;
 
-      if Data.Extends = No_Project then
-         case Data.Qualifier is
+      if Project.Extends = No_Project then
+         case Project.Qualifier is
             when Standard =>
-               if Data.Library then
+               if Project.Library then
                   Error_Msg
                     (Project, In_Tree,
                      "a standard project cannot be a library project",
@@ -3730,19 +3837,19 @@ package body Prj.Nmsc is
                end if;
 
             when Library =>
-               if not Data.Library then
-                  if Data.Library_Dir = No_Path_Information then
+               if not Project.Library then
+                  if Project.Library_Dir = No_Path_Information then
                      Error_Msg
                        (Project, In_Tree,
                         "\attribute Library_Dir not declared",
-                        Data.Location);
+                        Project.Location);
                   end if;
 
-                  if Data.Library_Name = No_Name then
+                  if Project.Library_Name = No_Name then
                      Error_Msg
                        (Project, In_Tree,
                         "\attribute Library_Name not declared",
-                        Data.Location);
+                        Project.Location);
                   end if;
                end if;
 
@@ -3752,9 +3859,9 @@ package body Prj.Nmsc is
          end case;
       end if;
 
-      if Data.Library then
+      if Project.Library then
          if Get_Mode = Multi_Language then
-            Support_For_Libraries := Data.Config.Lib_Support;
+            Support_For_Libraries := Project.Config.Lib_Support;
 
          else
             Support_For_Libraries := MLib.Tgt.Support_For_Libraries;
@@ -3765,14 +3872,15 @@ package body Prj.Nmsc is
               (Project, In_Tree,
                "?libraries are not supported on this platform",
                Lib_Name.Location);
-            Data.Library := False;
+            Project.Library := False;
 
          else
             if Lib_ALI_Dir.Value = Empty_String then
                if Current_Verbosity = High then
                   Write_Line ("No library ALI directory specified");
                end if;
-               Data.Library_ALI_Dir := Data.Library_Dir;
+
+               Project.Library_ALI_Dir := Project.Library_Dir;
 
             else
                --  Find path name, check that it is a directory
@@ -3781,81 +3889,55 @@ package body Prj.Nmsc is
                  (Project,
                   In_Tree,
                   File_Name_Type (Lib_ALI_Dir.Value),
-                  Data.Directory.Display_Name,
-                  Data.Library_ALI_Dir.Name,
-                  Data.Library_ALI_Dir.Display_Name,
+                  Path             => Project.Library_ALI_Dir,
                   Create           => "library ALI",
-                  Current_Dir      => Current_Dir,
+                  Dir_Exists       => Dir_Exists,
+                  Must_Exist       => False,
                   Location         => Lib_ALI_Dir.Location,
-                  Externally_Built => Data.Externally_Built);
-
-               if Data.Library_ALI_Dir = No_Path_Information then
+                  Externally_Built => Project.Externally_Built);
 
+               if not Dir_Exists then
                   --  Get the absolute name of the library ALI directory that
                   --  does not exist, to report an error.
 
-                  declare
-                     Dir_Name : constant String :=
-                                  Get_Name_String (Lib_ALI_Dir.Value);
-
-                  begin
-                     if Is_Absolute_Path (Dir_Name) then
-                        Err_Vars.Error_Msg_File_1 :=
-                          File_Name_Type (Lib_Dir.Value);
-
-                     else
-                        Get_Name_String (Data.Directory.Display_Name);
-
-                        if Name_Buffer (Name_Len) /= Directory_Separator then
-                           Name_Len := Name_Len + 1;
-                           Name_Buffer (Name_Len) := Directory_Separator;
-                        end if;
-
-                        Name_Buffer
-                          (Name_Len + 1 .. Name_Len + Dir_Name'Length) :=
-                          Dir_Name;
-                        Name_Len := Name_Len + Dir_Name'Length;
-                        Err_Vars.Error_Msg_File_1 := Name_Find;
-                     end if;
-
-                     --  Report the error
-
-                     Error_Msg
-                       (Project, In_Tree,
-                        "library 'A'L'I directory { does not exist",
-                        Lib_ALI_Dir.Location);
-                  end;
+                  Err_Vars.Error_Msg_File_1 :=
+                    File_Name_Type (Project.Library_ALI_Dir.Display_Name);
+                  Error_Msg
+                    (Project, In_Tree,
+                     "library 'A'L'I directory { does not exist",
+                     Lib_ALI_Dir.Location);
                end if;
 
-               if Data.Library_ALI_Dir /= Data.Library_Dir then
+               if Project.Library_ALI_Dir /= Project.Library_Dir then
 
                   --  The library ALI directory cannot be the same as the
                   --  Object directory.
 
-                  if Data.Library_ALI_Dir = Data.Object_Directory then
+                  if Project.Library_ALI_Dir = Project.Object_Directory then
                      Error_Msg
                        (Project, In_Tree,
                         "library 'A'L'I directory cannot be the same " &
                         "as object directory",
                         Lib_ALI_Dir.Location);
-                     Data.Library_ALI_Dir := No_Path_Information;
+                     Project.Library_ALI_Dir := No_Path_Information;
 
                   else
                      declare
                         OK       : Boolean := True;
                         Dirs_Id  : String_List_Id;
                         Dir_Elem : String_Element;
+                        Pid      : Project_List;
 
                      begin
                         --  The library ALI directory cannot be the same as
                         --  a source directory of the current project.
 
-                        Dirs_Id := Data.Source_Dirs;
+                        Dirs_Id := Project.Source_Dirs;
                         while Dirs_Id /= Nil_String loop
                            Dir_Elem := In_Tree.String_Elements.Table (Dirs_Id);
                            Dirs_Id  := Dir_Elem.Next;
 
-                           if Data.Library_ALI_Dir.Name =
+                           if Project.Library_ALI_Dir.Name =
                              Path_Name_Type (Dir_Elem.Value)
                            then
                               Err_Vars.Error_Msg_File_1 :=
@@ -3875,13 +3957,12 @@ package body Prj.Nmsc is
                            --  The library ALI directory cannot be the same as
                            --  a source directory of another project either.
 
-                           ALI_Project_Loop :
-                           for
-                             Pid in 1 .. Project_Table.Last (In_Tree.Projects)
-                           loop
-                              if Pid /= Project then
-                                 Dirs_Id :=
-                                   In_Tree.Projects.Table (Pid).Source_Dirs;
+                           Pid := In_Tree.Projects;
+                           ALI_Project_Loop : loop
+                              exit ALI_Project_Loop when Pid = null;
+
+                              if Pid.Project /= Project then
+                                 Dirs_Id := Pid.Project.Source_Dirs;
 
                                  ALI_Dir_Loop :
                                  while Dirs_Id /= Nil_String loop
@@ -3889,13 +3970,13 @@ package body Prj.Nmsc is
                                       In_Tree.String_Elements.Table (Dirs_Id);
                                     Dirs_Id  := Dir_Elem.Next;
 
-                                    if Data.Library_ALI_Dir.Name =
+                                    if Project.Library_ALI_Dir.Name =
                                         Path_Name_Type (Dir_Elem.Value)
                                     then
                                        Err_Vars.Error_Msg_File_1 :=
                                          File_Name_Type (Dir_Elem.Value);
                                        Err_Vars.Error_Msg_Name_1 :=
-                                         In_Tree.Projects.Table (Pid).Name;
+                                         Pid.Project.Name;
 
                                        Error_Msg
                                          (Project, In_Tree,
@@ -3908,11 +3989,12 @@ package body Prj.Nmsc is
                                     end if;
                                  end loop ALI_Dir_Loop;
                               end if;
+                              Pid := Pid.Next;
                            end loop ALI_Project_Loop;
                         end if;
 
                         if not OK then
-                           Data.Library_ALI_Dir := No_Path_Information;
+                           Project.Library_ALI_Dir := No_Path_Information;
 
                         elsif Current_Verbosity = High then
 
@@ -3922,7 +4004,7 @@ package body Prj.Nmsc is
                            Write_Attr
                              ("Library ALI dir",
                               Get_Name_String
-                                (Data.Library_ALI_Dir.Display_Name));
+                                (Project.Library_ALI_Dir.Display_Name));
                         end if;
                      end;
                   end if;
@@ -3937,7 +4019,7 @@ package body Prj.Nmsc is
                end if;
 
             else
-               Data.Lib_Internal_Name := Lib_Version.Value;
+               Project.Lib_Internal_Name := Lib_Version.Value;
             end if;
 
             pragma Assert (The_Lib_Kind.Kind = Single);
@@ -3958,13 +4040,13 @@ package body Prj.Nmsc is
 
                begin
                   if Kind_Name = "static" then
-                     Data.Library_Kind := Static;
+                     Project.Library_Kind := Static;
 
                   elsif Kind_Name = "dynamic" then
-                     Data.Library_Kind := Dynamic;
+                     Project.Library_Kind := Dynamic;
 
                   elsif Kind_Name = "relocatable" then
-                     Data.Library_Kind := Relocatable;
+                     Project.Library_Kind := Relocatable;
 
                   else
                      Error_Msg
@@ -3978,14 +4060,14 @@ package body Prj.Nmsc is
                      Write_Attr ("Library kind", Kind_Name);
                   end if;
 
-                  if Data.Library_Kind /= Static then
+                  if Project.Library_Kind /= Static then
                      if Support_For_Libraries = Prj.Static_Only then
                         Error_Msg
                           (Project, In_Tree,
                            "only static libraries are supported " &
                            "on this platform",
                            The_Lib_Kind.Location);
-                        Data.Library := False;
+                        Project.Library := False;
 
                      else
                         --  Check if (obsolescent) attribute Library_GCC or
@@ -3998,7 +4080,7 @@ package body Prj.Nmsc is
                               "?Library_'G'C'C is an obsolescent attribute, " &
                               "use Linker''Driver instead",
                               Lib_GCC.Location);
-                           Data.Config.Shared_Lib_Driver :=
+                           Project.Config.Shared_Lib_Driver :=
                              File_Name_Type (Lib_GCC.Value);
 
                         else
@@ -4006,7 +4088,7 @@ package body Prj.Nmsc is
                               Linker : constant Package_Id :=
                                          Value_Of
                                            (Name_Linker,
-                                            Data.Decl.Packages,
+                                            Project.Decl.Packages,
                                             In_Tree);
                               Driver : constant Variable_Value :=
                                          Value_Of
@@ -4021,7 +4103,7 @@ package body Prj.Nmsc is
                               if Driver /= Nil_Variable_Value
                                  and then Driver.Value /= Empty_String
                               then
-                                 Data.Config.Shared_Lib_Driver :=
+                                 Project.Config.Shared_Lib_Driver :=
                                    File_Name_Type (Driver.Value);
                               end if;
                            end;
@@ -4031,23 +4113,20 @@ package body Prj.Nmsc is
                end;
             end if;
 
-            if Data.Library then
+            if Project.Library then
                if Current_Verbosity = High then
                   Write_Line ("This is a library project file");
                end if;
 
                if Get_Mode = Multi_Language then
-                  Check_Library (Data.Extends, Extends => True);
+                  Check_Library (Project.Extends, Extends => True);
 
-                  Imported_Project_List := Data.Imported_Projects;
-                  while Imported_Project_List /= Empty_Project_List loop
+                  Imported_Project_List := Project.Imported_Projects;
+                  while Imported_Project_List /= null loop
                      Check_Library
-                       (In_Tree.Project_Lists.Table
-                          (Imported_Project_List).Project,
+                       (Imported_Project_List.Project,
                         Extends => False);
-                     Imported_Project_List :=
-                       In_Tree.Project_Lists.Table
-                         (Imported_Project_List).Next;
+                     Imported_Project_List := Imported_Project_List.Next;
                   end loop;
                end if;
             end if;
@@ -4059,254 +4138,48 @@ package body Prj.Nmsc is
       --  Warn if they are declared, as it is a common error to think that
       --  library are "linked" with Linker switches.
 
-      if Data.Library then
-         declare
-            Linker_Package_Id : constant Package_Id :=
-                                  Util.Value_Of
-                                    (Name_Linker, Data.Decl.Packages, In_Tree);
-            Linker_Package    : Package_Element;
-            Switches          : Array_Element_Id := No_Array_Element;
-
-         begin
-            if Linker_Package_Id /= No_Package then
-               Linker_Package := In_Tree.Packages.Table (Linker_Package_Id);
-
-               Switches :=
-                 Value_Of
-                   (Name      => Name_Switches,
-                    In_Arrays => Linker_Package.Decl.Arrays,
-                    In_Tree   => In_Tree);
-
-               if Switches = No_Array_Element then
-                  Switches :=
-                    Value_Of
-                      (Name      => Name_Default_Switches,
-                       In_Arrays => Linker_Package.Decl.Arrays,
-                       In_Tree   => In_Tree);
-               end if;
-
-               if Switches /= No_Array_Element then
-                  Error_Msg
-                    (Project, In_Tree,
-                     "?Linker switches not taken into account in library " &
-                     "projects",
-                     No_Location);
-               end if;
-            end if;
-         end;
-      end if;
-
-      if Data.Extends /= No_Project then
-         In_Tree.Projects.Table (Data.Extends).Library := False;
-      end if;
-   end Check_Library_Attributes;
-
-   --------------------------
-   -- Check_Package_Naming --
-   --------------------------
-
-   procedure Check_Package_Naming
-     (Project : Project_Id;
-      In_Tree : Project_Tree_Ref;
-      Data    : in out Project_Data)
-   is
-      Naming_Id : constant Package_Id :=
-                    Util.Value_Of (Name_Naming, Data.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 := Data.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;
-
-               --  Put the resulting array as the specification suffixes
-
-               Data.Naming.Spec_Suffix := Spec_Suffixs;
-            end if;
-         end;
-
-         declare
-            Current : Array_Element_Id;
-            Element : Array_Element;
-
-         begin
-            Current := Data.Naming.Spec_Suffix;
-            while Current /= No_Array_Element loop
-               Element := In_Tree.Array_Elements.Table (Current);
-               Get_Name_String (Element.Value.Value);
-
-               if Name_Len = 0 then
-                  Error_Msg
-                    (Project, In_Tree,
-                     "Spec_Suffix cannot be empty",
-                     Element.Value.Location);
-               end if;
-
-               In_Tree.Array_Elements.Table (Current) := Element;
-               Current := Element.Next;
-            end loop;
-         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 := Data.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;
-
-                  Suffix := Element.Next;
-               end loop;
-
-               --  Put the resulting array as the implementation suffixes
-
-               Data.Naming.Body_Suffix := Impl_Suffixs;
-            end if;
-         end;
-
+      if Project.Library then
          declare
-            Current : Array_Element_Id;
-            Element : Array_Element;
+            Linker_Package_Id : constant Package_Id :=
+                                  Util.Value_Of
+                                    (Name_Linker,
+                                     Project.Decl.Packages, In_Tree);
+            Linker_Package    : Package_Element;
+            Switches          : Array_Element_Id := No_Array_Element;
 
          begin
-            Current := Data.Naming.Body_Suffix;
-            while Current /= No_Array_Element loop
-               Element := In_Tree.Array_Elements.Table (Current);
-               Get_Name_String (Element.Value.Value);
+            if Linker_Package_Id /= No_Package then
+               Linker_Package := In_Tree.Packages.Table (Linker_Package_Id);
 
-               if Name_Len = 0 then
+               Switches :=
+                 Value_Of
+                   (Name      => Name_Switches,
+                    In_Arrays => Linker_Package.Decl.Arrays,
+                    In_Tree   => In_Tree);
+
+               if Switches = No_Array_Element then
+                  Switches :=
+                    Value_Of
+                      (Name      => Name_Default_Switches,
+                       In_Arrays => Linker_Package.Decl.Arrays,
+                       In_Tree   => In_Tree);
+               end if;
+
+               if Switches /= No_Array_Element then
                   Error_Msg
                     (Project, In_Tree,
-                     "Body_Suffix cannot be empty",
-                     Element.Value.Location);
+                     "?Linker switches not taken into account in library " &
+                     "projects",
+                     No_Location);
                end if;
-
-               In_Tree.Array_Elements.Table (Current) := Element;
-               Current := Element.Next;
-            end loop;
+            end if;
          end;
+      end if;
 
-         --  Get the exceptions, if any
-
-         Data.Naming.Specification_Exceptions :=
-           Util.Value_Of
-             (Name_Specification_Exceptions,
-              In_Arrays => Naming.Decl.Arrays,
-              In_Tree   => In_Tree);
-
-         Data.Naming.Implementation_Exceptions :=
-           Util.Value_Of
-             (Name_Implementation_Exceptions,
-              In_Arrays => Naming.Decl.Arrays,
-              In_Tree   => In_Tree);
+      if Project.Extends /= No_Project then
+         Project.Extends.Library := False;
       end if;
-   end Check_Package_Naming;
+   end Check_Library_Attributes;
 
    ---------------------------------
    -- Check_Programming_Languages --
@@ -4314,25 +4187,71 @@ package body Prj.Nmsc is
 
    procedure Check_Programming_Languages
      (In_Tree : Project_Tree_Ref;
-      Project : Project_Id;
-      Data    : in out Project_Data)
+      Project : Project_Id)
    is
       Languages   : Variable_Value := Nil_Variable_Value;
       Def_Lang    : Variable_Value := Nil_Variable_Value;
       Def_Lang_Id : Name_Id;
 
+      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
+
+      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;
+
+            Lang := Lang.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;
+
+         if Name = Name_Ada then
+            Lang.Config.Kind := Unit_Based;
+            Lang.Config.Dependency_Kind := ALI_File;
+
+            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;
+
+         else
+            Lang.Config.Kind := File_Based;
+         end if;
+      end Add_Language;
+
+   --  Start of processing for Check_Programming_Languages
+
    begin
-      Data.Languages := No_Language_Index;
+      Project.Languages := null;
       Languages :=
-        Prj.Util.Value_Of (Name_Languages, Data.Decl.Attributes, In_Tree);
+        Prj.Util.Value_Of (Name_Languages, Project.Decl.Attributes, In_Tree);
       Def_Lang :=
         Prj.Util.Value_Of
-          (Name_Default_Language, Data.Decl.Attributes, In_Tree);
+          (Name_Default_Language, Project.Decl.Attributes, In_Tree);
 
       --  Shouldn't these be set to False by default, and only set to True when
       --  we actually find some source file???
 
-      if Data.Source_Dirs /= Nil_String then
+      if Project.Source_Dirs /= Nil_String then
 
          --  Check if languages are specified in this project
 
@@ -4352,8 +4271,9 @@ package body Prj.Nmsc is
                        (Project,
                         In_Tree,
                         "no languages defined for this project",
-                        Data.Location);
+                        Project.Location);
                      Def_Lang_Id := No_Name;
+
                   else
                      Def_Lang_Id := Name_Ada;
                   end if;
@@ -4366,41 +4286,29 @@ package body Prj.Nmsc is
             end if;
 
             if Def_Lang_Id /= No_Name then
-               Data.Languages :=
-                 new Language_Data'(No_Language_Data);
-               Data.Languages.Name := Def_Lang_Id;
                Get_Name_String (Def_Lang_Id);
                Name_Buffer (1) := GNAT.Case_Util.To_Upper (Name_Buffer (1));
-               Data.Languages.Display_Name := Name_Find;
-
-               if Def_Lang_Id = Name_Ada then
-                  Data.Languages.Config.Kind := Unit_Based;
-                  Data.Languages.Config.Dependency_Kind :=
-                    ALI_File;
-               else
-                  Data.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
 
                if Current = Nil_String then
-                  Data.Source_Dirs := Nil_String;
+                  Project.Source_Dirs := Nil_String;
 
-                  if Data.Qualifier = Standard then
+                  if Project.Qualifier = Standard then
                      Error_Msg
                        (Project,
                         In_Tree,
-                        "a standard project cannot have no language declared",
+                        "a standard project must have at least one language",
                         Languages.Location);
                   end if;
 
@@ -4412,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 := Data.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 := Data.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;
 
-                        Data.Languages := Index;
-                     end if;
+                     Add_Language
+                       (Name         => Name_Find,
+                        Display_Name => Element.Value);
 
                      Current := Element.Next;
                   end loop;
@@ -4456,27 +4340,23 @@ package body Prj.Nmsc is
    function Check_Project
      (P            : Project_Id;
       Root_Project : Project_Id;
-      In_Tree      : Project_Tree_Ref;
       Extending    : Boolean) return Boolean
    is
+      Prj : Project_Id;
+
    begin
       if P = Root_Project then
          return True;
 
       elsif Extending then
-         declare
-            Data : Project_Data;
-
-         begin
-            Data := In_Tree.Projects.Table (Root_Project);
-            while Data.Extends /= No_Project loop
-               if P = Data.Extends then
-                  return True;
-               end if;
+         Prj := Root_Project;
+         while Prj.Extends /= No_Project loop
+            if P = Prj.Extends then
+               return True;
+            end if;
 
-               Data := In_Tree.Projects.Table (Data.Extends);
-            end loop;
-         end;
+            Prj := Prj.Extends;
+         end loop;
       end if;
 
       return False;
@@ -4489,44 +4369,43 @@ package body Prj.Nmsc is
    procedure Check_Stand_Alone_Library
      (Project     : Project_Id;
       In_Tree     : Project_Tree_Ref;
-      Data        : in out Project_Data;
       Current_Dir : String;
       Extending   : Boolean)
    is
       Lib_Interfaces      : constant Prj.Variable_Value :=
                               Prj.Util.Value_Of
                                 (Snames.Name_Library_Interface,
-                                 Data.Decl.Attributes,
+                                 Project.Decl.Attributes,
                                  In_Tree);
 
       Lib_Auto_Init       : constant Prj.Variable_Value :=
                               Prj.Util.Value_Of
                                 (Snames.Name_Library_Auto_Init,
-                                 Data.Decl.Attributes,
+                                 Project.Decl.Attributes,
                                  In_Tree);
 
       Lib_Src_Dir         : constant Prj.Variable_Value :=
                               Prj.Util.Value_Of
                                 (Snames.Name_Library_Src_Dir,
-                                 Data.Decl.Attributes,
+                                 Project.Decl.Attributes,
                                  In_Tree);
 
       Lib_Symbol_File     : constant Prj.Variable_Value :=
                               Prj.Util.Value_Of
                                 (Snames.Name_Library_Symbol_File,
-                                 Data.Decl.Attributes,
+                                 Project.Decl.Attributes,
                                  In_Tree);
 
       Lib_Symbol_Policy   : constant Prj.Variable_Value :=
                               Prj.Util.Value_Of
                                 (Snames.Name_Library_Symbol_Policy,
-                                 Data.Decl.Attributes,
+                                 Project.Decl.Attributes,
                                  In_Tree);
 
       Lib_Ref_Symbol_File : constant Prj.Variable_Value :=
                               Prj.Util.Value_Of
                                 (Snames.Name_Library_Reference_Symbol_File,
-                                 Data.Decl.Attributes,
+                                 Project.Decl.Attributes,
                                  In_Tree);
 
       Auto_Init_Supported : Boolean;
@@ -4537,7 +4416,7 @@ package body Prj.Nmsc is
 
    begin
       if Get_Mode = Multi_Language then
-         Auto_Init_Supported := Data.Config.Auto_Init_Supported;
+         Auto_Init_Supported := Project.Config.Auto_Init_Supported;
       else
          Auto_Init_Supported :=
            MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported;
@@ -4553,8 +4432,7 @@ package body Prj.Nmsc is
             Interfaces     : String_List_Id := Lib_Interfaces.Values;
             Interface_ALIs : String_List_Id := Nil_String;
             Unit           : Name_Id;
-            The_Unit_Id    : Unit_Index;
-            UData          : Unit_Data;
+            UData          : Unit_Index;
 
             procedure Add_ALI_For (Source : File_Name_Type);
             --  Add an ALI file name to the list of Interface ALIs
@@ -4598,7 +4476,7 @@ package body Prj.Nmsc is
          --  Start of processing for SAL_Library
 
          begin
-            Data.Standalone_Library := True;
+            Project.Standalone_Library := True;
 
             --  Library_Interface cannot be an empty list
 
@@ -4628,10 +4506,9 @@ package body Prj.Nmsc is
                   Error_Msg_Name_1 := Unit;
 
                   if Get_Mode = Ada_Only then
-                     The_Unit_Id :=
-                       Units_Htable.Get (In_Tree.Units_HT, Unit);
+                     UData := Units_Htable.Get (In_Tree.Units_HT, Unit);
 
-                     if The_Unit_Id = No_Unit_Index then
+                     if UData = No_Unit_Index then
                         Error_Msg
                           (Project, In_Tree,
                            "unknown unit %%",
@@ -4641,35 +4518,29 @@ package body Prj.Nmsc is
                      else
                         --  Check that the unit is part of the project
 
-                        UData := In_Tree.Units.Table (The_Unit_Id);
-
-                        if UData.File_Names (Body_Part).Name /= No_File
-                          and then
-                            UData.File_Names (Body_Part).Path.Name /=
-                             Slash
+                        if UData.File_Names (Impl) /= null
+                          and then not UData.File_Names (Impl).Locally_Removed
                         then
                            if Check_Project
-                             (UData.File_Names (Body_Part).Project,
-                              Project, In_Tree, Extending)
+                             (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 (Specification).Name =
-                                No_File
-                              then
+                              if UData.File_Names (Spec) = null then
                                  declare
                                     Src_Ind : Source_File_Index;
 
                                  begin
-                                    Src_Ind := Sinput.P.Load_Project_File
-                                      (Get_Name_String
-                                         (UData.File_Names
-                                            (Body_Part).Path.Name));
+                                    Src_Ind :=
+                                      Sinput.P.Load_Project_File
+                                        (Get_Name_String (UData.File_Names
+                                                           (Impl).Path.Name));
 
                                     if Sinput.P.Source_File_Is_Subunit
-                                      (Src_Ind)
+                                        (Src_Ind)
                                     then
                                        Error_Msg
                                          (Project, In_Tree,
@@ -4686,7 +4557,7 @@ package body Prj.Nmsc is
                               --  ALI file for its body to the Interface ALIs.
 
                               Add_ALI_For
-                                (UData.File_Names (Body_Part).Name);
+                                (UData.File_Names (Impl).File);
 
                            else
                               Error_Msg
@@ -4696,14 +4567,11 @@ package body Prj.Nmsc is
                                    (Interfaces).Location);
                            end if;
 
-                        elsif UData.File_Names (Specification).Name /=
-                             No_File
-                          and then UData.File_Names
-                                     (Specification).Path.Name /= Slash
+                        elsif UData.File_Names (Spec) /= null
+                          and then not UData.File_Names (Spec).Locally_Removed
                           and then Check_Project
-                                     (UData.File_Names
-                                        (Specification).Project,
-                                      Project, In_Tree, Extending)
+                                     (UData.File_Names (Spec).Project,
+                                      Project, Extending)
 
                         then
                            --  The unit is part of the project, it has a spec,
@@ -4711,7 +4579,7 @@ package body Prj.Nmsc is
                            --  Interface ALIs.
 
                            Add_ALI_For
-                             (UData.File_Names (Specification).Name);
+                             (UData.File_Names (Spec).File);
 
                         else
                            Error_Msg
@@ -4725,41 +4593,38 @@ package body Prj.Nmsc is
                   else
                      --  Multi_Language mode
 
-                     Next_Proj := Data.Extends;
-
+                     Next_Proj := Project.Extends;
                      Iter := For_Each_Source (In_Tree, Project);
-
                      loop
-                        while Prj.Element (Iter) /= No_Source and then
-                           Prj.Element (Iter).Unit /= Unit
+                        while Prj.Element (Iter) /= No_Source
+                          and then
+                            (Prj.Element (Iter).Unit = null
+                              or else Prj.Element (Iter).Unit.Name /= Unit)
                         loop
                            Next (Iter);
                         end loop;
 
                         Source := Prj.Element (Iter);
-                        exit when Source /= No_Source or else
-                                  Next_Proj = No_Project;
+                        exit when Source /= No_Source
+                          or else Next_Proj = No_Project;
 
                         Iter := For_Each_Source (In_Tree, Next_Proj);
-                        Next_Proj :=
-                          In_Tree.Projects.Table (Next_Proj).Extends;
+                        Next_Proj := Next_Proj.Extends;
                      end loop;
 
                      if Source /= No_Source then
                         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;
 
                      if Source /= No_Source then
                         if Source.Project /= Project
-                          and then
-                            not Is_Extending (Project, Source.Project, In_Tree)
+                          and then not Is_Extending (Project, Source.Project)
                         then
                            Source := No_Source;
                         end if;
@@ -4773,14 +4638,15 @@ 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
                           (In_Tree.String_Elements);
+
                         In_Tree.String_Elements.Table
                           (String_Element_Table.Last
                              (In_Tree.String_Elements)) :=
@@ -4792,8 +4658,9 @@ package body Prj.Nmsc is
                                (Interfaces).Location,
                            Flag          => False,
                            Next          => Interface_ALIs);
-                        Interface_ALIs := String_Element_Table.Last
-                          (In_Tree.String_Elements);
+
+                        Interface_ALIs :=
+                          String_Element_Table.Last (In_Tree.String_Elements);
                      end if;
 
                   end if;
@@ -4806,7 +4673,7 @@ package body Prj.Nmsc is
 
             --  Put the list of Interface ALIs in the project data
 
-            Data.Lib_Interface_ALIs := Interface_ALIs;
+            Project.Lib_Interface_ALIs := Interface_ALIs;
 
             --  Check value of attribute Library_Auto_Init and set
             --  Lib_Auto_Init accordingly.
@@ -4816,18 +4683,18 @@ package body Prj.Nmsc is
                --  If no attribute Library_Auto_Init is declared, then set auto
                --  init only if it is supported.
 
-               Data.Lib_Auto_Init := Auto_Init_Supported;
+               Project.Lib_Auto_Init := Auto_Init_Supported;
 
             else
                Get_Name_String (Lib_Auto_Init.Value);
                To_Lower (Name_Buffer (1 .. Name_Len));
 
                if Name_Buffer (1 .. Name_Len) = "false" then
-                  Data.Lib_Auto_Init := False;
+                  Project.Lib_Auto_Init := False;
 
                elsif Name_Buffer (1 .. Name_Len) = "true" then
                   if Auto_Init_Supported then
-                     Data.Lib_Auto_Init := True;
+                     Project.Lib_Auto_Init := True;
 
                   else
                      --  Library_Auto_Init cannot be "true" if auto init is not
@@ -4859,89 +4726,60 @@ package body Prj.Nmsc is
             declare
                Dir_Id : constant File_Name_Type :=
                           File_Name_Type (Lib_Src_Dir.Value);
+               Dir_Exists : Boolean;
 
             begin
                Locate_Directory
                  (Project,
                   In_Tree,
                   Dir_Id,
-                  Data.Directory.Display_Name,
-                  Data.Library_Src_Dir.Name,
-                  Data.Library_Src_Dir.Display_Name,
+                  Path             => Project.Library_Src_Dir,
+                  Dir_Exists       => Dir_Exists,
+                  Must_Exist       => False,
                   Create           => "library source copy",
-                  Current_Dir      => Current_Dir,
                   Location         => Lib_Src_Dir.Location,
-                  Externally_Built => Data.Externally_Built);
+                  Externally_Built => Project.Externally_Built);
 
                --  If directory does not exist, report an error
 
-               if Data.Library_Src_Dir = No_Path_Information then
-
+               if not Dir_Exists then
                   --  Get the absolute name of the library directory that does
                   --  not exist, to report an error.
 
-                  declare
-                     Dir_Name : constant String :=
-                                  Get_Name_String (Dir_Id);
-
-                  begin
-                     if Is_Absolute_Path (Dir_Name) then
-                        Err_Vars.Error_Msg_File_1 := Dir_Id;
-
-                     else
-                        Get_Name_String (Data.Directory.Name);
-
-                        if Name_Buffer (Name_Len) /=
-                          Directory_Separator
-                        then
-                           Name_Len := Name_Len + 1;
-                           Name_Buffer (Name_Len) :=
-                             Directory_Separator;
-                        end if;
-
-                        Name_Buffer
-                          (Name_Len + 1 ..
-                             Name_Len + Dir_Name'Length) :=
-                            Dir_Name;
-                        Name_Len := Name_Len + Dir_Name'Length;
-                        Err_Vars.Error_Msg_Name_1 := Name_Find;
-                     end if;
-
-                     --  Report the error
-
-                     Error_Msg_File_1 := Dir_Id;
-                     Error_Msg
-                       (Project, In_Tree,
-                        "Directory { does not exist",
-                        Lib_Src_Dir.Location);
-                  end;
+                  Err_Vars.Error_Msg_File_1 :=
+                    File_Name_Type (Project.Library_Src_Dir.Display_Name);
+                  Error_Msg
+                    (Project, In_Tree,
+                     "Directory { does not exist",
+                     Lib_Src_Dir.Location);
 
                   --  Report error if it is the same as the object directory
 
-               elsif Data.Library_Src_Dir = Data.Object_Directory then
+               elsif Project.Library_Src_Dir = Project.Object_Directory then
                   Error_Msg
                     (Project, In_Tree,
                      "directory to copy interfaces cannot be " &
                      "the object directory",
                      Lib_Src_Dir.Location);
-                  Data.Library_Src_Dir := No_Path_Information;
+                  Project.Library_Src_Dir := No_Path_Information;
 
                else
                   declare
                      Src_Dirs : String_List_Id;
                      Src_Dir  : String_Element;
+                     Pid      : Project_List;
 
                   begin
                      --  Interface copy directory cannot be one of the source
                      --  directory of the current project.
 
-                     Src_Dirs := Data.Source_Dirs;
+                     Src_Dirs := Project.Source_Dirs;
                      while Src_Dirs /= Nil_String loop
                         Src_Dir := In_Tree.String_Elements.Table (Src_Dirs);
 
                         --  Report error if it is one of the source directories
 
-                        if Data.Library_Src_Dir.Name =
+                        if Project.Library_Src_Dir.Name =
                           Path_Name_Type (Src_Dir.Value)
                         then
                            Error_Msg
@@ -4949,23 +4787,23 @@ package body Prj.Nmsc is
                               "directory to copy interfaces cannot " &
                               "be one of the source directories",
                               Lib_Src_Dir.Location);
-                           Data.Library_Src_Dir := No_Path_Information;
+                           Project.Library_Src_Dir := No_Path_Information;
                            exit;
                         end if;
 
                         Src_Dirs := Src_Dir.Next;
                      end loop;
 
-                     if Data.Library_Src_Dir /= No_Path_Information then
+                     if Project.Library_Src_Dir /= No_Path_Information then
 
                         --  It cannot be a source directory of any other
                         --  project either.
 
-                        Project_Loop : for Pid in 1 ..
-                          Project_Table.Last (In_Tree.Projects)
-                        loop
-                           Src_Dirs :=
-                             In_Tree.Projects.Table (Pid).Source_Dirs;
+                        Pid := In_Tree.Projects;
+                        Project_Loop : loop
+                           exit Project_Loop when Pid = null;
+
+                           Src_Dirs := Pid.Project.Source_Dirs;
                            Dir_Loop : while Src_Dirs /= Nil_String loop
                               Src_Dir :=
                                 In_Tree.String_Elements.Table (Src_Dirs);
@@ -4973,25 +4811,27 @@ package body Prj.Nmsc is
                               --  Report error if it is one of the source
                               --  directories
 
-                              if Data.Library_Src_Dir.Name =
+                              if Project.Library_Src_Dir.Name =
                                 Path_Name_Type (Src_Dir.Value)
                               then
                                  Error_Msg_File_1 :=
                                    File_Name_Type (Src_Dir.Value);
-                                 Error_Msg_Name_1 :=
-                                   In_Tree.Projects.Table (Pid).Name;
+                                 Error_Msg_Name_1 := Pid.Project.Name;
                                  Error_Msg
                                    (Project, In_Tree,
                                     "directory to copy interfaces cannot " &
                                     "be the same as source directory { of " &
                                     "project %%",
                                     Lib_Src_Dir.Location);
-                                 Data.Library_Src_Dir := No_Path_Information;
+                                 Project.Library_Src_Dir :=
+                                   No_Path_Information;
                                  exit Project_Loop;
                               end if;
 
                               Src_Dirs := Src_Dir.Next;
                            end loop Dir_Loop;
+
+                           Pid := Pid.Next;
                         end loop Project_Loop;
                      end if;
                   end;
@@ -4999,12 +4839,12 @@ package body Prj.Nmsc is
                   --  In high verbosity, if there is a valid Library_Src_Dir,
                   --  display its path name.
 
-                  if Data.Library_Src_Dir /= No_Path_Information
+                  if Project.Library_Src_Dir /= No_Path_Information
                     and then Current_Verbosity = High
                   then
                      Write_Attr
                        ("Directory to copy interfaces",
-                        Get_Name_String (Data.Library_Src_Dir.Name));
+                        Get_Name_String (Project.Library_Src_Dir.Name));
                   end if;
                end if;
             end;
@@ -5024,19 +4864,19 @@ package body Prj.Nmsc is
                --  Symbol policy must hove one of a limited number of values
 
                if Value = "autonomous" or else Value = "default" then
-                  Data.Symbol_Data.Symbol_Policy := Autonomous;
+                  Project.Symbol_Data.Symbol_Policy := Autonomous;
 
                elsif Value = "compliant" then
-                  Data.Symbol_Data.Symbol_Policy := Compliant;
+                  Project.Symbol_Data.Symbol_Policy := Compliant;
 
                elsif Value = "controlled" then
-                  Data.Symbol_Data.Symbol_Policy := Controlled;
+                  Project.Symbol_Data.Symbol_Policy := Controlled;
 
                elsif Value = "restricted" then
-                  Data.Symbol_Data.Symbol_Policy := Restricted;
+                  Project.Symbol_Data.Symbol_Policy := Restricted;
 
                elsif Value = "direct" then
-                  Data.Symbol_Data.Symbol_Policy := Direct;
+                  Project.Symbol_Data.Symbol_Policy := Direct;
 
                else
                   Error_Msg
@@ -5051,7 +4891,7 @@ package body Prj.Nmsc is
          --  cannot be Restricted.
 
          if Lib_Symbol_File.Default then
-            if Data.Symbol_Data.Symbol_Policy = Restricted then
+            if Project.Symbol_Data.Symbol_Policy = Restricted then
                Error_Msg
                  (Project, In_Tree,
                   "Library_Symbol_File needs to be defined when " &
@@ -5062,7 +4902,7 @@ package body Prj.Nmsc is
          else
             --  Library_Symbol_File is defined
 
-            Data.Symbol_Data.Symbol_File :=
+            Project.Symbol_Data.Symbol_File :=
               Path_Name_Type (Lib_Symbol_File.Value);
 
             Get_Name_String (Lib_Symbol_File.Value);
@@ -5102,8 +4942,8 @@ package body Prj.Nmsc is
          --  symbol policy cannot be Compliant or Controlled.
 
          if Lib_Ref_Symbol_File.Default then
-            if Data.Symbol_Data.Symbol_Policy = Compliant
-              or else Data.Symbol_Data.Symbol_Policy = Controlled
+            if Project.Symbol_Data.Symbol_Policy = Compliant
+              or else Project.Symbol_Data.Symbol_Policy = Controlled
             then
                Error_Msg
                  (Project, In_Tree,
@@ -5114,7 +4954,7 @@ package body Prj.Nmsc is
          else
             --  Library_Reference_Symbol_File is defined, check file exists
 
-            Data.Symbol_Data.Reference :=
+            Project.Symbol_Data.Reference :=
               Path_Name_Type (Lib_Ref_Symbol_File.Value);
 
             Get_Name_String (Lib_Ref_Symbol_File.Value);
@@ -5129,15 +4969,15 @@ package body Prj.Nmsc is
                if not Is_Absolute_Path (Name_Buffer (1 .. Name_Len)) then
                   Name_Len := 0;
                   Add_Str_To_Name_Buffer
-                    (Get_Name_String (Data.Directory.Name));
+                    (Get_Name_String (Project.Directory.Name));
                   Add_Char_To_Name_Buffer (Directory_Separator);
                   Add_Str_To_Name_Buffer
                     (Get_Name_String (Lib_Ref_Symbol_File.Value));
-                  Data.Symbol_Data.Reference := Name_Find;
+                  Project.Symbol_Data.Reference := Name_Find;
                end if;
 
                if not Is_Regular_File
-                 (Get_Name_String (Data.Symbol_Data.Reference))
+                 (Get_Name_String (Project.Symbol_Data.Reference))
                then
                   Error_Msg_File_1 :=
                     File_Name_Type (Lib_Ref_Symbol_File.Value);
@@ -5147,8 +4987,8 @@ package body Prj.Nmsc is
                   --  symbol policies, this is just a warning
 
                   Error_Msg_Warn :=
-                    Data.Symbol_Data.Symbol_Policy /= Controlled
-                    and then Data.Symbol_Data.Symbol_Policy /= Direct;
+                    Project.Symbol_Data.Symbol_Policy /= Controlled
+                    and then Project.Symbol_Data.Symbol_Policy /= Direct;
 
                   Error_Msg
                     (Project, In_Tree,
@@ -5160,9 +5000,9 @@ package body Prj.Nmsc is
                   --  is no reference to check against, and we don't want to
                   --  fail in this case.
 
-                  if Data.Symbol_Data.Symbol_Policy /= Controlled then
-                     if Data.Symbol_Data.Symbol_Policy = Compliant then
-                        Data.Symbol_Data.Symbol_Policy := Autonomous;
+                  if Project.Symbol_Data.Symbol_Policy /= Controlled then
+                     if Project.Symbol_Data.Symbol_Policy = Compliant then
+                        Project.Symbol_Data.Symbol_Policy := Autonomous;
                      end if;
                   end if;
                end if;
@@ -5170,15 +5010,15 @@ package body Prj.Nmsc is
                --  If both the reference symbol file and the symbol file are
                --  defined, then check that they are not the same file.
 
-               if Data.Symbol_Data.Symbol_File /= No_Path then
-                  Get_Name_String (Data.Symbol_Data.Symbol_File);
+               if Project.Symbol_Data.Symbol_File /= No_Path then
+                  Get_Name_String (Project.Symbol_Data.Symbol_File);
 
                   if Name_Len > 0 then
                      declare
                         Symb_Path : constant String :=
                                       Normalize_Pathname
                                         (Get_Name_String
-                                           (Data.Object_Directory.Name) &
+                                           (Project.Object_Directory.Name) &
                                          Directory_Separator &
                                          Name_Buffer (1 .. Name_Len),
                                          Directory     => Current_Dir,
@@ -5187,7 +5027,7 @@ package body Prj.Nmsc is
                         Ref_Path  : constant String :=
                                       Normalize_Pathname
                                         (Get_Name_String
-                                           (Data.Symbol_Data.Reference),
+                                           (Project.Symbol_Data.Reference),
                                          Directory     => Current_Dir,
                                          Resolve_Links =>
                                            Opt.Follow_Links_For_Files);
@@ -5329,7 +5169,7 @@ package body Prj.Nmsc is
       --  If location of error is unknown, use the location of the project
 
       if Real_Location = No_Location then
-         Real_Location := In_Tree.Projects.Table (Project).Location;
+         Real_Location := Project.Location;
       end if;
 
       if Error_Report = null then
@@ -5397,36 +5237,35 @@ package body Prj.Nmsc is
    procedure Get_Directories
      (Project     : Project_Id;
       In_Tree     : Project_Tree_Ref;
-      Current_Dir : String;
-      Data        : in out Project_Data)
+      Current_Dir : String)
    is
       Object_Dir  : constant Variable_Value :=
                       Util.Value_Of
-                        (Name_Object_Dir, Data.Decl.Attributes, In_Tree);
+                        (Name_Object_Dir, Project.Decl.Attributes, In_Tree);
 
       Exec_Dir : constant Variable_Value :=
                    Util.Value_Of
-                     (Name_Exec_Dir, Data.Decl.Attributes, In_Tree);
+                     (Name_Exec_Dir, Project.Decl.Attributes, In_Tree);
 
       Source_Dirs : constant Variable_Value :=
                       Util.Value_Of
-                        (Name_Source_Dirs, Data.Decl.Attributes, In_Tree);
+                        (Name_Source_Dirs, Project.Decl.Attributes, In_Tree);
 
       Excluded_Source_Dirs : constant Variable_Value :=
                               Util.Value_Of
                                 (Name_Excluded_Source_Dirs,
-                                 Data.Decl.Attributes,
+                                 Project.Decl.Attributes,
                                  In_Tree);
 
       Source_Files : constant Variable_Value :=
                       Util.Value_Of
-                        (Name_Source_Files, Data.Decl.Attributes, In_Tree);
+                        (Name_Source_Files, Project.Decl.Attributes, In_Tree);
 
       Last_Source_Dir : String_List_Id  := Nil_String;
 
       Languages : constant Variable_Value :=
                       Prj.Util.Value_Of
-                        (Name_Languages, Data.Decl.Attributes, In_Tree);
+                        (Name_Languages, Project.Decl.Attributes, In_Tree);
 
       procedure Find_Source_Dirs
         (From     : File_Name_Type;
@@ -5500,7 +5339,7 @@ package body Prj.Nmsc is
 
             --  Check if directory is already in list
 
-            List := Data.Source_Dirs;
+            List := Project.Source_Dirs;
             Prev := Nil_String;
             while List /= Nil_String loop
                Element := In_Tree.String_Elements.Table (List);
@@ -5535,7 +5374,7 @@ package body Prj.Nmsc is
                --  Case of first source directory
 
                if Last_Source_Dir = Nil_String then
-                  Data.Source_Dirs := String_Element_Table.Last
+                  Project.Source_Dirs := String_Element_Table.Last
                                         (In_Tree.String_Elements);
 
                   --  Here we already have source directories
@@ -5558,7 +5397,7 @@ package body Prj.Nmsc is
 
             elsif Removed and Found then
                if Prev = Nil_String then
-                  Data.Source_Dirs :=
+                  Project.Source_Dirs :=
                     In_Tree.String_Elements.Table (List).Next;
                else
                   In_Tree.String_Elements.Table (Prev).Next :=
@@ -5633,7 +5472,7 @@ package body Prj.Nmsc is
                      Directory (Directory'Last - 2) = Directory_Separator)
          then
             if not Removed then
-               Data.Known_Order_Of_Source_Dirs := False;
+               Project.Known_Order_Of_Source_Dirs := False;
             end if;
 
             Name_Len := Directory'Length - 3;
@@ -5662,7 +5501,8 @@ package body Prj.Nmsc is
                             Normalize_Pathname
                               (Name      => Get_Name_String (Base_Dir),
                                Directory =>
-                                 Get_Name_String (Data.Directory.Display_Name),
+                                 Get_Name_String
+                                   (Project.Directory.Display_Name),
                                Resolve_Links  => False,
                                Case_Sensitive => True);
 
@@ -5674,7 +5514,7 @@ package body Prj.Nmsc is
                      Error_Msg
                        (Project, In_Tree,
                         "{ is not a valid directory.",
-                        Data.Location);
+                        Project.Location);
                   else
                      Error_Msg
                        (Project, In_Tree,
@@ -5704,29 +5544,28 @@ package body Prj.Nmsc is
 
          else
             declare
-               Path_Name         : Path_Name_Type;
-               Display_Path_Name : Path_Name_Type;
+               Path_Name         : Path_Information;
                List              : String_List_Id;
                Prev              : String_List_Id;
+               Dir_Exists        : Boolean;
 
             begin
                Locate_Directory
                  (Project     => Project,
                   In_Tree     => In_Tree,
                   Name        => From,
-                  Parent      => Data.Directory.Display_Name,
-                  Dir         => Path_Name,
-                  Display     => Display_Path_Name,
-                  Current_Dir => Current_Dir);
+                  Path        => Path_Name,
+                  Dir_Exists  => Dir_Exists,
+                  Must_Exist  => False);
 
-               if Path_Name = No_Path then
+               if not Dir_Exists then
                   Err_Vars.Error_Msg_File_1 := From;
 
                   if Location = No_Location then
                      Error_Msg
                        (Project, In_Tree,
                         "{ is not a valid directory",
-                        Data.Location);
+                        Project.Location);
                   else
                      Error_Msg
                        (Project, In_Tree,
@@ -5737,14 +5576,14 @@ package body Prj.Nmsc is
                else
                   declare
                      Path              : constant String :=
-                                           Get_Name_String (Path_Name) &
+                                           Get_Name_String (Path_Name.Name) &
                                            Directory_Separator;
                      Last_Path         : constant Natural :=
                                            Compute_Directory_Last (Path);
                      Path_Id           : Name_Id;
                      Display_Path      : constant String :=
                                            Get_Name_String
-                                             (Display_Path_Name) &
+                                             (Path_Name.Display_Name) &
                                            Directory_Separator;
                      Last_Display_Path : constant Natural :=
                                            Compute_Directory_Last
@@ -5780,7 +5619,7 @@ package body Prj.Nmsc is
 
                            --  This is the first source directory
 
-                           Data.Source_Dirs := String_Element_Table.Last
+                           Project.Source_Dirs := String_Element_Table.Last
                              (In_Tree.String_Elements);
 
                         else
@@ -5803,11 +5642,11 @@ package body Prj.Nmsc is
                      else
                         --  Remove source dir, if present
 
-                        List := Data.Source_Dirs;
                         Prev := Nil_String;
 
                         --  Look for source dir in current list
 
+                        List := Project.Source_Dirs;
                         while List /= Nil_String loop
                            Element := In_Tree.String_Elements.Table (List);
                            exit when Element.Value = Path_Id;
@@ -5819,7 +5658,7 @@ package body Prj.Nmsc is
                            --  Source dir was found, remove it from the list
 
                            if Prev = Nil_String then
-                              Data.Source_Dirs :=
+                              Project.Source_Dirs :=
                                 In_Tree.String_Elements.Table (List).Next;
 
                            else
@@ -5836,6 +5675,8 @@ package body Prj.Nmsc is
 
    --  Start of processing for Get_Directories
 
+      Dir_Exists : Boolean;
+
    begin
       if Current_Verbosity = High then
          Write_Line ("Starting to look for directories");
@@ -5847,15 +5688,14 @@ package body Prj.Nmsc is
       if (((not Source_Files.Default)
            and then Source_Files.Values = Nil_String)
           or else
-          ((not Source_Dirs.Default) and then Source_Dirs.Values = Nil_String)
-           or else
-          ((not Languages.Default) and then Languages.Values = Nil_String))
-        and then Data.Extends = No_Project
+           ((not Source_Dirs.Default) and then Source_Dirs.Values = Nil_String)
+              or else
+           ((not Languages.Default) and then Languages.Values = Nil_String))
+        and then Project.Extends = No_Project
       then
-         Data.Object_Directory := No_Path_Information;
-
+         Project.Object_Directory := No_Path_Information;
       else
-         Data.Object_Directory := Data.Directory;
+         Project.Object_Directory := Project.Directory;
       end if;
 
       --  Check the object directory
@@ -5870,48 +5710,41 @@ package body Prj.Nmsc is
                Object_Dir.Location);
 
          else
-            --  We check that the specified object directory does exist
+            --  We check that the specified object directory does exist.
+            --  However, even when it doesn't exist, we set it to a default
+            --  value. This is for the benefit of tools that recover from
+            --  errors; for example, these tools could create the non existent
+            --  directory.
+            --  We always return an absolute directory name though
 
             Locate_Directory
               (Project,
                In_Tree,
                File_Name_Type (Object_Dir.Value),
-               Data.Directory.Display_Name,
-               Data.Object_Directory.Name,
-               Data.Object_Directory.Display_Name,
+               Path             => Project.Object_Directory,
                Create           => "object",
+               Dir_Exists       => Dir_Exists,
                Location         => Object_Dir.Location,
-               Current_Dir      => Current_Dir,
-               Externally_Built => Data.Externally_Built);
-
-            if Data.Object_Directory = No_Path_Information then
-
-               --  The object directory does not exist, report an error if the
-               --  project is not externally built.
-
-               if not Data.Externally_Built then
-                  Err_Vars.Error_Msg_File_1 :=
-                    File_Name_Type (Object_Dir.Value);
-                  Error_Msg
-                    (Project, In_Tree,
-                     "the object directory { cannot be found",
-                     Data.Location);
-               end if;
+               Must_Exist       => False,
+               Externally_Built => Project.Externally_Built);
 
-               --  Do not keep a nil Object_Directory. Set it to the specified
-               --  (relative or absolute) path. This is for the benefit of
-               --  tools that recover from errors; for example, these tools
-               --  could create the non existent directory.
+            if not Dir_Exists
+              and then not Project.Externally_Built
+            then
+               --  The object directory does not exist, report an error if
+               --  the project is not externally built.
 
-               Data.Object_Directory.Display_Name :=
-                 Path_Name_Type (Object_Dir.Value);
-               Data.Object_Directory.Name :=
-                 Path_Name_Type (Canonical_Case_File_Name (Object_Dir.Value));
+               Err_Vars.Error_Msg_File_1 :=
+                 File_Name_Type (Object_Dir.Value);
+               Error_Msg
+                 (Project, In_Tree,
+                  "object directory { not found",
+                  Project.Location);
             end if;
          end if;
 
-      elsif Data.Object_Directory /= No_Path_Information and then
-        Subdirs /= null
+      elsif Project.Object_Directory /= No_Path_Information
+        and then Subdirs /= null
       then
          Name_Len := 1;
          Name_Buffer (1) := '.';
@@ -5919,22 +5752,20 @@ package body Prj.Nmsc is
            (Project,
             In_Tree,
             Name_Find,
-            Data.Directory.Display_Name,
-            Data.Object_Directory.Name,
-            Data.Object_Directory.Display_Name,
+            Path             => Project.Object_Directory,
             Create           => "object",
+            Dir_Exists       => Dir_Exists,
             Location         => Object_Dir.Location,
-            Current_Dir      => Current_Dir,
-            Externally_Built => Data.Externally_Built);
+            Externally_Built => Project.Externally_Built);
       end if;
 
       if Current_Verbosity = High then
-         if Data.Object_Directory = No_Path_Information then
+         if Project.Object_Directory = No_Path_Information then
             Write_Line ("No object directory");
          else
             Write_Attr
               ("Object directory",
-               Get_Name_String (Data.Object_Directory.Display_Name));
+               Get_Name_String (Project.Object_Directory.Display_Name));
          end if;
       end if;
 
@@ -5942,7 +5773,7 @@ package body Prj.Nmsc is
 
       --  We set the object directory to its default
 
-      Data.Exec_Directory   := Data.Object_Directory;
+      Project.Exec_Directory   := Project.Object_Directory;
 
       if Exec_Dir.Value /= Empty_String then
          Get_Name_String (Exec_Dir.Value);
@@ -5960,30 +5791,28 @@ package body Prj.Nmsc is
               (Project,
                In_Tree,
                File_Name_Type (Exec_Dir.Value),
-               Data.Directory.Display_Name,
-               Data.Exec_Directory.Name,
-               Data.Exec_Directory.Display_Name,
+               Path             => Project.Exec_Directory,
+               Dir_Exists       => Dir_Exists,
                Create           => "exec",
                Location         => Exec_Dir.Location,
-               Current_Dir      => Current_Dir,
-               Externally_Built => Data.Externally_Built);
+               Externally_Built => Project.Externally_Built);
 
-            if Data.Exec_Directory = No_Path_Information then
+            if not Dir_Exists then
                Err_Vars.Error_Msg_File_1 := File_Name_Type (Exec_Dir.Value);
                Error_Msg
                  (Project, In_Tree,
-                  "the exec directory { cannot be found",
-                  Data.Location);
+                  "exec directory { not found",
+                  Project.Location);
             end if;
          end if;
       end if;
 
       if Current_Verbosity = High then
-         if Data.Exec_Directory = No_Path_Information then
+         if Project.Exec_Directory = No_Path_Information then
             Write_Line ("No exec directory");
          else
             Write_Str ("Exec directory: """);
-            Write_Str (Get_Name_String (Data.Exec_Directory.Display_Name));
+            Write_Str (Get_Name_String (Project.Exec_Directory.Display_Name));
             Write_Line ("""");
          end if;
       end if;
@@ -5999,9 +5828,9 @@ package body Prj.Nmsc is
       if (not Source_Files.Default) and then
         Source_Files.Values = Nil_String
       then
-         Data.Source_Dirs := Nil_String;
+         Project.Source_Dirs := Nil_String;
 
-         if Data.Qualifier = Standard then
+         if Project.Qualifier = Standard then
             Error_Msg
               (Project,
                In_Tree,
@@ -6014,26 +5843,24 @@ package body Prj.Nmsc is
          --  No Source_Dirs specified: the single source directory is the one
          --  containing the project file
 
-         String_Element_Table.Increment_Last
-           (In_Tree.String_Elements);
-         Data.Source_Dirs := String_Element_Table.Last
-           (In_Tree.String_Elements);
-         In_Tree.String_Elements.Table (Data.Source_Dirs) :=
-           (Value         => Name_Id (Data.Directory.Name),
-            Display_Value => Name_Id (Data.Directory.Display_Name),
+         String_Element_Table.Append (In_Tree.String_Elements,
+           (Value         => Name_Id (Project.Directory.Name),
+            Display_Value => Name_Id (Project.Directory.Display_Name),
             Location      => No_Location,
             Flag          => False,
             Next          => Nil_String,
-            Index         => 0);
+            Index         => 0));
+         Project.Source_Dirs := String_Element_Table.Last
+                                  (In_Tree.String_Elements);
 
          if Current_Verbosity = High then
             Write_Attr
-              ("Single source directory",
-               Get_Name_String (Data.Directory.Display_Name));
+              ("Default source directory",
+               Get_Name_String (Project.Directory.Display_Name));
          end if;
 
       elsif Source_Dirs.Values = Nil_String then
-         if Data.Qualifier = Standard then
+         if Project.Qualifier = Standard then
             Error_Msg
               (Project,
                In_Tree,
@@ -6041,7 +5868,7 @@ package body Prj.Nmsc is
                Source_Dirs.Location);
          end if;
 
-         Data.Source_Dirs := Nil_String;
+         Project.Source_Dirs := Nil_String;
 
       else
          declare
@@ -6088,7 +5915,7 @@ package body Prj.Nmsc is
       end if;
 
       declare
-         Current : String_List_Id := Data.Source_Dirs;
+         Current : String_List_Id := Project.Source_Dirs;
          Element : String_Element;
 
       begin
@@ -6111,29 +5938,27 @@ package body Prj.Nmsc is
 
    procedure Get_Mains
      (Project : Project_Id;
-      In_Tree : Project_Tree_Ref;
-      Data    : in out Project_Data)
+      In_Tree : Project_Tree_Ref)
    is
       Mains : constant Variable_Value :=
-                Prj.Util.Value_Of (Name_Main, Data.Decl.Attributes, In_Tree);
+               Prj.Util.Value_Of (Name_Main, Project.Decl.Attributes, In_Tree);
       List  : String_List_Id;
       Elem  : String_Element;
 
    begin
-      Data.Mains := Mains.Values;
+      Project.Mains := Mains.Values;
 
       --  If no Mains were specified, and if we are an extending project,
       --  inherit the Mains from the project we are extending.
 
       if Mains.Default then
-         if not Data.Library and then Data.Extends /= No_Project then
-            Data.Mains :=
-              In_Tree.Projects.Table (Data.Extends).Mains;
+         if not Project.Library and then Project.Extends /= No_Project then
+            Project.Mains := Project.Extends.Mains;
          end if;
 
       --  In a library project file, Main cannot be specified
 
-      elsif Data.Library then
+      elsif Project.Library then
          Error_Msg
            (Project, In_Tree,
             "a library project file cannot have Main specified",
@@ -6246,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;
@@ -6311,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))
@@ -6326,6 +6150,7 @@ package body Prj.Nmsc is
                      if Current_Verbosity = High then
                         Write_Line ("  Invalid casing");
                      end if;
+
                      return;
                   end if;
                end loop;
@@ -6338,6 +6163,7 @@ package body Prj.Nmsc is
                      if Current_Verbosity = High then
                         Write_Line ("  Invalid casing");
                      end if;
+
                      return;
                   end if;
                end loop;
@@ -6351,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
@@ -6360,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);
@@ -6385,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'
@@ -6477,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)
@@ -6486,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
@@ -6505,25 +6335,28 @@ package body Prj.Nmsc is
       if Info_Id /= No_Ada_Naming_Exception then
          Exception_Id := Info_Id;
          Unit_Name := No_Name;
-         Unit_Kind := Specification;
+         Unit_Kind := Spec;
 
       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 := Specification;
-            when Impl | Sep => Unit_Kind := Body_Part;
-         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;
 
@@ -6547,19 +6380,21 @@ package body Prj.Nmsc is
       Suffix_Str : constant String := Get_Name_String (Suffix);
 
    begin
-      if Suffix_Str'Length = 0 or else Index (Suffix_Str, ".") = 0 then
+      if Suffix_Str'Length = 0 then
+         return False;
+      elsif Index (Suffix_Str, ".") = 0 then
          return True;
       end if;
 
-      --  If dot replacement is a single dot, and first character of suffix is
-      --  also a dot
+      --  Case of dot replacement is a single dot, and first character of
+      --  suffix is also a dot.
 
       if Get_Name_String (Dot_Replacement) = "."
         and then Suffix_Str (Suffix_Str'First) = '.'
       then
          for Index in Suffix_Str'First + 1 .. Suffix_Str'Last loop
 
-            --  If there is another dot
+            --  Case of following dot
 
             if Suffix_Str (Index) = '.' then
 
@@ -6581,14 +6416,15 @@ package body Prj.Nmsc is
      (Project          : Project_Id;
       In_Tree          : Project_Tree_Ref;
       Name             : File_Name_Type;
-      Parent           : Path_Name_Type;
-      Dir              : out Path_Name_Type;
-      Display          : out Path_Name_Type;
+      Path             : out Path_Information;
+      Dir_Exists       : out Boolean;
       Create           : String := "";
-      Current_Dir      : String;
       Location         : Source_Ptr := No_Location;
+      Must_Exist       : Boolean := True;
       Externally_Built : Boolean := False)
    is
+      Parent          : constant Path_Name_Type :=
+                          Project.Directory.Display_Name;
       The_Parent      : constant String :=
                           Get_Name_String (Parent) & Directory_Separator;
       The_Parent_Last : constant Natural :=
@@ -6628,8 +6464,8 @@ package body Prj.Nmsc is
          Write_Line (""")");
       end if;
 
-      Dir     := No_Path;
-      Display := No_Path;
+      Path := No_Path_Information;
+      Dir_Exists := False;
 
       if Is_Absolute_Path (Get_Name_String (The_Name)) then
          Full_Name := The_Name;
@@ -6676,7 +6512,8 @@ package body Prj.Nmsc is
                         Write_Str (Create);
                         Write_Str (" directory """);
                         Write_Str (Full_Path_Name.all);
-                        Write_Line (""" created");
+                        Write_Str (""" created for project ");
+                        Write_Line (Get_Name_String (Project.Name));
                      end if;
 
                   exception
@@ -6691,19 +6528,24 @@ package body Prj.Nmsc is
             end if;
          end if;
 
-         if Is_Directory (Full_Path_Name.all) then
+         Dir_Exists := Is_Directory (Full_Path_Name.all);
+
+         if not Must_Exist or else Dir_Exists then
             declare
                Normed : constant String :=
                           Normalize_Pathname
                             (Full_Path_Name.all,
-                             Directory      => Current_Dir,
+                             Directory      =>
+                              The_Parent (The_Parent'First .. The_Parent_Last),
                              Resolve_Links  => False,
                              Case_Sensitive => True);
 
                Canonical_Path : constant String :=
                                   Normalize_Pathname
                                     (Normed,
-                                     Directory      => Current_Dir,
+                                     Directory      =>
+                                       The_Parent
+                                         (The_Parent'First .. The_Parent_Last),
                                      Resolve_Links  =>
                                         Opt.Follow_Links_For_Dirs,
                                      Case_Sensitive => False);
@@ -6711,11 +6553,11 @@ package body Prj.Nmsc is
             begin
                Name_Len := Normed'Length;
                Name_Buffer (1 .. Name_Len) := Normed;
-               Display := Name_Find;
+               Path.Display_Name := Name_Find;
 
                Name_Len := Canonical_Path'Length;
                Name_Buffer (1 .. Name_Len) := Canonical_Path;
-               Dir := Name_Find;
+               Path.Name := Name_Find;
             end;
          end if;
 
@@ -6729,18 +6571,17 @@ package body Prj.Nmsc is
 
    procedure Find_Excluded_Sources
      (Project : Project_Id;
-      In_Tree : Project_Tree_Ref;
-      Data    : Project_Data)
+      In_Tree : Project_Tree_Ref)
    is
       Excluded_Source_List_File : constant Variable_Value :=
                                     Util.Value_Of
                                       (Name_Excluded_Source_List_File,
-                                       Data.Decl.Attributes,
+                                       Project.Decl.Attributes,
                                        In_Tree);
 
       Excluded_Sources          : Variable_Value := Util.Value_Of
                                     (Name_Excluded_Source_Files,
-                                     Data.Decl.Attributes,
+                                     Project.Decl.Attributes,
                                      In_Tree);
 
       Current         : String_List_Id;
@@ -6760,7 +6601,7 @@ package body Prj.Nmsc is
          Locally_Removed := True;
          Excluded_Sources :=
            Util.Value_Of
-             (Name_Locally_Removed_Files, Data.Decl.Attributes, In_Tree);
+             (Name_Locally_Removed_Files, Project.Decl.Attributes, In_Tree);
       end if;
 
       Excluded_Sources_Htable.Reset;
@@ -6810,7 +6651,7 @@ package body Prj.Nmsc is
                                       Path_Name_Of
                                         (File_Name_Type
                                            (Excluded_Source_List_File.Value),
-                                         Data.Directory.Name);
+                                         Project.Directory.Name);
 
          begin
             if Source_File_Path_Name'Length = 0 then
@@ -6880,19 +6721,20 @@ package body Prj.Nmsc is
    ------------------
 
    procedure Find_Sources
-     (Project : Project_Id;
-      In_Tree : Project_Tree_Ref;
-      Data    : in out Project_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
                              (Name_Source_Files,
-                              Data.Decl.Attributes,
+                              Project.Decl.Attributes,
                               In_Tree);
       Source_List_File : constant Variable_Value :=
                            Util.Value_Of
                              (Name_Source_List_File,
-                              Data.Decl.Attributes,
+                              Project.Decl.Attributes,
                               In_Tree);
       Name_Loc         : Name_Location;
 
@@ -6904,7 +6746,7 @@ package body Prj.Nmsc is
         (Source_List_File.Kind = Single,
          "Source_List_File is not a single string");
 
-      --  If the user has specified a Sources attribute
+      --  If the user has specified a Source_Files attribute
 
       if not Sources.Default then
          if not Source_List_File.Default then
@@ -6926,16 +6768,16 @@ package body Prj.Nmsc is
          begin
             if Get_Mode = Multi_Language then
                if Current = Nil_String then
-                  Data.Languages := No_Language_Index;
+                  Project.Languages := No_Language_Index;
 
                   --  This project contains no source. For projects that don't
                   --  extend other projects, this also means that there is no
                   --  need for an object directory, if not specified.
 
-                  if Data.Extends = No_Project
-                    and then Data.Object_Directory = Data.Directory
+                  if Project.Extends = No_Project
+                    and then Project.Object_Directory = Project.Directory
                   then
-                     Data.Object_Directory := No_Path_Information;
+                     Project.Object_Directory := No_Path_Information;
                   end if;
                end if;
             end if;
@@ -7010,7 +6852,8 @@ package body Prj.Nmsc is
          declare
             Source_File_Path_Name : constant String :=
               Path_Name_Of
-                (File_Name_Type (Source_List_File.Value), Data.Directory.Name);
+                (File_Name_Type (Source_List_File.Value),
+                 Project.Directory.Name);
 
          begin
             Has_Explicit_Sources := True;
@@ -7040,14 +6883,16 @@ package body Prj.Nmsc is
 
       if Get_Mode = Ada_Only then
          Find_Ada_Sources
-           (Project, In_Tree, Data,
-            Explicit_Sources_Only => Has_Explicit_Sources);
+           (Project, In_Tree,
+            Explicit_Sources_Only => Has_Explicit_Sources,
+            Proc_Data             => Proc_Data);
 
       else
          Search_Directories
-           (Project, In_Tree, Data,
-            For_All_Sources =>
-              Sources.Default and then Source_List_File.Default);
+           (Project, In_Tree,
+            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
@@ -7067,9 +6912,9 @@ package body Prj.Nmsc is
             if Source.Naming_Exception
               and then Source.Path = No_Path_Information
             then
-               if Source.Unit /= No_Name then
+               if Source.Unit /= No_Unit_Index then
                   Error_Msg_Name_1 := Name_Id (Source.Display_File);
-                  Error_Msg_Name_2 := Name_Id (Source.Unit);
+                  Error_Msg_Name_2 := Name_Id (Source.Unit.Name);
                   Error_Msg
                     (Project, In_Tree,
                      "source file %% for unit %% not found",
@@ -7101,14 +6946,14 @@ package body Prj.Nmsc is
                   if First_Error then
                      Error_Msg
                        (Project, In_Tree,
-                        "source file { cannot be found",
+                        "source file { not found",
                         NL.Location);
                      First_Error := False;
 
                   else
                      Error_Msg
                        (Project, In_Tree,
-                        "\source file { cannot be found",
+                        "\source file { not found",
                         NL.Location);
                   end if;
                end if;
@@ -7119,17 +6964,35 @@ package body Prj.Nmsc is
       end if;
 
       if Get_Mode = Ada_Only
-        and then Data.Extends = No_Project
+        and then Project.Extends = No_Project
       then
          --  We should have found at least one source, if not report an error
 
-         if not Has_Ada_Sources (Data) then
+         if not Has_Ada_Sources (Project) then
             Report_No_Sources
               (Project, "Ada", In_Tree, Source_List_File.Location);
          end if;
       end if;
    end Find_Sources;
 
+   ----------------
+   -- Initialize --
+   ----------------
+
+   procedure Initialize (Proc_Data : in out Processing_Data) is
+   begin
+      Files_Htable.Reset (Proc_Data.Units);
+   end Initialize;
+
+   ----------
+   -- Free --
+   ----------
+
+   procedure Free (Proc_Data : in out Processing_Data) is
+   begin
+      Files_Htable.Reset (Proc_Data.Units);
+   end Free;
+
    ----------------------
    -- Find_Ada_Sources --
    ----------------------
@@ -7137,8 +7000,8 @@ package body Prj.Nmsc is
    procedure Find_Ada_Sources
      (Project               : Project_Id;
       In_Tree               : Project_Tree_Ref;
-      Data                  : in out Project_Data;
-      Explicit_Sources_Only : Boolean)
+      Explicit_Sources_Only : Boolean;
+      Proc_Data             : in out Processing_Data)
    is
       Source_Dir     : String_List_Id;
       Element        : String_Element;
@@ -7152,7 +7015,7 @@ package body Prj.Nmsc is
          Write_Line ("Looking for Ada sources:");
       end if;
 
-      Ada_Language := Data.Languages;
+      Ada_Language := Project.Languages;
       while Ada_Language /= No_Language_Index
         and then Ada_Language.Name /= Name_Ada
       loop
@@ -7162,7 +7025,7 @@ package body Prj.Nmsc is
       --  We look in all source directories for the file names in the hash
       --  table Source_Names.
 
-      Source_Dir := Data.Source_Dirs;
+      Source_Dir := Project.Source_Dirs;
       while Source_Dir /= Nil_String loop
          Dir_Has_Source := False;
          Element := In_Tree.String_Elements.Table (Source_Dir);
@@ -7251,7 +7114,7 @@ package body Prj.Nmsc is
                         Path_Name       => Path_Name,
                         Project         => Project,
                         In_Tree         => In_Tree,
-                        Data            => Data,
+                        Proc_Data       => Proc_Data,
                         Ada_Language    => Ada_Language,
                         Location        => Location,
                         Source_Recorded => Dir_Has_Source);
@@ -7285,11 +7148,10 @@ package body Prj.Nmsc is
 
    procedure Check_File_Naming_Schemes
      (In_Tree               : Project_Tree_Ref;
-      Data                  : in out Project_Data;
+      Project               : Project_Id;
       File_Name             : File_Name_Type;
-      Alternate_Languages   : out Alternate_Language_Id;
+      Alternate_Languages   : out Language_List;
       Language              : out Language_Ptr;
-      Language_Name         : out Name_Id;
       Display_Language_Name : out Name_Id;
       Unit                  : out Name_Id;
       Lang_Kind             : out Language_Kind;
@@ -7313,7 +7175,7 @@ package body Prj.Nmsc is
       --  Returns True if the file belongs to the current language and we
       --  should stop searching for matching languages. Not that a given header
       --  file could belong to several languages (C and C++ for instance). Thus
-      --  if we found a header we'll check whether it matches other languages
+      --  if we found a header we'll check whether it matches other languages.
 
       ---------------------------
       -- Check_File_Based_Lang --
@@ -7340,13 +7202,9 @@ package body Prj.Nmsc is
             end if;
 
             if Header_File then
-               Alternate_Language_Table.Increment_Last (In_Tree.Alt_Langs);
-               In_Tree.Alt_Langs.Table
-                 (Alternate_Language_Table.Last (In_Tree.Alt_Langs)) :=
+               Alternate_Languages := new Language_List_Element'
                  (Language => Language,
                   Next     => Alternate_Languages);
-               Alternate_Languages :=
-                 Alternate_Language_Table.Last (In_Tree.Alt_Langs);
 
             else
                Header_File := True;
@@ -7361,20 +7219,18 @@ package body Prj.Nmsc is
 
    begin
       Language              := No_Language_Index;
-      Alternate_Languages   := No_Alternate_Language;
+      Alternate_Languages   := null;
       Display_Language_Name := No_Name;
       Unit                  := No_Name;
       Lang_Kind             := File_Based;
       Kind                  := Spec;
 
-      Tmp_Lang := Data.Languages;
+      Tmp_Lang := Project.Languages;
       while Tmp_Lang /= No_Language_Index loop
-         Language_Name := Tmp_Lang.Name;
-
          if Current_Verbosity = High then
             Write_Line
               ("     Testing language "
-               & Get_Name_String (Language_Name)
+               & Get_Name_String (Tmp_Lang.Name)
                & " Header_File=" & Header_File'Img);
          end if;
 
@@ -7395,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);
@@ -7421,18 +7273,48 @@ package body Prj.Nmsc is
       end if;
    end Check_File_Naming_Schemes;
 
+   -------------------
+   -- Override_Kind --
+   -------------------
+
+   procedure Override_Kind (Source : Source_Id; Kind : Source_Kind) is
+   begin
+      --  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;
+
+      Source.Kind := Kind;
+
+      if Source.Kind in Spec_Or_Body and then Source.Unit /= null then
+         Source.Unit.File_Names (Source.Kind) := Source;
+      end if;
+   end Override_Kind;
+
    ----------------
    -- Check_File --
    ----------------
 
    procedure Check_File
-     (Project           : Project_Id;
-      In_Tree           : Project_Tree_Ref;
-      Data              : in out Project_Data;
-      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
@@ -7440,15 +7322,13 @@ package body Prj.Nmsc is
 
       Name_Loc              : Name_Location := Source_Names.Get (File_Name);
       Check_Name            : Boolean := False;
-      Alternate_Languages   : Alternate_Language_Id := No_Alternate_Language;
+      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;
       Source_To_Replace     : Source_Id := No_Source;
-      Language_Name         : Name_Id;
       Display_Language_Name : Name_Id;
       Lang_Kind             : Language_Kind;
       Kind                  : Source_Kind := Spec;
@@ -7460,11 +7340,10 @@ 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.
 
-            if not Data.Known_Order_Of_Source_Dirs then
+            if not Project.Known_Order_Of_Source_Dirs then
                Error_Msg_File_1 := File_Name;
                Error_Msg
                  (Project, In_Tree,
@@ -7481,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
@@ -7490,14 +7375,14 @@ package body Prj.Nmsc is
 
                --  Check if this is a subunit
 
-               if Name_Loc.Source.Unit /= No_Name
+               if Name_Loc.Source.Unit /= No_Unit_Index
                  and then Name_Loc.Source.Kind = Impl
                then
                   Src_Ind := Sinput.P.Load_Project_File
                     (Get_Name_String (Canonical_Path));
 
                   if Sinput.P.Source_File_Is_Subunit (Src_Ind) then
-                     Name_Loc.Source.Kind := Sep;
+                     Override_Kind (Name_Loc.Source, Sep);
                   end if;
                end if;
             end if;
@@ -7505,15 +7390,12 @@ package body Prj.Nmsc is
       end if;
 
       if Check_Name then
-         Other_Part := No_Source;
-
          Check_File_Naming_Schemes
            (In_Tree               => In_Tree,
-            Data                  => Data,
+            Project               => Project,
             File_Name             => File_Name,
             Alternate_Languages   => Alternate_Languages,
             Language              => Language,
-            Language_Name         => Language_Name,
             Display_Language_Name => Display_Language_Name,
             Unit                  => Unit,
             Lang_Kind             => Lang_Kind,
@@ -7542,16 +7424,20 @@ package body Prj.Nmsc is
                exit when Source = No_Source;
 
                if Unit /= No_Name
-                 and then Source.Unit = Unit
+                 and then Source.Unit /= No_Unit_Index
+                 and then Source.Unit.Name = Unit
                  and then
                    ((Source.Kind = Spec and then Kind = Impl)
                        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 = Unit
+                      and then Source.Unit /= No_Unit_Index
+                      and then Source.Unit.Name = Unit
                       and then
                         (Source.Kind = Kind
                            or else
@@ -7565,22 +7451,29 @@ package body Prj.Nmsc is
                   --  allowed if order of source directories is known.
 
                   if Project = Source.Project then
-                     if Data.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,
@@ -7590,7 +7483,7 @@ package body Prj.Nmsc is
                      --  a file in a project being extended, but it is allowed
                      --  to have the same file name in unrelated projects.
 
-                  elsif Is_Extending (Project, Source.Project, In_Tree) then
+                  elsif Is_Extending (Project, Source.Project) then
                      Source_To_Replace := Source;
 
                   elsif Unit /= No_Name
@@ -7602,14 +7495,12 @@ package body Prj.Nmsc is
                         "unit %% cannot belong to several projects",
                         No_Location);
 
-                     Error_Msg_Name_1 :=
-                       In_Tree.Projects.Table (Project).Name;
+                     Error_Msg_Name_1 := Project.Name;
                      Error_Msg_Name_2 := Name_Id (Path);
                      Error_Msg
                        (Project, In_Tree, "\  project %%, %%", No_Location);
 
-                     Error_Msg_Name_1 :=
-                       In_Tree.Projects.Table (Source.Project).Name;
+                     Error_Msg_Name_1 := Source.Project.Name;
                      Error_Msg_Name_2 := Name_Id (Source.Path.Display_Name);
                      Error_Msg
                        (Project, In_Tree, "\  project %%, %%", No_Location);
@@ -7627,12 +7518,10 @@ package body Prj.Nmsc is
                   In_Tree             => In_Tree,
                   Project             => Project,
                   Lang_Id             => Language,
-                  Lang_Kind           => Lang_Kind,
                   Kind                => Kind,
                   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);
@@ -7646,10 +7535,10 @@ package body Prj.Nmsc is
    ------------------------
 
    procedure Search_Directories
-     (Project         : Project_Id;
-      In_Tree         : Project_Tree_Ref;
-      Data            : in out Project_Data;
-      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;
@@ -7666,7 +7555,7 @@ package body Prj.Nmsc is
 
       --  Loop through subdirectories
 
-      Source_Dir := Data.Source_Dirs;
+      Source_Dir := Project.Source_Dirs;
       while Source_Dir /= Nil_String loop
          begin
             Element := In_Tree.String_Elements.Table (Source_Dir);
@@ -7722,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 :=
@@ -7752,13 +7645,15 @@ package body Prj.Nmsc is
 
                            else
                               Check_File
-                                (Project           => Project,
-                                 In_Tree           => In_Tree,
-                                 Data              => Data,
-                                 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;
@@ -7822,18 +7717,18 @@ package body Prj.Nmsc is
               (Name     => Source.File,
                Location => No_Location,
                Source   => Source,
-               Except   => Source.Unit /= No_Name,
+               Except   => Source.Unit /= No_Unit_Index,
                Found    => False));
 
          --  If this is an Ada exception, record in table Unit_Exceptions
 
-         if Source.Unit /= No_Name then
+         if Source.Unit /= No_Unit_Index then
             declare
                Unit_Except : Unit_Exception :=
-                                Unit_Exceptions.Get (Source.Unit);
+                                Unit_Exceptions.Get (Source.Unit.Name);
 
             begin
-               Unit_Except.Name := Source.Unit;
+               Unit_Except.Name := Source.Unit.Name;
 
                if Source.Kind = Spec then
                   Unit_Except.Spec := Source.File;
@@ -7841,7 +7736,7 @@ package body Prj.Nmsc is
                   Unit_Except.Impl := Source.File;
                end if;
 
-               Unit_Exceptions.Set (Source.Unit, Unit_Except);
+               Unit_Exceptions.Set (Source.Unit.Name, Unit_Except);
             end;
          end if;
 
@@ -7854,9 +7749,10 @@ package body Prj.Nmsc is
    ----------------------
 
    procedure Look_For_Sources
-     (Project     : Project_Id;
-      In_Tree     : Project_Tree_Ref;
-      Data        : in out Project_Data)
+     (Project                   : Project_Id;
+      In_Tree                   : Project_Tree_Ref;
+      Proc_Data                 : in out Processing_Data;
+      Allow_Duplicate_Basenames : Boolean)
    is
       Iter : Source_Iterator;
 
@@ -7873,103 +7769,60 @@ package body Prj.Nmsc is
       procedure Mark_Excluded_Sources is
          Source   : Source_Id := No_Source;
          OK       : Boolean;
-         Unit     : Unit_Data;
-         Excluded : File_Found := Excluded_Sources_Htable.Get_First;
-
-         procedure Exclude
-           (Extended : Project_Id;
-            Index    : Unit_Index;
-            Kind     : Spec_Or_Body);
-         --  If the current file (Excluded) belongs to the current project or
-         --  one that the current project extends, then mark this file/unit as
-         --  excluded. It is an error to locally remove a file from another
-         --  project.
-
-         -------------
-         -- Exclude --
-         -------------
-
-         procedure Exclude
-           (Extended : Project_Id;
-            Index    : Unit_Index;
-            Kind     : Spec_Or_Body)
-         is
-         begin
-            if Extended = Project
-              or else Is_Extending (Project, Extended, In_Tree)
-            then
-               OK := True;
-
-               if Index /= No_Unit_Index then
-                  Unit.File_Names (Kind).Path.Name    := Slash;
-                  Unit.File_Names (Kind).Needs_Pragma := False;
-                  In_Tree.Units.Table (Index) := Unit;
-               end if;
-
-               if Source /= No_Source then
-                  Source.Locally_Removed := True;
-                  Source.In_Interfaces := False;
-               end if;
-
-               if Current_Verbosity = High then
-                  Write_Str ("Removing file ");
-                  Write_Line (Get_Name_String (Excluded.File));
-               end if;
-
-               Add_Forbidden_File_Name (Excluded.File);
-
-            else
-               Error_Msg
-                 (Project, In_Tree,
-                  "cannot remove a source from another project",
-                  Excluded.Location);
-            end if;
-         end Exclude;
-
-      --  Start of processing for Mark_Excluded_Sources
+         Excluded : File_Found;
 
       begin
+         Excluded := Excluded_Sources_Htable.Get_First;
          while Excluded /= No_File_Found loop
-            OK     := False;
+            OK := False;
 
-            case Get_Mode is
-            when Ada_Only =>
+            --  ??? 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 ?
 
-               --  ??? This loop could be the same as for Multi_Language if
-               --  we were setting In_Tree.First_Source when we search for
-               --  Ada sources (basically once we have removed the use of
-               --  Data.Ada_Sources).
+            Iter := For_Each_Source (In_Tree);
+            loop
+               Source := Prj.Element (Iter);
+               exit when Source = No_Source;
 
-               For_Each_Unit :
-               for Index in Unit_Table.First ..
-                 Unit_Table.Last (In_Tree.Units)
-               loop
-                  Unit := In_Tree.Units.Table (Index);
+               if Source.File = Excluded.File then
+                  if Source.Project = Project
+                    or else Is_Extending (Project, Source.Project)
+                  then
+                     OK := True;
+                     Source.Locally_Removed := True;
+                     Source.In_Interfaces := False;
 
-                  for Kind in Spec_Or_Body'Range loop
-                     if Unit.File_Names (Kind).Name = Excluded.File then
-                        Exclude (Unit.File_Names (Kind).Project, Index, Kind);
-                        exit For_Each_Unit;
+                     if Current_Verbosity = High then
+                        Write_Str ("Removing file ");
+                        Write_Line
+                          (Get_Name_String (Excluded.File)
+                           & " " & Get_Name_String (Source.Project.Name));
                      end if;
-                  end loop;
-               end loop For_Each_Unit;
-
-            when Multi_Language =>
-               Iter := For_Each_Source (In_Tree);
-               loop
-                  Source := Prj.Element (Iter);
-                  exit when Source = No_Source;
 
-                  if Source.File = Excluded.File then
-                     Exclude (Source.Project, No_Unit_Index, Specification);
-                     exit;
+                  else
+                     Error_Msg
+                       (Project, In_Tree,
+                        "cannot remove a source from another project",
+                        Excluded.Location);
                   end if;
 
-                  Next (Iter);
-               end loop;
+                  --  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
 
-               OK := OK or Excluded.Found;
-            end case;
+                  --  exit;
+               end if;
+
+               Next (Iter);
+            end loop;
+
+            OK := OK or Excluded.Found;
 
             if not OK then
                Err_Vars.Error_Msg_File_1 := Excluded.File;
@@ -7987,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.
@@ -8031,10 +7885,11 @@ package body Prj.Nmsc is
                Src_Id := Prj.Element (Iter);
                exit when Src_Id = No_Source;
 
-               if Src_Id.Compiled and then Src_Id.Object_Exists
-                 and then Is_Extending (Project, Src_Id.Project, In_Tree)
+               if Is_Compilable (Src_Id)
+                 and then Src_Id.Language.Config.Object_Generated
+                 and then Is_Extending (Project, Src_Id.Project)
                then
-                  if Src_Id.Unit = No_Name then
+                  if Src_Id.Unit = No_Unit_Index then
                      if Src_Id.Kind = Impl then
                         Check_Object (Src_Id);
                      end if;
@@ -8042,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;
 
@@ -8050,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
@@ -8058,14 +7913,14 @@ 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
-                                    Src_Id.Kind := Sep;
+                                    Override_Kind (Src_Id, Sep);
                                  else
                                     Check_Object (Src_Id);
                                  end if;
@@ -8084,17 +7939,17 @@ package body Prj.Nmsc is
 
    begin
       Source_Names.Reset;
-      Find_Excluded_Sources (Project, In_Tree, Data);
+      Find_Excluded_Sources (Project, In_Tree);
 
-      if (Get_Mode = Ada_Only and then Is_A_Language (Data, Name_Ada))
+      if (Get_Mode = Ada_Only and then Is_A_Language (Project, Name_Ada))
         or else (Get_Mode = Multi_Language
-                  and then Data.Languages /= No_Language_Index)
+                  and then Project.Languages /= No_Language_Index)
       then
          if Get_Mode = Multi_Language then
             Load_Naming_Exceptions (Project, In_Tree);
          end if;
 
-         Find_Sources (Project, In_Tree, Data);
+         Find_Sources (Project, In_Tree, Proc_Data, Allow_Duplicate_Basenames);
          Mark_Excluded_Sources;
 
          if Get_Mode = Multi_Language then
@@ -8184,7 +8039,7 @@ package body Prj.Nmsc is
       Path_Name       : Path_Name_Type;
       Project         : Project_Id;
       In_Tree         : Project_Tree_Ref;
-      Data            : in out Project_Data;
+      Proc_Data       : in out Processing_Data;
       Ada_Language    : Language_Ptr;
       Location        : Source_Ptr;
       Source_Recorded : in out Boolean)
@@ -8214,14 +8069,14 @@ package body Prj.Nmsc is
          Unit_Kind    : Spec_Or_Body;
          Needs_Pragma : Boolean)
       is
-         The_Unit      : Unit_Index :=
-                           Units_Htable.Get (In_Tree.Units_HT, Unit_Name);
-         UData         : Unit_Data;
-         Kind          : Source_Kind;
-         Source        : Source_Id;
-         To_Record     : Boolean := False;
-         The_Location  : Source_Ptr := Location;
-         Unit_Prj      : Project_Id;
+         UData : constant Unit_Index :=
+                   Units_Htable.Get (In_Tree.Units_HT, Unit_Name);
+         --  ??? Add_Source will look it up again, can we do that only once ?
+
+         Source       : Source_Id;
+         To_Record    : Boolean := False;
+         The_Location : Source_Ptr := Location;
+         Unit_Prj     : Project_Id;
 
       begin
          if Current_Verbosity = High then
@@ -8234,42 +8089,21 @@ package body Prj.Nmsc is
          --  unit kind (spec or body), or what is in the unit list is a unit of
          --  a project we are extending.
 
-         if The_Unit /= No_Unit_Index then
-            UData := In_Tree.Units.Table (The_Unit);
-
-            if (UData.File_Names (Unit_Kind).Name = Canonical_File
-                 and then UData.File_Names (Unit_Kind).Path.Name = Slash)
-              or else UData.File_Names (Unit_Kind).Name = No_File
+         if UData /= No_Unit_Index 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).Locally_Removed)
               or else Is_Extending
-                (Data.Extends,
-                 UData.File_Names (Unit_Kind).Project,
-                 In_Tree)
+                (Project.Extends, UData.File_Names (Unit_Kind).Project)
             then
-               if UData.File_Names (Unit_Kind).Path.Name = Slash then
-                  Remove_Forbidden_File_Name
-                    (UData.File_Names (Unit_Kind).Name);
-               end if;
-
-               --  Record the file name in the hash table Files_Htable
-
-               Files_Htable.Set (In_Tree.Files_HT, Canonical_File, Project);
-
-               UData.File_Names (Unit_Kind) :=
-                 (Name         => Canonical_File,
-                  Index        => Unit_Ind,
-                  Display_Name => File_Name,
-                  Path         => (Canonical_Path, Path_Name),
-                  Project      => Project,
-                  Needs_Pragma => Needs_Pragma);
-               In_Tree.Units.Table (The_Unit) := UData;
                To_Record       := True;
-               Source_Recorded := True;
 
             --  If the same file is already in the list, do not add it again
 
             elsif UData.File_Names (Unit_Kind).Project = Project
               and then
-                (Data.Known_Order_Of_Source_Dirs
+                (Project.Known_Order_Of_Source_Dirs
                   or else
                     UData.File_Names (Unit_Kind).Path.Name = Canonical_Path)
             then
@@ -8280,7 +8114,7 @@ package body Prj.Nmsc is
 
             else
                if The_Location = No_Location then
-                  The_Location := In_Tree.Projects.Table (Project).Location;
+                  The_Location := Project.Location;
                end if;
 
                Err_Vars.Error_Msg_Name_1 := Unit_Name;
@@ -8288,16 +8122,14 @@ package body Prj.Nmsc is
                  (Project, In_Tree, "duplicate unit %%", The_Location);
 
                Err_Vars.Error_Msg_Name_1 :=
-                 In_Tree.Projects.Table
-                   (UData.File_Names (Unit_Kind).Project).Name;
+                 UData.File_Names (Unit_Kind).Project.Name;
                Err_Vars.Error_Msg_File_1 :=
                  File_Name_Type (UData.File_Names (Unit_Kind).Path.Name);
                Error_Msg
                  (Project, In_Tree,
                   "\   project file %%, {", The_Location);
 
-               Err_Vars.Error_Msg_Name_1 :=
-                 In_Tree.Projects.Table (Project).Name;
+               Err_Vars.Error_Msg_Name_1 := Project.Name;
                Err_Vars.Error_Msg_File_1 := File_Name_Type (Canonical_Path);
                Error_Msg
                  (Project, In_Tree, "\   project file %%, {", The_Location);
@@ -8312,58 +8144,38 @@ package body Prj.Nmsc is
             --  another project. If it is, report error but note we do that
             --  only for the first unit in the source file.
 
-            Unit_Prj := Files_Htable.Get (In_Tree.Files_HT, Canonical_File);
+            Unit_Prj := Files_Htable.Get (Proc_Data.Units, Canonical_File);
 
             if not File_Recorded
               and then Unit_Prj /= No_Project
             then
                Error_Msg_File_1 := File_Name;
-               Error_Msg_Name_1 := In_Tree.Projects.Table (Unit_Prj).Name;
+               Error_Msg_Name_1 := Unit_Prj.Name;
                Error_Msg
                  (Project, In_Tree,
                   "{ is already a source of project %%",
                   Location);
 
             else
-               Unit_Table.Increment_Last (In_Tree.Units);
-               The_Unit := Unit_Table.Last (In_Tree.Units);
-               Units_Htable.Set (In_Tree.Units_HT, Unit_Name, The_Unit);
-
-               Files_Htable.Set (In_Tree.Files_HT, Canonical_File, Project);
-
-               UData.Name := Unit_Name;
-               UData.File_Names (Unit_Kind) :=
-                 (Name         => Canonical_File,
-                  Index        => Unit_Ind,
-                  Display_Name => File_Name,
-                  Path         => (Canonical_Path, Path_Name),
-                  Project      => Project,
-                  Needs_Pragma => Needs_Pragma);
-               In_Tree.Units.Table (The_Unit) := UData;
-
-               Source_Recorded := True;
                To_Record := True;
             end if;
          end if;
 
          if To_Record then
-            case Unit_Kind is
-               when Body_Part      => Kind := Impl;
-               when Specification  => Kind := Spec;
-            end case;
-
+            Files_Htable.Set (Proc_Data.Units, Canonical_File, Project);
             Add_Source
               (Id                  => Source,
                In_Tree             => In_Tree,
                Project             => Project,
                Lang_Id             => Ada_Language,
-               Lang_Kind           => Unit_Based,
                File_Name           => Canonical_File,
                Display_File        => File_Name,
                Unit                => Unit_Name,
                Path                => (Canonical_Path, Path_Name),
-               Kind                => Kind,
-               Other_Part          => No_Source);  --  ??? Can we find file ?
+               Naming_Exception    => Needs_Pragma,
+               Kind                => Unit_Kind,
+               Index               => Unit_Ind);
+            Source_Recorded := True;
          end if;
       end Record_Unit;
 
@@ -8386,7 +8198,7 @@ package body Prj.Nmsc is
       Get_Unit
         (In_Tree             => In_Tree,
          Canonical_File_Name => Canonical_File,
-         Naming              => Data.Naming,
+         Project             => Project,
          Exception_Id        => Exception_Id,
          Unit_Name           => Unit_Name,
          Unit_Kind           => Unit_Kind);
@@ -8473,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
@@ -8527,7 +8349,7 @@ package body Prj.Nmsc is
    ----------------------
 
    procedure Show_Source_Dirs
-     (Data    : Project_Data;
+     (Project : Project_Id;
       In_Tree : Project_Tree_Ref)
    is
       Current : String_List_Id;
@@ -8536,7 +8358,7 @@ package body Prj.Nmsc is
    begin
       Write_Line ("Source_Dirs:");
 
-      Current := Data.Source_Dirs;
+      Current := Project.Source_Dirs;
       while Current /= Nil_String loop
          Element := In_Tree.String_Elements.Table (Current);
          Write_Str  ("   ");
@@ -8562,8 +8384,7 @@ package body Prj.Nmsc is
    is
       Conv          : Array_Element_Id;
       Unit          : Name_Id;
-      The_Unit_Id   : Unit_Index;
-      The_Unit_Data : Unit_Data;
+      The_Unit_Data : Unit_Index;
       Location      : Source_Ptr;
 
    begin
@@ -8574,38 +8395,38 @@ package body Prj.Nmsc is
          Get_Name_String (Unit);
          To_Lower (Name_Buffer (1 .. Name_Len));
          Unit := Name_Find;
-         The_Unit_Id := Units_Htable.Get (In_Tree.Units_HT, Unit);
+         The_Unit_Data := Units_Htable.Get (In_Tree.Units_HT, Unit);
          Location := In_Tree.Array_Elements.Table (Conv).Value.Location;
 
-         if The_Unit_Id = No_Unit_Index then
+         if The_Unit_Data = No_Unit_Index then
             Error_Msg (Project, In_Tree, "?unknown unit %%", Location);
 
          else
-            The_Unit_Data := In_Tree.Units.Table (The_Unit_Id);
             Error_Msg_Name_2 :=
               In_Tree.Array_Elements.Table (Conv).Value.Value;
 
             if Specs then
                if not Check_Project
-                 (The_Unit_Data.File_Names (Specification).Project,
-                  Project, In_Tree, Extending)
+                        (The_Unit_Data.File_Names (Spec).Project,
+                         Project, Extending)
                then
                   Error_Msg
                     (Project, In_Tree,
                      "?source of spec of unit %% (%%)" &
-                     " cannot be found in this project",
+                     " not found in this project",
                      Location);
                end if;
 
             else
-               if not Check_Project
-                 (The_Unit_Data.File_Names (Body_Part).Project,
-                  Project, In_Tree, Extending)
+               if The_Unit_Data.File_Names (Impl) = null
+                 or else not Check_Project
+                               (The_Unit_Data.File_Names (Impl).Project,
+                                Project, Extending)
                then
                   Error_Msg
                     (Project, In_Tree,
                      "?source of body of unit %% (%%)" &
-                     " cannot be found in this project",
+                     " not found in this project",
                      Location);
                end if;
             end if;