1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2008, 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
60 -- End is indicated by two consecutive '#'
62 Initialization_Data
: constant String :=
64 -- project level attributes
73 "SVexternally_built#" &
80 "Lainherit_source_path#" &
81 "LVexcluded_source_dirs#" &
86 "LVlocally_removed_files#" &
87 "LVexcluded_source_files#" &
88 "SVsource_list_file#" &
95 "SVlibrary_version#" &
96 "LVlibrary_interface#" &
97 "SVlibrary_auto_init#" &
98 "LVlibrary_options#" &
99 "SVlibrary_src_dir#" &
100 "SVlibrary_ali_dir#" &
102 "SVlibrary_symbol_file#" &
103 "SVlibrary_symbol_policy#" &
104 "SVlibrary_reference_symbol_file#" &
106 -- Configuration - General
108 "SVdefault_language#" &
109 "LVrun_path_option#" &
110 "Satoolchain_version#" &
111 "Satoolchain_description#" &
113 -- Configuration - Libraries
115 "SVlibrary_builder#" &
116 "SVlibrary_support#" &
118 -- Configuration - Archives
120 "LVarchive_builder#" &
121 "LVarchive_builder_append_option#" &
122 "LVarchive_indexer#" &
123 "SVarchive_suffix#" &
124 "LVlibrary_partial_linker#" &
126 -- Configuration - Shared libraries
128 "SVshared_library_prefix#" &
129 "SVshared_library_suffix#" &
130 "SVsymbolic_link_supported#" &
131 "SVlibrary_major_minor_id_supported#" &
132 "SVlibrary_auto_init_supported#" &
133 "LVshared_library_minimum_switches#" &
134 "LVlibrary_version_switches#" &
135 "Saruntime_library_dir#" &
140 "Saspecification_suffix#" &
142 "Saimplementation_suffix#" &
144 "SVseparate_suffix#" &
146 "SVdot_replacement#" &
149 "sAimplementation#" &
151 "Laspecification_exceptions#" &
152 "Laimplementation_exceptions#" &
157 "Ladefault_switches#" &
159 "SVlocal_configuration_pragmas#" &
160 "Salocal_config_file#" &
162 -- Configuration - Compiling
165 "Larequired_switches#" &
168 -- Configuration - Mapping files
170 "Lamapping_file_switches#" &
171 "Samapping_spec_suffix#" &
172 "Samapping_body_suffix#" &
174 -- Configuration - Config files
176 "Laconfig_file_switches#" &
177 "Saconfig_body_file_name#" &
178 "Saconfig_spec_file_name#" &
179 "Saconfig_body_file_name_pattern#" &
180 "Saconfig_spec_file_name_pattern#" &
181 "Saconfig_file_unique#" &
183 -- Configuration - Dependencies
185 "Ladependency_switches#" &
186 "Ladependency_driver#" &
188 -- Configuration - Search paths
190 "Lainclude_switches#" &
192 "Sainclude_path_file#" &
197 "Ladefault_switches#" &
200 "SVexecutable_suffix#" &
201 "SVglobal_configuration_pragmas#" &
202 "Saglobal_config_file#" &
212 "Ladefault_switches#" &
215 -- Configuration - Binding
218 "Larequired_switches#" &
221 "Saobjects_path_file#" &
226 "LVrequired_switches#" &
227 "Ladefault_switches#" &
229 "LVlinker_options#" &
231 -- Configuration - Linking
234 "LVexecutable_switch#" &
235 "SVlib_dir_switch#" &
236 "SVlib_name_switch#" &
238 -- package Cross_Reference
240 "Pcross_reference#" &
241 "Ladefault_switches#" &
247 "Ladefault_switches#" &
250 -- package Pretty_Printer
253 "Ladefault_switches#" &
259 "Ladefault_switches#" &
265 "Ladefault_switches#" &
268 -- package Synchronize
271 "Ladefault_switches#" &
277 "Ladefault_switches#" &
283 "Ladefault_switches#" &
289 "Ladefault_switches#" &
292 "SVcommunication_protocol#" &
293 "Sacompiler_command#" &
294 "SVdebugger_command#" &
297 "SVvcs_file_check#" &
307 Initialized
: Boolean := False;
308 -- A flag to avoid multiple initialization
310 Package_Names
: String_List_Access
:= new Strings
.String_List
(1 .. 20);
311 Last_Package_Name
: Natural := 0;
312 -- Package_Names (1 .. Last_Package_Name) contains the list of the known
313 -- package names, coming from the Initialization_Data string or from
314 -- calls to one of the two procedures Register_New_Package.
316 procedure Add_Package_Name
(Name
: String);
317 -- Add a package name in the Package_Name list, extending it, if necessary
319 function Name_Id_Of
(Name
: String) return Name_Id
;
320 -- Returns the Name_Id for Name in lower case
322 ----------------------
323 -- Add_Package_Name --
324 ----------------------
326 procedure Add_Package_Name
(Name
: String) is
328 if Last_Package_Name
= Package_Names
'Last then
330 New_List
: constant Strings
.String_List_Access
:=
331 new Strings
.String_List
(1 .. Package_Names
'Last * 2);
333 New_List
(Package_Names
'Range) := Package_Names
.all;
334 Package_Names
:= New_List
;
338 Last_Package_Name
:= Last_Package_Name
+ 1;
339 Package_Names
(Last_Package_Name
) := new String'(Name);
340 end Add_Package_Name;
342 -----------------------
343 -- Attribute_Kind_Of --
344 -----------------------
346 function Attribute_Kind_Of
347 (Attribute : Attribute_Node_Id) return Attribute_Kind
350 if Attribute = Empty_Attribute then
353 return Attrs.Table (Attribute.Value).Attr_Kind;
355 end Attribute_Kind_Of;
357 -----------------------
358 -- Attribute_Name_Of --
359 -----------------------
361 function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id is
363 if Attribute = Empty_Attribute then
366 return Attrs.Table (Attribute.Value).Name;
368 end Attribute_Name_Of;
370 --------------------------
371 -- Attribute_Node_Id_Of --
372 --------------------------
374 function Attribute_Node_Id_Of
376 Starting_At : Attribute_Node_Id) return Attribute_Node_Id
378 Id : Attr_Node_Id := Starting_At.Value;
381 while Id /= Empty_Attr
382 and then Attrs.Table (Id).Name /= Name
384 Id := Attrs.Table (Id).Next;
387 return (Value => Id);
388 end Attribute_Node_Id_Of;
394 procedure Initialize is
395 Start : Positive := Initialization_Data'First;
396 Finish : Positive := Start;
397 Current_Package : Pkg_Node_Id := Empty_Pkg;
398 Current_Attribute : Attr_Node_Id := Empty_Attr;
399 Is_An_Attribute : Boolean := False;
400 Var_Kind : Variable_Kind := Undefined;
401 Optional_Index : Boolean := False;
402 Attr_Kind : Attribute_Kind := Single;
403 Package_Name : Name_Id := No_Name;
404 Attribute_Name : Name_Id := No_Name;
405 First_Attribute : Attr_Node_Id := Attr.First_Attribute;
408 function Attribute_Location return String;
409 -- Returns a string depending if we are in the project level attributes
410 -- or in the attributes of a package.
412 ------------------------
413 -- Attribute_Location --
414 ------------------------
416 function Attribute_Location return String is
418 if Package_Name = No_Name then
419 return "project level attributes";
422 return "attribute of package """ &
423 Get_Name_String (Package_Name) & """";
425 end Attribute_Location;
427 -- Start of processing for Initialize
430 -- Don't allow Initialize action to be repeated
436 -- Make sure the two tables are empty
439 Package_Attributes.Init;
441 while Initialization_Data (Start) /= '#
' loop
442 Is_An_Attribute := True;
443 case Initialization_Data (Start) is
446 -- New allowed package
451 while Initialization_Data (Finish) /= '#
' loop
452 Finish := Finish + 1;
456 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
458 for Index in First_Package .. Package_Attributes.Last loop
459 if Package_Name = Package_Attributes.Table (Index).Name then
460 Osint.Fail ("duplicate name """,
461 Initialization_Data (Start .. Finish - 1),
462 """ in predefined packages.");
466 Is_An_Attribute := False;
467 Current_Attribute := Empty_Attr;
468 Package_Attributes.Increment_Last;
469 Current_Package := Package_Attributes.Last;
470 Package_Attributes.Table (Current_Package) :=
471 (Name => Package_Name,
473 First_Attribute => Empty_Attr);
476 Add_Package_Name (Get_Name_String (Package_Name));
480 Optional_Index := False;
484 Optional_Index := True;
488 Optional_Index := False;
492 Optional_Index := True;
498 if Is_An_Attribute then
503 case Initialization_Data (Start) is
508 Attr_Kind := Associative_Array;
511 Attr_Kind := Case_Insensitive_Associative_Array;
514 if Osint.File_Names_Case_Sensitive then
515 Attr_Kind := Associative_Array;
517 Attr_Kind := Case_Insensitive_Associative_Array;
521 if Osint.File_Names_Case_Sensitive then
522 Attr_Kind := Optional_Index_Associative_Array;
525 Optional_Index_Case_Insensitive_Associative_Array;
534 if Initialization_Data (Start) = 'R
' then
544 while Initialization_Data (Finish) /= '#
' loop
545 Finish := Finish + 1;
549 Name_Id_Of (Initialization_Data (Start .. Finish - 1));
550 Attrs.Increment_Last;
552 if Current_Attribute = Empty_Attr then
553 First_Attribute := Attrs.Last;
555 if Current_Package /= Empty_Pkg then
556 Package_Attributes.Table (Current_Package).First_Attribute
561 -- Check that there are no duplicate attributes
563 for Index in First_Attribute .. Attrs.Last - 1 loop
564 if Attribute_Name = Attrs.Table (Index).Name then
565 Osint.Fail ("duplicate attribute """,
566 Initialization_Data (Start .. Finish - 1),
567 """ in " & Attribute_Location);
571 Attrs.Table (Current_Attribute).Next :=
575 Current_Attribute := Attrs.Last;
576 Attrs.Table (Current_Attribute) :=
577 (Name => Attribute_Name,
578 Var_Kind => Var_Kind,
579 Optional_Index => Optional_Index,
580 Attr_Kind => Attr_Kind,
581 Read_Only => Read_Only,
594 function Is_Read_Only (Attribute : Attribute_Node_Id) return Boolean is
596 return Attrs.Table (Attribute.Value).Read_Only;
603 function Name_Id_Of (Name : String) return Name_Id is
606 Add_Str_To_Name_Buffer (Name);
607 To_Lower (Name_Buffer (1 .. Name_Len));
615 function Next_Attribute
616 (After : Attribute_Node_Id) return Attribute_Node_Id
619 if After = Empty_Attribute then
620 return Empty_Attribute;
622 return (Value => Attrs.Table (After.Value).Next);
626 -----------------------
627 -- Optional_Index_Of --
628 -----------------------
630 function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean is
632 if Attribute = Empty_Attribute then
635 return Attrs.Table (Attribute.Value).Optional_Index;
637 end Optional_Index_Of;
639 -----------------------
640 -- Package_Name_List --
641 -----------------------
643 function Package_Name_List return Strings.String_List is
645 return Package_Names (1 .. Last_Package_Name);
646 end Package_Name_List;
648 ------------------------
649 -- Package_Node_Id_Of --
650 ------------------------
652 function Package_Node_Id_Of (Name : Name_Id) return Package_Node_Id is
654 for Index in Package_Attributes.First .. Package_Attributes.Last loop
655 if Package_Attributes.Table (Index).Name = Name then
656 if Package_Attributes.Table (Index).Known then
657 return (Value => Index);
659 return Unknown_Package;
664 -- If there is no package with this name, return Empty_Package
666 return Empty_Package;
667 end Package_Node_Id_Of;
669 ----------------------------
670 -- Register_New_Attribute --
671 ----------------------------
673 procedure Register_New_Attribute
675 In_Package : Package_Node_Id;
676 Attr_Kind : Defined_Attribute_Kind;
677 Var_Kind : Defined_Variable_Kind;
678 Index_Is_File_Name : Boolean := False;
679 Opt_Index : Boolean := False)
682 First_Attr : Attr_Node_Id := Empty_Attr;
683 Curr_Attr : Attr_Node_Id;
684 Real_Attr_Kind : Attribute_Kind;
687 if Name'Length = 0 then
688 Fail ("cannot register an attribute with no name");
692 if In_Package = Empty_Package then
693 Fail ("attempt to add attribute """, Name,
694 """ to an undefined package");
698 Attr_Name := Name_Id_Of (Name);
701 Package_Attributes.Table (In_Package.Value).First_Attribute;
703 -- Check if attribute name is a duplicate
705 Curr_Attr := First_Attr;
706 while Curr_Attr /= Empty_Attr loop
707 if Attrs.Table (Curr_Attr).Name = Attr_Name then
708 Fail ("duplicate attribute name """, Name,
711 (Package_Attributes.Table (In_Package.Value).Name) &
716 Curr_Attr := Attrs.Table (Curr_Attr).Next;
719 Real_Attr_Kind := Attr_Kind;
721 -- If Index_Is_File_Name, change the attribute kind if necessary
723 if Index_Is_File_Name and then not Osint.File_Names_Case_Sensitive then
725 when Associative_Array =>
726 Real_Attr_Kind := Case_Insensitive_Associative_Array;
728 when Optional_Index_Associative_Array =>
730 Optional_Index_Case_Insensitive_Associative_Array;
737 -- Add the new attribute
739 Attrs.Increment_Last;
740 Attrs.Table (Attrs.Last) :=
742 Var_Kind => Var_Kind,
743 Optional_Index => Opt_Index,
744 Attr_Kind => Real_Attr_Kind,
748 Package_Attributes.Table (In_Package.Value).First_Attribute :=
750 end Register_New_Attribute;
752 --------------------------
753 -- Register_New_Package --
754 --------------------------
756 procedure Register_New_Package (Name : String; Id : out Package_Node_Id) is
760 if Name'Length = 0 then
761 Fail ("cannot register a package with no name");
766 Pkg_Name := Name_Id_Of (Name);
768 for Index in Package_Attributes.First .. Package_Attributes.Last loop
769 if Package_Attributes.Table (Index).Name = Pkg_Name then
770 Fail ("cannot register a package with a non unique name""",
777 Package_Attributes.Increment_Last;
778 Id := (Value => Package_Attributes.Last);
779 Package_Attributes.Table (Package_Attributes.Last) :=
782 First_Attribute => Empty_Attr);
784 Add_Package_Name (Get_Name_String (Pkg_Name));
785 end Register_New_Package;
787 procedure Register_New_Package
789 Attributes : Attribute_Data_Array)
793 First_Attr : Attr_Node_Id := Empty_Attr;
794 Curr_Attr : Attr_Node_Id;
795 Attr_Kind : Attribute_Kind;
798 if Name'Length = 0 then
799 Fail ("cannot register a package with no name");
803 Pkg_Name := Name_Id_Of (Name);
805 for Index in Package_Attributes.First .. Package_Attributes.Last loop
806 if Package_Attributes.Table (Index).Name = Pkg_Name then
807 Fail ("cannot register a package with a non unique name""",
813 for Index in Attributes'Range loop
814 Attr_Name := Name_Id_Of (Attributes (Index).Name);
816 Curr_Attr := First_Attr;
817 while Curr_Attr /= Empty_Attr loop
818 if Attrs.Table (Curr_Attr).Name = Attr_Name then
819 Fail ("duplicate attribute name """, Attributes (Index).Name,
820 """ in new package """ & Name & """");
824 Curr_Attr := Attrs.Table (Curr_Attr).Next;
827 Attr_Kind := Attributes (Index).Attr_Kind;
829 if Attributes (Index).Index_Is_File_Name
830 and then not Osint.File_Names_Case_Sensitive
833 when Associative_Array =>
834 Attr_Kind := Case_Insensitive_Associative_Array;
836 when Optional_Index_Associative_Array =>
838 Optional_Index_Case_Insensitive_Associative_Array;
845 Attrs.Increment_Last;
846 Attrs.Table (Attrs.Last) :=
848 Var_Kind => Attributes (Index).Var_Kind,
849 Optional_Index => Attributes (Index).Opt_Index,
850 Attr_Kind => Attr_Kind,
853 First_Attr := Attrs.Last;
856 Package_Attributes.Increment_Last;
857 Package_Attributes.Table (Package_Attributes.Last) :=
860 First_Attribute => First_Attr);
862 Add_Package_Name (Get_Name_String (Pkg_Name));
863 end Register_New_Package;
865 ---------------------------
866 -- Set_Attribute_Kind_Of --
867 ---------------------------
869 procedure Set_Attribute_Kind_Of
870 (Attribute : Attribute_Node_Id;
874 if Attribute /= Empty_Attribute then
875 Attrs.Table (Attribute.Value).Attr_Kind := To;
877 end Set_Attribute_Kind_Of;
879 --------------------------
880 -- Set_Variable_Kind_Of --
881 --------------------------
883 procedure Set_Variable_Kind_Of
884 (Attribute : Attribute_Node_Id;
888 if Attribute /= Empty_Attribute then
889 Attrs.Table (Attribute.Value).Var_Kind := To;
891 end Set_Variable_Kind_Of;
893 ----------------------
894 -- Variable_Kind_Of --
895 ----------------------
897 function Variable_Kind_Of
898 (Attribute : Attribute_Node_Id) return Variable_Kind
901 if Attribute = Empty_Attribute then
904 return Attrs.Table (Attribute.Value).Var_Kind;
906 end Variable_Kind_Of;
908 ------------------------
909 -- First_Attribute_Of --
910 ------------------------
912 function First_Attribute_Of
913 (Pkg : Package_Node_Id) return Attribute_Node_Id
916 if Pkg = Empty_Package then
917 return Empty_Attribute;
920 (Value => Package_Attributes.Table (Pkg.Value).First_Attribute);
922 end First_Attribute_Of;