1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2009, 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
76 "SVexternally_built#" &
83 "Lainherit_source_path#" &
84 "LVexcluded_source_dirs#" &
89 "LVlocally_removed_files#" &
90 "LVexcluded_source_files#" &
91 "SVsource_list_file#" &
92 "SVexcluded_source_list_file#" &
100 "SVlibrary_version#" &
101 "LVlibrary_interface#" &
102 "SVlibrary_auto_init#" &
103 "LVlibrary_options#" &
104 "SVlibrary_src_dir#" &
105 "SVlibrary_ali_dir#" &
107 "SVlibrary_symbol_file#" &
108 "SVlibrary_symbol_policy#" &
109 "SVlibrary_reference_symbol_file#" &
111 -- Configuration - General
113 "SVdefault_language#" &
114 "LVrun_path_option#" &
115 "SVrun_path_origin#" &
116 "SVseparate_run_path_options#" &
117 "Satoolchain_version#" &
118 "Satoolchain_description#" &
119 "Saobject_generated#" &
120 "Saobjects_linked#" &
123 -- Configuration - Libraries
125 "SVlibrary_builder#" &
126 "SVlibrary_support#" &
128 -- Configuration - Archives
130 "LVarchive_builder#" &
131 "LVarchive_builder_append_option#" &
132 "LVarchive_indexer#" &
133 "SVarchive_suffix#" &
134 "LVlibrary_partial_linker#" &
136 -- Configuration - Shared libraries
138 "SVshared_library_prefix#" &
139 "SVshared_library_suffix#" &
140 "SVsymbolic_link_supported#" &
141 "SVlibrary_major_minor_id_supported#" &
142 "SVlibrary_auto_init_supported#" &
143 "LVshared_library_minimum_switches#" &
144 "LVlibrary_version_switches#" &
145 "SVlibrary_install_name_option#" &
146 "Saruntime_library_dir#" &
147 "Saruntime_source_dir#" &
152 "Saspecification_suffix#" &
154 "Saimplementation_suffix#" &
156 "SVseparate_suffix#" &
158 "SVdot_replacement#" &
161 "sAimplementation#" &
163 "Laspecification_exceptions#" &
164 "Laimplementation_exceptions#" &
169 "Ladefault_switches#" &
171 "SVlocal_configuration_pragmas#" &
172 "Salocal_config_file#" &
174 -- Configuration - Compiling
177 "Larequired_switches#" &
178 "Laleading_required_switches#" &
179 "Latrailing_required_switches#" &
182 "Saobject_file_suffix#" &
183 "Laobject_file_switches#" &
184 "Lamulti_unit_switches#" &
185 "Samulti_unit_object_separator#" &
187 -- Configuration - Mapping files
189 "Lamapping_file_switches#" &
190 "Samapping_spec_suffix#" &
191 "Samapping_body_suffix#" &
193 -- Configuration - Config files
195 "Laconfig_file_switches#" &
196 "Saconfig_body_file_name#" &
197 "Saconfig_body_file_name_index#" &
198 "Saconfig_body_file_name_pattern#" &
199 "Saconfig_spec_file_name#" &
200 "Saconfig_spec_file_name_index#" &
201 "Saconfig_spec_file_name_pattern#" &
202 "Saconfig_file_unique#" &
204 -- Configuration - Dependencies
206 "Ladependency_switches#" &
207 "Ladependency_driver#" &
209 -- Configuration - Search paths
211 "Lainclude_switches#" &
213 "Sainclude_path_file#" &
218 "Ladefault_switches#" &
220 "Lcglobal_compilation_switches#" &
222 "SVexecutable_suffix#" &
223 "SVglobal_configuration_pragmas#" &
224 "Saglobal_config_file#" &
234 "Ladefault_switches#" &
237 -- Configuration - Binding
240 "Larequired_switches#" &
243 "Saobjects_path_file#" &
248 "LVrequired_switches#" &
249 "Ladefault_switches#" &
251 "LVlinker_options#" &
252 "SVmap_file_option#" &
254 -- Configuration - Linking
257 "LVexecutable_switch#" &
258 "SVlib_dir_switch#" &
259 "SVlib_name_switch#" &
261 -- Configuration - Response files
263 "SVmax_command_line_length#" &
264 "SVresponse_file_format#" &
265 "LVresponse_file_switches#" &
267 -- package Cross_Reference
269 "Pcross_reference#" &
270 "Ladefault_switches#" &
276 "Ladefault_switches#" &
279 -- package Pretty_Printer
282 "Ladefault_switches#" &
288 "Ladefault_switches#" &
294 "Ladefault_switches#" &
297 -- package Synchronize
300 "Ladefault_switches#" &
306 "Ladefault_switches#" &
312 "Ladefault_switches#" &
318 "Ladefault_switches#" &
321 "SVcommunication_protocol#" &
322 "Sacompiler_command#" &
323 "SVdebugger_command#" &
326 "SVvcs_file_check#" &
336 Initialized
: Boolean := False;
337 -- A flag to avoid multiple initialization
339 Package_Names
: String_List_Access
:= new Strings
.String_List
(1 .. 20);
340 Last_Package_Name
: Natural := 0;
341 -- Package_Names (1 .. Last_Package_Name) contains the list of the known
342 -- package names, coming from the Initialization_Data string or from
343 -- calls to one of the two procedures Register_New_Package.
345 procedure Add_Package_Name
(Name
: String);
346 -- Add a package name in the Package_Name list, extending it, if necessary
348 function Name_Id_Of
(Name
: String) return Name_Id
;
349 -- Returns the Name_Id for Name in lower case
351 ----------------------
352 -- Add_Package_Name --
353 ----------------------
355 procedure Add_Package_Name
(Name
: String) is
357 if Last_Package_Name
= Package_Names
'Last then
359 New_List
: constant Strings
.String_List_Access
:=
360 new Strings
.String_List
(1 .. Package_Names
'Last * 2);
362 New_List
(Package_Names
'Range) := Package_Names
.all;
363 Package_Names
:= New_List
;
367 Last_Package_Name
:= Last_Package_Name
+ 1;
368 Package_Names
(Last_Package_Name
) := new String'(Name);
369 end Add_Package_Name;
371 -----------------------
372 -- Attribute_Kind_Of --
373 -----------------------
375 function Attribute_Kind_Of
376 (Attribute : Attribute_Node_Id) return Attribute_Kind
379 if Attribute = Empty_Attribute then
382 return Attrs.Table (Attribute.Value).Attr_Kind;
384 end Attribute_Kind_Of;
386 -----------------------
387 -- Attribute_Name_Of --
388 -----------------------
390 function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id is
392 if Attribute = Empty_Attribute then
395 return Attrs.Table (Attribute.Value).Name;
397 end Attribute_Name_Of;
399 --------------------------
400 -- Attribute_Node_Id_Of --
401 --------------------------
403 function Attribute_Node_Id_Of
405 Starting_At : Attribute_Node_Id) return Attribute_Node_Id
407 Id : Attr_Node_Id := Starting_At.Value;
410 while Id /= Empty_Attr
411 and then Attrs.Table (Id).Name /= Name
413 Id := Attrs.Table (Id).Next;
416 return (Value => Id);
417 end Attribute_Node_Id_Of;
423 procedure Initialize is
424 Start : Positive := Initialization_Data'First;
425 Finish : Positive := Start;
426 Current_Package : Pkg_Node_Id := Empty_Pkg;
427 Current_Attribute : Attr_Node_Id := Empty_Attr;
428 Is_An_Attribute : Boolean := False;
429 Var_Kind : Variable_Kind := Undefined;
430 Optional_Index : Boolean := False;
431 Attr_Kind : Attribute_Kind := Single;
432 Package_Name : Name_Id := No_Name;
433 Attribute_Name : Name_Id := No_Name;
434 First_Attribute : Attr_Node_Id := Attr.First_Attribute;
436 Others_Allowed : Boolean;
438 function Attribute_Location return String;
439 -- Returns a string depending if we are in the project level attributes
440 -- or in the attributes of a package.
442 ------------------------
443 -- Attribute_Location --
444 ------------------------
446 function Attribute_Location return String is
448 if Package_Name = No_Name then
449 return "project level attributes";
452 return "attribute of package """ &
453 Get_Name_String (Package_Name) & """";
455 end Attribute_Location;
457 -- Start of processing for Initialize
460 -- Don't allow Initialize action to be repeated
466 -- Make sure the two tables are empty
469 Package_Attributes.Init;
471 while Initialization_Data (Start) /= '#
' loop
472 Is_An_Attribute := True;
473 case Initialization_Data (Start) is
476 -- New allowed package
481 while Initialization_Data (Finish) /= '#
' loop
482 Finish := Finish + 1;
486 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
488 for Index in First_Package .. Package_Attributes.Last loop
489 if Package_Name = Package_Attributes.Table (Index).Name then
490 Osint.Fail ("duplicate name """
491 & Initialization_Data (Start .. Finish - 1)
492 & """ in predefined packages.");
496 Is_An_Attribute := False;
497 Current_Attribute := Empty_Attr;
498 Package_Attributes.Increment_Last;
499 Current_Package := Package_Attributes.Last;
500 Package_Attributes.Table (Current_Package) :=
501 (Name => Package_Name,
503 First_Attribute => Empty_Attr);
506 Add_Package_Name (Get_Name_String (Package_Name));
510 Optional_Index := False;
514 Optional_Index := True;
518 Optional_Index := False;
522 Optional_Index := True;
528 if Is_An_Attribute then
533 case Initialization_Data (Start) is
538 Attr_Kind := Associative_Array;
541 Attr_Kind := Case_Insensitive_Associative_Array;
544 if Osint.File_Names_Case_Sensitive then
545 Attr_Kind := Associative_Array;
547 Attr_Kind := Case_Insensitive_Associative_Array;
551 if Osint.File_Names_Case_Sensitive then
552 Attr_Kind := Optional_Index_Associative_Array;
555 Optional_Index_Case_Insensitive_Associative_Array;
565 Others_Allowed := False;
567 if Initialization_Data (Start) = 'R
' then
571 elsif Initialization_Data (Start) = 'O
' then
572 Others_Allowed := True;
578 while Initialization_Data (Finish) /= '#
' loop
579 Finish := Finish + 1;
583 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
584 Attrs.Increment_Last;
586 if Current_Attribute = Empty_Attr then
587 First_Attribute := Attrs.Last;
589 if Current_Package /= Empty_Pkg then
590 Package_Attributes.Table (Current_Package).First_Attribute
595 -- Check that there are no duplicate attributes
597 for Index in First_Attribute .. Attrs.Last - 1 loop
598 if Attribute_Name = Attrs.Table (Index).Name then
599 Osint.Fail ("duplicate attribute """
600 & Initialization_Data (Start .. Finish - 1)
601 & """ in " & Attribute_Location);
605 Attrs.Table (Current_Attribute).Next :=
609 Current_Attribute := Attrs.Last;
610 Attrs.Table (Current_Attribute) :=
611 (Name => Attribute_Name,
612 Var_Kind => Var_Kind,
613 Optional_Index => Optional_Index,
614 Attr_Kind => Attr_Kind,
615 Read_Only => Read_Only,
616 Others_Allowed => Others_Allowed,
629 function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean is
631 return Attrs.Table (Attribute.Value).Read_Only;
638 function Name_Id_Of (Name : String) return Name_Id is
641 Add_Str_To_Name_Buffer (Name);
642 To_Lower (Name_Buffer (1 .. Name_Len));
650 function Next_Attribute
651 (After : Attribute_Node_Id) return Attribute_Node_Id
654 if After = Empty_Attribute then
655 return Empty_Attribute;
657 return (Value => Attrs.Table (After.Value).Next);
661 -----------------------
662 -- Optional_Index_Of --
663 -----------------------
665 function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean is
667 if Attribute = Empty_Attribute then
670 return Attrs.Table (Attribute.Value).Optional_Index;
672 end Optional_Index_Of;
674 function Others_Allowed_For
675 (Attribute : Attribute_Node_Id) return Boolean
678 if Attribute = Empty_Attribute then
681 return Attrs.Table (Attribute.Value).Others_Allowed;
683 end Others_Allowed_For;
685 -----------------------
686 -- Package_Name_List --
687 -----------------------
689 function Package_Name_List return Strings.String_List is
691 return Package_Names (1 .. Last_Package_Name);
692 end Package_Name_List;
694 ------------------------
695 -- Package_Node_Id_Of --
696 ------------------------
698 function Package_Node_Id_Of (Name : Name_Id) return Package_Node_Id is
700 for Index in Package_Attributes.First .. Package_Attributes.Last loop
701 if Package_Attributes.Table (Index).Name = Name then
702 if Package_Attributes.Table (Index).Known then
703 return (Value => Index);
705 return Unknown_Package;
710 -- If there is no package with this name, return Empty_Package
712 return Empty_Package;
713 end Package_Node_Id_Of;
715 ----------------------------
716 -- Register_New_Attribute --
717 ----------------------------
719 procedure Register_New_Attribute
721 In_Package : Package_Node_Id;
722 Attr_Kind : Defined_Attribute_Kind;
723 Var_Kind : Defined_Variable_Kind;
724 Index_Is_File_Name : Boolean := False;
725 Opt_Index : Boolean := False)
728 First_Attr : Attr_Node_Id := Empty_Attr;
729 Curr_Attr : Attr_Node_Id;
730 Real_Attr_Kind : Attribute_Kind;
733 if Name'Length = 0 then
734 Fail ("cannot register an attribute with no name");
738 if In_Package = Empty_Package then
739 Fail ("attempt to add attribute """
741 & """ to an undefined package");
745 Attr_Name := Name_Id_Of (Name);
748 Package_Attributes.Table (In_Package.Value).First_Attribute;
750 -- Check if attribute name is a duplicate
752 Curr_Attr := First_Attr;
753 while Curr_Attr /= Empty_Attr loop
754 if Attrs.Table (Curr_Attr).Name = Attr_Name then
755 Fail ("duplicate attribute name """
759 (Package_Attributes.Table (In_Package.Value).Name)
764 Curr_Attr := Attrs.Table (Curr_Attr).Next;
767 Real_Attr_Kind := Attr_Kind;
769 -- If Index_Is_File_Name, change the attribute kind if necessary
771 if Index_Is_File_Name and then not Osint.File_Names_Case_Sensitive then
773 when Associative_Array =>
774 Real_Attr_Kind := Case_Insensitive_Associative_Array;
776 when Optional_Index_Associative_Array =>
778 Optional_Index_Case_Insensitive_Associative_Array;
785 -- Add the new attribute
787 Attrs.Increment_Last;
788 Attrs.Table (Attrs.Last) :=
790 Var_Kind => Var_Kind,
791 Optional_Index => Opt_Index,
792 Attr_Kind => Real_Attr_Kind,
794 Others_Allowed => False,
797 Package_Attributes.Table (In_Package.Value).First_Attribute :=
799 end Register_New_Attribute;
801 --------------------------
802 -- Register_New_Package --
803 --------------------------
805 procedure Register_New_Package (Name : String; Id : out Package_Node_Id) is
809 if Name'Length = 0 then
810 Fail ("cannot register a package with no name");
815 Pkg_Name := Name_Id_Of (Name);
817 for Index in Package_Attributes.First .. Package_Attributes.Last loop
818 if Package_Attributes.Table (Index).Name = Pkg_Name then
819 Fail ("cannot register a package with a non unique name"""
827 Package_Attributes.Increment_Last;
828 Id := (Value => Package_Attributes.Last);
829 Package_Attributes.Table (Package_Attributes.Last) :=
832 First_Attribute => Empty_Attr);
834 Add_Package_Name (Get_Name_String (Pkg_Name));
835 end Register_New_Package;
837 procedure Register_New_Package
839 Attributes : Attribute_Data_Array)
843 First_Attr : Attr_Node_Id := Empty_Attr;
844 Curr_Attr : Attr_Node_Id;
845 Attr_Kind : Attribute_Kind;
848 if Name'Length = 0 then
849 Fail ("cannot register a package with no name");
853 Pkg_Name := Name_Id_Of (Name);
855 for Index in Package_Attributes.First .. Package_Attributes.Last loop
856 if Package_Attributes.Table (Index).Name = Pkg_Name then
857 Fail ("cannot register a package with a non unique name"""
864 for Index in Attributes'Range loop
865 Attr_Name := Name_Id_Of (Attributes (Index).Name);
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 """
871 & Attributes (Index).Name
872 & """ in new package """
878 Curr_Attr := Attrs.Table (Curr_Attr).Next;
881 Attr_Kind := Attributes (Index).Attr_Kind;
883 if Attributes (Index).Index_Is_File_Name
884 and then not Osint.File_Names_Case_Sensitive
887 when Associative_Array =>
888 Attr_Kind := Case_Insensitive_Associative_Array;
890 when Optional_Index_Associative_Array =>
892 Optional_Index_Case_Insensitive_Associative_Array;
899 Attrs.Increment_Last;
900 Attrs.Table (Attrs.Last) :=
902 Var_Kind => Attributes (Index).Var_Kind,
903 Optional_Index => Attributes (Index).Opt_Index,
904 Attr_Kind => Attr_Kind,
906 Others_Allowed => False,
908 First_Attr := Attrs.Last;
911 Package_Attributes.Increment_Last;
912 Package_Attributes.Table (Package_Attributes.Last) :=
915 First_Attribute => First_Attr);
917 Add_Package_Name (Get_Name_String (Pkg_Name));
918 end Register_New_Package;
920 ---------------------------
921 -- Set_Attribute_Kind_Of --
922 ---------------------------
924 procedure Set_Attribute_Kind_Of
925 (Attribute : Attribute_Node_Id;
929 if Attribute /= Empty_Attribute then
930 Attrs.Table (Attribute.Value).Attr_Kind := To;
932 end Set_Attribute_Kind_Of;
934 --------------------------
935 -- Set_Variable_Kind_Of --
936 --------------------------
938 procedure Set_Variable_Kind_Of
939 (Attribute : Attribute_Node_Id;
943 if Attribute /= Empty_Attribute then
944 Attrs.Table (Attribute.Value).Var_Kind := To;
946 end Set_Variable_Kind_Of;
948 ----------------------
949 -- Variable_Kind_Of --
950 ----------------------
952 function Variable_Kind_Of
953 (Attribute : Attribute_Node_Id) return Variable_Kind
956 if Attribute = Empty_Attribute then
959 return Attrs.Table (Attribute.Value).Var_Kind;
961 end Variable_Kind_Of;
963 ------------------------
964 -- First_Attribute_Of --
965 ------------------------
967 function First_Attribute_Of
968 (Pkg : Package_Node_Id) return Attribute_Node_Id
971 if Pkg = Empty_Package then
972 return Empty_Attribute;
975 (Value => Package_Attributes.Table (Pkg.Value).First_Attribute);
977 end First_Attribute_Of;