1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2012, 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 '#'
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' to indicate that the attribute is read-only
59 -- 'O' to indicate that others is allowed as an index for an associative
62 -- End is indicated by two consecutive '#'
64 Initialization_Data
: constant String :=
66 -- project level attributes
75 "SVexternally_built#" &
82 "Lainherit_source_path#" &
83 "LVexcluded_source_dirs#" &
84 "LVignore_source_sub_dirs#" &
89 "LVlocally_removed_files#" &
90 "LVexcluded_source_files#" &
91 "SVsource_list_file#" &
92 "SVexcluded_source_list_file#" &
95 -- Projects (in aggregate projects)
106 "SVlibrary_version#" &
107 "LVlibrary_interface#" &
108 "SVlibrary_standalone#" &
109 "LVlibrary_encapsulated_options#" &
110 "SVlibrary_encapsulated_supported#" &
111 "SVlibrary_auto_init#" &
112 "LVleading_library_options#" &
113 "LVlibrary_options#" &
114 "SVlibrary_src_dir#" &
115 "SVlibrary_ali_dir#" &
117 "SVlibrary_symbol_file#" &
118 "SVlibrary_symbol_policy#" &
119 "SVlibrary_reference_symbol_file#" &
121 -- Configuration - General
123 "SVdefault_language#" &
124 "LVrun_path_option#" &
125 "SVrun_path_origin#" &
126 "SVseparate_run_path_options#" &
127 "Satoolchain_version#" &
128 "Satoolchain_description#" &
129 "Saobject_generated#" &
130 "Saobjects_linked#" &
133 -- Configuration - Libraries
135 "SVlibrary_builder#" &
136 "SVlibrary_support#" &
138 -- Configuration - Archives
140 "LVarchive_builder#" &
141 "LVarchive_builder_append_option#" &
142 "LVarchive_indexer#" &
143 "SVarchive_suffix#" &
144 "LVlibrary_partial_linker#" &
146 -- Configuration - Shared libraries
148 "SVshared_library_prefix#" &
149 "SVshared_library_suffix#" &
150 "SVsymbolic_link_supported#" &
151 "SVlibrary_major_minor_id_supported#" &
152 "SVlibrary_auto_init_supported#" &
153 "LVshared_library_minimum_switches#" &
154 "LVlibrary_version_switches#" &
155 "SVlibrary_install_name_option#" &
156 "Saruntime_library_dir#" &
157 "Saruntime_source_dir#" &
160 -- Some attributes are obsolescent, and renamed in the tree (see
161 -- Prj.Dect.Rename_Obsolescent_Attributes).
164 "Saspecification_suffix#" & -- Always renamed to "spec_suffix" in tree
166 "Saimplementation_suffix#" & -- Always renamed to "body_suffix" in tree
168 "SVseparate_suffix#" &
170 "SVdot_replacement#" &
171 "saspecification#" & -- Always renamed to "spec" in project tree
173 "saimplementation#" & -- Always renamed to "body" in project tree
175 "Laspecification_exceptions#" &
176 "Laimplementation_exceptions#" &
181 "Ladefault_switches#" &
183 "SVlocal_configuration_pragmas#" &
184 "Salocal_config_file#" &
186 -- Configuration - Compiling
190 "Sadependency_kind#" &
191 "Larequired_switches#" &
192 "Laleading_required_switches#" &
193 "Latrailing_required_switches#" &
196 "Lasource_file_switches#" &
197 "Saobject_file_suffix#" &
198 "Laobject_file_switches#" &
199 "Lamulti_unit_switches#" &
200 "Samulti_unit_object_separator#" &
202 -- Configuration - Mapping files
204 "Lamapping_file_switches#" &
205 "Samapping_spec_suffix#" &
206 "Samapping_body_suffix#" &
208 -- Configuration - Config files
210 "Laconfig_file_switches#" &
211 "Saconfig_body_file_name#" &
212 "Saconfig_body_file_name_index#" &
213 "Saconfig_body_file_name_pattern#" &
214 "Saconfig_spec_file_name#" &
215 "Saconfig_spec_file_name_index#" &
216 "Saconfig_spec_file_name_pattern#" &
217 "Saconfig_file_unique#" &
219 -- Configuration - Dependencies
221 "Ladependency_switches#" &
222 "Ladependency_driver#" &
224 -- Configuration - Search paths
226 "Lainclude_switches#" &
228 "Sainclude_path_file#" &
229 "Laobject_path_switches#" &
234 "Ladefault_switches#" &
236 "Lcglobal_compilation_switches#" &
238 "SVexecutable_suffix#" &
239 "SVglobal_configuration_pragmas#" &
240 "Saglobal_config_file#" &
250 "Ladefault_switches#" &
253 -- Configuration - Binding
256 "Larequired_switches#" &
259 "Saobjects_path_file#" &
264 "LVrequired_switches#" &
265 "Ladefault_switches#" &
266 "LcOleading_switches#" &
268 "LVlinker_options#" &
269 "SVmap_file_option#" &
271 -- Configuration - Linking
274 "LVexecutable_switch#" &
275 "SVlib_dir_switch#" &
276 "SVlib_name_switch#" &
278 -- Configuration - Response files
280 "SVmax_command_line_length#" &
281 "SVresponse_file_format#" &
282 "LVresponse_file_switches#" &
288 "Lasource_artifact_extensions#" &
289 "Laobject_artifact_extensions#" &
291 -- package Cross_Reference
293 "Pcross_reference#" &
294 "Ladefault_switches#" &
300 "Ladefault_switches#" &
303 -- package Pretty_Printer
306 "Ladefault_switches#" &
312 "Ladefault_switches#" &
318 "Ladefault_switches#" &
321 -- package Synchronize
324 "Ladefault_switches#" &
330 "Ladefault_switches#" &
336 "Ladefault_switches#" &
342 "Ladefault_switches#" &
345 "SVcommunication_protocol#" &
346 "Sacompiler_command#" &
347 "SVdebugger_command#" &
350 "SVvcs_file_check#" &
352 "SVdocumentation_dir#" &
358 "SVsources_subdir#" &
361 "SVproject_subdir#" &
371 Initialized
: Boolean := False;
372 -- A flag to avoid multiple initialization
374 Package_Names
: String_List_Access
:= new Strings
.String_List
(1 .. 20);
375 Last_Package_Name
: Natural := 0;
376 -- Package_Names (1 .. Last_Package_Name) contains the list of the known
377 -- package names, coming from the Initialization_Data string or from
378 -- calls to one of the two procedures Register_New_Package.
380 procedure Add_Package_Name
(Name
: String);
381 -- Add a package name in the Package_Name list, extending it, if necessary
383 function Name_Id_Of
(Name
: String) return Name_Id
;
384 -- Returns the Name_Id for Name in lower case
386 ----------------------
387 -- Add_Package_Name --
388 ----------------------
390 procedure Add_Package_Name
(Name
: String) is
392 if Last_Package_Name
= Package_Names
'Last then
394 New_List
: constant Strings
.String_List_Access
:=
395 new Strings
.String_List
(1 .. Package_Names
'Last * 2);
397 New_List
(Package_Names
'Range) := Package_Names
.all;
398 Package_Names
:= New_List
;
402 Last_Package_Name
:= Last_Package_Name
+ 1;
403 Package_Names
(Last_Package_Name
) := new String'(Name);
404 end Add_Package_Name;
406 -----------------------
407 -- Attribute_Kind_Of --
408 -----------------------
410 function Attribute_Kind_Of
411 (Attribute : Attribute_Node_Id) return Attribute_Kind
414 if Attribute = Empty_Attribute then
417 return Attrs.Table (Attribute.Value).Attr_Kind;
419 end Attribute_Kind_Of;
421 -----------------------
422 -- Attribute_Name_Of --
423 -----------------------
425 function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id is
427 if Attribute = Empty_Attribute then
430 return Attrs.Table (Attribute.Value).Name;
432 end Attribute_Name_Of;
434 --------------------------
435 -- Attribute_Node_Id_Of --
436 --------------------------
438 function Attribute_Node_Id_Of
440 Starting_At : Attribute_Node_Id) return Attribute_Node_Id
442 Id : Attr_Node_Id := Starting_At.Value;
445 while Id /= Empty_Attr
446 and then Attrs.Table (Id).Name /= Name
448 Id := Attrs.Table (Id).Next;
451 return (Value => Id);
452 end Attribute_Node_Id_Of;
458 procedure Initialize is
459 Start : Positive := Initialization_Data'First;
460 Finish : Positive := Start;
461 Current_Package : Pkg_Node_Id := Empty_Pkg;
462 Current_Attribute : Attr_Node_Id := Empty_Attr;
463 Is_An_Attribute : Boolean := False;
464 Var_Kind : Variable_Kind := Undefined;
465 Optional_Index : Boolean := False;
466 Attr_Kind : Attribute_Kind := Single;
467 Package_Name : Name_Id := No_Name;
468 Attribute_Name : Name_Id := No_Name;
469 First_Attribute : Attr_Node_Id := Attr.First_Attribute;
471 Others_Allowed : Boolean;
473 function Attribute_Location return String;
474 -- Returns a string depending if we are in the project level attributes
475 -- or in the attributes of a package.
477 ------------------------
478 -- Attribute_Location --
479 ------------------------
481 function Attribute_Location return String is
483 if Package_Name = No_Name then
484 return "project level attributes";
487 return "attribute of package """ &
488 Get_Name_String (Package_Name) & """";
490 end Attribute_Location;
492 -- Start of processing for Initialize
495 -- Don't allow Initialize action to be repeated
501 -- Make sure the two tables are empty
504 Package_Attributes.Init;
506 while Initialization_Data (Start) /= '#
' loop
507 Is_An_Attribute := True;
508 case Initialization_Data (Start) is
511 -- New allowed package
516 while Initialization_Data (Finish) /= '#
' loop
517 Finish := Finish + 1;
521 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
523 for Index in First_Package .. Package_Attributes.Last loop
524 if Package_Name = Package_Attributes.Table (Index).Name then
525 Osint.Fail ("duplicate name """
526 & Initialization_Data (Start .. Finish - 1)
527 & """ in predefined packages.");
531 Is_An_Attribute := False;
532 Current_Attribute := Empty_Attr;
533 Package_Attributes.Increment_Last;
534 Current_Package := Package_Attributes.Last;
535 Package_Attributes.Table (Current_Package) :=
536 (Name => Package_Name,
538 First_Attribute => Empty_Attr);
541 Add_Package_Name (Get_Name_String (Package_Name));
545 Optional_Index := False;
549 Optional_Index := True;
553 Optional_Index := False;
557 Optional_Index := True;
563 if Is_An_Attribute then
568 case Initialization_Data (Start) is
573 Attr_Kind := Associative_Array;
576 Attr_Kind := Case_Insensitive_Associative_Array;
579 if Osint.File_Names_Case_Sensitive then
580 Attr_Kind := Associative_Array;
582 Attr_Kind := Case_Insensitive_Associative_Array;
586 if Osint.File_Names_Case_Sensitive then
587 Attr_Kind := Optional_Index_Associative_Array;
590 Optional_Index_Case_Insensitive_Associative_Array;
600 Others_Allowed := False;
602 if Initialization_Data (Start) = 'R
' then
606 elsif Initialization_Data (Start) = 'O
' then
607 Others_Allowed := True;
613 while Initialization_Data (Finish) /= '#
' loop
614 Finish := Finish + 1;
618 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
619 Attrs.Increment_Last;
621 if Current_Attribute = Empty_Attr then
622 First_Attribute := Attrs.Last;
624 if Current_Package /= Empty_Pkg then
625 Package_Attributes.Table (Current_Package).First_Attribute
630 -- Check that there are no duplicate attributes
632 for Index in First_Attribute .. Attrs.Last - 1 loop
633 if Attribute_Name = Attrs.Table (Index).Name then
634 Osint.Fail ("duplicate attribute """
635 & Initialization_Data (Start .. Finish - 1)
636 & """ in " & Attribute_Location);
640 Attrs.Table (Current_Attribute).Next :=
644 Current_Attribute := Attrs.Last;
645 Attrs.Table (Current_Attribute) :=
646 (Name => Attribute_Name,
647 Var_Kind => Var_Kind,
648 Optional_Index => Optional_Index,
649 Attr_Kind => Attr_Kind,
650 Read_Only => Read_Only,
651 Others_Allowed => Others_Allowed,
664 function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean is
666 return Attrs.Table (Attribute.Value).Read_Only;
673 function Name_Id_Of (Name : String) return Name_Id is
676 Add_Str_To_Name_Buffer (Name);
677 To_Lower (Name_Buffer (1 .. Name_Len));
685 function Next_Attribute
686 (After : Attribute_Node_Id) return Attribute_Node_Id
689 if After = Empty_Attribute then
690 return Empty_Attribute;
692 return (Value => Attrs.Table (After.Value).Next);
696 -----------------------
697 -- Optional_Index_Of --
698 -----------------------
700 function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean is
702 if Attribute = Empty_Attribute then
705 return Attrs.Table (Attribute.Value).Optional_Index;
707 end Optional_Index_Of;
709 function Others_Allowed_For
710 (Attribute : Attribute_Node_Id) return Boolean
713 if Attribute = Empty_Attribute then
716 return Attrs.Table (Attribute.Value).Others_Allowed;
718 end Others_Allowed_For;
720 -----------------------
721 -- Package_Name_List --
722 -----------------------
724 function Package_Name_List return Strings.String_List is
726 return Package_Names (1 .. Last_Package_Name);
727 end Package_Name_List;
729 ------------------------
730 -- Package_Node_Id_Of --
731 ------------------------
733 function Package_Node_Id_Of (Name : Name_Id) return Package_Node_Id is
735 for Index in Package_Attributes.First .. Package_Attributes.Last loop
736 if Package_Attributes.Table (Index).Name = Name then
737 if Package_Attributes.Table (Index).Known then
738 return (Value => Index);
740 return Unknown_Package;
745 -- If there is no package with this name, return Empty_Package
747 return Empty_Package;
748 end Package_Node_Id_Of;
750 ----------------------------
751 -- Register_New_Attribute --
752 ----------------------------
754 procedure Register_New_Attribute
756 In_Package : Package_Node_Id;
757 Attr_Kind : Defined_Attribute_Kind;
758 Var_Kind : Defined_Variable_Kind;
759 Index_Is_File_Name : Boolean := False;
760 Opt_Index : Boolean := False)
763 First_Attr : Attr_Node_Id := Empty_Attr;
764 Curr_Attr : Attr_Node_Id;
765 Real_Attr_Kind : Attribute_Kind;
768 if Name'Length = 0 then
769 Fail ("cannot register an attribute with no name");
773 if In_Package = Empty_Package then
774 Fail ("attempt to add attribute """
776 & """ to an undefined package");
780 Attr_Name := Name_Id_Of (Name);
783 Package_Attributes.Table (In_Package.Value).First_Attribute;
785 -- Check if attribute name is a duplicate
787 Curr_Attr := First_Attr;
788 while Curr_Attr /= Empty_Attr loop
789 if Attrs.Table (Curr_Attr).Name = Attr_Name then
790 Fail ("duplicate attribute name """
794 (Package_Attributes.Table (In_Package.Value).Name)
799 Curr_Attr := Attrs.Table (Curr_Attr).Next;
802 Real_Attr_Kind := Attr_Kind;
804 -- If Index_Is_File_Name, change the attribute kind if necessary
806 if Index_Is_File_Name and then not Osint.File_Names_Case_Sensitive then
808 when Associative_Array =>
809 Real_Attr_Kind := Case_Insensitive_Associative_Array;
811 when Optional_Index_Associative_Array =>
813 Optional_Index_Case_Insensitive_Associative_Array;
820 -- Add the new attribute
822 Attrs.Increment_Last;
823 Attrs.Table (Attrs.Last) :=
825 Var_Kind => Var_Kind,
826 Optional_Index => Opt_Index,
827 Attr_Kind => Real_Attr_Kind,
829 Others_Allowed => False,
832 Package_Attributes.Table (In_Package.Value).First_Attribute :=
834 end Register_New_Attribute;
836 --------------------------
837 -- Register_New_Package --
838 --------------------------
840 procedure Register_New_Package (Name : String; Id : out Package_Node_Id) is
844 if Name'Length = 0 then
845 Fail ("cannot register a package with no name");
850 Pkg_Name := Name_Id_Of (Name);
852 for Index in Package_Attributes.First .. Package_Attributes.Last loop
853 if Package_Attributes.Table (Index).Name = Pkg_Name then
854 Fail ("cannot register a package with a non unique name """
862 Package_Attributes.Increment_Last;
863 Id := (Value => Package_Attributes.Last);
864 Package_Attributes.Table (Package_Attributes.Last) :=
867 First_Attribute => Empty_Attr);
869 Add_Package_Name (Get_Name_String (Pkg_Name));
870 end Register_New_Package;
872 procedure Register_New_Package
874 Attributes : Attribute_Data_Array)
878 First_Attr : Attr_Node_Id := Empty_Attr;
879 Curr_Attr : Attr_Node_Id;
880 Attr_Kind : Attribute_Kind;
883 if Name'Length = 0 then
884 Fail ("cannot register a package with no name");
888 Pkg_Name := Name_Id_Of (Name);
890 for Index in Package_Attributes.First .. Package_Attributes.Last loop
891 if Package_Attributes.Table (Index).Name = Pkg_Name then
892 Fail ("cannot register a package with a non unique name """
899 for Index in Attributes'Range loop
900 Attr_Name := Name_Id_Of (Attributes (Index).Name);
902 Curr_Attr := First_Attr;
903 while Curr_Attr /= Empty_Attr loop
904 if Attrs.Table (Curr_Attr).Name = Attr_Name then
905 Fail ("duplicate attribute name """
906 & Attributes (Index).Name
907 & """ in new package """
913 Curr_Attr := Attrs.Table (Curr_Attr).Next;
916 Attr_Kind := Attributes (Index).Attr_Kind;
918 if Attributes (Index).Index_Is_File_Name
919 and then not Osint.File_Names_Case_Sensitive
922 when Associative_Array =>
923 Attr_Kind := Case_Insensitive_Associative_Array;
925 when Optional_Index_Associative_Array =>
927 Optional_Index_Case_Insensitive_Associative_Array;
934 Attrs.Increment_Last;
935 Attrs.Table (Attrs.Last) :=
937 Var_Kind => Attributes (Index).Var_Kind,
938 Optional_Index => Attributes (Index).Opt_Index,
939 Attr_Kind => Attr_Kind,
941 Others_Allowed => False,
943 First_Attr := Attrs.Last;
946 Package_Attributes.Increment_Last;
947 Package_Attributes.Table (Package_Attributes.Last) :=
950 First_Attribute => First_Attr);
952 Add_Package_Name (Get_Name_String (Pkg_Name));
953 end Register_New_Package;
955 ---------------------------
956 -- Set_Attribute_Kind_Of --
957 ---------------------------
959 procedure Set_Attribute_Kind_Of
960 (Attribute : Attribute_Node_Id;
964 if Attribute /= Empty_Attribute then
965 Attrs.Table (Attribute.Value).Attr_Kind := To;
967 end Set_Attribute_Kind_Of;
969 --------------------------
970 -- Set_Variable_Kind_Of --
971 --------------------------
973 procedure Set_Variable_Kind_Of
974 (Attribute : Attribute_Node_Id;
978 if Attribute /= Empty_Attribute then
979 Attrs.Table (Attribute.Value).Var_Kind := To;
981 end Set_Variable_Kind_Of;
983 ----------------------
984 -- Variable_Kind_Of --
985 ----------------------
987 function Variable_Kind_Of
988 (Attribute : Attribute_Node_Id) return Variable_Kind
991 if Attribute = Empty_Attribute then
994 return Attrs.Table (Attribute.Value).Var_Kind;
996 end Variable_Kind_Of;
998 ------------------------
999 -- First_Attribute_Of --
1000 ------------------------
1002 function First_Attribute_Of
1003 (Pkg : Package_Node_Id) return Attribute_Node_Id
1006 if Pkg = Empty_Package then
1007 return Empty_Attribute;
1010 (Value => Package_Attributes.Table (Pkg.Value).First_Attribute);
1012 end First_Attribute_Of;