1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2013, 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 "Lalibrary_rpath_options#" &
115 "SVlibrary_src_dir#" &
116 "SVlibrary_ali_dir#" &
118 "SVlibrary_symbol_file#" &
119 "SVlibrary_symbol_policy#" &
120 "SVlibrary_reference_symbol_file#" &
122 -- Configuration - General
124 "SVdefault_language#" &
125 "LVrun_path_option#" &
126 "SVrun_path_origin#" &
127 "SVseparate_run_path_options#" &
128 "Satoolchain_version#" &
129 "Satoolchain_description#" &
130 "Saobject_generated#" &
131 "Saobjects_linked#" &
134 -- Configuration - Libraries
136 "SVlibrary_builder#" &
137 "SVlibrary_support#" &
139 -- Configuration - Archives
141 "LVarchive_builder#" &
142 "LVarchive_builder_append_option#" &
143 "LVarchive_indexer#" &
144 "SVarchive_suffix#" &
145 "LVlibrary_partial_linker#" &
147 -- Configuration - Shared libraries
149 "SVshared_library_prefix#" &
150 "SVshared_library_suffix#" &
151 "SVsymbolic_link_supported#" &
152 "SVlibrary_major_minor_id_supported#" &
153 "SVlibrary_auto_init_supported#" &
154 "LVshared_library_minimum_switches#" &
155 "LVlibrary_version_switches#" &
156 "SVlibrary_install_name_option#" &
157 "Saruntime_library_dir#" &
158 "Saruntime_source_dir#" &
161 -- Some attributes are obsolescent, and renamed in the tree (see
162 -- Prj.Dect.Rename_Obsolescent_Attributes).
165 "Saspecification_suffix#" & -- Always renamed to "spec_suffix" in tree
167 "Saimplementation_suffix#" & -- Always renamed to "body_suffix" in tree
169 "SVseparate_suffix#" &
171 "SVdot_replacement#" &
172 "saspecification#" & -- Always renamed to "spec" in project tree
174 "saimplementation#" & -- Always renamed to "body" in project tree
176 "Laspecification_exceptions#" &
177 "Laimplementation_exceptions#" &
182 "Ladefault_switches#" &
184 "SVlocal_configuration_pragmas#" &
185 "Salocal_config_file#" &
187 -- Configuration - Compiling
191 "Sadependency_kind#" &
192 "Larequired_switches#" &
193 "Laleading_required_switches#" &
194 "Latrailing_required_switches#" &
197 "Lasource_file_switches#" &
198 "Saobject_file_suffix#" &
199 "Laobject_file_switches#" &
200 "Lamulti_unit_switches#" &
201 "Samulti_unit_object_separator#" &
203 -- Configuration - Mapping files
205 "Lamapping_file_switches#" &
206 "Samapping_spec_suffix#" &
207 "Samapping_body_suffix#" &
209 -- Configuration - Config files
211 "Laconfig_file_switches#" &
212 "Saconfig_body_file_name#" &
213 "Saconfig_body_file_name_index#" &
214 "Saconfig_body_file_name_pattern#" &
215 "Saconfig_spec_file_name#" &
216 "Saconfig_spec_file_name_index#" &
217 "Saconfig_spec_file_name_pattern#" &
218 "Saconfig_file_unique#" &
220 -- Configuration - Dependencies
222 "Ladependency_switches#" &
223 "Ladependency_driver#" &
225 -- Configuration - Search paths
227 "Lainclude_switches#" &
229 "Sainclude_path_file#" &
230 "Laobject_path_switches#" &
235 "Ladefault_switches#" &
237 "Lcglobal_compilation_switches#" &
239 "SVexecutable_suffix#" &
240 "SVglobal_configuration_pragmas#" &
241 "Saglobal_config_file#" &
251 "Ladefault_switches#" &
254 -- Configuration - Binding
257 "Larequired_switches#" &
260 "Saobjects_path_file#" &
265 "LVrequired_switches#" &
266 "Ladefault_switches#" &
267 "LcOleading_switches#" &
269 "LcOtrailing_switches#" &
270 "LVlinker_options#" &
271 "SVmap_file_option#" &
273 -- Configuration - Linking
276 "LVexecutable_switch#" &
277 "SVlib_dir_switch#" &
278 "SVlib_name_switch#" &
280 -- Configuration - Response files
282 "SVmax_command_line_length#" &
283 "SVresponse_file_format#" &
284 "LVresponse_file_switches#" &
290 "Lasource_artifact_extensions#" &
291 "Laobject_artifact_extensions#" &
292 "LVartifacts_in_exec_dir#" &
293 "LVartifacts_in_object_dir#" &
295 -- package Cross_Reference
297 "Pcross_reference#" &
298 "Ladefault_switches#" &
304 "Ladefault_switches#" &
307 -- package Pretty_Printer
310 "Ladefault_switches#" &
316 "Ladefault_switches#" &
322 "Ladefault_switches#" &
325 -- package Synchronize
328 "Ladefault_switches#" &
334 "Ladefault_switches#" &
340 "Ladefault_switches#" &
346 "Ladefault_switches#" &
349 "SVcommunication_protocol#" &
350 "Sacompiler_command#" &
351 "SVdebugger_command#" &
354 "SVvcs_file_check#" &
356 "SVdocumentation_dir#" &
362 "SVsources_subdir#" &
365 "SVproject_subdir#" &
373 "LVexcluded_patterns#" &
374 "LVincluded_patterns#" &
375 "LVincluded_artifact_patterns#" &
384 Initialized
: Boolean := False;
385 -- A flag to avoid multiple initialization
387 Package_Names
: String_List_Access
:= new Strings
.String_List
(1 .. 20);
388 Last_Package_Name
: Natural := 0;
389 -- Package_Names (1 .. Last_Package_Name) contains the list of the known
390 -- package names, coming from the Initialization_Data string or from
391 -- calls to one of the two procedures Register_New_Package.
393 procedure Add_Package_Name
(Name
: String);
394 -- Add a package name in the Package_Name list, extending it, if necessary
396 function Name_Id_Of
(Name
: String) return Name_Id
;
397 -- Returns the Name_Id for Name in lower case
399 ----------------------
400 -- Add_Package_Name --
401 ----------------------
403 procedure Add_Package_Name
(Name
: String) is
405 if Last_Package_Name
= Package_Names
'Last then
407 New_List
: constant Strings
.String_List_Access
:=
408 new Strings
.String_List
(1 .. Package_Names
'Last * 2);
410 New_List
(Package_Names
'Range) := Package_Names
.all;
411 Package_Names
:= New_List
;
415 Last_Package_Name
:= Last_Package_Name
+ 1;
416 Package_Names
(Last_Package_Name
) := new String'(Name);
417 end Add_Package_Name;
419 -----------------------
420 -- Attribute_Kind_Of --
421 -----------------------
423 function Attribute_Kind_Of
424 (Attribute : Attribute_Node_Id) return Attribute_Kind
427 if Attribute = Empty_Attribute then
430 return Attrs.Table (Attribute.Value).Attr_Kind;
432 end Attribute_Kind_Of;
434 -----------------------
435 -- Attribute_Name_Of --
436 -----------------------
438 function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id is
440 if Attribute = Empty_Attribute then
443 return Attrs.Table (Attribute.Value).Name;
445 end Attribute_Name_Of;
447 --------------------------
448 -- Attribute_Node_Id_Of --
449 --------------------------
451 function Attribute_Node_Id_Of
453 Starting_At : Attribute_Node_Id) return Attribute_Node_Id
455 Id : Attr_Node_Id := Starting_At.Value;
458 while Id /= Empty_Attr
459 and then Attrs.Table (Id).Name /= Name
461 Id := Attrs.Table (Id).Next;
464 return (Value => Id);
465 end Attribute_Node_Id_Of;
471 procedure Initialize is
472 Start : Positive := Initialization_Data'First;
473 Finish : Positive := Start;
474 Current_Package : Pkg_Node_Id := Empty_Pkg;
475 Current_Attribute : Attr_Node_Id := Empty_Attr;
476 Is_An_Attribute : Boolean := False;
477 Var_Kind : Variable_Kind := Undefined;
478 Optional_Index : Boolean := False;
479 Attr_Kind : Attribute_Kind := Single;
480 Package_Name : Name_Id := No_Name;
481 Attribute_Name : Name_Id := No_Name;
482 First_Attribute : Attr_Node_Id := Attr.First_Attribute;
484 Others_Allowed : Boolean;
486 function Attribute_Location return String;
487 -- Returns a string depending if we are in the project level attributes
488 -- or in the attributes of a package.
490 ------------------------
491 -- Attribute_Location --
492 ------------------------
494 function Attribute_Location return String is
496 if Package_Name = No_Name then
497 return "project level attributes";
500 return "attribute of package """ &
501 Get_Name_String (Package_Name) & """";
503 end Attribute_Location;
505 -- Start of processing for Initialize
508 -- Don't allow Initialize action to be repeated
514 -- Make sure the two tables are empty
517 Package_Attributes.Init;
519 while Initialization_Data (Start) /= '#
' loop
520 Is_An_Attribute := True;
521 case Initialization_Data (Start) is
524 -- New allowed package
529 while Initialization_Data (Finish) /= '#
' loop
530 Finish := Finish + 1;
534 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
536 for Index in First_Package .. Package_Attributes.Last loop
537 if Package_Name = Package_Attributes.Table (Index).Name then
538 Osint.Fail ("duplicate name """
539 & Initialization_Data (Start .. Finish - 1)
540 & """ in predefined packages.");
544 Is_An_Attribute := False;
545 Current_Attribute := Empty_Attr;
546 Package_Attributes.Increment_Last;
547 Current_Package := Package_Attributes.Last;
548 Package_Attributes.Table (Current_Package) :=
549 (Name => Package_Name,
551 First_Attribute => Empty_Attr);
554 Add_Package_Name (Get_Name_String (Package_Name));
558 Optional_Index := False;
562 Optional_Index := True;
566 Optional_Index := False;
570 Optional_Index := True;
576 if Is_An_Attribute then
581 case Initialization_Data (Start) is
586 Attr_Kind := Associative_Array;
589 Attr_Kind := Case_Insensitive_Associative_Array;
592 if Osint.File_Names_Case_Sensitive then
593 Attr_Kind := Associative_Array;
595 Attr_Kind := Case_Insensitive_Associative_Array;
599 if Osint.File_Names_Case_Sensitive then
600 Attr_Kind := Optional_Index_Associative_Array;
603 Optional_Index_Case_Insensitive_Associative_Array;
613 Others_Allowed := False;
615 if Initialization_Data (Start) = 'R
' then
619 elsif Initialization_Data (Start) = 'O
' then
620 Others_Allowed := True;
626 while Initialization_Data (Finish) /= '#
' loop
627 Finish := Finish + 1;
631 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
632 Attrs.Increment_Last;
634 if Current_Attribute = Empty_Attr then
635 First_Attribute := Attrs.Last;
637 if Current_Package /= Empty_Pkg then
638 Package_Attributes.Table (Current_Package).First_Attribute
643 -- Check that there are no duplicate attributes
645 for Index in First_Attribute .. Attrs.Last - 1 loop
646 if Attribute_Name = Attrs.Table (Index).Name then
647 Osint.Fail ("duplicate attribute """
648 & Initialization_Data (Start .. Finish - 1)
649 & """ in " & Attribute_Location);
653 Attrs.Table (Current_Attribute).Next :=
657 Current_Attribute := Attrs.Last;
658 Attrs.Table (Current_Attribute) :=
659 (Name => Attribute_Name,
660 Var_Kind => Var_Kind,
661 Optional_Index => Optional_Index,
662 Attr_Kind => Attr_Kind,
663 Read_Only => Read_Only,
664 Others_Allowed => Others_Allowed,
677 function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean is
679 return Attrs.Table (Attribute.Value).Read_Only;
686 function Name_Id_Of (Name : String) return Name_Id is
689 Add_Str_To_Name_Buffer (Name);
690 To_Lower (Name_Buffer (1 .. Name_Len));
698 function Next_Attribute
699 (After : Attribute_Node_Id) return Attribute_Node_Id
702 if After = Empty_Attribute then
703 return Empty_Attribute;
705 return (Value => Attrs.Table (After.Value).Next);
709 -----------------------
710 -- Optional_Index_Of --
711 -----------------------
713 function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean is
715 if Attribute = Empty_Attribute then
718 return Attrs.Table (Attribute.Value).Optional_Index;
720 end Optional_Index_Of;
722 function Others_Allowed_For
723 (Attribute : Attribute_Node_Id) return Boolean
726 if Attribute = Empty_Attribute then
729 return Attrs.Table (Attribute.Value).Others_Allowed;
731 end Others_Allowed_For;
733 -----------------------
734 -- Package_Name_List --
735 -----------------------
737 function Package_Name_List return Strings.String_List is
739 return Package_Names (1 .. Last_Package_Name);
740 end Package_Name_List;
742 ------------------------
743 -- Package_Node_Id_Of --
744 ------------------------
746 function Package_Node_Id_Of (Name : Name_Id) return Package_Node_Id is
748 for Index in Package_Attributes.First .. Package_Attributes.Last loop
749 if Package_Attributes.Table (Index).Name = Name then
750 if Package_Attributes.Table (Index).Known then
751 return (Value => Index);
753 return Unknown_Package;
758 -- If there is no package with this name, return Empty_Package
760 return Empty_Package;
761 end Package_Node_Id_Of;
763 ----------------------------
764 -- Register_New_Attribute --
765 ----------------------------
767 procedure Register_New_Attribute
769 In_Package : Package_Node_Id;
770 Attr_Kind : Defined_Attribute_Kind;
771 Var_Kind : Defined_Variable_Kind;
772 Index_Is_File_Name : Boolean := False;
773 Opt_Index : Boolean := False)
776 First_Attr : Attr_Node_Id := Empty_Attr;
777 Curr_Attr : Attr_Node_Id;
778 Real_Attr_Kind : Attribute_Kind;
781 if Name'Length = 0 then
782 Fail ("cannot register an attribute with no name");
786 if In_Package = Empty_Package then
787 Fail ("attempt to add attribute """
789 & """ to an undefined package");
793 Attr_Name := Name_Id_Of (Name);
796 Package_Attributes.Table (In_Package.Value).First_Attribute;
798 -- Check if attribute name is a duplicate
800 Curr_Attr := First_Attr;
801 while Curr_Attr /= Empty_Attr loop
802 if Attrs.Table (Curr_Attr).Name = Attr_Name then
803 Fail ("duplicate attribute name """
807 (Package_Attributes.Table (In_Package.Value).Name)
812 Curr_Attr := Attrs.Table (Curr_Attr).Next;
815 Real_Attr_Kind := Attr_Kind;
817 -- If Index_Is_File_Name, change the attribute kind if necessary
819 if Index_Is_File_Name and then not Osint.File_Names_Case_Sensitive then
821 when Associative_Array =>
822 Real_Attr_Kind := Case_Insensitive_Associative_Array;
824 when Optional_Index_Associative_Array =>
826 Optional_Index_Case_Insensitive_Associative_Array;
833 -- Add the new attribute
835 Attrs.Increment_Last;
836 Attrs.Table (Attrs.Last) :=
838 Var_Kind => Var_Kind,
839 Optional_Index => Opt_Index,
840 Attr_Kind => Real_Attr_Kind,
842 Others_Allowed => False,
845 Package_Attributes.Table (In_Package.Value).First_Attribute :=
847 end Register_New_Attribute;
849 --------------------------
850 -- Register_New_Package --
851 --------------------------
853 procedure Register_New_Package (Name : String; Id : out Package_Node_Id) is
857 if Name'Length = 0 then
858 Fail ("cannot register a package with no name");
863 Pkg_Name := Name_Id_Of (Name);
865 for Index in Package_Attributes.First .. Package_Attributes.Last loop
866 if Package_Attributes.Table (Index).Name = Pkg_Name then
867 Fail ("cannot register a package with a non unique name """
875 Package_Attributes.Increment_Last;
876 Id := (Value => Package_Attributes.Last);
877 Package_Attributes.Table (Package_Attributes.Last) :=
880 First_Attribute => Empty_Attr);
882 Add_Package_Name (Get_Name_String (Pkg_Name));
883 end Register_New_Package;
885 procedure Register_New_Package
887 Attributes : Attribute_Data_Array)
891 First_Attr : Attr_Node_Id := Empty_Attr;
892 Curr_Attr : Attr_Node_Id;
893 Attr_Kind : Attribute_Kind;
896 if Name'Length = 0 then
897 Fail ("cannot register a package with no name");
901 Pkg_Name := Name_Id_Of (Name);
903 for Index in Package_Attributes.First .. Package_Attributes.Last loop
904 if Package_Attributes.Table (Index).Name = Pkg_Name then
905 Fail ("cannot register a package with a non unique name """
912 for Index in Attributes'Range loop
913 Attr_Name := Name_Id_Of (Attributes (Index).Name);
915 Curr_Attr := First_Attr;
916 while Curr_Attr /= Empty_Attr loop
917 if Attrs.Table (Curr_Attr).Name = Attr_Name then
918 Fail ("duplicate attribute name """
919 & Attributes (Index).Name
920 & """ in new package """
926 Curr_Attr := Attrs.Table (Curr_Attr).Next;
929 Attr_Kind := Attributes (Index).Attr_Kind;
931 if Attributes (Index).Index_Is_File_Name
932 and then not Osint.File_Names_Case_Sensitive
935 when Associative_Array =>
936 Attr_Kind := Case_Insensitive_Associative_Array;
938 when Optional_Index_Associative_Array =>
940 Optional_Index_Case_Insensitive_Associative_Array;
947 Attrs.Increment_Last;
948 Attrs.Table (Attrs.Last) :=
950 Var_Kind => Attributes (Index).Var_Kind,
951 Optional_Index => Attributes (Index).Opt_Index,
952 Attr_Kind => Attr_Kind,
954 Others_Allowed => False,
956 First_Attr := Attrs.Last;
959 Package_Attributes.Increment_Last;
960 Package_Attributes.Table (Package_Attributes.Last) :=
963 First_Attribute => First_Attr);
965 Add_Package_Name (Get_Name_String (Pkg_Name));
966 end Register_New_Package;
968 ---------------------------
969 -- Set_Attribute_Kind_Of --
970 ---------------------------
972 procedure Set_Attribute_Kind_Of
973 (Attribute : Attribute_Node_Id;
977 if Attribute /= Empty_Attribute then
978 Attrs.Table (Attribute.Value).Attr_Kind := To;
980 end Set_Attribute_Kind_Of;
982 --------------------------
983 -- Set_Variable_Kind_Of --
984 --------------------------
986 procedure Set_Variable_Kind_Of
987 (Attribute : Attribute_Node_Id;
991 if Attribute /= Empty_Attribute then
992 Attrs.Table (Attribute.Value).Var_Kind := To;
994 end Set_Variable_Kind_Of;
996 ----------------------
997 -- Variable_Kind_Of --
998 ----------------------
1000 function Variable_Kind_Of
1001 (Attribute : Attribute_Node_Id) return Variable_Kind
1004 if Attribute = Empty_Attribute then
1007 return Attrs.Table (Attribute.Value).Var_Kind;
1009 end Variable_Kind_Of;
1011 ------------------------
1012 -- First_Attribute_Of --
1013 ------------------------
1015 function First_Attribute_Of
1016 (Pkg : Package_Node_Id) return Attribute_Node_Id
1019 if Pkg = Empty_Package or else Pkg = Unknown_Package then
1020 return Empty_Attribute;
1023 (Value => Package_Attributes.Table (Pkg.Value).First_Attribute);
1025 end First_Attribute_Of;