1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2014, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with Prj
.Com
; use Prj
.Com
;
29 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
31 package body Prj
.Attr
is
35 -- Data for predefined attributes and packages
37 -- Names are in lower case and end with '#' or 'D'
39 -- Package names are preceded by 'P'
41 -- Attribute names are preceded by two or three letters:
43 -- The first letter is one of
45 -- 's' for Single with optional index
47 -- 'l' for List of strings with optional indexes
49 -- The second letter is one of
50 -- 'V' for single variable
51 -- 'A' for associative array
52 -- 'a' for case insensitive associative array
53 -- 'b' for associative array, case insensitive if file names are case
55 -- 'c' same as 'b', with optional index
57 -- The third optional letter is
58 -- 'R' the attribute is read-only
59 -- 'O' others is allowed as an index for an associative array
61 -- If the character after the name in lower case letter is a 'D' (for
62 -- default), then 'D' must be followed by an enumeration value of type
63 -- Attribute_Default_Value, followed by a '#'.
66 -- "SVobject_dirDdot_value#"
68 -- End is indicated by two consecutive '#'.
70 Initialization_Data
: constant String :=
72 -- project level attributes
81 "SVexternally_built#" &
85 "SVobject_dirDdot_value#" &
86 "SVexec_dirDobject_dir_value#" &
87 "LVsource_dirsDdot_value#" &
88 "Lainherit_source_path#" &
89 "LVexcluded_source_dirs#" &
90 "LVignore_source_sub_dirs#" &
95 "LVlocally_removed_files#" &
96 "LVexcluded_source_files#" &
97 "SVsource_list_file#" &
98 "SVexcluded_source_list_file#" &
101 -- Projects (in aggregate projects)
112 "SVlibrary_version#" &
113 "LVlibrary_interface#" &
114 "SVlibrary_standalone#" &
115 "LVlibrary_encapsulated_options#" &
116 "SVlibrary_encapsulated_supported#" &
117 "SVlibrary_auto_init#" &
118 "LVleading_library_options#" &
119 "LVlibrary_options#" &
120 "Lalibrary_rpath_options#" &
121 "SVlibrary_src_dir#" &
122 "SVlibrary_ali_dir#" &
124 "SVlibrary_symbol_file#" &
125 "SVlibrary_symbol_policy#" &
126 "SVlibrary_reference_symbol_file#" &
128 -- Configuration - General
130 "SVdefault_language#" &
131 "LVrun_path_option#" &
132 "SVrun_path_origin#" &
133 "SVseparate_run_path_options#" &
134 "Satoolchain_version#" &
135 "Satoolchain_description#" &
136 "Saobject_generated#" &
137 "Saobjects_linked#" &
138 "SVtargetDtarget_value#" &
139 "SaruntimeDruntime_value#" &
141 -- Configuration - Libraries
143 "SVlibrary_builder#" &
144 "SVlibrary_support#" &
146 -- Configuration - Archives
148 "LVarchive_builder#" &
149 "LVarchive_builder_append_option#" &
150 "LVarchive_indexer#" &
151 "SVarchive_suffix#" &
152 "LVlibrary_partial_linker#" &
154 -- Configuration - Shared libraries
156 "SVshared_library_prefix#" &
157 "SVshared_library_suffix#" &
158 "SVsymbolic_link_supported#" &
159 "SVlibrary_major_minor_id_supported#" &
160 "SVlibrary_auto_init_supported#" &
161 "LVshared_library_minimum_switches#" &
162 "LVlibrary_version_switches#" &
163 "SVlibrary_install_name_option#" &
164 "Saruntime_library_dir#" &
165 "Saruntime_source_dir#" &
168 -- Some attributes are obsolescent, and renamed in the tree (see
169 -- Prj.Dect.Rename_Obsolescent_Attributes).
172 "Saspecification_suffix#" & -- Always renamed to "spec_suffix" in tree
174 "Saimplementation_suffix#" & -- Always renamed to "body_suffix" in tree
176 "SVseparate_suffix#" &
178 "SVdot_replacement#" &
179 "saspecification#" & -- Always renamed to "spec" in project tree
181 "saimplementation#" & -- Always renamed to "body" in project tree
183 "Laspecification_exceptions#" &
184 "Laimplementation_exceptions#" &
189 "Ladefault_switches#" &
191 "SVlocal_configuration_pragmas#" &
192 "Salocal_config_file#" &
194 -- Configuration - Compiling
198 "Sadependency_kind#" &
199 "Larequired_switches#" &
200 "Laleading_required_switches#" &
201 "Latrailing_required_switches#" &
204 "Lasource_file_switches#" &
205 "Saobject_file_suffix#" &
206 "Laobject_file_switches#" &
207 "Lamulti_unit_switches#" &
208 "Samulti_unit_object_separator#" &
210 -- Configuration - Mapping files
212 "Lamapping_file_switches#" &
213 "Samapping_spec_suffix#" &
214 "Samapping_body_suffix#" &
216 -- Configuration - Config files
218 "Laconfig_file_switches#" &
219 "Saconfig_body_file_name#" &
220 "Saconfig_body_file_name_index#" &
221 "Saconfig_body_file_name_pattern#" &
222 "Saconfig_spec_file_name#" &
223 "Saconfig_spec_file_name_index#" &
224 "Saconfig_spec_file_name_pattern#" &
225 "Saconfig_file_unique#" &
227 -- Configuration - Dependencies
229 "Ladependency_switches#" &
230 "Ladependency_driver#" &
232 -- Configuration - Search paths
234 "Lainclude_switches#" &
236 "Sainclude_path_file#" &
237 "Laobject_path_switches#" &
242 "Ladefault_switches#" &
244 "Lcglobal_compilation_switches#" &
246 "SVexecutable_suffix#" &
247 "SVglobal_configuration_pragmas#" &
248 "Saglobal_config_file#" &
258 "Ladefault_switches#" &
261 -- Configuration - Binding
264 "Larequired_switches#" &
267 "Saobjects_path_file#" &
272 "LVrequired_switches#" &
273 "Ladefault_switches#" &
274 "LcOleading_switches#" &
276 "LcOtrailing_switches#" &
277 "LVlinker_options#" &
278 "SVmap_file_option#" &
280 -- Configuration - Linking
284 -- Configuration - Response files
286 "SVmax_command_line_length#" &
287 "SVresponse_file_format#" &
288 "LVresponse_file_switches#" &
294 "Lasource_artifact_extensions#" &
295 "Laobject_artifact_extensions#" &
296 "LVartifacts_in_exec_dir#" &
297 "LVartifacts_in_object_dir#" &
299 -- package Cross_Reference
301 "Pcross_reference#" &
302 "Ladefault_switches#" &
308 "Ladefault_switches#" &
311 -- package Pretty_Printer
314 "Ladefault_switches#" &
320 "Ladefault_switches#" &
326 "Ladefault_switches#" &
329 -- package Synchronize
332 "Ladefault_switches#" &
338 "Ladefault_switches#" &
344 "Ladefault_switches#" &
350 "Ladefault_switches#" &
353 "SVcommunication_protocol#" &
354 "Sacompiler_command#" &
355 "SVdebugger_command#" &
358 "SVvcs_file_check#" &
360 "SVdocumentation_dir#" &
366 "SVsources_subdir#" &
369 "SVproject_subdir#" &
377 "LVexcluded_patterns#" &
378 "LVincluded_patterns#" &
379 "LVincluded_artifact_patterns#" &
388 Initialized
: Boolean := False;
389 -- A flag to avoid multiple initialization
391 Package_Names
: String_List_Access
:= new Strings
.String_List
(1 .. 20);
392 Last_Package_Name
: Natural := 0;
393 -- Package_Names (1 .. Last_Package_Name) contains the list of the known
394 -- package names, coming from the Initialization_Data string or from
395 -- calls to one of the two procedures Register_New_Package.
397 procedure Add_Package_Name
(Name
: String);
398 -- Add a package name in the Package_Name list, extending it, if necessary
400 function Name_Id_Of
(Name
: String) return Name_Id
;
401 -- Returns the Name_Id for Name in lower case
403 ----------------------
404 -- Add_Package_Name --
405 ----------------------
407 procedure Add_Package_Name
(Name
: String) is
409 if Last_Package_Name
= Package_Names
'Last then
411 New_List
: constant Strings
.String_List_Access
:=
412 new Strings
.String_List
(1 .. Package_Names
'Last * 2);
414 New_List
(Package_Names
'Range) := Package_Names
.all;
415 Package_Names
:= New_List
;
419 Last_Package_Name
:= Last_Package_Name
+ 1;
420 Package_Names
(Last_Package_Name
) := new String'(Name);
421 end Add_Package_Name;
423 --------------------------
424 -- Attribute_Default_Of --
425 --------------------------
427 function Attribute_Default_Of
428 (Attribute : Attribute_Node_Id) return Attribute_Default_Value
431 if Attribute = Empty_Attribute then
434 return Attrs.Table (Attribute.Value).Default;
436 end Attribute_Default_Of;
438 -----------------------
439 -- Attribute_Kind_Of --
440 -----------------------
442 function Attribute_Kind_Of
443 (Attribute : Attribute_Node_Id) return Attribute_Kind
446 if Attribute = Empty_Attribute then
449 return Attrs.Table (Attribute.Value).Attr_Kind;
451 end Attribute_Kind_Of;
453 -----------------------
454 -- Attribute_Name_Of --
455 -----------------------
457 function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id is
459 if Attribute = Empty_Attribute then
462 return Attrs.Table (Attribute.Value).Name;
464 end Attribute_Name_Of;
466 --------------------------
467 -- Attribute_Node_Id_Of --
468 --------------------------
470 function Attribute_Node_Id_Of
472 Starting_At : Attribute_Node_Id) return Attribute_Node_Id
474 Id : Attr_Node_Id := Starting_At.Value;
477 while Id /= Empty_Attr
478 and then Attrs.Table (Id).Name /= Name
480 Id := Attrs.Table (Id).Next;
483 return (Value => Id);
484 end Attribute_Node_Id_Of;
490 procedure Initialize is
491 Start : Positive := Initialization_Data'First;
492 Finish : Positive := Start;
493 Current_Package : Pkg_Node_Id := Empty_Pkg;
494 Current_Attribute : Attr_Node_Id := Empty_Attr;
495 Is_An_Attribute : Boolean := False;
496 Var_Kind : Variable_Kind := Undefined;
497 Optional_Index : Boolean := False;
498 Attr_Kind : Attribute_Kind := Single;
499 Package_Name : Name_Id := No_Name;
500 Attribute_Name : Name_Id := No_Name;
501 First_Attribute : Attr_Node_Id := Attr.First_Attribute;
503 Others_Allowed : Boolean;
504 Default : Attribute_Default_Value;
506 function Attribute_Location return String;
507 -- Returns a string depending if we are in the project level attributes
508 -- or in the attributes of a package.
510 ------------------------
511 -- Attribute_Location --
512 ------------------------
514 function Attribute_Location return String is
516 if Package_Name = No_Name then
517 return "project level attributes";
520 return "attribute of package """ &
521 Get_Name_String (Package_Name) & """";
523 end Attribute_Location;
525 -- Start of processing for Initialize
528 -- Don't allow Initialize action to be repeated
534 -- Make sure the two tables are empty
537 Package_Attributes.Init;
539 while Initialization_Data (Start) /= '#
' loop
540 Is_An_Attribute := True;
541 case Initialization_Data (Start) is
544 -- New allowed package
549 while Initialization_Data (Finish) /= '#
' loop
550 Finish := Finish + 1;
554 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
556 for Index in First_Package .. Package_Attributes.Last loop
557 if Package_Name = Package_Attributes.Table (Index).Name then
558 Osint.Fail ("duplicate name """
559 & Initialization_Data (Start .. Finish - 1)
560 & """ in predefined packages.");
564 Is_An_Attribute := False;
565 Current_Attribute := Empty_Attr;
566 Package_Attributes.Increment_Last;
567 Current_Package := Package_Attributes.Last;
568 Package_Attributes.Table (Current_Package) :=
569 (Name => Package_Name,
571 First_Attribute => Empty_Attr);
574 Add_Package_Name (Get_Name_String (Package_Name));
578 Optional_Index := False;
582 Optional_Index := True;
586 Optional_Index := False;
590 Optional_Index := True;
596 if Is_An_Attribute then
601 case Initialization_Data (Start) is
606 Attr_Kind := Associative_Array;
609 Attr_Kind := Case_Insensitive_Associative_Array;
612 if Osint.File_Names_Case_Sensitive then
613 Attr_Kind := Associative_Array;
615 Attr_Kind := Case_Insensitive_Associative_Array;
619 if Osint.File_Names_Case_Sensitive then
620 Attr_Kind := Optional_Index_Associative_Array;
623 Optional_Index_Case_Insensitive_Associative_Array;
633 Others_Allowed := False;
634 Default := Empty_Value;
636 if Initialization_Data (Start) = 'R
' then
638 Default := Read_Only_Value;
641 elsif Initialization_Data (Start) = 'O
' then
642 Others_Allowed := True;
648 while Initialization_Data (Finish) /= '#
'
650 Initialization_Data (Finish) /= 'D
'
652 Finish := Finish + 1;
656 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
658 if Initialization_Data (Finish) = 'D
' then
662 while Initialization_Data (Finish) /= '#
' loop
663 Finish := Finish + 1;
667 Default_Name : constant String :=
668 Initialization_Data (Start .. Finish - 1);
669 pragma Unsuppress (All_Checks);
671 Default := Attribute_Default_Value'Value (Default_Name);
673 when Constraint_Error =>
675 ("illegal default value """ &
677 """ for attribute " &
678 Get_Name_String (Attribute_Name));
682 Attrs.Increment_Last;
684 if Current_Attribute = Empty_Attr then
685 First_Attribute := Attrs.Last;
687 if Current_Package /= Empty_Pkg then
688 Package_Attributes.Table (Current_Package).First_Attribute
693 -- Check that there are no duplicate attributes
695 for Index in First_Attribute .. Attrs.Last - 1 loop
696 if Attribute_Name = Attrs.Table (Index).Name then
697 Osint.Fail ("duplicate attribute """
698 & Initialization_Data (Start .. Finish - 1)
699 & """ in " & Attribute_Location);
703 Attrs.Table (Current_Attribute).Next :=
707 Current_Attribute := Attrs.Last;
708 Attrs.Table (Current_Attribute) :=
709 (Name => Attribute_Name,
710 Var_Kind => Var_Kind,
711 Optional_Index => Optional_Index,
712 Attr_Kind => Attr_Kind,
713 Read_Only => Read_Only,
714 Others_Allowed => Others_Allowed,
728 function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean is
730 return Attrs.Table (Attribute.Value).Read_Only;
737 function Name_Id_Of (Name : String) return Name_Id is
740 Add_Str_To_Name_Buffer (Name);
741 To_Lower (Name_Buffer (1 .. Name_Len));
749 function Next_Attribute
750 (After : Attribute_Node_Id) return Attribute_Node_Id
753 if After = Empty_Attribute then
754 return Empty_Attribute;
756 return (Value => Attrs.Table (After.Value).Next);
760 -----------------------
761 -- Optional_Index_Of --
762 -----------------------
764 function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean is
766 if Attribute = Empty_Attribute then
769 return Attrs.Table (Attribute.Value).Optional_Index;
771 end Optional_Index_Of;
773 function Others_Allowed_For
774 (Attribute : Attribute_Node_Id) return Boolean
777 if Attribute = Empty_Attribute then
780 return Attrs.Table (Attribute.Value).Others_Allowed;
782 end Others_Allowed_For;
784 -----------------------
785 -- Package_Name_List --
786 -----------------------
788 function Package_Name_List return Strings.String_List is
790 return Package_Names (1 .. Last_Package_Name);
791 end Package_Name_List;
793 ------------------------
794 -- Package_Node_Id_Of --
795 ------------------------
797 function Package_Node_Id_Of (Name : Name_Id) return Package_Node_Id is
799 for Index in Package_Attributes.First .. Package_Attributes.Last loop
800 if Package_Attributes.Table (Index).Name = Name then
801 if Package_Attributes.Table (Index).Known then
802 return (Value => Index);
804 return Unknown_Package;
809 -- If there is no package with this name, return Empty_Package
811 return Empty_Package;
812 end Package_Node_Id_Of;
814 ----------------------------
815 -- Register_New_Attribute --
816 ----------------------------
818 procedure Register_New_Attribute
820 In_Package : Package_Node_Id;
821 Attr_Kind : Defined_Attribute_Kind;
822 Var_Kind : Defined_Variable_Kind;
823 Index_Is_File_Name : Boolean := False;
824 Opt_Index : Boolean := False;
825 Default : Attribute_Default_Value := Empty_Value)
828 First_Attr : Attr_Node_Id := Empty_Attr;
829 Curr_Attr : Attr_Node_Id;
830 Real_Attr_Kind : Attribute_Kind;
833 if Name'Length = 0 then
834 Fail ("cannot register an attribute with no name");
838 if In_Package = Empty_Package then
839 Fail ("attempt to add attribute """
841 & """ to an undefined package");
845 Attr_Name := Name_Id_Of (Name);
848 Package_Attributes.Table (In_Package.Value).First_Attribute;
850 -- Check if attribute name is a duplicate
852 Curr_Attr := First_Attr;
853 while Curr_Attr /= Empty_Attr loop
854 if Attrs.Table (Curr_Attr).Name = Attr_Name then
855 Fail ("duplicate attribute name """
859 (Package_Attributes.Table (In_Package.Value).Name)
864 Curr_Attr := Attrs.Table (Curr_Attr).Next;
867 Real_Attr_Kind := Attr_Kind;
869 -- If Index_Is_File_Name, change the attribute kind if necessary
871 if Index_Is_File_Name and then not Osint.File_Names_Case_Sensitive then
873 when Associative_Array =>
874 Real_Attr_Kind := Case_Insensitive_Associative_Array;
876 when Optional_Index_Associative_Array =>
878 Optional_Index_Case_Insensitive_Associative_Array;
885 -- Add the new attribute
887 Attrs.Increment_Last;
888 Attrs.Table (Attrs.Last) :=
890 Var_Kind => Var_Kind,
891 Optional_Index => Opt_Index,
892 Attr_Kind => Real_Attr_Kind,
894 Others_Allowed => False,
898 Package_Attributes.Table (In_Package.Value).First_Attribute :=
900 end Register_New_Attribute;
902 --------------------------
903 -- Register_New_Package --
904 --------------------------
906 procedure Register_New_Package (Name : String; Id : out Package_Node_Id) is
908 Found : Boolean := False;
911 if Name'Length = 0 then
912 Fail ("cannot register a package with no name");
917 Pkg_Name := Name_Id_Of (Name);
919 for Index in Package_Attributes.First .. Package_Attributes.Last loop
920 if Package_Attributes.Table (Index).Name = Pkg_Name then
921 if Package_Attributes.Table (Index).Known then
922 Fail ("cannot register a package with a non unique name """
930 Id := (Value => Index);
937 Package_Attributes.Increment_Last;
938 Id := (Value => Package_Attributes.Last);
941 Package_Attributes.Table (Id.Value) :=
944 First_Attribute => Empty_Attr);
946 Add_Package_Name (Get_Name_String (Pkg_Name));
947 end Register_New_Package;
949 procedure Register_New_Package
951 Attributes : Attribute_Data_Array)
955 First_Attr : Attr_Node_Id := Empty_Attr;
956 Curr_Attr : Attr_Node_Id;
957 Attr_Kind : Attribute_Kind;
960 if Name'Length = 0 then
961 Fail ("cannot register a package with no name");
965 Pkg_Name := Name_Id_Of (Name);
967 for Index in Package_Attributes.First .. Package_Attributes.Last loop
968 if Package_Attributes.Table (Index).Name = Pkg_Name then
969 Fail ("cannot register a package with a non unique name """
976 for Index in Attributes'Range loop
977 Attr_Name := Name_Id_Of (Attributes (Index).Name);
979 Curr_Attr := First_Attr;
980 while Curr_Attr /= Empty_Attr loop
981 if Attrs.Table (Curr_Attr).Name = Attr_Name then
982 Fail ("duplicate attribute name """
983 & Attributes (Index).Name
984 & """ in new package """
990 Curr_Attr := Attrs.Table (Curr_Attr).Next;
993 Attr_Kind := Attributes (Index).Attr_Kind;
995 if Attributes (Index).Index_Is_File_Name
996 and then not Osint.File_Names_Case_Sensitive
999 when Associative_Array =>
1000 Attr_Kind := Case_Insensitive_Associative_Array;
1002 when Optional_Index_Associative_Array =>
1004 Optional_Index_Case_Insensitive_Associative_Array;
1011 Attrs.Increment_Last;
1012 Attrs.Table (Attrs.Last) :=
1014 Var_Kind => Attributes (Index).Var_Kind,
1015 Optional_Index => Attributes (Index).Opt_Index,
1016 Attr_Kind => Attr_Kind,
1018 Others_Allowed => False,
1019 Default => Attributes (Index).Default,
1020 Next => First_Attr);
1021 First_Attr := Attrs.Last;
1024 Package_Attributes.Increment_Last;
1025 Package_Attributes.Table (Package_Attributes.Last) :=
1028 First_Attribute => First_Attr);
1030 Add_Package_Name (Get_Name_String (Pkg_Name));
1031 end Register_New_Package;
1033 ---------------------------
1034 -- Set_Attribute_Kind_Of --
1035 ---------------------------
1037 procedure Set_Attribute_Kind_Of
1038 (Attribute : Attribute_Node_Id;
1039 To : Attribute_Kind)
1042 if Attribute /= Empty_Attribute then
1043 Attrs.Table (Attribute.Value).Attr_Kind := To;
1045 end Set_Attribute_Kind_Of;
1047 --------------------------
1048 -- Set_Variable_Kind_Of --
1049 --------------------------
1051 procedure Set_Variable_Kind_Of
1052 (Attribute : Attribute_Node_Id;
1056 if Attribute /= Empty_Attribute then
1057 Attrs.Table (Attribute.Value).Var_Kind := To;
1059 end Set_Variable_Kind_Of;
1061 ----------------------
1062 -- Variable_Kind_Of --
1063 ----------------------
1065 function Variable_Kind_Of
1066 (Attribute : Attribute_Node_Id) return Variable_Kind
1069 if Attribute = Empty_Attribute then
1072 return Attrs.Table (Attribute.Value).Var_Kind;
1074 end Variable_Kind_Of;
1076 ------------------------
1077 -- First_Attribute_Of --
1078 ------------------------
1080 function First_Attribute_Of
1081 (Pkg : Package_Node_Id) return Attribute_Node_Id
1084 if Pkg = Empty_Package or else Pkg = Unknown_Package then
1085 return Empty_Attribute;
1088 (Value => Package_Attributes.Table (Pkg.Value).First_Attribute);
1090 end First_Attribute_Of;