OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-attr.adb
index 8234d27..ba569e1 100644 (file)
@@ -6,40 +6,39 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2001-2005, Free Software Foundation, Inc.         --
+--          Copyright (C) 2001-2011, 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 2,  or (at your option) any later ver- --
+-- 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 COPYING.  If not, write --
--- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
--- Boston, MA 02110-1301, USA.                                              --
+-- 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 Namet;   use Namet;
 with Osint;
 with Prj.Com; use Prj.Com;
-with Table;
 
-with System.Case_Util; use System.Case_Util;
+with GNAT.Case_Util; use GNAT.Case_Util;
 
 package body Prj.Attr is
 
+   use GNAT;
+
    --  Data for predefined attributes and packages
 
-   --  Names end with '#'
+   --  Names are in lower case and end with '#'
 
    --  Package names are preceded by 'P'
 
-   --  Attribute names are preceded by two letters:
+   --  Attribute names are preceded by two or three letters:
 
    --  The first letter is one of
    --    'S' for Single
@@ -55,163 +54,337 @@ package body Prj.Attr is
    --        insensitive
    --    'c' same as 'b', with optional index
 
+   --  The third optional letter is
+   --     'R' to indicate that the attribute is read-only
+   --     'O' to indicate that others is allowed as an index for an associative
+   --     array
+
    --  End is indicated by two consecutive '#'
 
    Initialization_Data : constant String :=
 
-   --  project attributes
-
-     "SVobject_dir#" &
-     "SVexec_dir#" &
-     "LVsource_dirs#" &
-     "LVsource_files#" &
-     "LVlocally_removed_files#" &
-     "SVsource_list_file#" &
-     "SVlibrary_dir#" &
-     "SVlibrary_name#" &
-     "SVlibrary_kind#" &
-     "SVlibrary_version#" &
-     "LVlibrary_interface#" &
-     "SVlibrary_auto_init#" &
-     "LVlibrary_options#" &
-     "SVlibrary_src_dir#" &
-     "SVlibrary_ali_dir#" &
-     "SVlibrary_gcc#" &
-     "SVlibrary_symbol_file#" &
-     "SVlibrary_symbol_policy#" &
-     "SVlibrary_reference_symbol_file#" &
-     "lVmain#" &
-     "LVlanguages#" &
-     "SVmain_language#" &
-     "LVada_roots#" &
-     "SVexternally_built#" &
+   --  project level attributes
+
+   --  General
+
+   "SVRname#" &
+   "SVRproject_dir#" &
+   "lVmain#" &
+   "LVlanguages#" &
+   "Lbroots#" &
+   "SVexternally_built#" &
+
+   --  Directories
+
+   "SVobject_dir#" &
+   "SVexec_dir#" &
+   "LVsource_dirs#" &
+   "Lainherit_source_path#" &
+   "LVexcluded_source_dirs#" &
+   "LVignore_source_sub_dirs#" &
+
+   --  Source files
+
+   "LVsource_files#" &
+   "LVlocally_removed_files#" &
+   "LVexcluded_source_files#" &
+   "SVsource_list_file#" &
+   "SVexcluded_source_list_file#" &
+   "LVinterfaces#" &
+
+   --  Projects (in aggregate projects)
+
+   "LVproject_files#" &
+   "LVproject_path#" &
+   "SAexternal#" &
+
+   --  Libraries
+
+   "SVlibrary_dir#" &
+   "SVlibrary_name#" &
+   "SVlibrary_kind#" &
+   "SVlibrary_version#" &
+   "LVlibrary_interface#" &
+   "SVlibrary_standalone#" &
+   "LVlibrary_encapsulated_options#" &
+   "SVlibrary_encapsulated_supported#" &
+   "SVlibrary_auto_init#" &
+   "LVleading_library_options#" &
+   "LVlibrary_options#" &
+   "SVlibrary_src_dir#" &
+   "SVlibrary_ali_dir#" &
+   "SVlibrary_gcc#" &
+   "SVlibrary_symbol_file#" &
+   "SVlibrary_symbol_policy#" &
+   "SVlibrary_reference_symbol_file#" &
+
+   --  Configuration - General
+
+   "SVdefault_language#" &
+   "LVrun_path_option#" &
+   "SVrun_path_origin#" &
+   "SVseparate_run_path_options#" &
+   "Satoolchain_version#" &
+   "Satoolchain_description#" &
+   "Saobject_generated#" &
+   "Saobjects_linked#" &
+   "SVtarget#" &
+
+   --  Configuration - Libraries
+
+   "SVlibrary_builder#" &
+   "SVlibrary_support#" &
+
+   --  Configuration - Archives
+
+   "LVarchive_builder#" &
+   "LVarchive_builder_append_option#" &
+   "LVarchive_indexer#" &
+   "SVarchive_suffix#" &
+   "LVlibrary_partial_linker#" &
+
+   --  Configuration - Shared libraries
+
+   "SVshared_library_prefix#" &
+   "SVshared_library_suffix#" &
+   "SVsymbolic_link_supported#" &
+   "SVlibrary_major_minor_id_supported#" &
+   "SVlibrary_auto_init_supported#" &
+   "LVshared_library_minimum_switches#" &
+   "LVlibrary_version_switches#" &
+   "SVlibrary_install_name_option#" &
+   "Saruntime_library_dir#" &
+   "Saruntime_source_dir#" &
 
    --  package Naming
