1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2016, 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#" &
332 "Ladefault_switches#" &
338 "Ladefault_switches#" &
344 "Ladefault_switches#" &
347 "SVcommunication_protocol#" &
348 "Sacompiler_command#" &
349 "SVdebugger_command#" &
352 "SVvcs_file_check#" &
354 "SVdocumentation_dir#" &
360 "SVsources_subdir#" &
363 "SVproject_subdir#" &
366 "LArequired_artifacts#" &
374 "LVexcluded_patterns#" &
375 "LVincluded_patterns#" &
376 "LVincluded_artifact_patterns#" &
386 "SVoutput_directory#" &
387 "SVdatabase_directory#" &
388 "SVmessage_patterns#" &
389 "SVadditional_patterns#" &
391 "LVexcluded_source_files#" &
403 Initialized
: Boolean := False;
404 -- A flag to avoid multiple initialization
406 Package_Names
: String_List_Access
:= new Strings
.String_List
(1 .. 20);
407 Last_Package_Name
: Natural := 0;
408 -- Package_Names (1 .. Last_Package_Name) contains the list of the known
409 -- package names, coming from the Initialization_Data string or from
410 -- calls to one of the two procedures Register_New_Package.
412 procedure Add_Package_Name
(Name
: String);
413 -- Add a package name in the Package_Name list, extending it, if necessary
415 function Name_Id_Of
(Name
: String) return Name_Id
;
416 -- Returns the Name_Id for Name in lower case
418 ----------------------
419 -- Add_Package_Name --
420 ----------------------
422 procedure Add_Package_Name
(Name
: String) is
424 if Last_Package_Name
= Package_Names
'Last then
426 New_List
: constant Strings
.String_List_Access
:=
427 new Strings
.String_List
(1 .. Package_Names
'Last * 2);
429 New_List
(Package_Names
'Range) := Package_Names
.all;
430 Package_Names
:= New_List
;
434 Last_Package_Name
:= Last_Package_Name
+ 1;
435 Package_Names
(Last_Package_Name
) := new String'(Name);
436 end Add_Package_Name;
438 --------------------------
439 -- Attribute_Default_Of --
440 --------------------------
442 function Attribute_Default_Of
443 (Attribute : Attribute_Node_Id) return Attribute_Default_Value
446 if Attribute = Empty_Attribute then
449 return Attrs.Table (Attribute.Value).Default;
451 end Attribute_Default_Of;
453 -----------------------
454 -- Attribute_Kind_Of --
455 -----------------------
457 function Attribute_Kind_Of
458 (Attribute : Attribute_Node_Id) return Attribute_Kind
461 if Attribute = Empty_Attribute then
464 return Attrs.Table (Attribute.Value).Attr_Kind;
466 end Attribute_Kind_Of;
468 -----------------------
469 -- Attribute_Name_Of --
470 -----------------------
472 function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id is
474 if Attribute = Empty_Attribute then
477 return Attrs.Table (Attribute.Value).Name;
479 end Attribute_Name_Of;
481 --------------------------
482 -- Attribute_Node_Id_Of --
483 --------------------------
485 function Attribute_Node_Id_Of
487 Starting_At : Attribute_Node_Id) return Attribute_Node_Id
489 Id : Attr_Node_Id := Starting_At.Value;
492 while Id /= Empty_Attr
493 and then Attrs.Table (Id).Name /= Name
495 Id := Attrs.Table (Id).Next;
498 return (Value => Id);
499 end Attribute_Node_Id_Of;
505 procedure Initialize is
506 Start : Positive := Initialization_Data'First;
507 Finish : Positive := Start;
508 Current_Package : Pkg_Node_Id := Empty_Pkg;
509 Current_Attribute : Attr_Node_Id := Empty_Attr;
510 Is_An_Attribute : Boolean := False;
511 Var_Kind : Variable_Kind := Undefined;
512 Optional_Index : Boolean := False;
513 Attr_Kind : Attribute_Kind := Single;
514 Package_Name : Name_Id := No_Name;
515 Attribute_Name : Name_Id := No_Name;
516 First_Attribute : Attr_Node_Id := Attr.First_Attribute;
518 Others_Allowed : Boolean;
519 Default : Attribute_Default_Value;
521 function Attribute_Location return String;
522 -- Returns a string depending if we are in the project level attributes
523 -- or in the attributes of a package.
525 ------------------------
526 -- Attribute_Location --
527 ------------------------
529 function Attribute_Location return String is
531 if Package_Name = No_Name then
532 return "project level attributes";
535 return "attribute of package """ &
536 Get_Name_String (Package_Name) & """";
538 end Attribute_Location;
540 -- Start of processing for Initialize
543 -- Don't allow Initialize action to be repeated
549 -- Make sure the two tables are empty
552 Package_Attributes.Init;
554 while Initialization_Data (Start) /= '#
' loop
555 Is_An_Attribute := True;
556 case Initialization_Data (Start) is
559 -- New allowed package
564 while Initialization_Data (Finish) /= '#
' loop
565 Finish := Finish + 1;
569 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
571 for Index in First_Package .. Package_Attributes.Last loop
572 if Package_Name = Package_Attributes.Table (Index).Name then
573 Osint.Fail ("duplicate name """
574 & Initialization_Data (Start .. Finish - 1)
575 & """ in predefined packages.");
579 Is_An_Attribute := False;
580 Current_Attribute := Empty_Attr;
581 Package_Attributes.Increment_Last;
582 Current_Package := Package_Attributes.Last;
583 Package_Attributes.Table (Current_Package) :=
584 (Name => Package_Name,
586 First_Attribute => Empty_Attr);
589 Add_Package_Name (Get_Name_String (Package_Name));
593 Optional_Index := False;
597 Optional_Index := True;
601 Optional_Index := False;
605 Optional_Index := True;
611 if Is_An_Attribute then
616 case Initialization_Data (Start) is
621 Attr_Kind := Associative_Array;
624 Attr_Kind := Case_Insensitive_Associative_Array;
627 if Osint.File_Names_Case_Sensitive then
628 Attr_Kind := Associative_Array;
630 Attr_Kind := Case_Insensitive_Associative_Array;
634 if Osint.File_Names_Case_Sensitive then
635 Attr_Kind := Optional_Index_Associative_Array;
638 Optional_Index_Case_Insensitive_Associative_Array;
648 Others_Allowed := False;
649 Default := Empty_Value;
651 if Initialization_Data (Start) = 'R
' then
653 Default := Read_Only_Value;
656 elsif Initialization_Data (Start) = 'O
' then
657 Others_Allowed := True;
663 while Initialization_Data (Finish) /= '#
'
665 Initialization_Data (Finish) /= 'D
'
667 Finish := Finish + 1;
671 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
673 if Initialization_Data (Finish) = 'D
' then
677 while Initialization_Data (Finish) /= '#
' loop
678 Finish := Finish + 1;
682 Default_Name : constant String :=
683 Initialization_Data (Start .. Finish - 1);
684 pragma Unsuppress (All_Checks);
686 Default := Attribute_Default_Value'Value (Default_Name);
688 when Constraint_Error =>
690 ("illegal default value """ &
692 """ for attribute " &
693 Get_Name_String (Attribute_Name));
697 Attrs.Increment_Last;
699 if Current_Attribute = Empty_Attr then
700 First_Attribute := Attrs.Last;
702 if Current_Package /= Empty_Pkg then
703 Package_Attributes.Table (Current_Package).First_Attribute
708 -- Check that there are no duplicate attributes
710 for Index in First_Attribute .. Attrs.Last - 1 loop
711 if Attribute_Name = Attrs.Table (Index).Name then
712 Osint.Fail ("duplicate attribute """
713 & Initialization_Data (Start .. Finish - 1)
714 & """ in " & Attribute_Location);
718 Attrs.Table (Current_Attribute).Next :=
722 Current_Attribute := Attrs.Last;
723 Attrs.Table (Current_Attribute) :=
724 (Name => Attribute_Name,
725 Var_Kind => Var_Kind,
726 Optional_Index => Optional_Index,
727 Attr_Kind => Attr_Kind,
728 Read_Only => Read_Only,
729 Others_Allowed => Others_Allowed,
743 function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean is
745 return Attrs.Table (Attribute.Value).Read_Only;
752 function Name_Id_Of (Name : String) return Name_Id is
755 Add_Str_To_Name_Buffer (Name);
756 To_Lower (Name_Buffer (1 .. Name_Len));
764 function Next_Attribute
765 (After : Attribute_Node_Id) return Attribute_Node_Id
768 if After = Empty_Attribute then
769 return Empty_Attribute;
771 return (Value => Attrs.Table (After.Value).Next);
775 -----------------------
776 -- Optional_Index_Of --
777 -----------------------
779 function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean is
781 if Attribute = Empty_Attribute then
784 return Attrs.Table (Attribute.Value).Optional_Index;
786 end Optional_Index_Of;
788 function Others_Allowed_For
789 (Attribute : Attribute_Node_Id) return Boolean
792 if Attribute = Empty_Attribute then
795 return Attrs.Table (Attribute.Value).Others_Allowed;
797 end Others_Allowed_For;
799 -----------------------
800 -- Package_Name_List --
801 -----------------------
803 function Package_Name_List return Strings.String_List is
805 return Package_Names (1 .. Last_Package_Name);
806 end Package_Name_List;
808 ------------------------
809 -- Package_Node_Id_Of --
810 ------------------------
812 function Package_Node_Id_Of (Name : Name_Id) return Package_Node_Id is
814 for Index in Package_Attributes.First .. Package_Attributes.Last loop
815 if Package_Attributes.Table (Index).Name = Name then
816 if Package_Attributes.Table (Index).Known then
817 return (Value => Index);
819 return Unknown_Package;
824 -- If there is no package with this name, return Empty_Package
826 return Empty_Package;
827 end Package_Node_Id_Of;
829 ----------------------------
830 -- Register_New_Attribute --
831 ----------------------------
833 procedure Register_New_Attribute
835 In_Package : Package_Node_Id;
836 Attr_Kind : Defined_Attribute_Kind;
837 Var_Kind : Defined_Variable_Kind;
838 Index_Is_File_Name : Boolean := False;
839 Opt_Index : Boolean := False;
840 Default : Attribute_Default_Value := Empty_Value)
843 First_Attr : Attr_Node_Id := Empty_Attr;
844 Curr_Attr : Attr_Node_Id;
845 Real_Attr_Kind : Attribute_Kind;
848 if Name'Length = 0 then
849 Fail ("cannot register an attribute with no name");
853 if In_Package = Empty_Package then
854 Fail ("attempt to add attribute """
856 & """ to an undefined package");
860 Attr_Name := Name_Id_Of (Name);
863 Package_Attributes.Table (In_Package.Value).First_Attribute;
865 -- Check if attribute name is a duplicate
867 Curr_Attr := First_Attr;
868 while Curr_Attr /= Empty_Attr loop
869 if Attrs.Table (Curr_Attr).Name = Attr_Name then
870 Fail ("duplicate attribute name """
874 (Package_Attributes.Table (In_Package.Value).Name)
879 Curr_Attr := Attrs.Table (Curr_Attr).Next;
882 Real_Attr_Kind := Attr_Kind;
884 -- If Index_Is_File_Name, change the attribute kind if necessary
886 if Index_Is_File_Name and then not Osint.File_Names_Case_Sensitive then
888 when Associative_Array =>
889 Real_Attr_Kind := Case_Insensitive_Associative_Array;
891 when Optional_Index_Associative_Array =>
893 Optional_Index_Case_Insensitive_Associative_Array;
900 -- Add the new attribute
902 Attrs.Increment_Last;
903 Attrs.Table (Attrs.Last) :=
905 Var_Kind => Var_Kind,
906 Optional_Index => Opt_Index,
907 Attr_Kind => Real_Attr_Kind,
909 Others_Allowed => False,
913 Package_Attributes.Table (In_Package.Value).First_Attribute :=
915 end Register_New_Attribute;
917 --------------------------
918 -- Register_New_Package --
919 --------------------------
921 procedure Register_New_Package (Name : String; Id : out Package_Node_Id) is
923 Found : Boolean := False;
926 if Name'Length = 0 then
927 Fail ("cannot register a package with no name");
932 Pkg_Name := Name_Id_Of (Name);
934 for Index in Package_Attributes.First .. Package_Attributes.Last loop
935 if Package_Attributes.Table (Index).Name = Pkg_Name then
936 if Package_Attributes.Table (Index).Known then
937 Fail ("cannot register a package with a non unique name """
945 Id := (Value => Index);
952 Package_Attributes.Increment_Last;
953 Id := (Value => Package_Attributes.Last);
956 Package_Attributes.Table (Id.Value) :=
959 First_Attribute => Empty_Attr);
961 Add_Package_Name (Get_Name_String (Pkg_Name));
962 end Register_New_Package;
964 procedure Register_New_Package
966 Attributes : Attribute_Data_Array)
970 First_Attr : Attr_Node_Id := Empty_Attr;
971 Curr_Attr : Attr_Node_Id;
972 Attr_Kind : Attribute_Kind;
975 if Name'Length = 0 then
976 Fail ("cannot register a package with no name");
980 Pkg_Name := Name_Id_Of (Name);
982 for Index in Package_Attributes.First .. Package_Attributes.Last loop
983 if Package_Attributes.Table (Index).Name = Pkg_Name then
984 Fail ("cannot register a package with a non unique name """
991 for Index in Attributes'Range loop
992 Attr_Name := Name_Id_Of (Attributes (Index).Name);
994 Curr_Attr := First_Attr;
995 while Curr_Attr /= Empty_Attr loop
996 if Attrs.Table (Curr_Attr).Name = Attr_Name then
997 Fail ("duplicate attribute name """
998 & Attributes (Index).Name
999 & """ in new package """
1002 raise Project_Error;
1005 Curr_Attr := Attrs.Table (Curr_Attr).Next;
1008 Attr_Kind := Attributes (Index).Attr_Kind;
1010 if Attributes (Index).Index_Is_File_Name
1011 and then not Osint.File_Names_Case_Sensitive
1014 when Associative_Array =>
1015 Attr_Kind := Case_Insensitive_Associative_Array;
1017 when Optional_Index_Associative_Array =>
1019 Optional_Index_Case_Insensitive_Associative_Array;
1026 Attrs.Increment_Last;
1027 Attrs.Table (Attrs.Last) :=
1029 Var_Kind => Attributes (Index).Var_Kind,
1030 Optional_Index => Attributes (Index).Opt_Index,
1031 Attr_Kind => Attr_Kind,
1033 Others_Allowed => False,
1034 Default => Attributes (Index).Default,
1035 Next => First_Attr);
1036 First_Attr := Attrs.Last;
1039 Package_Attributes.Increment_Last;
1040 Package_Attributes.Table (Package_Attributes.Last) :=
1043 First_Attribute => First_Attr);
1045 Add_Package_Name (Get_Name_String (Pkg_Name));
1046 end Register_New_Package;
1048 ---------------------------
1049 -- Set_Attribute_Kind_Of --
1050 ---------------------------
1052 procedure Set_Attribute_Kind_Of
1053 (Attribute : Attribute_Node_Id;
1054 To : Attribute_Kind)
1057 if Attribute /= Empty_Attribute then
1058 Attrs.Table (Attribute.Value).Attr_Kind := To;
1060 end Set_Attribute_Kind_Of;
1062 --------------------------
1063 -- Set_Variable_Kind_Of --
1064 --------------------------
1066 procedure Set_Variable_Kind_Of
1067 (Attribute : Attribute_Node_Id;
1071 if Attribute /= Empty_Attribute then
1072 Attrs.Table (Attribute.Value).Var_Kind := To;
1074 end Set_Variable_Kind_Of;
1076 ----------------------
1077 -- Variable_Kind_Of --
1078 ----------------------
1080 function Variable_Kind_Of
1081 (Attribute : Attribute_Node_Id) return Variable_Kind
1084 if Attribute = Empty_Attribute then
1087 return Attrs.Table (Attribute.Value).Var_Kind;
1089 end Variable_Kind_Of;
1091 ------------------------
1092 -- First_Attribute_Of --
1093 ------------------------
1095 function First_Attribute_Of
1096 (Pkg : Package_Node_Id) return Attribute_Node_Id
1099 if Pkg = Empty_Package or else Pkg = Unknown_Package then
1100 return Empty_Attribute;
1103 (Value => Package_Attributes.Table (Pkg.Value).First_Attribute);
1105 end First_Attribute_Of;