| ------------------------------------------------------------------------------ |
| -- -- |
| -- GNAT COMPILER COMPONENTS -- |
| -- -- |
| -- P R J . N M S C -- |
| -- -- |
| -- B o d y -- |
| -- -- |
| -- Copyright (C) 2000-2015, Free Software Foundation, Inc. -- |
| -- -- |
| -- GNAT is free software; you can redistribute it and/or modify it under -- |
| -- terms of the GNU General Public License as published by the Free Soft- -- |
| -- ware Foundation; either version 3, or (at your option) any later ver- -- |
| -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- |
| -- for more details. You should have received a copy of the GNU General -- |
| -- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
| -- http://www.gnu.org/licenses for a complete copy of the license. -- |
| -- -- |
| -- GNAT was originally developed by the GNAT team at New York University. -- |
| -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| -- -- |
| ------------------------------------------------------------------------------ |
| |
| with Err_Vars; use Err_Vars; |
| with Opt; use Opt; |
| with Osint; use Osint; |
| with Output; use Output; |
| with Prj.Com; |
| with Prj.Env; use Prj.Env; |
| with Prj.Err; use Prj.Err; |
| with Prj.Tree; use Prj.Tree; |
| with Prj.Util; use Prj.Util; |
| with Sinput.P; |
| with Snames; use Snames; |
| |
| with Ada; use Ada; |
| with Ada.Characters.Handling; use Ada.Characters.Handling; |
| with Ada.Directories; use Ada.Directories; |
| with Ada.Strings; use Ada.Strings; |
| with Ada.Strings.Fixed; use Ada.Strings.Fixed; |
| with Ada.Strings.Maps.Constants; use Ada.Strings.Maps.Constants; |
| |
| with GNAT.Case_Util; use GNAT.Case_Util; |
| with GNAT.Directory_Operations; use GNAT.Directory_Operations; |
| with GNAT.Dynamic_HTables; |
| with GNAT.Regexp; use GNAT.Regexp; |
| with GNAT.Table; |
| |
| package body Prj.Nmsc is |
| |
| No_Continuation_String : aliased String := ""; |
| Continuation_String : aliased String := "\"; |
| -- Used in Check_Library for continuation error messages at the same |
| -- location. |
| |
| type Name_Location is record |
| Name : File_Name_Type; |
| -- Key is duplicated, so that it is known when using functions Get_First |
| -- and Get_Next, as these functions only return an Element. |
| |
| Location : Source_Ptr; |
| Source : Source_Id := No_Source; |
| Listed : Boolean := False; |
| Found : Boolean := False; |
| end record; |
| |
| No_Name_Location : constant Name_Location := |
| (Name => No_File, |
| Location => No_Location, |
| Source => No_Source, |
| Listed => False, |
| Found => False); |
| |
| package Source_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable |
| (Header_Num => Header_Num, |
| Element => Name_Location, |
| No_Element => No_Name_Location, |
| Key => File_Name_Type, |
| Hash => Hash, |
| Equal => "="); |
| -- File name information found in string list attribute (Source_Files or |
| -- Source_List_File). Used to check that all referenced files were indeed |
| -- found on the disk. |
| |
| type Unit_Exception is record |
| Name : Name_Id; |
| -- Key is duplicated, so that it is known when using functions Get_First |
| -- and Get_Next, as these functions only return an Element. |
| |
| Spec : File_Name_Type; |
| Impl : File_Name_Type; |
| end record; |
| |
| No_Unit_Exception : constant Unit_Exception := (No_Name, No_File, No_File); |
| |
| package Unit_Exceptions_Htable is new GNAT.Dynamic_HTables.Simple_HTable |
| (Header_Num => Header_Num, |
| Element => Unit_Exception, |
| No_Element => No_Unit_Exception, |
| Key => Name_Id, |
| Hash => Hash, |
| Equal => "="); |
| -- Record special naming schemes for Ada units (name of spec file and name |
| -- of implementation file). The elements in this list come from the naming |
| -- exceptions specified in the project files. |
| |
| type File_Found is record |
| File : File_Name_Type := No_File; |
| Excl_File : File_Name_Type := No_File; |
| Excl_Line : Natural := 0; |
| Found : Boolean := False; |
| Location : Source_Ptr := No_Location; |
| end record; |
| |
| No_File_Found : constant File_Found := |
| (No_File, No_File, 0, False, No_Location); |
| |
| package Excluded_Sources_Htable is new GNAT.Dynamic_HTables.Simple_HTable |
| (Header_Num => Header_Num, |
| Element => File_Found, |
| No_Element => No_File_Found, |
| Key => File_Name_Type, |
| Hash => Hash, |
| Equal => "="); |
| -- A hash table to store the base names of excluded files, if any |
| |
| package Object_File_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable |
| (Header_Num => Header_Num, |
| Element => Source_Id, |
| No_Element => No_Source, |
| Key => File_Name_Type, |
| Hash => Hash, |
| Equal => "="); |
| -- A hash table to store the object file names for a project, to check that |
| -- two different sources have different object file names. |
| |
| type Project_Processing_Data is record |
| Project : Project_Id; |
| Source_Names : Source_Names_Htable.Instance; |
| Unit_Exceptions : Unit_Exceptions_Htable.Instance; |
| Excluded : Excluded_Sources_Htable.Instance; |
| |
| Source_List_File_Location : Source_Ptr; |
| -- Location of the Source_List_File attribute, for error messages |
| end record; |
| -- This is similar to Tree_Processing_Data, but contains project-specific |
| -- information which is only useful while processing the project, and can |
| -- be discarded as soon as we have finished processing the project |
| |
| type Tree_Processing_Data is record |
| Tree : Project_Tree_Ref; |
| Node_Tree : Prj.Tree.Project_Node_Tree_Ref; |
| Flags : Prj.Processing_Flags; |
| In_Aggregate_Lib : Boolean; |
| end record; |
| -- Temporary data which is needed while parsing a project. It does not need |
| -- to be kept in memory once a project has been fully loaded, but is |
| -- necessary while performing consistency checks (duplicate sources,...) |
| -- This data must be initialized before processing any project, and the |
| -- same data is used for processing all projects in the tree. |
| |
| type Lib_Data is record |
| Name : Name_Id; |
| Proj : Project_Id; |
| Tree : Project_Tree_Ref; |
| end record; |
| |
| package Lib_Data_Table is new GNAT.Table |
| (Table_Component_Type => Lib_Data, |
| Table_Index_Type => Natural, |
| Table_Low_Bound => 1, |
| Table_Initial => 10, |
| Table_Increment => 100); |
| -- A table to record library names in order to check that two library |
| -- projects do not have the same library names. |
| |
| procedure Initialize |
| (Data : out Tree_Processing_Data; |
| Tree : Project_Tree_Ref; |
| Node_Tree : Prj.Tree.Project_Node_Tree_Ref; |
| Flags : Prj.Processing_Flags); |
| -- Initialize Data |
| |
| procedure Free (Data : in out Tree_Processing_Data); |
| -- Free the memory occupied by Data |
| |
| procedure Initialize |
| (Data : in out Project_Processing_Data; |
| Project : Project_Id); |
| procedure Free (Data : in out Project_Processing_Data); |
| -- Initialize or free memory for a project-specific data |
| |
| procedure Find_Excluded_Sources |
| (Project : in out Project_Processing_Data; |
| Data : in out Tree_Processing_Data); |
| -- Find the list of files that should not be considered as source files |
| -- for this project. Sets the list in the Project.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. |
| |
| procedure Load_Naming_Exceptions |
| (Project : in out Project_Processing_Data; |
| Data : in out Tree_Processing_Data); |
| -- All source files in Data.First_Source are considered as naming |
| -- exceptions, and copied into the Source_Names and Unit_Exceptions tables |
| -- as appropriate. |
| |
| type Search_Type is (Search_Files, Search_Directories); |
| |
| generic |
| with procedure Callback |
| (Path : Path_Information; |
| Pattern_Index : Natural); |
| procedure Expand_Subdirectory_Pattern |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data; |
| Patterns : String_List_Id; |
| Ignore : String_List_Id; |
| Search_For : Search_Type; |
| Resolve_Links : Boolean); |
| -- Search the subdirectories of Project's directory for files or |
| -- directories that match the globbing patterns found in Patterns (for |
| -- instance "**/*.adb"). Typically, Patterns will be the value of the |
| -- Source_Dirs or Excluded_Source_Dirs attributes. |
| -- |
| -- Every time such a file or directory is found, the callback is called. |
| -- Resolve_Links indicates whether we should resolve links while |
| -- normalizing names. |
| -- |
| -- In the callback, Pattern_Index is the index within Patterns where the |
| -- expanded pattern was found (1 for the first element of Patterns and |
| -- all its matching directories, then 2,...). |
| -- |
| -- We use a generic and not an access-to-subprogram because in some cases |
| -- this code is compiled with the restriction No_Implicit_Dynamic_Code. |
| -- An error message is raised if a pattern does not match any file. |
| |
| procedure Add_Source |
| (Id : out Source_Id; |
| Data : in out Tree_Processing_Data; |
| Project : Project_Id; |
| Source_Dir_Rank : Natural; |
| Lang_Id : Language_Ptr; |
| Kind : Source_Kind; |
| File_Name : File_Name_Type; |
| Display_File : File_Name_Type; |
| Naming_Exception : Naming_Exception_Type := No; |
| Path : Path_Information := No_Path_Information; |
| Alternate_Languages : Language_List := null; |
| Unit : Name_Id := No_Name; |
| Index : Int := 0; |
| Locally_Removed : Boolean := False; |
| Location : Source_Ptr := No_Location); |
| -- Add a new source to the different lists: list of all sources in the |
| -- project tree, list of source of a project and list of sources of a |
| -- language. If Path is specified, the file is also added to |
| -- Source_Paths_HT. Location is used for error messages |
| |
| function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type; |
| -- Same as Osint.Canonical_Case_File_Name but applies to Name_Id. |
| -- This alters Name_Buffer. |
| |
| function Suffix_Matches |
| (Filename : String; |
| Suffix : File_Name_Type) return Boolean; |
| -- 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; |
| Pattern : String; |
| Replacement : Character); |
| -- Copy Str into Name_Buffer, replacing Pattern with Replacement. Str is |
| -- converted to lower-case at the same time. |
| |
| procedure Check_Abstract_Project |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data); |
| -- Check abstract projects attributes |
| |
| procedure Check_Configuration |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data); |
| -- Check the configuration attributes for the project |
| |
| procedure Check_If_Externally_Built |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data); |
| -- Check attribute Externally_Built of project Project in project tree |
| -- Data.Tree and modify its data Data if it has the value "true". |
| |
| procedure Check_Interfaces |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data); |
| -- 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; |
| Data : in out Tree_Processing_Data); |
| -- Check the library attributes of project Project in project tree |
| -- and modify its data Data accordingly. |
| |
| procedure Check_Package_Naming |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data); |
| -- Check the naming scheme part of Data, and initialize the naming scheme |
| -- data in the config of the various languages. |
| |
| procedure Check_Programming_Languages |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data); |
| -- Check attribute Languages for the project with data Data in project |
| -- tree Data.Tree and set the components of Data for all the programming |
| -- languages indicated in attribute Languages, if any. |
| |
| procedure Check_Stand_Alone_Library |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data); |
| -- Check if project Project in project tree Data.Tree is a Stand-Alone |
| -- Library project, and modify its data Data accordingly if it is one. |
| |
| procedure Check_Unit_Name (Name : String; Unit : out Name_Id); |
| -- Check that a name is a valid unit name |
| |
| function Compute_Directory_Last (Dir : String) return Natural; |
| -- Return the index of the last significant character in Dir. This is used |
| -- to avoid duplicate '/' (slash) characters at the end of directory names. |
| |
| procedure Search_Directories |
| (Project : in out Project_Processing_Data; |
| Data : in out Tree_Processing_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 |
| -- various languages. Otherwise consider only the file names in hash table |
| -- Source_Names. If Allow_Duplicate_Basenames then files with identical |
| -- base names are permitted within a project for source-based languages |
| -- (never for unit based languages). |
| |
| procedure Check_File |
| (Project : in out Project_Processing_Data; |
| Data : in out Tree_Processing_Data; |
| Source_Dir_Rank : Natural; |
| Path : Path_Name_Type; |
| Display_Path : Path_Name_Type; |
| File_Name : File_Name_Type; |
| Display_File_Name : File_Name_Type; |
| Locally_Removed : Boolean; |
| For_All_Sources : 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. |
| -- |
| -- File_Name is the same as Display_File_Name, but has been normalized. |
| -- They do not include the directory information. |
| -- |
| -- Path and Display_Path on the other hand are the full path to the file. |
| -- Path must have been normalized (canonical casing and possibly links |
| -- resolved). |
| -- |
| -- Source_Directory is the directory in which the file was found. It is |
| -- neither normalized nor has had links resolved, and must not end with a |
| -- a directory separator, to avoid duplicates later on. |
| -- |
| -- If For_All_Sources is True, then all possible file names are analyzed |
| -- otherwise only those currently set in the Source_Names hash table. |
| |
| procedure Check_File_Naming_Schemes |
| (Project : Project_Processing_Data; |
| File_Name : File_Name_Type; |
| Alternate_Languages : out Language_List; |
| Language : out Language_Ptr; |
| Display_Language_Name : out Name_Id; |
| Unit : out Name_Id; |
| Lang_Kind : out Language_Kind; |
| Kind : out Source_Kind); |
| -- Check if the file name File_Name conforms to one of the naming schemes |
| -- of the project. If the file does not match one of the naming schemes, |
| -- set Language to No_Language_Index. Filename is the name of the file |
| -- being investigated. It has been normalized (case-folded). File_Name is |
| -- the same value. |
| |
| procedure Get_Directories |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data); |
| -- Get the object directory, the exec directory and the source directories |
| -- of a project. |
| |
| procedure Get_Mains |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data); |
| -- Get the mains of a project from attribute Main, if it exists, and put |
| -- them in the project data. |
| |
| procedure Get_Sources_From_File |
| (Path : String; |
| Location : Source_Ptr; |
| Project : in out Project_Processing_Data; |
| Data : in out Tree_Processing_Data); |
| -- Get the list of sources from a text file and put them in hash table |
| -- Source_Names. |
| |
| procedure Find_Sources |
| (Project : in out Project_Processing_Data; |
| Data : in out Tree_Processing_Data); |
| -- 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; |
| Naming : Lang_Naming_Data; |
| Kind : out Source_Kind; |
| Unit : out Name_Id; |
| Project : Project_Processing_Data); |
| -- Check whether the file matches the naming scheme. If it does, |
| -- compute its unit name. If Unit is set to No_Name on exit, none of the |
| -- other out parameters are relevant. |
| |
| procedure Check_Illegal_Suffix |
| (Project : Project_Id; |
| Suffix : File_Name_Type; |
| Dot_Replacement : File_Name_Type; |
| Attribute_Name : String; |
| Location : Source_Ptr; |
| Data : in out Tree_Processing_Data); |
| -- Display an error message if the given suffix is illegal for some reason. |
| -- The name of the attribute we are testing is specified in Attribute_Name, |
| -- which is used in the error message. Location is the location where the |
| -- suffix is defined. |
| |
| procedure Locate_Directory |
| (Project : Project_Id; |
| Name : File_Name_Type; |
| Path : out Path_Information; |
| Dir_Exists : out Boolean; |
| Data : in out Tree_Processing_Data; |
| Create : String := ""; |
| Location : Source_Ptr := No_Location; |
| Must_Exist : Boolean := True; |
| Externally_Built : Boolean := False); |
| -- 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, 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. Create is also |
| -- used for debugging traces to show which path we are computing. |
| |
| procedure Look_For_Sources |
| (Project : in out Project_Processing_Data; |
| Data : in out Tree_Processing_Data); |
| -- Find all the sources of project Project in project tree Data.Tree and |
| -- update its Data accordingly. This assumes that the special naming |
| -- exceptions have already been processed. |
| |
| function Path_Name_Of |
| (File_Name : File_Name_Type; |
| Directory : Path_Name_Type) return String; |
| -- Returns the path name of a (non project) file. Returns an empty string |
| -- if file cannot be found. |
| |
| procedure Remove_Source |
| (Tree : Project_Tree_Ref; |
| Id : Source_Id; |
| Replaced_By : Source_Id); |
| -- 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; |
| Lang_Name : String; |
| Data : Tree_Processing_Data; |
| Location : Source_Ptr; |
| Continuation : Boolean := False); |
| -- Report an error or a warning depending on the value of When_No_Sources |
| -- when there are no sources for language Lang_Name. |
| |
| procedure Show_Source_Dirs |
| (Project : Project_Id; |
| Shared : Shared_Project_Tree_Data_Access); |
| -- List all the source directories of a project |
| |
| procedure Write_Attr (Name, Value : String); |
| -- Debug print a value for a specific property. Does nothing when not in |
| -- debug mode |
| |
| procedure Error_Or_Warning |
| (Flags : Processing_Flags; |
| Kind : Error_Warning; |
| Msg : String; |
| Location : Source_Ptr; |
| Project : Project_Id); |
| -- Emits either an error or warning message (or nothing), depending on Kind |
| |
| function No_Space_Img (N : Natural) return String; |
| -- Image of a Natural without the initial space |
| |
| ---------------------- |
| -- Error_Or_Warning -- |
| ---------------------- |
| |
| procedure Error_Or_Warning |
| (Flags : Processing_Flags; |
| Kind : Error_Warning; |
| Msg : String; |
| Location : Source_Ptr; |
| Project : Project_Id) is |
| begin |
| case Kind is |
| when Error => Error_Msg (Flags, Msg, Location, Project); |
| when Warning => Error_Msg (Flags, "?" & Msg, Location, Project); |
| when Silent => null; |
| end case; |
| end Error_Or_Warning; |
| |
| ------------------------------ |
| -- Replace_Into_Name_Buffer -- |
| ------------------------------ |
| |
| procedure Replace_Into_Name_Buffer |
| (Str : String; |
| Pattern : String; |
| Replacement : Character) |
| is |
| Max : constant Integer := Str'Last - Pattern'Length + 1; |
| J : Positive; |
| |
| begin |
| Name_Len := 0; |
| |
| J := Str'First; |
| while J <= Str'Last loop |
| Name_Len := Name_Len + 1; |
| |
| if J <= Max and then Str (J .. J + Pattern'Length - 1) = Pattern then |
| Name_Buffer (Name_Len) := Replacement; |
| J := J + Pattern'Length; |
| else |
| Name_Buffer (Name_Len) := GNAT.Case_Util.To_Lower (Str (J)); |
| J := J + 1; |
| end if; |
| end loop; |
| end Replace_Into_Name_Buffer; |
| |
| -------------------- |
| -- Suffix_Matches -- |
| -------------------- |
| |
| function Suffix_Matches |
| (Filename : String; |
| Suffix : File_Name_Type) return Boolean |
| is |
| Min_Prefix_Length : Natural := 0; |
| |
| begin |
| if Suffix = No_File or else Suffix = Empty_File then |
| return False; |
| end if; |
| |
| declare |
| Suf : String := Get_Name_String (Suffix); |
| |
| begin |
| -- On non case-sensitive systems, use proper suffix casing |
| |
| Canonical_Case_File_Name (Suf); |
| |
| -- 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; |
| end Suffix_Matches; |
| |
| ---------------- |
| -- Write_Attr -- |
| ---------------- |
| |
| procedure Write_Attr (Name, Value : String) is |
| begin |
| if Current_Verbosity = High then |
| Debug_Output (Name & " = """ & Value & '"'); |
| end if; |
| end Write_Attr; |
| |
| ---------------- |
| -- Add_Source -- |
| ---------------- |
| |
| procedure Add_Source |
| (Id : out Source_Id; |
| Data : in out Tree_Processing_Data; |
| Project : Project_Id; |
| Source_Dir_Rank : Natural; |
| Lang_Id : Language_Ptr; |
| Kind : Source_Kind; |
| File_Name : File_Name_Type; |
| Display_File : File_Name_Type; |
| Naming_Exception : Naming_Exception_Type := No; |
| Path : Path_Information := No_Path_Information; |
| Alternate_Languages : Language_List := null; |
| Unit : Name_Id := No_Name; |
| Index : Int := 0; |
| Locally_Removed : Boolean := False; |
| Location : Source_Ptr := No_Location) |
| is |
| Config : constant Language_Config := Lang_Id.Config; |
| UData : Unit_Index; |
| Add_Src : Boolean; |
| Source : Source_Id; |
| Prev_Unit : Unit_Index := No_Unit_Index; |
| Source_To_Replace : Source_Id := No_Source; |
| |
| begin |
| -- Check if the same file name or unit is used in the prj tree |
| |
| Add_Src := True; |
| |
| if Unit /= No_Name then |
| Prev_Unit := Units_Htable.Get (Data.Tree.Units_HT, Unit); |
| end if; |
| |
| if Prev_Unit /= No_Unit_Index |
| and then (Kind = Impl or else Kind = Spec) |
| and then Prev_Unit.File_Names (Kind) /= null |
| then |
| -- Suspicious, we need to check later whether this is authorized |
| |
| Add_Src := False; |
| Source := Prev_Unit.File_Names (Kind); |
| |
| else |
| Source := Source_Files_Htable.Get |
| (Data.Tree.Source_Files_HT, File_Name); |
| |
| if Source /= No_Source and then Source.Index = Index then |
| Add_Src := False; |
| end if; |
| end if; |
| |
| -- Always add the source if it is locally removed, to avoid incorrect |
| -- duplicate checks. |
| |
| if Locally_Removed then |
| Add_Src := True; |
| |
| -- A locally removed source may first replace a source in a project |
| -- being extended. |
| |
| if Source /= No_Source |
| and then Is_Extending (Project, Source.Project) |
| and then Naming_Exception /= Inherited |
| then |
| Source_To_Replace := Source; |
| end if; |
| |
| else |
| -- Duplication of file/unit in same project is allowed if order of |
| -- source directories is known, or if there is no compiler for the |
| -- language. |
| |
| if Add_Src = False then |
| Add_Src := True; |
| |
| if Project = Source.Project then |
| if Prev_Unit = No_Unit_Index then |
| if Data.Flags.Allow_Duplicate_Basenames then |
| Add_Src := True; |
| |
| elsif Lang_Id.Config.Compiler_Driver = Empty_File then |
| Add_Src := True; |
| |
| elsif Source_Dir_Rank /= Source.Source_Dir_Rank then |
| Add_Src := False; |
| |
| else |
| Error_Msg_File_1 := File_Name; |
| Error_Msg |
| (Data.Flags, "duplicate source file name {", |
| Location, Project); |
| Add_Src := False; |
| end if; |
| |
| else |
| if Source_Dir_Rank /= Source.Source_Dir_Rank then |
| Add_Src := False; |
| |
| -- We might be seeing the same file through a different |
| -- path (for instance because of symbolic links). |
| |
| elsif Source.Path.Name /= Path.Name then |
| if not Source.Duplicate_Unit then |
| Error_Msg_Name_1 := Unit; |
| Error_Msg |
| (Data.Flags, |
| "\duplicate unit %%", |
| Location, |
| Project); |
| Source.Duplicate_Unit := True; |
| end if; |
| |
| Add_Src := False; |
| end if; |
| end if; |
| |
| -- Do not allow the same unit name in different projects, |
| -- except if one is extending the other. |
| |
| -- For a file based language, the same file name replaces 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) then |
| if not Locally_Removed and then Naming_Exception /= Inherited |
| then |
| Source_To_Replace := Source; |
| end if; |
| |
| elsif Prev_Unit /= No_Unit_Index |
| and then Prev_Unit.File_Names (Kind) /= null |
| and then not Source.Locally_Removed |
| and then Source.Replaced_By = No_Source |
| and then not Data.In_Aggregate_Lib |
| then |
| -- Path is set if this is a source we found on the disk, in |
| -- which case we can provide more explicit error message. Path |
| -- is unset when the source is added from one of the naming |
| -- exceptions in the project. |
| |
| if Path /= No_Path_Information then |
| Error_Msg_Name_1 := Unit; |
| Error_Msg |
| (Data.Flags, |
| "unit %% cannot belong to several projects", |
| Location, Project); |
| |
| Error_Msg_Name_1 := Project.Name; |
| Error_Msg_Name_2 := Name_Id (Path.Display_Name); |
| Error_Msg |
| (Data.Flags, "\ project %%, %%", Location, Project); |
| |
| Error_Msg_Name_1 := Source.Project.Name; |
| Error_Msg_Name_2 := Name_Id (Source.Path.Display_Name); |
| Error_Msg |
| (Data.Flags, "\ project %%, %%", Location, Project); |
| |
| else |
| Error_Msg_Name_1 := Unit; |
| Error_Msg_Name_2 := Source.Project.Name; |
| Error_Msg |
| (Data.Flags, "unit %% already belongs to project %%", |
| Location, Project); |
| end if; |
| |
| Add_Src := False; |
| |
| elsif not Source.Locally_Removed |
| and then Source.Replaced_By /= No_Source |
| and then not Data.Flags.Allow_Duplicate_Basenames |
| and then Lang_Id.Config.Kind = Unit_Based |
| and then Source.Language.Config.Kind = Unit_Based |
| and then not Data.In_Aggregate_Lib |
| then |
| Error_Msg_File_1 := File_Name; |
| Error_Msg_File_2 := File_Name_Type (Source.Project.Name); |
| Error_Msg |
| (Data.Flags, |
| "{ is already a source of project {", Location, Project); |
| |
| -- Add the file anyway, to avoid further warnings like |
| -- "language unknown". |
| |
| Add_Src := True; |
| end if; |
| end if; |
| end if; |
| |
| if not Add_Src then |
| return; |
| end if; |
| |
| -- Add the new file |
| |
| Id := new Source_Data; |
| |
| if Current_Verbosity = High then |
| Debug_Indent; |
| Write_Str ("adding source File: "); |
| Write_Str (Get_Name_String (Display_File)); |
| |
| if Index /= 0 then |
| Write_Str (" at" & Index'Img); |
| end if; |
| |
| 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). |
| |
| if Unit /= No_Name then |
| Write_Str (Get_Name_String (Unit)); |
| end if; |
| |
| Write_Str (" Kind: "); |
| Write_Str (Source_Kind'Image (Kind)); |
| end if; |
| |
| Write_Eol; |
| end if; |
| |
| Id.Project := Project; |
| Id.Location := Location; |
| Id.Source_Dir_Rank := Source_Dir_Rank; |
| Id.Language := Lang_Id; |
| Id.Kind := Kind; |
| Id.Alternate_Languages := Alternate_Languages; |
| Id.Locally_Removed := Locally_Removed; |
| 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; |
| Id.Object := Object_Name |
| (File_Name, Config.Object_File_Suffix); |
| Id.Switches := Switches_Name (File_Name); |
| |
| -- Add the source id to the Unit_Sources_HT hash table, if the unit name |
| -- is not null. |
| |
| if Unit /= No_Name then |
| |
| -- Note: we might be creating a dummy unit here, when we in fact have |
| -- a separate. For instance, file file-bar.adb will initially be |
| -- assumed to be the IMPL of unit "file.bar". Only later on (in |
| -- Check_Object_Files) will we parse those units that only have an |
| -- impl and no spec to make sure whether we have a Separate in fact |
| -- (that significantly reduces the number of times we need to parse |
| -- the files, since we are then only interested in those with no |
| -- spec). We still need those dummy units in the table, since that's |
| -- the name we find in the ALI file |
| |
| UData := Units_Htable.Get (Data.Tree.Units_HT, Unit); |
| |
| if UData = No_Unit_Index then |
| UData := new Unit_Data; |
| UData.Name := Unit; |
| |
| if Naming_Exception /= Inherited then |
| Units_Htable.Set (Data.Tree.Units_HT, Unit, UData); |
| end if; |
| end if; |
| |
| Id.Unit := UData; |
| |
| -- Note that this updates Unit information as well |
| |
| if Naming_Exception /= Inherited and then not Locally_Removed then |
| Override_Kind (Id, Kind); |
| end if; |
| end if; |
| |
| if Path /= No_Path_Information then |
| Id.Path := Path; |
| Source_Paths_Htable.Set (Data.Tree.Source_Paths_HT, Path.Name, Id); |
| end if; |
| |
| Id.Next_With_File_Name := |
| Source_Files_Htable.Get (Data.Tree.Source_Files_HT, File_Name); |
| Source_Files_Htable.Set (Data.Tree.Source_Files_HT, File_Name, Id); |
| |
| if Index /= 0 then |
| Project.Has_Multi_Unit_Sources := True; |
| end if; |
| |
| -- Add the source to the language list |
| |
| Id.Next_In_Lang := Lang_Id.First_Source; |
| Lang_Id.First_Source := Id; |
| |
| if Source_To_Replace /= No_Source then |
| Remove_Source (Data.Tree, Source_To_Replace, Id); |
| end if; |
| |
| if Data.Tree.Replaced_Source_Number > 0 |
| and then |
| Replaced_Source_HTable.Get |
| (Data.Tree.Replaced_Sources, Id.File) /= No_File |
| then |
| Replaced_Source_HTable.Remove (Data.Tree.Replaced_Sources, Id.File); |
| Data.Tree.Replaced_Source_Number := |
| Data.Tree.Replaced_Source_Number - 1; |
| end if; |
| end Add_Source; |
| |
| ------------------------------ |
| -- Canonical_Case_File_Name -- |
| ------------------------------ |
| |
| function Canonical_Case_File_Name (Name : Name_Id) return File_Name_Type is |
| begin |
| if Osint.File_Names_Case_Sensitive then |
| return File_Name_Type (Name); |
| else |
| Get_Name_String (Name); |
| Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len)); |
| return Name_Find; |
| end if; |
| end Canonical_Case_File_Name; |
| |
| --------------------------------- |
| -- Process_Aggregated_Projects -- |
| --------------------------------- |
| |
| procedure Process_Aggregated_Projects |
| (Tree : Project_Tree_Ref; |
| Project : Project_Id; |
| Node_Tree : Prj.Tree.Project_Node_Tree_Ref; |
| Flags : Processing_Flags) |
| is |
| Data : Tree_Processing_Data := |
| (Tree => Tree, |
| Node_Tree => Node_Tree, |
| Flags => Flags, |
| In_Aggregate_Lib => False); |
| |
| Project_Files : constant Prj.Variable_Value := |
| Prj.Util.Value_Of |
| (Snames.Name_Project_Files, |
| Project.Decl.Attributes, |
| Tree.Shared); |
| |
| Project_Path_For_Aggregate : Prj.Env.Project_Search_Path; |
| |
| procedure Found_Project_File (Path : Path_Information; Rank : Natural); |
| -- Called for each project file aggregated by Project |
| |
| procedure Expand_Project_Files is |
| new Expand_Subdirectory_Pattern (Callback => Found_Project_File); |
| -- Search for all project files referenced by the patterns given in |
| -- parameter. Calls Found_Project_File for each of them. |
| |
| ------------------------ |
| -- Found_Project_File -- |
| ------------------------ |
| |
| procedure Found_Project_File (Path : Path_Information; Rank : Natural) is |
| pragma Unreferenced (Rank); |
| |
| begin |
| if Path.Name /= Project.Path.Name then |
| Debug_Output ("aggregates: ", Name_Id (Path.Display_Name)); |
| |
| -- For usual "with" statement, this phase will have been done when |
| -- parsing the project itself. However, for aggregate projects, we |
| -- can only do this when processing the aggregate project, since |
| -- the exact list of project files or project directories can |
| -- depend on scenario variables. |
| -- |
| -- We only load the projects explicitly here, but do not process |
| -- them. For the processing, Prj.Proc will take care of processing |
| -- them, within the same call to Recursive_Process (thus avoiding |
| -- the processing of a given project multiple times). |
| -- |
| -- ??? We might already have loaded the project |
| |
| Add_Aggregated_Project (Project, Path => Path.Name); |
| |
| else |
| Debug_Output ("pattern returned the aggregate itself, ignored"); |
| end if; |
| end Found_Project_File; |
| |
| -- Start of processing for Check_Aggregate_Project |
| |
| begin |
| pragma Assert (Project.Qualifier in Aggregate_Project); |
| |
| if Project_Files.Default then |
| Error_Msg_Name_1 := Snames.Name_Project_Files; |
| Error_Msg |
| (Flags, |
| "Attribute %% must be specified in aggregate project", |
| Project.Location, Project); |
| return; |
| end if; |
| |
| -- The aggregated projects are only searched relative to the directory |
| -- of the aggregate project, not in the default project path. |
| |
| Initialize_Empty (Project_Path_For_Aggregate); |
| |
| Free (Project.Aggregated_Projects); |
| |
| -- Look for aggregated projects. For similarity with source files and |
| -- dirs, the aggregated project files are not searched for on the |
| -- project path, and are only found through the path specified in |
| -- the Project_Files attribute. |
| |
| Expand_Project_Files |
| (Project => Project, |
| Data => Data, |
| Patterns => Project_Files.Values, |
| Ignore => Nil_String, |
| Search_For => Search_Files, |
| Resolve_Links => Opt.Follow_Links_For_Files); |
| |
| Free (Project_Path_For_Aggregate); |
| end Process_Aggregated_Projects; |
| |
| ---------------------------- |
| -- Check_Abstract_Project -- |
| ---------------------------- |
| |
| procedure Check_Abstract_Project |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data) |
| is |
| Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared; |
| |
| Source_Dirs : constant Variable_Value := |
| Util.Value_Of |
| (Name_Source_Dirs, |
| Project.Decl.Attributes, Shared); |
| Source_Files : constant Variable_Value := |
| Util.Value_Of |
| (Name_Source_Files, |
| Project.Decl.Attributes, Shared); |
| Source_List_File : constant Variable_Value := |
| Util.Value_Of |
| (Name_Source_List_File, |
| Project.Decl.Attributes, Shared); |
| Languages : constant Variable_Value := |
| Util.Value_Of |
| (Name_Languages, |
| Project.Decl.Attributes, Shared); |
| |
| begin |
| if Project.Source_Dirs /= Nil_String then |
| 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 |
| (Data.Flags, |
| "at least one of Source_Files, Source_Dirs or Languages " |
| & "must be declared empty for an abstract project", |
| Project.Location, Project); |
| end if; |
| end if; |
| end Check_Abstract_Project; |
| |
| ------------------------- |
| -- Check_Configuration -- |
| ------------------------- |
| |
| procedure Check_Configuration |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data) |
| is |
| Shared : constant Shared_Project_Tree_Data_Access := |
| Data.Tree.Shared; |
| |
| Dot_Replacement : File_Name_Type := No_File; |
| Casing : Casing_Type := All_Lower_Case; |
| Separate_Suffix : File_Name_Type := No_File; |
| |
| Lang_Index : Language_Ptr := No_Language_Index; |
| -- The index of the language data being checked |
| |
| Prev_Index : Language_Ptr := No_Language_Index; |
| -- The index of the previous language |
| |
| procedure Process_Project_Level_Simple_Attributes; |
| -- Process the simple attributes at the project level |
| |
| procedure Process_Project_Level_Array_Attributes; |
| -- Process the associate array attributes at the project level |
| |
| procedure Process_Packages; |
| -- Read the packages of the project |
| |
| ---------------------- |
| -- Process_Packages -- |
| ---------------------- |
| |
| procedure Process_Packages is |
| Packages : Package_Id; |
| Element : Package_Element; |
| |
| procedure Process_Binder (Arrays : Array_Id); |
| -- Process the associated array attributes of package Binder |
| |
| procedure Process_Builder (Attributes : Variable_Id); |
| -- Process the simple attributes of package Builder |
| |
| procedure Process_Clean (Attributes : Variable_Id); |
| -- Process the simple attributes of package Clean |
| |
| procedure Process_Clean (Arrays : Array_Id); |
| -- Process the associated array attributes of package Clean |
| |
| procedure Process_Compiler (Arrays : Array_Id); |
| -- Process the associated array attributes of package Compiler |
| |
| procedure Process_Naming (Attributes : Variable_Id); |
| -- Process the simple attributes of package Naming |
| |
| procedure Process_Naming (Arrays : Array_Id); |
| -- Process the associated array attributes of package Naming |
| |
| procedure Process_Linker (Attributes : Variable_Id); |
| -- Process the simple attributes of package Linker of a |
| -- configuration project. |
| |
| -------------------- |
| -- Process_Binder -- |
| -------------------- |
| |
| procedure Process_Binder (Arrays : Array_Id) is |
| Current_Array_Id : Array_Id; |
| Current_Array : Array_Data; |
| Element_Id : Array_Element_Id; |
| Element : Array_Element; |
| |
| begin |
| -- Process the associative array attribute of package Binder |
| |
| Current_Array_Id := Arrays; |
| while Current_Array_Id /= No_Array loop |
| Current_Array := Shared.Arrays.Table (Current_Array_Id); |
| |
| Element_Id := Current_Array.Value; |
| while Element_Id /= No_Array_Element loop |
| Element := Shared.Array_Elements.Table (Element_Id); |
| |
| if Element.Index /= All_Other_Names then |
| |
| -- Get the name of the language |
| |
| 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 => |
| |
| -- Attribute Driver (<language>) |
| |
| Lang_Index.Config.Binder_Driver := |
| File_Name_Type (Element.Value.Value); |
| |
| when Name_Required_Switches => |
| Put |
| (Into_List => |
| Lang_Index.Config.Binder_Required_Switches, |
| From_List => Element.Value.Values, |
| In_Tree => Data.Tree); |
| |
| when Name_Prefix => |
| |
| -- Attribute Prefix (<language>) |
| |
| Lang_Index.Config.Binder_Prefix := |
| Element.Value.Value; |
| |
| when Name_Objects_Path => |
| |
| -- Attribute Objects_Path (<language>) |
| |
| Lang_Index.Config.Objects_Path := |
| Element.Value.Value; |
| |
| when Name_Objects_Path_File => |
| |
| -- Attribute Objects_Path (<language>) |
| |
| Lang_Index.Config.Objects_Path_File := |
| Element.Value.Value; |
| |
| when others => |
| null; |
| end case; |
| end if; |
| end if; |
| |
| Element_Id := Element.Next; |
| end loop; |
| |
| Current_Array_Id := Current_Array.Next; |
| end loop; |
| end Process_Binder; |
| |
| --------------------- |
| -- Process_Builder -- |
| --------------------- |
| |
| procedure Process_Builder (Attributes : Variable_Id) is |
| Attribute_Id : Variable_Id; |
| Attribute : Variable; |
| |
| begin |
| -- Process non associated array attribute from package Builder |
| |
| Attribute_Id := Attributes; |
| while Attribute_Id /= No_Variable loop |
| Attribute := Shared.Variable_Elements.Table (Attribute_Id); |
| |
| if not Attribute.Value.Default then |
| if Attribute.Name = Name_Executable_Suffix then |
| |
| -- Attribute Executable_Suffix: the suffix of the |
| -- executables. |
| |
| Project.Config.Executable_Suffix := |
| Attribute.Value.Value; |
| end if; |
| end if; |
| |
| Attribute_Id := Attribute.Next; |
| end loop; |
| end Process_Builder; |
| |
| ------------------- |
| -- Process_Clean -- |
| ------------------- |
| |
| procedure Process_Clean (Attributes : Variable_Id) is |
| Attribute_Id : Variable_Id; |
| Attribute : Variable; |
| List : String_List_Id; |
| |
| begin |
| -- Process non associated array attributes from package Clean |
| |
| Attribute_Id := Attributes; |
| while Attribute_Id /= No_Variable loop |
| Attribute := Shared.Variable_Elements.Table (Attribute_Id); |
| |
| if not Attribute.Value.Default then |
| if Attribute.Name = Name_Artifacts_In_Exec_Dir then |
| |
| -- Attribute Artifacts_In_Exec_Dir: the list of file |
| -- names to be cleaned in the exec dir of the main |
| -- project. |
| |
| List := Attribute.Value.Values; |
| |
| if List /= Nil_String then |
| Put (Into_List => |
| Project.Config.Artifacts_In_Exec_Dir, |
| From_List => List, |
| In_Tree => Data.Tree); |
| end if; |
| |
| elsif Attribute.Name = Name_Artifacts_In_Object_Dir then |
| |
| -- Attribute Artifacts_In_Exec_Dir: the list of file |
| -- names to be cleaned in the object dir of every |
| -- project. |
| |
| List := Attribute.Value.Values; |
| |
| if List /= Nil_String then |
| Put (Into_List => |
| Project.Config.Artifacts_In_Object_Dir, |
| From_List => List, |
| In_Tree => Data.Tree); |
| end if; |
| end if; |
| end if; |
| |
| Attribute_Id := Attribute.Next; |
| end loop; |
| end Process_Clean; |
| |
| procedure Process_Clean (Arrays : Array_Id) is |
| Current_Array_Id : Array_Id; |
| Current_Array : Array_Data; |
| Element_Id : Array_Element_Id; |
| Element : Array_Element; |
| List : String_List_Id; |
| |
| begin |
| -- Process the associated array attributes of package Clean |
| |
| Current_Array_Id := Arrays; |
| while Current_Array_Id /= No_Array loop |
| Current_Array := Shared.Arrays.Table (Current_Array_Id); |
| |
| Element_Id := Current_Array.Value; |
| while Element_Id /= No_Array_Element loop |
| Element := Shared.Array_Elements.Table (Element_Id); |
| |
| -- Get the name of the language |
| |
| Lang_Index := |
| Get_Language_From_Name |
| (Project, Get_Name_String (Element.Index)); |
| |
| if Lang_Index /= No_Language_Index then |
| case Current_Array.Name is |
| |
| -- Attribute Object_Artifact_Extensions (<language>) |
| |
| when Name_Object_Artifact_Extensions => |
| List := Element.Value.Values; |
| |
| if List /= Nil_String then |
| Put (Into_List => |
| Lang_Index.Config.Clean_Object_Artifacts, |
| From_List => List, |
| In_Tree => Data.Tree); |
| end if; |
| |
| -- Attribute Source_Artifact_Extensions (<language>) |
| |
| when Name_Source_Artifact_Extensions => |
| List := Element.Value.Values; |
| |
| if List /= Nil_String then |
| Put (Into_List => |
| Lang_Index.Config.Clean_Source_Artifacts, |
| From_List => List, |
| In_Tree => Data.Tree); |
| end if; |
| |
| when others => |
| null; |
| end case; |
| end if; |
| |
| Element_Id := Element.Next; |
| end loop; |
| |
| Current_Array_Id := Current_Array.Next; |
| end loop; |
| end Process_Clean; |
| |
| ---------------------- |
| -- Process_Compiler -- |
| ---------------------- |
| |
| procedure Process_Compiler (Arrays : Array_Id) is |
| Current_Array_Id : Array_Id; |
| Current_Array : Array_Data; |
| Element_Id : Array_Element_Id; |
| Element : Array_Element; |
| List : String_List_Id; |
| |
| begin |
| -- Process the associative array attribute of package Compiler |
| |
| Current_Array_Id := Arrays; |
| while Current_Array_Id /= No_Array loop |
| Current_Array := Shared.Arrays.Table (Current_Array_Id); |
| |
| Element_Id := Current_Array.Value; |
| while Element_Id /= No_Array_Element loop |
| Element := Shared.Array_Elements.Table (Element_Id); |
| |
| if Element.Index /= All_Other_Names then |
| |
| -- Get the name of the language |
| |
| Lang_Index := Get_Language_From_Name |
| (Project, Get_Name_String (Element.Index)); |
| |
| if Lang_Index /= No_Language_Index then |
| case Current_Array.Name is |
| |
| -- Attribute Dependency_Kind (<language>) |
| |
| when Name_Dependency_Kind => |
| Get_Name_String (Element.Value.Value); |
| |
| begin |
| Lang_Index.Config.Dependency_Kind := |
| Dependency_File_Kind'Value |
| (Name_Buffer (1 .. Name_Len)); |
| |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "illegal value for Dependency_Kind", |
| Element.Value.Location, |
| Project); |
| end; |
| |
| -- Attribute Dependency_Switches (<language>) |
| |
| when Name_Dependency_Switches => |
| if Lang_Index.Config.Dependency_Kind = None then |
| Lang_Index.Config.Dependency_Kind := Makefile; |
| end if; |
| |
| List := Element.Value.Values; |
| |
| if List /= Nil_String then |
| Put (Into_List => |
| Lang_Index.Config.Dependency_Option, |
| From_List => List, |
| In_Tree => Data.Tree); |
| end if; |
| |
| -- Attribute Dependency_Driver (<language>) |
| |
| when Name_Dependency_Driver => |
| if Lang_Index.Config.Dependency_Kind = None then |
| Lang_Index.Config.Dependency_Kind := Makefile; |
| end if; |
| |
| List := Element.Value.Values; |
| |
| if List /= Nil_String then |
| Put (Into_List => |
| Lang_Index.Config.Compute_Dependency, |
| From_List => List, |
| In_Tree => Data.Tree); |
| end if; |
| |
| -- Attribute Language_Kind (<language>) |
| |
| when Name_Language_Kind => |
| Get_Name_String (Element.Value.Value); |
| |
| begin |
| Lang_Index.Config.Kind := |
| Language_Kind'Value |
| (Name_Buffer (1 .. Name_Len)); |
| |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "illegal value for Language_Kind", |
| Element.Value.Location, |
| Project); |
| end; |
| |
| -- Attribute Include_Switches (<language>) |
| |
| when Name_Include_Switches => |
| List := Element.Value.Values; |
| |
| if List = Nil_String then |
| Error_Msg |
| (Data.Flags, "include option cannot be null", |
| Element.Value.Location, Project); |
| end if; |
| |
| Put (Into_List => Lang_Index.Config.Include_Option, |
| From_List => List, |
| In_Tree => Data.Tree); |
| |
| -- Attribute Include_Path (<language>) |
| |
| when Name_Include_Path => |
| Lang_Index.Config.Include_Path := |
| Element.Value.Value; |
| |
| -- Attribute Include_Path_File (<language>) |
| |
| when Name_Include_Path_File => |
| Lang_Index.Config.Include_Path_File := |
| Element.Value.Value; |
| |
| -- Attribute Driver (<language>) |
| |
| when Name_Driver => |
| Lang_Index.Config.Compiler_Driver := |
| File_Name_Type (Element.Value.Value); |
| |
| when Name_Required_Switches |
| | Name_Leading_Required_Switches |
| => |
| Put (Into_List => |
| Lang_Index.Config. |
| Compiler_Leading_Required_Switches, |
| From_List => Element.Value.Values, |
| In_Tree => Data.Tree); |
| |
| when Name_Trailing_Required_Switches => |
| Put (Into_List => |
| Lang_Index.Config. |
| Compiler_Trailing_Required_Switches, |
| From_List => Element.Value.Values, |
| In_Tree => Data.Tree); |
| |
| when Name_Multi_Unit_Switches => |
| Put (Into_List => |
| Lang_Index.Config.Multi_Unit_Switches, |
| From_List => Element.Value.Values, |
| In_Tree => Data.Tree); |
| |
| when Name_Multi_Unit_Object_Separator => |
| Get_Name_String (Element.Value.Value); |
| |
| if Name_Len /= 1 then |
| Error_Msg |
| (Data.Flags, |
| "multi-unit object separator must have " & |
| "a single character", |
| Element.Value.Location, Project); |
| |
| elsif Name_Buffer (1) = ' ' then |
| Error_Msg |
| (Data.Flags, |
| "multi-unit object separator cannot be " & |
| "a space", |
| Element.Value.Location, Project); |
| |
| else |
| Lang_Index.Config.Multi_Unit_Object_Separator := |
| Name_Buffer (1); |
| end if; |
| |
| when Name_Path_Syntax => |
| begin |
| Lang_Index.Config.Path_Syntax := |
| Path_Syntax_Kind'Value |
| (Get_Name_String (Element.Value.Value)); |
| |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "invalid value for Path_Syntax", |
| Element.Value.Location, Project); |
| end; |
| |
| when Name_Source_File_Switches => |
| Put (Into_List => |
| Lang_Index.Config.Source_File_Switches, |
| From_List => Element.Value.Values, |
| In_Tree => Data.Tree); |
| |
| when Name_Object_File_Suffix => |
| if Get_Name_String (Element.Value.Value) = "" then |
| Error_Msg |
| (Data.Flags, |
| "object file suffix cannot be empty", |
| Element.Value.Location, Project); |
| |
| else |
| Lang_Index.Config.Object_File_Suffix := |
| 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 => Data.Tree); |
| |
| when Name_Object_Path_Switches => |
| Put (Into_List => |
| Lang_Index.Config.Object_Path_Switches, |
| From_List => Element.Value.Values, |
| In_Tree => Data.Tree); |
| |
| -- Attribute Compiler_Pic_Option (<language>) |
| |
| when Name_Pic_Option => |
| List := Element.Value.Values; |
| |
| if List = Nil_String then |
| Error_Msg |
| (Data.Flags, |
| "compiler PIC option cannot be null", |
| Element.Value.Location, Project); |
| end if; |
| |
| Put (Into_List => |
| Lang_Index.Config.Compilation_PIC_Option, |
| From_List => List, |
| In_Tree => Data.Tree); |
| |
| -- Attribute Mapping_File_Switches (<language>) |
| |
| when Name_Mapping_File_Switches => |
| List := Element.Value.Values; |
| |
| if List = Nil_String then |
| Error_Msg |
| (Data.Flags, |
| "mapping file switches cannot be null", |
| Element.Value.Location, Project); |
| end if; |
| |
| Put (Into_List => |
| Lang_Index.Config.Mapping_File_Switches, |
| From_List => List, |
| In_Tree => Data.Tree); |
| |
| -- Attribute Mapping_Spec_Suffix (<language>) |
| |
| when Name_Mapping_Spec_Suffix => |
| Lang_Index.Config.Mapping_Spec_Suffix := |
| File_Name_Type (Element.Value.Value); |
| |
| -- Attribute Mapping_Body_Suffix (<language>) |
| |
| when Name_Mapping_Body_Suffix => |
| Lang_Index.Config.Mapping_Body_Suffix := |
| File_Name_Type (Element.Value.Value); |
| |
| -- Attribute Config_File_Switches (<language>) |
| |
| when Name_Config_File_Switches => |
| List := Element.Value.Values; |
| |
| if List = Nil_String then |
| Error_Msg |
| (Data.Flags, |
| "config file switches cannot be null", |
| Element.Value.Location, Project); |
| end if; |
| |
| Put (Into_List => |
| Lang_Index.Config.Config_File_Switches, |
| From_List => List, |
| In_Tree => Data.Tree); |
| |
| -- Attribute Objects_Path (<language>) |
| |
| when Name_Objects_Path => |
| Lang_Index.Config.Objects_Path := |
| Element.Value.Value; |
| |
| -- Attribute Objects_Path_File (<language>) |
| |
| when Name_Objects_Path_File => |
| Lang_Index.Config.Objects_Path_File := |
| Element.Value.Value; |
| |
| -- Attribute Config_Body_File_Name (<language>) |
| |
| when Name_Config_Body_File_Name => |
| Lang_Index.Config.Config_Body := |
| Element.Value.Value; |
| |
| -- Attribute Config_Body_File_Name_Index (< Language>) |
| |
| when Name_Config_Body_File_Name_Index => |
| Lang_Index.Config.Config_Body_Index := |
| Element.Value.Value; |
| |
| -- Attribute Config_Body_File_Name_Pattern(<language>) |
| |
| when Name_Config_Body_File_Name_Pattern => |
| Lang_Index.Config.Config_Body_Pattern := |
| Element.Value.Value; |
| |
| -- Attribute Config_Spec_File_Name (<language>) |
| |
| when Name_Config_Spec_File_Name => |
| Lang_Index.Config.Config_Spec := |
| Element.Value.Value; |
| |
| -- Attribute Config_Spec_File_Name_Index (<language>) |
| |
| when Name_Config_Spec_File_Name_Index => |
| Lang_Index.Config.Config_Spec_Index := |
| Element.Value.Value; |
| |
| -- Attribute Config_Spec_File_Name_Pattern(<language>) |
| |
| when Name_Config_Spec_File_Name_Pattern => |
| Lang_Index.Config.Config_Spec_Pattern := |
| Element.Value.Value; |
| |
| -- Attribute Config_File_Unique (<language>) |
| |
| when Name_Config_File_Unique => |
| begin |
| Lang_Index.Config.Config_File_Unique := |
| Boolean'Value |
| (Get_Name_String (Element.Value.Value)); |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "illegal value for Config_File_Unique", |
| Element.Value.Location, Project); |
| end; |
| |
| when others => |
| null; |
| end case; |
| end if; |
| end if; |
| |
| Element_Id := Element.Next; |
| end loop; |
| |
| Current_Array_Id := Current_Array.Next; |
| end loop; |
| end Process_Compiler; |
| |
| -------------------- |
| -- Process_Naming -- |
| -------------------- |
| |
| procedure Process_Naming (Attributes : Variable_Id) is |
| Attribute_Id : Variable_Id; |
| Attribute : Variable; |
| |
| begin |
| -- Process non associated array attribute from package Naming |
| |
| Attribute_Id := Attributes; |
| while Attribute_Id /= No_Variable loop |
| Attribute := Shared.Variable_Elements.Table (Attribute_Id); |
| |
| if not Attribute.Value.Default then |
| if Attribute.Name = Name_Separate_Suffix then |
| |
| -- Attribute Separate_Suffix |
| |
| Get_Name_String (Attribute.Value.Value); |
| Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len)); |
| Separate_Suffix := Name_Find; |
| |
| elsif Attribute.Name = Name_Casing then |
| |
| -- Attribute Casing |
| |
| begin |
| Casing := |
| Value (Get_Name_String (Attribute.Value.Value)); |
| |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "invalid value for Casing", |
| Attribute.Value.Location, Project); |
| end; |
| |
| elsif Attribute.Name = Name_Dot_Replacement then |
| |
| -- Attribute Dot_Replacement |
| |
| Dot_Replacement := File_Name_Type (Attribute.Value.Value); |
| |
| end if; |
| end if; |
| |
| Attribute_Id := Attribute.Next; |
| end loop; |
| end Process_Naming; |
| |
| procedure Process_Naming (Arrays : Array_Id) is |
| Current_Array_Id : Array_Id; |
| Current_Array : Array_Data; |
| Element_Id : Array_Element_Id; |
| Element : Array_Element; |
| |
| begin |
| -- Process the associative array attribute of package Naming |
| |
| Current_Array_Id := Arrays; |
| while Current_Array_Id /= No_Array loop |
| Current_Array := Shared.Arrays.Table (Current_Array_Id); |
| |
| Element_Id := Current_Array.Value; |
| while Element_Id /= No_Array_Element loop |
| Element := Shared.Array_Elements.Table (Element_Id); |
| |
| -- Get the name of the language |
| |
| Lang_Index := Get_Language_From_Name |
| (Project, Get_Name_String (Element.Index)); |
| |
| if Lang_Index /= No_Language_Index |
| and then Element.Value.Kind = Single |
| and then Element.Value.Value /= No_Name |
| then |
| case Current_Array.Name is |
| 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 := |
| 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 := |
| Name_Find; |
| Lang_Index.Config.Naming_Data.Separate_Suffix := |
| Lang_Index.Config.Naming_Data.Body_Suffix; |
| |
| when others => |
| null; |
| end case; |
| end if; |
| |
| Element_Id := Element.Next; |
| end loop; |
| |
| Current_Array_Id := Current_Array.Next; |
| end loop; |
| end Process_Naming; |
| |
| -------------------- |
| -- Process_Linker -- |
| -------------------- |
| |
| procedure Process_Linker (Attributes : Variable_Id) is |
| Attribute_Id : Variable_Id; |
| Attribute : Variable; |
| |
| begin |
| -- Process non associated array attribute from package Linker |
| |
| Attribute_Id := Attributes; |
| while Attribute_Id /= No_Variable loop |
| Attribute := Shared.Variable_Elements.Table (Attribute_Id); |
| |
| if not Attribute.Value.Default then |
| if Attribute.Name = Name_Driver then |
| |
| -- Attribute Linker'Driver: the default linker to use |
| |
| 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 Project.Config.Shared_Lib_Driver = No_File then |
| Project.Config.Shared_Lib_Driver := |
| File_Name_Type (Attribute.Value.Value); |
| end if; |
| |
| elsif Attribute.Name = Name_Required_Switches then |
| |
| -- Attribute Required_Switches: the minimum trailing |
| -- options to use when invoking the linker |
| |
| Put (Into_List => |
| Project.Config.Trailing_Linker_Required_Switches, |
| From_List => Attribute.Value.Values, |
| In_Tree => Data.Tree); |
| |
| elsif Attribute.Name = Name_Map_File_Option then |
| Project.Config.Map_File_Option := Attribute.Value.Value; |
| |
| elsif Attribute.Name = Name_Max_Command_Line_Length then |
| begin |
| Project.Config.Max_Command_Line_Length := |
| Natural'Value (Get_Name_String |
| (Attribute.Value.Value)); |
| |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "value must be positive or equal to 0", |
| Attribute.Value.Location, Project); |
| end; |
| |
| elsif Attribute.Name = Name_Response_File_Format then |
| declare |
| Name : Name_Id; |
| |
| begin |
| Get_Name_String (Attribute.Value.Value); |
| To_Lower (Name_Buffer (1 .. Name_Len)); |
| Name := Name_Find; |
| |
| if Name = Name_None then |
| Project.Config.Resp_File_Format := None; |
| |
| elsif Name = Name_Gnu then |
| Project.Config.Resp_File_Format := GNU; |
| |
| elsif Name = Name_Object_List then |
| Project.Config.Resp_File_Format := Object_List; |
| |
| elsif Name = Name_Option_List then |
| Project.Config.Resp_File_Format := Option_List; |
| |
| elsif Name_Buffer (1 .. Name_Len) = "gcc" then |
| Project.Config.Resp_File_Format := GCC; |
| |
| elsif Name_Buffer (1 .. Name_Len) = "gcc_gnu" then |
| Project.Config.Resp_File_Format := GCC_GNU; |
| |
| elsif |
| Name_Buffer (1 .. Name_Len) = "gcc_option_list" |
| then |
| Project.Config.Resp_File_Format := GCC_Option_List; |
| |
| elsif |
| Name_Buffer (1 .. Name_Len) = "gcc_object_list" |
| then |
| Project.Config.Resp_File_Format := GCC_Object_List; |
| |
| else |
| Error_Msg |
| (Data.Flags, |
| "illegal response file format", |
| Attribute.Value.Location, Project); |
| end if; |
| end; |
| |
| elsif Attribute.Name = Name_Response_File_Switches then |
| Put (Into_List => Project.Config.Resp_File_Options, |
| From_List => Attribute.Value.Values, |
| In_Tree => Data.Tree); |
| end if; |
| end if; |
| |
| Attribute_Id := Attribute.Next; |
| end loop; |
| end Process_Linker; |
| |
| -- Start of processing for Process_Packages |
| |
| begin |
| Packages := Project.Decl.Packages; |
| while Packages /= No_Package loop |
| Element := Shared.Packages.Table (Packages); |
| |
| case Element.Name is |
| when Name_Binder => |
| |
| -- Process attributes of package Binder |
| |
| Process_Binder (Element.Decl.Arrays); |
| |
| when Name_Builder => |
| |
| -- Process attributes of package Builder |
| |
| Process_Builder (Element.Decl.Attributes); |
| |
| when Name_Clean => |
| |
| -- Process attributes of package Clean |
| |
| Process_Clean (Element.Decl.Attributes); |
| Process_Clean (Element.Decl.Arrays); |
| |
| when Name_Compiler => |
| |
| -- Process attributes of package Compiler |
| |
| Process_Compiler (Element.Decl.Arrays); |
| |
| when Name_Linker => |
| |
| -- Process attributes of package Linker |
| |
| Process_Linker (Element.Decl.Attributes); |
| |
| when Name_Naming => |
| |
| -- Process attributes of package Naming |
| |
| Process_Naming (Element.Decl.Attributes); |
| Process_Naming (Element.Decl.Arrays); |
| |
| when others => |
| null; |
| end case; |
| |
| Packages := Element.Next; |
| end loop; |
| end Process_Packages; |
| |
| --------------------------------------------- |
| -- Process_Project_Level_Simple_Attributes -- |
| --------------------------------------------- |
| |
| procedure Process_Project_Level_Simple_Attributes is |
| Attribute_Id : Variable_Id; |
| Attribute : Variable; |
| List : String_List_Id; |
| |
| begin |
| -- Process non associated array attribute at project level |
| |
| Attribute_Id := Project.Decl.Attributes; |
| while Attribute_Id /= No_Variable loop |
| Attribute := Shared.Variable_Elements.Table (Attribute_Id); |
| |
| if not Attribute.Value.Default then |
| if Attribute.Name = Name_Target then |
| |
| -- Attribute Target: the target specified |
| |
| Project.Config.Target := Attribute.Value.Value; |
| |
| elsif Attribute.Name = Name_Library_Builder then |
| |
| -- Attribute Library_Builder: the application to invoke |
| -- to build libraries. |
| |
| Project.Config.Library_Builder := |
| Path_Name_Type (Attribute.Value.Value); |
| |
| elsif Attribute.Name = Name_Archive_Builder then |
| |
| -- Attribute Archive_Builder: the archive builder |
| -- (usually "ar") and its minimum options (usually "cr"). |
| |
| List := Attribute.Value.Values; |
| |
| if List = Nil_String then |
| Error_Msg |
| (Data.Flags, |
| "archive builder cannot be null", |
| Attribute.Value.Location, Project); |
| end if; |
| |
| Put (Into_List => Project.Config.Archive_Builder, |
| From_List => List, |
| In_Tree => Data.Tree); |
| |
| elsif Attribute.Name = Name_Archive_Builder_Append_Option then |
| |
| -- Attribute Archive_Builder: the archive builder |
| -- (usually "ar") and its minimum options (usually "cr"). |
| |
| List := Attribute.Value.Values; |
| |
| if List /= Nil_String then |
| Put |
| (Into_List => |
| Project.Config.Archive_Builder_Append_Option, |
| From_List => List, |
| In_Tree => Data.Tree); |
| end if; |
| |
| elsif Attribute.Name = Name_Archive_Indexer then |
| |
| -- Attribute Archive_Indexer: the optional archive |
| -- indexer (usually "ranlib") with its minimum options |
| -- (usually none). |
| |
| List := Attribute.Value.Values; |
| |
| if List = Nil_String then |
| Error_Msg |
| (Data.Flags, |
| "archive indexer cannot be null", |
| Attribute.Value.Location, Project); |
| end if; |
| |
| Put (Into_List => Project.Config.Archive_Indexer, |
| From_List => List, |
| In_Tree => Data.Tree); |
| |
| elsif Attribute.Name = Name_Library_Partial_Linker then |
| |
| -- Attribute Library_Partial_Linker: the optional linker |
| -- driver with its minimum options, to partially link |
| -- archives. |
| |
| List := Attribute.Value.Values; |
| |
| if List = Nil_String then |
| Error_Msg |
| (Data.Flags, |
| "partial linker cannot be null", |
| Attribute.Value.Location, Project); |
| end if; |
| |
| Put (Into_List => Project.Config.Lib_Partial_Linker, |
| From_List => List, |
| In_Tree => Data.Tree); |
| |
| elsif Attribute.Name = Name_Library_GCC then |
| Project.Config.Shared_Lib_Driver := |
| File_Name_Type (Attribute.Value.Value); |
| Error_Msg |
| (Data.Flags, |
| "?Library_'G'C'C is an obsolescent attribute, " & |
| "use Linker''Driver instead", |
| Attribute.Value.Location, Project); |
| |
| elsif Attribute.Name = Name_Archive_Suffix then |
| Project.Config.Archive_Suffix := |
| File_Name_Type (Attribute.Value.Value); |
| |
| elsif Attribute.Name = Name_Linker_Executable_Option then |
| |
| -- Attribute Linker_Executable_Option: optional options |
| -- to specify an executable name. Defaults to "-o". |
| |
| List := Attribute.Value.Values; |
| |
| if List = Nil_String then |
| Error_Msg |
| (Data.Flags, |
| "linker executable option cannot be null", |
| Attribute.Value.Location, Project); |
| end if; |
| |
| Put (Into_List => Project.Config.Linker_Executable_Option, |
| From_List => List, |
| In_Tree => Data.Tree); |
| |
| elsif Attribute.Name = Name_Linker_Lib_Dir_Option then |
| |
| -- Attribute Linker_Lib_Dir_Option: optional options |
| -- to specify a library search directory. Defaults to |
| -- "-L". |
| |
| Get_Name_String (Attribute.Value.Value); |
| |
| if Name_Len = 0 then |
| Error_Msg |
| (Data.Flags, |
| "linker library directory option cannot be empty", |
| Attribute.Value.Location, Project); |
| end if; |
| |
| Project.Config.Linker_Lib_Dir_Option := |
| Attribute.Value.Value; |
| |
| elsif Attribute.Name = Name_Linker_Lib_Name_Option then |
| |
| -- Attribute Linker_Lib_Name_Option: optional options |
| -- to specify the name of a library to be linked in. |
| -- Defaults to "-l". |
| |
| Get_Name_String (Attribute.Value.Value); |
| |
| if Name_Len = 0 then |
| Error_Msg |
| (Data.Flags, |
| "linker library name option cannot be empty", |
| Attribute.Value.Location, Project); |
| end if; |
| |
| Project.Config.Linker_Lib_Name_Option := |
| Attribute.Value.Value; |
| |
| elsif Attribute.Name = Name_Run_Path_Option then |
| |
| -- Attribute Run_Path_Option: optional options to |
| -- specify a path for libraries. |
| |
| List := Attribute.Value.Values; |
| |
| if List /= Nil_String then |
| Put (Into_List => Project.Config.Run_Path_Option, |
| From_List => List, |
| In_Tree => Data.Tree); |
| end if; |
| |
| elsif Attribute.Name = Name_Run_Path_Origin then |
| Get_Name_String (Attribute.Value.Value); |
| |
| if Name_Len = 0 then |
| Error_Msg |
| (Data.Flags, |
| "run path origin cannot be empty", |
| Attribute.Value.Location, Project); |
| end if; |
| |
| Project.Config.Run_Path_Origin := Attribute.Value.Value; |
| |
| elsif Attribute.Name = Name_Library_Install_Name_Option then |
| Project.Config.Library_Install_Name_Option := |
| Attribute.Value.Value; |
| |
| elsif Attribute.Name = Name_Separate_Run_Path_Options then |
| declare |
| pragma Unsuppress (All_Checks); |
| begin |
| Project.Config.Separate_Run_Path_Options := |
| Boolean'Value (Get_Name_String (Attribute.Value.Value)); |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "invalid value """ & |
| Get_Name_String (Attribute.Value.Value) & |
| """ for Separate_Run_Path_Options", |
| Attribute.Value.Location, Project); |
| end; |
| |
| elsif Attribute.Name = Name_Library_Support then |
| declare |
| pragma Unsuppress (All_Checks); |
| begin |
| Project.Config.Lib_Support := |
| Library_Support'Value (Get_Name_String |
| (Attribute.Value.Value)); |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "invalid value """ & |
| Get_Name_String (Attribute.Value.Value) & |
| """ for Library_Support", |
| Attribute.Value.Location, Project); |
| end; |
| |
| elsif |
| Attribute.Name = Name_Library_Encapsulated_Supported |
| then |
| declare |
| pragma Unsuppress (All_Checks); |
| begin |
| Project.Config.Lib_Encapsulated_Supported := |
| Boolean'Value (Get_Name_String (Attribute.Value.Value)); |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "invalid value """ |
| & Get_Name_String (Attribute.Value.Value) |
| & """ for Library_Encapsulated_Supported", |
| Attribute.Value.Location, Project); |
| end; |
| |
| elsif Attribute.Name = Name_Shared_Library_Prefix then |
| Project.Config.Shared_Lib_Prefix := |
| File_Name_Type (Attribute.Value.Value); |
| |
| elsif Attribute.Name = Name_Shared_Library_Suffix then |
| 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 |
| Project.Config.Symbolic_Link_Supported := |
| Boolean'Value (Get_Name_String |
| (Attribute.Value.Value)); |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "invalid value """ |
| & Get_Name_String (Attribute.Value.Value) |
| & """ for Symbolic_Link_Supported", |
| Attribute.Value.Location, Project); |
| end; |
| |
| elsif |
| Attribute.Name = Name_Library_Major_Minor_Id_Supported |
| then |
| declare |
| pragma Unsuppress (All_Checks); |
| begin |
| Project.Config.Lib_Maj_Min_Id_Supported := |
| Boolean'Value (Get_Name_String |
| (Attribute.Value.Value)); |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "invalid value """ & |
| Get_Name_String (Attribute.Value.Value) & |
| """ for Library_Major_Minor_Id_Supported", |
| Attribute.Value.Location, Project); |
| end; |
| |
| elsif Attribute.Name = Name_Library_Auto_Init_Supported then |
| declare |
| pragma Unsuppress (All_Checks); |
| begin |
| Project.Config.Auto_Init_Supported := |
| Boolean'Value (Get_Name_String (Attribute.Value.Value)); |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "invalid value """ |
| & Get_Name_String (Attribute.Value.Value) |
| & """ for Library_Auto_Init_Supported", |
| Attribute.Value.Location, Project); |
| end; |
| |
| elsif Attribute.Name = Name_Shared_Library_Minimum_Switches then |
| List := Attribute.Value.Values; |
| |
| if List /= Nil_String then |
| Put (Into_List => Project.Config.Shared_Lib_Min_Options, |
| From_List => List, |
| In_Tree => Data.Tree); |
| end if; |
| |
| elsif Attribute.Name = Name_Library_Version_Switches then |
| List := Attribute.Value.Values; |
| |
| if List /= Nil_String then |
| Put (Into_List => Project.Config.Lib_Version_Options, |
| From_List => List, |
| In_Tree => Data.Tree); |
| end if; |
| end if; |
| end if; |
| |
| Attribute_Id := Attribute.Next; |
| end loop; |
| end Process_Project_Level_Simple_Attributes; |
| |
| -------------------------------------------- |
| -- Process_Project_Level_Array_Attributes -- |
| -------------------------------------------- |
| |
| procedure Process_Project_Level_Array_Attributes is |
| Current_Array_Id : Array_Id; |
| Current_Array : Array_Data; |
| Element_Id : Array_Element_Id; |
| Element : Array_Element; |
| List : String_List_Id; |
| |
| begin |
| -- Process the associative array attributes at project level |
| |
| Current_Array_Id := Project.Decl.Arrays; |
| while Current_Array_Id /= No_Array loop |
| Current_Array := Shared.Arrays.Table (Current_Array_Id); |
| |
| Element_Id := Current_Array.Value; |
| while Element_Id /= No_Array_Element loop |
| Element := Shared.Array_Elements.Table (Element_Id); |
| |
| -- Get the name of the language |
| |
| 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_Inherit_Source_Path => |
| List := Element.Value.Values; |
| |
| if List /= Nil_String then |
| Put |
| (Into_List => |
| Lang_Index.Config.Include_Compatible_Languages, |
| From_List => List, |
| In_Tree => Data.Tree, |
| Lower_Case => True); |
| end if; |
| |
| when Name_Toolchain_Description => |
| |
| -- Attribute Toolchain_Description (<language>) |
| |
| Lang_Index.Config.Toolchain_Description := |
| Element.Value.Value; |
| |
| when Name_Toolchain_Version => |
| |
| -- Attribute Toolchain_Version (<language>) |
| |
| Lang_Index.Config.Toolchain_Version := |
| Element.Value.Value; |
| |
| -- For Ada, set proper checksum computation mode, |
| -- which has changed from version to version. |
| |
| if Lang_Index.Name = Name_Ada then |
| declare |
| Vers : constant String := |
| Get_Name_String (Element.Value.Value); |
| pragma Assert (Vers'First = 1); |
| |
| begin |
| -- Version 6.3 or earlier |
| |
| if Vers'Length >= 8 |
| and then Vers (1 .. 5) = "GNAT " |
| and then Vers (7) = '.' |
| and then |
| (Vers (6) < '6' |
| or else |
| (Vers (6) = '6' and then Vers (8) < '4')) |
| then |
| Checksum_GNAT_6_3 := True; |
| |
| -- Version 5.03 or earlier |
| |
| if Vers (6) < '5' |
| or else (Vers (6) = '5' |
| and then Vers (Vers'Last) < '4') |
| then |
| Checksum_GNAT_5_03 := True; |
| |
| -- Version 5.02 or earlier (no checksums) |
| |
| if Vers (6) /= '5' |
| or else Vers (Vers'Last) < '3' |
| then |
| Checksum_Accumulate_Token_Checksum := |
| False; |
| end if; |
| end if; |
| end if; |
| end; |
| end if; |
| |
| when Name_Runtime_Library_Dir => |
| |
| -- Attribute Runtime_Library_Dir (<language>) |
| |
| Lang_Index.Config.Runtime_Library_Dir := |
| Element.Value.Value; |
| |
| when Name_Runtime_Source_Dir => |
| |
| -- Attribute Runtime_Source_Dir (<language>) |
| |
| Lang_Index.Config.Runtime_Source_Dir := |
| Element.Value.Value; |
| |
| when Name_Object_Generated => |
| declare |
| pragma Unsuppress (All_Checks); |
| Value : Boolean; |
| |
| begin |
| Value := |
| Boolean'Value |
| (Get_Name_String (Element.Value.Value)); |
| |
| Lang_Index.Config.Object_Generated := Value; |
| |
| -- If no object is generated, no object may be |
| -- linked. |
| |
| if not Value then |
| Lang_Index.Config.Objects_Linked := False; |
| end if; |
| |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "invalid value """ |
| & Get_Name_String (Element.Value.Value) |
| & """ for Object_Generated", |
| Element.Value.Location, Project); |
| end; |
| |
| when Name_Objects_Linked => |
| declare |
| pragma Unsuppress (All_Checks); |
| Value : Boolean; |
| |
| begin |
| Value := |
| Boolean'Value |
| (Get_Name_String (Element.Value.Value)); |
| |
| -- No change if Object_Generated is False, as this |
| -- forces Objects_Linked to be False too. |
| |
| if Lang_Index.Config.Object_Generated then |
| Lang_Index.Config.Objects_Linked := Value; |
| end if; |
| |
| exception |
| when Constraint_Error => |
| Error_Msg |
| (Data.Flags, |
| "invalid value """ |
| & Get_Name_String (Element.Value.Value) |
| & """ for Objects_Linked", |
| Element.Value.Location, Project); |
| end; |
| when others => |
| null; |
| end case; |
| end if; |
| |
| Element_Id := Element.Next; |
| end loop; |
| |
| Current_Array_Id := Current_Array.Next; |
| end loop; |
| end Process_Project_Level_Array_Attributes; |
| |
| -- Start of processing for Check_Configuration |
| |
| begin |
| Process_Project_Level_Simple_Attributes; |
| Process_Project_Level_Array_Attributes; |
| Process_Packages; |
| |
| -- For unit based languages, set Casing, Dot_Replacement and |
| -- Separate_Suffix in Naming_Data. |
| |
| Lang_Index := Project.Languages; |
| while Lang_Index /= No_Language_Index loop |
| if Lang_Index.Config.Kind = Unit_Based then |
| Lang_Index.Config.Naming_Data.Casing := Casing; |
| Lang_Index.Config.Naming_Data.Dot_Replacement := Dot_Replacement; |
| |
| if Separate_Suffix /= No_File then |
| Lang_Index.Config.Naming_Data.Separate_Suffix := |
| Separate_Suffix; |
| end if; |
| |
| exit; |
| end if; |
| |
| Lang_Index := Lang_Index.Next; |
| end loop; |
| |
| -- Give empty names to various prefixes/suffixes, if they have not |
| -- been specified in the configuration. |
| |
| if Project.Config.Archive_Suffix = No_File then |
| Project.Config.Archive_Suffix := Empty_File; |
| end if; |
| |
| if Project.Config.Shared_Lib_Prefix = No_File then |
| Project.Config.Shared_Lib_Prefix := Empty_File; |
| end if; |
| |
| if Project.Config.Shared_Lib_Suffix = No_File then |
| Project.Config.Shared_Lib_Suffix := Empty_File; |
| end if; |
| |
| Lang_Index := Project.Languages; |
| while Lang_Index /= No_Language_Index loop |
| |
| -- 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 Data.Flags.Compiler_Driver_Mandatory |
| and then Lang_Index.Config.Compiler_Driver = No_File |
| and then not Project.Externally_Built |
| then |
| Error_Msg_Name_1 := Lang_Index.Display_Name; |
| Error_Msg |
| (Data.Flags, |
| "?\no compiler specified for language %%" & |
| ", ignoring all its sources", |
| No_Location, Project); |
| |
| if Lang_Index = Project.Languages then |
| Project.Languages := Lang_Index.Next; |
| else |
| Prev_Index.Next := Lang_Index.Next; |
| end if; |
| |
| elsif Lang_Index.Config.Kind = Unit_Based then |
| Prev_Index := Lang_Index; |
| |
| -- For unit based languages, Dot_Replacement, Spec_Suffix and |
| -- Body_Suffix need to be specified. |
| |
| if Lang_Index.Config.Naming_Data.Dot_Replacement = No_File then |
| Error_Msg |
| (Data.Flags, |
| "Dot_Replacement not specified for " & |
| Get_Name_String (Lang_Index.Name), |
| No_Location, Project); |
| end if; |
| |
| if Lang_Index.Config.Naming_Data.Spec_Suffix = No_File then |
| Error_Msg |
| (Data.Flags, |
| "\Spec_Suffix not specified for " & |
| Get_Name_String (Lang_Index.Name), |
| No_Location, Project); |
| end if; |
| |
| if Lang_Index.Config.Naming_Data.Body_Suffix = No_File then |
| Error_Msg |
| (Data.Flags, |
| "\Body_Suffix not specified for " & |
| Get_Name_String (Lang_Index.Name), |
| No_Location, Project); |
| end if; |
| |
| else |
| Prev_Index := Lang_Index; |
| |
| -- For file based languages, either Spec_Suffix or Body_Suffix |
| -- need to be specified. |
| |
| if Data.Flags.Require_Sources_Other_Lang |
| and then 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 := Lang_Index.Display_Name; |
| Error_Msg |
| (Data.Flags, |
| "\no suffixes specified for %%", |
| No_Location, Project); |
| end if; |
| end if; |
| |
| Lang_Index := Lang_Index.Next; |
| end loop; |
| end Check_Configuration; |
| |
| ------------------------------- |
| -- Check_If_Externally_Built -- |
| ------------------------------- |
| |
| procedure Check_If_Externally_Built |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data) |
| is |
| Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared; |
| Externally_Built : constant Variable_Value := |
| Util.Value_Of |
| (Name_Externally_Built, |
| Project.Decl.Attributes, Shared); |
| |
| begin |
| if not Externally_Built.Default then |
| Get_Name_String (Externally_Built.Value); |
| To_Lower (Name_Buffer (1 .. Name_Len)); |
| |
| if Name_Buffer (1 .. Name_Len) = "true" then |
| Project.Externally_Built := True; |
| |
| elsif Name_Buffer (1 .. Name_Len) /= "false" then |
| Error_Msg (Data.Flags, |
| "Externally_Built may only be true or false", |
| Externally_Built.Location, Project); |
| end if; |
| end if; |
| |
| -- A virtual project extending an externally built project is itself |
| -- externally built. |
| |
| if Project.Virtual and then Project.Extends /= No_Project then |
| Project.Externally_Built := Project.Extends.Externally_Built; |
| end if; |
| |
| if Project.Externally_Built then |
| Debug_Output ("project is externally built"); |
| else |
| Debug_Output ("project is not externally built"); |
| end if; |
| end Check_If_Externally_Built; |
| |
| ---------------------- |
| -- Check_Interfaces -- |
| ---------------------- |
| |
| procedure Check_Interfaces |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data) |
| is |
| Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared; |
| |
| Interfaces : constant Prj.Variable_Value := |
| Prj.Util.Value_Of |
| (Snames.Name_Interfaces, |
| Project.Decl.Attributes, |
| Shared); |
| |
| Library_Interface : constant Prj.Variable_Value := |
| Prj.Util.Value_Of |
| (Snames.Name_Library_Interface, |
| Project.Decl.Attributes, |
| Shared); |
| |
| List : String_List_Id; |
| Element : String_Element; |
| Name : File_Name_Type; |
| Iter : Source_Iterator; |
| Source : Source_Id; |
| Project_2 : Project_Id; |
| Other : Source_Id; |
| Unit_Found : Boolean; |
| |
| Interface_ALIs : String_List_Id := Nil_String; |
| Other_Interfaces : String_List_Id := Nil_String; |
| |
| begin |
| if not Interfaces.Default then |
| |
| -- Set In_Interfaces to False for all sources. It will be set to True |
| -- later for the sources in the Interfaces list. |
| |
| Project_2 := Project; |
| while Project_2 /= No_Project loop |
| Iter := For_Each_Source (Data.Tree, Project_2); |
| loop |
| Source := Prj.Element (Iter); |
| exit when Source = No_Source; |
| Source.In_Interfaces := False; |
| Next (Iter); |
| end loop; |
| |
| Project_2 := Project_2.Extends; |
| end loop; |
| |
| List := Interfaces.Values; |
| while List /= Nil_String loop |
| Element := Shared.String_Elements.Table (List); |
| Name := Canonical_Case_File_Name (Element.Value); |
| |
| Project_2 := Project; |
| Big_Loop : while Project_2 /= No_Project loop |
| if Project.Qualifier = Aggregate_Library then |
| |
| -- For an aggregate library we want to consider sources of |
| -- all aggregated projects. |
| |
| Iter := For_Each_Source (Data.Tree); |
| |
| else |
| Iter := For_Each_Source (Data.Tree, Project_2); |
| end if; |
| |
| loop |
| Source := Prj.Element (Iter); |
| exit when Source = No_Source; |
| |
| if Source.File = Name then |
| if not Source.Locally_Removed then |
| Source.In_Interfaces := True; |
| Source.Declared_In_Interfaces := True; |
| |
| Other := Other_Part (Source); |
| |
| if Other /= No_Source then |
| Other.In_Interfaces := True; |
| Other.Declared_In_Interfaces := True; |
| end if; |
| |
| -- Unit based case |
| |
| if Source.Language.Config.Kind = Unit_Based then |
| if Source.Kind = Spec |
| and then Other_Part (Source) /= No_Source |
| then |
| Source := Other_Part (Source); |
| end if; |
| |
| String_Element_Table.Increment_Last |
| (Shared.String_Elements); |
| |
| Shared.String_Elements.Table |
| (String_Element_Table.Last |
| (Shared.String_Elements)) := |
| (Value => Name_Id (Source.Dep_Name), |
| Index => 0, |
| Display_Value => Name_Id (Source.Dep_Name), |
| Location => No_Location, |
| Flag => False, |
| Next => Interface_ALIs); |
| |
| Interface_ALIs := |
| String_Element_Table.Last |
| (Shared.String_Elements); |
| |
| -- File based case |
| |
| else |
| String_Element_Table.Increment_Last |
| (Shared.String_Elements); |
| |
| Shared.String_Elements.Table |
| (String_Element_Table.Last |
| (Shared.String_Elements)) := |
| (Value => Name_Id (Source.File), |
| Index => 0, |
| Display_Value => Name_Id (Source.Display_File), |
| Location => No_Location, |
| Flag => False, |
| Next => Other_Interfaces); |
| |
| Other_Interfaces := |
| String_Element_Table.Last |
| (Shared.String_Elements); |
| end if; |
| |
| Debug_Output |
| ("interface: ", Name_Id (Source.Path.Name)); |
| end if; |
| |
| exit Big_Loop; |
| end if; |
| |
| Next (Iter); |
| end loop; |
| |
| 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 := Project.Name; |
| |
| Error_Msg |
| (Data.Flags, |
| "{ cannot be an interface of project %% " |
| & "as it is not one of its sources", |
| Element.Location, Project); |
| end if; |
| |
| List := Element.Next; |
| end loop; |
| |
| Project.Interfaces_Defined := True; |
| Project.Lib_Interface_ALIs := Interface_ALIs; |
| Project.Other_Interfaces := Other_Interfaces; |
| |
| elsif Project.Library and then not Library_Interface.Default then |
| |
| -- Set In_Interfaces to False for all sources. It will be set to True |
| -- later for the sources in the Library_Interface list. |
| |
| Project_2 := Project; |
| while Project_2 /= No_Project loop |
| Iter := For_Each_Source (Data.Tree, Project_2); |
| loop |
| Source := Prj.Element (Iter); |
| exit when Source = No_Source; |
| Source.In_Interfaces := False; |
| Next (Iter); |
| end loop; |
| |
| Project_2 := Project_2.Extends; |
| end loop; |
| |
| List := Library_Interface.Values; |
| while List /= Nil_String loop |
| Element := Shared.String_Elements.Table (List); |
| Get_Name_String (Element.Value); |
| To_Lower (Name_Buffer (1 .. Name_Len)); |
| Name := Name_Find; |
| Unit_Found := False; |
| |
| Project_2 := Project; |
| Big_Loop_2 : while Project_2 /= No_Project loop |
| if Project.Qualifier = Aggregate_Library then |
| |
| -- For an aggregate library we want to consider sources of |
| -- all aggregated projects. |
| |
| Iter := For_Each_Source (Data.Tree); |
| |
| else |
| Iter := For_Each_Source (Data.Tree, Project_2); |
| end if; |
| |
| loop |
| Source := Prj.Element (Iter); |
| exit when Source = No_Source; |
| |
| if Source.Unit /= No_Unit_Index |
| and then Source.Unit.Name = Name_Id (Name) |
| then |
| if not Source.Locally_Removed then |
| Source.In_Interfaces := True; |
| Source.Declared_In_Interfaces := True; |
| Project.Interfaces_Defined := True; |
| |
| Other := Other_Part (Source); |
| |
| if Other /= No_Source then |
| Other.In_Interfaces := True; |
| Other.Declared_In_Interfaces := True; |
| end if; |
| |
| Debug_Output |
| ("interface: ", Name_Id (Source.Path.Name)); |
| |
| if Source.Kind = Spec |
| and then Other_Part (Source) /= No_Source |
| then |
| Source := Other_Part (Source); |
| end if; |
| |
| String_Element_Table.Increment_Last |
| (Shared.String_Elements); |
| |
| Shared.String_Elements.Table |
| (String_Element_Table.Last |
| (Shared.String_Elements)) := |
| (Value => Name_Id (Source.Dep_Name), |
| Index => 0, |
| Display_Value => Name_Id (Source.Dep_Name), |
| Location => No_Location, |
| Flag => False, |
| Next => Interface_ALIs); |
| |
| Interface_ALIs := |
| String_Element_Table.Last (Shared.String_Elements); |
| end if; |
| |
| Unit_Found := True; |
| exit Big_Loop_2; |
| end if; |
| |
| Next (Iter); |
| end loop; |
| |
| Project_2 := Project_2.Extends; |
| end loop Big_Loop_2; |
| |
| if not Unit_Found then |
| Error_Msg_Name_1 := Name_Id (Name); |
| |
| Error_Msg |
| (Data.Flags, |
| "%% is not a unit of this project", |
| Element.Location, Project); |
| end if; |
| |
| List := Element.Next; |
| end loop; |
| |
| Project.Lib_Interface_ALIs := Interface_ALIs; |
| |
| elsif Project.Extends /= No_Project |
| and then Project.Extends.Interfaces_Defined |
| then |
| Project.Interfaces_Defined := True; |
| |
| Iter := For_Each_Source (Data.Tree, Project); |
| loop |
| Source := Prj.Element (Iter); |
| exit when Source = No_Source; |
| |
| if not Source.Declared_In_Interfaces then |
| Source.In_Interfaces := False; |
| end if; |
| |
| Next (Iter); |
| end loop; |
| |
| Project.Lib_Interface_ALIs := Project.Extends.Lib_Interface_ALIs; |
| end if; |
| end Check_Interfaces; |
| |
| ------------------------------ |
| -- Check_Library_Attributes -- |
| ------------------------------ |
| |
| -- This procedure is awfully long (over 700 lines) should be broken up??? |
| |
| procedure Check_Library_Attributes |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data) |
| is |
| Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared; |
| |
| Attributes : constant Prj.Variable_Id := Project.Decl.Attributes; |
| |
| Lib_Dir : constant Prj.Variable_Value := |
| Prj.Util.Value_Of |
| (Snames.Name_Library_Dir, Attributes, Shared); |
| |
| Lib_Name : constant Prj.Variable_Value := |
| Prj.Util.Value_Of |
| (Snames.Name_Library_Name, Attributes, Shared); |
| |
| Lib_Standalone : constant Prj.Variable_Value := |
| Prj.Util.Value_Of |
| (Snames.Name_Library_Standalone, |
| Attributes, Shared); |
| |
| Lib_Version : constant Prj.Variable_Value := |
| Prj.Util.Value_Of |
| (Snames.Name_Library_Version, Attributes, Shared); |
| |
| Lib_ALI_Dir : constant Prj.Variable_Value := |
| Prj.Util.Value_Of |
| (Snames.Name_Library_Ali_Dir, Attributes, Shared); |
| |
| Lib_GCC : constant Prj.Variable_Value := |
| Prj.Util.Value_Of |
| (Snames.Name_Library_GCC, Attributes, Shared); |
| |
| The_Lib_Kind : constant Prj.Variable_Value := |
| Prj.Util.Value_Of |
| (Snames.Name_Library_Kind, Attributes, Shared); |
| |
| Imported_Project_List : Project_List; |
| Continuation : String_Access := No_Continuation_String'Access; |
| Support_For_Libraries : Library_Support; |
| |
| Library_Directory_Present : Boolean; |
| |
| procedure Check_Library (Proj : Project_Id; Extends : Boolean); |
| -- Check if an imported or extended project if also a library project |
| |
| procedure Check_Aggregate_Library_Dirs; |
| -- Check that the library directory and the library ALI directory of an |
| -- aggregate library project are not the same as the object directory or |
| -- the library directory of any of its aggregated projects. |
| |
| ---------------------------------- |
| -- Check_Aggregate_Library_Dirs -- |
| ---------------------------------- |
| |
| procedure Check_Aggregate_Library_Dirs is |
| procedure Process_Aggregate (Proj : Project_Id); |
| -- Recursive procedure to check the aggregated projects, as they may |
| -- also be aggregated library projects. |
| |
| ----------------------- |
| -- Process_Aggregate -- |
| ----------------------- |
| |
| procedure Process_Aggregate (Proj : Project_Id) is |
| Agg : Aggregated_Project_List; |
| |
| begin |
| Agg := Proj.Aggregated_Projects; |
| while Agg /= null loop |
| Error_Msg_Name_1 := Agg.Project.Name; |
| |
| if Agg.Project.Qualifier /= Aggregate_Library |
| and then Project.Library_ALI_Dir.Name = |
| Agg.Project.Object_Directory.Name |
| then |
| Error_Msg |
| (Data.Flags, |
| "aggregate library 'A'L'I directory cannot be shared with" |
| & " object directory of aggregated project %%", |
| The_Lib_Kind.Location, Project); |
| |
| elsif Project.Library_ALI_Dir.Name = |
| Agg.Project.Library_Dir.Name |
| then |
| Error_Msg |
| (Data.Flags, |
| "aggregate library 'A'L'I directory cannot be shared with" |
| & " library directory of aggregated project %%", |
| The_Lib_Kind.Location, Project); |
| |
| elsif Agg.Project.Qualifier /= Aggregate_Library |
| and then Project.Library_Dir.Name = |
| Agg.Project.Object_Directory.Name |
| then |
| Error_Msg |
| (Data.Flags, |
| "aggregate library directory cannot be shared with" |
| & " object directory of aggregated project %%", |
| The_Lib_Kind.Location, Project); |
| |
| elsif Project.Library_Dir.Name = |
| Agg.Project.Library_Dir.Name |
| then |
| Error_Msg |
| (Data.Flags, |
| "aggregate library directory cannot be shared with" |
| & " library directory of aggregated project %%", |
| The_Lib_Kind.Location, Project); |
| end if; |
| |
| if Agg.Project.Qualifier = Aggregate_Library then |
| Process_Aggregate (Agg.Project); |
| end if; |
| |
| Agg := Agg.Next; |
| end loop; |
| end Process_Aggregate; |
| |
| -- Start of processing for Check_Aggregate_Library_Dirs |
| |
| begin |
| if Project.Qualifier = Aggregate_Library then |
| Process_Aggregate (Project); |
| end if; |
| end Check_Aggregate_Library_Dirs; |
| |
| ------------------- |
| -- Check_Library -- |
| ------------------- |
| |
| procedure Check_Library (Proj : Project_Id; Extends : Boolean) is |
| Src_Id : Source_Id; |
| Iter : Source_Iterator; |
| |
| begin |
| if Proj /= No_Project 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 |
| -- languages are OK, as there is nothing to compile. |
| |
| Iter := For_Each_Source (Data.Tree, Proj); |
| loop |
| Src_Id := Prj.Element (Iter); |
| exit when Src_Id = No_Source |
| 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 := Project.Name; |
| Error_Msg_Name_2 := Proj.Name; |
| |
| if Extends then |
| if Project.Library_Kind /= Static then |
| Error_Msg |
| (Data.Flags, |
| Continuation.all & |
| "shared library project %% cannot extend " & |
| "project %% that is not a library project", |
| Project.Location, Project); |
| Continuation := Continuation_String'Access; |
| end if; |
| |
| elsif not Unchecked_Shared_Lib_Imports |
| and then Project.Library_Kind /= Static |
| then |
| Error_Msg |
| (Data.Flags, |
| Continuation.all & |
| "shared library project %% cannot import project %% " & |
| "that is not a shared library project", |
| Project.Location, Project); |
| Continuation := Continuation_String'Access; |
| end if; |
| end if; |
| |
| elsif Project.Library_Kind /= Static |
| and then not Lib_Standalone.Default |
| and then Get_Name_String (Lib_Standalone.Value) = "encapsulated" |
| and then Proj.Library_Kind /= Static |
| then |
| -- An encapsulated library must depend only on static libraries |
| |
| Error_Msg_Name_1 := Project.Name; |
| Error_Msg_Name_2 := Proj.Name; |
| |
| Error_Msg |
| (Data.Flags, |
| Continuation.all & |
| "encapsulated library project %% cannot import shared " & |
| "library project %%", |
| Project.Location, Project); |
| Continuation := Continuation_String'Access; |
| |
| elsif Project.Library_Kind /= Static |
| and then Proj.Library_Kind = Static |
| and then |
| (Lib_Standalone.Default |
| or else |
| Get_Name_String (Lib_Standalone.Value) /= "encapsulated") |
| then |
| Error_Msg_Name_1 := Project.Name; |
| Error_Msg_Name_2 := Proj.Name; |
| |
| if Extends then |
| Error_Msg |
| (Data.Flags, |
| Continuation.all & |
| "shared library project %% cannot extend static " & |
| "library project %%", |
| Project.Location, Project); |
| Continuation := Continuation_String'Access; |
| |
| elsif not Unchecked_Shared_Lib_Imports then |
| Error_Msg |
| (Data.Flags, |
| Continuation.all & |
| "shared library project %% cannot import static " & |
| "library project %%", |
| Project.Location, Project); |
| Continuation := Continuation_String'Access; |
| end if; |
| |
| end if; |
| end if; |
| end Check_Library; |
| |
| Dir_Exists : Boolean; |
| |
| -- Start of processing for Check_Library_Attributes |
| |
| begin |
| Library_Directory_Present := Lib_Dir.Value /= Empty_String; |
| |
| -- Special case of extending project |
| |
| if Project.Extends /= No_Project then |
| |
| -- 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 Project.Extends.Library then |
| if Project.Qualifier = Standard then |
| Error_Msg |
| (Data.Flags, |
| "a standard project cannot extend a library project", |
| Project.Location, Project); |
| |
| else |
| if Lib_Name.Default then |
| Project.Library_Name := Project.Extends.Library_Name; |
| end if; |
| |
| if Lib_Dir.Default then |
| if not Project.Virtual then |
| Error_Msg |
| (Data.Flags, |
| "a project extending a library project must " & |
| "specify an attribute Library_Dir", |
| Project.Location, Project); |
| |
| else |
| -- For a virtual project extending a library project, |
| -- inherit library directory and library kind. |
| |
| Project.Library_Dir := Project.Extends.Library_Dir; |
| Library_Directory_Present := True; |
| Project.Library_Kind := Project.Extends.Library_Kind; |
| end if; |
| end if; |
| end if; |
| end if; |
| end if; |
| |
| pragma Assert (Lib_Name.Kind = Single); |
| |
| if Lib_Name.Value = Empty_String then |
| if Current_Verbosity = High |
| and then Project.Library_Name = No_Name |
| then |
| Debug_Indent; |
| Write_Line ("no library name"); |
| end if; |
| |
| else |
| -- There is no restriction on the syntax of library names |
| |
| Project.Library_Name := Lib_Name.Value; |
| end if; |
| |
| if Project.Library_Name /= No_Name then |
| if Current_Verbosity = High then |
| Write_Attr |
| ("Library name: ", Get_Name_String (Project.Library_Name)); |
| end if; |
| |
| pragma Assert (Lib_Dir.Kind = Single); |
| |
| if not Library_Directory_Present then |
| Debug_Output ("no library directory"); |
| |
| else |
| -- Find path name (unless inherited), check that it is a directory |
| |
| if Project.Library_Dir = No_Path_Information then |
| Locate_Directory |
| (Project, |
| File_Name_Type (Lib_Dir.Value), |
| Path => Project.Library_Dir, |
| Dir_Exists => Dir_Exists, |
| Data => Data, |
| Create => "library", |
| Must_Exist => False, |
| Location => Lib_Dir.Location, |
| Externally_Built => Project.Externally_Built); |
| |
| else |
| Dir_Exists := |
| Is_Directory |
| (Get_Name_String (Project.Library_Dir.Display_Name)); |
| end if; |
| |
| if not Dir_Exists then |
| if Directories_Must_Exist_In_Projects then |
| |
| -- Get the absolute name of the library directory that does |
| -- not exist, to report an error. |
| |
| Err_Vars.Error_Msg_File_1 := |
| File_Name_Type (Project.Library_Dir.Display_Name); |
| Error_Msg |
| (Data.Flags, |
| "library directory { does not exist", |
| Lib_Dir.Location, Project); |
| end if; |
| |
| -- Checks for object/source directories |
| |
| elsif not Project.Externally_Built |
| |
| -- An aggregate library does not have sources or objects, so |
| -- these tests are not required in this case. |
| |
| and then Project.Qualifier /= Aggregate_Library |
| then |
| -- Library directory cannot be the same as Object directory |
| |
| if Project.Library_Dir.Name = Project.Object_Directory.Name then |
| Error_Msg |
| (Data.Flags, |
| "library directory cannot be the same " & |
| "as object directory", |
| Lib_Dir.Location, Project); |
| 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 := Project.Source_Dirs; |
| while Dirs_Id /= Nil_String loop |
| Dir_Elem := Shared.String_Elements.Table (Dirs_Id); |
| Dirs_Id := Dir_Elem.Next; |
| |
| if Project.Library_Dir.Name = |
| Path_Name_Type (Dir_Elem.Value) |
| then |
| Err_Vars.Error_Msg_File_1 := |
| File_Name_Type (Dir_Elem.Value); |
| Error_Msg |
| (Data.Flags, |
| "library directory cannot be the same " |
| & "as source directory {", |
| Lib_Dir.Location, Project); |
| OK := False; |
| exit; |
| end if; |
| end loop; |
| |
| if OK then |
| |
| -- The library directory cannot be the same as a |
| -- source directory of another project either. |
| |
| Pid := Data.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 := |
| Shared.String_Elements.Table (Dirs_Id); |
| Dirs_Id := Dir_Elem.Next; |
| |
| 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 := |
| Pid.Project.Name; |
| |
| Error_Msg |
| (Data.Flags, |
| "library directory cannot be the same " |
| & "as source directory { of project %%", |
| Lib_Dir.Location, Project); |
| OK := False; |
| exit Project_Loop; |
| end if; |
| end loop Dir_Loop; |
| end if; |
| |
| Pid := Pid.Next; |
| end loop Project_Loop; |
| end if; |
| |
| if not OK then |
| Project.Library_Dir := No_Path_Information; |
| |
| elsif Current_Verbosity = High then |
| |
| -- Display the Library directory in high verbosity |
| |
| Write_Attr |
| ("Library directory", |
| Get_Name_String (Project.Library_Dir.Display_Name)); |
| end if; |
| end; |
| end if; |
| end if; |
| end if; |
| |
| end if; |
| |
| Project.Library := |
| Project.Library_Dir /= No_Path_Information |
| and then Project.Library_Name /= No_Name; |
| |
| if Project.Extends = No_Project then |
| case Project.Qualifier is |
| when Standard => |
| if Project.Library then |
| Error_Msg |
| (Data.Flags, |
| "a standard project cannot be a library project", |
| Lib_Name.Location, Project); |
| end if; |
| |
| when Library | Aggregate_Library => |
| if not Project.Library then |
| if Project.Library_Name = No_Name then |
| Error_Msg |
| (Data.Flags, |
| "attribute Library_Name not declared", |
| Project.Location, Project); |
| |
| if not Library_Directory_Present then |
| Error_Msg |
| (Data.Flags, |
| "\attribute Library_Dir not declared", |
| Project.Location, Project); |
| end if; |
| |
| elsif Project.Library_Dir = No_Path_Information then |
| Error_Msg |
| (Data.Flags, |
| "attribute Library_Dir not declared", |
| Project.Location, Project); |
| end if; |
| end if; |
| |
| when others => |
| null; |
| end case; |
| end if; |
| |
| if Project.Library then |
| Support_For_Libraries := Project.Config.Lib_Support; |
| |
| if not Project.Externally_Built |
| and then Support_For_Libraries = Prj.None |
| then |
| Error_Msg |
| (Data.Flags, |
| "?libraries are not supported on this platform", |
| Lib_Name.Location, Project); |
| Project.Library := False; |
| |
| else |
| if Lib_ALI_Dir.Value = Empty_String then |
| Debug_Output ("no library ALI directory specified"); |
| Project.Library_ALI_Dir := Project.Library_Dir; |
| |
| else |
| -- Find path name, check that it is a directory |
| |
| Locate_Directory |
| (Project, |
| File_Name_Type (Lib_ALI_Dir.Value), |
| Path => Project.Library_ALI_Dir, |
| Create => "library ALI", |
| Dir_Exists => Dir_Exists, |
| Data => Data, |
| Must_Exist => False, |
| Location => Lib_ALI_Dir.Location, |
| 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. |
| |
| Err_Vars.Error_Msg_File_1 := |
| File_Name_Type (Project.Library_ALI_Dir.Display_Name); |
| Error_Msg |
| (Data.Flags, |
| "library 'A'L'I directory { does not exist", |
| Lib_ALI_Dir.Location, Project); |
| end if; |
| |
| if not Project.Externally_Built |
| and then Project.Library_ALI_Dir /= Project.Library_Dir |
| then |
| -- The library ALI directory cannot be the same as the |
| -- Object directory. |
| |
| if Project.Library_ALI_Dir = Project.Object_Directory then |
| Error_Msg |
| (Data.Flags, |
| "library 'A'L'I directory cannot be the same " & |
| "as object directory", |
| Lib_ALI_Dir.Location, Project); |
| 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 := Project.Source_Dirs; |
| while Dirs_Id /= Nil_String loop |
| Dir_Elem := Shared.String_Elements.Table (Dirs_Id); |
| Dirs_Id := Dir_Elem.Next; |
| |
| 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); |
| Error_Msg |
| (Data.Flags, |
| "library 'A'L'I directory cannot be " & |
| "the same as source directory {", |
| Lib_ALI_Dir.Location, Project); |
| OK := False; |
| exit; |
| end if; |
| end loop; |
| |
| if OK then |
| |
| -- The library ALI directory cannot be the same as |
| -- a source directory of another project either. |
| |
| Pid := Data.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 |
| Dir_Elem := |
| Shared.String_Elements.Table (Dirs_Id); |
| Dirs_Id := Dir_Elem.Next; |
| |
| 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 := |
| Pid.Project.Name; |
| |
| Error_Msg |
| (Data.Flags, |
| "library 'A'L'I directory cannot " & |
| "be the same as source directory " & |
| "{ of project %%", |
| Lib_ALI_Dir.Location, Project); |
| OK := False; |
| exit ALI_Project_Loop; |
| end if; |
| end loop ALI_Dir_Loop; |
| end if; |
| Pid := Pid.Next; |
| end loop ALI_Project_Loop; |
| end if; |
| |
| if not OK then |
| Project.Library_ALI_Dir := No_Path_Information; |
| |
| elsif Current_Verbosity = High then |
| |
| -- Display Library ALI directory in high verbosity |
| |
| Write_Attr |
| ("Library ALI dir", |
| Get_Name_String |
| (Project.Library_ALI_Dir.Display_Name)); |
| end if; |
| end; |
| end if; |
| end if; |
| end if; |
| |
| pragma Assert (Lib_Version.Kind = Single); |
| |
| if Lib_Version.Value = Empty_String then |
| Debug_Output ("no library version specified"); |
| |
| else |
| Project.Lib_Internal_Name := Lib_Version.Value; |
| end if; |
| |
| pragma Assert (The_Lib_Kind.Kind = Single); |
| |
| if The_Lib_Kind.Value = Empty_String then |
| Debug_Output ("no library kind specified"); |
| |
| else |
| Get_Name_String (The_Lib_Kind.Value); |
| |
| declare |
| Kind_Name : constant String := |
| To_Lower (Name_Buffer (1 .. Name_Len)); |
| |
| OK : Boolean := True; |
| |
| begin |
| if Kind_Name = "static" then |
| Project.Library_Kind := Static; |
| |
| elsif Kind_Name = "dynamic" then |
| Project.Library_Kind := Dynamic; |
| |
| elsif Kind_Name = "relocatable" then |
| Project.Library_Kind := Relocatable; |
| |
| else |
| Error_Msg |
| (Data.Flags, |
| "illegal value for Library_Kind", |
| The_Lib_Kind.Location, Project); |
| OK := False; |
| end if; |
| |
| if Current_Verbosity = High and then OK then |
| Write_Attr ("Library kind", Kind_Name); |
| end if; |
| |
| if Project.Library_Kind /= Static then |
| if not Project.Externally_Built |
| and then Support_For_Libraries = Prj.Static_Only |
| then |
| Error_Msg |
| (Data.Flags, |
| "only static libraries are supported " & |
| "on this platform", |
| The_Lib_Kind.Location, Project); |
| Project.Library := False; |
| |
| else |
| -- Check if (obsolescent) attribute Library_GCC or |
| -- Linker'Driver is declared. |
| |
| if Lib_GCC.Value /= Empty_String then |
| Error_Msg |
| (Data.Flags, |
| "?Library_'G'C'C is an obsolescent attribute, " & |
| "use Linker''Driver instead", |
| Lib_GCC.Location, Project); |
| Project.Config.Shared_Lib_Driver := |
| File_Name_Type (Lib_GCC.Value); |
| |
| else |
| declare |
| Linker : constant Package_Id := |
| Value_Of |
| (Name_Linker, |
| Project.Decl.Packages, |
| Shared); |
| Driver : constant Variable_Value := |
| Value_Of |
| (Name => No_Name, |
| Attribute_Or_Array_Name => |
| Name_Driver, |
| In_Package => Linker, |
| Shared => Shared); |
| |
| begin |
| if Driver /= Nil_Variable_Value |
| and then Driver.Value /= Empty_String |
| then |
| Project.Config.Shared_Lib_Driver := |
| File_Name_Type (Driver.Value); |
| end if; |
| end; |
| end if; |
| end if; |
| end if; |
| end; |
| end if; |
| |
| if Project.Library |
| and then Project.Qualifier /= Aggregate_Library |
| then |
| Debug_Output ("this is a library project file"); |
| |
| Check_Library (Project.Extends, Extends => True); |
| |
| Imported_Project_List := Project.Imported_Projects; |
| while Imported_Project_List /= null loop |
| Check_Library |
| (Imported_Project_List.Project, |
| Extends => False); |
| Imported_Project_List := Imported_Project_List.Next; |
| end loop; |
| end if; |
| end if; |
| end if; |
| |
| -- Check if Linker'Switches or Linker'Default_Switches are declared. |
| -- Warn if they are declared, as it is a common error to think that |
| -- library are "linked" with Linker switches. |
| |
| if Project.Library then |
| declare |
| Linker_Package_Id : constant Package_Id := |
| Util.Value_Of |
| (Name_Linker, |
| Project.Decl.Packages, Shared); |
| Linker_Package : Package_Element; |
| Switches : Array_Element_Id := No_Array_Element; |
| |
| begin |
| if Linker_Package_Id /= No_Package then |
| Linker_Package := Shared.Packages.Table (Linker_Package_Id); |
| |
| Switches := |
| Value_Of |
| (Name => Name_Switches, |
| In_Arrays => Linker_Package.Decl.Arrays, |
| Shared => Shared); |
| |
| if Switches = No_Array_Element then |
| Switches := |
| Value_Of |
| (Name => Name_Default_Switches, |
| In_Arrays => Linker_Package.Decl.Arrays, |
| Shared => Shared); |
| end if; |
| |
| if Switches /= No_Array_Element then |
| Error_Msg |
| (Data.Flags, |
| "?\Linker switches not taken into account in library " & |
| "projects", |
| No_Location, Project); |
| end if; |
| end if; |
| end; |
| end if; |
| |
| if Project.Extends /= No_Project and then Project.Extends.Library then |
| |
| -- Remove the library name from Lib_Data_Table |
| |
| for J in 1 .. Lib_Data_Table.Last loop |
| if Lib_Data_Table.Table (J).Proj = Project.Extends then |
| Lib_Data_Table.Table (J) := |
| Lib_Data_Table.Table (Lib_Data_Table.Last); |
| Lib_Data_Table.Set_Last (Lib_Data_Table.Last - 1); |
| exit; |
| end if; |
| end loop; |
| end if; |
| |
| if Project.Library and then not Lib_Name.Default then |
| |
| -- Check if the same library name is used in an other library project |
| |
| for J in 1 .. Lib_Data_Table.Last loop |
| if Lib_Data_Table.Table (J).Name = Project.Library_Name |
| and then Lib_Data_Table.Table (J).Tree = Data.Tree |
| then |
| Error_Msg_Name_1 := Lib_Data_Table.Table (J).Proj.Name; |
| Error_Msg |
| (Data.Flags, |
| "Library name cannot be the same as in project %%", |
| Lib_Name.Location, Project); |
| Project.Library := False; |
| exit; |
| end if; |
| end loop; |
| end if; |
| |
| if not Lib_Standalone.Default |
| and then Project.Library_Kind = Static |
| then |
| -- An standalone library must be a shared library |
| |
| Error_Msg_Name_1 := Project.Name; |
| |
| Error_Msg |
| (Data.Flags, |
| Continuation.all & |
| "standalone library project %% must be a shared library", |
| Project.Location, Project); |
| Continuation := Continuation_String'Access; |
| end if; |
| |
| -- Check that aggregated libraries do not share the aggregate |
| -- Library_ALI_Dir. |
| |
| if Project.Qualifier = Aggregate_Library then |
| Check_Aggregate_Library_Dirs; |
| end if; |
| |
| if Project.Library and not Data.In_Aggregate_Lib then |
| |
| -- Record the library name |
| |
| Lib_Data_Table.Append |
| ((Name => Project.Library_Name, |
| Proj => Project, |
| Tree => Data.Tree)); |
| end if; |
| end Check_Library_Attributes; |
| |
| -------------------------- |
| -- Check_Package_Naming -- |
| -------------------------- |
| |
| procedure Check_Package_Naming |
| (Project : Project_Id; |
| Data : in out Tree_Processing_Data) |
| is |
| Shared : constant Shared_Project_Tree_Data_Access := Data.Tree.Shared; |
| Naming_Id : constant Package_Id := |
| Util.Value_Of |
| (Name_Naming, Project.Decl.Packages, Shared); |
| Naming : Package_Element; |
| |
| Ada_Body_Suffix_Loc : Source_Ptr := No_Location; |
| |
| procedure Check_Naming; |
| -- Check the validity of the Naming package (suffixes valid, ...) |
| |
| procedure Check_Common |
| (Dot_Replacement : in out File_Name_Type; |
| Casing : in out Casing_Type; |
| Casing_Defined : out Boolean; |
| Separate_Suffix : in out File_Name_Type; |
| Sep_Suffix_Loc : out Source_Ptr); |
| -- Check attributes common |
| |
| procedure Process_Exceptions_File_Based |
| (Lang_Id : Language_Ptr; |
| Kind : Source_Kind); |
| procedure Process_Exceptions_Unit_Based |
| (Lang_Id : Language_Ptr; |
| Kind : Source_Kind); |
| -- Process the naming exceptions for the two types of languages |
| |
| procedure Initialize_Naming_Data; |
| -- Initialize internal naming data for the various languages |
| |
| ------------------ |
| -- Check_Common -- |
| ------------------ |
| |
| procedure Check_Common |
| (Dot_Replacement : in out File_Name_Type; |
| Casing : in out Casing_Type; |
| Casing_Defined : out Boolean; |
| Separate_Suffix : in out File_Name_Type; |
| Sep_Suffix_Loc : out Source_Ptr) |
| is |
| Dot_Repl : constant Variable_Value := |
| Util.Value_Of |
| (Name_Dot_Replacement, |
| Naming.Decl.Attributes, |
| Shared); |
| Casing_String : constant Variable_Value := |
| Util.Value_Of |
| (Name_Casing, |
| Naming.Decl.Attributes, |
| Shared); |
| Sep_Suffix : constant Variable_Value := |
| Util.Value_Of |
| (Name_Separate_Suffix, |
| Naming.Decl.Attributes, |
| Shared); |
| Dot_Repl_Loc : Source_Ptr; |
| |
| begin |
| Sep_Suffix_Loc := No_Location; |
| |
| if not Dot_Repl.Default then |
| pragma Assert |
| (Dot_Repl.Kind = Single, "Dot_Replacement is not a string"); |
| |
| if Length_Of_Name (Dot_Repl.Value) = 0 then |
| Error_Msg |
| (Data.Flags, "Dot_Replacement cannot be empty", |
| Dot_Repl.Location, Project); |
| end if; |
| |
| Dot_Replacement := Canonical_Case_File_Name (Dot_Repl.Value); |
| Dot_Repl_Loc := Dot_Repl.Location; |
| |
| declare |
| Repl : constant String := Get_Name_String (Dot_Replacement); |
| |
| begin |
| -- Dot_Replacement cannot |
| -- - be empty |
| -- - start or end with an alphanumeric |
| -- - be a single '_' |
| -- - start with an '_' followed by an alphanumeric |
| -- - contain a '.' except if it is "." |
| |
| if Repl'Length = 0 |
| or else Is_Alphanumeric (Repl (Repl'First)) |
| or else Is_Alphanumeric (Repl (Repl'Last)) |
| or else (Repl (Repl'First) = '_' |
| and then |
| (Repl'Length = 1 |
| or else |
| Is_Alphanumeric (Repl (Repl'First + 1)))) |
| or else (Repl'Length > 1 |
| and then |
| Index (Source => Repl, Pattern => ".") /= 0) |
| then |
| Error_Msg |
| (Data.Flags, |
| '"' & Repl & |
| """ is illegal for Dot_Replacement.", |
| Dot_Repl_Loc, Project); |
| end if; |
| end; |
| end if; |
| |
| if Dot_Replacement /= No_File then |
| Write_Attr |
| ("Dot_Replacement", Get_Name_String (Dot_Replacement)); |
| end if; |
| |
| Casing_Defined := False; |
| |
| if not Casing_String.Default then |
| pragma Assert |
| (Casing_String.Kind = Single, "Casing is not a string"); |
| |
| declare |
| Casing_Image : constant String := |
| Get_Name_String (Casing_String.Value); |
| |
| begin |
| if Casing_Image'Length = 0 then |
| Error_Msg |
| (Data.Flags, |
| "Casing cannot be an empty string", |
| Casing_String.Location, Project); |
| end if; |
| |
| Casing := Value (Casing_Image); |
| Casing_Defined := True; |
| |
| exception |
| when Constraint_Error => |
| Name_Len := Casing_Image'Length; |
| Name_Buffer (1 .. Name_Len) := Casing_Image; |
| Err_Vars.Error_Msg_Name_1 := Name_Find; |
| Error_Msg |
| (Data.Flags, |
| "%% is not a correct Casing", |
| Casing_String.Location, Project); |
| end; |
| end if; |
| |
| Write_Attr ("Casing", Image (Casing)); |
| |
| if not Sep_Suffix.Default then |
| if Length_Of_Name (Sep_Suffix.Value) = 0 then |
| Error_Msg |
| (Data.Flags, |
| "Separate_Suffix cannot be empty", |
| Sep_Suffix.Location, Project); |
| |
| else |
| Separate_Suffix := Canonical_Case_File_Name (Sep_Suffix.Value); |
| Sep_Suffix_Loc := Sep_Suffix.Location; |
| |
| Check_Illegal_Suffix |
| (Project, Separate_Suffix, |
| Dot_Replacement, "Separate_Suffix", Sep_Suffix.Location, |
| Data); |
| end if; |
| end if; |
| |
| if Separate_Suffix /= No_File then |
| Write_Attr |
| ("Separate_Suffix", Get_Name_String (Separate_Suffix)); |
| end if; |
| end Check_Common; |
| |
| ----------------------------------- |
| -- Process_Exceptions_File_Based -- |
| ----------------------------------- |
| |
| procedure Process_Exceptions_File_Based |
| (Lang_Id : Language_Ptr; |
| Kind : Source_Kind) |
| is |
| Lang : constant Name_Id := Lang_Id.Name; |
| Exceptions : Array_Element_Id; |
| Exception_List : Variable_Value; |
| Element_Id : String_List_Id; |
| Element : String_Element; |
| File_Name : File_Name_Type; |
| Source : Source_Id; |
| |
| begin |
| case Kind is |
| when Impl | Sep => |
| Exceptions := |
| Value_Of |
| (Name_Implementation_Exceptions, |
| In_Arrays => Naming.Decl.Arrays, |
| Shared => Shared); |
| |
| when Spec => |
| Exceptions := |
| Value_Of |
| (Name_Specification_Exceptions, |
| In_Arrays => Naming.Decl.Arrays, |
| Shared => Shared); |
| end case; |
| |
| Exception_List := |
| Value_Of |
| (Index => Lang, |
| In_Array => Exceptions, |
| Shared => Shared); |
| |
| if Exception_List /= Nil_Variable_Value then |
| Element_Id := Exception_List.Values; |
| while Element_Id /= Nil_String loop |
| Element := Shared.String_Elements.Table (Element_Id); |
| File_Name := Canonical_Case_File_Name (Element.Value); |
| |
| Source := |
| Source_Files_Htable.Get |
| (Data.Tree.Source_Files_HT, File_Name); |
| while Source /= No_Source |
| and then Source.Project /= Project |
| loop |
| Source := Source.Next_With_File_Name; |
| end loop; |
| |
| if Source = No_Source then |
| Add_Source |
| (Id => Source, |
| Data => Data, |
| Project => Project, |
| Source_Dir_Rank => 0, |
| Lang_Id => Lang_Id, |
| Kind => Kind, |
| File_Name => File_Name, |
| Display_File => File_Name_Type (Element.Value), |
| Naming_Exception => Yes, |
| Location => Element.Location); |
| |
| else |
| -- Check if the file name is already recorded for another |
| -- language or another kind. |
| |
| if Source.Language /= Lang_Id then |
| Error_Msg |
| (Data.Flags, |
| "the same file cannot be a source of two languages", |
| Element.Location, Project); |
| |
| elsif Source.Kind /= Kind then |
| Error_Msg |
| (Data.Flags, |
| "the same file cannot be a source and a template", |
| Element.Location, Project); |
| end if; |
| |
| -- If the file is already recorded for the same |
| -- language and the same kind, it means that the file |
| -- name appears several times in the *_Exceptions |
| -- attribute; so there is nothing to do. |
| end if; |
| |
| Element_Id := Element.Next; |
| end loop; |
| end if; |
| end Process_Exceptions_File_Based; |
| |
| ----------------------------------- |
| -- Process_Exceptions_Unit_Based -- |
| ----------------------------------- |
| |
| procedure Process_Exceptions_Unit_Based |
| (Lang_Id : Language_Ptr; |
| Kind : Source_Kind) |
| is |
| Exceptions : Array_Element_Id; |
| Element : Array_Element; |
| Unit : Name_Id; |
| Index : Int; |
| File_Name : File_Name_Type; |
| Source : Source_Id; |
| |
| Naming_Exception : Naming_Exception_Type; |
| |
| begin |
| case Kind is |
| when Impl | Sep => |
| Exceptions := |
| Value_Of |
| (Name_Body, |
| In_Arrays => Naming.Decl.Arrays, |
| Shared => Shared); |
| |
| if Exceptions = No_Array_Element then |
| Exceptions := |
| Value_Of |
| (Name_Implementation, |
| In_Arrays => Naming.Decl.Arrays, |
| Shared => Shared); |
| end if; |
| |
| when Spec => |
| Exceptions := |
| Value_Of |
| (Name_Spec, |
| In_Arrays => Naming.Decl.Arrays, |
| Shared => Shared); |
| |
| if Exceptions = No_Array_Element then |
| Exceptions := |
| Value_Of |
| (Name_Specification, |
| In_Arrays => Naming.Decl.Arrays, |
| Shared => Shared); |
| end if; |
| end case; |
| |
| while Exceptions /= No_Array_Element loop |
| Element := Shared.Array_Elements.Table (Exceptions); |
| |
| if Element.Restricted then |
| Naming_Exception := Inherited; |
| else |
| Naming_Exception := Yes; |
| end if; |
| |
| File_Name := Canonical_Case_File_Name (Element.Value.Value); |
| |
| Get_Name_String (Element.Index); |
| To_Lower (Name_Buffer (1 .. Name_Len)); |
| Index := Element.Value.Index; |
| |
| -- Check if it is a valid unit name |
| |
| Get_Name_String (Element.Index); |
| Check_Unit_Name (Name_Buffer (1 .. Name_Len), Unit); |
| |
| if Unit = No_Name then |
| Err_Vars.Error_Msg_Name_1 := Element.Index; |
| Error_Msg |
| (Data.Flags, |
| "%% is not a valid unit name.", |
| Element.Value.Location, Project); |
| end if; |
| |
| if Unit /= No_Name then |
| Add_Source |
| (Id => Source, |
| Data => Data, |
| Project => Project, |
| Source_Dir_Rank => 0, |
| Lang_Id => Lang_Id, |
| Kind => Kind, |
| File_Name => File_Name, |
| Display_File => File_Name_Type (Element.Value.Value), |
| Unit => Unit, |
| Index => Index, |
| Location => Element.Value.Location, |
| Naming_Exception => Naming_Exception); |
| end if; |
| |
| Exceptions := Element.Next; |
| end loop; |
| end Process_Exceptions_Unit_Based; |
| |
| ------------------ |
| -- Check_Naming -- |
| ------------------ |
| |
| procedure Check_Naming is |
| Dot_Replacement : File_Name_Type := |
| File_Name_Type |
| (First_Name_Id + Character'Pos ('-')); |
| Separate_Suffix : File_Name_Type := No_File; |
| Casing : Casing_Type := All_Lower_Case; |
| Casing_Defined : Boolean; |
| Lang_Id : Language_Ptr; |
| Sep_Suffix_Loc : Source_Ptr; |
| Suffix : Variable_Value; |
| Lang : Name_Id; |
| |
| begin |
| Check_Common |
| (Dot_Replacement => Dot_Replacement, |
| Casing => Casing, |
| Casing_Defined => Casing_Defined, |
| Separate_Suffix => Separate_Suffix, |
| Sep_Su
|