* pa64-hpux.h (LIB_SPEC): Fix library specification used with GNU ld.
[official-gcc.git] / gcc / ada / prj.adb
blob0f09236fd8fb173255a9ef0de7b3077e063326d3
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P R J --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2001-2004 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 ------------------------------------------------------------------------------
27 with Ada.Characters.Handling; use Ada.Characters.Handling;
29 with Namet; use Namet;
30 with Osint; use Osint;
31 with Prj.Attr;
32 with Prj.Com;
33 with Prj.Env;
34 with Prj.Err; use Prj.Err;
35 with Scans; use Scans;
36 with Snames; use Snames;
38 with GNAT.OS_Lib; use GNAT.OS_Lib;
40 package body Prj is
42 The_Empty_String : Name_Id;
44 Ada_Language : constant Name_Id := Name_Ada;
46 subtype Known_Casing is Casing_Type range All_Upper_Case .. Mixed_Case;
48 The_Casing_Images : constant array (Known_Casing) of String_Access :=
49 (All_Lower_Case => new String'("lowercase"),
50 All_Upper_Case => new String'("UPPERCASE"),
51 Mixed_Case => new String'("MixedCase"));
53 Initialized : Boolean := False;
55 Standard_Dot_Replacement : constant Name_Id :=
56 First_Name_Id + Character'Pos ('-');
58 Std_Naming_Data : Naming_Data :=
59 (Current_Language => No_Name,
60 Dot_Replacement => Standard_Dot_Replacement,
61 Dot_Repl_Loc => No_Location,
62 Casing => All_Lower_Case,
63 Spec_Suffix => No_Array_Element,
64 Current_Spec_Suffix => No_Name,
65 Spec_Suffix_Loc => No_Location,
66 Body_Suffix => No_Array_Element,
67 Current_Body_Suffix => No_Name,
68 Body_Suffix_Loc => No_Location,
69 Separate_Suffix => No_Name,
70 Sep_Suffix_Loc => No_Location,
71 Specs => No_Array_Element,
72 Bodies => No_Array_Element,
73 Specification_Exceptions => No_Array_Element,
74 Implementation_Exceptions => No_Array_Element);
76 Project_Empty : constant Project_Data :=
77 (First_Referred_By => No_Project,
78 Name => No_Name,
79 Path_Name => No_Name,
80 Virtual => False,
81 Display_Path_Name => No_Name,
82 Location => No_Location,
83 Mains => Nil_String,
84 Directory => No_Name,
85 Display_Directory => No_Name,
86 Dir_Path => null,
87 Library => False,
88 Library_Dir => No_Name,
89 Display_Library_Dir => No_Name,
90 Library_Src_Dir => No_Name,
91 Display_Library_Src_Dir => No_Name,
92 Library_Name => No_Name,
93 Library_Kind => Static,
94 Lib_Internal_Name => No_Name,
95 Lib_Elaboration => False,
96 Standalone_Library => False,
97 Lib_Interface_ALIs => Nil_String,
98 Lib_Auto_Init => False,
99 Symbol_Data => No_Symbols,
100 Sources_Present => True,
101 Sources => Nil_String,
102 Source_Dirs => Nil_String,
103 Known_Order_Of_Source_Dirs => True,
104 Object_Directory => No_Name,
105 Display_Object_Dir => No_Name,
106 Exec_Directory => No_Name,
107 Display_Exec_Dir => No_Name,
108 Extends => No_Project,
109 Extended_By => No_Project,
110 Naming => Std_Naming_Data,
111 Decl => No_Declarations,
112 Imported_Projects => Empty_Project_List,
113 Ada_Include_Path => null,
114 Ada_Objects_Path => null,
115 Include_Path_File => No_Name,
116 Objects_Path_File_With_Libs => No_Name,
117 Objects_Path_File_Without_Libs => No_Name,
118 Config_File_Name => No_Name,
119 Config_File_Temp => False,
120 Config_Checked => False,
121 Language_Independent_Checked => False,
122 Checked => False,
123 Seen => False,
124 Flag1 => False,
125 Flag2 => False,
126 Depth => 0,
127 Unkept_Comments => False);
129 -------------------
130 -- Add_To_Buffer --
131 -------------------
133 procedure Add_To_Buffer (S : String) is
134 begin
135 -- If Buffer is too small, double its size
137 if Buffer_Last + S'Length > Buffer'Last then
138 declare
139 New_Buffer : constant String_Access :=
140 new String (1 .. 2 * Buffer'Last);
142 begin
143 New_Buffer (1 .. Buffer_Last) := Buffer (1 .. Buffer_Last);
144 Free (Buffer);
145 Buffer := New_Buffer;
146 end;
147 end if;
149 Buffer (Buffer_Last + 1 .. Buffer_Last + S'Length) := S;
150 Buffer_Last := Buffer_Last + S'Length;
151 end Add_To_Buffer;
153 -------------------
154 -- Empty_Project --
155 -------------------
157 function Empty_Project return Project_Data is
158 begin
159 Initialize;
160 return Project_Empty;
161 end Empty_Project;
163 ------------------
164 -- Empty_String --
165 ------------------
167 function Empty_String return Name_Id is
168 begin
169 return The_Empty_String;
170 end Empty_String;
172 ------------
173 -- Expect --
174 ------------
176 procedure Expect (The_Token : Token_Type; Token_Image : String) is
177 begin
178 if Token /= The_Token then
179 Error_Msg (Token_Image & " expected", Token_Ptr);
180 end if;
181 end Expect;
183 --------------------------------
184 -- For_Every_Project_Imported --
185 --------------------------------
187 procedure For_Every_Project_Imported
188 (By : Project_Id;
189 With_State : in out State)
192 procedure Check (Project : Project_Id);
193 -- Check if a project has already been seen.
194 -- If not seen, mark it as seen, call Action,
195 -- and check all its imported projects.
197 procedure Check (Project : Project_Id) is
198 List : Project_List;
200 begin
201 if not Projects.Table (Project).Seen then
202 Projects.Table (Project).Seen := True;
203 Action (Project, With_State);
205 List := Projects.Table (Project).Imported_Projects;
206 while List /= Empty_Project_List loop
207 Check (Project_Lists.Table (List).Project);
208 List := Project_Lists.Table (List).Next;
209 end loop;
210 end if;
211 end Check;
213 begin
214 for Project in Projects.First .. Projects.Last loop
215 Projects.Table (Project).Seen := False;
216 end loop;
218 Check (Project => By);
219 end For_Every_Project_Imported;
221 -----------
222 -- Image --
223 -----------
225 function Image (Casing : Casing_Type) return String is
226 begin
227 return The_Casing_Images (Casing).all;
228 end Image;
230 ----------------
231 -- Initialize --
232 ----------------
234 procedure Initialize is
235 begin
236 if not Initialized then
237 Initialized := True;
238 Name_Len := 0;
239 The_Empty_String := Name_Find;
240 Empty_Name := The_Empty_String;
241 Name_Len := 4;
242 Name_Buffer (1 .. 4) := ".ads";
243 Default_Ada_Spec_Suffix := Name_Find;
244 Name_Len := 4;
245 Name_Buffer (1 .. 4) := ".adb";
246 Default_Ada_Body_Suffix := Name_Find;
247 Name_Len := 1;
248 Name_Buffer (1) := '/';
249 Slash := Name_Find;
250 Std_Naming_Data.Current_Spec_Suffix := Default_Ada_Spec_Suffix;
251 Std_Naming_Data.Current_Body_Suffix := Default_Ada_Body_Suffix;
252 Std_Naming_Data.Separate_Suffix := Default_Ada_Body_Suffix;
253 Register_Default_Naming_Scheme
254 (Language => Ada_Language,
255 Default_Spec_Suffix => Default_Ada_Spec_Suffix,
256 Default_Body_Suffix => Default_Ada_Body_Suffix);
257 Prj.Env.Initialize;
258 Prj.Attr.Initialize;
259 Set_Name_Table_Byte (Name_Project, Token_Type'Pos (Tok_Project));
260 Set_Name_Table_Byte (Name_Extends, Token_Type'Pos (Tok_Extends));
261 Set_Name_Table_Byte (Name_External, Token_Type'Pos (Tok_External));
262 end if;
263 end Initialize;
265 ------------------------------------
266 -- Register_Default_Naming_Scheme --
267 ------------------------------------
269 procedure Register_Default_Naming_Scheme
270 (Language : Name_Id;
271 Default_Spec_Suffix : Name_Id;
272 Default_Body_Suffix : Name_Id)
274 Lang : Name_Id;
275 Suffix : Array_Element_Id;
276 Found : Boolean := False;
277 Element : Array_Element;
279 begin
280 -- Get the language name in small letters
282 Get_Name_String (Language);
283 Name_Buffer (1 .. Name_Len) := To_Lower (Name_Buffer (1 .. Name_Len));
284 Lang := Name_Find;
286 Suffix := Std_Naming_Data.Spec_Suffix;
287 Found := False;
289 -- Look for an element of the spec sufix array indexed by the language
290 -- name. If one is found, put the default value.
292 while Suffix /= No_Array_Element and then not Found loop
293 Element := Array_Elements.Table (Suffix);
295 if Element.Index = Lang then
296 Found := True;
297 Element.Value.Value := Default_Spec_Suffix;
298 Array_Elements.Table (Suffix) := Element;
300 else
301 Suffix := Element.Next;
302 end if;
303 end loop;
305 -- If none can be found, create a new one.
307 if not Found then
308 Element :=
309 (Index => Lang,
310 Index_Case_Sensitive => False,
311 Value => (Project => No_Project,
312 Kind => Single,
313 Location => No_Location,
314 Default => False,
315 Value => Default_Spec_Suffix),
316 Next => Std_Naming_Data.Spec_Suffix);
317 Array_Elements.Increment_Last;
318 Array_Elements.Table (Array_Elements.Last) := Element;
319 Std_Naming_Data.Spec_Suffix := Array_Elements.Last;
320 end if;
322 Suffix := Std_Naming_Data.Body_Suffix;
323 Found := False;
325 -- Look for an element of the body sufix array indexed by the language
326 -- name. If one is found, put the default value.
328 while Suffix /= No_Array_Element and then not Found loop
329 Element := Array_Elements.Table (Suffix);
331 if Element.Index = Lang then
332 Found := True;
333 Element.Value.Value := Default_Body_Suffix;
334 Array_Elements.Table (Suffix) := Element;
336 else
337 Suffix := Element.Next;
338 end if;
339 end loop;
341 -- If none can be found, create a new one.
343 if not Found then
344 Element :=
345 (Index => Lang,
346 Index_Case_Sensitive => False,
347 Value => (Project => No_Project,
348 Kind => Single,
349 Location => No_Location,
350 Default => False,
351 Value => Default_Body_Suffix),
352 Next => Std_Naming_Data.Body_Suffix);
353 Array_Elements.Increment_Last;
354 Array_Elements.Table (Array_Elements.Last) := Element;
355 Std_Naming_Data.Body_Suffix := Array_Elements.Last;
356 end if;
357 end Register_Default_Naming_Scheme;
359 ------------
360 -- Reset --
361 ------------
363 procedure Reset is
364 begin
365 Projects.Init;
366 Project_Lists.Init;
367 Packages.Init;
368 Arrays.Init;
369 Variable_Elements.Init;
370 String_Elements.Init;
371 Prj.Com.Units.Init;
372 Prj.Com.Units_Htable.Reset;
373 Prj.Com.Files_Htable.Reset;
374 end Reset;
376 ------------------------
377 -- Same_Naming_Scheme --
378 ------------------------
380 function Same_Naming_Scheme
381 (Left, Right : Naming_Data)
382 return Boolean
384 begin
385 return Left.Dot_Replacement = Right.Dot_Replacement
386 and then Left.Casing = Right.Casing
387 and then Left.Current_Spec_Suffix = Right.Current_Spec_Suffix
388 and then Left.Current_Body_Suffix = Right.Current_Body_Suffix
389 and then Left.Separate_Suffix = Right.Separate_Suffix;
390 end Same_Naming_Scheme;
392 --------------------------
393 -- Standard_Naming_Data --
394 --------------------------
396 function Standard_Naming_Data return Naming_Data is
397 begin
398 Initialize;
399 return Std_Naming_Data;
400 end Standard_Naming_Data;
402 -----------
403 -- Value --
404 -----------
406 function Value (Image : String) return Casing_Type is
407 begin
408 for Casing in The_Casing_Images'Range loop
409 if To_Lower (Image) = To_Lower (The_Casing_Images (Casing).all) then
410 return Casing;
411 end if;
412 end loop;
414 raise Constraint_Error;
415 end Value;
417 begin
418 -- Make sure that the standard project file extension is compatible
419 -- with canonical case file naming.
421 Canonical_Case_File_Name (Project_File_Extension);
422 end Prj;