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 "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 "Saruntime_library_dir#" &
145 "Saruntime_source_dir#" &
150 "Saspecification_suffix#" &
152 "Saimplementation_suffix#" &
154 "SVseparate_suffix#" &
156 "SVdot_replacement#" &
159 "sAimplementation#" &
161 "Laspecification_exceptions#" &
162 "Laimplementation_exceptions#" &
167 "Ladefault_switches#" &
169 "SVlocal_configuration_pragmas#" &
170 "Salocal_config_file#" &
172 -- Configuration - Compiling
175 "Larequired_switches#" &
178 "Saobject_file_suffix#" &
180 -- Configuration - Mapping files
182 "Lamapping_file_switches#" &
183 "Samapping_spec_suffix#" &
184 "Samapping_body_suffix#" &
186 -- Configuration - Config files
188 "Laconfig_file_switches#" &
189 "Saconfig_body_file_name#" &
190 "Saconfig_spec_file_name#" &
191 "Saconfig_body_file_name_pattern#" &
192 "Saconfig_spec_file_name_pattern#" &
193 "Saconfig_file_unique#" &
195 -- Configuration - Dependencies
197 "Ladependency_switches#" &
198 "Ladependency_driver#" &
200 -- Configuration - Search paths
202 "Lainclude_switches#" &
204 "Sainclude_path_file#" &
209 "Ladefault_switches#" &
211 "Lcglobal_compilation_switches#" &
213 "SVexecutable_suffix#" &
214 "SVglobal_configuration_pragmas#" &
215 "Saglobal_config_file#" &
225 "Ladefault_switches#" &
228 -- Configuration - Binding
231 "Larequired_switches#" &
234 "Saobjects_path_file#" &
239 "LVrequired_switches#" &
240 "Ladefault_switches#" &
242 "LVlinker_options#" &
243 "SVmap_file_option#" &
245 -- Configuration - Linking
248 "LVexecutable_switch#" &
249 "SVlib_dir_switch#" &
250 "SVlib_name_switch#" &
252 -- Configuration - Response files
254 "SVmax_command_line_length#" &
255 "SVresponse_file_format#" &
256 "LVresponse_file_switches#" &
258 -- package Cross_Reference
260 "Pcross_reference#" &
261 "Ladefault_switches#" &
267 "Ladefault_switches#" &
270 -- package Pretty_Printer
273 "Ladefault_switches#" &
279 "Ladefault_switches#" &
285 "Ladefault_switches#" &
288 -- package Synchronize
291 "Ladefault_switches#" &
297 "Ladefault_switches#" &
303 "Ladefault_switches#" &
309 "Ladefault_switches#" &
312 "SVcommunication_protocol#" &
313 "Sacompiler_command#" &
314 "SVdebugger_command#" &
317 "SVvcs_file_check#" &
327 Initialized
: Boolean := False;
328 -- A flag to avoid multiple initialization
330 Package_Names
: String_List_Access
:= new Strings
.String_List
(1 .. 20);
331 Last_Package_Name
: Natural := 0;
332 -- Package_Names (1 .. Last_Package_Name) contains the list of the known
333 -- package names, coming from the Initialization_Data string or from
334 -- calls to one of the two procedures Register_New_Package.
336 procedure Add_Package_Name
(Name
: String);
337 -- Add a package name in the Package_Name list, extending it, if necessary
339 function Name_Id_Of
(Name
: String) return Name_Id
;
340 -- Returns the Name_Id for Name in lower case
342 ----------------------
343 -- Add_Package_Name --
344 ----------------------
346 procedure Add_Package_Name
(Name
: String) is
348 if Last_Package_Name
= Package_Names
'Last then
350 New_List
: constant Strings
.String_List_Access
:=
351 new Strings
.String_List
(1 .. Package_Names
'Last * 2);
353 New_List
(Package_Names
'Range) := Package_Names
.all;
354 Package_Names
:= New_List
;
358 Last_Package_Name
:= Last_Package_Name
+ 1;
359 Package_Names
(Last_Package_Name
) := new String'(Name);
360 end Add_Package_Name;
362 -----------------------
363 -- Attribute_Kind_Of --
364 -----------------------
366 function Attribute_Kind_Of
367 (Attribute : Attribute_Node_Id) return Attribute_Kind
370 if Attribute = Empty_Attribute then
373 return Attrs.Table (Attribute.Value).Attr_Kind;
375 end Attribute_Kind_Of;
377 -----------------------
378 -- Attribute_Name_Of --
379 -----------------------
381 function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id is
383 if Attribute = Empty_Attribute then
386 return Attrs.Table (Attribute.Value).Name;
388 end Attribute_Name_Of;
390 --------------------------
391 -- Attribute_Node_Id_Of --
392 --------------------------
394 function Attribute_Node_Id_Of
396 Starting_At : Attribute_Node_Id) return Attribute_Node_Id
398 Id : Attr_Node_Id := Starting_At.Value;
401 while Id /= Empty_Attr
402 and then Attrs.Table (Id).Name /= Name
404 Id := Attrs.Table (Id).Next;
407 return (Value => Id);
408 end Attribute_Node_Id_Of;
414 procedure Initialize is
415 Start : Positive := Initialization_Data'First;
416 Finish : Positive := Start;
417 Current_Package : Pkg_Node_Id := Empty_Pkg;
418 Current_Attribute : Attr_Node_Id := Empty_Attr;
419 Is_An_Attribute : Boolean := False;
420 Var_Kind : Variable_Kind := Undefined;
421 Optional_Index : Boolean := False;
422 Attr_Kind : Attribute_Kind := Single;
423 Package_Name : Name_Id := No_Name;
424 Attribute_Name : Name_Id := No_Name;
425 First_Attribute : Attr_Node_Id := Attr.First_Attribute;
427 Others_Allowed : Boolean;
429 function Attribute_Location return String;
430 -- Returns a string depending if we are in the project level attributes
431 -- or in the attributes of a package.
433 ------------------------
434 -- Attribute_Location --
435 ------------------------
437 function Attribute_Location return String is
439 if Package_Name = No_Name then
440 return "project level attributes";
443 return "attribute of package """ &
444 Get_Name_String (Package_Name) & """";
446 end Attribute_Location;
448 -- Start of processing for Initialize
451 -- Don't allow Initialize action to be repeated
457 -- Make sure the two tables are empty
460 Package_Attributes.Init;
462 while Initialization_Data (Start) /= '#
' loop
463 Is_An_Attribute := True;
464 case Initialization_Data (Start) is
467 -- New allowed package
472 while Initialization_Data (Finish) /= '#
' loop
473 Finish := Finish + 1;
477 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
479 for Index in First_Package .. Package_Attributes.Last loop
480 if Package_Name = Package_Attributes.Table (Index).Name then
481 Osint.Fail ("duplicate name """
482 & Initialization_Data (Start .. Finish - 1)
483 & """ in predefined packages.");
487 Is_An_Attribute := False;
488 Current_Attribute := Empty_Attr;
489 Package_Attributes.Increment_Last;
490 Current_Package := Package_Attributes.Last;
491 Package_Attributes.Table (Current_Package) :=
492 (Name => Package_Name,
494 First_Attribute => Empty_Attr);
497 Add_Package_Name (Get_Name_String (Package_Name));
501 Optional_Index := False;
505 Optional_Index := True;
509 Optional_Index := False;
513 Optional_Index := True;
519 if Is_An_Attribute then
524 case Initialization_Data (Start) is
529 Attr_Kind := Associative_Array;
532 Attr_Kind := Case_Insensitive_Associative_Array;
535 if Osint.File_Names_Case_Sensitive then
536 Attr_Kind := Associative_Array;
538 Attr_Kind := Case_Insensitive_Associative_Array;
542 if Osint.File_Names_Case_Sensitive then
543 Attr_Kind := Optional_Index_Associative_Array;
546 Optional_Index_Case_Insensitive_Associative_Array;
556 Others_Allowed := False;
558 if Initialization_Data (Start) = 'R
' then
562 elsif Initialization_Data (Start) = 'O
' then
563 Others_Allowed := True;
569 while Initialization_Data (Finish) /= '#
' loop
570 Finish := Finish + 1;
574 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
575 Attrs.Increment_Last;
577 if Current_Attribute = Empty_Attr then
578 First_Attribute := Attrs.Last;
580 if Current_Package /= Empty_Pkg then
581 Package_Attributes.Table (Current_Package).First_Attribute
586 -- Check that there are no duplicate attributes
588 for Index in First_Attribute .. Attrs.Last - 1 loop
589 if Attribute_Name = Attrs.Table (Index).Name then
590 Osint.Fail ("duplicate attribute """
591 & Initialization_Data (Start .. Finish - 1)
592 & """ in " & Attribute_Location);
596 Attrs.Table (Current_Attribute).Next :=
600 Current_Attribute := Attrs.Last;
601 Attrs.Table (Current_Attribute) :=
602 (Name => Attribute_Name,
603 Var_Kind => Var_Kind,
604 Optional_Index => Optional_Index,
605 Attr_Kind => Attr_Kind,
606 Read_Only => Read_Only,
607 Others_Allowed => Others_Allowed,
620 function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean is
622 return Attrs.Table (Attribute.Value).Read_Only;
629 function Name_Id_Of (Name : String) return Name_Id is
632 Add_Str_To_Name_Buffer (Name);
633 To_Lower (Name_Buffer (1 .. Name_Len));
641 function Next_Attribute
642 (After : Attribute_Node_Id) return Attribute_Node_Id
645 if After = Empty_Attribute then
646 return Empty_Attribute;
648 return (Value => Attrs.Table (After.Value).Next);
652 -----------------------
653 -- Optional_Index_Of --
654 -----------------------
656 function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean is
658 if Attribute = Empty_Attribute then
661 return Attrs.Table (Attribute.Value).Optional_Index;
663 end Optional_Index_Of;
665 function Others_Allowed_For
666 (Attribute : Attribute_Node_Id) return Boolean
669 if Attribute = Empty_Attribute then
672 return Attrs.Table (Attribute.Value).Others_Allowed;
674 end Others_Allowed_For;
676 -----------------------
677 -- Package_Name_List --
678 -----------------------
680 function Package_Name_List return Strings.String_List is
682 return Package_Names (1 .. Last_Package_Name);
683 end Package_Name_List;
685 ------------------------
686 -- Package_Node_Id_Of --
687 ------------------------
689 function Package_Node_Id_Of (Name : Name_Id) return Package_Node_Id is
691 for Index in Package_Attributes.First .. Package_Attributes.Last loop
692 if Package_Attributes.Table (Index).Name = Name then
693 if Package_Attributes.Table (Index).Known then
694 return (Value => Index);
696 return Unknown_Package;
701 -- If there is no package with this name, return Empty_Package
703 return Empty_Package;
704 end Package_Node_Id_Of;
706 ----------------------------
707 -- Register_New_Attribute --
708 ----------------------------
710 procedure Register_New_Attribute
712 In_Package : Package_Node_Id;
713 Attr_Kind : Defined_Attribute_Kind;
714 Var_Kind : Defined_Variable_Kind;
715 Index_Is_File_Name : Boolean := False;
716 Opt_Index : Boolean := False)
719 First_Attr : Attr_Node_Id := Empty_Attr;
720 Curr_Attr : Attr_Node_Id;
721 Real_Attr_Kind : Attribute_Kind;
724 if Name'Length = 0 then
725 Fail ("cannot register an attribute with no name");
729 if In_Package = Empty_Package then
730 Fail ("attempt to add attribute """
732 & """ to an undefined package");
736 Attr_Name := Name_Id_Of (Name);
739 Package_Attributes.Table (In_Package.Value).First_Attribute;
741 -- Check if attribute name is a duplicate
743 Curr_Attr := First_Attr;
744 while Curr_Attr /= Empty_Attr loop
745 if Attrs.Table (Curr_Attr).Name = Attr_Name then
746 Fail ("duplicate attribute name """
750 (Package_Attributes.Table (In_Package.Value).Name)
755 Curr_Attr := Attrs.Table (Curr_Attr).Next;
758 Real_Attr_Kind := Attr_Kind;
760 -- If Index_Is_File_Name, change the attribute kind if necessary
762 if Index_Is_File_Name and then not Osint.File_Names_Case_Sensitive then
764 when Associative_Array =>
765 Real_Attr_Kind := Case_Insensitive_Associative_Array;
767 when Optional_Index_Associative_Array =>
769 Optional_Index_Case_Insensitive_Associative_Array;
776 -- Add the new attribute
778 Attrs.Increment_Last;
779 Attrs.Table (Attrs.Last) :=
781 Var_Kind => Var_Kind,
782 Optional_Index => Opt_Index,
783 Attr_Kind => Real_Attr_Kind,
785 Others_Allowed => False,
788 Package_Attributes.Table (In_Package.Value).First_Attribute :=
790 end Register_New_Attribute;
792 --------------------------
793 -- Register_New_Package --
794 --------------------------
796 procedure Register_New_Package (Name : String; Id : out Package_Node_Id) is
800 if Name'Length = 0 then
801 Fail ("cannot register a package with no name");
806 Pkg_Name := Name_Id_Of (Name);
808 for Index in Package_Attributes.First .. Package_Attributes.Last loop
809 if Package_Attributes.Table (Index).Name = Pkg_Name then
810 Fail ("cannot register a package with a non unique name"""
818 Package_Attributes.Increment_Last;
819 Id := (Value => Package_Attributes.Last);
820 Package_Attributes.Table (Package_Attributes.Last) :=
823 First_Attribute => Empty_Attr);
825 Add_Package_Name (Get_Name_String (Pkg_Name));
826 end Register_New_Package;
828 procedure Register_New_Package
830 Attributes : Attribute_Data_Array)
834 First_Attr : Attr_Node_Id := Empty_Attr;
835 Curr_Attr : Attr_Node_Id;
836 Attr_Kind : Attribute_Kind;
839 if Name'Length = 0 then
840 Fail ("cannot register a package with no name");
844 Pkg_Name := Name_Id_Of (Name);
846 for Index in Package_Attributes.First .. Package_Attributes.Last loop
847 if Package_Attributes.Table (Index).Name = Pkg_Name then
848 Fail ("cannot register a package with a non unique name"""
855 for Index in Attributes'Range loop
856 Attr_Name := Name_Id_Of (Attributes (Index).Name);
858 Curr_Attr := First_Attr;
859 while Curr_Attr /= Empty_Attr loop
860 if Attrs.Table (Curr_Attr).Name = Attr_Name then
861 Fail ("duplicate attribute name """
862 & Attributes (Index).Name
863 & """ in new package """
869 Curr_Attr := Attrs.Table (Curr_Attr).Next;
872 Attr_Kind := Attributes (Index).Attr_Kind;
874 if Attributes (Index).Index_Is_File_Name
875 and then not Osint.File_Names_Case_Sensitive
878 when Associative_Array =>
879 Attr_Kind := Case_Insensitive_Associative_Array;
881 when Optional_Index_Associative_Array =>
883 Optional_Index_Case_Insensitive_Associative_Array;
890 Attrs.Increment_Last;
891 Attrs.Table (Attrs.Last) :=
893 Var_Kind => Attributes (Index).Var_Kind,
894 Optional_Index => Attributes (Index).Opt_Index,
895 Attr_Kind => Attr_Kind,
897 Others_Allowed => False,
899 First_Attr := Attrs.Last;
902 Package_Attributes.Increment_Last;
903 Package_Attributes.Table (Package_Attributes.Last) :=
906 First_Attribute => First_Attr);
908 Add_Package_Name (Get_Name_String (Pkg_Name));
909 end Register_New_Package;
911 ---------------------------
912 -- Set_Attribute_Kind_Of --
913 ---------------------------
915 procedure Set_Attribute_Kind_Of
916 (Attribute : Attribute_Node_Id;
920 if Attribute /= Empty_Attribute then
921 Attrs.Table (Attribute.Value).Attr_Kind := To;
923 end Set_Attribute_Kind_Of;
925 --------------------------
926 -- Set_Variable_Kind_Of --
927 --------------------------
929 procedure Set_Variable_Kind_Of
930 (Attribute : Attribute_Node_Id;
934 if Attribute /= Empty_Attribute then
935 Attrs.Table (Attribute.Value).Var_Kind := To;
937 end Set_Variable_Kind_Of;
939 ----------------------
940 -- Variable_Kind_Of --
941 ----------------------
943 function Variable_Kind_Of
944 (Attribute : Attribute_Node_Id) return Variable_Kind
947 if Attribute = Empty_Attribute then
950 return Attrs.Table (Attribute.Value).Var_Kind;
952 end Variable_Kind_Of;
954 ------------------------
955 -- First_Attribute_Of --
956 ------------------------
958 function First_Attribute_Of
959 (Pkg : Package_Node_Id) return Attribute_Node_Id
962 if Pkg = Empty_Package then
963 return Empty_Attribute;
966 (Value => Package_Attributes.Table (Pkg.Value).First_Attribute);
968 end First_Attribute_Of;