OSDN Git Service

* sysdep.c: Problem discovered during IA64 VMS port.
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-attr.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             P R J . A T T R                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --             Copyright (C) 2001-2003 Free Software Foundation, Inc.       --
10 --                                                                          --
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 2,  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 COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Ada.Characters.Handling; use Ada.Characters.Handling;
28 with Namet;     use Namet;
29 with Osint;     use Osint;
30 with Output;    use Output;
31
32 package body Prj.Attr is
33
34    --  Names end with '#'
35
36    --  Package names are preceded by 'P'
37
38    --  Attribute names are preceded by two letters
39
40    --  The first letter is one of
41    --    'S' for Single
42    --    'L' for list
43
44    --  The second letter is one of
45    --    'V' for single variable
46    --    'A' for associative array
47    --    'a' for case insensitive associative array
48    --    'b' for associative array, case insensitive if file names are case
49    --        insensitive
50
51    --  End is indicated by two consecutive '#'.
52
53    Initialization_Data : constant String :=
54
55    --  project attributes
56
57      "SVobject_dir#" &
58      "SVexec_dir#" &
59      "LVsource_dirs#" &
60      "LVsource_files#" &
61      "LVlocally_removed_files#" &
62      "SVsource_list_file#" &
63      "SVlibrary_dir#" &
64      "SVlibrary_name#" &
65      "SVlibrary_kind#" &
66      "SVlibrary_version#" &
67      "LVlibrary_interface#" &
68      "SVlibrary_auto_init#" &
69      "LVlibrary_options#" &
70      "SVlibrary_src_dir#" &
71      "SVlibrary_gcc#" &
72      "LVmain#" &
73      "LVlanguages#" &
74      "SVmain_language#" &
75
76    --  package Naming
77
78      "Pnaming#" &
79      "Saspecification_suffix#" &
80      "Saspec_suffix#" &
81      "Saimplementation_suffix#" &
82      "Sabody_suffix#" &
83      "SVseparate_suffix#" &
84      "SVcasing#" &
85      "SVdot_replacement#" &
86      "SAspecification#" &
87      "SAspec#" &
88      "SAimplementation#" &
89      "SAbody#" &
90      "Laspecification_exceptions#" &
91      "Laimplementation_exceptions#" &
92
93    --  package Compiler
94
95      "Pcompiler#" &
96      "Ladefault_switches#" &
97      "Lbswitches#" &
98      "SVlocal_configuration_pragmas#" &
99
100    --  package Builder
101
102      "Pbuilder#" &
103      "Ladefault_switches#" &
104      "Lbswitches#" &
105      "SAexecutable#" &
106      "SVexecutable_suffix#" &
107      "SVglobal_configuration_pragmas#" &
108
109    --  package gnatls
110
111      "Pgnatls#" &
112      "LVswitches#" &
113
114    --  package Binder
115
116      "Pbinder#" &
117      "Ladefault_switches#" &
118      "Lbswitches#" &
119
120    --  package Linker
121
122      "Plinker#" &
123      "Ladefault_switches#" &
124      "Lbswitches#" &
125      "LVlinker_options#" &
126
127    --  package Cross_Reference
128
129      "Pcross_reference#" &
130      "Ladefault_switches#" &
131      "Lbswitches#" &
132
133    --  package Finder
134
135      "Pfinder#" &
136      "Ladefault_switches#" &
137      "Lbswitches#" &
138
139    --  package Pretty_Printer
140
141      "Ppretty_printer#" &
142      "Ladefault_switches#" &
143      "Lbswitches#" &
144
145    --  package gnatstub
146
147      "Pgnatstub#" &
148      "Ladefault_switches#" &
149      "Lbswitches#" &
150
151    --  package Eliminate
152
153      "Peliminate#" &
154      "Ladefault_switches#" &
155      "Lbswitches#" &
156
157    --  package Ide
158
159      "Pide#" &
160      "Ladefault_switches#" &
161      "SVremote_host#" &
162      "SVprogram_host#" &
163      "SVcommunication_protocol#" &
164      "Sacompiler_command#" &
165      "SVdebugger_command#" &
166      "SVgnatlist#" &
167      "SVvcs_kind#" &
168      "SVvcs_file_check#" &
169      "SVvcs_log_check#" &
170
171      "#";
172
173    ----------------
174    -- Initialize --
175    ----------------
176
177    procedure Initialize is
178       Start             : Positive           := Initialization_Data'First;
179       Finish            : Positive           := Start;
180       Current_Package   : Package_Node_Id    := Empty_Package;
181       Current_Attribute : Attribute_Node_Id  := Empty_Attribute;
182       Is_An_Attribute   : Boolean            := False;
183       Kind_1            : Variable_Kind      := Undefined;
184       Kind_2            : Attribute_Kind     := Single;
185       Package_Name      : Name_Id            := No_Name;
186       Attribute_Name    : Name_Id            := No_Name;
187       First_Attribute   : Attribute_Node_Id  := Attribute_First;
188
189    begin
190       --  Make sure the two tables are empty
191
192       Attributes.Init;
193       Package_Attributes.Init;
194
195       while Initialization_Data (Start) /= '#' loop
196          Is_An_Attribute := True;
197          case Initialization_Data (Start) is
198             when 'P' =>
199
200                --  New allowed package
201
202                Start := Start + 1;
203
204                Finish := Start;
205                while Initialization_Data (Finish) /= '#' loop
206                   Finish := Finish + 1;
207                end loop;
208
209                Name_Len := Finish - Start;
210                Name_Buffer (1 .. Name_Len) :=
211                  To_Lower (Initialization_Data (Start .. Finish - 1));
212                Package_Name := Name_Find;
213
214                for Index in Package_First .. Package_Attributes.Last loop
215                   if Package_Name = Package_Attributes.Table (Index).Name then
216                      Write_Line ("Duplicate package name """ &
217                                  Initialization_Data (Start .. Finish - 1) &
218                                  """ in Prj.Attr body.");
219                      raise Program_Error;
220                   end if;
221                end loop;
222
223                Is_An_Attribute := False;
224                Current_Attribute := Empty_Attribute;
225                Package_Attributes.Increment_Last;
226                Current_Package := Package_Attributes.Last;
227                Package_Attributes.Table (Current_Package).Name :=
228                  Package_Name;
229                Start := Finish + 1;
230
231             when 'S' =>
232                Kind_1 := Single;
233
234             when 'L' =>
235                Kind_1 := List;
236
237             when others =>
238                raise Program_Error;
239          end case;
240
241          if Is_An_Attribute then
242
243             --  New attribute
244
245             Start := Start + 1;
246             case Initialization_Data (Start) is
247                when 'V' =>
248                   Kind_2 := Single;
249
250                when 'A' =>
251                   Kind_2 := Associative_Array;
252
253                when 'a' =>
254                   Kind_2 := Case_Insensitive_Associative_Array;
255
256                when 'b' =>
257                   if File_Names_Case_Sensitive then
258                      Kind_2 := Case_Insensitive_Associative_Array;
259                   else
260                      Kind_2 := Case_Insensitive_Associative_Array;
261                   end if;
262
263                when others =>
264                   raise Program_Error;
265             end case;
266
267             Start := Start + 1;
268             Finish := Start;
269
270             while Initialization_Data (Finish) /= '#' loop
271                Finish := Finish + 1;
272             end loop;
273
274             Name_Len := Finish - Start;
275             Name_Buffer (1 .. Name_Len) :=
276               To_Lower (Initialization_Data (Start .. Finish - 1));
277             Attribute_Name := Name_Find;
278             Attributes.Increment_Last;
279             if Current_Attribute = Empty_Attribute then
280                First_Attribute := Attributes.Last;
281
282                if Current_Package /= Empty_Package then
283                   Package_Attributes.Table (Current_Package).First_Attribute
284                     := Attributes.Last;
285                end if;
286
287             else
288                --  Check that there are no duplicate attributes
289
290                for Index in First_Attribute .. Attributes.Last - 1 loop
291                   if Attribute_Name =
292                     Attributes.Table (Index).Name then
293                      Write_Line ("Duplicate attribute name """ &
294                                  Initialization_Data (Start .. Finish - 1) &
295                                  """ in Prj.Attr body.");
296                      raise Program_Error;
297                   end if;
298                end loop;
299
300                Attributes.Table (Current_Attribute).Next :=
301                  Attributes.Last;
302             end if;
303
304             Current_Attribute := Attributes.Last;
305             Attributes.Table (Current_Attribute) :=
306               (Name    => Attribute_Name,
307                Kind_1  => Kind_1,
308                Kind_2  => Kind_2,
309                Next    => Empty_Attribute);
310             Start := Finish + 1;
311          end if;
312       end loop;
313    end Initialize;
314
315 end Prj.Attr;