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#" &
176 "Laleading_required_switches#" &
177 "Latrailing_required_switches#" &
180 "Saobject_file_suffix#" &
181 "Laobject_file_switches#" &
183 -- Configuration - Mapping files
185 "Lamapping_file_switches#" &
186 "Samapping_spec_suffix#" &
187 "Samapping_body_suffix#" &
189 -- Configuration - Config files
191 "Laconfig_file_switches#" &
192 "Saconfig_body_file_name#" &
193 "Saconfig_spec_file_name#" &
194 "Saconfig_body_file_name_pattern#" &
195 "Saconfig_spec_file_name_pattern#" &
196 "Saconfig_file_unique#" &
198 -- Configuration - Dependencies
200 "Ladependency_switches#" &
201 "Ladependency_driver#" &
203 -- Configuration - Search paths
205 "Lainclude_switches#" &
207 "Sainclude_path_file#" &
212 "Ladefault_switches#" &
214 "Lcglobal_compilation_switches#" &
216 "SVexecutable_suffix#" &
217 "SVglobal_configuration_pragmas#" &
218 "Saglobal_config_file#" &
228 "Ladefault_switches#" &
231 -- Configuration - Binding
234 "Larequired_switches#" &
237 "Saobjects_path_file#" &
242 "LVrequired_switches#" &
243 "Ladefault_switches#" &
245 "LVlinker_options#" &
246 "SVmap_file_option#" &
248 -- Configuration - Linking
251 "LVexecutable_switch#" &
252 "SVlib_dir_switch#" &
253 "SVlib_name_switch#" &
255 -- Configuration - Response files
257 "SVmax_command_line_length#" &
258 "SVresponse_file_format#" &
259 "LVresponse_file_switches#" &
261 -- package Cross_Reference
263 "Pcross_reference#" &
264 "Ladefault_switches#" &
270 "Ladefault_switches#" &
273 -- package Pretty_Printer
276 "Ladefault_switches#" &
282 "Ladefault_switches#" &
288 "Ladefault_switches#" &
291 -- package Synchronize
294 "Ladefault_switches#" &
300 "Ladefault_switches#" &
306 "Ladefault_switches#" &
312 "Ladefault_switches#" &
315 "SVcommunication_protocol#" &
316 "Sacompiler_command#" &
317 "SVdebugger_command#" &
320 "SVvcs_file_check#" &
330 Initialized : Boolean := False;
331 -- A flag to avoid multiple initialization
333 Package_Names : String_List_Access := new Strings.String_List (1 .. 20);
334 Last_Package_Name : Natural := 0;
335 -- Package_Names (1 .. Last_Package_Name) contains the list of the known
336 -- package names, coming from the Initialization_Data string or from
337 -- calls to one of the two procedures Register_New_Package.
339 procedure Add_Package_Name (Name : String);
340 -- Add a package name in the Package_Name list, extending it, if necessary
342 function Name_Id_Of (Name : String) return Name_Id;
343 -- Returns the Name_Id for Name in lower case
345 ----------------------
346 -- Add_Package_Name --
347 ----------------------
349 procedure Add_Package_Name (Name : String) is
351 if Last_Package_Name = Package_Names'Last then
353 New_List : constant Strings.String_List_Access :=
354 new Strings.String_List (1 .. Package_Names'Last * 2);
356 New_List (Package_Names'Range) := Package_Names.all;
357 Package_Names := New_List;
361 Last_Package_Name := Last_Package_Name + 1;
362 Package_Names (Last_Package_Name) := new String'(Name);
363 end Add_Package_Name;
365 -----------------------
366 -- Attribute_Kind_Of --
367 -----------------------
369 function Attribute_Kind_Of
370 (Attribute : Attribute_Node_Id) return Attribute_Kind
373 if Attribute = Empty_Attribute then
376 return Attrs.Table (Attribute.Value).Attr_Kind;
378 end Attribute_Kind_Of;
380 -----------------------
381 -- Attribute_Name_Of --
382 -----------------------
384 function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id is
386 if Attribute = Empty_Attribute then
389 return Attrs.Table (Attribute.Value).Name;
391 end Attribute_Name_Of;
393 --------------------------
394 -- Attribute_Node_Id_Of --
395 --------------------------
397 function Attribute_Node_Id_Of
399 Starting_At : Attribute_Node_Id) return Attribute_Node_Id
401 Id : Attr_Node_Id := Starting_At.Value;
404 while Id /= Empty_Attr
405 and then Attrs.Table (Id).Name /= Name
407 Id := Attrs.Table (Id).Next;
410 return (Value => Id);
411 end Attribute_Node_Id_Of;
417 procedure Initialize is
418 Start : Positive := Initialization_Data'First;
419 Finish : Positive := Start;
420 Current_Package : Pkg_Node_Id := Empty_Pkg;
421 Current_Attribute : Attr_Node_Id := Empty_Attr;
422 Is_An_Attribute : Boolean := False;
423 Var_Kind : Variable_Kind := Undefined;
424 Optional_Index : Boolean := False;
425 Attr_Kind : Attribute_Kind := Single;
426 Package_Name : Name_Id := No_Name;
427 Attribute_Name : Name_Id := No_Name;
428 First_Attribute : Attr_Node_Id := Attr.First_Attribute;
430 Others_Allowed : Boolean;
432 function Attribute_Location return String;
433 -- Returns a string depending if we are in the project level attributes
434 -- or in the attributes of a package.
436 ------------------------
437 -- Attribute_Location --
438 ------------------------
440 function Attribute_Location return String is
442 if Package_Name = No_Name then
443 return "project level attributes";
446 return "attribute of package """ &
447 Get_Name_String (Package_Name) & """";
449 end Attribute_Location;
451 -- Start of processing for Initialize
454 -- Don't allow Initialize action to be repeated
460 -- Make sure the two tables are empty
463 Package_Attributes.Init;
465 while Initialization_Data (Start) /= '#' loop
466 Is_An_Attribute := True;
467 case Initialization_Data (Start) is
470 -- New allowed package
475 while Initialization_Data (Finish) /= '#' loop
476 Finish := Finish + 1;
480 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
482 for Index in First_Package .. Package_Attributes.Last loop
483 if Package_Name = Package_Attributes.Table (Index).Name then
484 Osint.Fail ("duplicate name """
485 & Initialization_Data (Start .. Finish - 1)
486 & """ in predefined packages.");
490 Is_An_Attribute := False;
491 Current_Attribute := Empty_Attr;
492 Package_Attributes.Increment_Last;
493 Current_Package := Package_Attributes.Last;
494 Package_Attributes.Table (Current_Package) :=
495 (Name => Package_Name,
497 First_Attribute => Empty_Attr);
500 Add_Package_Name (Get_Name_String (Package_Name));
504 Optional_Index := False;
508 Optional_Index := True;
512 Optional_Index := False;
516 Optional_Index := True;
522 if Is_An_Attribute then
527 case Initialization_Data (Start) is
532 Attr_Kind := Associative_Array;
535 Attr_Kind := Case_Insensitive_Associative_Array;
538 if Osint.File_Names_Case_Sensitive then
539 Attr_Kind := Associative_Array;
541 Attr_Kind := Case_Insensitive_Associative_Array;
545 if Osint.File_Names_Case_Sensitive then
546 Attr_Kind := Optional_Index_Associative_Array;
549 Optional_Index_Case_Insensitive_Associative_Array;
559 Others_Allowed := False;
561 if Initialization_Data (Start) = 'R' then
565 elsif Initialization_Data (Start) = 'O' then
566 Others_Allowed := True;
572 while Initialization_Data (Finish) /= '#' loop
573 Finish := Finish + 1;
577 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
578 Attrs.Increment_Last;
580 if Current_Attribute = Empty_Attr then
581 First_Attribute := Attrs.Last;
583 if Current_Package /= Empty_Pkg then
584 Package_Attributes.Table (Current_Package).First_Attribute
589 -- Check that there are no duplicate attributes
591 for Index in First_Attribute .. Attrs.Last - 1 loop
592 if Attribute_Name = Attrs.Table (Index).Name then
593 Osint.Fail ("duplicate attribute """
594 & Initialization_Data (Start .. Finish - 1)
595 & """ in " & Attribute_Location);
599 Attrs.Table (Current_Attribute).Next :=
603 Current_Attribute := Attrs.Last;
604 Attrs.Table (Current_Attribute) :=
605 (Name => Attribute_Name,
606 Var_Kind => Var_Kind,
607 Optional_Index => Optional_Index,
608 Attr_Kind => Attr_Kind,
609 Read_Only => Read_Only,
610 Others_Allowed => Others_Allowed,
623 function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean is
625 return Attrs.Table (Attribute.Value).Read_Only;
632 function Name_Id_Of (Name : String) return Name_Id is
635 Add_Str_To_Name_Buffer (Name);
636 To_Lower (Name_Buffer (1 .. Name_Len));
644 function Next_Attribute
645 (After : Attribute_Node_Id) return Attribute_Node_Id
648 if After = Empty_Attribute then
649 return Empty_Attribute;
651 return (Value => Attrs.Table (After.Value).Next);
655 -----------------------
656 -- Optional_Index_Of --
657 -----------------------
659 function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean is
661 if Attribute = Empty_Attribute then
664 return Attrs.Table (Attribute.Value).Optional_Index;
666 end Optional_Index_Of;
668 function Others_Allowed_For
669 (Attribute : Attribute_Node_Id) return Boolean
672 if Attribute = Empty_Attribute then
675 return Attrs.Table (Attribute.Value).Others_Allowed;
677 end Others_Allowed_For;
679 -----------------------
680 -- Package_Name_List --
681 -----------------------
683 function Package_Name_List return Strings.String_List is
685 return Package_Names (1 .. Last_Package_Name);
686 end Package_Name_List;
688 ------------------------
689 -- Package_Node_Id_Of --
690 ------------------------
692 function Package_Node_Id_Of (Name : Name_Id) return Package_Node_Id is
694 for Index in Package_Attributes.First .. Package_Attributes.Last loop
695 if Package_Attributes.Table (Index).Name = Name then
696 if Package_Attributes.Table (Index).Known then
697 return (Value => Index);
699 return Unknown_Package;
704 -- If there is no package with this name, return Empty_Package
706 return Empty_Package;
707 end Package_Node_Id_Of;
709 ----------------------------
710 -- Register_New_Attribute --
711 ----------------------------
713 procedure Register_New_Attribute
715 In_Package : Package_Node_Id;
716 Attr_Kind : Defined_Attribute_Kind;
717 Var_Kind : Defined_Variable_Kind;
718 Index_Is_File_Name : Boolean := False;
719 Opt_Index : Boolean := False)
722 First_Attr : Attr_Node_Id := Empty_Attr;
723 Curr_Attr : Attr_Node_Id;
724 Real_Attr_Kind : Attribute_Kind;
727 if Name'Length = 0 then
728 Fail ("cannot register an attribute with no name");
732 if In_Package = Empty_Package then
733 Fail ("attempt to add attribute """
735 & """ to an undefined package");
739 Attr_Name := Name_Id_Of (Name);
742 Package_Attributes.Table (In_Package.Value).First_Attribute;
744 -- Check if attribute name is a duplicate
746 Curr_Attr := First_Attr;
747 while Curr_Attr /= Empty_Attr loop
748 if Attrs.Table (Curr_Attr).Name = Attr_Name then
749 Fail ("duplicate attribute name """
753 (Package_Attributes.Table (In_Package.Value).Name)
758 Curr_Attr := Attrs.Table (Curr_Attr).Next;
761 Real_Attr_Kind := Attr_Kind;
763 -- If Index_Is_File_Name, change the attribute kind if necessary
765 if Index_Is_File_Name and then not Osint.File_Names_Case_Sensitive then
767 when Associative_Array =>
768 Real_Attr_Kind := Case_Insensitive_Associative_Array;
770 when Optional_Index_Associative_Array =>
772 Optional_Index_Case_Insensitive_Associative_Array;
779 -- Add the new attribute
781 Attrs.Increment_Last;
782 Attrs.Table (Attrs.Last) :=
784 Var_Kind => Var_Kind,
785 Optional_Index => Opt_Index,
786 Attr_Kind => Real_Attr_Kind,
788 Others_Allowed => False,
791 Package_Attributes.Table (In_Package.Value).First_Attribute :=
793 end Register_New_Attribute;
795 --------------------------
796 -- Register_New_Package --
797 --------------------------
799 procedure Register_New_Package (Name : String; Id : out Package_Node_Id) is
803 if Name'Length = 0 then
804 Fail ("cannot register a package with no name");
809 Pkg_Name := Name_Id_Of (Name);
811 for Index in Package_Attributes.First .. Package_Attributes.Last loop
812 if Package_Attributes.Table (Index).Name = Pkg_Name then
813 Fail ("cannot register a package with a non unique name"""
821 Package_Attributes.Increment_Last;
822 Id := (Value => Package_Attributes.Last);
823 Package_Attributes.Table (Package_Attributes.Last) :=
826 First_Attribute => Empty_Attr);
828 Add_Package_Name (Get_Name_String (Pkg_Name));
829 end Register_New_Package;
831 procedure Register_New_Package
833 Attributes : Attribute_Data_Array)
837 First_Attr : Attr_Node_Id := Empty_Attr;
838 Curr_Attr : Attr_Node_Id;
839 Attr_Kind : Attribute_Kind;
842 if Name'Length = 0 then
843 Fail ("cannot register a package with no name");
847 Pkg_Name := Name_Id_Of (Name);
849 for Index in Package_Attributes.First .. Package_Attributes.Last loop
850 if Package_Attributes.Table (Index).Name = Pkg_Name then
851 Fail ("cannot register a package with a non unique name"""
858 for Index in Attributes'Range loop
859 Attr_Name := Name_Id_Of (Attributes (Index).Name);
861 Curr_Attr := First_Attr;
862 while Curr_Attr /= Empty_Attr loop
863 if Attrs.Table (Curr_Attr).Name = Attr_Name then
864 Fail ("duplicate attribute name """
865 & Attributes (Index).Name
866 & """ in new package """
872 Curr_Attr := Attrs.Table (Curr_Attr).Next;
875 Attr_Kind := Attributes (Index).Attr_Kind;
877 if Attributes (Index).Index_Is_File_Name
878 and then not Osint.File_Names_Case_Sensitive
881 when Associative_Array =>
882 Attr_Kind := Case_Insensitive_Associative_Array;
884 when Optional_Index_Associative_Array =>
886 Optional_Index_Case_Insensitive_Associative_Array;
893 Attrs.Increment_Last;
894 Attrs.Table (Attrs.Last) :=
896 Var_Kind => Attributes (Index).Var_Kind,
897 Optional_Index => Attributes (Index).Opt_Index,
898 Attr_Kind => Attr_Kind,
900 Others_Allowed => False,
902 First_Attr := Attrs.Last;
905 Package_Attributes.Increment_Last;
906 Package_Attributes.Table (Package_Attributes.Last) :=
909 First_Attribute => First_Attr);
911 Add_Package_Name (Get_Name_String (Pkg_Name));
912 end Register_New_Package;
914 ---------------------------
915 -- Set_Attribute_Kind_Of --
916 ---------------------------
918 procedure Set_Attribute_Kind_Of
919 (Attribute : Attribute_Node_Id;
923 if Attribute /= Empty_Attribute then
924 Attrs.Table (Attribute.Value).Attr_Kind := To;
926 end Set_Attribute_Kind_Of;
928 --------------------------
929 -- Set_Variable_Kind_Of --
930 --------------------------
932 procedure Set_Variable_Kind_Of
933 (Attribute : Attribute_Node_Id;
937 if Attribute /= Empty_Attribute then
938 Attrs.Table (Attribute.Value).Var_Kind := To;
940 end Set_Variable_Kind_Of;
942 ----------------------
943 -- Variable_Kind_Of --
944 ----------------------
946 function Variable_Kind_Of
947 (Attribute : Attribute_Node_Id) return Variable_Kind
950 if Attribute = Empty_Attribute then
953 return Attrs.Table (Attribute.Value).Var_Kind;
955 end Variable_Kind_Of;
957 ------------------------
958 -- First_Attribute_Of --
959 ------------------------
961 function First_Attribute_Of
962 (Pkg : Package_Node_Id) return Attribute_Node_Id
965 if Pkg = Empty_Package then
966 return Empty_Attribute;
969 (Value => Package_Attributes.Table (Pkg.Value).First_Attribute);
971 end First_Attribute_Of;