1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2010, 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#" &
88 "LVlocally_removed_files#" &
89 "LVexcluded_source_files#" &
90 "SVsource_list_file#" &
91 "SVexcluded_source_list_file#" &
99 "SVlibrary_version#" &
100 "LVlibrary_interface#" &
101 "SVlibrary_auto_init#" &
102 "LVlibrary_options#" &
103 "SVlibrary_src_dir#" &
104 "SVlibrary_ali_dir#" &
106 "SVlibrary_symbol_file#" &
107 "SVlibrary_symbol_policy#" &
108 "SVlibrary_reference_symbol_file#" &
110 -- Configuration - General
112 "SVdefault_language#" &
113 "LVrun_path_option#" &
114 "SVrun_path_origin#" &
115 "SVseparate_run_path_options#" &
116 "Satoolchain_version#" &
117 "Satoolchain_description#" &
118 "Saobject_generated#" &
119 "Saobjects_linked#" &
122 -- Configuration - Libraries
124 "SVlibrary_builder#" &
125 "SVlibrary_support#" &
127 -- Configuration - Archives
129 "LVarchive_builder#" &
130 "LVarchive_builder_append_option#" &
131 "LVarchive_indexer#" &
132 "SVarchive_suffix#" &
133 "LVlibrary_partial_linker#" &
135 -- Configuration - Shared libraries
137 "SVshared_library_prefix#" &
138 "SVshared_library_suffix#" &
139 "SVsymbolic_link_supported#" &
140 "SVlibrary_major_minor_id_supported#" &
141 "SVlibrary_auto_init_supported#" &
142 "LVshared_library_minimum_switches#" &
143 "LVlibrary_version_switches#" &
144 "SVlibrary_install_name_option#" &
145 "Saruntime_library_dir#" &
146 "Saruntime_source_dir#" &
151 "Saspecification_suffix#" &
153 "Saimplementation_suffix#" &
155 "SVseparate_suffix#" &
157 "SVdot_replacement#" &
160 "sAimplementation#" &
162 "Laspecification_exceptions#" &
163 "Laimplementation_exceptions#" &
168 "Ladefault_switches#" &
170 "SVlocal_configuration_pragmas#" &
171 "Salocal_config_file#" &
173 -- Configuration - Compiling
176 "Larequired_switches#" &
177 "Laleading_required_switches#" &
178 "Latrailing_required_switches#" &
181 "Saobject_file_suffix#" &
182 "Laobject_file_switches#" &
183 "Lamulti_unit_switches#" &
184 "Samulti_unit_object_separator#" &
186 -- Configuration - Mapping files
188 "Lamapping_file_switches#" &
189 "Samapping_spec_suffix#" &
190 "Samapping_body_suffix#" &
192 -- Configuration - Config files
194 "Laconfig_file_switches#" &
195 "Saconfig_body_file_name#" &
196 "Saconfig_body_file_name_index#" &
197 "Saconfig_body_file_name_pattern#" &
198 "Saconfig_spec_file_name#" &
199 "Saconfig_spec_file_name_index#" &
200 "Saconfig_spec_file_name_pattern#" &
201 "Saconfig_file_unique#" &
203 -- Configuration - Dependencies
205 "Ladependency_switches#" &
206 "Ladependency_driver#" &
208 -- Configuration - Search paths
210 "Lainclude_switches#" &
212 "Sainclude_path_file#" &
217 "Ladefault_switches#" &
219 "Lcglobal_compilation_switches#" &
221 "SVexecutable_suffix#" &
222 "SVglobal_configuration_pragmas#" &
223 "Saglobal_config_file#" &
233 "Ladefault_switches#" &
236 -- Configuration - Binding
239 "Larequired_switches#" &
242 "Saobjects_path_file#" &
247 "LVrequired_switches#" &
248 "Ladefault_switches#" &
250 "LVlinker_options#" &
251 "SVmap_file_option#" &
253 -- Configuration - Linking
256 "LVexecutable_switch#" &
257 "SVlib_dir_switch#" &
258 "SVlib_name_switch#" &
260 -- Configuration - Response files
262 "SVmax_command_line_length#" &
263 "SVresponse_file_format#" &
264 "LVresponse_file_switches#" &
266 -- package Cross_Reference
268 "Pcross_reference#" &
269 "Ladefault_switches#" &
275 "Ladefault_switches#" &
278 -- package Pretty_Printer
281 "Ladefault_switches#" &
287 "Ladefault_switches#" &
293 "Ladefault_switches#" &
296 -- package Synchronize
299 "Ladefault_switches#" &
305 "Ladefault_switches#" &
311 "Ladefault_switches#" &
317 "Ladefault_switches#" &
320 "SVcommunication_protocol#" &
321 "Sacompiler_command#" &
322 "SVdebugger_command#" &
325 "SVvcs_file_check#" &
335 Initialized
: Boolean := False;
336 -- A flag to avoid multiple initialization
338 Package_Names
: String_List_Access
:= new Strings
.String_List
(1 .. 20);
339 Last_Package_Name
: Natural := 0;
340 -- Package_Names (1 .. Last_Package_Name) contains the list of the known
341 -- package names, coming from the Initialization_Data string or from
342 -- calls to one of the two procedures Register_New_Package.
344 procedure Add_Package_Name
(Name
: String);
345 -- Add a package name in the Package_Name list, extending it, if necessary
347 function Name_Id_Of
(Name
: String) return Name_Id
;
348 -- Returns the Name_Id for Name in lower case
350 ----------------------
351 -- Add_Package_Name --
352 ----------------------
354 procedure Add_Package_Name
(Name
: String) is
356 if Last_Package_Name
= Package_Names
'Last then
358 New_List
: constant Strings
.String_List_Access
:=
359 new Strings
.String_List
(1 .. Package_Names
'Last * 2);
361 New_List
(Package_Names
'Range) := Package_Names
.all;
362 Package_Names
:= New_List
;
366 Last_Package_Name
:= Last_Package_Name
+ 1;
367 Package_Names
(Last_Package_Name
) := new String'(Name);
368 end Add_Package_Name;
370 -----------------------
371 -- Attribute_Kind_Of --
372 -----------------------
374 function Attribute_Kind_Of
375 (Attribute : Attribute_Node_Id) return Attribute_Kind
378 if Attribute = Empty_Attribute then
381 return Attrs.Table (Attribute.Value).Attr_Kind;
383 end Attribute_Kind_Of;
385 -----------------------
386 -- Attribute_Name_Of --
387 -----------------------
389 function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id is
391 if Attribute = Empty_Attribute then
394 return Attrs.Table (Attribute.Value).Name;
396 end Attribute_Name_Of;
398 --------------------------
399 -- Attribute_Node_Id_Of --
400 --------------------------
402 function Attribute_Node_Id_Of
404 Starting_At : Attribute_Node_Id) return Attribute_Node_Id
406 Id : Attr_Node_Id := Starting_At.Value;
409 while Id /= Empty_Attr
410 and then Attrs.Table (Id).Name /= Name
412 Id := Attrs.Table (Id).Next;
415 return (Value => Id);
416 end Attribute_Node_Id_Of;
422 procedure Initialize is
423 Start : Positive := Initialization_Data'First;
424 Finish : Positive := Start;
425 Current_Package : Pkg_Node_Id := Empty_Pkg;
426 Current_Attribute : Attr_Node_Id := Empty_Attr;
427 Is_An_Attribute : Boolean := False;
428 Var_Kind : Variable_Kind := Undefined;
429 Optional_Index : Boolean := False;
430 Attr_Kind : Attribute_Kind := Single;
431 Package_Name : Name_Id := No_Name;
432 Attribute_Name : Name_Id := No_Name;
433 First_Attribute : Attr_Node_Id := Attr.First_Attribute;
435 Others_Allowed : Boolean;
437 function Attribute_Location return String;
438 -- Returns a string depending if we are in the project level attributes
439 -- or in the attributes of a package.
441 ------------------------
442 -- Attribute_Location --
443 ------------------------
445 function Attribute_Location return String is
447 if Package_Name = No_Name then
448 return "project level attributes";
451 return "attribute of package """ &
452 Get_Name_String (Package_Name) & """";
454 end Attribute_Location;
456 -- Start of processing for Initialize
459 -- Don't allow Initialize action to be repeated
465 -- Make sure the two tables are empty
468 Package_Attributes.Init;
470 while Initialization_Data (Start) /= '#
' loop
471 Is_An_Attribute := True;
472 case Initialization_Data (Start) is
475 -- New allowed package
480 while Initialization_Data (Finish) /= '#
' loop
481 Finish := Finish + 1;
485 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
487 for Index in First_Package .. Package_Attributes.Last loop
488 if Package_Name = Package_Attributes.Table (Index).Name then
489 Osint.Fail ("duplicate name """
490 & Initialization_Data (Start .. Finish - 1)
491 & """ in predefined packages.");
495 Is_An_Attribute := False;
496 Current_Attribute := Empty_Attr;
497 Package_Attributes.Increment_Last;
498 Current_Package := Package_Attributes.Last;
499 Package_Attributes.Table (Current_Package) :=
500 (Name => Package_Name,
502 First_Attribute => Empty_Attr);
505 Add_Package_Name (Get_Name_String (Package_Name));
509 Optional_Index := False;
513 Optional_Index := True;
517 Optional_Index := False;
521 Optional_Index := True;
527 if Is_An_Attribute then
532 case Initialization_Data (Start) is
537 Attr_Kind := Associative_Array;
540 Attr_Kind := Case_Insensitive_Associative_Array;
543 if Osint.File_Names_Case_Sensitive then
544 Attr_Kind := Associative_Array;
546 Attr_Kind := Case_Insensitive_Associative_Array;
550 if Osint.File_Names_Case_Sensitive then
551 Attr_Kind := Optional_Index_Associative_Array;
554 Optional_Index_Case_Insensitive_Associative_Array;
564 Others_Allowed := False;
566 if Initialization_Data (Start) = 'R
' then
570 elsif Initialization_Data (Start) = 'O
' then
571 Others_Allowed := True;
577 while Initialization_Data (Finish) /= '#
' loop
578 Finish := Finish + 1;
582 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
583 Attrs.Increment_Last;
585 if Current_Attribute = Empty_Attr then
586 First_Attribute := Attrs.Last;
588 if Current_Package /= Empty_Pkg then
589 Package_Attributes.Table (Current_Package).First_Attribute
594 -- Check that there are no duplicate attributes
596 for Index in First_Attribute .. Attrs.Last - 1 loop
597 if Attribute_Name = Attrs.Table (Index).Name then
598 Osint.Fail ("duplicate attribute """
599 & Initialization_Data (Start .. Finish - 1)
600 & """ in " & Attribute_Location);
604 Attrs.Table (Current_Attribute).Next :=
608 Current_Attribute := Attrs.Last;
609 Attrs.Table (Current_Attribute) :=
610 (Name => Attribute_Name,
611 Var_Kind => Var_Kind,
612 Optional_Index => Optional_Index,
613 Attr_Kind => Attr_Kind,
614 Read_Only => Read_Only,
615 Others_Allowed => Others_Allowed,
628 function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean is
630 return Attrs.Table (Attribute.Value).Read_Only;
637 function Name_Id_Of (Name : String) return Name_Id is
640 Add_Str_To_Name_Buffer (Name);
641 To_Lower (Name_Buffer (1 .. Name_Len));
649 function Next_Attribute
650 (After : Attribute_Node_Id) return Attribute_Node_Id
653 if After = Empty_Attribute then
654 return Empty_Attribute;
656 return (Value => Attrs.Table (After.Value).Next);
660 -----------------------
661 -- Optional_Index_Of --
662 -----------------------
664 function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean is
666 if Attribute = Empty_Attribute then
669 return Attrs.Table (Attribute.Value).Optional_Index;
671 end Optional_Index_Of;
673 function Others_Allowed_For
674 (Attribute : Attribute_Node_Id) return Boolean
677 if Attribute = Empty_Attribute then
680 return Attrs.Table (Attribute.Value).Others_Allowed;
682 end Others_Allowed_For;
684 -----------------------
685 -- Package_Name_List --
686 -----------------------
688 function Package_Name_List return Strings.String_List is
690 return Package_Names (1 .. Last_Package_Name);
691 end Package_Name_List;
693 ------------------------
694 -- Package_Node_Id_Of --
695 ------------------------
697 function Package_Node_Id_Of (Name : Name_Id) return Package_Node_Id is
699 for Index in Package_Attributes.First .. Package_Attributes.Last loop
700 if Package_Attributes.Table (Index).Name = Name then
701 if Package_Attributes.Table (Index).Known then
702 return (Value => Index);
704 return Unknown_Package;
709 -- If there is no package with this name, return Empty_Package
711 return Empty_Package;
712 end Package_Node_Id_Of;
714 ----------------------------
715 -- Register_New_Attribute --
716 ----------------------------
718 procedure Register_New_Attribute
720 In_Package : Package_Node_Id;
721 Attr_Kind : Defined_Attribute_Kind;
722 Var_Kind : Defined_Variable_Kind;
723 Index_Is_File_Name : Boolean := False;
724 Opt_Index : Boolean := False)
727 First_Attr : Attr_Node_Id := Empty_Attr;
728 Curr_Attr : Attr_Node_Id;
729 Real_Attr_Kind : Attribute_Kind;
732 if Name'Length = 0 then
733 Fail ("cannot register an attribute with no name");
737 if In_Package = Empty_Package then
738 Fail ("attempt to add attribute """
740 & """ to an undefined package");
744 Attr_Name := Name_Id_Of (Name);
747 Package_Attributes.Table (In_Package.Value).First_Attribute;
749 -- Check if attribute name is a duplicate
751 Curr_Attr := First_Attr;
752 while Curr_Attr /= Empty_Attr loop
753 if Attrs.Table (Curr_Attr).Name = Attr_Name then
754 Fail ("duplicate attribute name """
758 (Package_Attributes.Table (In_Package.Value).Name)
763 Curr_Attr := Attrs.Table (Curr_Attr).Next;
766 Real_Attr_Kind := Attr_Kind;
768 -- If Index_Is_File_Name, change the attribute kind if necessary
770 if Index_Is_File_Name and then not Osint.File_Names_Case_Sensitive then
772 when Associative_Array =>
773 Real_Attr_Kind := Case_Insensitive_Associative_Array;
775 when Optional_Index_Associative_Array =>
777 Optional_Index_Case_Insensitive_Associative_Array;
784 -- Add the new attribute
786 Attrs.Increment_Last;
787 Attrs.Table (Attrs.Last) :=
789 Var_Kind => Var_Kind,
790 Optional_Index => Opt_Index,
791 Attr_Kind => Real_Attr_Kind,
793 Others_Allowed => False,
796 Package_Attributes.Table (In_Package.Value).First_Attribute :=
798 end Register_New_Attribute;
800 --------------------------
801 -- Register_New_Package --
802 --------------------------
804 procedure Register_New_Package (Name : String; Id : out Package_Node_Id) is
808 if Name'Length = 0 then
809 Fail ("cannot register a package with no name");
814 Pkg_Name := Name_Id_Of (Name);
816 for Index in Package_Attributes.First .. Package_Attributes.Last loop
817 if Package_Attributes.Table (Index).Name = Pkg_Name then
818 Fail ("cannot register a package with a non unique name"""
826 Package_Attributes.Increment_Last;
827 Id := (Value => Package_Attributes.Last);
828 Package_Attributes.Table (Package_Attributes.Last) :=
831 First_Attribute => Empty_Attr);
833 Add_Package_Name (Get_Name_String (Pkg_Name));
834 end Register_New_Package;
836 procedure Register_New_Package
838 Attributes : Attribute_Data_Array)
842 First_Attr : Attr_Node_Id := Empty_Attr;
843 Curr_Attr : Attr_Node_Id;
844 Attr_Kind : Attribute_Kind;
847 if Name'Length = 0 then
848 Fail ("cannot register a package with no name");
852 Pkg_Name := Name_Id_Of (Name);
854 for Index in Package_Attributes.First .. Package_Attributes.Last loop
855 if Package_Attributes.Table (Index).Name = Pkg_Name then
856 Fail ("cannot register a package with a non unique name"""
863 for Index in Attributes'Range loop
864 Attr_Name := Name_Id_Of (Attributes (Index).Name);
866 Curr_Attr := First_Attr;
867 while Curr_Attr /= Empty_Attr loop
868 if Attrs.Table (Curr_Attr).Name = Attr_Name then
869 Fail ("duplicate attribute name """
870 & Attributes (Index).Name
871 & """ in new package """
877 Curr_Attr := Attrs.Table (Curr_Attr).Next;
880 Attr_Kind := Attributes (Index).Attr_Kind;
882 if Attributes (Index).Index_Is_File_Name
883 and then not Osint.File_Names_Case_Sensitive
886 when Associative_Array =>
887 Attr_Kind := Case_Insensitive_Associative_Array;
889 when Optional_Index_Associative_Array =>
891 Optional_Index_Case_Insensitive_Associative_Array;
898 Attrs.Increment_Last;
899 Attrs.Table (Attrs.Last) :=
901 Var_Kind => Attributes (Index).Var_Kind,
902 Optional_Index => Attributes (Index).Opt_Index,
903 Attr_Kind => Attr_Kind,
905 Others_Allowed => False,
907 First_Attr := Attrs.Last;
910 Package_Attributes.Increment_Last;
911 Package_Attributes.Table (Package_Attributes.Last) :=
914 First_Attribute => First_Attr);
916 Add_Package_Name (Get_Name_String (Pkg_Name));
917 end Register_New_Package;
919 ---------------------------
920 -- Set_Attribute_Kind_Of --
921 ---------------------------
923 procedure Set_Attribute_Kind_Of
924 (Attribute : Attribute_Node_Id;
928 if Attribute /= Empty_Attribute then
929 Attrs.Table (Attribute.Value).Attr_Kind := To;
931 end Set_Attribute_Kind_Of;
933 --------------------------
934 -- Set_Variable_Kind_Of --
935 --------------------------
937 procedure Set_Variable_Kind_Of
938 (Attribute : Attribute_Node_Id;
942 if Attribute /= Empty_Attribute then
943 Attrs.Table (Attribute.Value).Var_Kind := To;
945 end Set_Variable_Kind_Of;
947 ----------------------
948 -- Variable_Kind_Of --
949 ----------------------
951 function Variable_Kind_Of
952 (Attribute : Attribute_Node_Id) return Variable_Kind
955 if Attribute = Empty_Attribute then
958 return Attrs.Table (Attribute.Value).Var_Kind;
960 end Variable_Kind_Of;
962 ------------------------
963 -- First_Attribute_Of --
964 ------------------------
966 function First_Attribute_Of
967 (Pkg : Package_Node_Id) return Attribute_Node_Id
970 if Pkg = Empty_Package then
971 return Empty_Attribute;
974 (Value => Package_Attributes.Table (Pkg.Value).First_Attribute);
976 end First_Attribute_Of;