OSDN Git Service

* 41intnam.ads, 42intnam.ads, 4aintnam.ads, 4cintnam.ads,
[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 --                            $Revision$
10 --                                                                          --
11 --             Copyright (C) 2001-2002 Free Software Foundation, Inc.       --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- GNAT was originally developed  by the GNAT team at  New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 --                                                                          --
27 ------------------------------------------------------------------------------
28
29 with Ada.Characters.Handling; use Ada.Characters.Handling;
30 with Namet;     use Namet;
31 with Output;    use Output;
32
33 package body Prj.Attr is
34
35    --  Names end with '#'
36
37    --  Package names are preceded by 'P'
38
39    --  Attribute names are preceded by two letters
40
41    --  The first letter is one of
42    --    'S' for Single
43    --    'L' for list
44
45    --  The second letter is one of
46    --    'V' for single variable
47    --    'A' for associative array
48    --    'a' for case insensitive associative array
49
50    --  End is indicated by two consecutive '#'.
51
52    Initialization_Data : constant String :=
53
54    --  project attributes
55
56      "SVobject_dir#" &
57      "SVexec_dir#" &
58      "LVsource_dirs#" &
59      "LVsource_files#" &
60      "SVsource_list_file#" &
61      "SVlibrary_dir#" &
62      "SVlibrary_name#" &
63      "SVlibrary_kind#" &
64      "SVlibrary_elaboration#" &
65      "SVlibrary_version#" &
66      "LVmain#" &
67      "LVlanguages#" &
68
69    --  package Naming
70
71      "Pnaming#" &
72      "Saspecification_suffix#" &
73      "Saimplementation_suffix#" &
74      "SVseparate_suffix#" &
75      "SVcasing#" &
76      "SVdot_replacement#" &
77      "SAspecification#" &
78      "SAimplementation#" &
79      "LAspecification_exceptions#" &
80      "LAimplementation_exceptions#" &
81
82    --  package Compiler
83
84      "Pcompiler#" &
85      "Ladefault_switches#" &
86      "LAswitches#" &
87      "SVlocal_configuration_pragmas#" &
88
89    --  package Builder
90
91      "Pbuilder#" &
92      "Ladefault_switches#" &
93      "LAswitches#" &
94      "SVglobal_configuration_pragmas#" &
95
96    --  package gnatls
97
98      "Pgnatls#" &
99      "LVswitches#" &
100
101    --  package Binder
102
103      "Pbinder#" &
104      "Ladefault_switches#" &
105      "LAswitches#" &
106
107    --  package Linker
108
109      "Plinker#" &
110      "Ladefault_switches#" &
111      "LAswitches#" &
112
113    --  package Cross_Reference
114
115      "Pcross_reference#" &
116      "Ladefault_switches#" &
117      "LAswitches#" &
118
119    --  package Finder
120
121      "Pfinder#" &
122      "Ladefault_switches#" &
123      "LAswitches#" &
124
125    --  package Gnatstub
126
127      "Pgnatstub#" &
128      "LVswitches#" &
129
130    --  package Ide
131
132      "Pide#" &
133      "SVremote_host#" &
134      "Sacompiler_command#" &
135      "SVdebugger_command#" &
136      "SVgnatlist#" &
137      "SVvcs_kind#" &
138      "SVvcs_file_check#" &
139      "SVvcs_log_check#" &
140
141      "#";
142
143    ----------------
144    -- Initialize --
145    ----------------
146
147    procedure Initialize is
148       Start             : Positive           := Initialization_Data'First;
149       Finish            : Positive           := Start;
150       Current_Package   : Package_Node_Id    := Empty_Package;
151       Current_Attribute : Attribute_Node_Id  := Empty_Attribute;
152       Is_An_Attribute   : Boolean            := False;
153       Kind_1            : Variable_Kind      := Undefined;
154       Kind_2            : Attribute_Kind     := Single;
155       Package_Name      : Name_Id            := No_Name;
156       Attribute_Name    : Name_Id            := No_Name;
157       First_Attribute   : Attribute_Node_Id  := Attribute_First;
158
159    begin
160       --  Make sure the two tables are empty
161
162       Attributes.Set_Last (Attributes.First);
163       Package_Attributes.Set_Last (Package_Attributes.First);
164
165       while Initialization_Data (Start) /= '#' loop
166          Is_An_Attribute := True;
167          case Initialization_Data (Start) is
168             when 'P' =>
169
170                --  New allowed package
171
172                Start := Start + 1;
173
174                Finish := Start;
175                while Initialization_Data (Finish) /= '#' loop
176                   Finish := Finish + 1;
177                end loop;
178
179                Name_Len := Finish - Start;
180                Name_Buffer (1 .. Name_Len) :=
181                  To_Lower (Initialization_Data (Start .. Finish - 1));
182                Package_Name := Name_Find;
183
184                for Index in Package_First .. Package_Attributes.Last loop
185                   if Package_Name = Package_Attributes.Table (Index).Name then
186                      Write_Line ("Duplicate package name """ &
187                                  Initialization_Data (Start .. Finish - 1) &
188                                  """ in Prj.Attr body.");
189                      raise Program_Error;
190                   end if;
191                end loop;
192
193                Is_An_Attribute := False;
194                Current_Attribute := Empty_Attribute;
195                Package_Attributes.Increment_Last;
196                Current_Package := Package_Attributes.Last;
197                Package_Attributes.Table (Current_Package).Name :=
198                  Package_Name;
199                Start := Finish + 1;
200
201             when 'S' =>
202                Kind_1 := Single;
203
204             when 'L' =>
205                Kind_1 := List;
206
207             when others =>
208                raise Program_Error;
209          end case;
210
211          if Is_An_Attribute then
212
213             --  New attribute
214
215             Start := Start + 1;
216             case Initialization_Data (Start) is
217                when 'V' =>
218                   Kind_2 := Single;
219                when 'A' =>
220                   Kind_2 := Associative_Array;
221                when 'a' =>
222                   Kind_2 := Case_Insensitive_Associative_Array;
223                when others =>
224                   raise Program_Error;
225             end case;
226
227             Start := Start + 1;
228             Finish := Start;
229
230             while Initialization_Data (Finish) /= '#' loop
231                Finish := Finish + 1;
232             end loop;
233
234             Name_Len := Finish - Start;
235             Name_Buffer (1 .. Name_Len) :=
236               To_Lower (Initialization_Data (Start .. Finish - 1));
237             Attribute_Name := Name_Find;
238             Attributes.Increment_Last;
239             if Current_Attribute = Empty_Attribute then
240                First_Attribute := Attributes.Last;
241
242                if Current_Package /= Empty_Package then
243                   Package_Attributes.Table (Current_Package).First_Attribute
244                     := Attributes.Last;
245                end if;
246
247             else
248                --  Check that there are no duplicate attributes
249
250                for Index in First_Attribute .. Attributes.Last - 1 loop
251                   if Attribute_Name =
252                     Attributes.Table (Index).Name then
253                      Write_Line ("Duplicate attribute name """ &
254                                  Initialization_Data (Start .. Finish - 1) &
255                                  """ in Prj.Attr body.");
256                      raise Program_Error;
257                   end if;
258                end loop;
259
260                Attributes.Table (Current_Attribute).Next :=
261                  Attributes.Last;
262             end if;
263
264             Current_Attribute := Attributes.Last;
265             Attributes.Table (Current_Attribute) :=
266               (Name    => Attribute_Name,
267                Kind_1  => Kind_1,
268                Kind_2  => Kind_2,
269                Next    => Empty_Attribute);
270             Start := Finish + 1;
271          end if;
272       end loop;
273    end Initialize;
274
275 end Prj.Attr;