-
-     "Pnaming#" &
-     "Saspecification_suffix#" &
-     "Saspec_suffix#" &
-     "Saimplementation_suffix#" &
-     "Sabody_suffix#" &
-     "SVseparate_suffix#" &
-     "SVcasing#" &
-     "SVdot_replacement#" &
-     "sAspecification#" &
-     "sAspec#" &
-     "sAimplementation#" &
-     "sAbody#" &
-     "Laspecification_exceptions#" &
-     "Laimplementation_exceptions#" &
+   --  Some attributes are obsolescent, and renamed in the tree (see
+   --  Prj.Dect.Rename_Obsolescent_Attributes).
+
+   "Pnaming#" &
+   "Saspecification_suffix#" &  --  Always renamed to "spec_suffix" in tree
+   "Saspec_suffix#" &
+   "Saimplementation_suffix#" & --  Always renamed to "body_suffix" in tree
+   "Sabody_suffix#" &
+   "SVseparate_suffix#" &
+   "SVcasing#" &
+   "SVdot_replacement#" &
+   "saspecification#" &  --  Always renamed to "spec" in project tree
+   "saspec#" &
+   "saimplementation#" & --  Always renamed to "body" in project tree
+   "sabody#" &
+   "Laspecification_exceptions#" &
+   "Laimplementation_exceptions#" &
 
    --  package Compiler
 
-     "Pcompiler#" &
-     "Ladefault_switches#" &
-     "Lcswitches#" &
-     "SVlocal_configuration_pragmas#" &
+   "Pcompiler#" &
+   "Ladefault_switches#" &
+   "LcOswitches#" &
+   "SVlocal_configuration_pragmas#" &
+   "Salocal_config_file#" &
+
+   --  Configuration - Compiling
+
+   "Sadriver#" &
+   "Salanguage_kind#" &
+   "Sadependency_kind#" &
+   "Larequired_switches#" &
+   "Laleading_required_switches#" &
+   "Latrailing_required_switches#" &
+   "Lapic_option#" &
+   "Sapath_syntax#" &
+   "Lasource_file_switches#" &
+   "Saobject_file_suffix#" &
+   "Laobject_file_switches#" &
+   "Lamulti_unit_switches#" &
+   "Samulti_unit_object_separator#" &
+
+   --  Configuration - Mapping files
+
+   "Lamapping_file_switches#" &
+   "Samapping_spec_suffix#" &
+   "Samapping_body_suffix#" &
+
+   --  Configuration - Config files
+
+   "Laconfig_file_switches#" &
+   "Saconfig_body_file_name#" &
+   "Saconfig_body_file_name_index#" &
+   "Saconfig_body_file_name_pattern#" &
+   "Saconfig_spec_file_name#" &
+   "Saconfig_spec_file_name_index#" &
+   "Saconfig_spec_file_name_pattern#" &
+   "Saconfig_file_unique#" &
+
+   --  Configuration - Dependencies
+
+   "Ladependency_switches#" &
+   "Ladependency_driver#" &
+
+   --  Configuration - Search paths
+
+   "Lainclude_switches#" &
+   "Sainclude_path#" &
+   "Sainclude_path_file#" &
 
    --  package Builder
 
-     "Pbuilder#" &
-     "Ladefault_switches#" &
-     "Lcswitches#" &
-     "Scexecutable#" &
-     "SVexecutable_suffix#" &
-     "SVglobal_configuration_pragmas#" &
+   "Pbuilder#" &
+   "Ladefault_switches#" &
+   "LcOswitches#" &
+   "Lcglobal_compilation_switches#" &
+   "Scexecutable#" &
+   "SVexecutable_suffix#" &
+   "SVglobal_configuration_pragmas#" &
+   "Saglobal_config_file#" &
 
    --  package gnatls
 
-     "Pgnatls#" &
-     "LVswitches#" &
+   "Pgnatls#" &
+   "LVswitches#" &
 
    --  package Binder
 
-     "Pbinder#" &
-     "Ladefault_switches#" &
-     "Lcswitches#" &
+   "Pbinder#" &
+   "Ladefault_switches#" &
+   "LcOswitches#" &
+
+   --  Configuration - Binding
+
+   "Sadriver#" &
+   "Larequired_switches#" &
+   "Saprefix#" &
+   "Saobjects_path#" &
+   "Saobjects_path_file#" &
 
    --  package Linker
 
-     "Plinker#" &
-     "Ladefault_switches#" &
-     "Lcswitches#" &
-     "LVlinker_options#" &
+   "Plinker#" &
+   "LVrequired_switches#" &
+   "Ladefault_switches#" &
+   "LcOleading_switches#" &
+   "LcOswitches#" &
+   "LVlinker_options#" &
+   "SVmap_file_option#" &
+
+   --  Configuration - Linking
+
+   "SVdriver#" &
+   "LVexecutable_switch#" &
+   "SVlib_dir_switch#" &
+   "SVlib_name_switch#" &
+
+   --  Configuration - Response files
+
+   "SVmax_command_line_length#" &
+   "SVresponse_file_format#" &
+   "LVresponse_file_switches#" &
 
    --  package Cross_Reference
 
-     "Pcross_reference#" &
-     "Ladefault_switches#" &
-     "Lbswitches#" &
+   "Pcross_reference#" &
+   "Ladefault_switches#" &
+   "LbOswitches#" &
 
    --  package Finder
 
-     "Pfinder#" &
-     "Ladefault_switches#" &
-     "Lbswitches#" &
+   "Pfinder#" &
+   "Ladefault_switches#" &
+   "LbOswitches#" &
 
    --  package Pretty_Printer
 
-     "Ppretty_printer#" &
-     "Ladefault_switches#" &
-     "Lbswitches#" &
+   "Ppretty_printer#" &
+   "Ladefault_switches#" &
+   "LbOswitches#" &
 
    --  package gnatstub
 
-     "Pgnatstub#" &
-     "Ladefault_switches#" &
-     "Lbswitches#" &
+   "Pgnatstub#" &
+   "Ladefault_switches#" &
+   "LbOswitches#" &
 
    --  package Check
 
-     "Pcheck#" &
-     "Ladefault_switches#" &
-     "Lbswitches#" &
+   "Pcheck#" &
+   "Ladefault_switches#" &
+   "LbOswitches#" &
+
+   --  package Synchronize
+
+   "Psynchronize#" &
+   "Ladefault_switches#" &
+   "LbOswitches#" &
 
    --  package Eliminate
 
-     "Peliminate#" &
-     "Ladefault_switches#" &
-     "Lbswitches#" &
+   "Peliminate#" &
+   "Ladefault_switches#" &
+   "LbOswitches#" &
 
    --  package Metrics
 
-     "Pmetrics#" &
-     "Ladefault_switches#" &
-     "Lbswitches#" &
+   "Pmetrics#" &
+   "Ladefault_switches#" &
+   "LbOswitches#" &
 
    --  package Ide
 
-     "Pide#" &
-     "Ladefault_switches#" &
-     "SVremote_host#" &
-     "SVprogram_host#" &
-     "SVcommunication_protocol#" &
-     "Sacompiler_command#" &
-     "SVdebugger_command#" &
-     "SVgnatlist#" &
-     "SVvcs_kind#" &
-     "SVvcs_file_check#" &
-     "SVvcs_log_check#" &
-
-   --  package Language_Processing
-
-     "Planguage_processing#" &
-     "Lacompiler_driver#" &
-     "Sacompiler_kind#" &
-     "Ladependency_option#" &
-     "Lacompute_dependency#" &
-     "Lainclude_option#" &
-     "Sabinder_driver#" &
-     "SVdefault_linker#" &
-
-     "#";
+   "Pide#" &
+   "Ladefault_switches#" &
+   "SVremote_host#" &
+   "SVprogram_host#" &
+   "SVcommunication_protocol#" &
+   "Sacompiler_command#" &
+   "SVdebugger_command#" &
+   "SVgnatlist#" &
+   "SVvcs_kind#" &
+   "SVvcs_file_check#" &
+   "SVvcs_log_check#" &
+   "SVdocumentation_dir#" &
+
+   --  package Stack
+
+   "Pstack#" &
+   "LVswitches#" &
+
+   "#";
 
    Initialized : Boolean := False;
    --  A flag to avoid multiple initialization
 
+   Package_Names     : String_List_Access := new Strings.String_List (1 .. 20);
+   Last_Package_Name : Natural := 0;
+   --  Package_Names (1 .. Last_Package_Name) contains the list of the known
+   --  package names, coming from the Initialization_Data string or from
+   --  calls to one of the two procedures Register_New_Package.
+
+   procedure Add_Package_Name (Name : String);
+   --  Add a package name in the Package_Name list, extending it, if necessary
+
    function Name_Id_Of (Name : String) return Name_Id;
    --  Returns the Name_Id for Name in lower case
 
+   ----------------------
+   -- Add_Package_Name --
+   ----------------------
+
+   procedure Add_Package_Name (Name : String) is
+   begin
+      if Last_Package_Name = Package_Names'Last then
+         declare
+            New_List : constant Strings.String_List_Access :=
+                         new Strings.String_List (1 .. Package_Names'Last * 2);
+         begin
+            New_List (Package_Names'Range) := Package_Names.all;
+            Package_Names := New_List;
+         end;
+      end if;
+
+      Last_Package_Name := Last_Package_Name + 1;
+      Package_Names (Last_Package_Name) := new String'(Name);
+   end Add_Package_Name;
+
    -----------------------
    -- Attribute_Kind_Of --
    -----------------------
@@ -272,10 +445,12 @@ package body Prj.Attr is
       Is_An_Attribute   : Boolean           := False;
       Var_Kind          : Variable_Kind     := Undefined;
       Optional_Index    : Boolean           := False;
-      Attr_Kind            : Attribute_Kind := Single;
+      Attr_Kind         : Attribute_Kind    := Single;
       Package_Name      : Name_Id           := No_Name;
       Attribute_Name    : Name_Id           := No_Name;
       First_Attribute   : Attr_Node_Id      := Attr.First_Attribute;
+      Read_Only         : Boolean;
+      Others_Allowed    : Boolean;
 
       function Attribute_Location return String;
       --  Returns a string depending if we are in the project level attributes
@@ -329,9 +504,9 @@ package body Prj.Attr is
 
                for Index in First_Package .. Package_Attributes.Last loop
                   if Package_Name = Package_Attributes.Table (Index).Name then
-                     Osint.Fail ("duplicate name """,
-                           Initialization_Data (Start .. Finish - 1),
-                           """ in predefined packages.");
+                     Osint.Fail ("duplicate name """
+                                 & Initialization_Data (Start .. Finish - 1)
+                                 & """ in predefined packages.");
                   end if;
                end loop;
 
@@ -340,11 +515,13 @@ package body Prj.Attr is
                Package_Attributes.Increment_Last;
                Current_Package := Package_Attributes.Last;
                Package_Attributes.Table (Current_Package) :=
-                 (Name            => Package_Name,
-                  Known           => True,
-                  First_Attribute => Empty_Attr);
+                 (Name             => Package_Name,
+                  Known            => True,
+                  First_Attribute  => Empty_Attr);
                Start := Finish + 1;
 
+               Add_Package_Name (Get_Name_String (Package_Name));
+
             when 'S' =>
                Var_Kind       := Single;
                Optional_Index := False;
@@ -400,6 +577,19 @@ package body Prj.Attr is
             end case;
 
             Start := Start + 1;
+
+            Read_Only := False;
+            Others_Allowed := False;
+
+            if Initialization_Data (Start) = 'R' then
+               Read_Only := True;
+               Start := Start + 1;
+
+            elsif Initialization_Data (Start) = 'O' then
+               Others_Allowed := True;
+               Start := Start + 1;
+            end if;
+
             Finish := Start;
 
             while Initialization_Data (Finish) /= '#' loop
@@ -423,9 +613,9 @@ package body Prj.Attr is
 
                for Index in First_Attribute .. Attrs.Last - 1 loop
                   if Attribute_Name = Attrs.Table (Index).Name then
-                     Osint.Fail ("duplicate attribute """,
-                           Initialization_Data (Start .. Finish - 1),
-                           """ in " & Attribute_Location);
+                     Osint.Fail ("duplicate attribute """
+                                 & Initialization_Data (Start .. Finish - 1)
+                                 & """ in " & Attribute_Location);
                   end if;
                end loop;
 
@@ -439,6 +629,8 @@ package body Prj.Attr is
                Var_Kind       => Var_Kind,
                Optional_Index => Optional_Index,
                Attr_Kind      => Attr_Kind,
+               Read_Only      => Read_Only,
+               Others_Allowed => Others_Allowed,
                Next           => Empty_Attr);
             Start := Finish + 1;
          end if;
@@ -447,6 +639,15 @@ package body Prj.Attr is
       Initialized := True;
    end Initialize;
 
+   ------------------
+   -- Is_Read_Only --
+   ------------------
+
+   function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean is
+   begin
+      return Attrs.Table (Attribute.Value).Read_Only;
+   end Is_Read_Only;
+
    ----------------
    -- Name_Id_Of --
    ----------------
@@ -487,6 +688,26 @@ package body Prj.Attr is
       end if;
    end Optional_Index_Of;
 
+   function Others_Allowed_For
+     (Attribute : Attribute_Node_Id) return Boolean
+   is
+   begin
+      if Attribute = Empty_Attribute then
+         return False;
+      else
+         return Attrs.Table (Attribute.Value).Others_Allowed;
+      end if;
+   end Others_Allowed_For;
+
+   -----------------------
+   -- Package_Name_List --
+   -----------------------
+
+   function Package_Name_List return Strings.String_List is
+   begin
+      return Package_Names (1 .. Last_Package_Name);
+   end Package_Name_List;
+
    ------------------------
    -- Package_Node_Id_Of --
    ------------------------
@@ -495,7 +716,11 @@ package body Prj.Attr is
    begin
       for Index in Package_Attributes.First .. Package_Attributes.Last loop
          if Package_Attributes.Table (Index).Name = Name then
-            return (Value => Index);
+            if Package_Attributes.Table (Index).Known then
+               return (Value => Index);
+            else
+               return Unknown_Package;
+            end if;
          end if;
       end loop;
 
@@ -528,8 +753,9 @@ package body Prj.Attr is
       end if;
 
       if In_Package = Empty_Package then
-         Fail ("attempt to add attribute """, Name,
-               """ to an undefined package");
+         Fail ("attempt to add attribute """
+               & Name
+               & """ to an undefined package");
          raise Project_Error;
       end if;
 
@@ -543,11 +769,12 @@ package body Prj.Attr is
       Curr_Attr := First_Attr;
       while Curr_Attr /= Empty_Attr loop
          if Attrs.Table (Curr_Attr).Name = Attr_Name then
-            Fail ("duplicate attribute name """, Name,
-                  """ in package """ &
-                  Get_Name_String
-                    (Package_Attributes.Table (In_Package.Value).Name) &
-                  """");
+            Fail ("duplicate attribute name """
+                  & Name
+                  & """ in package """
+                  & Get_Name_String
+                     (Package_Attributes.Table (In_Package.Value).Name)
+                  & """");
             raise Project_Error;
          end if;
 
@@ -580,7 +807,10 @@ package body Prj.Attr is
          Var_Kind       => Var_Kind,
          Optional_Index => Opt_Index,
          Attr_Kind      => Real_Attr_Kind,
+         Read_Only      => False,
+         Others_Allowed => False,
          Next           => First_Attr);
+
       Package_Attributes.Table (In_Package.Value).First_Attribute :=
         Attrs.Last;
    end Register_New_Attribute;
@@ -603,8 +833,9 @@ package body Prj.Attr is
 
       for Index in Package_Attributes.First .. Package_Attributes.Last loop
          if Package_Attributes.Table (Index).Name = Pkg_Name then
-            Fail ("cannot register a package with a non unique name""",
-                  Name, """");
+            Fail ("cannot register a package with a non unique name"""
+                  & Name
+                  & """");
             Id := Empty_Package;
             return;
          end if;
@@ -613,7 +844,11 @@ package body Prj.Attr is
       Package_Attributes.Increment_Last;
       Id := (Value => Package_Attributes.Last);
       Package_Attributes.Table (Package_Attributes.Last) :=
-        (Name => Pkg_Name, Known => True, First_Attribute => Empty_Attr);
+        (Name             => Pkg_Name,
+         Known            => True,
+         First_Attribute  => Empty_Attr);
+
+      Add_Package_Name (Get_Name_String (Pkg_Name));
    end Register_New_Package;
 
    procedure Register_New_Package
@@ -636,8 +871,9 @@ package body Prj.Attr is
 
       for Index in Package_Attributes.First .. Package_Attributes.Last loop
          if Package_Attributes.Table (Index).Name = Pkg_Name then
-            Fail ("cannot register a package with a non unique name""",
-                  Name, """");
+            Fail ("cannot register a package with a non unique name"""
+                  & Name
+                  & """");
             raise Project_Error;
          end if;
       end loop;
@@ -648,8 +884,11 @@ package body Prj.Attr is
          Curr_Attr := First_Attr;
          while Curr_Attr /= Empty_Attr loop
             if Attrs.Table (Curr_Attr).Name = Attr_Name then
-               Fail ("duplicate attribute name """, Attributes (Index).Name,
-                     """ in new package """ & Name & """");
+               Fail ("duplicate attribute name """
+                     & Attributes (Index).Name
+                     & """ in new package """
+                     & Name
+                     & """");
                raise Project_Error;
             end if;
 
@@ -680,13 +919,19 @@ package body Prj.Attr is
             Var_Kind       => Attributes (Index).Var_Kind,
             Optional_Index => Attributes (Index).Opt_Index,
             Attr_Kind      => Attr_Kind,
+            Read_Only      => False,
+            Others_Allowed => False,
             Next           => First_Attr);
          First_Attr := Attrs.Last;
       end loop;
 
       Package_Attributes.Increment_Last;
       Package_Attributes.Table (Package_Attributes.Last) :=
-        (Name => Pkg_Name, Known => True, First_Attribute => First_Attr);
+        (Name             => Pkg_Name,
+         Known            => True,
+         First_Attribute  => First_Attr);
+
+      Add_Package_Name (Get_Name_String (Pkg_Name));
    end Register_New_Package;
 
    ---------------------------